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;
51 import jalview.structure.VamsasSource;
59 public class AlignViewport implements SelectionSource, VamsasSource
61 private static final int RIGHT_JUSTIFY = 1;
71 boolean showJVSuffix = true;
73 boolean showText = true;
75 boolean showColourText = false;
77 boolean showBoxes = true;
79 boolean wrapAlignment = false;
81 boolean renderGaps = true;
83 boolean showSequenceFeatures = false;
85 boolean showAnnotation = true;
87 boolean colourAppliesToAllGroups = true;
89 ColourSchemeI globalColourScheme = null;
91 boolean conservationColourSelected = false;
93 boolean abovePIDThreshold = false;
95 SequenceGroup selectionGroup;
101 boolean validCharWidth;
107 boolean seqNameItalics;
109 AlignmentI alignment;
111 ColumnSelection colSel = new ColumnSelection();
117 NJTree currentTree = null;
119 boolean scaleAboveWrapped = false;
121 boolean scaleLeftWrapped = true;
123 boolean scaleRightWrapped = true;
125 boolean hasHiddenColumns = false;
127 boolean hasHiddenRows = false;
129 boolean showHiddenMarkers = true;
131 boolean cursorMode = false;
134 * Keys are the feature types which are currently visible. Note: Values are
137 Hashtable featuresDisplayed = null;
140 public Hashtable[] hconsensus;
142 AlignmentAnnotation consensus;
144 AlignmentAnnotation conservation;
146 AlignmentAnnotation quality;
148 AlignmentAnnotation[] groupConsensus;
150 AlignmentAnnotation[] groupConservation;
152 boolean autoCalculateConsensus = true;
155 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
157 // JBPNote Prolly only need this in the applet version.
158 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
161 boolean ignoreGapsInConsensusCalculation = false;
163 boolean isDataset = false;
165 boolean antiAlias = false;
167 boolean padGaps = false;
169 Rectangle explodedPosition;
173 String sequenceSetID;
175 boolean gatherViewsHere = false;
177 Stack historyList = new Stack();
179 Stack redoList = new Stack();
181 Hashtable sequenceColours;
183 int thresholdTextColour = 0;
185 Color textColour = Color.black;
187 Color textColour2 = Color.white;
189 boolean rightAlignIds = false;
191 Hashtable hiddenRepSequences;
196 * Creates a new AlignViewport object.
201 public AlignViewport(AlignmentI al)
208 * Create a new AlignViewport object with a specific sequence set ID
212 * (may be null - but potential for ambiguous constructor exception)
214 public AlignViewport(AlignmentI al, String seqsetid)
216 this(al, seqsetid, null);
219 public AlignViewport(AlignmentI al, String seqsetid, String viewid)
221 sequenceSetID = seqsetid;
223 // TODO remove these once 2.4.VAMSAS release finished
224 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
226 Cache.log.debug("Setting viewport's sequence set id : "
229 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
231 Cache.log.debug("Setting viewport's view id : " + viewId);
238 * Create a new AlignViewport with hidden regions
242 * @param hiddenColumns
245 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns)
248 if (hiddenColumns != null)
250 this.colSel = hiddenColumns;
251 if (hiddenColumns.getHiddenColumns() != null
252 && hiddenColumns.getHiddenColumns().size() > 0)
254 hasHiddenColumns = true;
258 hasHiddenColumns = false;
265 * New viewport with hidden columns and an existing sequence set id
268 * @param hiddenColumns
272 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
275 this(al, hiddenColumns, seqsetid, null);
279 * New viewport with hidden columns and an existing sequence set id and viewid
282 * @param hiddenColumns
288 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
289 String seqsetid, String viewid)
291 sequenceSetID = seqsetid;
293 // TODO remove these once 2.4.VAMSAS release finished
294 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
296 Cache.log.debug("Setting viewport's sequence set id : "
299 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
301 Cache.log.debug("Setting viewport's view id : " + viewId);
304 if (hiddenColumns != null)
306 this.colSel = hiddenColumns;
307 if (hiddenColumns.getHiddenColumns() != null
308 && hiddenColumns.getHiddenColumns().size() > 0)
310 hasHiddenColumns = true;
314 hasHiddenColumns = false;
323 this.endRes = alignment.getWidth() - 1;
325 this.endSeq = alignment.getHeight() - 1;
327 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
329 showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
330 showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
332 rightAlignIds = Cache.getDefault("RIGHT_ALIGN_IDS", false);
333 centreColumnLabels = Cache.getDefault("CENTRE_COLUMN_LABELS", false);
334 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
336 padGaps = Cache.getDefault("PAD_GAPS", true);
337 shownpfeats = Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true);
338 showdbrefs = Cache.getDefault("SHOW_DBREFS_TOOLTIP", true);
340 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
341 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
342 String fontSize = Cache.getDefault("FONT_SIZE", "10");
344 seqNameItalics = Cache.getDefault("ID_ITALICS", true);
348 if (fontStyle.equals("bold"))
352 else if (fontStyle.equals("italic"))
357 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
360 .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
362 // We must set conservation and consensus before setting colour,
363 // as Blosum and Clustal require this to be done
364 if (hconsensus == null && !isDataset)
366 if (!alignment.isNucleotide())
368 conservation = new AlignmentAnnotation("Conservation",
369 "Conservation of total alignment less than " + ConsPercGaps
370 + "% gaps", new Annotation[1], 0f, 11f,
371 AlignmentAnnotation.BAR_GRAPH);
372 conservation.hasText = true;
373 conservation.autoCalculated = true;
375 if (Cache.getDefault("SHOW_CONSERVATION", true))
377 alignment.addAnnotation(conservation);
380 if (Cache.getDefault("SHOW_QUALITY", true))
382 quality = new AlignmentAnnotation("Quality",
383 "Alignment Quality based on Blosum62 scores",
384 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
385 quality.hasText = true;
386 quality.autoCalculated = true;
388 alignment.addAnnotation(quality);
390 showGroupConservation = Cache.getDefault("SHOW_GROUP_CONSERVATION",
397 showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",
399 showSequenceLogo = Cache.getDefault("SHOW_CONSENSUS_LOGO", false);
400 showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
401 // TODO: add menu option action that nulls or creates consensus object
402 // depending on if the user wants to see the annotation or not in a
403 // specific alignment
404 consensus = new AlignmentAnnotation("Consensus", "PID",
405 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
406 consensus.hasText = true;
407 consensus.autoCalculated = true;
409 if (Cache.getDefault("SHOW_IDENTITY", true))
411 alignment.addAnnotation(consensus);
415 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
417 globalColourScheme = ColourSchemeProperty.getColour(alignment,
418 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
420 if (globalColourScheme instanceof UserColourScheme)
422 globalColourScheme = UserDefinedColours.loadDefaultColours();
423 ((UserColourScheme) globalColourScheme).setThreshold(0,
424 getIgnoreGapsConsensus());
427 if (globalColourScheme != null)
429 globalColourScheme.setConsensus(hconsensus);
433 wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false);
434 showUnconserved = jalview.bin.Cache.getDefault("SHOW_UNCONSERVED",
436 sortByTree = jalview.bin.Cache.getDefault("SORT_BY_TREE", false);
437 followSelection = jalview.bin.Cache.getDefault("FOLLOW_SELECTIONS",
445 * features are displayed if true
447 public void setShowSequenceFeatures(boolean b)
449 showSequenceFeatures = b;
452 public boolean getShowSequenceFeatures()
454 return showSequenceFeatures;
457 ConservationThread conservationThread;
459 ConsensusThread consensusThread;
461 boolean consUpdateNeeded = false;
463 static boolean UPDATING_CONSENSUS = false;
465 static boolean UPDATING_CONSERVATION = false;
467 boolean updatingConsensus = false;
469 boolean updatingConservation = false;
472 * centre columnar annotation labels in displayed alignment annotation TODO:
473 * add to jalviewXML and annotation display settings
475 boolean centreColumnLabels = false;
477 private boolean showdbrefs;
479 private boolean shownpfeats;
482 * trigger update of conservation annotation
484 public void updateConservation(final AlignmentPanel ap)
486 // see note in mantis : issue number 8585
487 if (alignment.isNucleotide() || conservation == null
488 || !autoCalculateConsensus)
493 conservationThread = new ConservationThread(this, ap);
494 conservationThread.start();
498 * trigger update of consensus annotation
500 public void updateConsensus(final AlignmentPanel ap)
502 // see note in mantis : issue number 8585
503 if (consensus == null || !autoCalculateConsensus)
507 consensusThread = new ConsensusThread(ap);
508 consensusThread.start();
511 class ConsensusThread extends Thread
515 public ConsensusThread(AlignmentPanel ap)
522 updatingConsensus = true;
523 while (UPDATING_CONSENSUS)
529 ap.paintAlignment(false);
533 } catch (Exception ex)
535 ex.printStackTrace();
539 UPDATING_CONSENSUS = true;
543 int aWidth = (alignment != null) ? alignment.getWidth() : -1; // null
549 updatingConsensus = false;
550 UPDATING_CONSENSUS = false;
554 consensus.annotations = null;
555 consensus.annotations = new Annotation[aWidth];
557 hconsensus = new Hashtable[aWidth];
558 AAFrequency.calculate(alignment.getSequencesArray(), 0,
559 alignment.getWidth(), hconsensus, true);
560 updateAnnotation(true);
562 if (globalColourScheme != null)
564 globalColourScheme.setConsensus(hconsensus);
567 } catch (OutOfMemoryError error)
569 alignment.deleteAnnotation(consensus);
573 new OOMWarning("calculating consensus", error);
575 UPDATING_CONSENSUS = false;
576 updatingConsensus = false;
580 ap.paintAlignment(true);
585 * update the consensus annotation from the sequence profile data using
586 * current visualization settings.
588 public void updateAnnotation()
590 updateAnnotation(false);
593 protected void updateAnnotation(boolean immediate)
595 // TODO: make calls thread-safe, so if another thread calls this method,
596 // it will either return or wait until one calculation is finished.
598 || (!updatingConsensus && consensus != null && hconsensus != null))
600 AAFrequency.completeConsensus(consensus, hconsensus, 0,
601 hconsensus.length, ignoreGapsInConsensusCalculation,
608 * get the consensus sequence as displayed under the PID consensus annotation
611 * @return consensus sequence as a new sequence object
613 public SequenceI getConsensusSeq()
615 if (consensus == null)
617 updateConsensus(null);
619 if (consensus == null)
623 StringBuffer seqs = new StringBuffer();
624 for (int i = 0; i < consensus.annotations.length; i++)
626 if (consensus.annotations[i] != null)
628 if (consensus.annotations[i].description.charAt(0) == '[')
630 seqs.append(consensus.annotations[i].description.charAt(1));
634 seqs.append(consensus.annotations[i].displayCharacter);
639 SequenceI sq = new Sequence("Consensus", seqs.toString());
640 sq.setDescription("Percentage Identity Consensus "
641 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
648 * @return DOCUMENT ME!
650 public SequenceGroup getSelectionGroup()
652 return selectionGroup;
661 public void setSelectionGroup(SequenceGroup sg)
669 * @return DOCUMENT ME!
671 public boolean getConservationSelected()
673 return conservationColourSelected;
682 public void setConservationSelected(boolean b)
684 conservationColourSelected = b;
690 * @return DOCUMENT ME!
692 public boolean getAbovePIDThreshold()
694 return abovePIDThreshold;
703 public void setAbovePIDThreshold(boolean b)
705 abovePIDThreshold = b;
711 * @return DOCUMENT ME!
713 public int getStartRes()
721 * @return DOCUMENT ME!
723 public int getEndRes()
731 * @return DOCUMENT ME!
733 public int getStartSeq()
744 public void setGlobalColourScheme(ColourSchemeI cs)
746 globalColourScheme = cs;
752 * @return DOCUMENT ME!
754 public ColourSchemeI getGlobalColourScheme()
756 return globalColourScheme;
765 public void setStartRes(int res)
776 public void setStartSeq(int seq)
787 public void setEndRes(int res)
789 if (res > (alignment.getWidth() - 1))
791 // log.System.out.println(" Corrected res from " + res + " to maximum " +
792 // (alignment.getWidth()-1));
793 res = alignment.getWidth() - 1;
810 public void setEndSeq(int seq)
812 if (seq > alignment.getHeight())
814 seq = alignment.getHeight();
828 * @return DOCUMENT ME!
830 public int getEndSeq()
841 public void setFont(Font f)
845 Container c = new Container();
847 java.awt.FontMetrics fm = c.getFontMetrics(font);
848 setCharHeight(fm.getHeight());
849 setCharWidth(fm.charWidth('M'));
850 validCharWidth = true;
856 * @return DOCUMENT ME!
858 public Font getFont()
869 public void setCharWidth(int w)
877 * @return DOCUMENT ME!
879 public int getCharWidth()
890 public void setCharHeight(int h)
898 * @return DOCUMENT ME!
900 public int getCharHeight()
911 public void setWrappedWidth(int w)
913 this.wrappedWidth = w;
919 * @return DOCUMENT ME!
921 public int getWrappedWidth()
929 * @return DOCUMENT ME!
931 public AlignmentI getAlignment()
942 public void setAlignment(AlignmentI align)
944 if (alignment != null && alignment.getCodonFrames() != null)
946 StructureSelectionManager.getStructureSelectionManager()
947 .removeMappings(alignment.getCodonFrames());
949 this.alignment = align;
950 if (alignment.getCodonFrames() != null)
952 StructureSelectionManager.getStructureSelectionManager().addMappings(
953 alignment.getCodonFrames());
963 public void setWrapAlignment(boolean state)
965 wrapAlignment = state;
974 public void setShowText(boolean state)
985 public void setRenderGaps(boolean state)
993 * @return DOCUMENT ME!
995 public boolean getColourText()
997 return showColourText;
1006 public void setColourText(boolean state)
1008 showColourText = state;
1017 public void setShowBoxes(boolean state)
1025 * @return DOCUMENT ME!
1027 public boolean getWrapAlignment()
1029 return wrapAlignment;
1035 * @return DOCUMENT ME!
1037 public boolean getShowText()
1045 * @return DOCUMENT ME!
1047 public boolean getShowBoxes()
1055 * @return DOCUMENT ME!
1057 public char getGapCharacter()
1059 return getAlignment().getGapCharacter();
1068 public void setGapCharacter(char gap)
1070 if (getAlignment() != null)
1072 getAlignment().setGapCharacter(gap);
1082 public void setThreshold(int thresh)
1090 * @return DOCUMENT ME!
1092 public int getThreshold()
1103 public void setIncrement(int inc)
1111 * @return DOCUMENT ME!
1113 public int getIncrement()
1121 * @return DOCUMENT ME!
1123 public ColumnSelection getColumnSelection()
1134 public void setCurrentTree(NJTree tree)
1142 * @return DOCUMENT ME!
1144 public NJTree getCurrentTree()
1155 public void setColourAppliesToAllGroups(boolean b)
1157 colourAppliesToAllGroups = b;
1163 * @return DOCUMENT ME!
1165 public boolean getColourAppliesToAllGroups()
1167 return colourAppliesToAllGroups;
1173 * @return DOCUMENT ME!
1175 public boolean getShowJVSuffix()
1177 return showJVSuffix;
1186 public void setShowJVSuffix(boolean b)
1194 * @return DOCUMENT ME!
1196 public boolean getShowAnnotation()
1198 return showAnnotation;
1207 public void setShowAnnotation(boolean b)
1215 * @return DOCUMENT ME!
1217 public boolean getScaleAboveWrapped()
1219 return scaleAboveWrapped;
1225 * @return DOCUMENT ME!
1227 public boolean getScaleLeftWrapped()
1229 return scaleLeftWrapped;
1235 * @return DOCUMENT ME!
1237 public boolean getScaleRightWrapped()
1239 return scaleRightWrapped;
1248 public void setScaleAboveWrapped(boolean b)
1250 scaleAboveWrapped = b;
1259 public void setScaleLeftWrapped(boolean b)
1261 scaleLeftWrapped = b;
1270 public void setScaleRightWrapped(boolean b)
1272 scaleRightWrapped = b;
1276 * Property change listener for changes in alignment
1281 public void addPropertyChangeListener(
1282 java.beans.PropertyChangeListener listener)
1284 changeSupport.addPropertyChangeListener(listener);
1293 public void removePropertyChangeListener(
1294 java.beans.PropertyChangeListener listener)
1296 changeSupport.removePropertyChangeListener(listener);
1300 * Property change listener for changes in alignment
1309 public void firePropertyChange(String prop, Object oldvalue,
1312 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1315 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1317 ignoreGapsInConsensusCalculation = b;
1318 updateConsensus(ap);
1319 if (globalColourScheme != null)
1321 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1322 ignoreGapsInConsensusCalculation);
1326 public boolean getIgnoreGapsConsensus()
1328 return ignoreGapsInConsensusCalculation;
1331 public void setDataset(boolean b)
1336 public boolean isDataset()
1341 public void hideSelectedColumns()
1343 if (colSel.size() < 1)
1348 colSel.hideSelectedColumns();
1349 setSelectionGroup(null);
1351 hasHiddenColumns = true;
1354 public void hideColumns(int start, int end)
1358 colSel.hideColumns(start);
1362 colSel.hideColumns(start, end);
1365 hasHiddenColumns = true;
1368 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1370 int sSize = sg.getSize();
1376 if (hiddenRepSequences == null)
1378 hiddenRepSequences = new Hashtable();
1381 hiddenRepSequences.put(repSequence, sg);
1383 // Hide all sequences except the repSequence
1384 SequenceI[] seqs = new SequenceI[sSize - 1];
1386 for (int i = 0; i < sSize; i++)
1388 if (sg.getSequenceAt(i) != repSequence)
1390 if (index == sSize - 1)
1395 seqs[index++] = sg.getSequenceAt(i);
1398 sg.setSeqrep(repSequence);
1399 sg.setHidereps(true);
1404 public void hideAllSelectedSeqs()
1406 if (selectionGroup == null || selectionGroup.getSize() < 1)
1411 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1415 setSelectionGroup(null);
1418 public void hideSequence(SequenceI[] seq)
1422 for (int i = 0; i < seq.length; i++)
1424 alignment.getHiddenSequences().hideSequence(seq[i]);
1426 hasHiddenRows = true;
1427 firePropertyChange("alignment", null, alignment.getSequences());
1431 public void showSequence(int index)
1433 Vector tmp = alignment.getHiddenSequences().showSequence(index,
1434 hiddenRepSequences);
1437 if (selectionGroup == null)
1439 selectionGroup = new SequenceGroup();
1440 selectionGroup.setEndRes(alignment.getWidth() - 1);
1443 for (int t = 0; t < tmp.size(); t++)
1445 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1447 firePropertyChange("alignment", null, alignment.getSequences());
1451 if (alignment.getHiddenSequences().getSize() < 1)
1453 hasHiddenRows = false;
1457 public void showColumn(int col)
1459 colSel.revealHiddenColumns(col);
1460 if (colSel.getHiddenColumns() == null)
1462 hasHiddenColumns = false;
1466 public void showAllHiddenColumns()
1468 colSel.revealAllHiddenColumns();
1469 hasHiddenColumns = false;
1472 public void showAllHiddenSeqs()
1474 if (alignment.getHiddenSequences().getSize() > 0)
1476 if (selectionGroup == null)
1478 selectionGroup = new SequenceGroup();
1479 selectionGroup.setEndRes(alignment.getWidth() - 1);
1481 Vector tmp = alignment.getHiddenSequences().showAll(
1482 hiddenRepSequences);
1483 for (int t = 0; t < tmp.size(); t++)
1485 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1487 firePropertyChange("alignment", null, alignment.getSequences());
1489 hasHiddenRows = false;
1490 hiddenRepSequences = null;
1494 public void invertColumnSelection()
1496 colSel.invertColumnSelection(0, alignment.getWidth());
1499 public int adjustForHiddenSeqs(int alignmentIndex)
1501 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1506 * This method returns an array of new SequenceI objects derived from the
1507 * whole alignment or just the current selection with start and end points
1510 * @note if you need references to the actual SequenceI objects in the
1511 * alignment or currently selected then use getSequenceSelection()
1512 * @return selection as new sequenceI objects
1514 public SequenceI[] getSelectionAsNewSequence()
1516 SequenceI[] sequences;
1518 if (selectionGroup == null)
1520 sequences = alignment.getSequencesArray();
1521 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1522 for (int i = 0; i < sequences.length; i++)
1524 sequences[i] = new Sequence(sequences[i], annots); // construct new
1526 // subset of visible
1532 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1539 * get the currently selected sequence objects or all the sequences in the
1542 * @return array of references to sequence objects
1544 public SequenceI[] getSequenceSelection()
1546 SequenceI[] sequences = null;
1547 if (selectionGroup != null)
1549 sequences = selectionGroup.getSequencesInOrder(alignment);
1551 if (sequences == null)
1553 sequences = alignment.getSequencesArray();
1559 * This method returns the visible alignment as text, as seen on the GUI, ie
1560 * if columns are hidden they will not be returned in the result. Use this for
1561 * calculating trees, PCA, redundancy etc on views which contain hidden
1566 public jalview.datamodel.CigarArray getViewAsCigars(
1567 boolean selectedRegionOnly)
1569 return new jalview.datamodel.CigarArray(alignment, (hasHiddenColumns ? colSel : null), (selectedRegionOnly ? selectionGroup : null));
1573 * return a compact representation of the current alignment selection to pass
1574 * to an analysis function
1576 * @param selectedOnly
1577 * boolean true to just return the selected view
1578 * @return AlignmentView
1580 public jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
1582 return getAlignmentView(selectedOnly, false);
1586 * return a compact representation of the current alignment selection to pass
1587 * to an analysis function
1589 * @param selectedOnly
1590 * boolean true to just return the selected view
1592 * boolean true to annotate the alignment view with groups on the alignment (and intersecting with selected region if selectedOnly is true)
1593 * @return AlignmentView
1595 public jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly, boolean markGroups)
1597 return new AlignmentView(alignment, colSel, selectionGroup, hasHiddenColumns, selectedOnly, markGroups);
1601 * This method returns the visible alignment as text, as seen on the GUI, ie
1602 * if columns are hidden they will not be returned in the result. Use this for
1603 * calculating trees, PCA, redundancy etc on views which contain hidden
1608 public String[] getViewAsString(boolean selectedRegionOnly)
1610 String[] selection = null;
1611 SequenceI[] seqs = null;
1613 int start = 0, end = 0;
1614 if (selectedRegionOnly && selectionGroup != null)
1616 iSize = selectionGroup.getSize();
1617 seqs = selectionGroup.getSequencesInOrder(alignment);
1618 start = selectionGroup.getStartRes();
1619 end = selectionGroup.getEndRes() + 1;
1623 iSize = alignment.getHeight();
1624 seqs = alignment.getSequencesArray();
1625 end = alignment.getWidth();
1628 selection = new String[iSize];
1629 if (hasHiddenColumns)
1631 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1635 for (i = 0; i < iSize; i++)
1637 selection[i] = seqs[i].getSequenceAsString(start, end);
1644 public int[][] getVisibleRegionBoundaries(int min, int max)
1646 Vector regions = new Vector();
1652 if (hasHiddenColumns)
1656 start = colSel.adjustForHiddenColumns(start);
1659 end = colSel.getHiddenBoundaryRight(start);
1670 regions.addElement(new int[]
1673 if (hasHiddenColumns)
1675 start = colSel.adjustForHiddenColumns(end);
1676 start = colSel.getHiddenBoundaryLeft(start) + 1;
1678 } while (end < max);
1680 int[][] startEnd = new int[regions.size()][2];
1682 regions.copyInto(startEnd);
1688 public boolean getShowHiddenMarkers()
1690 return showHiddenMarkers;
1693 public void setShowHiddenMarkers(boolean show)
1695 showHiddenMarkers = show;
1698 public String getSequenceSetId()
1700 if (sequenceSetID == null)
1702 sequenceSetID = alignment.hashCode() + "";
1705 return sequenceSetID;
1709 * unique viewId for synchronizing state with stored Jalview Project
1712 private String viewId = null;
1714 public String getViewId()
1718 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1723 public void alignmentChanged(AlignmentPanel ap)
1727 alignment.padGaps();
1729 if (hconsensus != null && autoCalculateConsensus)
1731 updateConservation(ap);
1733 if (autoCalculateConsensus)
1735 updateConsensus(ap);
1738 // Reset endRes of groups if beyond alignment width
1739 int alWidth = alignment.getWidth();
1740 Vector groups = alignment.getGroups();
1743 for (int i = 0; i < groups.size(); i++)
1745 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
1746 if (sg.getEndRes() > alWidth)
1748 sg.setEndRes(alWidth - 1);
1753 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1755 selectionGroup.setEndRes(alWidth - 1);
1758 resetAllColourSchemes();
1760 // alignment.adjustSequenceAnnotations();
1763 void resetAllColourSchemes()
1765 ColourSchemeI cs = globalColourScheme;
1768 if (cs instanceof ClustalxColourScheme)
1770 ((ClustalxColourScheme) cs).resetClustalX(alignment.getSequences(),
1771 alignment.getWidth());
1774 cs.setConsensus(hconsensus);
1775 if (cs.conservationApplied())
1777 Alignment al = (Alignment) alignment;
1778 Conservation c = new Conservation("All",
1779 ResidueProperties.propHash, 3, al.getSequences(), 0,
1782 c.verdict(false, ConsPercGaps);
1784 cs.setConservation(c);
1788 int s, sSize = alignment.getGroups().size();
1789 for (s = 0; s < sSize; s++)
1791 SequenceGroup sg = (SequenceGroup) alignment.getGroups().elementAt(s);
1792 if (sg.cs != null && sg.cs instanceof ClustalxColourScheme)
1794 ((ClustalxColourScheme) sg.cs).resetClustalX(
1795 sg.getSequences(hiddenRepSequences), sg.getWidth());
1797 sg.recalcConservation();
1801 public Color getSequenceColour(SequenceI seq)
1803 if (sequenceColours == null || !sequenceColours.containsKey(seq))
1809 return (Color) sequenceColours.get(seq);
1813 public void setSequenceColour(SequenceI seq, Color col)
1815 if (sequenceColours == null)
1817 sequenceColours = new Hashtable();
1822 sequenceColours.remove(seq);
1826 sequenceColours.put(seq, col);
1831 * returns the visible column regions of the alignment
1833 * @param selectedRegionOnly
1834 * true to just return the contigs intersecting with the selected
1838 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
1840 int[] viscontigs = null;
1841 int start = 0, end = 0;
1842 if (selectedRegionOnly && selectionGroup != null)
1844 start = selectionGroup.getStartRes();
1845 end = selectionGroup.getEndRes() + 1;
1849 end = alignment.getWidth();
1851 viscontigs = colSel.getVisibleContigs(start, end);
1856 * get hash of undo and redo list for the alignment
1858 * @return long[] { historyList.hashCode, redoList.hashCode };
1860 public long[] getUndoRedoHash()
1862 if (historyList == null || redoList == null)
1866 { historyList.hashCode(), this.redoList.hashCode() };
1870 * test if a particular set of hashcodes are different to the hashcodes for
1871 * the undo and redo list.
1874 * the stored set of hashcodes as returned by getUndoRedoHash
1875 * @return true if the hashcodes differ (ie the alignment has been edited) or
1876 * the stored hashcode array differs in size
1878 public boolean isUndoRedoHashModified(long[] undoredo)
1880 if (undoredo == null)
1884 long[] cstate = getUndoRedoHash();
1885 if (cstate.length != undoredo.length)
1890 for (int i = 0; i < cstate.length; i++)
1892 if (cstate[i] != undoredo[i])
1900 public boolean getCentreColumnLabels()
1902 return centreColumnLabels;
1905 public void setCentreColumnLabels(boolean centrecolumnlabels)
1907 centreColumnLabels = centrecolumnlabels;
1910 public void updateSequenceIdColours()
1912 Vector groups = alignment.getGroups();
1913 if (sequenceColours == null)
1915 sequenceColours = new Hashtable();
1917 for (int ig = 0, igSize = groups.size(); ig < igSize; ig++)
1919 SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
1920 if (sg.idColour != null)
1922 Vector sqs = sg.getSequences(hiddenRepSequences);
1923 for (int s = 0, sSize = sqs.size(); s < sSize; s++)
1925 sequenceColours.put(sqs.elementAt(s), sg.idColour);
1932 * enable or disable the display of Database Cross References in the sequence
1935 public void setShowDbRefs(boolean show)
1942 * @return true if Database References are to be displayed on tooltips.
1944 public boolean isShowDbRefs()
1951 * @return true if Non-positional features are to be displayed on tooltips.
1953 public boolean isShowNpFeats()
1959 * enable or disable the display of Non-Positional sequence features in the
1960 * sequence ID tooltip
1964 public void setShowNpFeats(boolean show)
1971 * @return true if view has hidden rows
1973 public boolean hasHiddenRows()
1975 return hasHiddenRows;
1980 * @return true if view has hidden columns
1982 public boolean hasHiddenColumns()
1984 return hasHiddenColumns;
1988 * when set, view will scroll to show the highlighted position
1990 public boolean followHighlight = true;
1993 * @return true if view should scroll to show the highlighted region of a
1997 public boolean getFollowHighlight()
1999 return followHighlight;
2002 public boolean followSelection = true;
2005 * @return true if view selection should always follow the selections
2006 * broadcast by other selection sources
2008 public boolean getFollowSelection()
2010 return followSelection;
2013 private long sgrouphash = -1, colselhash = -1;
2015 boolean showSeqFeaturesHeight;
2018 * checks current SelectionGroup against record of last hash value, and
2021 * @return true if SelectionGroup changed since last call
2023 boolean isSelectionGroupChanged()
2025 int hc = (selectionGroup == null) ? -1 : selectionGroup.hashCode();
2026 if (hc != sgrouphash)
2035 * checks current colsel against record of last hash value, and updates
2038 * @return true if colsel changed since last call
2040 boolean isColSelChanged()
2042 int hc = (colSel == null) ? -1 : colSel.hashCode();
2043 if (hc != colselhash)
2051 public void sendSelection()
2053 jalview.structure.StructureSelectionManager
2054 .getStructureSelectionManager().sendSelection(
2055 new SequenceGroup(getSelectionGroup()),
2056 new ColumnSelection(getColumnSelection()), this);
2059 public void setShowSequenceFeaturesHeight(boolean selected)
2061 showSeqFeaturesHeight = selected;
2064 public boolean getShowSequenceFeaturesHeight()
2066 return showSeqFeaturesHeight;
2069 boolean showUnconserved = false;
2071 public boolean getShowUnconserved()
2073 return showUnconserved;
2076 public void setShowUnconserved(boolean showunconserved)
2078 showUnconserved = showunconserved;
2082 * return the alignPanel containing the given viewport. Use this to get the
2083 * components currently handling the given viewport.
2086 * @return null or an alignPanel guaranteed to have non-null alignFrame
2089 public AlignmentPanel getAlignPanel()
2091 AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(this
2092 .getSequenceSetId());
2093 AlignmentPanel ap = null;
2094 for (int p = 0; aps != null && p < aps.length; p++)
2096 if (aps[p].av == this)
2104 public boolean getSortByTree()
2109 public void setSortByTree(boolean sort)
2115 * should conservation rows be shown for groups
2117 boolean showGroupConservation = false;
2120 * should consensus rows be shown for groups
2122 boolean showGroupConsensus = false;
2125 * should consensus profile be rendered by default
2127 public boolean showSequenceLogo = false;
2130 * should consensus histograms be rendered by default
2132 public boolean showConsensusHistogram = true;
2135 * @return the showConsensusProfile
2137 public boolean isShowSequenceLogo()
2139 return showSequenceLogo;
2143 * @param showSequenceLogo
2146 public void setShowSequenceLogo(boolean showSequenceLogo)
2148 if (showSequenceLogo != this.showSequenceLogo)
2150 // TODO: decouple settings setting from calculation when refactoring
2151 // annotation update method from alignframe to viewport
2152 this.showSequenceLogo = showSequenceLogo;
2153 if (consensusThread != null)
2155 consensusThread.updateAnnotation();
2158 this.showSequenceLogo = showSequenceLogo;
2162 * @param showConsensusHistogram
2163 * the showConsensusHistogram to set
2165 public void setShowConsensusHistogram(boolean showConsensusHistogram)
2167 this.showConsensusHistogram = showConsensusHistogram;
2171 * @return the showGroupConservation
2173 public boolean isShowGroupConservation()
2175 return showGroupConservation;
2179 * @param showGroupConservation
2180 * the showGroupConservation to set
2182 public void setShowGroupConservation(boolean showGroupConservation)
2184 this.showGroupConservation = showGroupConservation;
2188 * @return the showGroupConsensus
2190 public boolean isShowGroupConsensus()
2192 return showGroupConsensus;
2196 * @param showGroupConsensus
2197 * the showGroupConsensus to set
2199 public void setShowGroupConsensus(boolean showGroupConsensus)
2201 this.showGroupConsensus = showGroupConsensus;
2206 * @return flag to indicate if the consensus histogram should be rendered by
2209 public boolean isShowConsensusHistogram()
2211 return this.showConsensusHistogram;
2215 * synthesize a column selection if none exists so it covers the given
2216 * selection group. if wholewidth is false, no column selection is made if the
2217 * selection group covers the whole alignment width.
2222 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2226 && (sgs = sg.getStartRes()) >= 0
2227 && sg.getStartRes() <= (sge = sg.getEndRes())
2228 && (colSel == null || colSel.getSelected() == null || colSel
2229 .getSelected().size() == 0))
2231 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2238 colSel = new ColumnSelection();
2240 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2242 colSel.addElement(cspos);