2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, 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/>.
18 package jalview.viewmodel;
20 import jalview.analysis.AAFrequency;
21 import jalview.analysis.Conservation;
22 import jalview.api.AlignCalcManagerI;
23 import jalview.api.AlignViewportI;
24 import jalview.api.AlignmentViewPanel;
25 import jalview.datamodel.AlignmentAnnotation;
26 import jalview.datamodel.AlignmentI;
27 import jalview.datamodel.AlignmentView;
28 import jalview.datamodel.Annotation;
29 import jalview.datamodel.ColumnSelection;
30 import jalview.datamodel.Sequence;
31 import jalview.datamodel.SequenceCollectionI;
32 import jalview.datamodel.SequenceGroup;
33 import jalview.datamodel.SequenceI;
34 import jalview.schemes.Blosum62ColourScheme;
35 import jalview.schemes.ClustalxColourScheme;
36 import jalview.schemes.ColourSchemeI;
37 import jalview.schemes.PIDColourScheme;
38 import jalview.schemes.ResidueProperties;
39 import jalview.workers.AlignCalcManager;
40 import jalview.workers.ConsensusThread;
41 import jalview.workers.StrucConsensusThread;
43 import java.util.ArrayList;
44 import java.util.Hashtable;
45 import java.util.List;
47 import java.util.Vector;
50 * base class holding visualization and analysis attributes and common logic for
51 * an active alignment view displayed in the GUI
56 public abstract class AlignmentViewport implements AlignViewportI
59 * alignment displayed in the viewport. Please use get/setter
61 protected AlignmentI alignment;
63 protected String sequenceSetID;
66 * probably unused indicator that view is of a dataset rather than an
69 protected boolean isDataset = false;
71 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
73 protected ColumnSelection colSel = new ColumnSelection();
75 public boolean autoCalculateConsensus = true;
77 protected boolean autoCalculateStrucConsensus = true;
79 protected boolean ignoreGapsInConsensusCalculation = false;
81 protected ColourSchemeI globalColourScheme = null;
84 * gui state - changes to colour scheme propagated to all groups
86 private boolean colourAppliesToAllGroups;
90 * indicating if subsequent colourscheme changes will be propagated
93 public void setColourAppliesToAllGroups(boolean b)
95 colourAppliesToAllGroups = b;
101 * @return flag indicating if colourchanges propagated to all groups
103 public boolean getColourAppliesToAllGroups()
105 return colourAppliesToAllGroups;
108 boolean abovePIDThreshold = false;
113 * @return true if percent identity threshold is applied to shading
115 public boolean getAbovePIDThreshold()
117 return abovePIDThreshold;
125 * indicate if percent identity threshold is applied to shading
127 public void setAbovePIDThreshold(boolean b)
129 abovePIDThreshold = b;
140 public void setThreshold(int thresh)
148 * @return DOCUMENT ME!
150 public int getThreshold()
160 * set the scalar for bleaching colourschemes according to degree of
163 public void setIncrement(int inc)
171 * @return get scalar for bleaching colourschemes by conservation
173 public int getIncrement()
178 boolean conservationColourSelected = false;
183 * @return true if conservation based shading is enabled
185 public boolean getConservationSelected()
187 return conservationColourSelected;
194 * enable conservation based shading
196 public void setConservationSelected(boolean b)
198 conservationColourSelected = b;
202 public void setGlobalColourScheme(ColourSchemeI cs)
204 // TODO: logic refactored from AlignFrame changeColour -
205 // autorecalc stuff should be changed to rely on the worker system
206 // check to see if we should implement a changeColour(cs) method rather than
207 // put th logic in here
208 // - means that caller decides if they want to just modify state and defer
209 // calculation till later or to do all calculations in thread.
211 globalColourScheme = cs;
212 if (getColourAppliesToAllGroups())
214 for (SequenceGroup sg : getAlignment().getGroups())
221 if (cs instanceof ClustalxColourScheme)
223 sg.cs = new ClustalxColourScheme(sg, getHiddenRepSequences());
229 sg.cs = cs.getClass().newInstance();
230 } catch (Exception ex)
232 ex.printStackTrace();
237 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
238 || cs instanceof Blosum62ColourScheme)
240 sg.cs.setThreshold(threshold, getIgnoreGapsConsensus());
241 sg.cs.setConsensus(AAFrequency.calculate(
242 sg.getSequences(getHiddenRepSequences()), 0,
247 sg.cs.setThreshold(0, getIgnoreGapsConsensus());
250 if (getConservationSelected())
252 Conservation c = new Conservation("Group",
253 ResidueProperties.propHash, 3,
254 sg.getSequences(getHiddenRepSequences()), 0,
255 getAlignment().getWidth() - 1);
257 c.verdict(false, getConsPercGaps());
258 sg.cs.setConservation(c);
262 sg.cs.setConservation(null);
263 sg.cs.setThreshold(0, getIgnoreGapsConsensus());
272 public ColourSchemeI getGlobalColourScheme()
274 return globalColourScheme;
277 protected AlignmentAnnotation consensus;
279 protected AlignmentAnnotation strucConsensus;
281 protected AlignmentAnnotation conservation;
283 protected AlignmentAnnotation quality;
285 protected AlignmentAnnotation[] groupConsensus;
287 protected AlignmentAnnotation[] groupConservation;
290 * results of alignment consensus analysis for visible portion of view
292 protected Hashtable[] hconsensus = null;
295 * results of secondary structure base pair consensus for visible portion of
298 protected Hashtable[] hStrucConsensus = null;
301 * percentage gaps allowed in a column before all amino acid properties should
302 * be considered unconserved
304 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
307 public int getConsPercGaps()
313 public void setSequenceConsensusHash(Hashtable[] hconsensus)
315 this.hconsensus = hconsensus;
320 public Hashtable[] getSequenceConsensusHash()
326 public Hashtable[] getRnaStructureConsensusHash()
328 return hStrucConsensus;
332 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
334 this.hStrucConsensus = hStrucConsensus;
339 public AlignmentAnnotation getAlignmentQualityAnnot()
345 public AlignmentAnnotation getAlignmentConservationAnnotation()
351 public AlignmentAnnotation getAlignmentConsensusAnnotation()
357 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
359 return strucConsensus;
362 protected AlignCalcManagerI calculator = new AlignCalcManager();
365 * trigger update of conservation annotation
367 public void updateConservation(final AlignmentViewPanel ap)
369 // see note in mantis : issue number 8585
370 if (alignment.isNucleotide() || conservation == null
371 || !autoCalculateConsensus)
376 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
378 calculator.registerWorker(new jalview.workers.ConservationThread(
384 * trigger update of consensus annotation
386 public void updateConsensus(final AlignmentViewPanel ap)
388 // see note in mantis : issue number 8585
389 if (consensus == null || !autoCalculateConsensus)
393 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
395 calculator.registerWorker(new ConsensusThread(this, ap));
399 // --------START Structure Conservation
400 public void updateStrucConsensus(final AlignmentViewPanel ap)
402 if (autoCalculateStrucConsensus && strucConsensus == null
403 && alignment.isNucleotide() && alignment.hasRNAStructure())
408 // see note in mantis : issue number 8585
409 if (strucConsensus == null || !autoCalculateStrucConsensus)
413 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
415 calculator.registerWorker(new StrucConsensusThread(this, ap));
419 public boolean isCalcInProgress()
421 return calculator.isWorking();
425 public boolean isCalculationInProgress(
426 AlignmentAnnotation alignmentAnnotation)
428 if (!alignmentAnnotation.autoCalculated)
430 if (calculator.workingInvolvedWith(alignmentAnnotation))
432 // System.err.println("grey out ("+alignmentAnnotation.label+")");
439 public boolean isClosed()
441 // TODO: check that this isClosed is only true after panel is closed, not
442 // before it is fully constructed.
443 return alignment == null;
447 public AlignCalcManagerI getCalcManager()
453 * should conservation rows be shown for groups
455 protected boolean showGroupConservation = false;
458 * should consensus rows be shown for groups
460 protected boolean showGroupConsensus = false;
463 * should consensus profile be rendered by default
465 protected boolean showSequenceLogo = false;
468 * should consensus profile be rendered normalised to row height
470 protected boolean normaliseSequenceLogo = false;
473 * should consensus histograms be rendered by default
475 protected boolean showConsensusHistogram = true;
478 * @return the showConsensusProfile
481 public boolean isShowSequenceLogo()
483 return showSequenceLogo;
487 * @param showSequenceLogo
490 public void setShowSequenceLogo(boolean showSequenceLogo)
492 if (showSequenceLogo != this.showSequenceLogo)
494 // TODO: decouple settings setting from calculation when refactoring
495 // annotation update method from alignframe to viewport
496 this.showSequenceLogo = showSequenceLogo;
497 calculator.updateAnnotationFor(ConsensusThread.class);
498 calculator.updateAnnotationFor(StrucConsensusThread.class);
500 this.showSequenceLogo = showSequenceLogo;
504 * @param showConsensusHistogram
505 * the showConsensusHistogram to set
507 public void setShowConsensusHistogram(boolean showConsensusHistogram)
509 this.showConsensusHistogram = showConsensusHistogram;
513 * @return the showGroupConservation
515 public boolean isShowGroupConservation()
517 return showGroupConservation;
521 * @param showGroupConservation
522 * the showGroupConservation to set
524 public void setShowGroupConservation(boolean showGroupConservation)
526 this.showGroupConservation = showGroupConservation;
530 * @return the showGroupConsensus
532 public boolean isShowGroupConsensus()
534 return showGroupConsensus;
538 * @param showGroupConsensus
539 * the showGroupConsensus to set
541 public void setShowGroupConsensus(boolean showGroupConsensus)
543 this.showGroupConsensus = showGroupConsensus;
548 * @return flag to indicate if the consensus histogram should be rendered by
552 public boolean isShowConsensusHistogram()
554 return this.showConsensusHistogram;
558 * show non-conserved residues only
560 protected boolean showUnconserved = false;
563 * when set, updateAlignment will always ensure sequences are of equal length
565 private boolean padGaps = false;
568 * when set, alignment should be reordered according to a newly opened tree
570 public boolean sortByTree = false;
572 public boolean getShowUnconserved()
574 return showUnconserved;
577 public void setShowUnconserved(boolean showunconserved)
579 showUnconserved = showunconserved;
583 * @param showNonconserved
584 * the showUnconserved to set
586 public void setShowunconserved(boolean displayNonconserved)
588 this.showUnconserved = displayNonconserved;
594 * @return null or the currently selected sequence region
596 public SequenceGroup getSelectionGroup()
598 return selectionGroup;
602 * Set the selection group for this window.
605 * - group holding references to sequences in this alignment view
608 public void setSelectionGroup(SequenceGroup sg)
613 public void setHiddenColumns(ColumnSelection colsel)
615 this.colSel = colsel;
616 if (colSel.getHiddenColumns() != null)
618 hasHiddenColumns = true;
623 public ColumnSelection getColumnSelection()
628 public void setColumnSelection(ColumnSelection colSel)
630 this.colSel = colSel;
638 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
640 return hiddenRepSequences;
644 public void setHiddenRepSequences(
645 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
647 this.hiddenRepSequences = hiddenRepSequences;
650 protected boolean hasHiddenColumns = false;
652 public void updateHiddenColumns()
654 hasHiddenColumns = colSel.getHiddenColumns() != null;
657 protected boolean hasHiddenRows = false;
659 public boolean hasHiddenRows()
661 return hasHiddenRows;
664 protected SequenceGroup selectionGroup;
666 public void setSequenceSetId(String newid)
668 if (sequenceSetID != null)
671 .println("Warning - overwriting a sequenceSetId for a viewport!");
673 sequenceSetID = new String(newid);
676 public String getSequenceSetId()
678 if (sequenceSetID == null)
680 sequenceSetID = alignment.hashCode() + "";
683 return sequenceSetID;
687 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
690 protected String viewId = null;
692 public String getViewId()
696 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
701 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
703 ignoreGapsInConsensusCalculation = b;
707 if (globalColourScheme != null)
709 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
710 ignoreGapsInConsensusCalculation);
716 private long sgrouphash = -1, colselhash = -1;
719 * checks current SelectionGroup against record of last hash value, and
723 * update the record of last hash value
725 * @return true if SelectionGroup changed since last call (when b is true)
727 public boolean isSelectionGroupChanged(boolean b)
729 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
730 : selectionGroup.hashCode();
731 if (hc != -1 && hc != sgrouphash)
743 * checks current colsel against record of last hash value, and optionally
747 * update the record of last hash value
748 * @return true if colsel changed since last call (when b is true)
750 public boolean isColSelChanged(boolean b)
752 int hc = (colSel == null || colSel.size() == 0) ? -1 : colSel
754 if (hc != -1 && hc != colselhash)
766 public boolean getIgnoreGapsConsensus()
768 return ignoreGapsInConsensusCalculation;
771 // / property change stuff
773 // JBPNote Prolly only need this in the applet version.
774 private final java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
777 protected boolean showConservation = true;
779 protected boolean showQuality = true;
781 protected boolean showConsensus = true;
784 * Property change listener for changes in alignment
789 public void addPropertyChangeListener(
790 java.beans.PropertyChangeListener listener)
792 changeSupport.addPropertyChangeListener(listener);
801 public void removePropertyChangeListener(
802 java.beans.PropertyChangeListener listener)
804 changeSupport.removePropertyChangeListener(listener);
808 * Property change listener for changes in alignment
817 public void firePropertyChange(String prop, Object oldvalue,
820 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
823 // common hide/show column stuff
825 public void hideSelectedColumns()
827 if (colSel.size() < 1)
832 colSel.hideSelectedColumns();
833 setSelectionGroup(null);
835 hasHiddenColumns = true;
838 public void hideColumns(int start, int end)
842 colSel.hideColumns(start);
846 colSel.hideColumns(start, end);
849 hasHiddenColumns = true;
852 public void showColumn(int col)
854 colSel.revealHiddenColumns(col);
855 if (colSel.getHiddenColumns() == null)
857 hasHiddenColumns = false;
861 public void showAllHiddenColumns()
863 colSel.revealAllHiddenColumns();
864 hasHiddenColumns = false;
867 // common hide/show seq stuff
868 public void showAllHiddenSeqs()
870 if (alignment.getHiddenSequences().getSize() > 0)
872 if (selectionGroup == null)
874 selectionGroup = new SequenceGroup();
875 selectionGroup.setEndRes(alignment.getWidth() - 1);
877 Vector tmp = alignment.getHiddenSequences().showAll(
879 for (int t = 0; t < tmp.size(); t++)
881 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
884 hasHiddenRows = false;
885 hiddenRepSequences = null;
887 firePropertyChange("alignment", null, alignment.getSequences());
888 // used to set hasHiddenRows/hiddenRepSequences here, after the property
894 public void showSequence(int index)
896 Vector tmp = alignment.getHiddenSequences().showSequence(index,
900 if (selectionGroup == null)
902 selectionGroup = new SequenceGroup();
903 selectionGroup.setEndRes(alignment.getWidth() - 1);
906 for (int t = 0; t < tmp.size(); t++)
908 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
910 // JBPNote: refactor: only update flag if we modified visiblity (used to
911 // do this regardless)
912 if (alignment.getHiddenSequences().getSize() < 1)
914 hasHiddenRows = false;
916 firePropertyChange("alignment", null, alignment.getSequences());
921 public void hideAllSelectedSeqs()
923 if (selectionGroup == null || selectionGroup.getSize() < 1)
928 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
932 setSelectionGroup(null);
935 public void hideSequence(SequenceI[] seq)
939 for (int i = 0; i < seq.length; i++)
941 alignment.getHiddenSequences().hideSequence(seq[i]);
943 hasHiddenRows = true;
944 firePropertyChange("alignment", null, alignment.getSequences());
948 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
950 int sSize = sg.getSize();
956 if (hiddenRepSequences == null)
958 hiddenRepSequences = new Hashtable();
961 hiddenRepSequences.put(repSequence, sg);
963 // Hide all sequences except the repSequence
964 SequenceI[] seqs = new SequenceI[sSize - 1];
966 for (int i = 0; i < sSize; i++)
968 if (sg.getSequenceAt(i) != repSequence)
970 if (index == sSize - 1)
975 seqs[index++] = sg.getSequenceAt(i);
978 sg.setSeqrep(repSequence); // note: not done in 2.7applet
979 sg.setHidereps(true); // note: not done in 2.7applet
984 public boolean isHiddenRepSequence(SequenceI seq)
986 return hiddenRepSequences != null
987 && hiddenRepSequences.containsKey(seq);
990 public SequenceGroup getRepresentedSequences(SequenceI seq)
992 return (SequenceGroup) (hiddenRepSequences == null ? null
993 : hiddenRepSequences.get(seq));
996 public int adjustForHiddenSeqs(int alignmentIndex)
998 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1002 // Selection manipulation
1004 * broadcast selection to any interested parties
1006 public abstract void sendSelection();
1008 public void invertColumnSelection()
1010 colSel.invertColumnSelection(0, alignment.getWidth());
1014 * This method returns an array of new SequenceI objects derived from the
1015 * whole alignment or just the current selection with start and end points
1018 * @note if you need references to the actual SequenceI objects in the
1019 * alignment or currently selected then use getSequenceSelection()
1020 * @return selection as new sequenceI objects
1022 public SequenceI[] getSelectionAsNewSequence()
1024 SequenceI[] sequences;
1025 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1026 // this was the only caller in the applet for this method
1027 // JBPNote: in applet, this method returned references to the alignment
1028 // sequences, and it did not honour the presence/absence of annotation
1029 // attached to the alignment (probably!)
1030 if (selectionGroup == null || selectionGroup.getSize() == 0)
1032 sequences = alignment.getSequencesArray();
1033 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1034 for (int i = 0; i < sequences.length; i++)
1036 sequences[i] = new Sequence(sequences[i], annots); // construct new
1038 // subset of visible
1044 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1051 * get the currently selected sequence objects or all the sequences in the
1054 * @return array of references to sequence objects
1056 public SequenceI[] getSequenceSelection()
1058 SequenceI[] sequences = null;
1059 if (selectionGroup != null)
1061 sequences = selectionGroup.getSequencesInOrder(alignment);
1063 if (sequences == null)
1065 sequences = alignment.getSequencesArray();
1071 * This method returns the visible alignment as text, as seen on the GUI, ie
1072 * if columns are hidden they will not be returned in the result. Use this for
1073 * calculating trees, PCA, redundancy etc on views which contain hidden
1078 public jalview.datamodel.CigarArray getViewAsCigars(
1079 boolean selectedRegionOnly)
1081 return new jalview.datamodel.CigarArray(alignment,
1082 (hasHiddenColumns ? colSel : null),
1083 (selectedRegionOnly ? selectionGroup : null));
1087 * return a compact representation of the current alignment selection to pass
1088 * to an analysis function
1090 * @param selectedOnly
1091 * boolean true to just return the selected view
1092 * @return AlignmentView
1094 public jalview.datamodel.AlignmentView getAlignmentView(
1095 boolean selectedOnly)
1097 return getAlignmentView(selectedOnly, false);
1101 * return a compact representation of the current alignment selection to pass
1102 * to an analysis function
1104 * @param selectedOnly
1105 * boolean true to just return the selected view
1107 * boolean true to annotate the alignment view with groups on the
1108 * alignment (and intersecting with selected region if selectedOnly
1110 * @return AlignmentView
1112 public jalview.datamodel.AlignmentView getAlignmentView(
1113 boolean selectedOnly, boolean markGroups)
1115 return new AlignmentView(alignment, colSel, selectionGroup,
1116 hasHiddenColumns, selectedOnly, markGroups);
1120 * This method returns the visible alignment as text, as seen on the GUI, ie
1121 * if columns are hidden they will not be returned in the result. Use this for
1122 * calculating trees, PCA, redundancy etc on views which contain hidden
1127 public String[] getViewAsString(boolean selectedRegionOnly)
1129 String[] selection = null;
1130 SequenceI[] seqs = null;
1132 int start = 0, end = 0;
1133 if (selectedRegionOnly && selectionGroup != null)
1135 iSize = selectionGroup.getSize();
1136 seqs = selectionGroup.getSequencesInOrder(alignment);
1137 start = selectionGroup.getStartRes();
1138 end = selectionGroup.getEndRes() + 1;
1142 iSize = alignment.getHeight();
1143 seqs = alignment.getSequencesArray();
1144 end = alignment.getWidth();
1147 selection = new String[iSize];
1148 if (hasHiddenColumns)
1150 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1154 for (i = 0; i < iSize; i++)
1156 selection[i] = seqs[i].getSequenceAsString(start, end);
1164 * return visible region boundaries within given column range
1167 * first column (inclusive, from 0)
1169 * last column (exclusive)
1170 * @return int[][] range of {start,end} visible positions
1172 public int[][] getVisibleRegionBoundaries(int min, int max)
1174 Vector regions = new Vector();
1180 if (hasHiddenColumns)
1184 start = colSel.adjustForHiddenColumns(start);
1187 end = colSel.getHiddenBoundaryRight(start);
1198 regions.addElement(new int[]
1201 if (hasHiddenColumns)
1203 start = colSel.adjustForHiddenColumns(end);
1204 start = colSel.getHiddenBoundaryLeft(start) + 1;
1206 } while (end < max);
1208 int[][] startEnd = new int[regions.size()][2];
1210 regions.copyInto(startEnd);
1217 * @return the padGaps
1219 public boolean isPadGaps()
1226 * the padGaps to set
1228 public void setPadGaps(boolean padGaps)
1230 this.padGaps = padGaps;
1234 * apply any post-edit constraints and trigger any calculations needed after
1235 * an edit has been performed on the alignment
1239 public void alignmentChanged(AlignmentViewPanel ap)
1243 alignment.padGaps();
1245 if (autoCalculateConsensus)
1247 updateConsensus(ap);
1249 if (hconsensus != null && autoCalculateConsensus)
1251 updateConservation(ap);
1253 if (autoCalculateStrucConsensus)
1255 updateStrucConsensus(ap);
1258 // Reset endRes of groups if beyond alignment width
1259 int alWidth = alignment.getWidth();
1260 List<SequenceGroup> groups = alignment.getGroups();
1263 for (SequenceGroup sg : groups)
1265 if (sg.getEndRes() > alWidth)
1267 sg.setEndRes(alWidth - 1);
1272 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1274 selectionGroup.setEndRes(alWidth - 1);
1277 resetAllColourSchemes();
1278 calculator.restartWorkers();
1279 // alignment.adjustSequenceAnnotations();
1283 * reset scope and do calculations for all applied colourschemes on alignment
1285 void resetAllColourSchemes()
1287 ColourSchemeI cs = globalColourScheme;
1290 cs.alignmentChanged(alignment, null);
1292 cs.setConsensus(hconsensus);
1293 if (cs.conservationApplied())
1295 cs.setConservation(Conservation.calculateConservation("All",
1296 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1297 alignment.getWidth(), false, getConsPercGaps(), false));
1301 for (SequenceGroup sg : alignment.getGroups())
1305 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1307 sg.recalcConservation();
1311 protected void initAutoAnnotation()
1313 // TODO: add menu option action that nulls or creates consensus object
1314 // depending on if the user wants to see the annotation or not in a
1315 // specific alignment
1317 if (hconsensus == null && !isDataset)
1319 if (!alignment.isNucleotide())
1321 if (showConservation)
1323 if (conservation == null)
1325 conservation = new AlignmentAnnotation("Conservation",
1326 "Conservation of total alignment less than "
1327 + getConsPercGaps() + "% gaps",
1328 new Annotation[1], 0f, 11f,
1329 AlignmentAnnotation.BAR_GRAPH);
1330 conservation.hasText = true;
1331 conservation.autoCalculated = true;
1332 alignment.addAnnotation(conservation);
1337 if (quality == null)
1339 quality = new AlignmentAnnotation("Quality",
1340 "Alignment Quality based on Blosum62 scores",
1341 new Annotation[1], 0f, 11f,
1342 AlignmentAnnotation.BAR_GRAPH);
1343 quality.hasText = true;
1344 quality.autoCalculated = true;
1345 alignment.addAnnotation(quality);
1351 if (alignment.hasRNAStructure())
1353 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1354 new Annotation[1], 0f, 100f,
1355 AlignmentAnnotation.BAR_GRAPH);
1356 strucConsensus.hasText = true;
1357 strucConsensus.autoCalculated = true;
1361 consensus = new AlignmentAnnotation("Consensus", "PID",
1362 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1363 consensus.hasText = true;
1364 consensus.autoCalculated = true;
1368 alignment.addAnnotation(consensus);
1369 if (strucConsensus != null)
1371 alignment.addAnnotation(strucConsensus);
1380 * @see jalview.api.AlignViewportI#calcPanelHeight()
1382 public int calcPanelHeight()
1384 // setHeight of panels
1385 AlignmentAnnotation[] aa = getAlignment().getAlignmentAnnotation();
1387 int charHeight = getCharHeight();
1390 boolean graphgrp[] = null;
1391 for (int i = 0; i < aa.length; i++)
1395 System.err.println("Null annotation row: ignoring.");
1402 if (aa[i].graphGroup > -1)
1404 if (graphgrp == null)
1406 graphgrp = new boolean[aa.length];
1408 if (graphgrp[aa[i].graphGroup])
1414 graphgrp[aa[i].graphGroup] = true;
1421 aa[i].height += charHeight;
1429 if (aa[i].graph > 0)
1431 aa[i].height += aa[i].graphHeight;
1434 if (aa[i].height == 0)
1439 height += aa[i].height;
1451 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1452 boolean preserveNewGroupSettings)
1454 boolean updateCalcs = false;
1455 boolean conv = isShowGroupConservation();
1456 boolean cons = isShowGroupConsensus();
1457 boolean showprf = isShowSequenceLogo();
1458 boolean showConsHist = isShowConsensusHistogram();
1459 boolean normLogo = isNormaliseSequenceLogo();
1462 * TODO reorder the annotation rows according to group/sequence ordering on
1465 boolean sortg = true;
1467 // remove old automatic annotation
1468 // add any new annotation
1470 // intersect alignment annotation with alignment groups
1472 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
1473 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
1476 for (int an = 0; an < aan.length; an++)
1478 if (aan[an].autoCalculated && aan[an].groupRef != null)
1480 oldrfs.add(aan[an].groupRef);
1481 alignment.deleteAnnotation(aan[an]);
1486 if (alignment.getGroups() != null)
1488 for (SequenceGroup sg : alignment.getGroups())
1490 updateCalcs = false;
1491 if (applyGlobalSettings
1492 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
1494 // set defaults for this group's conservation/consensus
1495 sg.setshowSequenceLogo(showprf);
1496 sg.setShowConsensusHistogram(showConsHist);
1497 sg.setNormaliseSequenceLogo(normLogo);
1502 alignment.addAnnotation(sg.getConservationRow(), 0);
1507 alignment.addAnnotation(sg.getConsensus(), 0);
1509 // refresh the annotation rows
1512 sg.recalcConservation();