2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
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 followSelection = jalview.bin.Cache.getDefault("FOLLOW_SELECTIONS",
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() : -1; // null
548 updatingConsensus = false;
549 UPDATING_CONSENSUS = false;
553 consensus.annotations = null;
554 consensus.annotations = new Annotation[aWidth];
556 hconsensus = new Hashtable[aWidth];
557 AAFrequency.calculate(alignment.getSequencesArray(), 0,
558 alignment.getWidth(), hconsensus, true);
559 updateAnnotation(true);
561 if (globalColourScheme != null)
563 globalColourScheme.setConsensus(hconsensus);
566 } catch (OutOfMemoryError error)
568 alignment.deleteAnnotation(consensus);
572 new OOMWarning("calculating consensus", error);
574 UPDATING_CONSENSUS = false;
575 updatingConsensus = false;
579 ap.paintAlignment(true);
584 * update the consensus annotation from the sequence profile data using
585 * current visualization settings.
587 public void updateAnnotation()
589 updateAnnotation(false);
592 protected void updateAnnotation(boolean immediate)
594 // TODO: make calls thread-safe, so if another thread calls this method,
595 // it will either return or wait until one calculation is finished.
597 || (!updatingConsensus && consensus != null && hconsensus != null))
599 AAFrequency.completeConsensus(consensus, hconsensus, 0,
600 hconsensus.length, ignoreGapsInConsensusCalculation,
607 * get the consensus sequence as displayed under the PID consensus annotation
610 * @return consensus sequence as a new sequence object
612 public SequenceI getConsensusSeq()
614 if (consensus == null)
616 updateConsensus(null);
618 if (consensus == null)
622 StringBuffer seqs = new StringBuffer();
623 for (int i = 0; i < consensus.annotations.length; i++)
625 if (consensus.annotations[i] != null)
627 if (consensus.annotations[i].description.charAt(0) == '[')
629 seqs.append(consensus.annotations[i].description.charAt(1));
633 seqs.append(consensus.annotations[i].displayCharacter);
638 SequenceI sq = new Sequence("Consensus", seqs.toString());
639 sq.setDescription("Percentage Identity Consensus "
640 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
647 * @return DOCUMENT ME!
649 public SequenceGroup getSelectionGroup()
651 return selectionGroup;
660 public void setSelectionGroup(SequenceGroup sg)
668 * @return DOCUMENT ME!
670 public boolean getConservationSelected()
672 return conservationColourSelected;
681 public void setConservationSelected(boolean b)
683 conservationColourSelected = b;
689 * @return DOCUMENT ME!
691 public boolean getAbovePIDThreshold()
693 return abovePIDThreshold;
702 public void setAbovePIDThreshold(boolean b)
704 abovePIDThreshold = b;
710 * @return DOCUMENT ME!
712 public int getStartRes()
720 * @return DOCUMENT ME!
722 public int getEndRes()
730 * @return DOCUMENT ME!
732 public int getStartSeq()
743 public void setGlobalColourScheme(ColourSchemeI cs)
745 globalColourScheme = cs;
751 * @return DOCUMENT ME!
753 public ColourSchemeI getGlobalColourScheme()
755 return globalColourScheme;
764 public void setStartRes(int res)
775 public void setStartSeq(int seq)
786 public void setEndRes(int res)
788 if (res > (alignment.getWidth() - 1))
790 // log.System.out.println(" Corrected res from " + res + " to maximum " +
791 // (alignment.getWidth()-1));
792 res = alignment.getWidth() - 1;
809 public void setEndSeq(int seq)
811 if (seq > alignment.getHeight())
813 seq = alignment.getHeight();
827 * @return DOCUMENT ME!
829 public int getEndSeq()
840 public void setFont(Font f)
844 Container c = new Container();
846 java.awt.FontMetrics fm = c.getFontMetrics(font);
847 setCharHeight(fm.getHeight());
848 setCharWidth(fm.charWidth('M'));
849 validCharWidth = true;
855 * @return DOCUMENT ME!
857 public Font getFont()
868 public void setCharWidth(int w)
876 * @return DOCUMENT ME!
878 public int getCharWidth()
889 public void setCharHeight(int h)
897 * @return DOCUMENT ME!
899 public int getCharHeight()
910 public void setWrappedWidth(int w)
912 this.wrappedWidth = w;
918 * @return DOCUMENT ME!
920 public int getWrappedWidth()
928 * @return DOCUMENT ME!
930 public AlignmentI getAlignment()
941 public void setAlignment(AlignmentI align)
943 if (alignment != null && alignment.getCodonFrames() != null)
945 StructureSelectionManager.getStructureSelectionManager()
946 .removeMappings(alignment.getCodonFrames());
948 this.alignment = align;
949 if (alignment.getCodonFrames() != null)
951 StructureSelectionManager.getStructureSelectionManager().addMappings(
952 alignment.getCodonFrames());
962 public void setWrapAlignment(boolean state)
964 wrapAlignment = state;
973 public void setShowText(boolean state)
984 public void setRenderGaps(boolean state)
992 * @return DOCUMENT ME!
994 public boolean getColourText()
996 return showColourText;
1005 public void setColourText(boolean state)
1007 showColourText = state;
1016 public void setShowBoxes(boolean state)
1024 * @return DOCUMENT ME!
1026 public boolean getWrapAlignment()
1028 return wrapAlignment;
1034 * @return DOCUMENT ME!
1036 public boolean getShowText()
1044 * @return DOCUMENT ME!
1046 public boolean getShowBoxes()
1054 * @return DOCUMENT ME!
1056 public char getGapCharacter()
1058 return getAlignment().getGapCharacter();
1067 public void setGapCharacter(char gap)
1069 if (getAlignment() != null)
1071 getAlignment().setGapCharacter(gap);
1081 public void setThreshold(int thresh)
1089 * @return DOCUMENT ME!
1091 public int getThreshold()
1102 public void setIncrement(int inc)
1110 * @return DOCUMENT ME!
1112 public int getIncrement()
1120 * @return DOCUMENT ME!
1122 public ColumnSelection getColumnSelection()
1133 public void setCurrentTree(NJTree tree)
1141 * @return DOCUMENT ME!
1143 public NJTree getCurrentTree()
1154 public void setColourAppliesToAllGroups(boolean b)
1156 colourAppliesToAllGroups = b;
1162 * @return DOCUMENT ME!
1164 public boolean getColourAppliesToAllGroups()
1166 return colourAppliesToAllGroups;
1172 * @return DOCUMENT ME!
1174 public boolean getShowJVSuffix()
1176 return showJVSuffix;
1185 public void setShowJVSuffix(boolean b)
1193 * @return DOCUMENT ME!
1195 public boolean getShowAnnotation()
1197 return showAnnotation;
1206 public void setShowAnnotation(boolean b)
1214 * @return DOCUMENT ME!
1216 public boolean getScaleAboveWrapped()
1218 return scaleAboveWrapped;
1224 * @return DOCUMENT ME!
1226 public boolean getScaleLeftWrapped()
1228 return scaleLeftWrapped;
1234 * @return DOCUMENT ME!
1236 public boolean getScaleRightWrapped()
1238 return scaleRightWrapped;
1247 public void setScaleAboveWrapped(boolean b)
1249 scaleAboveWrapped = b;
1258 public void setScaleLeftWrapped(boolean b)
1260 scaleLeftWrapped = b;
1269 public void setScaleRightWrapped(boolean b)
1271 scaleRightWrapped = b;
1275 * Property change listener for changes in alignment
1280 public void addPropertyChangeListener(
1281 java.beans.PropertyChangeListener listener)
1283 changeSupport.addPropertyChangeListener(listener);
1292 public void removePropertyChangeListener(
1293 java.beans.PropertyChangeListener listener)
1295 changeSupport.removePropertyChangeListener(listener);
1299 * Property change listener for changes in alignment
1308 public void firePropertyChange(String prop, Object oldvalue,
1311 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1314 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1316 ignoreGapsInConsensusCalculation = b;
1317 updateConsensus(ap);
1318 if (globalColourScheme != null)
1320 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1321 ignoreGapsInConsensusCalculation);
1325 public boolean getIgnoreGapsConsensus()
1327 return ignoreGapsInConsensusCalculation;
1330 public void setDataset(boolean b)
1335 public boolean isDataset()
1340 public void hideSelectedColumns()
1342 if (colSel.size() < 1)
1347 colSel.hideSelectedColumns();
1348 setSelectionGroup(null);
1350 hasHiddenColumns = true;
1353 public void hideColumns(int start, int end)
1357 colSel.hideColumns(start);
1361 colSel.hideColumns(start, end);
1364 hasHiddenColumns = true;
1367 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1369 int sSize = sg.getSize();
1375 if (hiddenRepSequences == null)
1377 hiddenRepSequences = new Hashtable();
1380 hiddenRepSequences.put(repSequence, sg);
1382 // Hide all sequences except the repSequence
1383 SequenceI[] seqs = new SequenceI[sSize - 1];
1385 for (int i = 0; i < sSize; i++)
1387 if (sg.getSequenceAt(i) != repSequence)
1389 if (index == sSize - 1)
1394 seqs[index++] = sg.getSequenceAt(i);
1397 sg.setSeqrep(repSequence);
1398 sg.setHidereps(true);
1403 public void hideAllSelectedSeqs()
1405 if (selectionGroup == null || selectionGroup.getSize() < 1)
1410 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1414 setSelectionGroup(null);
1417 public void hideSequence(SequenceI[] seq)
1421 for (int i = 0; i < seq.length; i++)
1423 alignment.getHiddenSequences().hideSequence(seq[i]);
1425 hasHiddenRows = true;
1426 firePropertyChange("alignment", null, alignment.getSequences());
1430 public void showSequence(int index)
1432 Vector tmp = alignment.getHiddenSequences().showSequence(index,
1433 hiddenRepSequences);
1436 if (selectionGroup == null)
1438 selectionGroup = new SequenceGroup();
1439 selectionGroup.setEndRes(alignment.getWidth() - 1);
1442 for (int t = 0; t < tmp.size(); t++)
1444 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1446 firePropertyChange("alignment", null, alignment.getSequences());
1450 if (alignment.getHiddenSequences().getSize() < 1)
1452 hasHiddenRows = false;
1456 public void showColumn(int col)
1458 colSel.revealHiddenColumns(col);
1459 if (colSel.getHiddenColumns() == null)
1461 hasHiddenColumns = false;
1465 public void showAllHiddenColumns()
1467 colSel.revealAllHiddenColumns();
1468 hasHiddenColumns = false;
1471 public void showAllHiddenSeqs()
1473 if (alignment.getHiddenSequences().getSize() > 0)
1475 if (selectionGroup == null)
1477 selectionGroup = new SequenceGroup();
1478 selectionGroup.setEndRes(alignment.getWidth() - 1);
1480 Vector tmp = alignment.getHiddenSequences().showAll(
1481 hiddenRepSequences);
1482 for (int t = 0; t < tmp.size(); t++)
1484 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1486 firePropertyChange("alignment", null, alignment.getSequences());
1488 hasHiddenRows = false;
1489 hiddenRepSequences = null;
1493 public void invertColumnSelection()
1495 colSel.invertColumnSelection(0, alignment.getWidth());
1498 public int adjustForHiddenSeqs(int alignmentIndex)
1500 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1505 * This method returns an array of new SequenceI objects derived from the
1506 * whole alignment or just the current selection with start and end points
1509 * @note if you need references to the actual SequenceI objects in the
1510 * alignment or currently selected then use getSequenceSelection()
1511 * @return selection as new sequenceI objects
1513 public SequenceI[] getSelectionAsNewSequence()
1515 SequenceI[] sequences;
1517 if (selectionGroup == null)
1519 sequences = alignment.getSequencesArray();
1520 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1521 for (int i = 0; i < sequences.length; i++)
1523 sequences[i] = new Sequence(sequences[i], annots); // construct new
1525 // subset of visible
1531 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1538 * get the currently selected sequence objects or all the sequences in the
1541 * @return array of references to sequence objects
1543 public SequenceI[] getSequenceSelection()
1545 SequenceI[] sequences = null;
1546 if (selectionGroup != null)
1548 sequences = selectionGroup.getSequencesInOrder(alignment);
1550 if (sequences == null)
1552 sequences = alignment.getSequencesArray();
1558 * This method returns the visible alignment as text, as seen on the GUI, ie
1559 * if columns are hidden they will not be returned in the result. Use this for
1560 * calculating trees, PCA, redundancy etc on views which contain hidden
1565 public jalview.datamodel.CigarArray getViewAsCigars(
1566 boolean selectedRegionOnly)
1568 return new jalview.datamodel.CigarArray(alignment, (hasHiddenColumns ? colSel : null), (selectedRegionOnly ? selectionGroup : null));
1572 * return a compact representation of the current alignment selection to pass
1573 * to an analysis function
1575 * @param selectedOnly
1576 * boolean true to just return the selected view
1577 * @return AlignmentView
1579 public jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
1581 return getAlignmentView(selectedOnly, false);
1585 * return a compact representation of the current alignment selection to pass
1586 * to an analysis function
1588 * @param selectedOnly
1589 * boolean true to just return the selected view
1591 * boolean true to annotate the alignment view with groups on the alignment (and intersecting with selected region if selectedOnly is true)
1592 * @return AlignmentView
1594 public jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly, boolean markGroups)
1596 return new AlignmentView(alignment, colSel, selectionGroup, hasHiddenColumns, selectedOnly, markGroups);
1600 * This method returns the visible alignment as text, as seen on the GUI, ie
1601 * if columns are hidden they will not be returned in the result. Use this for
1602 * calculating trees, PCA, redundancy etc on views which contain hidden
1607 public String[] getViewAsString(boolean selectedRegionOnly)
1609 String[] selection = null;
1610 SequenceI[] seqs = null;
1612 int start = 0, end = 0;
1613 if (selectedRegionOnly && selectionGroup != null)
1615 iSize = selectionGroup.getSize();
1616 seqs = selectionGroup.getSequencesInOrder(alignment);
1617 start = selectionGroup.getStartRes();
1618 end = selectionGroup.getEndRes() + 1;
1622 iSize = alignment.getHeight();
1623 seqs = alignment.getSequencesArray();
1624 end = alignment.getWidth();
1627 selection = new String[iSize];
1628 if (hasHiddenColumns)
1630 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1634 for (i = 0; i < iSize; i++)
1636 selection[i] = seqs[i].getSequenceAsString(start, end);
1643 public int[][] getVisibleRegionBoundaries(int min, int max)
1645 Vector regions = new Vector();
1651 if (hasHiddenColumns)
1655 start = colSel.adjustForHiddenColumns(start);
1658 end = colSel.getHiddenBoundaryRight(start);
1669 regions.addElement(new int[]
1672 if (hasHiddenColumns)
1674 start = colSel.adjustForHiddenColumns(end);
1675 start = colSel.getHiddenBoundaryLeft(start) + 1;
1677 } while (end < max);
1679 int[][] startEnd = new int[regions.size()][2];
1681 regions.copyInto(startEnd);
1687 public boolean getShowHiddenMarkers()
1689 return showHiddenMarkers;
1692 public void setShowHiddenMarkers(boolean show)
1694 showHiddenMarkers = show;
1697 public String getSequenceSetId()
1699 if (sequenceSetID == null)
1701 sequenceSetID = alignment.hashCode() + "";
1704 return sequenceSetID;
1708 * unique viewId for synchronizing state with stored Jalview Project
1711 private String viewId = null;
1713 public String getViewId()
1717 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1722 public void alignmentChanged(AlignmentPanel ap)
1726 alignment.padGaps();
1728 if (hconsensus != null && autoCalculateConsensus)
1730 updateConservation(ap);
1732 if (autoCalculateConsensus)
1734 updateConsensus(ap);
1737 // Reset endRes of groups if beyond alignment width
1738 int alWidth = alignment.getWidth();
1739 Vector groups = alignment.getGroups();
1742 for (int i = 0; i < groups.size(); i++)
1744 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
1745 if (sg.getEndRes() > alWidth)
1747 sg.setEndRes(alWidth - 1);
1752 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1754 selectionGroup.setEndRes(alWidth - 1);
1757 resetAllColourSchemes();
1759 // alignment.adjustSequenceAnnotations();
1762 void resetAllColourSchemes()
1764 ColourSchemeI cs = globalColourScheme;
1767 if (cs instanceof ClustalxColourScheme)
1769 ((ClustalxColourScheme) cs).resetClustalX(alignment.getSequences(),
1770 alignment.getWidth());
1773 cs.setConsensus(hconsensus);
1774 if (cs.conservationApplied())
1776 Alignment al = (Alignment) alignment;
1777 Conservation c = new Conservation("All",
1778 ResidueProperties.propHash, 3, al.getSequences(), 0,
1781 c.verdict(false, ConsPercGaps);
1783 cs.setConservation(c);
1787 int s, sSize = alignment.getGroups().size();
1788 for (s = 0; s < sSize; s++)
1790 SequenceGroup sg = (SequenceGroup) alignment.getGroups().elementAt(s);
1791 if (sg.cs != null && sg.cs instanceof ClustalxColourScheme)
1793 ((ClustalxColourScheme) sg.cs).resetClustalX(
1794 sg.getSequences(hiddenRepSequences), sg.getWidth());
1796 sg.recalcConservation();
1800 public Color getSequenceColour(SequenceI seq)
1802 if (sequenceColours == null || !sequenceColours.containsKey(seq))
1808 return (Color) sequenceColours.get(seq);
1812 public void setSequenceColour(SequenceI seq, Color col)
1814 if (sequenceColours == null)
1816 sequenceColours = new Hashtable();
1821 sequenceColours.remove(seq);
1825 sequenceColours.put(seq, col);
1830 * returns the visible column regions of the alignment
1832 * @param selectedRegionOnly
1833 * true to just return the contigs intersecting with the selected
1837 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
1839 int[] viscontigs = null;
1840 int start = 0, end = 0;
1841 if (selectedRegionOnly && selectionGroup != null)
1843 start = selectionGroup.getStartRes();
1844 end = selectionGroup.getEndRes() + 1;
1848 end = alignment.getWidth();
1850 viscontigs = colSel.getVisibleContigs(start, end);
1855 * get hash of undo and redo list for the alignment
1857 * @return long[] { historyList.hashCode, redoList.hashCode };
1859 public long[] getUndoRedoHash()
1861 if (historyList == null || redoList == null)
1865 { historyList.hashCode(), this.redoList.hashCode() };
1869 * test if a particular set of hashcodes are different to the hashcodes for
1870 * the undo and redo list.
1873 * the stored set of hashcodes as returned by getUndoRedoHash
1874 * @return true if the hashcodes differ (ie the alignment has been edited) or
1875 * the stored hashcode array differs in size
1877 public boolean isUndoRedoHashModified(long[] undoredo)
1879 if (undoredo == null)
1883 long[] cstate = getUndoRedoHash();
1884 if (cstate.length != undoredo.length)
1889 for (int i = 0; i < cstate.length; i++)
1891 if (cstate[i] != undoredo[i])
1899 public boolean getCentreColumnLabels()
1901 return centreColumnLabels;
1904 public void setCentreColumnLabels(boolean centrecolumnlabels)
1906 centreColumnLabels = centrecolumnlabels;
1909 public void updateSequenceIdColours()
1911 Vector groups = alignment.getGroups();
1912 if (sequenceColours == null)
1914 sequenceColours = new Hashtable();
1916 for (int ig = 0, igSize = groups.size(); ig < igSize; ig++)
1918 SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
1919 if (sg.idColour != null)
1921 Vector sqs = sg.getSequences(hiddenRepSequences);
1922 for (int s = 0, sSize = sqs.size(); s < sSize; s++)
1924 sequenceColours.put(sqs.elementAt(s), sg.idColour);
1931 * enable or disable the display of Database Cross References in the sequence
1934 public void setShowDbRefs(boolean show)
1941 * @return true if Database References are to be displayed on tooltips.
1943 public boolean isShowDbRefs()
1950 * @return true if Non-positional features are to be displayed on tooltips.
1952 public boolean isShowNpFeats()
1958 * enable or disable the display of Non-Positional sequence features in the
1959 * sequence ID tooltip
1963 public void setShowNpFeats(boolean show)
1970 * @return true if view has hidden rows
1972 public boolean hasHiddenRows()
1974 return hasHiddenRows;
1979 * @return true if view has hidden columns
1981 public boolean hasHiddenColumns()
1983 return hasHiddenColumns;
1987 * when set, view will scroll to show the highlighted position
1989 public boolean followHighlight = true;
1992 * @return true if view should scroll to show the highlighted region of a
1996 public boolean getFollowHighlight()
1998 return followHighlight;
2001 public boolean followSelection = true;
2004 * @return true if view selection should always follow the selections
2005 * broadcast by other selection sources
2007 public boolean getFollowSelection()
2009 return followSelection;
2012 private long sgrouphash = -1, colselhash = -1;
2014 boolean showSeqFeaturesHeight;
2017 * checks current SelectionGroup against record of last hash value, and
2020 * @return true if SelectionGroup changed since last call
2022 boolean isSelectionGroupChanged()
2024 int hc = (selectionGroup == null) ? -1 : selectionGroup.hashCode();
2025 if (hc != sgrouphash)
2034 * checks current colsel against record of last hash value, and updates
2037 * @return true if colsel changed since last call
2039 boolean isColSelChanged()
2041 int hc = (colSel == null) ? -1 : colSel.hashCode();
2042 if (hc != colselhash)
2050 public void sendSelection()
2052 jalview.structure.StructureSelectionManager
2053 .getStructureSelectionManager().sendSelection(
2054 new SequenceGroup(getSelectionGroup()),
2055 new ColumnSelection(getColumnSelection()), this);
2058 public void setShowSequenceFeaturesHeight(boolean selected)
2060 showSeqFeaturesHeight = selected;
2063 public boolean getShowSequenceFeaturesHeight()
2065 return showSeqFeaturesHeight;
2068 boolean showUnconserved = false;
2070 public boolean getShowUnconserved()
2072 return showUnconserved;
2075 public void setShowUnconserved(boolean showunconserved)
2077 showUnconserved = showunconserved;
2081 * return the alignPanel containing the given viewport. Use this to get the
2082 * components currently handling the given viewport.
2085 * @return null or an alignPanel guaranteed to have non-null alignFrame
2088 public AlignmentPanel getAlignPanel()
2090 AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(this
2091 .getSequenceSetId());
2092 AlignmentPanel ap = null;
2093 for (int p = 0; aps != null && p < aps.length; p++)
2095 if (aps[p].av == this)
2103 public boolean getSortByTree()
2108 public void setSortByTree(boolean sort)
2114 * should conservation rows be shown for groups
2116 boolean showGroupConservation = false;
2119 * should consensus rows be shown for groups
2121 boolean showGroupConsensus = false;
2124 * should consensus profile be rendered by default
2126 public boolean showSequenceLogo = false;
2129 * should consensus histograms be rendered by default
2131 public boolean showConsensusHistogram = true;
2134 * @return the showConsensusProfile
2136 public boolean isShowSequenceLogo()
2138 return showSequenceLogo;
2142 * @param showSequenceLogo
2145 public void setShowSequenceLogo(boolean showSequenceLogo)
2147 if (showSequenceLogo != this.showSequenceLogo)
2149 // TODO: decouple settings setting from calculation when refactoring
2150 // annotation update method from alignframe to viewport
2151 this.showSequenceLogo = showSequenceLogo;
2152 if (consensusThread != null)
2154 consensusThread.updateAnnotation();
2157 this.showSequenceLogo = showSequenceLogo;
2161 * @param showConsensusHistogram
2162 * the showConsensusHistogram to set
2164 public void setShowConsensusHistogram(boolean showConsensusHistogram)
2166 this.showConsensusHistogram = showConsensusHistogram;
2170 * @return the showGroupConservation
2172 public boolean isShowGroupConservation()
2174 return showGroupConservation;
2178 * @param showGroupConservation
2179 * the showGroupConservation to set
2181 public void setShowGroupConservation(boolean showGroupConservation)
2183 this.showGroupConservation = showGroupConservation;
2187 * @return the showGroupConsensus
2189 public boolean isShowGroupConsensus()
2191 return showGroupConsensus;
2195 * @param showGroupConsensus
2196 * the showGroupConsensus to set
2198 public void setShowGroupConsensus(boolean showGroupConsensus)
2200 this.showGroupConsensus = showGroupConsensus;
2205 * @return flag to indicate if the consensus histogram should be rendered by
2208 public boolean isShowConsensusHistogram()
2210 return this.showConsensusHistogram;
2214 * synthesize a column selection if none exists so it covers the given
2215 * selection group. if wholewidth is false, no column selection is made if the
2216 * selection group covers the whole alignment width.
2221 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2225 && (sgs = sg.getStartRes()) >= 0
2226 && sg.getStartRes() <= (sge = sg.getEndRes())
2227 && (colSel == null || colSel.getSelected() == null || colSel
2228 .getSelected().size() == 0))
2230 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2237 colSel = new ColumnSelection();
2239 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2241 colSel.addElement(cspos);