2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * Jalview - A Sequence Alignment Editor and Viewer
20 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License
24 * as published by the Free Software Foundation; either version 2
25 * of the License, or (at your option) any later version.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
42 import jalview.analysis.*;
46 import jalview.datamodel.*;
48 import jalview.schemes.*;
49 import jalview.structure.SelectionSource;
50 import jalview.structure.StructureSelectionManager;
58 public class AlignViewport implements SelectionSource
60 private static final int RIGHT_JUSTIFY = 1;
70 boolean showJVSuffix = true;
72 boolean showText = true;
74 boolean showColourText = false;
76 boolean showBoxes = true;
78 boolean wrapAlignment = false;
80 boolean renderGaps = true;
82 boolean showSequenceFeatures = false;
84 boolean showAnnotation = true;
86 boolean colourAppliesToAllGroups = true;
88 ColourSchemeI globalColourScheme = null;
90 boolean conservationColourSelected = false;
92 boolean abovePIDThreshold = false;
94 SequenceGroup selectionGroup;
100 boolean validCharWidth;
106 boolean seqNameItalics;
108 AlignmentI alignment;
110 ColumnSelection colSel = new ColumnSelection();
116 NJTree currentTree = null;
118 boolean scaleAboveWrapped = false;
120 boolean scaleLeftWrapped = true;
122 boolean scaleRightWrapped = true;
124 boolean hasHiddenColumns = false;
126 boolean hasHiddenRows = false;
128 boolean showHiddenMarkers = true;
130 boolean cursorMode = false;
133 * Keys are the feature types which are currently visible. Note: Values are
136 Hashtable featuresDisplayed = null;
139 public Hashtable[] hconsensus;
141 AlignmentAnnotation consensus;
143 AlignmentAnnotation conservation;
145 AlignmentAnnotation quality;
147 AlignmentAnnotation[] groupConsensus;
149 AlignmentAnnotation[] groupConservation;
151 boolean autoCalculateConsensus = true;
154 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
156 // JBPNote Prolly only need this in the applet version.
157 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
160 boolean ignoreGapsInConsensusCalculation = false;
162 boolean isDataset = false;
164 boolean antiAlias = false;
166 boolean padGaps = false;
168 Rectangle explodedPosition;
172 String sequenceSetID;
174 boolean gatherViewsHere = false;
176 Stack historyList = new Stack();
178 Stack redoList = new Stack();
180 Hashtable sequenceColours;
182 int thresholdTextColour = 0;
184 Color textColour = Color.black;
186 Color textColour2 = Color.white;
188 boolean rightAlignIds = false;
190 Hashtable hiddenRepSequences;
195 * Creates a new AlignViewport object.
200 public AlignViewport(AlignmentI al)
207 * Create a new AlignViewport object with a specific sequence set ID
211 * (may be null - but potential for ambiguous constructor exception)
213 public AlignViewport(AlignmentI al, String seqsetid)
215 this(al, seqsetid, null);
218 public AlignViewport(AlignmentI al, String seqsetid, String viewid)
220 sequenceSetID = seqsetid;
222 // TODO remove these once 2.4.VAMSAS release finished
223 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
225 Cache.log.debug("Setting viewport's sequence set id : "
228 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
230 Cache.log.debug("Setting viewport's view id : " + viewId);
237 * Create a new AlignViewport with hidden regions
241 * @param hiddenColumns
244 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns)
247 if (hiddenColumns != null)
249 this.colSel = hiddenColumns;
250 if (hiddenColumns.getHiddenColumns() != null
251 && hiddenColumns.getHiddenColumns().size() > 0)
253 hasHiddenColumns = true;
257 hasHiddenColumns = false;
264 * New viewport with hidden columns and an existing sequence set id
267 * @param hiddenColumns
271 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
274 this(al, hiddenColumns, seqsetid, null);
278 * New viewport with hidden columns and an existing sequence set id and viewid
281 * @param hiddenColumns
287 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
288 String seqsetid, String viewid)
290 sequenceSetID = seqsetid;
292 // TODO remove these once 2.4.VAMSAS release finished
293 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
295 Cache.log.debug("Setting viewport's sequence set id : "
298 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
300 Cache.log.debug("Setting viewport's view id : " + viewId);
303 if (hiddenColumns != null)
305 this.colSel = hiddenColumns;
306 if (hiddenColumns.getHiddenColumns() != null
307 && hiddenColumns.getHiddenColumns().size() > 0)
309 hasHiddenColumns = true;
313 hasHiddenColumns = false;
322 this.endRes = alignment.getWidth() - 1;
324 this.endSeq = alignment.getHeight() - 1;
326 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
328 showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
329 showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
331 rightAlignIds = Cache.getDefault("RIGHT_ALIGN_IDS", false);
332 centreColumnLabels = Cache.getDefault("CENTRE_COLUMN_LABELS", false);
333 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
335 padGaps = Cache.getDefault("PAD_GAPS", true);
336 shownpfeats = Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true);
337 showdbrefs = Cache.getDefault("SHOW_DBREFS_TOOLTIP", true);
339 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
340 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
341 String fontSize = Cache.getDefault("FONT_SIZE", "10");
343 seqNameItalics = Cache.getDefault("ID_ITALICS", true);
347 if (fontStyle.equals("bold"))
351 else if (fontStyle.equals("italic"))
356 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
359 .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
361 // We must set conservation and consensus before setting colour,
362 // as Blosum and Clustal require this to be done
363 if (hconsensus == null && !isDataset)
365 if (!alignment.isNucleotide())
367 conservation = new AlignmentAnnotation("Conservation",
368 "Conservation of total alignment less than " + ConsPercGaps
369 + "% gaps", new Annotation[1], 0f, 11f,
370 AlignmentAnnotation.BAR_GRAPH);
371 conservation.hasText = true;
372 conservation.autoCalculated = true;
374 if (Cache.getDefault("SHOW_CONSERVATION", true))
376 alignment.addAnnotation(conservation);
379 if (Cache.getDefault("SHOW_QUALITY", true))
381 quality = new AlignmentAnnotation("Quality",
382 "Alignment Quality based on Blosum62 scores",
383 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
384 quality.hasText = true;
385 quality.autoCalculated = true;
387 alignment.addAnnotation(quality);
389 showGroupConservation = Cache.getDefault("SHOW_GROUP_CONSERVATION",
396 showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",
398 showSequenceLogo = Cache.getDefault("SHOW_CONSENSUS_LOGO", false);
399 showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
400 // TODO: add menu option action that nulls or creates consensus object
401 // depending on if the user wants to see the annotation or not in a
402 // specific alignment
403 consensus = new AlignmentAnnotation("Consensus", "PID",
404 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
405 consensus.hasText = true;
406 consensus.autoCalculated = true;
408 if (Cache.getDefault("SHOW_IDENTITY", true))
410 alignment.addAnnotation(consensus);
414 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
416 globalColourScheme = ColourSchemeProperty.getColour(alignment,
417 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
419 if (globalColourScheme instanceof UserColourScheme)
421 globalColourScheme = UserDefinedColours.loadDefaultColours();
422 ((UserColourScheme) globalColourScheme).setThreshold(0,
423 getIgnoreGapsConsensus());
426 if (globalColourScheme != null)
428 globalColourScheme.setConsensus(hconsensus);
432 wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false);
433 showUnconserved = jalview.bin.Cache.getDefault("SHOW_UNCONSERVED",
435 sortByTree = jalview.bin.Cache.getDefault("SORT_BY_TREE", false);
436 // disabled by default for 2.5.1 release
437 followSelection = jalview.bin.Cache.getDefault("FOLLOW_SELECTIONS", false);
444 * features are displayed if true
446 public void setShowSequenceFeatures(boolean b)
448 showSequenceFeatures = b;
451 public boolean getShowSequenceFeatures()
453 return showSequenceFeatures;
456 ConservationThread conservationThread;
458 ConsensusThread consensusThread;
460 boolean consUpdateNeeded = false;
462 static boolean UPDATING_CONSENSUS = false;
464 static boolean UPDATING_CONSERVATION = false;
466 boolean updatingConsensus = false;
468 boolean updatingConservation = false;
471 * centre columnar annotation labels in displayed alignment annotation TODO:
472 * add to jalviewXML and annotation display settings
474 boolean centreColumnLabels = false;
476 private boolean showdbrefs;
478 private boolean shownpfeats;
481 * consensus annotation includes all percentage for all symbols in column
483 private boolean includeAllConsensusSymbols = true;
486 * trigger update of conservation annotation
488 public void updateConservation(final AlignmentPanel ap)
490 // see note in mantis : issue number 8585
491 if (alignment.isNucleotide() || conservation == null
492 || !autoCalculateConsensus)
497 conservationThread = new ConservationThread(this, ap);
498 conservationThread.start();
502 * trigger update of consensus annotation
504 public void updateConsensus(final AlignmentPanel ap)
506 // see note in mantis : issue number 8585
507 if (consensus == null || !autoCalculateConsensus)
511 consensusThread = new ConsensusThread(ap);
512 consensusThread.start();
515 class ConsensusThread extends Thread
519 public ConsensusThread(AlignmentPanel ap)
526 updatingConsensus = true;
527 while (UPDATING_CONSENSUS)
533 ap.paintAlignment(false);
537 } catch (Exception ex)
539 ex.printStackTrace();
543 UPDATING_CONSENSUS = true;
547 int aWidth = (alignment != null) ? alignment.getWidth() : 0; // null
556 consensus.annotations = null;
557 consensus.annotations = new Annotation[aWidth];
559 hconsensus = new Hashtable[aWidth];
560 AAFrequency.calculate(alignment.getSequencesArray(), 0, alignment
561 .getWidth(), hconsensus, includeAllConsensusSymbols);
562 AAFrequency.completeConsensus(consensus, hconsensus, 0, aWidth,
563 ignoreGapsInConsensusCalculation,
564 includeAllConsensusSymbols);
566 if (globalColourScheme != null)
568 globalColourScheme.setConsensus(hconsensus);
571 } catch (OutOfMemoryError error)
573 alignment.deleteAnnotation(consensus);
577 new OOMWarning("calculating consensus", error);
579 UPDATING_CONSENSUS = false;
580 updatingConsensus = false;
584 ap.paintAlignment(true);
590 * get the consensus sequence as displayed under the PID consensus annotation
593 * @return consensus sequence as a new sequence object
595 public SequenceI getConsensusSeq()
597 if (consensus == null)
599 updateConsensus(null);
601 if (consensus == null)
605 StringBuffer seqs = new StringBuffer();
606 for (int i = 0; i < consensus.annotations.length; i++)
608 if (consensus.annotations[i] != null)
610 if (consensus.annotations[i].description.charAt(0) == '[')
612 seqs.append(consensus.annotations[i].description.charAt(1));
616 seqs.append(consensus.annotations[i].displayCharacter);
621 SequenceI sq = new Sequence("Consensus", seqs.toString());
622 sq.setDescription("Percentage Identity Consensus "
623 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
630 * @return DOCUMENT ME!
632 public SequenceGroup getSelectionGroup()
634 return selectionGroup;
643 public void setSelectionGroup(SequenceGroup sg)
651 * @return DOCUMENT ME!
653 public boolean getConservationSelected()
655 return conservationColourSelected;
664 public void setConservationSelected(boolean b)
666 conservationColourSelected = b;
672 * @return DOCUMENT ME!
674 public boolean getAbovePIDThreshold()
676 return abovePIDThreshold;
685 public void setAbovePIDThreshold(boolean b)
687 abovePIDThreshold = b;
693 * @return DOCUMENT ME!
695 public int getStartRes()
703 * @return DOCUMENT ME!
705 public int getEndRes()
713 * @return DOCUMENT ME!
715 public int getStartSeq()
726 public void setGlobalColourScheme(ColourSchemeI cs)
728 globalColourScheme = cs;
734 * @return DOCUMENT ME!
736 public ColourSchemeI getGlobalColourScheme()
738 return globalColourScheme;
747 public void setStartRes(int res)
758 public void setStartSeq(int seq)
769 public void setEndRes(int res)
771 if (res > (alignment.getWidth() - 1))
773 // log.System.out.println(" Corrected res from " + res + " to maximum " +
774 // (alignment.getWidth()-1));
775 res = alignment.getWidth() - 1;
792 public void setEndSeq(int seq)
794 if (seq > alignment.getHeight())
796 seq = alignment.getHeight();
810 * @return DOCUMENT ME!
812 public int getEndSeq()
823 public void setFont(Font f)
827 Container c = new Container();
829 java.awt.FontMetrics fm = c.getFontMetrics(font);
830 setCharHeight(fm.getHeight());
831 setCharWidth(fm.charWidth('M'));
832 validCharWidth = true;
838 * @return DOCUMENT ME!
840 public Font getFont()
851 public void setCharWidth(int w)
859 * @return DOCUMENT ME!
861 public int getCharWidth()
872 public void setCharHeight(int h)
880 * @return DOCUMENT ME!
882 public int getCharHeight()
893 public void setWrappedWidth(int w)
895 this.wrappedWidth = w;
901 * @return DOCUMENT ME!
903 public int getWrappedWidth()
911 * @return DOCUMENT ME!
913 public AlignmentI getAlignment()
924 public void setAlignment(AlignmentI align)
926 if (alignment != null && alignment.getCodonFrames() != null)
928 StructureSelectionManager.getStructureSelectionManager()
929 .removeMappings(alignment.getCodonFrames());
931 this.alignment = align;
932 if (alignment.getCodonFrames() != null)
934 StructureSelectionManager.getStructureSelectionManager().addMappings(
935 alignment.getCodonFrames());
945 public void setWrapAlignment(boolean state)
947 wrapAlignment = state;
956 public void setShowText(boolean state)
967 public void setRenderGaps(boolean state)
975 * @return DOCUMENT ME!
977 public boolean getColourText()
979 return showColourText;
988 public void setColourText(boolean state)
990 showColourText = state;
999 public void setShowBoxes(boolean state)
1007 * @return DOCUMENT ME!
1009 public boolean getWrapAlignment()
1011 return wrapAlignment;
1017 * @return DOCUMENT ME!
1019 public boolean getShowText()
1027 * @return DOCUMENT ME!
1029 public boolean getShowBoxes()
1037 * @return DOCUMENT ME!
1039 public char getGapCharacter()
1041 return getAlignment().getGapCharacter();
1050 public void setGapCharacter(char gap)
1052 if (getAlignment() != null)
1054 getAlignment().setGapCharacter(gap);
1064 public void setThreshold(int thresh)
1072 * @return DOCUMENT ME!
1074 public int getThreshold()
1085 public void setIncrement(int inc)
1093 * @return DOCUMENT ME!
1095 public int getIncrement()
1103 * @return DOCUMENT ME!
1105 public ColumnSelection getColumnSelection()
1116 public void setCurrentTree(NJTree tree)
1124 * @return DOCUMENT ME!
1126 public NJTree getCurrentTree()
1137 public void setColourAppliesToAllGroups(boolean b)
1139 colourAppliesToAllGroups = b;
1145 * @return DOCUMENT ME!
1147 public boolean getColourAppliesToAllGroups()
1149 return colourAppliesToAllGroups;
1155 * @return DOCUMENT ME!
1157 public boolean getShowJVSuffix()
1159 return showJVSuffix;
1168 public void setShowJVSuffix(boolean b)
1176 * @return DOCUMENT ME!
1178 public boolean getShowAnnotation()
1180 return showAnnotation;
1189 public void setShowAnnotation(boolean b)
1197 * @return DOCUMENT ME!
1199 public boolean getScaleAboveWrapped()
1201 return scaleAboveWrapped;
1207 * @return DOCUMENT ME!
1209 public boolean getScaleLeftWrapped()
1211 return scaleLeftWrapped;
1217 * @return DOCUMENT ME!
1219 public boolean getScaleRightWrapped()
1221 return scaleRightWrapped;
1230 public void setScaleAboveWrapped(boolean b)
1232 scaleAboveWrapped = b;
1241 public void setScaleLeftWrapped(boolean b)
1243 scaleLeftWrapped = b;
1252 public void setScaleRightWrapped(boolean b)
1254 scaleRightWrapped = b;
1258 * Property change listener for changes in alignment
1263 public void addPropertyChangeListener(
1264 java.beans.PropertyChangeListener listener)
1266 changeSupport.addPropertyChangeListener(listener);
1275 public void removePropertyChangeListener(
1276 java.beans.PropertyChangeListener listener)
1278 changeSupport.removePropertyChangeListener(listener);
1282 * Property change listener for changes in alignment
1291 public void firePropertyChange(String prop, Object oldvalue,
1294 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1297 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1299 ignoreGapsInConsensusCalculation = b;
1300 updateConsensus(ap);
1301 if (globalColourScheme != null)
1303 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1304 ignoreGapsInConsensusCalculation);
1308 public boolean getIgnoreGapsConsensus()
1310 return ignoreGapsInConsensusCalculation;
1313 public void setDataset(boolean b)
1318 public boolean isDataset()
1323 public void hideSelectedColumns()
1325 if (colSel.size() < 1)
1330 colSel.hideSelectedColumns();
1331 setSelectionGroup(null);
1333 hasHiddenColumns = true;
1336 public void hideColumns(int start, int end)
1340 colSel.hideColumns(start);
1344 colSel.hideColumns(start, end);
1347 hasHiddenColumns = true;
1350 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1352 int sSize = sg.getSize();
1358 if (hiddenRepSequences == null)
1360 hiddenRepSequences = new Hashtable();
1363 hiddenRepSequences.put(repSequence, sg);
1365 // Hide all sequences except the repSequence
1366 SequenceI[] seqs = new SequenceI[sSize - 1];
1368 for (int i = 0; i < sSize; i++)
1370 if (sg.getSequenceAt(i) != repSequence)
1372 if (index == sSize - 1)
1377 seqs[index++] = sg.getSequenceAt(i);
1380 sg.setSeqrep(repSequence);
1381 sg.setHidereps(true);
1386 public void hideAllSelectedSeqs()
1388 if (selectionGroup == null || selectionGroup.getSize() < 1)
1393 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1397 setSelectionGroup(null);
1400 public void hideSequence(SequenceI[] seq)
1404 for (int i = 0; i < seq.length; i++)
1406 alignment.getHiddenSequences().hideSequence(seq[i]);
1408 hasHiddenRows = true;
1409 firePropertyChange("alignment", null, alignment.getSequences());
1413 public void showSequence(int index)
1415 Vector tmp = alignment.getHiddenSequences().showSequence(index,
1416 hiddenRepSequences);
1419 if (selectionGroup == null)
1421 selectionGroup = new SequenceGroup();
1422 selectionGroup.setEndRes(alignment.getWidth() - 1);
1425 for (int t = 0; t < tmp.size(); t++)
1427 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1429 firePropertyChange("alignment", null, alignment.getSequences());
1433 if (alignment.getHiddenSequences().getSize() < 1)
1435 hasHiddenRows = false;
1439 public void showColumn(int col)
1441 colSel.revealHiddenColumns(col);
1442 if (colSel.getHiddenColumns() == null)
1444 hasHiddenColumns = false;
1448 public void showAllHiddenColumns()
1450 colSel.revealAllHiddenColumns();
1451 hasHiddenColumns = false;
1454 public void showAllHiddenSeqs()
1456 if (alignment.getHiddenSequences().getSize() > 0)
1458 if (selectionGroup == null)
1460 selectionGroup = new SequenceGroup();
1461 selectionGroup.setEndRes(alignment.getWidth() - 1);
1463 Vector tmp = alignment.getHiddenSequences().showAll(
1464 hiddenRepSequences);
1465 for (int t = 0; t < tmp.size(); t++)
1467 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1469 firePropertyChange("alignment", null, alignment.getSequences());
1471 hasHiddenRows = false;
1472 hiddenRepSequences = null;
1476 public void invertColumnSelection()
1478 colSel.invertColumnSelection(0, alignment.getWidth());
1481 public int adjustForHiddenSeqs(int alignmentIndex)
1483 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1488 * This method returns an array of new SequenceI objects derived from the
1489 * whole alignment or just the current selection with start and end points
1492 * @note if you need references to the actual SequenceI objects in the
1493 * alignment or currently selected then use getSequenceSelection()
1494 * @return selection as new sequenceI objects
1496 public SequenceI[] getSelectionAsNewSequence()
1498 SequenceI[] sequences;
1500 if (selectionGroup == null)
1502 sequences = alignment.getSequencesArray();
1503 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1504 for (int i = 0; i < sequences.length; i++)
1506 sequences[i] = new Sequence(sequences[i], annots); // construct new
1508 // subset of visible
1514 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1521 * get the currently selected sequence objects or all the sequences in the
1524 * @return array of references to sequence objects
1526 public SequenceI[] getSequenceSelection()
1528 SequenceI[] sequences = null;
1529 if (selectionGroup != null)
1531 sequences = selectionGroup.getSequencesInOrder(alignment);
1533 if (sequences == null)
1535 sequences = alignment.getSequencesArray();
1541 * This method returns the visible alignment as text, as seen on the GUI, ie
1542 * if columns are hidden they will not be returned in the result. Use this for
1543 * calculating trees, PCA, redundancy etc on views which contain hidden
1548 public jalview.datamodel.CigarArray getViewAsCigars(
1549 boolean selectedRegionOnly)
1551 CigarArray selection = null;
1552 SequenceI[] seqs = null;
1554 int start = 0, end = 0;
1555 if (selectedRegionOnly && selectionGroup != null)
1557 iSize = selectionGroup.getSize();
1558 seqs = selectionGroup.getSequencesInOrder(alignment);
1559 start = selectionGroup.getStartRes();
1560 end = selectionGroup.getEndRes(); // inclusive for start and end in
1561 // SeqCigar constructor
1565 iSize = alignment.getHeight();
1566 seqs = alignment.getSequencesArray();
1567 end = alignment.getWidth() - 1;
1569 SeqCigar[] selseqs = new SeqCigar[iSize];
1570 for (i = 0; i < iSize; i++)
1572 selseqs[i] = new SeqCigar(seqs[i], start, end);
1574 selection = new CigarArray(selseqs);
1575 // now construct the CigarArray operations
1576 if (hasHiddenColumns)
1578 Vector regions = colSel.getHiddenColumns();
1580 int hideStart, hideEnd;
1582 for (int j = 0; last < end & j < regions.size(); j++)
1584 region = (int[]) regions.elementAt(j);
1585 hideStart = region[0];
1586 hideEnd = region[1];
1587 // edit hidden regions to selection range
1588 if (hideStart < last)
1600 if (hideStart > end)
1610 if (hideStart > hideEnd)
1615 * form operations...
1617 if (last < hideStart)
1619 selection.addOperation(CigarArray.M, hideStart - last);
1621 selection.addOperation(CigarArray.D, 1 + hideEnd - hideStart);
1624 // Final match if necessary.
1627 selection.addOperation(CigarArray.M, end - last + 1);
1632 selection.addOperation(CigarArray.M, end - start + 1);
1638 * return a compact representation of the current alignment selection to pass
1639 * to an analysis function
1641 * @param selectedOnly
1642 * boolean true to just return the selected view
1643 * @return AlignmentView
1645 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
1648 // this is here because the AlignmentView constructor modifies the
1650 // object. Refactoring of Cigar and alignment view representation should
1651 // be done to remove redundancy.
1652 CigarArray aligview = getViewAsCigars(selectedOnly);
1653 if (aligview != null)
1655 return new AlignmentView(aligview,
1656 (selectedOnly && selectionGroup != null) ? selectionGroup
1657 .getStartRes() : 0);
1663 * This method returns the visible alignment as text, as seen on the GUI, ie
1664 * if columns are hidden they will not be returned in the result. Use this for
1665 * calculating trees, PCA, redundancy etc on views which contain hidden
1670 public String[] getViewAsString(boolean selectedRegionOnly)
1672 String[] selection = null;
1673 SequenceI[] seqs = null;
1675 int start = 0, end = 0;
1676 if (selectedRegionOnly && selectionGroup != null)
1678 iSize = selectionGroup.getSize();
1679 seqs = selectionGroup.getSequencesInOrder(alignment);
1680 start = selectionGroup.getStartRes();
1681 end = selectionGroup.getEndRes() + 1;
1685 iSize = alignment.getHeight();
1686 seqs = alignment.getSequencesArray();
1687 end = alignment.getWidth();
1690 selection = new String[iSize];
1691 if (hasHiddenColumns)
1693 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1697 for (i = 0; i < iSize; i++)
1699 selection[i] = seqs[i].getSequenceAsString(start, end);
1706 public int[][] getVisibleRegionBoundaries(int min, int max)
1708 Vector regions = new Vector();
1714 if (hasHiddenColumns)
1718 start = colSel.adjustForHiddenColumns(start);
1721 end = colSel.getHiddenBoundaryRight(start);
1732 regions.addElement(new int[]
1735 if (hasHiddenColumns)
1737 start = colSel.adjustForHiddenColumns(end);
1738 start = colSel.getHiddenBoundaryLeft(start) + 1;
1740 } while (end < max);
1742 int[][] startEnd = new int[regions.size()][2];
1744 regions.copyInto(startEnd);
1750 public boolean getShowHiddenMarkers()
1752 return showHiddenMarkers;
1755 public void setShowHiddenMarkers(boolean show)
1757 showHiddenMarkers = show;
1760 public String getSequenceSetId()
1762 if (sequenceSetID == null)
1764 sequenceSetID = alignment.hashCode() + "";
1767 return sequenceSetID;
1771 * unique viewId for synchronizing state with stored Jalview Project
1774 private String viewId = null;
1776 public String getViewId()
1780 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1785 public void alignmentChanged(AlignmentPanel ap)
1789 alignment.padGaps();
1791 if (hconsensus != null && autoCalculateConsensus)
1793 updateConservation(ap);
1795 if (autoCalculateConsensus)
1797 updateConsensus(ap);
1800 // Reset endRes of groups if beyond alignment width
1801 int alWidth = alignment.getWidth();
1802 Vector groups = alignment.getGroups();
1805 for (int i = 0; i < groups.size(); i++)
1807 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
1808 if (sg.getEndRes() > alWidth)
1810 sg.setEndRes(alWidth - 1);
1815 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1817 selectionGroup.setEndRes(alWidth - 1);
1820 resetAllColourSchemes();
1822 // alignment.adjustSequenceAnnotations();
1825 void resetAllColourSchemes()
1827 ColourSchemeI cs = globalColourScheme;
1830 if (cs instanceof ClustalxColourScheme)
1832 ((ClustalxColourScheme) cs).resetClustalX(alignment.getSequences(),
1833 alignment.getWidth());
1836 cs.setConsensus(hconsensus);
1837 if (cs.conservationApplied())
1839 Alignment al = (Alignment) alignment;
1840 Conservation c = new Conservation("All",
1841 ResidueProperties.propHash, 3, al.getSequences(), 0, al
1844 c.verdict(false, ConsPercGaps);
1846 cs.setConservation(c);
1850 int s, sSize = alignment.getGroups().size();
1851 for (s = 0; s < sSize; s++)
1853 SequenceGroup sg = (SequenceGroup) alignment.getGroups().elementAt(s);
1854 if (sg.cs != null && sg.cs instanceof ClustalxColourScheme)
1856 ((ClustalxColourScheme) sg.cs).resetClustalX(sg
1857 .getSequences(hiddenRepSequences), sg.getWidth());
1859 sg.recalcConservation();
1863 public Color getSequenceColour(SequenceI seq)
1865 if (sequenceColours == null || !sequenceColours.containsKey(seq))
1871 return (Color) sequenceColours.get(seq);
1875 public void setSequenceColour(SequenceI seq, Color col)
1877 if (sequenceColours == null)
1879 sequenceColours = new Hashtable();
1884 sequenceColours.remove(seq);
1888 sequenceColours.put(seq, col);
1893 * returns the visible column regions of the alignment
1895 * @param selectedRegionOnly
1896 * true to just return the contigs intersecting with the selected
1900 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
1902 int[] viscontigs = null;
1903 int start = 0, end = 0;
1904 if (selectedRegionOnly && selectionGroup != null)
1906 start = selectionGroup.getStartRes();
1907 end = selectionGroup.getEndRes() + 1;
1911 end = alignment.getWidth();
1913 viscontigs = colSel.getVisibleContigs(start, end);
1918 * get hash of undo and redo list for the alignment
1920 * @return long[] { historyList.hashCode, redoList.hashCode };
1922 public long[] getUndoRedoHash()
1924 if (historyList == null || redoList == null)
1928 { historyList.hashCode(), this.redoList.hashCode() };
1932 * test if a particular set of hashcodes are different to the hashcodes for
1933 * the undo and redo list.
1936 * the stored set of hashcodes as returned by getUndoRedoHash
1937 * @return true if the hashcodes differ (ie the alignment has been edited) or
1938 * the stored hashcode array differs in size
1940 public boolean isUndoRedoHashModified(long[] undoredo)
1942 if (undoredo == null)
1946 long[] cstate = getUndoRedoHash();
1947 if (cstate.length != undoredo.length)
1952 for (int i = 0; i < cstate.length; i++)
1954 if (cstate[i] != undoredo[i])
1962 public boolean getCentreColumnLabels()
1964 return centreColumnLabels;
1967 public void setCentreColumnLabels(boolean centrecolumnlabels)
1969 centreColumnLabels = centrecolumnlabels;
1972 public void updateSequenceIdColours()
1974 Vector groups = alignment.getGroups();
1975 if (sequenceColours == null)
1977 sequenceColours = new Hashtable();
1979 for (int ig = 0, igSize = groups.size(); ig < igSize; ig++)
1981 SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
1982 if (sg.idColour != null)
1984 Vector sqs = sg.getSequences(hiddenRepSequences);
1985 for (int s = 0, sSize = sqs.size(); s < sSize; s++)
1987 sequenceColours.put(sqs.elementAt(s), sg.idColour);
1994 * enable or disable the display of Database Cross References in the sequence
1997 public void setShowDbRefs(boolean show)
2004 * @return true if Database References are to be displayed on tooltips.
2006 public boolean isShowDbRefs()
2013 * @return true if Non-positional features are to be displayed on tooltips.
2015 public boolean isShowNpFeats()
2021 * enable or disable the display of Non-Positional sequence features in the
2022 * sequence ID tooltip
2026 public void setShowNpFeats(boolean show)
2033 * @return true if view has hidden rows
2035 public boolean hasHiddenRows()
2037 return hasHiddenRows;
2042 * @return true if view has hidden columns
2044 public boolean hasHiddenColumns()
2046 return hasHiddenColumns;
2050 * when set, view will scroll to show the highlighted position
2052 public boolean followHighlight = true;
2055 * @return true if view should scroll to show the highlighted region of a
2059 public boolean getFollowHighlight()
2061 return followHighlight;
2064 public boolean followSelection = true;
2067 * @return true if view selection should always follow the selections
2068 * broadcast by other selection sources
2070 public boolean getFollowSelection()
2072 return followSelection;
2075 private long sgrouphash = -1, colselhash = -1;
2077 boolean showSeqFeaturesHeight;
2080 * checks current SelectionGroup against record of last hash value, and
2083 * @return true if SelectionGroup changed since last call
2085 boolean isSelectionGroupChanged()
2087 int hc = (selectionGroup == null) ? -1 : selectionGroup.hashCode();
2088 if (hc != sgrouphash)
2097 * checks current colsel against record of last hash value, and updates
2100 * @return true if colsel changed since last call
2102 boolean isColSelChanged()
2104 int hc = (colSel == null) ? -1 : colSel.hashCode();
2105 if (hc != colselhash)
2113 public void sendSelection()
2115 jalview.structure.StructureSelectionManager
2116 .getStructureSelectionManager().sendSelection(
2117 new SequenceGroup(getSelectionGroup()),
2118 new ColumnSelection(getColumnSelection()), this);
2121 public void setShowSequenceFeaturesHeight(boolean selected)
2123 showSeqFeaturesHeight = selected;
2126 public boolean getShowSequenceFeaturesHeight()
2128 return showSeqFeaturesHeight;
2131 boolean showUnconserved = false;
2133 public boolean getShowUnconserved()
2135 return showUnconserved;
2138 public void setShowUnconserved(boolean showunconserved)
2140 showUnconserved = showunconserved;
2144 * return the alignPanel containing the given viewport. Use this to get the
2145 * components currently handling the given viewport.
2148 * @return null or an alignPanel guaranteed to have non-null alignFrame
2151 public AlignmentPanel getAlignPanel()
2153 AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(this
2154 .getSequenceSetId());
2155 AlignmentPanel ap = null;
2156 for (int p = 0; aps != null && p < aps.length; p++)
2158 if (aps[p].av == this)
2166 public boolean getSortByTree()
2171 public void setSortByTree(boolean sort)
2177 * should conservation rows be shown for groups
2179 boolean showGroupConservation = false;
2182 * should consensus rows be shown for groups
2184 boolean showGroupConsensus = false;
2187 * should consensus profile be rendered by default
2189 public boolean showSequenceLogo = false;
2192 * should consensus histograms be rendered by default
2194 public boolean showConsensusHistogram = true;
2197 * @return the showConsensusProfile
2199 public boolean isShowSequenceLogo()
2201 return showSequenceLogo;
2205 * @param showSequenceLogo
2208 public void setShowSequenceLogo(boolean showSequenceLogo)
2210 this.showSequenceLogo = showSequenceLogo;
2214 * @param showConsensusHistogram
2215 * the showConsensusHistogram to set
2217 public void setShowConsensusHistogram(boolean showConsensusHistogram)
2219 this.showConsensusHistogram = showConsensusHistogram;
2223 * @return the showGroupConservation
2225 public boolean isShowGroupConservation()
2227 return showGroupConservation;
2231 * @param showGroupConservation
2232 * the showGroupConservation to set
2234 public void setShowGroupConservation(boolean showGroupConservation)
2236 this.showGroupConservation = showGroupConservation;
2240 * @return the showGroupConsensus
2242 public boolean isShowGroupConsensus()
2244 return showGroupConsensus;
2248 * @param showGroupConsensus
2249 * the showGroupConsensus to set
2251 public void setShowGroupConsensus(boolean showGroupConsensus)
2253 this.showGroupConsensus = showGroupConsensus;
2257 * @return the includeAllConsensusSymbols
2259 public boolean isIncludeAllConsensusSymbols()
2261 return includeAllConsensusSymbols;
2265 * @param includeAllConsensusSymbols
2266 * the includeAllConsensusSymbols to set
2268 public void setIncludeAllConsensusSymbols(
2269 boolean includeAllConsensusSymbols)
2271 this.includeAllConsensusSymbols = includeAllConsensusSymbols;
2276 * @return flag to indicate if the consensus histogram should be rendered by
2279 public boolean isShowConsensusHistogram()
2281 return this.showConsensusHistogram;
2285 * synthesize a column selection if none exists so it covers the given
2286 * selection group. if wholewidth is false, no column selection is made if the
2287 * selection group covers the whole alignment width.
2292 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2296 && (sgs = sg.getStartRes()) >= 0
2297 && sg.getStartRes() <= (sge = sg.getEndRes())
2298 && (colSel == null || colSel.getSelected() == null || colSel
2299 .getSelected().size() == 0))
2301 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2308 colSel = new ColumnSelection();
2310 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2312 colSel.addElement(cspos);