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.*;
43 import jalview.api.StructureSelectionManagerProvider;
47 import jalview.datamodel.*;
49 import jalview.schemes.*;
50 import jalview.structure.SelectionSource;
51 import jalview.structure.StructureSelectionManager;
52 import jalview.structure.VamsasSource;
58 * @version $Revision: 1.141 $
60 public class AlignViewport implements SelectionSource, VamsasSource
62 private static final int RIGHT_JUSTIFY = 1;
72 boolean showJVSuffix = true;
74 boolean showText = true;
76 boolean showColourText = false;
78 boolean showBoxes = true;
80 boolean wrapAlignment = false;
82 boolean renderGaps = true;
84 boolean showSequenceFeatures = false;
86 boolean showAnnotation = true;
88 boolean colourAppliesToAllGroups = true;
90 ColourSchemeI globalColourScheme = null;
92 boolean conservationColourSelected = false;
94 boolean abovePIDThreshold = false;
96 SequenceGroup selectionGroup;
102 boolean validCharWidth;
108 boolean seqNameItalics;
110 AlignmentI alignment;
112 ColumnSelection colSel = new ColumnSelection();
118 NJTree currentTree = null;
120 boolean scaleAboveWrapped = false;
122 boolean scaleLeftWrapped = true;
124 boolean scaleRightWrapped = true;
126 boolean hasHiddenColumns = false;
128 boolean hasHiddenRows = false;
130 boolean showHiddenMarkers = true;
132 boolean cursorMode = false;
135 * Keys are the feature types which are currently visible. Note: Values are
138 Hashtable featuresDisplayed = null;
141 public Hashtable[] hconsensus;
143 public Hashtable[] hStrucConsensus;
145 AlignmentAnnotation consensus;
147 AlignmentAnnotation strucConsensus;
149 AlignmentAnnotation conservation;
151 AlignmentAnnotation quality;
153 AlignmentAnnotation[] groupConsensus;
155 AlignmentAnnotation[] groupConservation;
157 boolean autoCalculateConsensus = true;
159 boolean autoCalculateStrucConsensus = true;
163 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
165 // JBPNote Prolly only need this in the applet version.
166 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
169 boolean ignoreGapsInConsensusCalculation = false;
171 boolean isDataset = false;
173 boolean antiAlias = false;
175 boolean padGaps = false;
177 Rectangle explodedPosition;
181 String sequenceSetID;
183 boolean gatherViewsHere = false;
185 Stack historyList = new Stack();
187 Stack redoList = new Stack();
189 Hashtable sequenceColours;
191 int thresholdTextColour = 0;
193 Color textColour = Color.black;
195 Color textColour2 = Color.white;
197 boolean rightAlignIds = false;
199 Hashtable hiddenRepSequences;
204 * Creates a new AlignViewport object.
209 public AlignViewport(AlignmentI al)
216 * Create a new AlignViewport object with a specific sequence set ID
220 * (may be null - but potential for ambiguous constructor exception)
222 public AlignViewport(AlignmentI al, String seqsetid)
224 this(al, seqsetid, null);
227 public AlignViewport(AlignmentI al, String seqsetid, String viewid)
229 sequenceSetID = seqsetid;
231 // TODO remove these once 2.4.VAMSAS release finished
232 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
234 Cache.log.debug("Setting viewport's sequence set id : "
237 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
239 Cache.log.debug("Setting viewport's view id : " + viewId);
246 * Create a new AlignViewport with hidden regions
250 * @param hiddenColumns
253 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns)
256 if (hiddenColumns != null)
258 this.colSel = hiddenColumns;
259 if (hiddenColumns.getHiddenColumns() != null
260 && hiddenColumns.getHiddenColumns().size() > 0)
262 hasHiddenColumns = true;
266 hasHiddenColumns = false;
273 * New viewport with hidden columns and an existing sequence set id
276 * @param hiddenColumns
280 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
283 this(al, hiddenColumns, seqsetid, null);
287 * New viewport with hidden columns and an existing sequence set id and viewid
290 * @param hiddenColumns
296 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
297 String seqsetid, String viewid)
299 sequenceSetID = seqsetid;
301 // TODO remove these once 2.4.VAMSAS release finished
302 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
304 Cache.log.debug("Setting viewport's sequence set id : "
307 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
309 Cache.log.debug("Setting viewport's view id : " + viewId);
312 if (hiddenColumns != null)
314 this.colSel = hiddenColumns;
315 if (hiddenColumns.getHiddenColumns() != null
316 && hiddenColumns.getHiddenColumns().size() > 0)
318 hasHiddenColumns = true;
322 hasHiddenColumns = false;
331 this.endRes = alignment.getWidth() - 1;
333 this.endSeq = alignment.getHeight() - 1;
335 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
337 showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
338 showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
340 rightAlignIds = Cache.getDefault("RIGHT_ALIGN_IDS", false);
341 centreColumnLabels = Cache.getDefault("CENTRE_COLUMN_LABELS", false);
342 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
344 padGaps = Cache.getDefault("PAD_GAPS", true);
345 shownpfeats = Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true);
346 showdbrefs = Cache.getDefault("SHOW_DBREFS_TOOLTIP", true);
348 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
349 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
350 String fontSize = Cache.getDefault("FONT_SIZE", "10");
352 seqNameItalics = Cache.getDefault("ID_ITALICS", true);
356 if (fontStyle.equals("bold"))
360 else if (fontStyle.equals("italic"))
365 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
368 .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
370 // We must set conservation and consensus before setting colour,
371 // as Blosum and Clustal require this to be done
372 if (hconsensus == null && !isDataset)
374 if (!alignment.isNucleotide())
376 conservation = new AlignmentAnnotation("Conservation",
377 "Conservation of total alignment less than " + ConsPercGaps
378 + "% gaps", new Annotation[1], 0f, 11f,
379 AlignmentAnnotation.BAR_GRAPH);
380 conservation.hasText = true;
381 conservation.autoCalculated = true;
383 if (Cache.getDefault("SHOW_CONSERVATION", true))
385 alignment.addAnnotation(conservation);
388 if (Cache.getDefault("SHOW_QUALITY", true))
390 quality = new AlignmentAnnotation("Quality",
391 "Alignment Quality based on Blosum62 scores",
392 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
393 quality.hasText = true;
394 quality.autoCalculated = true;
396 alignment.addAnnotation(quality);
398 showGroupConservation = Cache.getDefault("SHOW_GROUP_CONSERVATION",
405 showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",
407 showSequenceLogo = Cache.getDefault("SHOW_CONSENSUS_LOGO", false);
408 showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
409 // TODO: add menu option action that nulls or creates consensus object
410 // depending on if the user wants to see the annotation or not in a
411 // specific alignment
412 consensus = new AlignmentAnnotation("Consensus", "PID",
413 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
414 consensus.hasText = true;
415 consensus.autoCalculated = true;
417 if (Cache.getDefault("SHOW_IDENTITY", true))
419 alignment.addAnnotation(consensus);
423 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
425 globalColourScheme = ColourSchemeProperty.getColour(alignment,
426 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
428 if (globalColourScheme instanceof UserColourScheme)
430 globalColourScheme = UserDefinedColours.loadDefaultColours();
431 ((UserColourScheme) globalColourScheme).setThreshold(0,
432 getIgnoreGapsConsensus());
435 if (globalColourScheme != null)
437 globalColourScheme.setConsensus(hconsensus);
441 wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false);
442 showUnconserved = jalview.bin.Cache.getDefault("SHOW_UNCONSERVED",
444 sortByTree = jalview.bin.Cache.getDefault("SORT_BY_TREE", false);
445 followSelection = jalview.bin.Cache.getDefault("FOLLOW_SELECTIONS",
453 * features are displayed if true
455 public void setShowSequenceFeatures(boolean b)
457 showSequenceFeatures = b;
460 public boolean getShowSequenceFeatures()
462 return showSequenceFeatures;
465 ConservationThread conservationThread;
467 ConsensusThread consensusThread;
469 StrucConsensusThread strucConsensusThread;
471 boolean consUpdateNeeded = false;
473 static boolean UPDATING_CONSENSUS = false;
475 static boolean UPDATING_STRUC_CONSENSUS = false;
477 static boolean UPDATING_CONSERVATION = false;
479 boolean updatingConsensus = false;
481 boolean updatingStrucConsensus = false;
483 boolean updatingConservation = false;
486 * centre columnar annotation labels in displayed alignment annotation TODO:
487 * add to jalviewXML and annotation display settings
489 boolean centreColumnLabels = false;
491 private boolean showdbrefs;
493 private boolean shownpfeats;
496 * trigger update of conservation annotation
498 public void updateConservation(final AlignmentPanel ap)
500 // see note in mantis : issue number 8585
501 if (alignment.isNucleotide() || conservation == null
502 || !autoCalculateConsensus)
507 conservationThread = new ConservationThread(this, ap);
508 conservationThread.start();
512 * trigger update of consensus annotation
514 public void updateConsensus(final AlignmentPanel ap)
516 // see note in mantis : issue number 8585
517 if (consensus == null || !autoCalculateConsensus)
521 consensusThread = new ConsensusThread(ap);
522 consensusThread.start();
525 class ConsensusThread extends Thread
529 public ConsensusThread(AlignmentPanel ap)
536 updatingConsensus = true;
537 while (UPDATING_CONSENSUS)
543 ap.paintAlignment(false);
547 } catch (Exception ex)
549 ex.printStackTrace();
553 UPDATING_CONSENSUS = true;
557 int aWidth = (alignment != null) ? alignment.getWidth() : -1; // null
563 updatingConsensus = false;
564 UPDATING_CONSENSUS = false;
568 consensus.annotations = null;
569 consensus.annotations = new Annotation[aWidth];
571 hconsensus = new Hashtable[aWidth];
572 AAFrequency.calculate(alignment.getSequencesArray(), 0,
573 alignment.getWidth(), hconsensus, true);
574 updateAnnotation(true);
575 if (globalColourScheme != null)
577 globalColourScheme.setConsensus(hconsensus);
580 } catch (OutOfMemoryError error)
582 alignment.deleteAnnotation(consensus);
586 new OOMWarning("calculating consensus", error);
588 UPDATING_CONSENSUS = false;
589 updatingConsensus = false;
593 ap.paintAlignment(true);
598 * update the consensus annotation from the sequence profile data using
599 * current visualization settings.
601 public void updateAnnotation()
603 updateAnnotation(false);
606 protected void updateAnnotation(boolean immediate)
608 // TODO: make calls thread-safe, so if another thread calls this method,
609 // it will either return or wait until one calculation is finished.
611 || (!updatingConsensus && consensus != null && hconsensus != null))
613 AAFrequency.completeConsensus(consensus, hconsensus, 0,
614 hconsensus.length, ignoreGapsInConsensusCalculation,
620 //--------START Structure Conservation
621 public void updateStrucConsensus(final AlignmentPanel ap)
623 // see note in mantis : issue number 8585
624 if (strucConsensus == null || !autoCalculateStrucConsensus)
628 strucConsensusThread = new StrucConsensusThread(ap);
629 strucConsensusThread.start();
632 class StrucConsensusThread extends Thread
636 public StrucConsensusThread(AlignmentPanel ap)
643 updatingStrucConsensus = true;
644 while (UPDATING_STRUC_CONSENSUS)
650 ap.paintAlignment(false);
654 } catch (Exception ex)
656 ex.printStackTrace();
660 UPDATING_STRUC_CONSENSUS = true;
664 int aWidth = (alignment != null) ? alignment.getWidth() : -1; // null
670 updatingStrucConsensus = false;
671 UPDATING_STRUC_CONSENSUS = false;
675 strucConsensus.annotations = null;
676 strucConsensus.annotations = new Annotation[aWidth];
678 hStrucConsensus = new Hashtable[aWidth];
679 AlignmentAnnotation rna = ap.av.getAlignment().getAlignmentAnnotation()[0];
680 StructureFrequency.calculate(alignment.getSequencesArray(), 0,
681 alignment.getWidth(), hStrucConsensus, true, rna);
682 //TODO AlignmentAnnotation rnaStruc!!!
683 updateAnnotation(true);
684 if (globalColourScheme != null)
686 globalColourScheme.setConsensus(hStrucConsensus);
689 } catch (OutOfMemoryError error)
691 alignment.deleteAnnotation(consensus);
693 strucConsensus = null;
694 hStrucConsensus = null;
695 new OOMWarning("calculating structure consensus", error);
697 UPDATING_STRUC_CONSENSUS = false;
698 updatingStrucConsensus = false;
702 ap.paintAlignment(true);
707 * update the consensus annotation from the sequence profile data using
708 * current visualization settings.
710 public void updateAnnotation()
712 updateAnnotation(false);
715 protected void updateAnnotation(boolean immediate)
717 // TODO: make calls thread-safe, so if another thread calls this method,
718 // it will either return or wait until one calculation is finished.
720 || (!updatingConsensus && consensus != null && hconsensus != null))
722 StructureFrequency.completeConsensus(strucConsensus, hStrucConsensus, 0,
723 hStrucConsensus.length, ignoreGapsInConsensusCalculation,
728 //--------END Structure Conservation
731 * get the consensus sequence as displayed under the PID consensus annotation
734 * @return consensus sequence as a new sequence object
736 public SequenceI getConsensusSeq()
738 if (consensus == null)
740 updateConsensus(null);
742 if (consensus == null)
746 StringBuffer seqs = new StringBuffer();
747 for (int i = 0; i < consensus.annotations.length; i++)
749 if (consensus.annotations[i] != null)
751 if (consensus.annotations[i].description.charAt(0) == '[')
753 seqs.append(consensus.annotations[i].description.charAt(1));
757 seqs.append(consensus.annotations[i].displayCharacter);
762 SequenceI sq = new Sequence("Consensus", seqs.toString());
763 sq.setDescription("Percentage Identity Consensus "
764 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
771 * @return null or the currently selected sequence region
773 public SequenceGroup getSelectionGroup()
775 return selectionGroup;
779 * Set the selection group for this window.
781 * @param sg - group holding references to sequences in this alignment view
784 public void setSelectionGroup(SequenceGroup sg)
791 * @return true if conservation based shading is enabled
793 public boolean getConservationSelected()
795 return conservationColourSelected;
801 * enable conservation based shading
803 public void setConservationSelected(boolean b)
805 conservationColourSelected = b;
810 * @return true if percent identity threshold is applied to shading
812 public boolean getAbovePIDThreshold()
814 return abovePIDThreshold;
821 * @param b indicate if percent identity threshold is applied to shading
823 public void setAbovePIDThreshold(boolean b)
825 abovePIDThreshold = b;
831 * @return DOCUMENT ME!
833 public int getStartRes()
841 * @return DOCUMENT ME!
843 public int getEndRes()
851 * @return DOCUMENT ME!
853 public int getStartSeq()
864 public void setGlobalColourScheme(ColourSchemeI cs)
866 globalColourScheme = cs;
872 * @return DOCUMENT ME!
874 public ColourSchemeI getGlobalColourScheme()
876 return globalColourScheme;
885 public void setStartRes(int res)
896 public void setStartSeq(int seq)
907 public void setEndRes(int res)
909 if (res > (alignment.getWidth() - 1))
911 // log.System.out.println(" Corrected res from " + res + " to maximum " +
912 // (alignment.getWidth()-1));
913 res = alignment.getWidth() - 1;
930 public void setEndSeq(int seq)
932 if (seq > alignment.getHeight())
934 seq = alignment.getHeight();
948 * @return DOCUMENT ME!
950 public int getEndSeq()
961 public void setFont(Font f)
965 Container c = new Container();
967 java.awt.FontMetrics fm = c.getFontMetrics(font);
968 setCharHeight(fm.getHeight());
969 setCharWidth(fm.charWidth('M'));
970 validCharWidth = true;
976 * @return DOCUMENT ME!
978 public Font getFont()
989 public void setCharWidth(int w)
997 * @return DOCUMENT ME!
999 public int getCharWidth()
1010 public void setCharHeight(int h)
1012 this.charHeight = h;
1018 * @return DOCUMENT ME!
1020 public int getCharHeight()
1031 public void setWrappedWidth(int w)
1033 this.wrappedWidth = w;
1039 * @return DOCUMENT ME!
1041 public int getWrappedWidth()
1043 return wrappedWidth;
1049 * @return DOCUMENT ME!
1051 public AlignmentI getAlignment()
1062 public void setAlignment(AlignmentI align)
1064 if (alignment != null && alignment.getCodonFrames() != null)
1066 StructureSelectionManager.getStructureSelectionManager(Desktop.instance)
1067 .removeMappings(alignment.getCodonFrames());
1069 this.alignment = align;
1070 if (alignment.getCodonFrames() != null)
1072 StructureSelectionManager.getStructureSelectionManager(Desktop.instance).addMappings(
1073 alignment.getCodonFrames());
1083 public void setWrapAlignment(boolean state)
1085 wrapAlignment = state;
1094 public void setShowText(boolean state)
1105 public void setRenderGaps(boolean state)
1113 * @return DOCUMENT ME!
1115 public boolean getColourText()
1117 return showColourText;
1126 public void setColourText(boolean state)
1128 showColourText = state;
1137 public void setShowBoxes(boolean state)
1145 * @return DOCUMENT ME!
1147 public boolean getWrapAlignment()
1149 return wrapAlignment;
1155 * @return DOCUMENT ME!
1157 public boolean getShowText()
1165 * @return DOCUMENT ME!
1167 public boolean getShowBoxes()
1175 * @return DOCUMENT ME!
1177 public char getGapCharacter()
1179 return getAlignment().getGapCharacter();
1188 public void setGapCharacter(char gap)
1190 if (getAlignment() != null)
1192 getAlignment().setGapCharacter(gap);
1202 public void setThreshold(int thresh)
1210 * @return DOCUMENT ME!
1212 public int getThreshold()
1223 public void setIncrement(int inc)
1231 * @return DOCUMENT ME!
1233 public int getIncrement()
1241 * @return DOCUMENT ME!
1243 public ColumnSelection getColumnSelection()
1254 public void setCurrentTree(NJTree tree)
1262 * @return DOCUMENT ME!
1264 public NJTree getCurrentTree()
1275 public void setColourAppliesToAllGroups(boolean b)
1277 colourAppliesToAllGroups = b;
1283 * @return DOCUMENT ME!
1285 public boolean getColourAppliesToAllGroups()
1287 return colourAppliesToAllGroups;
1293 * @return DOCUMENT ME!
1295 public boolean getShowJVSuffix()
1297 return showJVSuffix;
1306 public void setShowJVSuffix(boolean b)
1314 * @return DOCUMENT ME!
1316 public boolean getShowAnnotation()
1318 return showAnnotation;
1327 public void setShowAnnotation(boolean b)
1335 * @return DOCUMENT ME!
1337 public boolean getScaleAboveWrapped()
1339 return scaleAboveWrapped;
1345 * @return DOCUMENT ME!
1347 public boolean getScaleLeftWrapped()
1349 return scaleLeftWrapped;
1355 * @return DOCUMENT ME!
1357 public boolean getScaleRightWrapped()
1359 return scaleRightWrapped;
1368 public void setScaleAboveWrapped(boolean b)
1370 scaleAboveWrapped = b;
1379 public void setScaleLeftWrapped(boolean b)
1381 scaleLeftWrapped = b;
1390 public void setScaleRightWrapped(boolean b)
1392 scaleRightWrapped = b;
1396 * Property change listener for changes in alignment
1401 public void addPropertyChangeListener(
1402 java.beans.PropertyChangeListener listener)
1404 changeSupport.addPropertyChangeListener(listener);
1413 public void removePropertyChangeListener(
1414 java.beans.PropertyChangeListener listener)
1416 changeSupport.removePropertyChangeListener(listener);
1420 * Property change listener for changes in alignment
1429 public void firePropertyChange(String prop, Object oldvalue,
1432 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1435 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1437 ignoreGapsInConsensusCalculation = b;
1438 updateConsensus(ap);
1439 if (globalColourScheme != null)
1441 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1442 ignoreGapsInConsensusCalculation);
1446 public boolean getIgnoreGapsConsensus()
1448 return ignoreGapsInConsensusCalculation;
1451 public void setDataset(boolean b)
1456 public boolean isDataset()
1461 public void hideSelectedColumns()
1463 if (colSel.size() < 1)
1468 colSel.hideSelectedColumns();
1469 setSelectionGroup(null);
1471 hasHiddenColumns = true;
1474 public void hideColumns(int start, int end)
1478 colSel.hideColumns(start);
1482 colSel.hideColumns(start, end);
1485 hasHiddenColumns = true;
1488 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1490 int sSize = sg.getSize();
1496 if (hiddenRepSequences == null)
1498 hiddenRepSequences = new Hashtable();
1501 hiddenRepSequences.put(repSequence, sg);
1503 // Hide all sequences except the repSequence
1504 SequenceI[] seqs = new SequenceI[sSize - 1];
1506 for (int i = 0; i < sSize; i++)
1508 if (sg.getSequenceAt(i) != repSequence)
1510 if (index == sSize - 1)
1515 seqs[index++] = sg.getSequenceAt(i);
1518 sg.setSeqrep(repSequence);
1519 sg.setHidereps(true);
1524 public void hideAllSelectedSeqs()
1526 if (selectionGroup == null || selectionGroup.getSize() < 1)
1531 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1535 setSelectionGroup(null);
1538 public void hideSequence(SequenceI[] seq)
1542 for (int i = 0; i < seq.length; i++)
1544 alignment.getHiddenSequences().hideSequence(seq[i]);
1546 hasHiddenRows = true;
1547 firePropertyChange("alignment", null, alignment.getSequences());
1551 public void showSequence(int index)
1553 Vector tmp = alignment.getHiddenSequences().showSequence(index,
1554 hiddenRepSequences);
1557 if (selectionGroup == null)
1559 selectionGroup = new SequenceGroup();
1560 selectionGroup.setEndRes(alignment.getWidth() - 1);
1563 for (int t = 0; t < tmp.size(); t++)
1565 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1567 firePropertyChange("alignment", null, alignment.getSequences());
1571 if (alignment.getHiddenSequences().getSize() < 1)
1573 hasHiddenRows = false;
1577 public void showColumn(int col)
1579 colSel.revealHiddenColumns(col);
1580 if (colSel.getHiddenColumns() == null)
1582 hasHiddenColumns = false;
1586 public void showAllHiddenColumns()
1588 colSel.revealAllHiddenColumns();
1589 hasHiddenColumns = false;
1592 public void showAllHiddenSeqs()
1594 if (alignment.getHiddenSequences().getSize() > 0)
1596 if (selectionGroup == null)
1598 selectionGroup = new SequenceGroup();
1599 selectionGroup.setEndRes(alignment.getWidth() - 1);
1601 Vector tmp = alignment.getHiddenSequences().showAll(
1602 hiddenRepSequences);
1603 for (int t = 0; t < tmp.size(); t++)
1605 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1607 firePropertyChange("alignment", null, alignment.getSequences());
1609 hasHiddenRows = false;
1610 hiddenRepSequences = null;
1614 public void invertColumnSelection()
1616 colSel.invertColumnSelection(0, alignment.getWidth());
1619 public int adjustForHiddenSeqs(int alignmentIndex)
1621 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1626 * This method returns an array of new SequenceI objects derived from the
1627 * whole alignment or just the current selection with start and end points
1630 * @note if you need references to the actual SequenceI objects in the
1631 * alignment or currently selected then use getSequenceSelection()
1632 * @return selection as new sequenceI objects
1634 public SequenceI[] getSelectionAsNewSequence()
1636 SequenceI[] sequences;
1638 if (selectionGroup == null)
1640 sequences = alignment.getSequencesArray();
1641 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1642 for (int i = 0; i < sequences.length; i++)
1644 sequences[i] = new Sequence(sequences[i], annots); // construct new
1646 // subset of visible
1652 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1659 * get the currently selected sequence objects or all the sequences in the
1662 * @return array of references to sequence objects
1664 public SequenceI[] getSequenceSelection()
1666 SequenceI[] sequences = null;
1667 if (selectionGroup != null)
1669 sequences = selectionGroup.getSequencesInOrder(alignment);
1671 if (sequences == null)
1673 sequences = alignment.getSequencesArray();
1679 * This method returns the visible alignment as text, as seen on the GUI, ie
1680 * if columns are hidden they will not be returned in the result. Use this for
1681 * calculating trees, PCA, redundancy etc on views which contain hidden
1686 public jalview.datamodel.CigarArray getViewAsCigars(
1687 boolean selectedRegionOnly)
1689 return new jalview.datamodel.CigarArray(alignment, (hasHiddenColumns ? colSel : null), (selectedRegionOnly ? selectionGroup : null));
1693 * return a compact representation of the current alignment selection to pass
1694 * to an analysis function
1696 * @param selectedOnly
1697 * boolean true to just return the selected view
1698 * @return AlignmentView
1700 public jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
1702 return getAlignmentView(selectedOnly, false);
1706 * return a compact representation of the current alignment selection to pass
1707 * to an analysis function
1709 * @param selectedOnly
1710 * boolean true to just return the selected view
1712 * boolean true to annotate the alignment view with groups on the alignment (and intersecting with selected region if selectedOnly is true)
1713 * @return AlignmentView
1715 public jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly, boolean markGroups)
1717 return new AlignmentView(alignment, colSel, selectionGroup, hasHiddenColumns, selectedOnly, markGroups);
1721 * This method returns the visible alignment as text, as seen on the GUI, ie
1722 * if columns are hidden they will not be returned in the result. Use this for
1723 * calculating trees, PCA, redundancy etc on views which contain hidden
1728 public String[] getViewAsString(boolean selectedRegionOnly)
1730 String[] selection = null;
1731 SequenceI[] seqs = null;
1733 int start = 0, end = 0;
1734 if (selectedRegionOnly && selectionGroup != null)
1736 iSize = selectionGroup.getSize();
1737 seqs = selectionGroup.getSequencesInOrder(alignment);
1738 start = selectionGroup.getStartRes();
1739 end = selectionGroup.getEndRes() + 1;
1743 iSize = alignment.getHeight();
1744 seqs = alignment.getSequencesArray();
1745 end = alignment.getWidth();
1748 selection = new String[iSize];
1749 if (hasHiddenColumns)
1751 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1755 for (i = 0; i < iSize; i++)
1757 selection[i] = seqs[i].getSequenceAsString(start, end);
1764 public int[][] getVisibleRegionBoundaries(int min, int max)
1766 Vector regions = new Vector();
1772 if (hasHiddenColumns)
1776 start = colSel.adjustForHiddenColumns(start);
1779 end = colSel.getHiddenBoundaryRight(start);
1790 regions.addElement(new int[]
1793 if (hasHiddenColumns)
1795 start = colSel.adjustForHiddenColumns(end);
1796 start = colSel.getHiddenBoundaryLeft(start) + 1;
1798 } while (end < max);
1800 int[][] startEnd = new int[regions.size()][2];
1802 regions.copyInto(startEnd);
1808 public boolean getShowHiddenMarkers()
1810 return showHiddenMarkers;
1813 public void setShowHiddenMarkers(boolean show)
1815 showHiddenMarkers = show;
1818 public String getSequenceSetId()
1820 if (sequenceSetID == null)
1822 sequenceSetID = alignment.hashCode() + "";
1825 return sequenceSetID;
1829 * unique viewId for synchronizing state with stored Jalview Project
1832 private String viewId = null;
1834 public String getViewId()
1838 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1843 public void alignmentChanged(AlignmentPanel ap)
1847 alignment.padGaps();
1849 if (hconsensus != null && autoCalculateConsensus)
1851 updateConservation(ap);
1853 if (autoCalculateConsensus)
1855 updateConsensus(ap);
1858 if(autoCalculateStrucConsensus)
1860 updateStrucConsensus(ap);
1863 // Reset endRes of groups if beyond alignment width
1864 int alWidth = alignment.getWidth();
1865 Vector groups = alignment.getGroups();
1868 for (int i = 0; i < groups.size(); i++)
1870 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
1871 if (sg.getEndRes() > alWidth)
1873 sg.setEndRes(alWidth - 1);
1878 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1880 selectionGroup.setEndRes(alWidth - 1);
1883 resetAllColourSchemes();
1885 // alignment.adjustSequenceAnnotations();
1888 void resetAllColourSchemes()
1890 ColourSchemeI cs = globalColourScheme;
1893 if (cs instanceof ClustalxColourScheme)
1895 ((ClustalxColourScheme) cs).resetClustalX(alignment.getSequences(),
1896 alignment.getWidth());
1899 cs.setConsensus(hconsensus);
1900 if (cs.conservationApplied())
1902 Alignment al = (Alignment) alignment;
1903 Conservation c = new Conservation("All",
1904 ResidueProperties.propHash, 3, al.getSequences(), 0,
1907 c.verdict(false, ConsPercGaps);
1909 cs.setConservation(c);
1913 int s, sSize = alignment.getGroups().size();
1914 for (s = 0; s < sSize; s++)
1916 SequenceGroup sg = (SequenceGroup) alignment.getGroups().elementAt(s);
1917 if (sg.cs != null && sg.cs instanceof ClustalxColourScheme)
1919 ((ClustalxColourScheme) sg.cs).resetClustalX(
1920 sg.getSequences(hiddenRepSequences), sg.getWidth());
1922 sg.recalcConservation();
1926 public Color getSequenceColour(SequenceI seq)
1928 if (sequenceColours == null || !sequenceColours.containsKey(seq))
1934 return (Color) sequenceColours.get(seq);
1938 public void setSequenceColour(SequenceI seq, Color col)
1940 if (sequenceColours == null)
1942 sequenceColours = new Hashtable();
1947 sequenceColours.remove(seq);
1951 sequenceColours.put(seq, col);
1956 * returns the visible column regions of the alignment
1958 * @param selectedRegionOnly
1959 * true to just return the contigs intersecting with the selected
1963 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
1965 int[] viscontigs = null;
1966 int start = 0, end = 0;
1967 if (selectedRegionOnly && selectionGroup != null)
1969 start = selectionGroup.getStartRes();
1970 end = selectionGroup.getEndRes() + 1;
1974 end = alignment.getWidth();
1976 viscontigs = colSel.getVisibleContigs(start, end);
1981 * get hash of undo and redo list for the alignment
1983 * @return long[] { historyList.hashCode, redoList.hashCode };
1985 public long[] getUndoRedoHash()
1987 if (historyList == null || redoList == null)
1991 { historyList.hashCode(), this.redoList.hashCode() };
1995 * test if a particular set of hashcodes are different to the hashcodes for
1996 * the undo and redo list.
1999 * the stored set of hashcodes as returned by getUndoRedoHash
2000 * @return true if the hashcodes differ (ie the alignment has been edited) or
2001 * the stored hashcode array differs in size
2003 public boolean isUndoRedoHashModified(long[] undoredo)
2005 if (undoredo == null)
2009 long[] cstate = getUndoRedoHash();
2010 if (cstate.length != undoredo.length)
2015 for (int i = 0; i < cstate.length; i++)
2017 if (cstate[i] != undoredo[i])
2025 public boolean getCentreColumnLabels()
2027 return centreColumnLabels;
2030 public void setCentreColumnLabels(boolean centrecolumnlabels)
2032 centreColumnLabels = centrecolumnlabels;
2035 public void updateSequenceIdColours()
2037 Vector groups = alignment.getGroups();
2038 if (sequenceColours == null)
2040 sequenceColours = new Hashtable();
2042 for (int ig = 0, igSize = groups.size(); ig < igSize; ig++)
2044 SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
2045 if (sg.idColour != null)
2047 Vector sqs = sg.getSequences(hiddenRepSequences);
2048 for (int s = 0, sSize = sqs.size(); s < sSize; s++)
2050 sequenceColours.put(sqs.elementAt(s), sg.idColour);
2057 * enable or disable the display of Database Cross References in the sequence
2060 public void setShowDbRefs(boolean show)
2067 * @return true if Database References are to be displayed on tooltips.
2069 public boolean isShowDbRefs()
2076 * @return true if Non-positional features are to be displayed on tooltips.
2078 public boolean isShowNpFeats()
2084 * enable or disable the display of Non-Positional sequence features in the
2085 * sequence ID tooltip
2089 public void setShowNpFeats(boolean show)
2096 * @return true if view has hidden rows
2098 public boolean hasHiddenRows()
2100 return hasHiddenRows;
2105 * @return true if view has hidden columns
2107 public boolean hasHiddenColumns()
2109 return hasHiddenColumns;
2113 * when set, view will scroll to show the highlighted position
2115 public boolean followHighlight = true;
2118 * @return true if view should scroll to show the highlighted region of a
2122 public boolean getFollowHighlight()
2124 return followHighlight;
2127 public boolean followSelection = true;
2130 * @return true if view selection should always follow the selections
2131 * broadcast by other selection sources
2133 public boolean getFollowSelection()
2135 return followSelection;
2138 private long sgrouphash = -1, colselhash = -1;
2140 boolean showSeqFeaturesHeight;
2143 * checks current SelectionGroup against record of last hash value, and
2145 * @param b update the record of last hash value
2147 * @return true if SelectionGroup changed since last call (when b is true)
2149 boolean isSelectionGroupChanged(boolean b)
2151 int hc = (selectionGroup == null || selectionGroup.getSize()==0) ? -1 : selectionGroup.hashCode();
2152 if (hc!=-1 && hc != sgrouphash)
2154 if (b) {sgrouphash = hc;}
2161 * checks current colsel against record of last hash value, and optionally updates
2164 * @param b update the record of last hash value
2165 * @return true if colsel changed since last call (when b is true)
2167 boolean isColSelChanged(boolean b)
2169 int hc = (colSel == null || colSel.size()==0) ? -1 : colSel.hashCode();
2170 if (hc!=-1 && hc != colselhash)
2172 if (b) {colselhash = hc;}
2178 public void sendSelection()
2180 jalview.structure.StructureSelectionManager
2181 .getStructureSelectionManager(Desktop.instance).sendSelection(
2182 new SequenceGroup(getSelectionGroup()),
2183 new ColumnSelection(getColumnSelection()), this);
2186 public void setShowSequenceFeaturesHeight(boolean selected)
2188 showSeqFeaturesHeight = selected;
2191 public boolean getShowSequenceFeaturesHeight()
2193 return showSeqFeaturesHeight;
2196 boolean showUnconserved = false;
2198 public boolean getShowUnconserved()
2200 return showUnconserved;
2203 public void setShowUnconserved(boolean showunconserved)
2205 showUnconserved = showunconserved;
2209 * return the alignPanel containing the given viewport. Use this to get the
2210 * components currently handling the given viewport.
2213 * @return null or an alignPanel guaranteed to have non-null alignFrame
2216 public AlignmentPanel getAlignPanel()
2218 AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(this
2219 .getSequenceSetId());
2220 AlignmentPanel ap = null;
2221 for (int p = 0; aps != null && p < aps.length; p++)
2223 if (aps[p].av == this)
2231 public boolean getSortByTree()
2236 public void setSortByTree(boolean sort)
2242 * should conservation rows be shown for groups
2244 boolean showGroupConservation = false;
2247 * should consensus rows be shown for groups
2249 boolean showGroupConsensus = false;
2252 * should consensus profile be rendered by default
2254 public boolean showSequenceLogo = false;
2257 * should consensus histograms be rendered by default
2259 public boolean showConsensusHistogram = true;
2262 * @return the showConsensusProfile
2264 public boolean isShowSequenceLogo()
2266 return showSequenceLogo;
2270 * @param showSequenceLogo
2273 public void setShowSequenceLogo(boolean showSequenceLogo)
2275 if (showSequenceLogo != this.showSequenceLogo)
2277 // TODO: decouple settings setting from calculation when refactoring
2278 // annotation update method from alignframe to viewport
2279 this.showSequenceLogo = showSequenceLogo;
2280 if (consensusThread != null)
2282 consensusThread.updateAnnotation();
2285 this.showSequenceLogo = showSequenceLogo;
2289 * @param showConsensusHistogram
2290 * the showConsensusHistogram to set
2292 public void setShowConsensusHistogram(boolean showConsensusHistogram)
2294 this.showConsensusHistogram = showConsensusHistogram;
2298 * @return the showGroupConservation
2300 public boolean isShowGroupConservation()
2302 return showGroupConservation;
2306 * @param showGroupConservation
2307 * the showGroupConservation to set
2309 public void setShowGroupConservation(boolean showGroupConservation)
2311 this.showGroupConservation = showGroupConservation;
2315 * @return the showGroupConsensus
2317 public boolean isShowGroupConsensus()
2319 return showGroupConsensus;
2323 * @param showGroupConsensus
2324 * the showGroupConsensus to set
2326 public void setShowGroupConsensus(boolean showGroupConsensus)
2328 this.showGroupConsensus = showGroupConsensus;
2333 * @return flag to indicate if the consensus histogram should be rendered by
2336 public boolean isShowConsensusHistogram()
2338 return this.showConsensusHistogram;
2342 * synthesize a column selection if none exists so it covers the given
2343 * selection group. if wholewidth is false, no column selection is made if the
2344 * selection group covers the whole alignment width.
2349 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2353 && (sgs = sg.getStartRes()) >= 0
2354 && sg.getStartRes() <= (sge = sg.getEndRes())
2355 && (colSel == null || colSel.getSelected() == null || colSel
2356 .getSelected().size() == 0))
2358 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2365 colSel = new ColumnSelection();
2367 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2369 colSel.addElement(cspos);
2374 public StructureSelectionManager getStructureSelectionManager()
2376 return StructureSelectionManager.getStructureSelectionManager(Desktop.instance);
2382 * @return a series of SequenceI arrays, one for each PDBEntry, listing which sequence in the alignment holds a reference to it
2384 public SequenceI[][] collateForPDB(PDBEntry[] pdbEntries)
2386 ArrayList<SequenceI[]> seqvectors = new ArrayList<SequenceI[]>();
2387 for (PDBEntry pdb: pdbEntries) {
2388 ArrayList<SequenceI> seqs = new ArrayList<SequenceI>();
2389 for (int i = 0; i < alignment.getHeight(); i++)
2391 Vector pdbs = alignment.getSequenceAt(i)
2392 .getDatasetSequence().getPDBId();
2396 for (int p = 0; p < pdbs.size(); p++)
2398 PDBEntry p1 = (PDBEntry) pdbs.elementAt(p);
2399 if (p1.getId().equals(pdb.getId()))
2401 if (!seqs.contains(sq=alignment.getSequenceAt(i)))
2408 seqvectors.add(seqs.toArray(new SequenceI[seqs.size()]));
2410 return seqvectors.toArray(new SequenceI[seqvectors.size()][]);