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() : 0; // null
551 consensus.annotations = null;
552 consensus.annotations = new Annotation[aWidth];
554 hconsensus = new Hashtable[aWidth];
555 AAFrequency.calculate(alignment.getSequencesArray(), 0,
556 alignment.getWidth(), hconsensus, true);
557 updateAnnotation(true);
559 if (globalColourScheme != null)
561 globalColourScheme.setConsensus(hconsensus);
564 } catch (OutOfMemoryError error)
566 alignment.deleteAnnotation(consensus);
570 new OOMWarning("calculating consensus", error);
572 UPDATING_CONSENSUS = false;
573 updatingConsensus = false;
577 ap.paintAlignment(true);
582 * update the consensus annotation from the sequence profile data using
583 * current visualization settings.
585 public void updateAnnotation()
587 updateAnnotation(false);
590 protected void updateAnnotation(boolean immediate)
592 // TODO: make calls thread-safe, so if another thread calls this method,
593 // it will either return or wait until one calculation is finished.
595 || (!updatingConsensus && consensus != null && hconsensus != null))
597 AAFrequency.completeConsensus(consensus, hconsensus, 0,
598 hconsensus.length, ignoreGapsInConsensusCalculation,
605 * get the consensus sequence as displayed under the PID consensus annotation
608 * @return consensus sequence as a new sequence object
610 public SequenceI getConsensusSeq()
612 if (consensus == null)
614 updateConsensus(null);
616 if (consensus == null)
620 StringBuffer seqs = new StringBuffer();
621 for (int i = 0; i < consensus.annotations.length; i++)
623 if (consensus.annotations[i] != null)
625 if (consensus.annotations[i].description.charAt(0) == '[')
627 seqs.append(consensus.annotations[i].description.charAt(1));
631 seqs.append(consensus.annotations[i].displayCharacter);
636 SequenceI sq = new Sequence("Consensus", seqs.toString());
637 sq.setDescription("Percentage Identity Consensus "
638 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
645 * @return DOCUMENT ME!
647 public SequenceGroup getSelectionGroup()
649 return selectionGroup;
658 public void setSelectionGroup(SequenceGroup sg)
666 * @return DOCUMENT ME!
668 public boolean getConservationSelected()
670 return conservationColourSelected;
679 public void setConservationSelected(boolean b)
681 conservationColourSelected = b;
687 * @return DOCUMENT ME!
689 public boolean getAbovePIDThreshold()
691 return abovePIDThreshold;
700 public void setAbovePIDThreshold(boolean b)
702 abovePIDThreshold = b;
708 * @return DOCUMENT ME!
710 public int getStartRes()
718 * @return DOCUMENT ME!
720 public int getEndRes()
728 * @return DOCUMENT ME!
730 public int getStartSeq()
741 public void setGlobalColourScheme(ColourSchemeI cs)
743 globalColourScheme = cs;
749 * @return DOCUMENT ME!
751 public ColourSchemeI getGlobalColourScheme()
753 return globalColourScheme;
762 public void setStartRes(int res)
773 public void setStartSeq(int seq)
784 public void setEndRes(int res)
786 if (res > (alignment.getWidth() - 1))
788 // log.System.out.println(" Corrected res from " + res + " to maximum " +
789 // (alignment.getWidth()-1));
790 res = alignment.getWidth() - 1;
807 public void setEndSeq(int seq)
809 if (seq > alignment.getHeight())
811 seq = alignment.getHeight();
825 * @return DOCUMENT ME!
827 public int getEndSeq()
838 public void setFont(Font f)
842 Container c = new Container();
844 java.awt.FontMetrics fm = c.getFontMetrics(font);
845 setCharHeight(fm.getHeight());
846 setCharWidth(fm.charWidth('M'));
847 validCharWidth = true;
853 * @return DOCUMENT ME!
855 public Font getFont()
866 public void setCharWidth(int w)
874 * @return DOCUMENT ME!
876 public int getCharWidth()
887 public void setCharHeight(int h)
895 * @return DOCUMENT ME!
897 public int getCharHeight()
908 public void setWrappedWidth(int w)
910 this.wrappedWidth = w;
916 * @return DOCUMENT ME!
918 public int getWrappedWidth()
926 * @return DOCUMENT ME!
928 public AlignmentI getAlignment()
939 public void setAlignment(AlignmentI align)
941 if (alignment != null && alignment.getCodonFrames() != null)
943 StructureSelectionManager.getStructureSelectionManager()
944 .removeMappings(alignment.getCodonFrames());
946 this.alignment = align;
947 if (alignment.getCodonFrames() != null)
949 StructureSelectionManager.getStructureSelectionManager().addMappings(
950 alignment.getCodonFrames());
960 public void setWrapAlignment(boolean state)
962 wrapAlignment = state;
971 public void setShowText(boolean state)
982 public void setRenderGaps(boolean state)
990 * @return DOCUMENT ME!
992 public boolean getColourText()
994 return showColourText;
1003 public void setColourText(boolean state)
1005 showColourText = state;
1014 public void setShowBoxes(boolean state)
1022 * @return DOCUMENT ME!
1024 public boolean getWrapAlignment()
1026 return wrapAlignment;
1032 * @return DOCUMENT ME!
1034 public boolean getShowText()
1042 * @return DOCUMENT ME!
1044 public boolean getShowBoxes()
1052 * @return DOCUMENT ME!
1054 public char getGapCharacter()
1056 return getAlignment().getGapCharacter();
1065 public void setGapCharacter(char gap)
1067 if (getAlignment() != null)
1069 getAlignment().setGapCharacter(gap);
1079 public void setThreshold(int thresh)
1087 * @return DOCUMENT ME!
1089 public int getThreshold()
1100 public void setIncrement(int inc)
1108 * @return DOCUMENT ME!
1110 public int getIncrement()
1118 * @return DOCUMENT ME!
1120 public ColumnSelection getColumnSelection()
1131 public void setCurrentTree(NJTree tree)
1139 * @return DOCUMENT ME!
1141 public NJTree getCurrentTree()
1152 public void setColourAppliesToAllGroups(boolean b)
1154 colourAppliesToAllGroups = b;
1160 * @return DOCUMENT ME!
1162 public boolean getColourAppliesToAllGroups()
1164 return colourAppliesToAllGroups;
1170 * @return DOCUMENT ME!
1172 public boolean getShowJVSuffix()
1174 return showJVSuffix;
1183 public void setShowJVSuffix(boolean b)
1191 * @return DOCUMENT ME!
1193 public boolean getShowAnnotation()
1195 return showAnnotation;
1204 public void setShowAnnotation(boolean b)
1212 * @return DOCUMENT ME!
1214 public boolean getScaleAboveWrapped()
1216 return scaleAboveWrapped;
1222 * @return DOCUMENT ME!
1224 public boolean getScaleLeftWrapped()
1226 return scaleLeftWrapped;
1232 * @return DOCUMENT ME!
1234 public boolean getScaleRightWrapped()
1236 return scaleRightWrapped;
1245 public void setScaleAboveWrapped(boolean b)
1247 scaleAboveWrapped = b;
1256 public void setScaleLeftWrapped(boolean b)
1258 scaleLeftWrapped = b;
1267 public void setScaleRightWrapped(boolean b)
1269 scaleRightWrapped = b;
1273 * Property change listener for changes in alignment
1278 public void addPropertyChangeListener(
1279 java.beans.PropertyChangeListener listener)
1281 changeSupport.addPropertyChangeListener(listener);
1290 public void removePropertyChangeListener(
1291 java.beans.PropertyChangeListener listener)
1293 changeSupport.removePropertyChangeListener(listener);
1297 * Property change listener for changes in alignment
1306 public void firePropertyChange(String prop, Object oldvalue,
1309 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1312 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1314 ignoreGapsInConsensusCalculation = b;
1315 updateConsensus(ap);
1316 if (globalColourScheme != null)
1318 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1319 ignoreGapsInConsensusCalculation);
1323 public boolean getIgnoreGapsConsensus()
1325 return ignoreGapsInConsensusCalculation;
1328 public void setDataset(boolean b)
1333 public boolean isDataset()
1338 public void hideSelectedColumns()
1340 if (colSel.size() < 1)
1345 colSel.hideSelectedColumns();
1346 setSelectionGroup(null);
1348 hasHiddenColumns = true;
1351 public void hideColumns(int start, int end)
1355 colSel.hideColumns(start);
1359 colSel.hideColumns(start, end);
1362 hasHiddenColumns = true;
1365 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1367 int sSize = sg.getSize();
1373 if (hiddenRepSequences == null)
1375 hiddenRepSequences = new Hashtable();
1378 hiddenRepSequences.put(repSequence, sg);
1380 // Hide all sequences except the repSequence
1381 SequenceI[] seqs = new SequenceI[sSize - 1];
1383 for (int i = 0; i < sSize; i++)
1385 if (sg.getSequenceAt(i) != repSequence)
1387 if (index == sSize - 1)
1392 seqs[index++] = sg.getSequenceAt(i);
1395 sg.setSeqrep(repSequence);
1396 sg.setHidereps(true);
1401 public void hideAllSelectedSeqs()
1403 if (selectionGroup == null || selectionGroup.getSize() < 1)
1408 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1412 setSelectionGroup(null);
1415 public void hideSequence(SequenceI[] seq)
1419 for (int i = 0; i < seq.length; i++)
1421 alignment.getHiddenSequences().hideSequence(seq[i]);
1423 hasHiddenRows = true;
1424 firePropertyChange("alignment", null, alignment.getSequences());
1428 public void showSequence(int index)
1430 Vector tmp = alignment.getHiddenSequences().showSequence(index,
1431 hiddenRepSequences);
1434 if (selectionGroup == null)
1436 selectionGroup = new SequenceGroup();
1437 selectionGroup.setEndRes(alignment.getWidth() - 1);
1440 for (int t = 0; t < tmp.size(); t++)
1442 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1444 firePropertyChange("alignment", null, alignment.getSequences());
1448 if (alignment.getHiddenSequences().getSize() < 1)
1450 hasHiddenRows = false;
1454 public void showColumn(int col)
1456 colSel.revealHiddenColumns(col);
1457 if (colSel.getHiddenColumns() == null)
1459 hasHiddenColumns = false;
1463 public void showAllHiddenColumns()
1465 colSel.revealAllHiddenColumns();
1466 hasHiddenColumns = false;
1469 public void showAllHiddenSeqs()
1471 if (alignment.getHiddenSequences().getSize() > 0)
1473 if (selectionGroup == null)
1475 selectionGroup = new SequenceGroup();
1476 selectionGroup.setEndRes(alignment.getWidth() - 1);
1478 Vector tmp = alignment.getHiddenSequences().showAll(
1479 hiddenRepSequences);
1480 for (int t = 0; t < tmp.size(); t++)
1482 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1484 firePropertyChange("alignment", null, alignment.getSequences());
1486 hasHiddenRows = false;
1487 hiddenRepSequences = null;
1491 public void invertColumnSelection()
1493 colSel.invertColumnSelection(0, alignment.getWidth());
1496 public int adjustForHiddenSeqs(int alignmentIndex)
1498 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1503 * This method returns an array of new SequenceI objects derived from the
1504 * whole alignment or just the current selection with start and end points
1507 * @note if you need references to the actual SequenceI objects in the
1508 * alignment or currently selected then use getSequenceSelection()
1509 * @return selection as new sequenceI objects
1511 public SequenceI[] getSelectionAsNewSequence()
1513 SequenceI[] sequences;
1515 if (selectionGroup == null)
1517 sequences = alignment.getSequencesArray();
1518 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1519 for (int i = 0; i < sequences.length; i++)
1521 sequences[i] = new Sequence(sequences[i], annots); // construct new
1523 // subset of visible
1529 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1536 * get the currently selected sequence objects or all the sequences in the
1539 * @return array of references to sequence objects
1541 public SequenceI[] getSequenceSelection()
1543 SequenceI[] sequences = null;
1544 if (selectionGroup != null)
1546 sequences = selectionGroup.getSequencesInOrder(alignment);
1548 if (sequences == null)
1550 sequences = alignment.getSequencesArray();
1556 * This method returns the visible alignment as text, as seen on the GUI, ie
1557 * if columns are hidden they will not be returned in the result. Use this for
1558 * calculating trees, PCA, redundancy etc on views which contain hidden
1563 public jalview.datamodel.CigarArray getViewAsCigars(
1564 boolean selectedRegionOnly)
1566 CigarArray selection = null;
1567 SequenceI[] seqs = null;
1569 int start = 0, end = 0;
1570 if (selectedRegionOnly && selectionGroup != null)
1572 iSize = selectionGroup.getSize();
1573 seqs = selectionGroup.getSequencesInOrder(alignment);
1574 start = selectionGroup.getStartRes();
1575 end = selectionGroup.getEndRes(); // inclusive for start and end in
1576 // SeqCigar constructor
1580 iSize = alignment.getHeight();
1581 seqs = alignment.getSequencesArray();
1582 end = alignment.getWidth() - 1;
1584 SeqCigar[] selseqs = new SeqCigar[iSize];
1585 for (i = 0; i < iSize; i++)
1587 selseqs[i] = new SeqCigar(seqs[i], start, end);
1589 selection = new CigarArray(selseqs);
1590 // now construct the CigarArray operations
1591 if (hasHiddenColumns)
1593 Vector regions = colSel.getHiddenColumns();
1595 int hideStart, hideEnd;
1597 for (int j = 0; last < end & j < regions.size(); j++)
1599 region = (int[]) regions.elementAt(j);
1600 hideStart = region[0];
1601 hideEnd = region[1];
1602 // edit hidden regions to selection range
1603 if (hideStart < last)
1615 if (hideStart > end)
1625 if (hideStart > hideEnd)
1630 * form operations...
1632 if (last < hideStart)
1634 selection.addOperation(CigarArray.M, hideStart - last);
1636 selection.addOperation(CigarArray.D, 1 + hideEnd - hideStart);
1639 // Final match if necessary.
1642 selection.addOperation(CigarArray.M, end - last + 1);
1647 selection.addOperation(CigarArray.M, end - start + 1);
1653 * return a compact representation of the current alignment selection to pass
1654 * to an analysis function
1656 * @param selectedOnly
1657 * boolean true to just return the selected view
1658 * @return AlignmentView
1660 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
1663 // this is here because the AlignmentView constructor modifies the
1665 // object. Refactoring of Cigar and alignment view representation should
1666 // be done to remove redundancy.
1667 CigarArray aligview = getViewAsCigars(selectedOnly);
1668 if (aligview != null)
1670 return new AlignmentView(aligview,
1671 (selectedOnly && selectionGroup != null) ? selectionGroup
1672 .getStartRes() : 0);
1678 * This method returns the visible alignment as text, as seen on the GUI, ie
1679 * if columns are hidden they will not be returned in the result. Use this for
1680 * calculating trees, PCA, redundancy etc on views which contain hidden
1685 public String[] getViewAsString(boolean selectedRegionOnly)
1687 String[] selection = null;
1688 SequenceI[] seqs = null;
1690 int start = 0, end = 0;
1691 if (selectedRegionOnly && selectionGroup != null)
1693 iSize = selectionGroup.getSize();
1694 seqs = selectionGroup.getSequencesInOrder(alignment);
1695 start = selectionGroup.getStartRes();
1696 end = selectionGroup.getEndRes() + 1;
1700 iSize = alignment.getHeight();
1701 seqs = alignment.getSequencesArray();
1702 end = alignment.getWidth();
1705 selection = new String[iSize];
1706 if (hasHiddenColumns)
1708 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1712 for (i = 0; i < iSize; i++)
1714 selection[i] = seqs[i].getSequenceAsString(start, end);
1721 public int[][] getVisibleRegionBoundaries(int min, int max)
1723 Vector regions = new Vector();
1729 if (hasHiddenColumns)
1733 start = colSel.adjustForHiddenColumns(start);
1736 end = colSel.getHiddenBoundaryRight(start);
1747 regions.addElement(new int[]
1750 if (hasHiddenColumns)
1752 start = colSel.adjustForHiddenColumns(end);
1753 start = colSel.getHiddenBoundaryLeft(start) + 1;
1755 } while (end < max);
1757 int[][] startEnd = new int[regions.size()][2];
1759 regions.copyInto(startEnd);
1765 public boolean getShowHiddenMarkers()
1767 return showHiddenMarkers;
1770 public void setShowHiddenMarkers(boolean show)
1772 showHiddenMarkers = show;
1775 public String getSequenceSetId()
1777 if (sequenceSetID == null)
1779 sequenceSetID = alignment.hashCode() + "";
1782 return sequenceSetID;
1786 * unique viewId for synchronizing state with stored Jalview Project
1789 private String viewId = null;
1791 public String getViewId()
1795 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1800 public void alignmentChanged(AlignmentPanel ap)
1804 alignment.padGaps();
1806 if (hconsensus != null && autoCalculateConsensus)
1808 updateConservation(ap);
1810 if (autoCalculateConsensus)
1812 updateConsensus(ap);
1815 // Reset endRes of groups if beyond alignment width
1816 int alWidth = alignment.getWidth();
1817 Vector groups = alignment.getGroups();
1820 for (int i = 0; i < groups.size(); i++)
1822 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
1823 if (sg.getEndRes() > alWidth)
1825 sg.setEndRes(alWidth - 1);
1830 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1832 selectionGroup.setEndRes(alWidth - 1);
1835 resetAllColourSchemes();
1837 // alignment.adjustSequenceAnnotations();
1840 void resetAllColourSchemes()
1842 ColourSchemeI cs = globalColourScheme;
1845 if (cs instanceof ClustalxColourScheme)
1847 ((ClustalxColourScheme) cs).resetClustalX(alignment.getSequences(),
1848 alignment.getWidth());
1851 cs.setConsensus(hconsensus);
1852 if (cs.conservationApplied())
1854 Alignment al = (Alignment) alignment;
1855 Conservation c = new Conservation("All",
1856 ResidueProperties.propHash, 3, al.getSequences(), 0,
1859 c.verdict(false, ConsPercGaps);
1861 cs.setConservation(c);
1865 int s, sSize = alignment.getGroups().size();
1866 for (s = 0; s < sSize; s++)
1868 SequenceGroup sg = (SequenceGroup) alignment.getGroups().elementAt(s);
1869 if (sg.cs != null && sg.cs instanceof ClustalxColourScheme)
1871 ((ClustalxColourScheme) sg.cs).resetClustalX(
1872 sg.getSequences(hiddenRepSequences), sg.getWidth());
1874 sg.recalcConservation();
1878 public Color getSequenceColour(SequenceI seq)
1880 if (sequenceColours == null || !sequenceColours.containsKey(seq))
1886 return (Color) sequenceColours.get(seq);
1890 public void setSequenceColour(SequenceI seq, Color col)
1892 if (sequenceColours == null)
1894 sequenceColours = new Hashtable();
1899 sequenceColours.remove(seq);
1903 sequenceColours.put(seq, col);
1908 * returns the visible column regions of the alignment
1910 * @param selectedRegionOnly
1911 * true to just return the contigs intersecting with the selected
1915 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
1917 int[] viscontigs = null;
1918 int start = 0, end = 0;
1919 if (selectedRegionOnly && selectionGroup != null)
1921 start = selectionGroup.getStartRes();
1922 end = selectionGroup.getEndRes() + 1;
1926 end = alignment.getWidth();
1928 viscontigs = colSel.getVisibleContigs(start, end);
1933 * get hash of undo and redo list for the alignment
1935 * @return long[] { historyList.hashCode, redoList.hashCode };
1937 public long[] getUndoRedoHash()
1939 if (historyList == null || redoList == null)
1943 { historyList.hashCode(), this.redoList.hashCode() };
1947 * test if a particular set of hashcodes are different to the hashcodes for
1948 * the undo and redo list.
1951 * the stored set of hashcodes as returned by getUndoRedoHash
1952 * @return true if the hashcodes differ (ie the alignment has been edited) or
1953 * the stored hashcode array differs in size
1955 public boolean isUndoRedoHashModified(long[] undoredo)
1957 if (undoredo == null)
1961 long[] cstate = getUndoRedoHash();
1962 if (cstate.length != undoredo.length)
1967 for (int i = 0; i < cstate.length; i++)
1969 if (cstate[i] != undoredo[i])
1977 public boolean getCentreColumnLabels()
1979 return centreColumnLabels;
1982 public void setCentreColumnLabels(boolean centrecolumnlabels)
1984 centreColumnLabels = centrecolumnlabels;
1987 public void updateSequenceIdColours()
1989 Vector groups = alignment.getGroups();
1990 if (sequenceColours == null)
1992 sequenceColours = new Hashtable();
1994 for (int ig = 0, igSize = groups.size(); ig < igSize; ig++)
1996 SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
1997 if (sg.idColour != null)
1999 Vector sqs = sg.getSequences(hiddenRepSequences);
2000 for (int s = 0, sSize = sqs.size(); s < sSize; s++)
2002 sequenceColours.put(sqs.elementAt(s), sg.idColour);
2009 * enable or disable the display of Database Cross References in the sequence
2012 public void setShowDbRefs(boolean show)
2019 * @return true if Database References are to be displayed on tooltips.
2021 public boolean isShowDbRefs()
2028 * @return true if Non-positional features are to be displayed on tooltips.
2030 public boolean isShowNpFeats()
2036 * enable or disable the display of Non-Positional sequence features in the
2037 * sequence ID tooltip
2041 public void setShowNpFeats(boolean show)
2048 * @return true if view has hidden rows
2050 public boolean hasHiddenRows()
2052 return hasHiddenRows;
2057 * @return true if view has hidden columns
2059 public boolean hasHiddenColumns()
2061 return hasHiddenColumns;
2065 * when set, view will scroll to show the highlighted position
2067 public boolean followHighlight = true;
2070 * @return true if view should scroll to show the highlighted region of a
2074 public boolean getFollowHighlight()
2076 return followHighlight;
2079 public boolean followSelection = true;
2082 * @return true if view selection should always follow the selections
2083 * broadcast by other selection sources
2085 public boolean getFollowSelection()
2087 return followSelection;
2090 private long sgrouphash = -1, colselhash = -1;
2092 boolean showSeqFeaturesHeight;
2095 * checks current SelectionGroup against record of last hash value, and
2098 * @return true if SelectionGroup changed since last call
2100 boolean isSelectionGroupChanged()
2102 int hc = (selectionGroup == null) ? -1 : selectionGroup.hashCode();
2103 if (hc != sgrouphash)
2112 * checks current colsel against record of last hash value, and updates
2115 * @return true if colsel changed since last call
2117 boolean isColSelChanged()
2119 int hc = (colSel == null) ? -1 : colSel.hashCode();
2120 if (hc != colselhash)
2128 public void sendSelection()
2130 jalview.structure.StructureSelectionManager
2131 .getStructureSelectionManager().sendSelection(
2132 new SequenceGroup(getSelectionGroup()),
2133 new ColumnSelection(getColumnSelection()), this);
2136 public void setShowSequenceFeaturesHeight(boolean selected)
2138 showSeqFeaturesHeight = selected;
2141 public boolean getShowSequenceFeaturesHeight()
2143 return showSeqFeaturesHeight;
2146 boolean showUnconserved = false;
2148 public boolean getShowUnconserved()
2150 return showUnconserved;
2153 public void setShowUnconserved(boolean showunconserved)
2155 showUnconserved = showunconserved;
2159 * return the alignPanel containing the given viewport. Use this to get the
2160 * components currently handling the given viewport.
2163 * @return null or an alignPanel guaranteed to have non-null alignFrame
2166 public AlignmentPanel getAlignPanel()
2168 AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(this
2169 .getSequenceSetId());
2170 AlignmentPanel ap = null;
2171 for (int p = 0; aps != null && p < aps.length; p++)
2173 if (aps[p].av == this)
2181 public boolean getSortByTree()
2186 public void setSortByTree(boolean sort)
2192 * should conservation rows be shown for groups
2194 boolean showGroupConservation = false;
2197 * should consensus rows be shown for groups
2199 boolean showGroupConsensus = false;
2202 * should consensus profile be rendered by default
2204 public boolean showSequenceLogo = false;
2207 * should consensus histograms be rendered by default
2209 public boolean showConsensusHistogram = true;
2212 * @return the showConsensusProfile
2214 public boolean isShowSequenceLogo()
2216 return showSequenceLogo;
2220 * @param showSequenceLogo
2223 public void setShowSequenceLogo(boolean showSequenceLogo)
2225 if (showSequenceLogo != this.showSequenceLogo)
2227 // TODO: decouple settings setting from calculation when refactoring
2228 // annotation update method from alignframe to viewport
2229 this.showSequenceLogo = showSequenceLogo;
2230 if (consensusThread != null)
2232 consensusThread.updateAnnotation();
2235 this.showSequenceLogo = showSequenceLogo;
2239 * @param showConsensusHistogram
2240 * the showConsensusHistogram to set
2242 public void setShowConsensusHistogram(boolean showConsensusHistogram)
2244 this.showConsensusHistogram = showConsensusHistogram;
2248 * @return the showGroupConservation
2250 public boolean isShowGroupConservation()
2252 return showGroupConservation;
2256 * @param showGroupConservation
2257 * the showGroupConservation to set
2259 public void setShowGroupConservation(boolean showGroupConservation)
2261 this.showGroupConservation = showGroupConservation;
2265 * @return the showGroupConsensus
2267 public boolean isShowGroupConsensus()
2269 return showGroupConsensus;
2273 * @param showGroupConsensus
2274 * the showGroupConsensus to set
2276 public void setShowGroupConsensus(boolean showGroupConsensus)
2278 this.showGroupConsensus = showGroupConsensus;
2283 * @return flag to indicate if the consensus histogram should be rendered by
2286 public boolean isShowConsensusHistogram()
2288 return this.showConsensusHistogram;
2292 * synthesize a column selection if none exists so it covers the given
2293 * selection group. if wholewidth is false, no column selection is made if the
2294 * selection group covers the whole alignment width.
2299 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2303 && (sgs = sg.getStartRes()) >= 0
2304 && sg.getStartRes() <= (sge = sg.getEndRes())
2305 && (colSel == null || colSel.getSelected() == null || colSel
2306 .getSelected().size() == 0))
2308 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2315 colSel = new ColumnSelection();
2317 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2319 colSel.addElement(cspos);