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",
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, alignment
556 .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, it will either return or wait until one calculation is finished.
594 || (!updatingConsensus && consensus != null && hconsensus != null))
596 AAFrequency.completeConsensus(consensus, hconsensus, 0,
597 hconsensus.length, ignoreGapsInConsensusCalculation,
604 * get the consensus sequence as displayed under the PID consensus annotation
607 * @return consensus sequence as a new sequence object
609 public SequenceI getConsensusSeq()
611 if (consensus == null)
613 updateConsensus(null);
615 if (consensus == null)
619 StringBuffer seqs = new StringBuffer();
620 for (int i = 0; i < consensus.annotations.length; i++)
622 if (consensus.annotations[i] != null)
624 if (consensus.annotations[i].description.charAt(0) == '[')
626 seqs.append(consensus.annotations[i].description.charAt(1));
630 seqs.append(consensus.annotations[i].displayCharacter);
635 SequenceI sq = new Sequence("Consensus", seqs.toString());
636 sq.setDescription("Percentage Identity Consensus "
637 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
644 * @return DOCUMENT ME!
646 public SequenceGroup getSelectionGroup()
648 return selectionGroup;
657 public void setSelectionGroup(SequenceGroup sg)
665 * @return DOCUMENT ME!
667 public boolean getConservationSelected()
669 return conservationColourSelected;
678 public void setConservationSelected(boolean b)
680 conservationColourSelected = b;
686 * @return DOCUMENT ME!
688 public boolean getAbovePIDThreshold()
690 return abovePIDThreshold;
699 public void setAbovePIDThreshold(boolean b)
701 abovePIDThreshold = b;
707 * @return DOCUMENT ME!
709 public int getStartRes()
717 * @return DOCUMENT ME!
719 public int getEndRes()
727 * @return DOCUMENT ME!
729 public int getStartSeq()
740 public void setGlobalColourScheme(ColourSchemeI cs)
742 globalColourScheme = cs;
748 * @return DOCUMENT ME!
750 public ColourSchemeI getGlobalColourScheme()
752 return globalColourScheme;
761 public void setStartRes(int res)
772 public void setStartSeq(int seq)
783 public void setEndRes(int res)
785 if (res > (alignment.getWidth() - 1))
787 // log.System.out.println(" Corrected res from " + res + " to maximum " +
788 // (alignment.getWidth()-1));
789 res = alignment.getWidth() - 1;
806 public void setEndSeq(int seq)
808 if (seq > alignment.getHeight())
810 seq = alignment.getHeight();
824 * @return DOCUMENT ME!
826 public int getEndSeq()
837 public void setFont(Font f)
841 Container c = new Container();
843 java.awt.FontMetrics fm = c.getFontMetrics(font);
844 setCharHeight(fm.getHeight());
845 setCharWidth(fm.charWidth('M'));
846 validCharWidth = true;
852 * @return DOCUMENT ME!
854 public Font getFont()
865 public void setCharWidth(int w)
873 * @return DOCUMENT ME!
875 public int getCharWidth()
886 public void setCharHeight(int h)
894 * @return DOCUMENT ME!
896 public int getCharHeight()
907 public void setWrappedWidth(int w)
909 this.wrappedWidth = w;
915 * @return DOCUMENT ME!
917 public int getWrappedWidth()
925 * @return DOCUMENT ME!
927 public AlignmentI getAlignment()
938 public void setAlignment(AlignmentI align)
940 if (alignment != null && alignment.getCodonFrames() != null)
942 StructureSelectionManager.getStructureSelectionManager()
943 .removeMappings(alignment.getCodonFrames());
945 this.alignment = align;
946 if (alignment.getCodonFrames() != null)
948 StructureSelectionManager.getStructureSelectionManager().addMappings(
949 alignment.getCodonFrames());
959 public void setWrapAlignment(boolean state)
961 wrapAlignment = state;
970 public void setShowText(boolean state)
981 public void setRenderGaps(boolean state)
989 * @return DOCUMENT ME!
991 public boolean getColourText()
993 return showColourText;
1002 public void setColourText(boolean state)
1004 showColourText = state;
1013 public void setShowBoxes(boolean state)
1021 * @return DOCUMENT ME!
1023 public boolean getWrapAlignment()
1025 return wrapAlignment;
1031 * @return DOCUMENT ME!
1033 public boolean getShowText()
1041 * @return DOCUMENT ME!
1043 public boolean getShowBoxes()
1051 * @return DOCUMENT ME!
1053 public char getGapCharacter()
1055 return getAlignment().getGapCharacter();
1064 public void setGapCharacter(char gap)
1066 if (getAlignment() != null)
1068 getAlignment().setGapCharacter(gap);
1078 public void setThreshold(int thresh)
1086 * @return DOCUMENT ME!
1088 public int getThreshold()
1099 public void setIncrement(int inc)
1107 * @return DOCUMENT ME!
1109 public int getIncrement()
1117 * @return DOCUMENT ME!
1119 public ColumnSelection getColumnSelection()
1130 public void setCurrentTree(NJTree tree)
1138 * @return DOCUMENT ME!
1140 public NJTree getCurrentTree()
1151 public void setColourAppliesToAllGroups(boolean b)
1153 colourAppliesToAllGroups = b;
1159 * @return DOCUMENT ME!
1161 public boolean getColourAppliesToAllGroups()
1163 return colourAppliesToAllGroups;
1169 * @return DOCUMENT ME!
1171 public boolean getShowJVSuffix()
1173 return showJVSuffix;
1182 public void setShowJVSuffix(boolean b)
1190 * @return DOCUMENT ME!
1192 public boolean getShowAnnotation()
1194 return showAnnotation;
1203 public void setShowAnnotation(boolean b)
1211 * @return DOCUMENT ME!
1213 public boolean getScaleAboveWrapped()
1215 return scaleAboveWrapped;
1221 * @return DOCUMENT ME!
1223 public boolean getScaleLeftWrapped()
1225 return scaleLeftWrapped;
1231 * @return DOCUMENT ME!
1233 public boolean getScaleRightWrapped()
1235 return scaleRightWrapped;
1244 public void setScaleAboveWrapped(boolean b)
1246 scaleAboveWrapped = b;
1255 public void setScaleLeftWrapped(boolean b)
1257 scaleLeftWrapped = b;
1266 public void setScaleRightWrapped(boolean b)
1268 scaleRightWrapped = b;
1272 * Property change listener for changes in alignment
1277 public void addPropertyChangeListener(
1278 java.beans.PropertyChangeListener listener)
1280 changeSupport.addPropertyChangeListener(listener);
1289 public void removePropertyChangeListener(
1290 java.beans.PropertyChangeListener listener)
1292 changeSupport.removePropertyChangeListener(listener);
1296 * Property change listener for changes in alignment
1305 public void firePropertyChange(String prop, Object oldvalue,
1308 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1311 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1313 ignoreGapsInConsensusCalculation = b;
1314 updateConsensus(ap);
1315 if (globalColourScheme != null)
1317 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1318 ignoreGapsInConsensusCalculation);
1322 public boolean getIgnoreGapsConsensus()
1324 return ignoreGapsInConsensusCalculation;
1327 public void setDataset(boolean b)
1332 public boolean isDataset()
1337 public void hideSelectedColumns()
1339 if (colSel.size() < 1)
1344 colSel.hideSelectedColumns();
1345 setSelectionGroup(null);
1347 hasHiddenColumns = true;
1350 public void hideColumns(int start, int end)
1354 colSel.hideColumns(start);
1358 colSel.hideColumns(start, end);
1361 hasHiddenColumns = true;
1364 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1366 int sSize = sg.getSize();
1372 if (hiddenRepSequences == null)
1374 hiddenRepSequences = new Hashtable();
1377 hiddenRepSequences.put(repSequence, sg);
1379 // Hide all sequences except the repSequence
1380 SequenceI[] seqs = new SequenceI[sSize - 1];
1382 for (int i = 0; i < sSize; i++)
1384 if (sg.getSequenceAt(i) != repSequence)
1386 if (index == sSize - 1)
1391 seqs[index++] = sg.getSequenceAt(i);
1394 sg.setSeqrep(repSequence);
1395 sg.setHidereps(true);
1400 public void hideAllSelectedSeqs()
1402 if (selectionGroup == null || selectionGroup.getSize() < 1)
1407 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1411 setSelectionGroup(null);
1414 public void hideSequence(SequenceI[] seq)
1418 for (int i = 0; i < seq.length; i++)
1420 alignment.getHiddenSequences().hideSequence(seq[i]);
1422 hasHiddenRows = true;
1423 firePropertyChange("alignment", null, alignment.getSequences());
1427 public void showSequence(int index)
1429 Vector tmp = alignment.getHiddenSequences().showSequence(index,
1430 hiddenRepSequences);
1433 if (selectionGroup == null)
1435 selectionGroup = new SequenceGroup();
1436 selectionGroup.setEndRes(alignment.getWidth() - 1);
1439 for (int t = 0; t < tmp.size(); t++)
1441 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1443 firePropertyChange("alignment", null, alignment.getSequences());
1447 if (alignment.getHiddenSequences().getSize() < 1)
1449 hasHiddenRows = false;
1453 public void showColumn(int col)
1455 colSel.revealHiddenColumns(col);
1456 if (colSel.getHiddenColumns() == null)
1458 hasHiddenColumns = false;
1462 public void showAllHiddenColumns()
1464 colSel.revealAllHiddenColumns();
1465 hasHiddenColumns = false;
1468 public void showAllHiddenSeqs()
1470 if (alignment.getHiddenSequences().getSize() > 0)
1472 if (selectionGroup == null)
1474 selectionGroup = new SequenceGroup();
1475 selectionGroup.setEndRes(alignment.getWidth() - 1);
1477 Vector tmp = alignment.getHiddenSequences().showAll(
1478 hiddenRepSequences);
1479 for (int t = 0; t < tmp.size(); t++)
1481 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1483 firePropertyChange("alignment", null, alignment.getSequences());
1485 hasHiddenRows = false;
1486 hiddenRepSequences = null;
1490 public void invertColumnSelection()
1492 colSel.invertColumnSelection(0, alignment.getWidth());
1495 public int adjustForHiddenSeqs(int alignmentIndex)
1497 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1502 * This method returns an array of new SequenceI objects derived from the
1503 * whole alignment or just the current selection with start and end points
1506 * @note if you need references to the actual SequenceI objects in the
1507 * alignment or currently selected then use getSequenceSelection()
1508 * @return selection as new sequenceI objects
1510 public SequenceI[] getSelectionAsNewSequence()
1512 SequenceI[] sequences;
1514 if (selectionGroup == null)
1516 sequences = alignment.getSequencesArray();
1517 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1518 for (int i = 0; i < sequences.length; i++)
1520 sequences[i] = new Sequence(sequences[i], annots); // construct new
1522 // subset of visible
1528 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1535 * get the currently selected sequence objects or all the sequences in the
1538 * @return array of references to sequence objects
1540 public SequenceI[] getSequenceSelection()
1542 SequenceI[] sequences = null;
1543 if (selectionGroup != null)
1545 sequences = selectionGroup.getSequencesInOrder(alignment);
1547 if (sequences == null)
1549 sequences = alignment.getSequencesArray();
1555 * This method returns the visible alignment as text, as seen on the GUI, ie
1556 * if columns are hidden they will not be returned in the result. Use this for
1557 * calculating trees, PCA, redundancy etc on views which contain hidden
1562 public jalview.datamodel.CigarArray getViewAsCigars(
1563 boolean selectedRegionOnly)
1565 CigarArray selection = null;
1566 SequenceI[] seqs = null;
1568 int start = 0, end = 0;
1569 if (selectedRegionOnly && selectionGroup != null)
1571 iSize = selectionGroup.getSize();
1572 seqs = selectionGroup.getSequencesInOrder(alignment);
1573 start = selectionGroup.getStartRes();
1574 end = selectionGroup.getEndRes(); // inclusive for start and end in
1575 // SeqCigar constructor
1579 iSize = alignment.getHeight();
1580 seqs = alignment.getSequencesArray();
1581 end = alignment.getWidth() - 1;
1583 SeqCigar[] selseqs = new SeqCigar[iSize];
1584 for (i = 0; i < iSize; i++)
1586 selseqs[i] = new SeqCigar(seqs[i], start, end);
1588 selection = new CigarArray(selseqs);
1589 // now construct the CigarArray operations
1590 if (hasHiddenColumns)
1592 Vector regions = colSel.getHiddenColumns();
1594 int hideStart, hideEnd;
1596 for (int j = 0; last < end & j < regions.size(); j++)
1598 region = (int[]) regions.elementAt(j);
1599 hideStart = region[0];
1600 hideEnd = region[1];
1601 // edit hidden regions to selection range
1602 if (hideStart < last)
1614 if (hideStart > end)
1624 if (hideStart > hideEnd)
1629 * form operations...
1631 if (last < hideStart)
1633 selection.addOperation(CigarArray.M, hideStart - last);
1635 selection.addOperation(CigarArray.D, 1 + hideEnd - hideStart);
1638 // Final match if necessary.
1641 selection.addOperation(CigarArray.M, end - last + 1);
1646 selection.addOperation(CigarArray.M, end - start + 1);
1652 * return a compact representation of the current alignment selection to pass
1653 * to an analysis function
1655 * @param selectedOnly
1656 * boolean true to just return the selected view
1657 * @return AlignmentView
1659 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
1662 // this is here because the AlignmentView constructor modifies the
1664 // object. Refactoring of Cigar and alignment view representation should
1665 // be done to remove redundancy.
1666 CigarArray aligview = getViewAsCigars(selectedOnly);
1667 if (aligview != null)
1669 return new AlignmentView(aligview,
1670 (selectedOnly && selectionGroup != null) ? selectionGroup
1671 .getStartRes() : 0);
1677 * This method returns the visible alignment as text, as seen on the GUI, ie
1678 * if columns are hidden they will not be returned in the result. Use this for
1679 * calculating trees, PCA, redundancy etc on views which contain hidden
1684 public String[] getViewAsString(boolean selectedRegionOnly)
1686 String[] selection = null;
1687 SequenceI[] seqs = null;
1689 int start = 0, end = 0;
1690 if (selectedRegionOnly && selectionGroup != null)
1692 iSize = selectionGroup.getSize();
1693 seqs = selectionGroup.getSequencesInOrder(alignment);
1694 start = selectionGroup.getStartRes();
1695 end = selectionGroup.getEndRes() + 1;
1699 iSize = alignment.getHeight();
1700 seqs = alignment.getSequencesArray();
1701 end = alignment.getWidth();
1704 selection = new String[iSize];
1705 if (hasHiddenColumns)
1707 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1711 for (i = 0; i < iSize; i++)
1713 selection[i] = seqs[i].getSequenceAsString(start, end);
1720 public int[][] getVisibleRegionBoundaries(int min, int max)
1722 Vector regions = new Vector();
1728 if (hasHiddenColumns)
1732 start = colSel.adjustForHiddenColumns(start);
1735 end = colSel.getHiddenBoundaryRight(start);
1746 regions.addElement(new int[]
1749 if (hasHiddenColumns)
1751 start = colSel.adjustForHiddenColumns(end);
1752 start = colSel.getHiddenBoundaryLeft(start) + 1;
1754 } while (end < max);
1756 int[][] startEnd = new int[regions.size()][2];
1758 regions.copyInto(startEnd);
1764 public boolean getShowHiddenMarkers()
1766 return showHiddenMarkers;
1769 public void setShowHiddenMarkers(boolean show)
1771 showHiddenMarkers = show;
1774 public String getSequenceSetId()
1776 if (sequenceSetID == null)
1778 sequenceSetID = alignment.hashCode() + "";
1781 return sequenceSetID;
1785 * unique viewId for synchronizing state with stored Jalview Project
1788 private String viewId = null;
1790 public String getViewId()
1794 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1799 public void alignmentChanged(AlignmentPanel ap)
1803 alignment.padGaps();
1805 if (hconsensus != null && autoCalculateConsensus)
1807 updateConservation(ap);
1809 if (autoCalculateConsensus)
1811 updateConsensus(ap);
1814 // Reset endRes of groups if beyond alignment width
1815 int alWidth = alignment.getWidth();
1816 Vector groups = alignment.getGroups();
1819 for (int i = 0; i < groups.size(); i++)
1821 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
1822 if (sg.getEndRes() > alWidth)
1824 sg.setEndRes(alWidth - 1);
1829 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1831 selectionGroup.setEndRes(alWidth - 1);
1834 resetAllColourSchemes();
1836 // alignment.adjustSequenceAnnotations();
1839 void resetAllColourSchemes()
1841 ColourSchemeI cs = globalColourScheme;
1844 if (cs instanceof ClustalxColourScheme)
1846 ((ClustalxColourScheme) cs).resetClustalX(alignment.getSequences(),
1847 alignment.getWidth());
1850 cs.setConsensus(hconsensus);
1851 if (cs.conservationApplied())
1853 Alignment al = (Alignment) alignment;
1854 Conservation c = new Conservation("All",
1855 ResidueProperties.propHash, 3, al.getSequences(), 0, al
1858 c.verdict(false, ConsPercGaps);
1860 cs.setConservation(c);
1864 int s, sSize = alignment.getGroups().size();
1865 for (s = 0; s < sSize; s++)
1867 SequenceGroup sg = (SequenceGroup) alignment.getGroups().elementAt(s);
1868 if (sg.cs != null && sg.cs instanceof ClustalxColourScheme)
1870 ((ClustalxColourScheme) sg.cs).resetClustalX(sg
1871 .getSequences(hiddenRepSequences), sg.getWidth());
1873 sg.recalcConservation();
1877 public Color getSequenceColour(SequenceI seq)
1879 if (sequenceColours == null || !sequenceColours.containsKey(seq))
1885 return (Color) sequenceColours.get(seq);
1889 public void setSequenceColour(SequenceI seq, Color col)
1891 if (sequenceColours == null)
1893 sequenceColours = new Hashtable();
1898 sequenceColours.remove(seq);
1902 sequenceColours.put(seq, col);
1907 * returns the visible column regions of the alignment
1909 * @param selectedRegionOnly
1910 * true to just return the contigs intersecting with the selected
1914 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
1916 int[] viscontigs = null;
1917 int start = 0, end = 0;
1918 if (selectedRegionOnly && selectionGroup != null)
1920 start = selectionGroup.getStartRes();
1921 end = selectionGroup.getEndRes() + 1;
1925 end = alignment.getWidth();
1927 viscontigs = colSel.getVisibleContigs(start, end);
1932 * get hash of undo and redo list for the alignment
1934 * @return long[] { historyList.hashCode, redoList.hashCode };
1936 public long[] getUndoRedoHash()
1938 if (historyList == null || redoList == null)
1942 { historyList.hashCode(), this.redoList.hashCode() };
1946 * test if a particular set of hashcodes are different to the hashcodes for
1947 * the undo and redo list.
1950 * the stored set of hashcodes as returned by getUndoRedoHash
1951 * @return true if the hashcodes differ (ie the alignment has been edited) or
1952 * the stored hashcode array differs in size
1954 public boolean isUndoRedoHashModified(long[] undoredo)
1956 if (undoredo == null)
1960 long[] cstate = getUndoRedoHash();
1961 if (cstate.length != undoredo.length)
1966 for (int i = 0; i < cstate.length; i++)
1968 if (cstate[i] != undoredo[i])
1976 public boolean getCentreColumnLabels()
1978 return centreColumnLabels;
1981 public void setCentreColumnLabels(boolean centrecolumnlabels)
1983 centreColumnLabels = centrecolumnlabels;
1986 public void updateSequenceIdColours()
1988 Vector groups = alignment.getGroups();
1989 if (sequenceColours == null)
1991 sequenceColours = new Hashtable();
1993 for (int ig = 0, igSize = groups.size(); ig < igSize; ig++)
1995 SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
1996 if (sg.idColour != null)
1998 Vector sqs = sg.getSequences(hiddenRepSequences);
1999 for (int s = 0, sSize = sqs.size(); s < sSize; s++)
2001 sequenceColours.put(sqs.elementAt(s), sg.idColour);
2008 * enable or disable the display of Database Cross References in the sequence
2011 public void setShowDbRefs(boolean show)
2018 * @return true if Database References are to be displayed on tooltips.
2020 public boolean isShowDbRefs()
2027 * @return true if Non-positional features are to be displayed on tooltips.
2029 public boolean isShowNpFeats()
2035 * enable or disable the display of Non-Positional sequence features in the
2036 * sequence ID tooltip
2040 public void setShowNpFeats(boolean show)
2047 * @return true if view has hidden rows
2049 public boolean hasHiddenRows()
2051 return hasHiddenRows;
2056 * @return true if view has hidden columns
2058 public boolean hasHiddenColumns()
2060 return hasHiddenColumns;
2064 * when set, view will scroll to show the highlighted position
2066 public boolean followHighlight = true;
2069 * @return true if view should scroll to show the highlighted region of a
2073 public boolean getFollowHighlight()
2075 return followHighlight;
2078 public boolean followSelection = true;
2081 * @return true if view selection should always follow the selections
2082 * broadcast by other selection sources
2084 public boolean getFollowSelection()
2086 return followSelection;
2089 private long sgrouphash = -1, colselhash = -1;
2091 boolean showSeqFeaturesHeight;
2094 * checks current SelectionGroup against record of last hash value, and
2097 * @return true if SelectionGroup changed since last call
2099 boolean isSelectionGroupChanged()
2101 int hc = (selectionGroup == null) ? -1 : selectionGroup.hashCode();
2102 if (hc != sgrouphash)
2111 * checks current colsel against record of last hash value, and updates
2114 * @return true if colsel changed since last call
2116 boolean isColSelChanged()
2118 int hc = (colSel == null) ? -1 : colSel.hashCode();
2119 if (hc != colselhash)
2127 public void sendSelection()
2129 jalview.structure.StructureSelectionManager
2130 .getStructureSelectionManager().sendSelection(
2131 new SequenceGroup(getSelectionGroup()),
2132 new ColumnSelection(getColumnSelection()), this);
2135 public void setShowSequenceFeaturesHeight(boolean selected)
2137 showSeqFeaturesHeight = selected;
2140 public boolean getShowSequenceFeaturesHeight()
2142 return showSeqFeaturesHeight;
2145 boolean showUnconserved = false;
2147 public boolean getShowUnconserved()
2149 return showUnconserved;
2152 public void setShowUnconserved(boolean showunconserved)
2154 showUnconserved = showunconserved;
2158 * return the alignPanel containing the given viewport. Use this to get the
2159 * components currently handling the given viewport.
2162 * @return null or an alignPanel guaranteed to have non-null alignFrame
2165 public AlignmentPanel getAlignPanel()
2167 AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(this
2168 .getSequenceSetId());
2169 AlignmentPanel ap = null;
2170 for (int p = 0; aps != null && p < aps.length; p++)
2172 if (aps[p].av == this)
2180 public boolean getSortByTree()
2185 public void setSortByTree(boolean sort)
2191 * should conservation rows be shown for groups
2193 boolean showGroupConservation = false;
2196 * should consensus rows be shown for groups
2198 boolean showGroupConsensus = false;
2201 * should consensus profile be rendered by default
2203 public boolean showSequenceLogo = false;
2206 * should consensus histograms be rendered by default
2208 public boolean showConsensusHistogram = true;
2211 * @return the showConsensusProfile
2213 public boolean isShowSequenceLogo()
2215 return showSequenceLogo;
2219 * @param showSequenceLogo
2222 public void setShowSequenceLogo(boolean showSequenceLogo)
2224 if (showSequenceLogo != this.showSequenceLogo)
2226 // TODO: decouple settings setting from calculation when refactoring
2227 // annotation update method from alignframe to viewport
2228 this.showSequenceLogo = showSequenceLogo;
2229 if (consensusThread != null)
2231 consensusThread.updateAnnotation();
2234 this.showSequenceLogo = showSequenceLogo;
2238 * @param showConsensusHistogram
2239 * the showConsensusHistogram to set
2241 public void setShowConsensusHistogram(boolean showConsensusHistogram)
2243 this.showConsensusHistogram = showConsensusHistogram;
2247 * @return the showGroupConservation
2249 public boolean isShowGroupConservation()
2251 return showGroupConservation;
2255 * @param showGroupConservation
2256 * the showGroupConservation to set
2258 public void setShowGroupConservation(boolean showGroupConservation)
2260 this.showGroupConservation = showGroupConservation;
2264 * @return the showGroupConsensus
2266 public boolean isShowGroupConsensus()
2268 return showGroupConsensus;
2272 * @param showGroupConsensus
2273 * the showGroupConsensus to set
2275 public void setShowGroupConsensus(boolean showGroupConsensus)
2277 this.showGroupConsensus = showGroupConsensus;
2282 * @return flag to indicate if the consensus histogram should be rendered by
2285 public boolean isShowConsensusHistogram()
2287 return this.showConsensusHistogram;
2291 * synthesize a column selection if none exists so it covers the given
2292 * selection group. if wholewidth is false, no column selection is made if the
2293 * selection group covers the whole alignment width.
2298 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2302 && (sgs = sg.getStartRes()) >= 0
2303 && sg.getStartRes() <= (sge = sg.getEndRes())
2304 && (colSel == null || colSel.getSelected() == null || colSel
2305 .getSelected().size() == 0))
2307 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2314 colSel = new ColumnSelection();
2316 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2318 colSel.addElement(cspos);