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 CigarArray selection = null;
1569 SequenceI[] seqs = null;
1571 int start = 0, end = 0;
1572 if (selectedRegionOnly && selectionGroup != null)
1574 iSize = selectionGroup.getSize();
1575 seqs = selectionGroup.getSequencesInOrder(alignment);
1576 start = selectionGroup.getStartRes();
1577 end = selectionGroup.getEndRes(); // inclusive for start and end in
1578 // SeqCigar constructor
1582 iSize = alignment.getHeight();
1583 seqs = alignment.getSequencesArray();
1584 end = alignment.getWidth() - 1;
1586 SeqCigar[] selseqs = new SeqCigar[iSize];
1587 for (i = 0; i < iSize; i++)
1589 selseqs[i] = new SeqCigar(seqs[i], start, end);
1591 selection = new CigarArray(selseqs);
1592 // now construct the CigarArray operations
1593 if (hasHiddenColumns)
1595 Vector regions = colSel.getHiddenColumns();
1597 int hideStart, hideEnd;
1599 for (int j = 0; last < end & j < regions.size(); j++)
1601 region = (int[]) regions.elementAt(j);
1602 hideStart = region[0];
1603 hideEnd = region[1];
1604 // edit hidden regions to selection range
1605 if (hideStart < last)
1617 if (hideStart > end)
1627 if (hideStart > hideEnd)
1632 * form operations...
1634 if (last < hideStart)
1636 selection.addOperation(CigarArray.M, hideStart - last);
1638 selection.addOperation(CigarArray.D, 1 + hideEnd - hideStart);
1641 // Final match if necessary.
1644 selection.addOperation(CigarArray.M, end - last + 1);
1649 selection.addOperation(CigarArray.M, end - start + 1);
1655 * return a compact representation of the current alignment selection to pass
1656 * to an analysis function
1658 * @param selectedOnly
1659 * boolean true to just return the selected view
1660 * @return AlignmentView
1662 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
1665 // this is here because the AlignmentView constructor modifies the
1667 // object. Refactoring of Cigar and alignment view representation should
1668 // be done to remove redundancy.
1669 CigarArray aligview = getViewAsCigars(selectedOnly);
1670 if (aligview != null)
1672 return new AlignmentView(aligview,
1673 (selectedOnly && selectionGroup != null) ? selectionGroup
1674 .getStartRes() : 0);
1680 * This method returns the visible alignment as text, as seen on the GUI, ie
1681 * if columns are hidden they will not be returned in the result. Use this for
1682 * calculating trees, PCA, redundancy etc on views which contain hidden
1687 public String[] getViewAsString(boolean selectedRegionOnly)
1689 String[] selection = null;
1690 SequenceI[] seqs = null;
1692 int start = 0, end = 0;
1693 if (selectedRegionOnly && selectionGroup != null)
1695 iSize = selectionGroup.getSize();
1696 seqs = selectionGroup.getSequencesInOrder(alignment);
1697 start = selectionGroup.getStartRes();
1698 end = selectionGroup.getEndRes() + 1;
1702 iSize = alignment.getHeight();
1703 seqs = alignment.getSequencesArray();
1704 end = alignment.getWidth();
1707 selection = new String[iSize];
1708 if (hasHiddenColumns)
1710 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1714 for (i = 0; i < iSize; i++)
1716 selection[i] = seqs[i].getSequenceAsString(start, end);
1723 public int[][] getVisibleRegionBoundaries(int min, int max)
1725 Vector regions = new Vector();
1731 if (hasHiddenColumns)
1735 start = colSel.adjustForHiddenColumns(start);
1738 end = colSel.getHiddenBoundaryRight(start);
1749 regions.addElement(new int[]
1752 if (hasHiddenColumns)
1754 start = colSel.adjustForHiddenColumns(end);
1755 start = colSel.getHiddenBoundaryLeft(start) + 1;
1757 } while (end < max);
1759 int[][] startEnd = new int[regions.size()][2];
1761 regions.copyInto(startEnd);
1767 public boolean getShowHiddenMarkers()
1769 return showHiddenMarkers;
1772 public void setShowHiddenMarkers(boolean show)
1774 showHiddenMarkers = show;
1777 public String getSequenceSetId()
1779 if (sequenceSetID == null)
1781 sequenceSetID = alignment.hashCode() + "";
1784 return sequenceSetID;
1788 * unique viewId for synchronizing state with stored Jalview Project
1791 private String viewId = null;
1793 public String getViewId()
1797 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1802 public void alignmentChanged(AlignmentPanel ap)
1806 alignment.padGaps();
1808 if (hconsensus != null && autoCalculateConsensus)
1810 updateConservation(ap);
1812 if (autoCalculateConsensus)
1814 updateConsensus(ap);
1817 // Reset endRes of groups if beyond alignment width
1818 int alWidth = alignment.getWidth();
1819 Vector groups = alignment.getGroups();
1822 for (int i = 0; i < groups.size(); i++)
1824 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
1825 if (sg.getEndRes() > alWidth)
1827 sg.setEndRes(alWidth - 1);
1832 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1834 selectionGroup.setEndRes(alWidth - 1);
1837 resetAllColourSchemes();
1839 // alignment.adjustSequenceAnnotations();
1842 void resetAllColourSchemes()
1844 ColourSchemeI cs = globalColourScheme;
1847 if (cs instanceof ClustalxColourScheme)
1849 ((ClustalxColourScheme) cs).resetClustalX(alignment.getSequences(),
1850 alignment.getWidth());
1853 cs.setConsensus(hconsensus);
1854 if (cs.conservationApplied())
1856 Alignment al = (Alignment) alignment;
1857 Conservation c = new Conservation("All",
1858 ResidueProperties.propHash, 3, al.getSequences(), 0,
1861 c.verdict(false, ConsPercGaps);
1863 cs.setConservation(c);
1867 int s, sSize = alignment.getGroups().size();
1868 for (s = 0; s < sSize; s++)
1870 SequenceGroup sg = (SequenceGroup) alignment.getGroups().elementAt(s);
1871 if (sg.cs != null && sg.cs instanceof ClustalxColourScheme)
1873 ((ClustalxColourScheme) sg.cs).resetClustalX(
1874 sg.getSequences(hiddenRepSequences), sg.getWidth());
1876 sg.recalcConservation();
1880 public Color getSequenceColour(SequenceI seq)
1882 if (sequenceColours == null || !sequenceColours.containsKey(seq))
1888 return (Color) sequenceColours.get(seq);
1892 public void setSequenceColour(SequenceI seq, Color col)
1894 if (sequenceColours == null)
1896 sequenceColours = new Hashtable();
1901 sequenceColours.remove(seq);
1905 sequenceColours.put(seq, col);
1910 * returns the visible column regions of the alignment
1912 * @param selectedRegionOnly
1913 * true to just return the contigs intersecting with the selected
1917 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
1919 int[] viscontigs = null;
1920 int start = 0, end = 0;
1921 if (selectedRegionOnly && selectionGroup != null)
1923 start = selectionGroup.getStartRes();
1924 end = selectionGroup.getEndRes() + 1;
1928 end = alignment.getWidth();
1930 viscontigs = colSel.getVisibleContigs(start, end);
1935 * get hash of undo and redo list for the alignment
1937 * @return long[] { historyList.hashCode, redoList.hashCode };
1939 public long[] getUndoRedoHash()
1941 if (historyList == null || redoList == null)
1945 { historyList.hashCode(), this.redoList.hashCode() };
1949 * test if a particular set of hashcodes are different to the hashcodes for
1950 * the undo and redo list.
1953 * the stored set of hashcodes as returned by getUndoRedoHash
1954 * @return true if the hashcodes differ (ie the alignment has been edited) or
1955 * the stored hashcode array differs in size
1957 public boolean isUndoRedoHashModified(long[] undoredo)
1959 if (undoredo == null)
1963 long[] cstate = getUndoRedoHash();
1964 if (cstate.length != undoredo.length)
1969 for (int i = 0; i < cstate.length; i++)
1971 if (cstate[i] != undoredo[i])
1979 public boolean getCentreColumnLabels()
1981 return centreColumnLabels;
1984 public void setCentreColumnLabels(boolean centrecolumnlabels)
1986 centreColumnLabels = centrecolumnlabels;
1989 public void updateSequenceIdColours()
1991 Vector groups = alignment.getGroups();
1992 if (sequenceColours == null)
1994 sequenceColours = new Hashtable();
1996 for (int ig = 0, igSize = groups.size(); ig < igSize; ig++)
1998 SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
1999 if (sg.idColour != null)
2001 Vector sqs = sg.getSequences(hiddenRepSequences);
2002 for (int s = 0, sSize = sqs.size(); s < sSize; s++)
2004 sequenceColours.put(sqs.elementAt(s), sg.idColour);
2011 * enable or disable the display of Database Cross References in the sequence
2014 public void setShowDbRefs(boolean show)
2021 * @return true if Database References are to be displayed on tooltips.
2023 public boolean isShowDbRefs()
2030 * @return true if Non-positional features are to be displayed on tooltips.
2032 public boolean isShowNpFeats()
2038 * enable or disable the display of Non-Positional sequence features in the
2039 * sequence ID tooltip
2043 public void setShowNpFeats(boolean show)
2050 * @return true if view has hidden rows
2052 public boolean hasHiddenRows()
2054 return hasHiddenRows;
2059 * @return true if view has hidden columns
2061 public boolean hasHiddenColumns()
2063 return hasHiddenColumns;
2067 * when set, view will scroll to show the highlighted position
2069 public boolean followHighlight = true;
2072 * @return true if view should scroll to show the highlighted region of a
2076 public boolean getFollowHighlight()
2078 return followHighlight;
2081 public boolean followSelection = true;
2084 * @return true if view selection should always follow the selections
2085 * broadcast by other selection sources
2087 public boolean getFollowSelection()
2089 return followSelection;
2092 private long sgrouphash = -1, colselhash = -1;
2094 boolean showSeqFeaturesHeight;
2097 * checks current SelectionGroup against record of last hash value, and
2100 * @return true if SelectionGroup changed since last call
2102 boolean isSelectionGroupChanged()
2104 int hc = (selectionGroup == null) ? -1 : selectionGroup.hashCode();
2105 if (hc != sgrouphash)
2114 * checks current colsel against record of last hash value, and updates
2117 * @return true if colsel changed since last call
2119 boolean isColSelChanged()
2121 int hc = (colSel == null) ? -1 : colSel.hashCode();
2122 if (hc != colselhash)
2130 public void sendSelection()
2132 jalview.structure.StructureSelectionManager
2133 .getStructureSelectionManager().sendSelection(
2134 new SequenceGroup(getSelectionGroup()),
2135 new ColumnSelection(getColumnSelection()), this);
2138 public void setShowSequenceFeaturesHeight(boolean selected)
2140 showSeqFeaturesHeight = selected;
2143 public boolean getShowSequenceFeaturesHeight()
2145 return showSeqFeaturesHeight;
2148 boolean showUnconserved = false;
2150 public boolean getShowUnconserved()
2152 return showUnconserved;
2155 public void setShowUnconserved(boolean showunconserved)
2157 showUnconserved = showunconserved;
2161 * return the alignPanel containing the given viewport. Use this to get the
2162 * components currently handling the given viewport.
2165 * @return null or an alignPanel guaranteed to have non-null alignFrame
2168 public AlignmentPanel getAlignPanel()
2170 AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(this
2171 .getSequenceSetId());
2172 AlignmentPanel ap = null;
2173 for (int p = 0; aps != null && p < aps.length; p++)
2175 if (aps[p].av == this)
2183 public boolean getSortByTree()
2188 public void setSortByTree(boolean sort)
2194 * should conservation rows be shown for groups
2196 boolean showGroupConservation = false;
2199 * should consensus rows be shown for groups
2201 boolean showGroupConsensus = false;
2204 * should consensus profile be rendered by default
2206 public boolean showSequenceLogo = false;
2209 * should consensus histograms be rendered by default
2211 public boolean showConsensusHistogram = true;
2214 * @return the showConsensusProfile
2216 public boolean isShowSequenceLogo()
2218 return showSequenceLogo;
2222 * @param showSequenceLogo
2225 public void setShowSequenceLogo(boolean showSequenceLogo)
2227 if (showSequenceLogo != this.showSequenceLogo)
2229 // TODO: decouple settings setting from calculation when refactoring
2230 // annotation update method from alignframe to viewport
2231 this.showSequenceLogo = showSequenceLogo;
2232 if (consensusThread != null)
2234 consensusThread.updateAnnotation();
2237 this.showSequenceLogo = showSequenceLogo;
2241 * @param showConsensusHistogram
2242 * the showConsensusHistogram to set
2244 public void setShowConsensusHistogram(boolean showConsensusHistogram)
2246 this.showConsensusHistogram = showConsensusHistogram;
2250 * @return the showGroupConservation
2252 public boolean isShowGroupConservation()
2254 return showGroupConservation;
2258 * @param showGroupConservation
2259 * the showGroupConservation to set
2261 public void setShowGroupConservation(boolean showGroupConservation)
2263 this.showGroupConservation = showGroupConservation;
2267 * @return the showGroupConsensus
2269 public boolean isShowGroupConsensus()
2271 return showGroupConsensus;
2275 * @param showGroupConsensus
2276 * the showGroupConsensus to set
2278 public void setShowGroupConsensus(boolean showGroupConsensus)
2280 this.showGroupConsensus = showGroupConsensus;
2285 * @return flag to indicate if the consensus histogram should be rendered by
2288 public boolean isShowConsensusHistogram()
2290 return this.showConsensusHistogram;
2294 * synthesize a column selection if none exists so it covers the given
2295 * selection group. if wholewidth is false, no column selection is made if the
2296 * selection group covers the whole alignment width.
2301 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2305 && (sgs = sg.getStartRes()) >= 0
2306 && sg.getStartRes() <= (sge = sg.getEndRes())
2307 && (colSel == null || colSel.getSelected() == null || colSel
2308 .getSelected().size() == 0))
2310 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2317 colSel = new ColumnSelection();
2319 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2321 colSel.addElement(cspos);