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.BitSet;
45 import java.util.Hashtable;
46 import java.util.List;
48 import java.util.Vector;
51 * base class holding visualization and analysis attributes and common logic for
52 * an active alignment view displayed in the GUI
57 public abstract class AlignmentViewport implements AlignViewportI
60 * alignment displayed in the viewport. Please use get/setter
62 protected AlignmentI alignment;
64 protected String sequenceSetID;
67 * probably unused indicator that view is of a dataset rather than an
70 protected boolean isDataset = false;
72 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
74 protected ColumnSelection colSel = new ColumnSelection();
76 public boolean autoCalculateConsensus = true;
78 protected boolean autoCalculateStrucConsensus = true;
80 protected boolean ignoreGapsInConsensusCalculation = false;
82 protected ColourSchemeI globalColourScheme = null;
85 * gui state - changes to colour scheme propagated to all groups
87 private boolean colourAppliesToAllGroups;
91 * indicating if subsequent colourscheme changes will be propagated
94 public void setColourAppliesToAllGroups(boolean b)
96 colourAppliesToAllGroups = b;
102 * @return flag indicating if colourchanges propagated to all groups
104 public boolean getColourAppliesToAllGroups()
106 return colourAppliesToAllGroups;
109 boolean abovePIDThreshold = false;
114 * @return true if percent identity threshold is applied to shading
116 public boolean getAbovePIDThreshold()
118 return abovePIDThreshold;
126 * indicate if percent identity threshold is applied to shading
128 public void setAbovePIDThreshold(boolean b)
130 abovePIDThreshold = b;
141 public void setThreshold(int thresh)
149 * @return DOCUMENT ME!
151 public int getThreshold()
161 * set the scalar for bleaching colourschemes according to degree of
164 public void setIncrement(int inc)
172 * @return get scalar for bleaching colourschemes by conservation
174 public int getIncrement()
179 boolean conservationColourSelected = false;
184 * @return true if conservation based shading is enabled
186 public boolean getConservationSelected()
188 return conservationColourSelected;
195 * enable conservation based shading
197 public void setConservationSelected(boolean b)
199 conservationColourSelected = b;
203 public void setGlobalColourScheme(ColourSchemeI cs)
205 // TODO: logic refactored from AlignFrame changeColour -
206 // autorecalc stuff should be changed to rely on the worker system
207 // check to see if we should implement a changeColour(cs) method rather than
208 // put th logic in here
209 // - means that caller decides if they want to just modify state and defer
210 // calculation till later or to do all calculations in thread.
212 globalColourScheme = cs;
213 if (getColourAppliesToAllGroups())
215 for (SequenceGroup sg : getAlignment().getGroups())
222 if (cs instanceof ClustalxColourScheme)
224 sg.cs = new ClustalxColourScheme(sg, getHiddenRepSequences());
230 sg.cs = cs.getClass().newInstance();
231 } catch (Exception ex)
233 ex.printStackTrace();
238 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
239 || cs instanceof Blosum62ColourScheme)
241 sg.cs.setThreshold(threshold, getIgnoreGapsConsensus());
242 sg.cs.setConsensus(AAFrequency.calculate(
243 sg.getSequences(getHiddenRepSequences()), 0,
248 sg.cs.setThreshold(0, getIgnoreGapsConsensus());
251 if (getConservationSelected())
253 Conservation c = new Conservation("Group",
254 ResidueProperties.propHash, 3,
255 sg.getSequences(getHiddenRepSequences()), 0,
256 getAlignment().getWidth() - 1);
258 c.verdict(false, getConsPercGaps());
259 sg.cs.setConservation(c);
263 sg.cs.setConservation(null);
264 sg.cs.setThreshold(0, getIgnoreGapsConsensus());
273 public ColourSchemeI getGlobalColourScheme()
275 return globalColourScheme;
278 protected AlignmentAnnotation consensus;
280 protected AlignmentAnnotation strucConsensus;
282 protected AlignmentAnnotation conservation;
284 protected AlignmentAnnotation quality;
286 protected AlignmentAnnotation[] groupConsensus;
288 protected AlignmentAnnotation[] groupConservation;
291 * results of alignment consensus analysis for visible portion of view
293 protected Hashtable[] hconsensus = null;
296 * results of secondary structure base pair consensus for visible portion of
299 protected Hashtable[] hStrucConsensus = null;
302 * percentage gaps allowed in a column before all amino acid properties should
303 * be considered unconserved
305 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
308 public int getConsPercGaps()
314 public void setSequenceConsensusHash(Hashtable[] hconsensus)
316 this.hconsensus = hconsensus;
321 public Hashtable[] getSequenceConsensusHash()
327 public Hashtable[] getRnaStructureConsensusHash()
329 return hStrucConsensus;
333 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
335 this.hStrucConsensus = hStrucConsensus;
340 public AlignmentAnnotation getAlignmentQualityAnnot()
346 public AlignmentAnnotation getAlignmentConservationAnnotation()
352 public AlignmentAnnotation getAlignmentConsensusAnnotation()
358 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
360 return strucConsensus;
363 protected AlignCalcManagerI calculator = new AlignCalcManager();
366 * trigger update of conservation annotation
368 public void updateConservation(final AlignmentViewPanel ap)
370 // see note in mantis : issue number 8585
371 if (alignment.isNucleotide() || conservation == null
372 || !autoCalculateConsensus)
377 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
379 calculator.registerWorker(new jalview.workers.ConservationThread(
385 * trigger update of consensus annotation
387 public void updateConsensus(final AlignmentViewPanel ap)
389 // see note in mantis : issue number 8585
390 if (consensus == null || !autoCalculateConsensus)
394 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
396 calculator.registerWorker(new ConsensusThread(this, ap));
400 // --------START Structure Conservation
401 public void updateStrucConsensus(final AlignmentViewPanel ap)
403 if (autoCalculateStrucConsensus && strucConsensus == null
404 && alignment.isNucleotide() && alignment.hasRNAStructure())
406 // secondary structure has been added - so init the consensus line
410 // see note in mantis : issue number 8585
411 if (strucConsensus == null || !autoCalculateStrucConsensus)
415 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
417 calculator.registerWorker(new StrucConsensusThread(this, ap));
421 public boolean isCalcInProgress()
423 return calculator.isWorking();
427 public boolean isCalculationInProgress(
428 AlignmentAnnotation alignmentAnnotation)
430 if (!alignmentAnnotation.autoCalculated)
432 if (calculator.workingInvolvedWith(alignmentAnnotation))
434 // System.err.println("grey out ("+alignmentAnnotation.label+")");
441 public boolean isClosed()
443 // TODO: check that this isClosed is only true after panel is closed, not
444 // before it is fully constructed.
445 return alignment == null;
449 public AlignCalcManagerI getCalcManager()
455 * should conservation rows be shown for groups
457 protected boolean showGroupConservation = false;
460 * should consensus rows be shown for groups
462 protected boolean showGroupConsensus = false;
465 * should consensus profile be rendered by default
467 protected boolean showSequenceLogo = false;
470 * should consensus profile be rendered normalised to row height
472 protected boolean normaliseSequenceLogo = false;
475 * should consensus histograms be rendered by default
477 protected boolean showConsensusHistogram = true;
480 * @return the showConsensusProfile
483 public boolean isShowSequenceLogo()
485 return showSequenceLogo;
489 * @param showSequenceLogo
492 public void setShowSequenceLogo(boolean showSequenceLogo)
494 if (showSequenceLogo != this.showSequenceLogo)
496 // TODO: decouple settings setting from calculation when refactoring
497 // annotation update method from alignframe to viewport
498 this.showSequenceLogo = showSequenceLogo;
499 calculator.updateAnnotationFor(ConsensusThread.class);
500 calculator.updateAnnotationFor(StrucConsensusThread.class);
502 this.showSequenceLogo = showSequenceLogo;
506 * @param showConsensusHistogram
507 * the showConsensusHistogram to set
509 public void setShowConsensusHistogram(boolean showConsensusHistogram)
511 this.showConsensusHistogram = showConsensusHistogram;
515 * @return the showGroupConservation
517 public boolean isShowGroupConservation()
519 return showGroupConservation;
523 * @param showGroupConservation
524 * the showGroupConservation to set
526 public void setShowGroupConservation(boolean showGroupConservation)
528 this.showGroupConservation = showGroupConservation;
532 * @return the showGroupConsensus
534 public boolean isShowGroupConsensus()
536 return showGroupConsensus;
540 * @param showGroupConsensus
541 * the showGroupConsensus to set
543 public void setShowGroupConsensus(boolean showGroupConsensus)
545 this.showGroupConsensus = showGroupConsensus;
550 * @return flag to indicate if the consensus histogram should be rendered by
554 public boolean isShowConsensusHistogram()
556 return this.showConsensusHistogram;
560 * show non-conserved residues only
562 protected boolean showUnconserved = false;
565 * when set, updateAlignment will always ensure sequences are of equal length
567 private boolean padGaps = false;
570 * when set, alignment should be reordered according to a newly opened tree
572 public boolean sortByTree = false;
574 public boolean getShowUnconserved()
576 return showUnconserved;
579 public void setShowUnconserved(boolean showunconserved)
581 showUnconserved = showunconserved;
585 * @param showNonconserved
586 * the showUnconserved to set
588 public void setShowunconserved(boolean displayNonconserved)
590 this.showUnconserved = displayNonconserved;
596 * @return null or the currently selected sequence region
599 public SequenceGroup getSelectionGroup()
601 return selectionGroup;
605 * Set the selection group for this window.
608 * - group holding references to sequences in this alignment view
612 public void setSelectionGroup(SequenceGroup sg)
617 public void setHiddenColumns(ColumnSelection colsel)
619 this.colSel = colsel;
620 if (colSel.getHiddenColumns() != null)
622 hasHiddenColumns = true;
627 public ColumnSelection getColumnSelection()
632 public void setColumnSelection(ColumnSelection colSel)
634 this.colSel = colSel;
642 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
644 return hiddenRepSequences;
648 public void setHiddenRepSequences(
649 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
651 this.hiddenRepSequences = hiddenRepSequences;
654 protected boolean hasHiddenColumns = false;
656 public void updateHiddenColumns()
658 hasHiddenColumns = colSel.getHiddenColumns() != null;
661 protected boolean hasHiddenRows = false;
663 public boolean hasHiddenRows()
665 return hasHiddenRows;
668 protected SequenceGroup selectionGroup;
670 public void setSequenceSetId(String newid)
672 if (sequenceSetID != null)
675 .println("Warning - overwriting a sequenceSetId for a viewport!");
677 sequenceSetID = new String(newid);
680 public String getSequenceSetId()
682 if (sequenceSetID == null)
684 sequenceSetID = alignment.hashCode() + "";
687 return sequenceSetID;
691 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
694 protected String viewId = null;
696 public String getViewId()
700 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
705 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
707 ignoreGapsInConsensusCalculation = b;
711 if (globalColourScheme != null)
713 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
714 ignoreGapsInConsensusCalculation);
720 private long sgrouphash = -1, colselhash = -1;
723 * checks current SelectionGroup against record of last hash value, and
727 * update the record of last hash value
729 * @return true if SelectionGroup changed since last call (when b is true)
731 public boolean isSelectionGroupChanged(boolean b)
733 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
734 : selectionGroup.hashCode();
735 if (hc != -1 && hc != sgrouphash)
747 * checks current colsel against record of last hash value, and optionally
751 * update the record of last hash value
752 * @return true if colsel changed since last call (when b is true)
754 public boolean isColSelChanged(boolean b)
756 int hc = (colSel == null || colSel.size() == 0) ? -1 : colSel
758 if (hc != -1 && hc != colselhash)
770 public boolean getIgnoreGapsConsensus()
772 return ignoreGapsInConsensusCalculation;
775 // / property change stuff
777 // JBPNote Prolly only need this in the applet version.
778 private final java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
781 protected boolean showConservation = true;
783 protected boolean showQuality = true;
785 protected boolean showConsensus = true;
788 * Property change listener for changes in alignment
793 public void addPropertyChangeListener(
794 java.beans.PropertyChangeListener listener)
796 changeSupport.addPropertyChangeListener(listener);
805 public void removePropertyChangeListener(
806 java.beans.PropertyChangeListener listener)
808 changeSupport.removePropertyChangeListener(listener);
812 * Property change listener for changes in alignment
821 public void firePropertyChange(String prop, Object oldvalue,
824 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
827 // common hide/show column stuff
829 public void hideSelectedColumns()
831 if (colSel.size() < 1)
836 colSel.hideSelectedColumns();
837 setSelectionGroup(null);
839 hasHiddenColumns = true;
842 public void hideColumns(int start, int end)
846 colSel.hideColumns(start);
850 colSel.hideColumns(start, end);
853 hasHiddenColumns = true;
856 public void showColumn(int col)
858 colSel.revealHiddenColumns(col);
859 if (colSel.getHiddenColumns() == null)
861 hasHiddenColumns = false;
865 public void showAllHiddenColumns()
867 colSel.revealAllHiddenColumns();
868 hasHiddenColumns = false;
871 // common hide/show seq stuff
872 public void showAllHiddenSeqs()
874 if (alignment.getHiddenSequences().getSize() > 0)
876 if (selectionGroup == null)
878 selectionGroup = new SequenceGroup();
879 selectionGroup.setEndRes(alignment.getWidth() - 1);
881 Vector tmp = alignment.getHiddenSequences().showAll(
883 for (int t = 0; t < tmp.size(); t++)
885 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
888 hasHiddenRows = false;
889 hiddenRepSequences = null;
891 firePropertyChange("alignment", null, alignment.getSequences());
892 // used to set hasHiddenRows/hiddenRepSequences here, after the property
898 public void showSequence(int index)
900 Vector tmp = alignment.getHiddenSequences().showSequence(index,
904 if (selectionGroup == null)
906 selectionGroup = new SequenceGroup();
907 selectionGroup.setEndRes(alignment.getWidth() - 1);
910 for (int t = 0; t < tmp.size(); t++)
912 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
914 // JBPNote: refactor: only update flag if we modified visiblity (used to
915 // do this regardless)
916 if (alignment.getHiddenSequences().getSize() < 1)
918 hasHiddenRows = false;
920 firePropertyChange("alignment", null, alignment.getSequences());
925 public void hideAllSelectedSeqs()
927 if (selectionGroup == null || selectionGroup.getSize() < 1)
932 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
936 setSelectionGroup(null);
939 public void hideSequence(SequenceI[] seq)
943 for (int i = 0; i < seq.length; i++)
945 alignment.getHiddenSequences().hideSequence(seq[i]);
947 hasHiddenRows = true;
948 firePropertyChange("alignment", null, alignment.getSequences());
952 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
954 int sSize = sg.getSize();
960 if (hiddenRepSequences == null)
962 hiddenRepSequences = new Hashtable();
965 hiddenRepSequences.put(repSequence, sg);
967 // Hide all sequences except the repSequence
968 SequenceI[] seqs = new SequenceI[sSize - 1];
970 for (int i = 0; i < sSize; i++)
972 if (sg.getSequenceAt(i) != repSequence)
974 if (index == sSize - 1)
979 seqs[index++] = sg.getSequenceAt(i);
982 sg.setSeqrep(repSequence); // note: not done in 2.7applet
983 sg.setHidereps(true); // note: not done in 2.7applet
988 public boolean isHiddenRepSequence(SequenceI seq)
990 return hiddenRepSequences != null
991 && hiddenRepSequences.containsKey(seq);
994 public SequenceGroup getRepresentedSequences(SequenceI seq)
996 return (SequenceGroup) (hiddenRepSequences == null ? null
997 : hiddenRepSequences.get(seq));
1000 public int adjustForHiddenSeqs(int alignmentIndex)
1002 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1006 // Selection manipulation
1008 * broadcast selection to any interested parties
1010 public abstract void sendSelection();
1012 public void invertColumnSelection()
1014 colSel.invertColumnSelection(0, alignment.getWidth());
1018 * This method returns an array of new SequenceI objects derived from the
1019 * whole alignment or just the current selection with start and end points
1022 * @note if you need references to the actual SequenceI objects in the
1023 * alignment or currently selected then use getSequenceSelection()
1024 * @return selection as new sequenceI objects
1026 public SequenceI[] getSelectionAsNewSequence()
1028 SequenceI[] sequences;
1029 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1030 // this was the only caller in the applet for this method
1031 // JBPNote: in applet, this method returned references to the alignment
1032 // sequences, and it did not honour the presence/absence of annotation
1033 // attached to the alignment (probably!)
1034 if (selectionGroup == null || selectionGroup.getSize() == 0)
1036 sequences = alignment.getSequencesArray();
1037 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1038 for (int i = 0; i < sequences.length; i++)
1040 sequences[i] = new Sequence(sequences[i], annots); // construct new
1042 // subset of visible
1048 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1055 * get the currently selected sequence objects or all the sequences in the
1058 * @return array of references to sequence objects
1061 public SequenceI[] getSequenceSelection()
1063 SequenceI[] sequences = null;
1064 if (selectionGroup != null)
1066 sequences = selectionGroup.getSequencesInOrder(alignment);
1068 if (sequences == null)
1070 sequences = alignment.getSequencesArray();
1076 * This method returns the visible alignment as text, as seen on the GUI, ie
1077 * if columns are hidden they will not be returned in the result. Use this for
1078 * calculating trees, PCA, redundancy etc on views which contain hidden
1084 public jalview.datamodel.CigarArray getViewAsCigars(
1085 boolean selectedRegionOnly)
1087 return new jalview.datamodel.CigarArray(alignment,
1088 (hasHiddenColumns ? colSel : null),
1089 (selectedRegionOnly ? selectionGroup : null));
1093 * return a compact representation of the current alignment selection to pass
1094 * to an analysis function
1096 * @param selectedOnly
1097 * boolean true to just return the selected view
1098 * @return AlignmentView
1101 public jalview.datamodel.AlignmentView getAlignmentView(
1102 boolean selectedOnly)
1104 return getAlignmentView(selectedOnly, false);
1108 * return a compact representation of the current alignment selection to pass
1109 * to an analysis function
1111 * @param selectedOnly
1112 * boolean true to just return the selected view
1114 * boolean true to annotate the alignment view with groups on the
1115 * alignment (and intersecting with selected region if selectedOnly
1117 * @return AlignmentView
1120 public jalview.datamodel.AlignmentView getAlignmentView(
1121 boolean selectedOnly, boolean markGroups)
1123 return new AlignmentView(alignment, colSel, selectionGroup,
1124 hasHiddenColumns, selectedOnly, markGroups);
1128 * This method returns the visible alignment as text, as seen on the GUI, ie
1129 * if columns are hidden they will not be returned in the result. Use this for
1130 * calculating trees, PCA, redundancy etc on views which contain hidden
1136 public String[] getViewAsString(boolean selectedRegionOnly)
1138 String[] selection = null;
1139 SequenceI[] seqs = null;
1141 int start = 0, end = 0;
1142 if (selectedRegionOnly && selectionGroup != null)
1144 iSize = selectionGroup.getSize();
1145 seqs = selectionGroup.getSequencesInOrder(alignment);
1146 start = selectionGroup.getStartRes();
1147 end = selectionGroup.getEndRes() + 1;
1151 iSize = alignment.getHeight();
1152 seqs = alignment.getSequencesArray();
1153 end = alignment.getWidth();
1156 selection = new String[iSize];
1157 if (hasHiddenColumns)
1159 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1163 for (i = 0; i < iSize; i++)
1165 selection[i] = seqs[i].getSequenceAsString(start, end);
1173 * return visible region boundaries within given column range
1176 * first column (inclusive, from 0)
1178 * last column (exclusive)
1179 * @return int[][] range of {start,end} visible positions
1181 public int[][] getVisibleRegionBoundaries(int min, int max)
1183 Vector regions = new Vector();
1189 if (hasHiddenColumns)
1193 start = colSel.adjustForHiddenColumns(start);
1196 end = colSel.getHiddenBoundaryRight(start);
1207 regions.addElement(new int[]
1210 if (hasHiddenColumns)
1212 start = colSel.adjustForHiddenColumns(end);
1213 start = colSel.getHiddenBoundaryLeft(start) + 1;
1215 } while (end < max);
1217 int[][] startEnd = new int[regions.size()][2];
1219 regions.copyInto(startEnd);
1226 * @return the padGaps
1228 public boolean isPadGaps()
1235 * the padGaps to set
1237 public void setPadGaps(boolean padGaps)
1239 this.padGaps = padGaps;
1243 * apply any post-edit constraints and trigger any calculations needed after
1244 * an edit has been performed on the alignment
1248 public void alignmentChanged(AlignmentViewPanel ap)
1252 alignment.padGaps();
1254 if (autoCalculateConsensus)
1256 updateConsensus(ap);
1258 if (hconsensus != null && autoCalculateConsensus)
1260 updateConservation(ap);
1262 if (autoCalculateStrucConsensus)
1264 updateStrucConsensus(ap);
1267 // Reset endRes of groups if beyond alignment width
1268 int alWidth = alignment.getWidth();
1269 List<SequenceGroup> groups = alignment.getGroups();
1272 for (SequenceGroup sg : groups)
1274 if (sg.getEndRes() > alWidth)
1276 sg.setEndRes(alWidth - 1);
1281 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1283 selectionGroup.setEndRes(alWidth - 1);
1286 resetAllColourSchemes();
1287 calculator.restartWorkers();
1288 // alignment.adjustSequenceAnnotations();
1292 * reset scope and do calculations for all applied colourschemes on alignment
1294 void resetAllColourSchemes()
1296 ColourSchemeI cs = globalColourScheme;
1299 cs.alignmentChanged(alignment, null);
1301 cs.setConsensus(hconsensus);
1302 if (cs.conservationApplied())
1304 cs.setConservation(Conservation.calculateConservation("All",
1305 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1306 alignment.getWidth(), false, getConsPercGaps(), false));
1310 for (SequenceGroup sg : alignment.getGroups())
1314 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1316 sg.recalcConservation();
1320 protected void initAutoAnnotation()
1322 // TODO: add menu option action that nulls or creates consensus object
1323 // depending on if the user wants to see the annotation or not in a
1324 // specific alignment
1326 if (hconsensus == null && !isDataset)
1328 if (!alignment.isNucleotide())
1341 private void initConsensus()
1344 consensus = new AlignmentAnnotation("Consensus", "PID",
1345 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1346 consensus.hasText = true;
1347 consensus.autoCalculated = true;
1351 alignment.addAnnotation(consensus);
1355 private void initConservation()
1357 if (showConservation)
1359 if (conservation == null)
1361 conservation = new AlignmentAnnotation("Conservation",
1362 "Conservation of total alignment less than "
1363 + getConsPercGaps() + "% gaps",
1364 new Annotation[1], 0f, 11f,
1365 AlignmentAnnotation.BAR_GRAPH);
1366 conservation.hasText = true;
1367 conservation.autoCalculated = true;
1368 alignment.addAnnotation(conservation);
1372 private void initQuality()
1376 if (quality == null)
1378 quality = new AlignmentAnnotation("Quality",
1379 "Alignment Quality based on Blosum62 scores",
1380 new Annotation[1], 0f, 11f,
1381 AlignmentAnnotation.BAR_GRAPH);
1382 quality.hasText = true;
1383 quality.autoCalculated = true;
1384 alignment.addAnnotation(quality);
1388 private void initRNAStructure()
1390 if (alignment.hasRNAStructure() && strucConsensus==null)
1392 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1393 new Annotation[1], 0f, 100f,
1394 AlignmentAnnotation.BAR_GRAPH);
1395 strucConsensus.hasText = true;
1396 strucConsensus.autoCalculated = true;
1400 alignment.addAnnotation(strucConsensus);
1407 * @see jalview.api.AlignViewportI#calcPanelHeight()
1409 public int calcPanelHeight()
1411 // setHeight of panels
1412 AlignmentAnnotation[] aa = getAlignment().getAlignmentAnnotation();
1414 int charHeight = getCharHeight();
1417 BitSet graphgrp = new BitSet();
1418 for (int i = 0; i < aa.length; i++)
1422 System.err.println("Null annotation row: ignoring.");
1429 if (aa[i].graphGroup > -1)
1431 if (graphgrp.get(aa[i].graphGroup))
1437 graphgrp.set(aa[i].graphGroup);
1444 aa[i].height += charHeight;
1452 if (aa[i].graph > 0)
1454 aa[i].height += aa[i].graphHeight;
1457 if (aa[i].height == 0)
1462 height += aa[i].height;
1474 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1475 boolean preserveNewGroupSettings)
1477 boolean updateCalcs = false;
1478 boolean conv = isShowGroupConservation();
1479 boolean cons = isShowGroupConsensus();
1480 boolean showprf = isShowSequenceLogo();
1481 boolean showConsHist = isShowConsensusHistogram();
1482 boolean normLogo = isNormaliseSequenceLogo();
1485 * TODO reorder the annotation rows according to group/sequence ordering on
1488 boolean sortg = true;
1490 // remove old automatic annotation
1491 // add any new annotation
1493 // intersect alignment annotation with alignment groups
1495 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
1496 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
1499 for (int an = 0; an < aan.length; an++)
1501 if (aan[an].autoCalculated && aan[an].groupRef != null)
1503 oldrfs.add(aan[an].groupRef);
1504 alignment.deleteAnnotation(aan[an]);
1509 if (alignment.getGroups() != null)
1511 for (SequenceGroup sg : alignment.getGroups())
1513 updateCalcs = false;
1514 if (applyGlobalSettings
1515 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
1517 // set defaults for this group's conservation/consensus
1518 sg.setshowSequenceLogo(showprf);
1519 sg.setShowConsensusHistogram(showConsHist);
1520 sg.setNormaliseSequenceLogo(normLogo);
1525 alignment.addAnnotation(sg.getConservationRow(), 0);
1530 alignment.addAnnotation(sg.getConsensus(), 0);
1532 // refresh the annotation rows
1535 sg.recalcConservation();