2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.viewmodel;
23 import jalview.analysis.Conservation;
24 import jalview.api.AlignCalcManagerI;
25 import jalview.api.AlignViewportI;
26 import jalview.api.AlignmentViewPanel;
27 import jalview.datamodel.AlignmentAnnotation;
28 import jalview.datamodel.AlignmentI;
29 import jalview.datamodel.AlignmentView;
30 import jalview.datamodel.Annotation;
31 import jalview.datamodel.ColumnSelection;
32 import jalview.datamodel.Sequence;
33 import jalview.datamodel.SequenceCollectionI;
34 import jalview.datamodel.SequenceGroup;
35 import jalview.datamodel.SequenceI;
36 import jalview.schemes.Blosum62ColourScheme;
37 import jalview.schemes.ColourSchemeI;
38 import jalview.schemes.PIDColourScheme;
39 import jalview.schemes.ResidueProperties;
40 import jalview.workers.AlignCalcManager;
41 import jalview.workers.ConsensusThread;
42 import jalview.workers.StrucConsensusThread;
44 import java.awt.Color;
45 import java.util.ArrayList;
46 import java.util.BitSet;
47 import java.util.Hashtable;
48 import java.util.List;
50 import java.util.Vector;
53 * base class holding visualization and analysis attributes and common logic for
54 * an active alignment view displayed in the GUI
59 public abstract class AlignmentViewport implements AlignViewportI
62 * alignment displayed in the viewport. Please use get/setter
64 protected AlignmentI alignment;
66 protected String sequenceSetID;
69 * probably unused indicator that view is of a dataset rather than an
72 protected boolean isDataset = false;
74 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
76 protected ColumnSelection colSel = new ColumnSelection();
78 public boolean autoCalculateConsensus = true;
80 protected boolean autoCalculateStrucConsensus = true;
82 protected boolean ignoreGapsInConsensusCalculation = false;
84 protected ColourSchemeI globalColourScheme = null;
87 * gui state - changes to colour scheme propagated to all groups
89 private boolean colourAppliesToAllGroups;
93 * indicating if subsequent colourscheme changes will be propagated
96 public void setColourAppliesToAllGroups(boolean b)
98 colourAppliesToAllGroups = b;
104 * @return flag indicating if colourchanges propagated to all groups
106 public boolean getColourAppliesToAllGroups()
108 return colourAppliesToAllGroups;
111 boolean abovePIDThreshold = false;
116 * @return true if percent identity threshold is applied to shading
118 public boolean getAbovePIDThreshold()
120 return abovePIDThreshold;
128 * indicate if percent identity threshold is applied to shading
130 public void setAbovePIDThreshold(boolean b)
132 abovePIDThreshold = b;
143 public void setThreshold(int thresh)
151 * @return DOCUMENT ME!
153 public int getThreshold()
163 * set the scalar for bleaching colourschemes according to degree of
166 public void setIncrement(int inc)
174 * @return get scalar for bleaching colourschemes by conservation
176 public int getIncrement()
181 boolean conservationColourSelected = false;
186 * @return true if conservation based shading is enabled
188 public boolean getConservationSelected()
190 return conservationColourSelected;
197 * enable conservation based shading
199 public void setConservationSelected(boolean b)
201 conservationColourSelected = b;
205 public void setGlobalColourScheme(ColourSchemeI cs)
207 // TODO: logic refactored from AlignFrame changeColour -
208 // autorecalc stuff should be changed to rely on the worker system
209 // check to see if we should implement a changeColour(cs) method rather than
210 // put th logic in here
211 // - means that caller decides if they want to just modify state and defer
212 // calculation till later or to do all calculations in thread.
214 globalColourScheme = cs;
215 boolean recalc = false;
218 cs.setConservationApplied(recalc = getConservationSelected());
219 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
220 || cs instanceof Blosum62ColourScheme)
223 cs.setThreshold(threshold, ignoreGapsInConsensusCalculation);
227 cs.setThreshold(0, ignoreGapsInConsensusCalculation);
231 cs.setConsensus(hconsensus);
232 cs.setConservation(hconservation);
234 cs.alignmentChanged(alignment, hiddenRepSequences);
236 if (getColourAppliesToAllGroups())
238 for (SequenceGroup sg : getAlignment().getGroups())
245 sg.cs = cs.applyTo(sg, getHiddenRepSequences());
246 sg.setConsPercGaps(ConsPercGaps);
247 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
248 || cs instanceof Blosum62ColourScheme)
250 sg.cs.setThreshold(threshold, getIgnoreGapsConsensus());
255 sg.cs.setThreshold(0, getIgnoreGapsConsensus());
258 if (getConservationSelected())
260 sg.cs.setConservationApplied(true);
265 sg.cs.setConservation(null);
266 // sg.cs.setThreshold(0, getIgnoreGapsConsensus());
270 sg.recalcConservation();
274 sg.cs.alignmentChanged(sg, hiddenRepSequences);
282 public ColourSchemeI getGlobalColourScheme()
284 return globalColourScheme;
287 protected AlignmentAnnotation consensus;
289 protected AlignmentAnnotation strucConsensus;
291 protected AlignmentAnnotation conservation;
293 protected AlignmentAnnotation quality;
295 protected AlignmentAnnotation[] groupConsensus;
297 protected AlignmentAnnotation[] groupConservation;
300 * results of alignment consensus analysis for visible portion of view
302 protected Hashtable[] hconsensus = null;
305 * results of secondary structure base pair consensus for visible portion of
308 protected Hashtable[] hStrucConsensus = null;
310 protected Conservation hconservation = null;
313 public void setConservation(Conservation cons)
315 hconservation = cons;
319 * percentage gaps allowed in a column before all amino acid properties should
320 * be considered unconserved
322 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
325 public int getConsPercGaps()
331 public void setSequenceConsensusHash(Hashtable[] hconsensus)
333 this.hconsensus = hconsensus;
338 public Hashtable[] getSequenceConsensusHash()
344 public Hashtable[] getRnaStructureConsensusHash()
346 return hStrucConsensus;
350 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
352 this.hStrucConsensus = hStrucConsensus;
357 public AlignmentAnnotation getAlignmentQualityAnnot()
363 public AlignmentAnnotation getAlignmentConservationAnnotation()
369 public AlignmentAnnotation getAlignmentConsensusAnnotation()
375 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
377 return strucConsensus;
380 protected AlignCalcManagerI calculator = new AlignCalcManager();
383 * trigger update of conservation annotation
385 public void updateConservation(final AlignmentViewPanel ap)
387 // see note in mantis : issue number 8585
388 if (alignment.isNucleotide() || conservation == null
389 || !autoCalculateConsensus)
394 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
396 calculator.registerWorker(new jalview.workers.ConservationThread(
402 * trigger update of consensus annotation
404 public void updateConsensus(final AlignmentViewPanel ap)
406 // see note in mantis : issue number 8585
407 if (consensus == null || !autoCalculateConsensus)
411 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
413 calculator.registerWorker(new ConsensusThread(this, ap));
417 // --------START Structure Conservation
418 public void updateStrucConsensus(final AlignmentViewPanel ap)
420 if (autoCalculateStrucConsensus && strucConsensus == null
421 && alignment.isNucleotide() && alignment.hasRNAStructure())
423 // secondary structure has been added - so init the consensus line
427 // see note in mantis : issue number 8585
428 if (strucConsensus == null || !autoCalculateStrucConsensus)
432 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
434 calculator.registerWorker(new StrucConsensusThread(this, ap));
438 public boolean isCalcInProgress()
440 return calculator.isWorking();
444 public boolean isCalculationInProgress(
445 AlignmentAnnotation alignmentAnnotation)
447 if (!alignmentAnnotation.autoCalculated)
451 if (calculator.workingInvolvedWith(alignmentAnnotation))
453 // System.err.println("grey out ("+alignmentAnnotation.label+")");
460 public boolean isClosed()
462 // TODO: check that this isClosed is only true after panel is closed, not
463 // before it is fully constructed.
464 return alignment == null;
468 public AlignCalcManagerI getCalcManager()
474 * should conservation rows be shown for groups
476 protected boolean showGroupConservation = false;
479 * should consensus rows be shown for groups
481 protected boolean showGroupConsensus = false;
484 * should consensus profile be rendered by default
486 protected boolean showSequenceLogo = false;
489 * should consensus profile be rendered normalised to row height
491 protected boolean normaliseSequenceLogo = false;
494 * should consensus histograms be rendered by default
496 protected boolean showConsensusHistogram = true;
499 * @return the showConsensusProfile
502 public boolean isShowSequenceLogo()
504 return showSequenceLogo;
508 * @param showSequenceLogo
511 public void setShowSequenceLogo(boolean showSequenceLogo)
513 if (showSequenceLogo != this.showSequenceLogo)
515 // TODO: decouple settings setting from calculation when refactoring
516 // annotation update method from alignframe to viewport
517 this.showSequenceLogo = showSequenceLogo;
518 calculator.updateAnnotationFor(ConsensusThread.class);
519 calculator.updateAnnotationFor(StrucConsensusThread.class);
521 this.showSequenceLogo = showSequenceLogo;
525 * @param showConsensusHistogram
526 * the showConsensusHistogram to set
528 public void setShowConsensusHistogram(boolean showConsensusHistogram)
530 this.showConsensusHistogram = showConsensusHistogram;
534 * @return the showGroupConservation
536 public boolean isShowGroupConservation()
538 return showGroupConservation;
542 * @param showGroupConservation
543 * the showGroupConservation to set
545 public void setShowGroupConservation(boolean showGroupConservation)
547 this.showGroupConservation = showGroupConservation;
551 * @return the showGroupConsensus
553 public boolean isShowGroupConsensus()
555 return showGroupConsensus;
559 * @param showGroupConsensus
560 * the showGroupConsensus to set
562 public void setShowGroupConsensus(boolean showGroupConsensus)
564 this.showGroupConsensus = showGroupConsensus;
569 * @return flag to indicate if the consensus histogram should be rendered by
573 public boolean isShowConsensusHistogram()
575 return this.showConsensusHistogram;
579 * show non-conserved residues only
581 protected boolean showUnconserved = false;
584 * when set, updateAlignment will always ensure sequences are of equal length
586 private boolean padGaps = false;
589 * when set, alignment should be reordered according to a newly opened tree
591 public boolean sortByTree = false;
593 public boolean getShowUnconserved()
595 return showUnconserved;
598 public void setShowUnconserved(boolean showunconserved)
600 showUnconserved = showunconserved;
604 * @param showNonconserved
605 * the showUnconserved to set
607 public void setShowunconserved(boolean displayNonconserved)
609 this.showUnconserved = displayNonconserved;
615 * @return null or the currently selected sequence region
618 public SequenceGroup getSelectionGroup()
620 return selectionGroup;
624 * Set the selection group for this window.
627 * - group holding references to sequences in this alignment view
631 public void setSelectionGroup(SequenceGroup sg)
636 public void setHiddenColumns(ColumnSelection colsel)
638 this.colSel = colsel;
639 if (colSel.getHiddenColumns() != null)
641 hasHiddenColumns = true;
646 public ColumnSelection getColumnSelection()
651 public void setColumnSelection(ColumnSelection colSel)
653 this.colSel = colSel;
661 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
663 return hiddenRepSequences;
667 public void setHiddenRepSequences(
668 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
670 this.hiddenRepSequences = hiddenRepSequences;
673 protected boolean hasHiddenColumns = false;
675 public void updateHiddenColumns()
677 hasHiddenColumns = colSel.getHiddenColumns() != null;
680 protected boolean hasHiddenRows = false;
682 public boolean hasHiddenRows()
684 return hasHiddenRows;
687 protected SequenceGroup selectionGroup;
689 public void setSequenceSetId(String newid)
691 if (sequenceSetID != null)
694 .println("Warning - overwriting a sequenceSetId for a viewport!");
696 sequenceSetID = new String(newid);
699 public String getSequenceSetId()
701 if (sequenceSetID == null)
703 sequenceSetID = alignment.hashCode() + "";
706 return sequenceSetID;
710 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
713 protected String viewId = null;
715 public String getViewId()
719 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
724 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
726 ignoreGapsInConsensusCalculation = b;
730 if (globalColourScheme != null)
732 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
733 ignoreGapsInConsensusCalculation);
739 private long sgrouphash = -1, colselhash = -1;
742 * checks current SelectionGroup against record of last hash value, and
746 * update the record of last hash value
748 * @return true if SelectionGroup changed since last call (when b is true)
750 public boolean isSelectionGroupChanged(boolean b)
752 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
753 : selectionGroup.hashCode();
754 if (hc != -1 && hc != sgrouphash)
766 * checks current colsel against record of last hash value, and optionally
770 * update the record of last hash value
771 * @return true if colsel changed since last call (when b is true)
773 public boolean isColSelChanged(boolean b)
775 int hc = (colSel == null || colSel.size() == 0) ? -1 : colSel
777 if (hc != -1 && hc != colselhash)
789 public boolean getIgnoreGapsConsensus()
791 return ignoreGapsInConsensusCalculation;
794 // / property change stuff
796 // JBPNote Prolly only need this in the applet version.
797 private final java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
800 protected boolean showConservation = true;
802 protected boolean showQuality = true;
804 protected boolean showConsensus = true;
806 Hashtable sequenceColours;
809 * Property change listener for changes in alignment
814 public void addPropertyChangeListener(
815 java.beans.PropertyChangeListener listener)
817 changeSupport.addPropertyChangeListener(listener);
826 public void removePropertyChangeListener(
827 java.beans.PropertyChangeListener listener)
829 changeSupport.removePropertyChangeListener(listener);
833 * Property change listener for changes in alignment
842 public void firePropertyChange(String prop, Object oldvalue,
845 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
848 // common hide/show column stuff
850 public void hideSelectedColumns()
852 if (colSel.size() < 1)
857 colSel.hideSelectedColumns();
858 setSelectionGroup(null);
860 hasHiddenColumns = true;
863 public void hideColumns(int start, int end)
867 colSel.hideColumns(start);
871 colSel.hideColumns(start, end);
874 hasHiddenColumns = true;
877 public void showColumn(int col)
879 colSel.revealHiddenColumns(col);
880 if (colSel.getHiddenColumns() == null)
882 hasHiddenColumns = false;
886 public void showAllHiddenColumns()
888 colSel.revealAllHiddenColumns();
889 hasHiddenColumns = false;
892 // common hide/show seq stuff
893 public void showAllHiddenSeqs()
895 if (alignment.getHiddenSequences().getSize() > 0)
897 if (selectionGroup == null)
899 selectionGroup = new SequenceGroup();
900 selectionGroup.setEndRes(alignment.getWidth() - 1);
902 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
904 for (SequenceI seq : tmp)
906 selectionGroup.addSequence(seq, false);
907 setSequenceAnnotationsVisible(seq, true);
910 hasHiddenRows = false;
911 hiddenRepSequences = null;
913 firePropertyChange("alignment", null, alignment.getSequences());
914 // used to set hasHiddenRows/hiddenRepSequences here, after the property
920 public void showSequence(int index)
922 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
927 if (selectionGroup == null)
929 selectionGroup = new SequenceGroup();
930 selectionGroup.setEndRes(alignment.getWidth() - 1);
933 for (SequenceI seq : tmp)
935 selectionGroup.addSequence(seq, false);
936 setSequenceAnnotationsVisible(seq, true);
938 // JBPNote: refactor: only update flag if we modified visiblity (used to
939 // do this regardless)
940 if (alignment.getHiddenSequences().getSize() < 1)
942 hasHiddenRows = false;
944 firePropertyChange("alignment", null, alignment.getSequences());
949 public void hideAllSelectedSeqs()
951 if (selectionGroup == null || selectionGroup.getSize() < 1)
956 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
960 setSelectionGroup(null);
963 public void hideSequence(SequenceI[] seq)
967 for (int i = 0; i < seq.length; i++)
969 alignment.getHiddenSequences().hideSequence(seq[i]);
970 setSequenceAnnotationsVisible(seq[i], false);
972 hasHiddenRows = true;
973 firePropertyChange("alignment", null, alignment.getSequences());
978 * Set visibility for any annotations for the given sequence.
982 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
985 for (AlignmentAnnotation ann : alignment.getAlignmentAnnotation())
987 if (ann.sequenceRef == sequenceI)
989 ann.visible = visible;
994 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
996 int sSize = sg.getSize();
1002 if (hiddenRepSequences == null)
1004 hiddenRepSequences = new Hashtable();
1007 hiddenRepSequences.put(repSequence, sg);
1009 // Hide all sequences except the repSequence
1010 SequenceI[] seqs = new SequenceI[sSize - 1];
1012 for (int i = 0; i < sSize; i++)
1014 if (sg.getSequenceAt(i) != repSequence)
1016 if (index == sSize - 1)
1021 seqs[index++] = sg.getSequenceAt(i);
1024 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1025 sg.setHidereps(true); // note: not done in 2.7applet
1030 public boolean isHiddenRepSequence(SequenceI seq)
1032 return hiddenRepSequences != null
1033 && hiddenRepSequences.containsKey(seq);
1036 public SequenceGroup getRepresentedSequences(SequenceI seq)
1038 return (SequenceGroup) (hiddenRepSequences == null ? null
1039 : hiddenRepSequences.get(seq));
1042 public int adjustForHiddenSeqs(int alignmentIndex)
1044 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1048 // Selection manipulation
1050 * broadcast selection to any interested parties
1052 public abstract void sendSelection();
1054 public void invertColumnSelection()
1056 colSel.invertColumnSelection(0, alignment.getWidth());
1060 * This method returns an array of new SequenceI objects derived from the
1061 * whole alignment or just the current selection with start and end points
1064 * @note if you need references to the actual SequenceI objects in the
1065 * alignment or currently selected then use getSequenceSelection()
1066 * @return selection as new sequenceI objects
1068 public SequenceI[] getSelectionAsNewSequence()
1070 SequenceI[] sequences;
1071 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1072 // this was the only caller in the applet for this method
1073 // JBPNote: in applet, this method returned references to the alignment
1074 // sequences, and it did not honour the presence/absence of annotation
1075 // attached to the alignment (probably!)
1076 if (selectionGroup == null || selectionGroup.getSize() == 0)
1078 sequences = alignment.getSequencesArray();
1079 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1080 for (int i = 0; i < sequences.length; i++)
1082 sequences[i] = new Sequence(sequences[i], annots); // construct new
1084 // subset of visible
1090 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1097 * get the currently selected sequence objects or all the sequences in the
1100 * @return array of references to sequence objects
1103 public SequenceI[] getSequenceSelection()
1105 SequenceI[] sequences = null;
1106 if (selectionGroup != null)
1108 sequences = selectionGroup.getSequencesInOrder(alignment);
1110 if (sequences == null)
1112 sequences = alignment.getSequencesArray();
1118 * This method returns the visible alignment as text, as seen on the GUI, ie
1119 * if columns are hidden they will not be returned in the result. Use this for
1120 * calculating trees, PCA, redundancy etc on views which contain hidden
1126 public jalview.datamodel.CigarArray getViewAsCigars(
1127 boolean selectedRegionOnly)
1129 return new jalview.datamodel.CigarArray(alignment,
1130 (hasHiddenColumns ? colSel : null),
1131 (selectedRegionOnly ? selectionGroup : null));
1135 * return a compact representation of the current alignment selection to pass
1136 * to an analysis function
1138 * @param selectedOnly
1139 * boolean true to just return the selected view
1140 * @return AlignmentView
1143 public jalview.datamodel.AlignmentView getAlignmentView(
1144 boolean selectedOnly)
1146 return getAlignmentView(selectedOnly, false);
1150 * return a compact representation of the current alignment selection to pass
1151 * to an analysis function
1153 * @param selectedOnly
1154 * boolean true to just return the selected view
1156 * boolean true to annotate the alignment view with groups on the
1157 * alignment (and intersecting with selected region if selectedOnly
1159 * @return AlignmentView
1162 public jalview.datamodel.AlignmentView getAlignmentView(
1163 boolean selectedOnly, boolean markGroups)
1165 return new AlignmentView(alignment, colSel, selectionGroup,
1166 hasHiddenColumns, selectedOnly, markGroups);
1170 * This method returns the visible alignment as text, as seen on the GUI, ie
1171 * if columns are hidden they will not be returned in the result. Use this for
1172 * calculating trees, PCA, redundancy etc on views which contain hidden
1178 public String[] getViewAsString(boolean selectedRegionOnly)
1180 String[] selection = null;
1181 SequenceI[] seqs = null;
1183 int start = 0, end = 0;
1184 if (selectedRegionOnly && selectionGroup != null)
1186 iSize = selectionGroup.getSize();
1187 seqs = selectionGroup.getSequencesInOrder(alignment);
1188 start = selectionGroup.getStartRes();
1189 end = selectionGroup.getEndRes() + 1;
1193 iSize = alignment.getHeight();
1194 seqs = alignment.getSequencesArray();
1195 end = alignment.getWidth();
1198 selection = new String[iSize];
1199 if (hasHiddenColumns)
1201 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1205 for (i = 0; i < iSize; i++)
1207 selection[i] = seqs[i].getSequenceAsString(start, end);
1215 * return visible region boundaries within given column range
1218 * first column (inclusive, from 0)
1220 * last column (exclusive)
1221 * @return int[][] range of {start,end} visible positions
1223 public int[][] getVisibleRegionBoundaries(int min, int max)
1225 Vector regions = new Vector();
1231 if (hasHiddenColumns)
1235 start = colSel.adjustForHiddenColumns(start);
1238 end = colSel.getHiddenBoundaryRight(start);
1249 regions.addElement(new int[]
1252 if (hasHiddenColumns)
1254 start = colSel.adjustForHiddenColumns(end);
1255 start = colSel.getHiddenBoundaryLeft(start) + 1;
1257 } while (end < max);
1259 int[][] startEnd = new int[regions.size()][2];
1261 regions.copyInto(startEnd);
1268 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(boolean selectedOnly)
1270 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1271 AlignmentAnnotation[] aa;
1272 if ((aa=alignment.getAlignmentAnnotation())!=null)
1274 for (AlignmentAnnotation annot:aa)
1276 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1277 if (selectedOnly && selectionGroup!=null)
1279 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(), selectionGroup.getEndRes(),clone);
1281 colSel.makeVisibleAnnotation(clone);
1290 * @return the padGaps
1292 public boolean isPadGaps()
1299 * the padGaps to set
1301 public void setPadGaps(boolean padGaps)
1303 this.padGaps = padGaps;
1307 * apply any post-edit constraints and trigger any calculations needed after
1308 * an edit has been performed on the alignment
1312 public void alignmentChanged(AlignmentViewPanel ap)
1316 alignment.padGaps();
1318 if (autoCalculateConsensus)
1320 updateConsensus(ap);
1322 if (hconsensus != null && autoCalculateConsensus)
1324 updateConservation(ap);
1326 if (autoCalculateStrucConsensus)
1328 updateStrucConsensus(ap);
1331 // Reset endRes of groups if beyond alignment width
1332 int alWidth = alignment.getWidth();
1333 List<SequenceGroup> groups = alignment.getGroups();
1336 for (SequenceGroup sg : groups)
1338 if (sg.getEndRes() > alWidth)
1340 sg.setEndRes(alWidth - 1);
1345 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1347 selectionGroup.setEndRes(alWidth - 1);
1350 resetAllColourSchemes();
1351 calculator.restartWorkers();
1352 // alignment.adjustSequenceAnnotations();
1356 * reset scope and do calculations for all applied colourschemes on alignment
1358 void resetAllColourSchemes()
1360 ColourSchemeI cs = globalColourScheme;
1363 cs.alignmentChanged(alignment, hiddenRepSequences);
1365 cs.setConsensus(hconsensus);
1366 if (cs.conservationApplied())
1368 cs.setConservation(Conservation.calculateConservation("All",
1369 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1370 alignment.getWidth(), false, getConsPercGaps(), false));
1374 for (SequenceGroup sg : alignment.getGroups())
1378 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1380 sg.recalcConservation();
1384 protected void initAutoAnnotation()
1386 // TODO: add menu option action that nulls or creates consensus object
1387 // depending on if the user wants to see the annotation or not in a
1388 // specific alignment
1390 if (hconsensus == null && !isDataset)
1392 if (!alignment.isNucleotide())
1405 private void initConsensus()
1408 consensus = new AlignmentAnnotation("Consensus", "PID",
1409 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1410 consensus.hasText = true;
1411 consensus.autoCalculated = true;
1415 alignment.addAnnotation(consensus);
1419 private void initConservation()
1421 if (showConservation)
1423 if (conservation == null)
1425 conservation = new AlignmentAnnotation("Conservation",
1426 "Conservation of total alignment less than "
1427 + getConsPercGaps() + "% gaps", new Annotation[1],
1428 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1429 conservation.hasText = true;
1430 conservation.autoCalculated = true;
1431 alignment.addAnnotation(conservation);
1436 private void initQuality()
1440 if (quality == null)
1442 quality = new AlignmentAnnotation("Quality",
1443 "Alignment Quality based on Blosum62 scores",
1444 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1445 quality.hasText = true;
1446 quality.autoCalculated = true;
1447 alignment.addAnnotation(quality);
1452 private void initRNAStructure()
1454 if (alignment.hasRNAStructure() && strucConsensus == null)
1456 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1457 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1458 strucConsensus.hasText = true;
1459 strucConsensus.autoCalculated = true;
1463 alignment.addAnnotation(strucConsensus);
1471 * @see jalview.api.AlignViewportI#calcPanelHeight()
1473 public int calcPanelHeight()
1475 // setHeight of panels
1476 AlignmentAnnotation[] aa = getAlignment().getAlignmentAnnotation();
1478 int charHeight = getCharHeight();
1481 BitSet graphgrp = new BitSet();
1482 for (int i = 0; i < aa.length; i++)
1486 System.err.println("Null annotation row: ignoring.");
1493 if (aa[i].graphGroup > -1)
1495 if (graphgrp.get(aa[i].graphGroup))
1501 graphgrp.set(aa[i].graphGroup);
1508 aa[i].height += charHeight;
1516 if (aa[i].graph > 0)
1518 aa[i].height += aa[i].graphHeight;
1521 if (aa[i].height == 0)
1526 height += aa[i].height;
1538 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1539 boolean preserveNewGroupSettings)
1541 boolean updateCalcs = false;
1542 boolean conv = isShowGroupConservation();
1543 boolean cons = isShowGroupConsensus();
1544 boolean showprf = isShowSequenceLogo();
1545 boolean showConsHist = isShowConsensusHistogram();
1546 boolean normLogo = isNormaliseSequenceLogo();
1549 * TODO reorder the annotation rows according to group/sequence ordering on
1552 boolean sortg = true;
1554 // remove old automatic annotation
1555 // add any new annotation
1557 // intersect alignment annotation with alignment groups
1559 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
1560 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
1563 for (int an = 0; an < aan.length; an++)
1565 if (aan[an].autoCalculated && aan[an].groupRef != null)
1567 oldrfs.add(aan[an].groupRef);
1568 alignment.deleteAnnotation(aan[an], false);
1572 if (alignment.getGroups() != null)
1574 for (SequenceGroup sg : alignment.getGroups())
1576 updateCalcs = false;
1577 if (applyGlobalSettings
1578 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
1580 // set defaults for this group's conservation/consensus
1581 sg.setshowSequenceLogo(showprf);
1582 sg.setShowConsensusHistogram(showConsHist);
1583 sg.setNormaliseSequenceLogo(normLogo);
1588 alignment.addAnnotation(sg.getConservationRow(), 0);
1593 alignment.addAnnotation(sg.getConsensus(), 0);
1595 // refresh the annotation rows
1598 sg.recalcConservation();
1606 public Color getSequenceColour(SequenceI seq)
1608 Color sqc = Color.white;
1609 if (sequenceColours != null)
1611 sqc = (Color) sequenceColours.get(seq);
1621 public void setSequenceColour(SequenceI seq, Color col)
1623 if (sequenceColours == null)
1625 sequenceColours = new Hashtable();
1630 sequenceColours.remove(seq);
1634 sequenceColours.put(seq, col);
1639 public void updateSequenceIdColours()
1641 if (sequenceColours == null)
1643 sequenceColours = new Hashtable();
1645 for (SequenceGroup sg : alignment.getGroups())
1647 if (sg.idColour != null)
1649 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
1651 sequenceColours.put(s, sg.idColour);
1658 public void clearSequenceColours()
1660 sequenceColours = null;