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 * trigger update of conservation annotation
483 public void updateConservation(final AlignmentPanel ap)
485 // see note in mantis : issue number 8585
486 if (alignment.isNucleotide() || conservation == null
487 || !autoCalculateConsensus)
492 conservationThread = new ConservationThread(this, ap);
493 conservationThread.start();
497 * trigger update of consensus annotation
499 public void updateConsensus(final AlignmentPanel ap)
501 // see note in mantis : issue number 8585
502 if (consensus == null || !autoCalculateConsensus)
506 consensusThread = new ConsensusThread(ap);
507 consensusThread.start();
510 class ConsensusThread extends Thread
514 public ConsensusThread(AlignmentPanel ap)
521 updatingConsensus = true;
522 while (UPDATING_CONSENSUS)
528 ap.paintAlignment(false);
532 } catch (Exception ex)
534 ex.printStackTrace();
538 UPDATING_CONSENSUS = true;
542 int aWidth = (alignment != null) ? alignment.getWidth() : 0; // null
551 consensus.annotations = null;
552 consensus.annotations = new Annotation[aWidth];
554 hconsensus = new Hashtable[aWidth];
555 AAFrequency.calculate(alignment.getSequencesArray(), 0, alignment
556 .getWidth(), hconsensus, true);
557 updateAnnotation(true);
559 if (globalColourScheme != null)
561 globalColourScheme.setConsensus(hconsensus);
564 } catch (OutOfMemoryError error)
566 alignment.deleteAnnotation(consensus);
570 new OOMWarning("calculating consensus", error);
572 UPDATING_CONSENSUS = false;
573 updatingConsensus = false;
577 ap.paintAlignment(true);
582 * update the consensus annotation from the sequence profile data using
583 * current visualization settings.
585 public void updateAnnotation()
587 updateAnnotation(false);
590 protected void updateAnnotation(boolean immediate)
593 || (!updatingConsensus && consensus != null && hconsensus != null))
595 AAFrequency.completeConsensus(consensus, hconsensus, 0,
596 hconsensus.length, ignoreGapsInConsensusCalculation,
603 * get the consensus sequence as displayed under the PID consensus annotation
606 * @return consensus sequence as a new sequence object
608 public SequenceI getConsensusSeq()
610 if (consensus == null)
612 updateConsensus(null);
614 if (consensus == null)
618 StringBuffer seqs = new StringBuffer();
619 for (int i = 0; i < consensus.annotations.length; i++)
621 if (consensus.annotations[i] != null)
623 if (consensus.annotations[i].description.charAt(0) == '[')
625 seqs.append(consensus.annotations[i].description.charAt(1));
629 seqs.append(consensus.annotations[i].displayCharacter);
634 SequenceI sq = new Sequence("Consensus", seqs.toString());
635 sq.setDescription("Percentage Identity Consensus "
636 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
643 * @return DOCUMENT ME!
645 public SequenceGroup getSelectionGroup()
647 return selectionGroup;
656 public void setSelectionGroup(SequenceGroup sg)
664 * @return DOCUMENT ME!
666 public boolean getConservationSelected()
668 return conservationColourSelected;
677 public void setConservationSelected(boolean b)
679 conservationColourSelected = b;
685 * @return DOCUMENT ME!
687 public boolean getAbovePIDThreshold()
689 return abovePIDThreshold;
698 public void setAbovePIDThreshold(boolean b)
700 abovePIDThreshold = b;
706 * @return DOCUMENT ME!
708 public int getStartRes()
716 * @return DOCUMENT ME!
718 public int getEndRes()
726 * @return DOCUMENT ME!
728 public int getStartSeq()
739 public void setGlobalColourScheme(ColourSchemeI cs)
741 globalColourScheme = cs;
747 * @return DOCUMENT ME!
749 public ColourSchemeI getGlobalColourScheme()
751 return globalColourScheme;
760 public void setStartRes(int res)
771 public void setStartSeq(int seq)
782 public void setEndRes(int res)
784 if (res > (alignment.getWidth() - 1))
786 // log.System.out.println(" Corrected res from " + res + " to maximum " +
787 // (alignment.getWidth()-1));
788 res = alignment.getWidth() - 1;
805 public void setEndSeq(int seq)
807 if (seq > alignment.getHeight())
809 seq = alignment.getHeight();
823 * @return DOCUMENT ME!
825 public int getEndSeq()
836 public void setFont(Font f)
840 Container c = new Container();
842 java.awt.FontMetrics fm = c.getFontMetrics(font);
843 setCharHeight(fm.getHeight());
844 setCharWidth(fm.charWidth('M'));
845 validCharWidth = true;
851 * @return DOCUMENT ME!
853 public Font getFont()
864 public void setCharWidth(int w)
872 * @return DOCUMENT ME!
874 public int getCharWidth()
885 public void setCharHeight(int h)
893 * @return DOCUMENT ME!
895 public int getCharHeight()
906 public void setWrappedWidth(int w)
908 this.wrappedWidth = w;
914 * @return DOCUMENT ME!
916 public int getWrappedWidth()
924 * @return DOCUMENT ME!
926 public AlignmentI getAlignment()
937 public void setAlignment(AlignmentI align)
939 if (alignment != null && alignment.getCodonFrames() != null)
941 StructureSelectionManager.getStructureSelectionManager()
942 .removeMappings(alignment.getCodonFrames());
944 this.alignment = align;
945 if (alignment.getCodonFrames() != null)
947 StructureSelectionManager.getStructureSelectionManager().addMappings(
948 alignment.getCodonFrames());
958 public void setWrapAlignment(boolean state)
960 wrapAlignment = state;
969 public void setShowText(boolean state)
980 public void setRenderGaps(boolean state)
988 * @return DOCUMENT ME!
990 public boolean getColourText()
992 return showColourText;
1001 public void setColourText(boolean state)
1003 showColourText = state;
1012 public void setShowBoxes(boolean state)
1020 * @return DOCUMENT ME!
1022 public boolean getWrapAlignment()
1024 return wrapAlignment;
1030 * @return DOCUMENT ME!
1032 public boolean getShowText()
1040 * @return DOCUMENT ME!
1042 public boolean getShowBoxes()
1050 * @return DOCUMENT ME!
1052 public char getGapCharacter()
1054 return getAlignment().getGapCharacter();
1063 public void setGapCharacter(char gap)
1065 if (getAlignment() != null)
1067 getAlignment().setGapCharacter(gap);
1077 public void setThreshold(int thresh)
1085 * @return DOCUMENT ME!
1087 public int getThreshold()
1098 public void setIncrement(int inc)
1106 * @return DOCUMENT ME!
1108 public int getIncrement()
1116 * @return DOCUMENT ME!
1118 public ColumnSelection getColumnSelection()
1129 public void setCurrentTree(NJTree tree)
1137 * @return DOCUMENT ME!
1139 public NJTree getCurrentTree()
1150 public void setColourAppliesToAllGroups(boolean b)
1152 colourAppliesToAllGroups = b;
1158 * @return DOCUMENT ME!
1160 public boolean getColourAppliesToAllGroups()
1162 return colourAppliesToAllGroups;
1168 * @return DOCUMENT ME!
1170 public boolean getShowJVSuffix()
1172 return showJVSuffix;
1181 public void setShowJVSuffix(boolean b)
1189 * @return DOCUMENT ME!
1191 public boolean getShowAnnotation()
1193 return showAnnotation;
1202 public void setShowAnnotation(boolean b)
1210 * @return DOCUMENT ME!
1212 public boolean getScaleAboveWrapped()
1214 return scaleAboveWrapped;
1220 * @return DOCUMENT ME!
1222 public boolean getScaleLeftWrapped()
1224 return scaleLeftWrapped;
1230 * @return DOCUMENT ME!
1232 public boolean getScaleRightWrapped()
1234 return scaleRightWrapped;
1243 public void setScaleAboveWrapped(boolean b)
1245 scaleAboveWrapped = b;
1254 public void setScaleLeftWrapped(boolean b)
1256 scaleLeftWrapped = b;
1265 public void setScaleRightWrapped(boolean b)
1267 scaleRightWrapped = b;
1271 * Property change listener for changes in alignment
1276 public void addPropertyChangeListener(
1277 java.beans.PropertyChangeListener listener)
1279 changeSupport.addPropertyChangeListener(listener);
1288 public void removePropertyChangeListener(
1289 java.beans.PropertyChangeListener listener)
1291 changeSupport.removePropertyChangeListener(listener);
1295 * Property change listener for changes in alignment
1304 public void firePropertyChange(String prop, Object oldvalue,
1307 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1310 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1312 ignoreGapsInConsensusCalculation = b;
1313 updateConsensus(ap);
1314 if (globalColourScheme != null)
1316 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1317 ignoreGapsInConsensusCalculation);
1321 public boolean getIgnoreGapsConsensus()
1323 return ignoreGapsInConsensusCalculation;
1326 public void setDataset(boolean b)
1331 public boolean isDataset()
1336 public void hideSelectedColumns()
1338 if (colSel.size() < 1)
1343 colSel.hideSelectedColumns();
1344 setSelectionGroup(null);
1346 hasHiddenColumns = true;
1349 public void hideColumns(int start, int end)
1353 colSel.hideColumns(start);
1357 colSel.hideColumns(start, end);
1360 hasHiddenColumns = true;
1363 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1365 int sSize = sg.getSize();
1371 if (hiddenRepSequences == null)
1373 hiddenRepSequences = new Hashtable();
1376 hiddenRepSequences.put(repSequence, sg);
1378 // Hide all sequences except the repSequence
1379 SequenceI[] seqs = new SequenceI[sSize - 1];
1381 for (int i = 0; i < sSize; i++)
1383 if (sg.getSequenceAt(i) != repSequence)
1385 if (index == sSize - 1)
1390 seqs[index++] = sg.getSequenceAt(i);
1393 sg.setSeqrep(repSequence);
1394 sg.setHidereps(true);
1399 public void hideAllSelectedSeqs()
1401 if (selectionGroup == null || selectionGroup.getSize() < 1)
1406 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1410 setSelectionGroup(null);
1413 public void hideSequence(SequenceI[] seq)
1417 for (int i = 0; i < seq.length; i++)
1419 alignment.getHiddenSequences().hideSequence(seq[i]);
1421 hasHiddenRows = true;
1422 firePropertyChange("alignment", null, alignment.getSequences());
1426 public void showSequence(int index)
1428 Vector tmp = alignment.getHiddenSequences().showSequence(index,
1429 hiddenRepSequences);
1432 if (selectionGroup == null)
1434 selectionGroup = new SequenceGroup();
1435 selectionGroup.setEndRes(alignment.getWidth() - 1);
1438 for (int t = 0; t < tmp.size(); t++)
1440 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1442 firePropertyChange("alignment", null, alignment.getSequences());
1446 if (alignment.getHiddenSequences().getSize() < 1)
1448 hasHiddenRows = false;
1452 public void showColumn(int col)
1454 colSel.revealHiddenColumns(col);
1455 if (colSel.getHiddenColumns() == null)
1457 hasHiddenColumns = false;
1461 public void showAllHiddenColumns()
1463 colSel.revealAllHiddenColumns();
1464 hasHiddenColumns = false;
1467 public void showAllHiddenSeqs()
1469 if (alignment.getHiddenSequences().getSize() > 0)
1471 if (selectionGroup == null)
1473 selectionGroup = new SequenceGroup();
1474 selectionGroup.setEndRes(alignment.getWidth() - 1);
1476 Vector tmp = alignment.getHiddenSequences().showAll(
1477 hiddenRepSequences);
1478 for (int t = 0; t < tmp.size(); t++)
1480 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1482 firePropertyChange("alignment", null, alignment.getSequences());
1484 hasHiddenRows = false;
1485 hiddenRepSequences = null;
1489 public void invertColumnSelection()
1491 colSel.invertColumnSelection(0, alignment.getWidth());
1494 public int adjustForHiddenSeqs(int alignmentIndex)
1496 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1501 * This method returns an array of new SequenceI objects derived from the
1502 * whole alignment or just the current selection with start and end points
1505 * @note if you need references to the actual SequenceI objects in the
1506 * alignment or currently selected then use getSequenceSelection()
1507 * @return selection as new sequenceI objects
1509 public SequenceI[] getSelectionAsNewSequence()
1511 SequenceI[] sequences;
1513 if (selectionGroup == null)
1515 sequences = alignment.getSequencesArray();
1516 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1517 for (int i = 0; i < sequences.length; i++)
1519 sequences[i] = new Sequence(sequences[i], annots); // construct new
1521 // subset of visible
1527 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1534 * get the currently selected sequence objects or all the sequences in the
1537 * @return array of references to sequence objects
1539 public SequenceI[] getSequenceSelection()
1541 SequenceI[] sequences = null;
1542 if (selectionGroup != null)
1544 sequences = selectionGroup.getSequencesInOrder(alignment);
1546 if (sequences == null)
1548 sequences = alignment.getSequencesArray();
1554 * This method returns the visible alignment as text, as seen on the GUI, ie
1555 * if columns are hidden they will not be returned in the result. Use this for
1556 * calculating trees, PCA, redundancy etc on views which contain hidden
1561 public jalview.datamodel.CigarArray getViewAsCigars(
1562 boolean selectedRegionOnly)
1564 CigarArray selection = null;
1565 SequenceI[] seqs = null;
1567 int start = 0, end = 0;
1568 if (selectedRegionOnly && selectionGroup != null)
1570 iSize = selectionGroup.getSize();
1571 seqs = selectionGroup.getSequencesInOrder(alignment);
1572 start = selectionGroup.getStartRes();
1573 end = selectionGroup.getEndRes(); // inclusive for start and end in
1574 // SeqCigar constructor
1578 iSize = alignment.getHeight();
1579 seqs = alignment.getSequencesArray();
1580 end = alignment.getWidth() - 1;
1582 SeqCigar[] selseqs = new SeqCigar[iSize];
1583 for (i = 0; i < iSize; i++)
1585 selseqs[i] = new SeqCigar(seqs[i], start, end);
1587 selection = new CigarArray(selseqs);
1588 // now construct the CigarArray operations
1589 if (hasHiddenColumns)
1591 Vector regions = colSel.getHiddenColumns();
1593 int hideStart, hideEnd;
1595 for (int j = 0; last < end & j < regions.size(); j++)
1597 region = (int[]) regions.elementAt(j);
1598 hideStart = region[0];
1599 hideEnd = region[1];
1600 // edit hidden regions to selection range
1601 if (hideStart < last)
1613 if (hideStart > end)
1623 if (hideStart > hideEnd)
1628 * form operations...
1630 if (last < hideStart)
1632 selection.addOperation(CigarArray.M, hideStart - last);
1634 selection.addOperation(CigarArray.D, 1 + hideEnd - hideStart);
1637 // Final match if necessary.
1640 selection.addOperation(CigarArray.M, end - last + 1);
1645 selection.addOperation(CigarArray.M, end - start + 1);
1651 * return a compact representation of the current alignment selection to pass
1652 * to an analysis function
1654 * @param selectedOnly
1655 * boolean true to just return the selected view
1656 * @return AlignmentView
1658 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
1661 // this is here because the AlignmentView constructor modifies the
1663 // object. Refactoring of Cigar and alignment view representation should
1664 // be done to remove redundancy.
1665 CigarArray aligview = getViewAsCigars(selectedOnly);
1666 if (aligview != null)
1668 return new AlignmentView(aligview,
1669 (selectedOnly && selectionGroup != null) ? selectionGroup
1670 .getStartRes() : 0);
1676 * This method returns the visible alignment as text, as seen on the GUI, ie
1677 * if columns are hidden they will not be returned in the result. Use this for
1678 * calculating trees, PCA, redundancy etc on views which contain hidden
1683 public String[] getViewAsString(boolean selectedRegionOnly)
1685 String[] selection = null;
1686 SequenceI[] seqs = null;
1688 int start = 0, end = 0;
1689 if (selectedRegionOnly && selectionGroup != null)
1691 iSize = selectionGroup.getSize();
1692 seqs = selectionGroup.getSequencesInOrder(alignment);
1693 start = selectionGroup.getStartRes();
1694 end = selectionGroup.getEndRes() + 1;
1698 iSize = alignment.getHeight();
1699 seqs = alignment.getSequencesArray();
1700 end = alignment.getWidth();
1703 selection = new String[iSize];
1704 if (hasHiddenColumns)
1706 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1710 for (i = 0; i < iSize; i++)
1712 selection[i] = seqs[i].getSequenceAsString(start, end);
1719 public int[][] getVisibleRegionBoundaries(int min, int max)
1721 Vector regions = new Vector();
1727 if (hasHiddenColumns)
1731 start = colSel.adjustForHiddenColumns(start);
1734 end = colSel.getHiddenBoundaryRight(start);
1745 regions.addElement(new int[]
1748 if (hasHiddenColumns)
1750 start = colSel.adjustForHiddenColumns(end);
1751 start = colSel.getHiddenBoundaryLeft(start) + 1;
1753 } while (end < max);
1755 int[][] startEnd = new int[regions.size()][2];
1757 regions.copyInto(startEnd);
1763 public boolean getShowHiddenMarkers()
1765 return showHiddenMarkers;
1768 public void setShowHiddenMarkers(boolean show)
1770 showHiddenMarkers = show;
1773 public String getSequenceSetId()
1775 if (sequenceSetID == null)
1777 sequenceSetID = alignment.hashCode() + "";
1780 return sequenceSetID;
1784 * unique viewId for synchronizing state with stored Jalview Project
1787 private String viewId = null;
1789 public String getViewId()
1793 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1798 public void alignmentChanged(AlignmentPanel ap)
1802 alignment.padGaps();
1804 if (hconsensus != null && autoCalculateConsensus)
1806 updateConservation(ap);
1808 if (autoCalculateConsensus)
1810 updateConsensus(ap);
1813 // Reset endRes of groups if beyond alignment width
1814 int alWidth = alignment.getWidth();
1815 Vector groups = alignment.getGroups();
1818 for (int i = 0; i < groups.size(); i++)
1820 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
1821 if (sg.getEndRes() > alWidth)
1823 sg.setEndRes(alWidth - 1);
1828 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1830 selectionGroup.setEndRes(alWidth - 1);
1833 resetAllColourSchemes();
1835 // alignment.adjustSequenceAnnotations();
1838 void resetAllColourSchemes()
1840 ColourSchemeI cs = globalColourScheme;
1843 if (cs instanceof ClustalxColourScheme)
1845 ((ClustalxColourScheme) cs).resetClustalX(alignment.getSequences(),
1846 alignment.getWidth());
1849 cs.setConsensus(hconsensus);
1850 if (cs.conservationApplied())
1852 Alignment al = (Alignment) alignment;
1853 Conservation c = new Conservation("All",
1854 ResidueProperties.propHash, 3, al.getSequences(), 0, al
1857 c.verdict(false, ConsPercGaps);
1859 cs.setConservation(c);
1863 int s, sSize = alignment.getGroups().size();
1864 for (s = 0; s < sSize; s++)
1866 SequenceGroup sg = (SequenceGroup) alignment.getGroups().elementAt(s);
1867 if (sg.cs != null && sg.cs instanceof ClustalxColourScheme)
1869 ((ClustalxColourScheme) sg.cs).resetClustalX(sg
1870 .getSequences(hiddenRepSequences), sg.getWidth());
1872 sg.recalcConservation();
1876 public Color getSequenceColour(SequenceI seq)
1878 if (sequenceColours == null || !sequenceColours.containsKey(seq))
1884 return (Color) sequenceColours.get(seq);
1888 public void setSequenceColour(SequenceI seq, Color col)
1890 if (sequenceColours == null)
1892 sequenceColours = new Hashtable();
1897 sequenceColours.remove(seq);
1901 sequenceColours.put(seq, col);
1906 * returns the visible column regions of the alignment
1908 * @param selectedRegionOnly
1909 * true to just return the contigs intersecting with the selected
1913 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
1915 int[] viscontigs = null;
1916 int start = 0, end = 0;
1917 if (selectedRegionOnly && selectionGroup != null)
1919 start = selectionGroup.getStartRes();
1920 end = selectionGroup.getEndRes() + 1;
1924 end = alignment.getWidth();
1926 viscontigs = colSel.getVisibleContigs(start, end);
1931 * get hash of undo and redo list for the alignment
1933 * @return long[] { historyList.hashCode, redoList.hashCode };
1935 public long[] getUndoRedoHash()
1937 if (historyList == null || redoList == null)
1941 { historyList.hashCode(), this.redoList.hashCode() };
1945 * test if a particular set of hashcodes are different to the hashcodes for
1946 * the undo and redo list.
1949 * the stored set of hashcodes as returned by getUndoRedoHash
1950 * @return true if the hashcodes differ (ie the alignment has been edited) or
1951 * the stored hashcode array differs in size
1953 public boolean isUndoRedoHashModified(long[] undoredo)
1955 if (undoredo == null)
1959 long[] cstate = getUndoRedoHash();
1960 if (cstate.length != undoredo.length)
1965 for (int i = 0; i < cstate.length; i++)
1967 if (cstate[i] != undoredo[i])
1975 public boolean getCentreColumnLabels()
1977 return centreColumnLabels;
1980 public void setCentreColumnLabels(boolean centrecolumnlabels)
1982 centreColumnLabels = centrecolumnlabels;
1985 public void updateSequenceIdColours()
1987 Vector groups = alignment.getGroups();
1988 if (sequenceColours == null)
1990 sequenceColours = new Hashtable();
1992 for (int ig = 0, igSize = groups.size(); ig < igSize; ig++)
1994 SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
1995 if (sg.idColour != null)
1997 Vector sqs = sg.getSequences(hiddenRepSequences);
1998 for (int s = 0, sSize = sqs.size(); s < sSize; s++)
2000 sequenceColours.put(sqs.elementAt(s), sg.idColour);
2007 * enable or disable the display of Database Cross References in the sequence
2010 public void setShowDbRefs(boolean show)
2017 * @return true if Database References are to be displayed on tooltips.
2019 public boolean isShowDbRefs()
2026 * @return true if Non-positional features are to be displayed on tooltips.
2028 public boolean isShowNpFeats()
2034 * enable or disable the display of Non-Positional sequence features in the
2035 * sequence ID tooltip
2039 public void setShowNpFeats(boolean show)
2046 * @return true if view has hidden rows
2048 public boolean hasHiddenRows()
2050 return hasHiddenRows;
2055 * @return true if view has hidden columns
2057 public boolean hasHiddenColumns()
2059 return hasHiddenColumns;
2063 * when set, view will scroll to show the highlighted position
2065 public boolean followHighlight = true;
2068 * @return true if view should scroll to show the highlighted region of a
2072 public boolean getFollowHighlight()
2074 return followHighlight;
2077 public boolean followSelection = true;
2080 * @return true if view selection should always follow the selections
2081 * broadcast by other selection sources
2083 public boolean getFollowSelection()
2085 return followSelection;
2088 private long sgrouphash = -1, colselhash = -1;
2090 boolean showSeqFeaturesHeight;
2093 * checks current SelectionGroup against record of last hash value, and
2096 * @return true if SelectionGroup changed since last call
2098 boolean isSelectionGroupChanged()
2100 int hc = (selectionGroup == null) ? -1 : selectionGroup.hashCode();
2101 if (hc != sgrouphash)
2110 * checks current colsel against record of last hash value, and updates
2113 * @return true if colsel changed since last call
2115 boolean isColSelChanged()
2117 int hc = (colSel == null) ? -1 : colSel.hashCode();
2118 if (hc != colselhash)
2126 public void sendSelection()
2128 jalview.structure.StructureSelectionManager
2129 .getStructureSelectionManager().sendSelection(
2130 new SequenceGroup(getSelectionGroup()),
2131 new ColumnSelection(getColumnSelection()), this);
2134 public void setShowSequenceFeaturesHeight(boolean selected)
2136 showSeqFeaturesHeight = selected;
2139 public boolean getShowSequenceFeaturesHeight()
2141 return showSeqFeaturesHeight;
2144 boolean showUnconserved = false;
2146 public boolean getShowUnconserved()
2148 return showUnconserved;
2151 public void setShowUnconserved(boolean showunconserved)
2153 showUnconserved = showunconserved;
2157 * return the alignPanel containing the given viewport. Use this to get the
2158 * components currently handling the given viewport.
2161 * @return null or an alignPanel guaranteed to have non-null alignFrame
2164 public AlignmentPanel getAlignPanel()
2166 AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(this
2167 .getSequenceSetId());
2168 AlignmentPanel ap = null;
2169 for (int p = 0; aps != null && p < aps.length; p++)
2171 if (aps[p].av == this)
2179 public boolean getSortByTree()
2184 public void setSortByTree(boolean sort)
2190 * should conservation rows be shown for groups
2192 boolean showGroupConservation = false;
2195 * should consensus rows be shown for groups
2197 boolean showGroupConsensus = false;
2200 * should consensus profile be rendered by default
2202 public boolean showSequenceLogo = false;
2205 * should consensus histograms be rendered by default
2207 public boolean showConsensusHistogram = true;
2210 * @return the showConsensusProfile
2212 public boolean isShowSequenceLogo()
2214 return showSequenceLogo;
2218 * @param showSequenceLogo
2221 public void setShowSequenceLogo(boolean showSequenceLogo)
2223 if (showSequenceLogo != this.showSequenceLogo)
2225 // TODO: decouple settings setting from calculation when refactoring
2226 // annotation update method from alignframe to viewport
2227 this.showSequenceLogo = showSequenceLogo;
2228 if (consensusThread != null)
2230 consensusThread.updateAnnotation();
2233 this.showSequenceLogo = showSequenceLogo;
2237 * @param showConsensusHistogram
2238 * the showConsensusHistogram to set
2240 public void setShowConsensusHistogram(boolean showConsensusHistogram)
2242 this.showConsensusHistogram = showConsensusHistogram;
2246 * @return the showGroupConservation
2248 public boolean isShowGroupConservation()
2250 return showGroupConservation;
2254 * @param showGroupConservation
2255 * the showGroupConservation to set
2257 public void setShowGroupConservation(boolean showGroupConservation)
2259 this.showGroupConservation = showGroupConservation;
2263 * @return the showGroupConsensus
2265 public boolean isShowGroupConsensus()
2267 return showGroupConsensus;
2271 * @param showGroupConsensus
2272 * the showGroupConsensus to set
2274 public void setShowGroupConsensus(boolean showGroupConsensus)
2276 this.showGroupConsensus = showGroupConsensus;
2281 * @return flag to indicate if the consensus histogram should be rendered by
2284 public boolean isShowConsensusHistogram()
2286 return this.showConsensusHistogram;
2290 * synthesize a column selection if none exists so it covers the given
2291 * selection group. if wholewidth is false, no column selection is made if the
2292 * selection group covers the whole alignment width.
2297 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2301 && (sgs = sg.getStartRes()) >= 0
2302 && sg.getStartRes() <= (sge = sg.getEndRes())
2303 && (colSel == null || colSel.getSelected() == null || colSel
2304 .getSelected().size() == 0))
2306 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2313 colSel = new ColumnSelection();
2315 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2317 colSel.addElement(cspos);