2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * Jalview - A Sequence Alignment Editor and Viewer
20 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License
24 * as published by the Free Software Foundation; either version 2
25 * of the License, or (at your option) any later version.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
42 import jalview.analysis.*;
46 import jalview.datamodel.*;
48 import jalview.schemes.*;
49 import jalview.structure.SelectionSource;
50 import jalview.structure.StructureSelectionManager;
58 public class AlignViewport implements SelectionSource
60 private static final int RIGHT_JUSTIFY = 1;
70 boolean showJVSuffix = true;
72 boolean showText = true;
74 boolean showColourText = false;
76 boolean showBoxes = true;
78 boolean wrapAlignment = false;
80 boolean renderGaps = true;
82 boolean showSequenceFeatures = false;
84 boolean showAnnotation = true;
86 boolean colourAppliesToAllGroups = true;
88 ColourSchemeI globalColourScheme = null;
90 boolean conservationColourSelected = false;
92 boolean abovePIDThreshold = false;
94 SequenceGroup selectionGroup;
100 boolean validCharWidth;
106 boolean seqNameItalics;
108 AlignmentI alignment;
110 ColumnSelection colSel = new ColumnSelection();
116 NJTree currentTree = null;
118 boolean scaleAboveWrapped = false;
120 boolean scaleLeftWrapped = true;
122 boolean scaleRightWrapped = true;
124 boolean hasHiddenColumns = false;
126 boolean hasHiddenRows = false;
128 boolean showHiddenMarkers = true;
130 boolean cursorMode = false;
133 * Keys are the feature types which are currently visible. Note: Values are
136 Hashtable featuresDisplayed = null;
139 public Hashtable[] hconsensus;
141 AlignmentAnnotation consensus;
143 AlignmentAnnotation conservation;
145 AlignmentAnnotation quality;
147 AlignmentAnnotation[] groupConsensus;
149 AlignmentAnnotation[] groupConservation;
151 boolean autoCalculateConsensus = true;
154 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
156 // JBPNote Prolly only need this in the applet version.
157 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
160 boolean ignoreGapsInConsensusCalculation = false;
162 boolean isDataset = false;
164 boolean antiAlias = false;
166 boolean padGaps = false;
168 Rectangle explodedPosition;
172 String sequenceSetID;
174 boolean gatherViewsHere = false;
176 Stack historyList = new Stack();
178 Stack redoList = new Stack();
180 Hashtable sequenceColours;
182 int thresholdTextColour = 0;
184 Color textColour = Color.black;
186 Color textColour2 = Color.white;
188 boolean rightAlignIds = false;
190 Hashtable hiddenRepSequences;
195 * Creates a new AlignViewport object.
200 public AlignViewport(AlignmentI al)
207 * Create a new AlignViewport object with a specific sequence set ID
211 * (may be null - but potential for ambiguous constructor exception)
213 public AlignViewport(AlignmentI al, String seqsetid)
215 this(al, seqsetid, null);
218 public AlignViewport(AlignmentI al, String seqsetid, String viewid)
220 sequenceSetID = seqsetid;
222 // TODO remove these once 2.4.VAMSAS release finished
223 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
225 Cache.log.debug("Setting viewport's sequence set id : "
228 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
230 Cache.log.debug("Setting viewport's view id : " + viewId);
237 * Create a new AlignViewport with hidden regions
241 * @param hiddenColumns
244 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns)
247 if (hiddenColumns != null)
249 this.colSel = hiddenColumns;
250 if (hiddenColumns.getHiddenColumns() != null
251 && hiddenColumns.getHiddenColumns().size() > 0)
253 hasHiddenColumns = true;
257 hasHiddenColumns = false;
264 * New viewport with hidden columns and an existing sequence set id
267 * @param hiddenColumns
271 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
274 this(al, hiddenColumns, seqsetid, null);
278 * New viewport with hidden columns and an existing sequence set id and viewid
281 * @param hiddenColumns
287 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
288 String seqsetid, String viewid)
290 sequenceSetID = seqsetid;
292 // TODO remove these once 2.4.VAMSAS release finished
293 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
295 Cache.log.debug("Setting viewport's sequence set id : "
298 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
300 Cache.log.debug("Setting viewport's view id : " + viewId);
303 if (hiddenColumns != null)
305 this.colSel = hiddenColumns;
306 if (hiddenColumns.getHiddenColumns() != null
307 && hiddenColumns.getHiddenColumns().size() > 0)
309 hasHiddenColumns = true;
313 hasHiddenColumns = false;
322 this.endRes = alignment.getWidth() - 1;
324 this.endSeq = alignment.getHeight() - 1;
326 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
328 showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
329 showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
331 rightAlignIds = Cache.getDefault("RIGHT_ALIGN_IDS", false);
332 centreColumnLabels = Cache.getDefault("CENTRE_COLUMN_LABELS", false);
333 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
335 padGaps = Cache.getDefault("PAD_GAPS", true);
336 shownpfeats = Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true);
337 showdbrefs = Cache.getDefault("SHOW_DBREFS_TOOLTIP", true);
339 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
340 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
341 String fontSize = Cache.getDefault("FONT_SIZE", "10");
343 seqNameItalics = Cache.getDefault("ID_ITALICS", true);
347 if (fontStyle.equals("bold"))
351 else if (fontStyle.equals("italic"))
356 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
359 .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
361 // We must set conservation and consensus before setting colour,
362 // as Blosum and Clustal require this to be done
363 if (hconsensus == null && !isDataset)
365 if (!alignment.isNucleotide())
367 conservation = new AlignmentAnnotation("Conservation",
368 "Conservation of total alignment less than " + ConsPercGaps
369 + "% gaps", new Annotation[1], 0f, 11f,
370 AlignmentAnnotation.BAR_GRAPH);
371 conservation.hasText = true;
372 conservation.autoCalculated = true;
374 if (Cache.getDefault("SHOW_CONSERVATION", true))
376 alignment.addAnnotation(conservation);
379 if (Cache.getDefault("SHOW_QUALITY", true))
381 quality = new AlignmentAnnotation("Quality",
382 "Alignment Quality based on Blosum62 scores",
383 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
384 quality.hasText = true;
385 quality.autoCalculated = true;
387 alignment.addAnnotation(quality);
389 showGroupConservation = Cache.getDefault("SHOW_GROUP_CONSERVATION",
396 showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",
398 showSequenceLogo = Cache.getDefault("SHOW_CONSENSUS_LOGO", false);
399 showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
400 // TODO: add menu option action that nulls or creates consensus object
401 // depending on if the user wants to see the annotation or not in a
402 // specific alignment
403 consensus = new AlignmentAnnotation("Consensus", "PID",
404 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
405 consensus.hasText = true;
406 consensus.autoCalculated = true;
408 if (Cache.getDefault("SHOW_IDENTITY", true))
410 alignment.addAnnotation(consensus);
414 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
416 globalColourScheme = ColourSchemeProperty.getColour(alignment,
417 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
419 if (globalColourScheme instanceof UserColourScheme)
421 globalColourScheme = UserDefinedColours.loadDefaultColours();
422 ((UserColourScheme) globalColourScheme).setThreshold(0,
423 getIgnoreGapsConsensus());
426 if (globalColourScheme != null)
428 globalColourScheme.setConsensus(hconsensus);
432 wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false);
433 showUnconserved = jalview.bin.Cache.getDefault("SHOW_UNCONSERVED",
435 sortByTree = jalview.bin.Cache.getDefault("SORT_BY_TREE", false);
436 followSelection = jalview.bin.Cache.getDefault("FOLLOW_SELECTIONS", true);
443 * features are displayed if true
445 public void setShowSequenceFeatures(boolean b)
447 showSequenceFeatures = b;
450 public boolean getShowSequenceFeatures()
452 return showSequenceFeatures;
455 ConservationThread conservationThread;
457 ConsensusThread consensusThread;
459 boolean consUpdateNeeded = false;
461 static boolean UPDATING_CONSENSUS = false;
463 static boolean UPDATING_CONSERVATION = false;
465 boolean updatingConsensus = false;
467 boolean updatingConservation = false;
470 * centre columnar annotation labels in displayed alignment annotation TODO:
471 * add to jalviewXML and annotation display settings
473 boolean centreColumnLabels = false;
475 private boolean showdbrefs;
477 private boolean shownpfeats;
480 * consensus annotation includes all percentage for all symbols in column
482 private boolean includeAllConsensusSymbols = true;
485 * trigger update of conservation annotation
487 public void updateConservation(final AlignmentPanel ap)
489 // see note in mantis : issue number 8585
490 if (alignment.isNucleotide() || conservation == null
491 || !autoCalculateConsensus)
496 conservationThread = new ConservationThread(this, ap);
497 conservationThread.start();
501 * trigger update of consensus annotation
503 public void updateConsensus(final AlignmentPanel ap)
505 // see note in mantis : issue number 8585
506 if (consensus == null || !autoCalculateConsensus)
510 consensusThread = new ConsensusThread(ap);
511 consensusThread.start();
514 class ConsensusThread extends Thread
518 public ConsensusThread(AlignmentPanel ap)
525 updatingConsensus = true;
526 while (UPDATING_CONSENSUS)
532 ap.paintAlignment(false);
536 } catch (Exception ex)
538 ex.printStackTrace();
542 UPDATING_CONSENSUS = true;
546 int aWidth = (alignment != null) ? alignment.getWidth() : 0; // null
555 consensus.annotations = null;
556 consensus.annotations = new Annotation[aWidth];
558 hconsensus = new Hashtable[aWidth];
559 AAFrequency.calculate(alignment.getSequencesArray(), 0, alignment
560 .getWidth(), hconsensus, includeAllConsensusSymbols);
561 AAFrequency.completeConsensus(consensus, hconsensus, 0, aWidth,
562 ignoreGapsInConsensusCalculation,
563 includeAllConsensusSymbols);
565 if (globalColourScheme != null)
567 globalColourScheme.setConsensus(hconsensus);
570 } catch (OutOfMemoryError error)
572 alignment.deleteAnnotation(consensus);
576 new OOMWarning("calculating consensus", error);
578 UPDATING_CONSENSUS = false;
579 updatingConsensus = false;
583 ap.paintAlignment(true);
589 * get the consensus sequence as displayed under the PID consensus annotation
592 * @return consensus sequence as a new sequence object
594 public SequenceI getConsensusSeq()
596 if (consensus == null)
598 updateConsensus(null);
600 if (consensus == null)
604 StringBuffer seqs = new StringBuffer();
605 for (int i = 0; i < consensus.annotations.length; i++)
607 if (consensus.annotations[i] != null)
609 if (consensus.annotations[i].description.charAt(0) == '[')
611 seqs.append(consensus.annotations[i].description.charAt(1));
615 seqs.append(consensus.annotations[i].displayCharacter);
620 SequenceI sq = new Sequence("Consensus", seqs.toString());
621 sq.setDescription("Percentage Identity Consensus "
622 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
629 * @return DOCUMENT ME!
631 public SequenceGroup getSelectionGroup()
633 return selectionGroup;
642 public void setSelectionGroup(SequenceGroup sg)
650 * @return DOCUMENT ME!
652 public boolean getConservationSelected()
654 return conservationColourSelected;
663 public void setConservationSelected(boolean b)
665 conservationColourSelected = b;
671 * @return DOCUMENT ME!
673 public boolean getAbovePIDThreshold()
675 return abovePIDThreshold;
684 public void setAbovePIDThreshold(boolean b)
686 abovePIDThreshold = b;
692 * @return DOCUMENT ME!
694 public int getStartRes()
702 * @return DOCUMENT ME!
704 public int getEndRes()
712 * @return DOCUMENT ME!
714 public int getStartSeq()
725 public void setGlobalColourScheme(ColourSchemeI cs)
727 globalColourScheme = cs;
733 * @return DOCUMENT ME!
735 public ColourSchemeI getGlobalColourScheme()
737 return globalColourScheme;
746 public void setStartRes(int res)
757 public void setStartSeq(int seq)
768 public void setEndRes(int res)
770 if (res > (alignment.getWidth() - 1))
772 // log.System.out.println(" Corrected res from " + res + " to maximum " +
773 // (alignment.getWidth()-1));
774 res = alignment.getWidth() - 1;
791 public void setEndSeq(int seq)
793 if (seq > alignment.getHeight())
795 seq = alignment.getHeight();
809 * @return DOCUMENT ME!
811 public int getEndSeq()
822 public void setFont(Font f)
826 Container c = new Container();
828 java.awt.FontMetrics fm = c.getFontMetrics(font);
829 setCharHeight(fm.getHeight());
830 setCharWidth(fm.charWidth('M'));
831 validCharWidth = true;
837 * @return DOCUMENT ME!
839 public Font getFont()
850 public void setCharWidth(int w)
858 * @return DOCUMENT ME!
860 public int getCharWidth()
871 public void setCharHeight(int h)
879 * @return DOCUMENT ME!
881 public int getCharHeight()
892 public void setWrappedWidth(int w)
894 this.wrappedWidth = w;
900 * @return DOCUMENT ME!
902 public int getWrappedWidth()
910 * @return DOCUMENT ME!
912 public AlignmentI getAlignment()
923 public void setAlignment(AlignmentI align)
925 if (alignment != null && alignment.getCodonFrames() != null)
927 StructureSelectionManager.getStructureSelectionManager()
928 .removeMappings(alignment.getCodonFrames());
930 this.alignment = align;
931 if (alignment.getCodonFrames() != null)
933 StructureSelectionManager.getStructureSelectionManager().addMappings(
934 alignment.getCodonFrames());
944 public void setWrapAlignment(boolean state)
946 wrapAlignment = state;
955 public void setShowText(boolean state)
966 public void setRenderGaps(boolean state)
974 * @return DOCUMENT ME!
976 public boolean getColourText()
978 return showColourText;
987 public void setColourText(boolean state)
989 showColourText = state;
998 public void setShowBoxes(boolean state)
1006 * @return DOCUMENT ME!
1008 public boolean getWrapAlignment()
1010 return wrapAlignment;
1016 * @return DOCUMENT ME!
1018 public boolean getShowText()
1026 * @return DOCUMENT ME!
1028 public boolean getShowBoxes()
1036 * @return DOCUMENT ME!
1038 public char getGapCharacter()
1040 return getAlignment().getGapCharacter();
1049 public void setGapCharacter(char gap)
1051 if (getAlignment() != null)
1053 getAlignment().setGapCharacter(gap);
1063 public void setThreshold(int thresh)
1071 * @return DOCUMENT ME!
1073 public int getThreshold()
1084 public void setIncrement(int inc)
1092 * @return DOCUMENT ME!
1094 public int getIncrement()
1102 * @return DOCUMENT ME!
1104 public ColumnSelection getColumnSelection()
1115 public void setCurrentTree(NJTree tree)
1123 * @return DOCUMENT ME!
1125 public NJTree getCurrentTree()
1136 public void setColourAppliesToAllGroups(boolean b)
1138 colourAppliesToAllGroups = b;
1144 * @return DOCUMENT ME!
1146 public boolean getColourAppliesToAllGroups()
1148 return colourAppliesToAllGroups;
1154 * @return DOCUMENT ME!
1156 public boolean getShowJVSuffix()
1158 return showJVSuffix;
1167 public void setShowJVSuffix(boolean b)
1175 * @return DOCUMENT ME!
1177 public boolean getShowAnnotation()
1179 return showAnnotation;
1188 public void setShowAnnotation(boolean b)
1196 * @return DOCUMENT ME!
1198 public boolean getScaleAboveWrapped()
1200 return scaleAboveWrapped;
1206 * @return DOCUMENT ME!
1208 public boolean getScaleLeftWrapped()
1210 return scaleLeftWrapped;
1216 * @return DOCUMENT ME!
1218 public boolean getScaleRightWrapped()
1220 return scaleRightWrapped;
1229 public void setScaleAboveWrapped(boolean b)
1231 scaleAboveWrapped = b;
1240 public void setScaleLeftWrapped(boolean b)
1242 scaleLeftWrapped = b;
1251 public void setScaleRightWrapped(boolean b)
1253 scaleRightWrapped = b;
1257 * Property change listener for changes in alignment
1262 public void addPropertyChangeListener(
1263 java.beans.PropertyChangeListener listener)
1265 changeSupport.addPropertyChangeListener(listener);
1274 public void removePropertyChangeListener(
1275 java.beans.PropertyChangeListener listener)
1277 changeSupport.removePropertyChangeListener(listener);
1281 * Property change listener for changes in alignment
1290 public void firePropertyChange(String prop, Object oldvalue,
1293 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1296 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1298 ignoreGapsInConsensusCalculation = b;
1299 updateConsensus(ap);
1300 if (globalColourScheme != null)
1302 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1303 ignoreGapsInConsensusCalculation);
1307 public boolean getIgnoreGapsConsensus()
1309 return ignoreGapsInConsensusCalculation;
1312 public void setDataset(boolean b)
1317 public boolean isDataset()
1322 public void hideSelectedColumns()
1324 if (colSel.size() < 1)
1329 colSel.hideSelectedColumns();
1330 setSelectionGroup(null);
1332 hasHiddenColumns = true;
1335 public void hideColumns(int start, int end)
1339 colSel.hideColumns(start);
1343 colSel.hideColumns(start, end);
1346 hasHiddenColumns = true;
1349 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1351 int sSize = sg.getSize();
1357 if (hiddenRepSequences == null)
1359 hiddenRepSequences = new Hashtable();
1362 hiddenRepSequences.put(repSequence, sg);
1364 // Hide all sequences except the repSequence
1365 SequenceI[] seqs = new SequenceI[sSize - 1];
1367 for (int i = 0; i < sSize; i++)
1369 if (sg.getSequenceAt(i) != repSequence)
1371 if (index == sSize - 1)
1376 seqs[index++] = sg.getSequenceAt(i);
1379 sg.setSeqrep(repSequence);
1380 sg.setHidereps(true);
1385 public void hideAllSelectedSeqs()
1387 if (selectionGroup == null || selectionGroup.getSize() < 1)
1392 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1396 setSelectionGroup(null);
1399 public void hideSequence(SequenceI[] seq)
1403 for (int i = 0; i < seq.length; i++)
1405 alignment.getHiddenSequences().hideSequence(seq[i]);
1407 hasHiddenRows = true;
1408 firePropertyChange("alignment", null, alignment.getSequences());
1412 public void showSequence(int index)
1414 Vector tmp = alignment.getHiddenSequences().showSequence(index,
1415 hiddenRepSequences);
1418 if (selectionGroup == null)
1420 selectionGroup = new SequenceGroup();
1421 selectionGroup.setEndRes(alignment.getWidth() - 1);
1424 for (int t = 0; t < tmp.size(); t++)
1426 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1428 firePropertyChange("alignment", null, alignment.getSequences());
1432 if (alignment.getHiddenSequences().getSize() < 1)
1434 hasHiddenRows = false;
1438 public void showColumn(int col)
1440 colSel.revealHiddenColumns(col);
1441 if (colSel.getHiddenColumns() == null)
1443 hasHiddenColumns = false;
1447 public void showAllHiddenColumns()
1449 colSel.revealAllHiddenColumns();
1450 hasHiddenColumns = false;
1453 public void showAllHiddenSeqs()
1455 if (alignment.getHiddenSequences().getSize() > 0)
1457 if (selectionGroup == null)
1459 selectionGroup = new SequenceGroup();
1460 selectionGroup.setEndRes(alignment.getWidth() - 1);
1462 Vector tmp = alignment.getHiddenSequences().showAll(
1463 hiddenRepSequences);
1464 for (int t = 0; t < tmp.size(); t++)
1466 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1468 firePropertyChange("alignment", null, alignment.getSequences());
1470 hasHiddenRows = false;
1471 hiddenRepSequences = null;
1475 public void invertColumnSelection()
1477 colSel.invertColumnSelection(0, alignment.getWidth());
1480 public int adjustForHiddenSeqs(int alignmentIndex)
1482 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1487 * This method returns an array of new SequenceI objects derived from the
1488 * whole alignment or just the current selection with start and end points
1491 * @note if you need references to the actual SequenceI objects in the
1492 * alignment or currently selected then use getSequenceSelection()
1493 * @return selection as new sequenceI objects
1495 public SequenceI[] getSelectionAsNewSequence()
1497 SequenceI[] sequences;
1499 if (selectionGroup == null)
1501 sequences = alignment.getSequencesArray();
1502 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1503 for (int i = 0; i < sequences.length; i++)
1505 sequences[i] = new Sequence(sequences[i], annots); // construct new
1507 // subset of visible
1513 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1520 * get the currently selected sequence objects or all the sequences in the
1523 * @return array of references to sequence objects
1525 public SequenceI[] getSequenceSelection()
1527 SequenceI[] sequences = null;
1528 if (selectionGroup != null)
1530 sequences = selectionGroup.getSequencesInOrder(alignment);
1532 if (sequences == null)
1534 sequences = alignment.getSequencesArray();
1540 * This method returns the visible alignment as text, as seen on the GUI, ie
1541 * if columns are hidden they will not be returned in the result. Use this for
1542 * calculating trees, PCA, redundancy etc on views which contain hidden
1547 public jalview.datamodel.CigarArray getViewAsCigars(
1548 boolean selectedRegionOnly)
1550 CigarArray selection = null;
1551 SequenceI[] seqs = null;
1553 int start = 0, end = 0;
1554 if (selectedRegionOnly && selectionGroup != null)
1556 iSize = selectionGroup.getSize();
1557 seqs = selectionGroup.getSequencesInOrder(alignment);
1558 start = selectionGroup.getStartRes();
1559 end = selectionGroup.getEndRes(); // inclusive for start and end in
1560 // SeqCigar constructor
1564 iSize = alignment.getHeight();
1565 seqs = alignment.getSequencesArray();
1566 end = alignment.getWidth() - 1;
1568 SeqCigar[] selseqs = new SeqCigar[iSize];
1569 for (i = 0; i < iSize; i++)
1571 selseqs[i] = new SeqCigar(seqs[i], start, end);
1573 selection = new CigarArray(selseqs);
1574 // now construct the CigarArray operations
1575 if (hasHiddenColumns)
1577 Vector regions = colSel.getHiddenColumns();
1579 int hideStart, hideEnd;
1581 for (int j = 0; last < end & j < regions.size(); j++)
1583 region = (int[]) regions.elementAt(j);
1584 hideStart = region[0];
1585 hideEnd = region[1];
1586 // edit hidden regions to selection range
1587 if (hideStart < last)
1599 if (hideStart > end)
1609 if (hideStart > hideEnd)
1614 * form operations...
1616 if (last < hideStart)
1618 selection.addOperation(CigarArray.M, hideStart - last);
1620 selection.addOperation(CigarArray.D, 1 + hideEnd - hideStart);
1623 // Final match if necessary.
1626 selection.addOperation(CigarArray.M, end - last + 1);
1631 selection.addOperation(CigarArray.M, end - start + 1);
1637 * return a compact representation of the current alignment selection to pass
1638 * to an analysis function
1640 * @param selectedOnly
1641 * boolean true to just return the selected view
1642 * @return AlignmentView
1644 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
1647 // this is here because the AlignmentView constructor modifies the
1649 // object. Refactoring of Cigar and alignment view representation should
1650 // be done to remove redundancy.
1651 CigarArray aligview = getViewAsCigars(selectedOnly);
1652 if (aligview != null)
1654 return new AlignmentView(aligview,
1655 (selectedOnly && selectionGroup != null) ? selectionGroup
1656 .getStartRes() : 0);
1662 * This method returns the visible alignment as text, as seen on the GUI, ie
1663 * if columns are hidden they will not be returned in the result. Use this for
1664 * calculating trees, PCA, redundancy etc on views which contain hidden
1669 public String[] getViewAsString(boolean selectedRegionOnly)
1671 String[] selection = null;
1672 SequenceI[] seqs = null;
1674 int start = 0, end = 0;
1675 if (selectedRegionOnly && selectionGroup != null)
1677 iSize = selectionGroup.getSize();
1678 seqs = selectionGroup.getSequencesInOrder(alignment);
1679 start = selectionGroup.getStartRes();
1680 end = selectionGroup.getEndRes() + 1;
1684 iSize = alignment.getHeight();
1685 seqs = alignment.getSequencesArray();
1686 end = alignment.getWidth();
1689 selection = new String[iSize];
1690 if (hasHiddenColumns)
1692 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1696 for (i = 0; i < iSize; i++)
1698 selection[i] = seqs[i].getSequenceAsString(start, end);
1705 public int[][] getVisibleRegionBoundaries(int min, int max)
1707 Vector regions = new Vector();
1713 if (hasHiddenColumns)
1717 start = colSel.adjustForHiddenColumns(start);
1720 end = colSel.getHiddenBoundaryRight(start);
1731 regions.addElement(new int[]
1734 if (hasHiddenColumns)
1736 start = colSel.adjustForHiddenColumns(end);
1737 start = colSel.getHiddenBoundaryLeft(start) + 1;
1739 } while (end < max);
1741 int[][] startEnd = new int[regions.size()][2];
1743 regions.copyInto(startEnd);
1749 public boolean getShowHiddenMarkers()
1751 return showHiddenMarkers;
1754 public void setShowHiddenMarkers(boolean show)
1756 showHiddenMarkers = show;
1759 public String getSequenceSetId()
1761 if (sequenceSetID == null)
1763 sequenceSetID = alignment.hashCode() + "";
1766 return sequenceSetID;
1770 * unique viewId for synchronizing state with stored Jalview Project
1773 private String viewId = null;
1775 public String getViewId()
1779 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1784 public void alignmentChanged(AlignmentPanel ap)
1788 alignment.padGaps();
1790 if (hconsensus != null && autoCalculateConsensus)
1792 updateConservation(ap);
1794 if (autoCalculateConsensus)
1796 updateConsensus(ap);
1799 // Reset endRes of groups if beyond alignment width
1800 int alWidth = alignment.getWidth();
1801 Vector groups = alignment.getGroups();
1804 for (int i = 0; i < groups.size(); i++)
1806 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
1807 if (sg.getEndRes() > alWidth)
1809 sg.setEndRes(alWidth - 1);
1814 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1816 selectionGroup.setEndRes(alWidth - 1);
1819 resetAllColourSchemes();
1821 // alignment.adjustSequenceAnnotations();
1824 void resetAllColourSchemes()
1826 ColourSchemeI cs = globalColourScheme;
1829 if (cs instanceof ClustalxColourScheme)
1831 ((ClustalxColourScheme) cs).resetClustalX(alignment.getSequences(),
1832 alignment.getWidth());
1835 cs.setConsensus(hconsensus);
1836 if (cs.conservationApplied())
1838 Alignment al = (Alignment) alignment;
1839 Conservation c = new Conservation("All",
1840 ResidueProperties.propHash, 3, al.getSequences(), 0, al
1843 c.verdict(false, ConsPercGaps);
1845 cs.setConservation(c);
1849 int s, sSize = alignment.getGroups().size();
1850 for (s = 0; s < sSize; s++)
1852 SequenceGroup sg = (SequenceGroup) alignment.getGroups().elementAt(s);
1853 if (sg.cs != null && sg.cs instanceof ClustalxColourScheme)
1855 ((ClustalxColourScheme) sg.cs).resetClustalX(sg
1856 .getSequences(hiddenRepSequences), sg.getWidth());
1858 sg.recalcConservation();
1862 public Color getSequenceColour(SequenceI seq)
1864 if (sequenceColours == null || !sequenceColours.containsKey(seq))
1870 return (Color) sequenceColours.get(seq);
1874 public void setSequenceColour(SequenceI seq, Color col)
1876 if (sequenceColours == null)
1878 sequenceColours = new Hashtable();
1883 sequenceColours.remove(seq);
1887 sequenceColours.put(seq, col);
1892 * returns the visible column regions of the alignment
1894 * @param selectedRegionOnly
1895 * true to just return the contigs intersecting with the selected
1899 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
1901 int[] viscontigs = null;
1902 int start = 0, end = 0;
1903 if (selectedRegionOnly && selectionGroup != null)
1905 start = selectionGroup.getStartRes();
1906 end = selectionGroup.getEndRes() + 1;
1910 end = alignment.getWidth();
1912 viscontigs = colSel.getVisibleContigs(start, end);
1917 * get hash of undo and redo list for the alignment
1919 * @return long[] { historyList.hashCode, redoList.hashCode };
1921 public long[] getUndoRedoHash()
1923 if (historyList == null || redoList == null)
1927 { historyList.hashCode(), this.redoList.hashCode() };
1931 * test if a particular set of hashcodes are different to the hashcodes for
1932 * the undo and redo list.
1935 * the stored set of hashcodes as returned by getUndoRedoHash
1936 * @return true if the hashcodes differ (ie the alignment has been edited) or
1937 * the stored hashcode array differs in size
1939 public boolean isUndoRedoHashModified(long[] undoredo)
1941 if (undoredo == null)
1945 long[] cstate = getUndoRedoHash();
1946 if (cstate.length != undoredo.length)
1951 for (int i = 0; i < cstate.length; i++)
1953 if (cstate[i] != undoredo[i])
1961 public boolean getCentreColumnLabels()
1963 return centreColumnLabels;
1966 public void setCentreColumnLabels(boolean centrecolumnlabels)
1968 centreColumnLabels = centrecolumnlabels;
1971 public void updateSequenceIdColours()
1973 Vector groups = alignment.getGroups();
1974 if (sequenceColours == null)
1976 sequenceColours = new Hashtable();
1978 for (int ig = 0, igSize = groups.size(); ig < igSize; ig++)
1980 SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
1981 if (sg.idColour != null)
1983 Vector sqs = sg.getSequences(hiddenRepSequences);
1984 for (int s = 0, sSize = sqs.size(); s < sSize; s++)
1986 sequenceColours.put(sqs.elementAt(s), sg.idColour);
1993 * enable or disable the display of Database Cross References in the sequence
1996 public void setShowDbRefs(boolean show)
2003 * @return true if Database References are to be displayed on tooltips.
2005 public boolean isShowDbRefs()
2012 * @return true if Non-positional features are to be displayed on tooltips.
2014 public boolean isShowNpFeats()
2020 * enable or disable the display of Non-Positional sequence features in the
2021 * sequence ID tooltip
2025 public void setShowNpFeats(boolean show)
2032 * @return true if view has hidden rows
2034 public boolean hasHiddenRows()
2036 return hasHiddenRows;
2041 * @return true if view has hidden columns
2043 public boolean hasHiddenColumns()
2045 return hasHiddenColumns;
2049 * when set, view will scroll to show the highlighted position
2051 public boolean followHighlight = true;
2054 * @return true if view should scroll to show the highlighted region of a
2058 public boolean getFollowHighlight()
2060 return followHighlight;
2063 public boolean followSelection = true;
2066 * @return true if view selection should always follow the selections
2067 * broadcast by other selection sources
2069 public boolean getFollowSelection()
2071 return followSelection;
2074 private long sgrouphash = -1, colselhash = -1;
2076 boolean showSeqFeaturesHeight;
2079 * checks current SelectionGroup against record of last hash value, and
2082 * @return true if SelectionGroup changed since last call
2084 boolean isSelectionGroupChanged()
2086 int hc = (selectionGroup == null) ? -1 : selectionGroup.hashCode();
2087 if (hc != sgrouphash)
2096 * checks current colsel against record of last hash value, and updates
2099 * @return true if colsel changed since last call
2101 boolean isColSelChanged()
2103 int hc = (colSel == null) ? -1 : colSel.hashCode();
2104 if (hc != colselhash)
2112 public void sendSelection()
2114 jalview.structure.StructureSelectionManager
2115 .getStructureSelectionManager().sendSelection(
2116 new SequenceGroup(getSelectionGroup()),
2117 new ColumnSelection(getColumnSelection()), this);
2120 public void setShowSequenceFeaturesHeight(boolean selected)
2122 showSeqFeaturesHeight = selected;
2125 public boolean getShowSequenceFeaturesHeight()
2127 return showSeqFeaturesHeight;
2130 boolean showUnconserved = false;
2132 public boolean getShowUnconserved()
2134 return showUnconserved;
2137 public void setShowUnconserved(boolean showunconserved)
2139 showUnconserved = showunconserved;
2143 * return the alignPanel containing the given viewport. Use this to get the
2144 * components currently handling the given viewport.
2147 * @return null or an alignPanel guaranteed to have non-null alignFrame
2150 public AlignmentPanel getAlignPanel()
2152 AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(this
2153 .getSequenceSetId());
2154 AlignmentPanel ap = null;
2155 for (int p = 0; aps != null && p < aps.length; p++)
2157 if (aps[p].av == this)
2165 public boolean getSortByTree()
2170 public void setSortByTree(boolean sort)
2176 * should conservation rows be shown for groups
2178 boolean showGroupConservation = false;
2181 * should consensus rows be shown for groups
2183 boolean showGroupConsensus = false;
2186 * should consensus profile be rendered by default
2188 public boolean showSequenceLogo = false;
2191 * should consensus histograms be rendered by default
2193 public boolean showConsensusHistogram = true;
2196 * @return the showConsensusProfile
2198 public boolean isShowSequenceLogo()
2200 return showSequenceLogo;
2204 * @param showSequenceLogo
2207 public void setShowSequenceLogo(boolean showSequenceLogo)
2209 this.showSequenceLogo = showSequenceLogo;
2213 * @param showConsensusHistogram
2214 * the showConsensusHistogram to set
2216 public void setShowConsensusHistogram(boolean showConsensusHistogram)
2218 this.showConsensusHistogram = showConsensusHistogram;
2222 * @return the showGroupConservation
2224 public boolean isShowGroupConservation()
2226 return showGroupConservation;
2230 * @param showGroupConservation
2231 * the showGroupConservation to set
2233 public void setShowGroupConservation(boolean showGroupConservation)
2235 this.showGroupConservation = showGroupConservation;
2239 * @return the showGroupConsensus
2241 public boolean isShowGroupConsensus()
2243 return showGroupConsensus;
2247 * @param showGroupConsensus
2248 * the showGroupConsensus to set
2250 public void setShowGroupConsensus(boolean showGroupConsensus)
2252 this.showGroupConsensus = showGroupConsensus;
2256 * @return the includeAllConsensusSymbols
2258 public boolean isIncludeAllConsensusSymbols()
2260 return includeAllConsensusSymbols;
2264 * @param includeAllConsensusSymbols
2265 * the includeAllConsensusSymbols to set
2267 public void setIncludeAllConsensusSymbols(
2268 boolean includeAllConsensusSymbols)
2270 this.includeAllConsensusSymbols = includeAllConsensusSymbols;
2275 * @return flag to indicate if the consensus histogram should be rendered by
2278 public boolean isShowConsensusHistogram()
2280 return this.showConsensusHistogram;
2284 * synthesize a column selection if none exists so it covers the given
2285 * selection group. if wholewidth is false, no column selection is made if the
2286 * selection group covers the whole alignment width.
2291 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2295 && (sgs = sg.getStartRes()) >= 0
2296 && sg.getStartRes() <= (sge = sg.getEndRes())
2297 && (colSel == null || colSel.getSelected() == null || colSel
2298 .getSelected().size() == 0))
2300 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2307 colSel = new ColumnSelection();
2309 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2311 colSel.addElement(cspos);