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.AAFrequency;
24 import jalview.analysis.Conservation;
25 import jalview.api.AlignCalcManagerI;
26 import jalview.api.AlignViewportI;
27 import jalview.api.AlignmentViewPanel;
28 import jalview.datamodel.AlignmentAnnotation;
29 import jalview.datamodel.AlignmentI;
30 import jalview.datamodel.AlignmentView;
31 import jalview.datamodel.Annotation;
32 import jalview.datamodel.ColumnSelection;
33 import jalview.datamodel.Sequence;
34 import jalview.datamodel.SequenceCollectionI;
35 import jalview.datamodel.SequenceGroup;
36 import jalview.datamodel.SequenceI;
37 import jalview.schemes.Blosum62ColourScheme;
38 import jalview.schemes.ClustalxColourScheme;
39 import jalview.schemes.ColourSchemeI;
40 import jalview.schemes.PIDColourScheme;
41 import jalview.schemes.ResidueProperties;
42 import jalview.workers.AlignCalcManager;
43 import jalview.workers.ConsensusThread;
44 import jalview.workers.StrucConsensusThread;
46 import java.awt.Color;
47 import java.util.ArrayList;
48 import java.util.BitSet;
49 import java.util.Hashtable;
50 import java.util.List;
52 import java.util.Vector;
55 * base class holding visualization and analysis attributes and common logic for
56 * an active alignment view displayed in the GUI
61 public abstract class AlignmentViewport implements AlignViewportI
64 * alignment displayed in the viewport. Please use get/setter
66 protected AlignmentI alignment;
68 protected String sequenceSetID;
71 * probably unused indicator that view is of a dataset rather than an
74 protected boolean isDataset = false;
76 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
78 protected ColumnSelection colSel = new ColumnSelection();
80 public boolean autoCalculateConsensus = true;
82 protected boolean autoCalculateStrucConsensus = true;
84 protected boolean ignoreGapsInConsensusCalculation = false;
86 protected ColourSchemeI globalColourScheme = null;
89 * gui state - changes to colour scheme propagated to all groups
91 private boolean colourAppliesToAllGroups;
95 * indicating if subsequent colourscheme changes will be propagated
98 public void setColourAppliesToAllGroups(boolean b)
100 colourAppliesToAllGroups = b;
106 * @return flag indicating if colourchanges propagated to all groups
108 public boolean getColourAppliesToAllGroups()
110 return colourAppliesToAllGroups;
113 boolean abovePIDThreshold = false;
118 * @return true if percent identity threshold is applied to shading
120 public boolean getAbovePIDThreshold()
122 return abovePIDThreshold;
130 * indicate if percent identity threshold is applied to shading
132 public void setAbovePIDThreshold(boolean b)
134 abovePIDThreshold = b;
145 public void setThreshold(int thresh)
153 * @return DOCUMENT ME!
155 public int getThreshold()
165 * set the scalar for bleaching colourschemes according to degree of
168 public void setIncrement(int inc)
176 * @return get scalar for bleaching colourschemes by conservation
178 public int getIncrement()
183 boolean conservationColourSelected = false;
188 * @return true if conservation based shading is enabled
190 public boolean getConservationSelected()
192 return conservationColourSelected;
199 * enable conservation based shading
201 public void setConservationSelected(boolean b)
203 conservationColourSelected = b;
207 public void setGlobalColourScheme(ColourSchemeI cs)
209 // TODO: logic refactored from AlignFrame changeColour -
210 // autorecalc stuff should be changed to rely on the worker system
211 // check to see if we should implement a changeColour(cs) method rather than
212 // put th logic in here
213 // - means that caller decides if they want to just modify state and defer
214 // calculation till later or to do all calculations in thread.
216 globalColourScheme = cs;
217 boolean recalc = false;
220 cs.setConservationApplied(recalc = getConservationSelected());
221 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
222 || cs instanceof Blosum62ColourScheme)
225 cs.setThreshold(threshold, ignoreGapsInConsensusCalculation);
229 cs.setThreshold(0, ignoreGapsInConsensusCalculation);
233 cs.setConsensus(hconsensus);
234 cs.setConservation(hconservation);
236 cs.alignmentChanged(alignment, hiddenRepSequences);
238 if (getColourAppliesToAllGroups())
240 for (SequenceGroup sg : getAlignment().getGroups())
247 sg.cs = cs.applyTo(sg, getHiddenRepSequences());
248 sg.setConsPercGaps(ConsPercGaps);
249 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
250 || cs instanceof Blosum62ColourScheme)
252 sg.cs.setThreshold(threshold, getIgnoreGapsConsensus());
257 sg.cs.setThreshold(0, getIgnoreGapsConsensus());
260 if (getConservationSelected())
262 sg.cs.setConservationApplied(true);
267 sg.cs.setConservation(null);
268 // sg.cs.setThreshold(0, getIgnoreGapsConsensus());
272 sg.recalcConservation();
276 sg.cs.alignmentChanged(sg, hiddenRepSequences);
284 public ColourSchemeI getGlobalColourScheme()
286 return globalColourScheme;
289 protected AlignmentAnnotation consensus;
291 protected AlignmentAnnotation strucConsensus;
293 protected AlignmentAnnotation conservation;
295 protected AlignmentAnnotation quality;
297 protected AlignmentAnnotation[] groupConsensus;
299 protected AlignmentAnnotation[] groupConservation;
302 * results of alignment consensus analysis for visible portion of view
304 protected Hashtable[] hconsensus = null;
307 * results of secondary structure base pair consensus for visible portion of
310 protected Hashtable[] hStrucConsensus = null;
312 protected Conservation hconservation = null;
315 public void setConservation(Conservation cons)
317 hconservation = cons;
321 * percentage gaps allowed in a column before all amino acid properties should
322 * be considered unconserved
324 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
327 public int getConsPercGaps()
333 public void setSequenceConsensusHash(Hashtable[] hconsensus)
335 this.hconsensus = hconsensus;
340 public Hashtable[] getSequenceConsensusHash()
346 public Hashtable[] getRnaStructureConsensusHash()
348 return hStrucConsensus;
352 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
354 this.hStrucConsensus = hStrucConsensus;
359 public AlignmentAnnotation getAlignmentQualityAnnot()
365 public AlignmentAnnotation getAlignmentConservationAnnotation()
371 public AlignmentAnnotation getAlignmentConsensusAnnotation()
377 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
379 return strucConsensus;
382 protected AlignCalcManagerI calculator = new AlignCalcManager();
385 * trigger update of conservation annotation
387 public void updateConservation(final AlignmentViewPanel ap)
389 // see note in mantis : issue number 8585
390 if (alignment.isNucleotide() || conservation == null
391 || !autoCalculateConsensus)
396 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
398 calculator.registerWorker(new jalview.workers.ConservationThread(
404 * trigger update of consensus annotation
406 public void updateConsensus(final AlignmentViewPanel ap)
408 // see note in mantis : issue number 8585
409 if (consensus == null || !autoCalculateConsensus)
413 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
415 calculator.registerWorker(new ConsensusThread(this, ap));
419 // --------START Structure Conservation
420 public void updateStrucConsensus(final AlignmentViewPanel ap)
422 if (autoCalculateStrucConsensus && strucConsensus == null
423 && alignment.isNucleotide() && alignment.hasRNAStructure())
425 // secondary structure has been added - so init the consensus line
429 // see note in mantis : issue number 8585
430 if (strucConsensus == null || !autoCalculateStrucConsensus)
434 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
436 calculator.registerWorker(new StrucConsensusThread(this, ap));
440 public boolean isCalcInProgress()
442 return calculator.isWorking();
446 public boolean isCalculationInProgress(
447 AlignmentAnnotation alignmentAnnotation)
449 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 Vector tmp = alignment.getHiddenSequences().showAll(
904 for (int t = 0; t < tmp.size(); t++)
906 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
909 hasHiddenRows = false;
910 hiddenRepSequences = null;
912 firePropertyChange("alignment", null, alignment.getSequences());
913 // used to set hasHiddenRows/hiddenRepSequences here, after the property
919 public void showSequence(int index)
921 Vector tmp = alignment.getHiddenSequences().showSequence(index,
925 if (selectionGroup == null)
927 selectionGroup = new SequenceGroup();
928 selectionGroup.setEndRes(alignment.getWidth() - 1);
931 for (int t = 0; t < tmp.size(); t++)
933 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
935 // JBPNote: refactor: only update flag if we modified visiblity (used to
936 // do this regardless)
937 if (alignment.getHiddenSequences().getSize() < 1)
939 hasHiddenRows = false;
941 firePropertyChange("alignment", null, alignment.getSequences());
946 public void hideAllSelectedSeqs()
948 if (selectionGroup == null || selectionGroup.getSize() < 1)
953 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
957 setSelectionGroup(null);
960 public void hideSequence(SequenceI[] seq)
964 for (int i = 0; i < seq.length; i++)
966 alignment.getHiddenSequences().hideSequence(seq[i]);
968 hasHiddenRows = true;
969 firePropertyChange("alignment", null, alignment.getSequences());
973 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
975 int sSize = sg.getSize();
981 if (hiddenRepSequences == null)
983 hiddenRepSequences = new Hashtable();
986 hiddenRepSequences.put(repSequence, sg);
988 // Hide all sequences except the repSequence
989 SequenceI[] seqs = new SequenceI[sSize - 1];
991 for (int i = 0; i < sSize; i++)
993 if (sg.getSequenceAt(i) != repSequence)
995 if (index == sSize - 1)
1000 seqs[index++] = sg.getSequenceAt(i);
1003 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1004 sg.setHidereps(true); // note: not done in 2.7applet
1009 public boolean isHiddenRepSequence(SequenceI seq)
1011 return hiddenRepSequences != null
1012 && hiddenRepSequences.containsKey(seq);
1015 public SequenceGroup getRepresentedSequences(SequenceI seq)
1017 return (SequenceGroup) (hiddenRepSequences == null ? null
1018 : hiddenRepSequences.get(seq));
1021 public int adjustForHiddenSeqs(int alignmentIndex)
1023 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1027 // Selection manipulation
1029 * broadcast selection to any interested parties
1031 public abstract void sendSelection();
1033 public void invertColumnSelection()
1035 colSel.invertColumnSelection(0, alignment.getWidth());
1039 * This method returns an array of new SequenceI objects derived from the
1040 * whole alignment or just the current selection with start and end points
1043 * @note if you need references to the actual SequenceI objects in the
1044 * alignment or currently selected then use getSequenceSelection()
1045 * @return selection as new sequenceI objects
1047 public SequenceI[] getSelectionAsNewSequence()
1049 SequenceI[] sequences;
1050 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1051 // this was the only caller in the applet for this method
1052 // JBPNote: in applet, this method returned references to the alignment
1053 // sequences, and it did not honour the presence/absence of annotation
1054 // attached to the alignment (probably!)
1055 if (selectionGroup == null || selectionGroup.getSize() == 0)
1057 sequences = alignment.getSequencesArray();
1058 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1059 for (int i = 0; i < sequences.length; i++)
1061 sequences[i] = new Sequence(sequences[i], annots); // construct new
1063 // subset of visible
1069 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1076 * get the currently selected sequence objects or all the sequences in the
1079 * @return array of references to sequence objects
1082 public SequenceI[] getSequenceSelection()
1084 SequenceI[] sequences = null;
1085 if (selectionGroup != null)
1087 sequences = selectionGroup.getSequencesInOrder(alignment);
1089 if (sequences == null)
1091 sequences = alignment.getSequencesArray();
1097 * This method returns the visible alignment as text, as seen on the GUI, ie
1098 * if columns are hidden they will not be returned in the result. Use this for
1099 * calculating trees, PCA, redundancy etc on views which contain hidden
1105 public jalview.datamodel.CigarArray getViewAsCigars(
1106 boolean selectedRegionOnly)
1108 return new jalview.datamodel.CigarArray(alignment,
1109 (hasHiddenColumns ? colSel : null),
1110 (selectedRegionOnly ? selectionGroup : null));
1114 * return a compact representation of the current alignment selection to pass
1115 * to an analysis function
1117 * @param selectedOnly
1118 * boolean true to just return the selected view
1119 * @return AlignmentView
1122 public jalview.datamodel.AlignmentView getAlignmentView(
1123 boolean selectedOnly)
1125 return getAlignmentView(selectedOnly, false);
1129 * return a compact representation of the current alignment selection to pass
1130 * to an analysis function
1132 * @param selectedOnly
1133 * boolean true to just return the selected view
1135 * boolean true to annotate the alignment view with groups on the
1136 * alignment (and intersecting with selected region if selectedOnly
1138 * @return AlignmentView
1141 public jalview.datamodel.AlignmentView getAlignmentView(
1142 boolean selectedOnly, boolean markGroups)
1144 return new AlignmentView(alignment, colSel, selectionGroup,
1145 hasHiddenColumns, selectedOnly, markGroups);
1149 * This method returns the visible alignment as text, as seen on the GUI, ie
1150 * if columns are hidden they will not be returned in the result. Use this for
1151 * calculating trees, PCA, redundancy etc on views which contain hidden
1157 public String[] getViewAsString(boolean selectedRegionOnly)
1159 String[] selection = null;
1160 SequenceI[] seqs = null;
1162 int start = 0, end = 0;
1163 if (selectedRegionOnly && selectionGroup != null)
1165 iSize = selectionGroup.getSize();
1166 seqs = selectionGroup.getSequencesInOrder(alignment);
1167 start = selectionGroup.getStartRes();
1168 end = selectionGroup.getEndRes() + 1;
1172 iSize = alignment.getHeight();
1173 seqs = alignment.getSequencesArray();
1174 end = alignment.getWidth();
1177 selection = new String[iSize];
1178 if (hasHiddenColumns)
1180 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1184 for (i = 0; i < iSize; i++)
1186 selection[i] = seqs[i].getSequenceAsString(start, end);
1194 * return visible region boundaries within given column range
1197 * first column (inclusive, from 0)
1199 * last column (exclusive)
1200 * @return int[][] range of {start,end} visible positions
1202 public int[][] getVisibleRegionBoundaries(int min, int max)
1204 Vector regions = new Vector();
1210 if (hasHiddenColumns)
1214 start = colSel.adjustForHiddenColumns(start);
1217 end = colSel.getHiddenBoundaryRight(start);
1228 regions.addElement(new int[]
1231 if (hasHiddenColumns)
1233 start = colSel.adjustForHiddenColumns(end);
1234 start = colSel.getHiddenBoundaryLeft(start) + 1;
1236 } while (end < max);
1238 int[][] startEnd = new int[regions.size()][2];
1240 regions.copyInto(startEnd);
1247 * @return the padGaps
1249 public boolean isPadGaps()
1256 * the padGaps to set
1258 public void setPadGaps(boolean padGaps)
1260 this.padGaps = padGaps;
1264 * apply any post-edit constraints and trigger any calculations needed after
1265 * an edit has been performed on the alignment
1269 public void alignmentChanged(AlignmentViewPanel ap)
1273 alignment.padGaps();
1275 if (autoCalculateConsensus)
1277 updateConsensus(ap);
1279 if (hconsensus != null && autoCalculateConsensus)
1281 updateConservation(ap);
1283 if (autoCalculateStrucConsensus)
1285 updateStrucConsensus(ap);
1288 // Reset endRes of groups if beyond alignment width
1289 int alWidth = alignment.getWidth();
1290 List<SequenceGroup> groups = alignment.getGroups();
1293 for (SequenceGroup sg : groups)
1295 if (sg.getEndRes() > alWidth)
1297 sg.setEndRes(alWidth - 1);
1302 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1304 selectionGroup.setEndRes(alWidth - 1);
1307 resetAllColourSchemes();
1308 calculator.restartWorkers();
1309 // alignment.adjustSequenceAnnotations();
1313 * reset scope and do calculations for all applied colourschemes on alignment
1315 void resetAllColourSchemes()
1317 ColourSchemeI cs = globalColourScheme;
1320 cs.alignmentChanged(alignment, hiddenRepSequences);
1322 cs.setConsensus(hconsensus);
1323 if (cs.conservationApplied())
1325 cs.setConservation(Conservation.calculateConservation("All",
1326 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1327 alignment.getWidth(), false, getConsPercGaps(), false));
1331 for (SequenceGroup sg : alignment.getGroups())
1335 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1337 sg.recalcConservation();
1341 protected void initAutoAnnotation()
1343 // TODO: add menu option action that nulls or creates consensus object
1344 // depending on if the user wants to see the annotation or not in a
1345 // specific alignment
1347 if (hconsensus == null && !isDataset)
1349 if (!alignment.isNucleotide())
1362 private void initConsensus()
1365 consensus = new AlignmentAnnotation("Consensus", "PID",
1366 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1367 consensus.hasText = true;
1368 consensus.autoCalculated = true;
1372 alignment.addAnnotation(consensus);
1376 private void initConservation()
1378 if (showConservation)
1380 if (conservation == null)
1382 conservation = new AlignmentAnnotation("Conservation",
1383 "Conservation of total alignment less than "
1384 + getConsPercGaps() + "% gaps", new Annotation[1],
1385 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1386 conservation.hasText = true;
1387 conservation.autoCalculated = true;
1388 alignment.addAnnotation(conservation);
1393 private void initQuality()
1397 if (quality == null)
1399 quality = new AlignmentAnnotation("Quality",
1400 "Alignment Quality based on Blosum62 scores",
1401 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1402 quality.hasText = true;
1403 quality.autoCalculated = true;
1404 alignment.addAnnotation(quality);
1409 private void initRNAStructure()
1411 if (alignment.hasRNAStructure() && strucConsensus == null)
1413 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1414 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1415 strucConsensus.hasText = true;
1416 strucConsensus.autoCalculated = true;
1420 alignment.addAnnotation(strucConsensus);
1428 * @see jalview.api.AlignViewportI#calcPanelHeight()
1430 public int calcPanelHeight()
1432 // setHeight of panels
1433 AlignmentAnnotation[] aa = getAlignment().getAlignmentAnnotation();
1435 int charHeight = getCharHeight();
1438 BitSet graphgrp = new BitSet();
1439 for (int i = 0; i < aa.length; i++)
1443 System.err.println("Null annotation row: ignoring.");
1450 if (aa[i].graphGroup > -1)
1452 if (graphgrp.get(aa[i].graphGroup))
1458 graphgrp.set(aa[i].graphGroup);
1465 aa[i].height += charHeight;
1473 if (aa[i].graph > 0)
1475 aa[i].height += aa[i].graphHeight;
1478 if (aa[i].height == 0)
1483 height += aa[i].height;
1495 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1496 boolean preserveNewGroupSettings)
1498 boolean updateCalcs = false;
1499 boolean conv = isShowGroupConservation();
1500 boolean cons = isShowGroupConsensus();
1501 boolean showprf = isShowSequenceLogo();
1502 boolean showConsHist = isShowConsensusHistogram();
1503 boolean normLogo = isNormaliseSequenceLogo();
1506 * TODO reorder the annotation rows according to group/sequence ordering on
1509 boolean sortg = true;
1511 // remove old automatic annotation
1512 // add any new annotation
1514 // intersect alignment annotation with alignment groups
1516 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
1517 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
1520 for (int an = 0; an < aan.length; an++)
1522 if (aan[an].autoCalculated && aan[an].groupRef != null)
1524 oldrfs.add(aan[an].groupRef);
1525 alignment.deleteAnnotation(aan[an], false);
1529 if (alignment.getGroups() != null)
1531 for (SequenceGroup sg : alignment.getGroups())
1533 updateCalcs = false;
1534 if (applyGlobalSettings
1535 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
1537 // set defaults for this group's conservation/consensus
1538 sg.setshowSequenceLogo(showprf);
1539 sg.setShowConsensusHistogram(showConsHist);
1540 sg.setNormaliseSequenceLogo(normLogo);
1545 alignment.addAnnotation(sg.getConservationRow(), 0);
1550 alignment.addAnnotation(sg.getConsensus(), 0);
1552 // refresh the annotation rows
1555 sg.recalcConservation();
1563 public Color getSequenceColour(SequenceI seq)
1565 Color sqc = Color.white;
1566 if (sequenceColours != null)
1568 sqc = (Color) sequenceColours.get(seq);
1578 public void setSequenceColour(SequenceI seq, Color col)
1580 if (sequenceColours == null)
1582 sequenceColours = new Hashtable();
1587 sequenceColours.remove(seq);
1591 sequenceColours.put(seq, col);
1596 public void updateSequenceIdColours()
1598 if (sequenceColours == null)
1600 sequenceColours = new Hashtable();
1602 for (SequenceGroup sg : alignment.getGroups())
1604 if (sg.idColour != null)
1606 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
1608 sequenceColours.put(s, sg.idColour);
1615 public void clearSequenceColours()
1617 sequenceColours = null;