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())
405 // secondary structure has been added - so init the consensus line
409 // see note in mantis : issue number 8585
410 if (strucConsensus == null || !autoCalculateStrucConsensus)
414 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
416 calculator.registerWorker(new StrucConsensusThread(this, ap));
420 public boolean isCalcInProgress()
422 return calculator.isWorking();
426 public boolean isCalculationInProgress(
427 AlignmentAnnotation alignmentAnnotation)
429 if (!alignmentAnnotation.autoCalculated)
431 if (calculator.workingInvolvedWith(alignmentAnnotation))
433 // System.err.println("grey out ("+alignmentAnnotation.label+")");
440 public boolean isClosed()
442 // TODO: check that this isClosed is only true after panel is closed, not
443 // before it is fully constructed.
444 return alignment == null;
448 public AlignCalcManagerI getCalcManager()
454 * should conservation rows be shown for groups
456 protected boolean showGroupConservation = false;
459 * should consensus rows be shown for groups
461 protected boolean showGroupConsensus = false;
464 * should consensus profile be rendered by default
466 protected boolean showSequenceLogo = false;
469 * should consensus profile be rendered normalised to row height
471 protected boolean normaliseSequenceLogo = false;
474 * should consensus histograms be rendered by default
476 protected boolean showConsensusHistogram = true;
479 * @return the showConsensusProfile
482 public boolean isShowSequenceLogo()
484 return showSequenceLogo;
488 * @param showSequenceLogo
491 public void setShowSequenceLogo(boolean showSequenceLogo)
493 if (showSequenceLogo != this.showSequenceLogo)
495 // TODO: decouple settings setting from calculation when refactoring
496 // annotation update method from alignframe to viewport
497 this.showSequenceLogo = showSequenceLogo;
498 calculator.updateAnnotationFor(ConsensusThread.class);
499 calculator.updateAnnotationFor(StrucConsensusThread.class);
501 this.showSequenceLogo = showSequenceLogo;
505 * @param showConsensusHistogram
506 * the showConsensusHistogram to set
508 public void setShowConsensusHistogram(boolean showConsensusHistogram)
510 this.showConsensusHistogram = showConsensusHistogram;
514 * @return the showGroupConservation
516 public boolean isShowGroupConservation()
518 return showGroupConservation;
522 * @param showGroupConservation
523 * the showGroupConservation to set
525 public void setShowGroupConservation(boolean showGroupConservation)
527 this.showGroupConservation = showGroupConservation;
531 * @return the showGroupConsensus
533 public boolean isShowGroupConsensus()
535 return showGroupConsensus;
539 * @param showGroupConsensus
540 * the showGroupConsensus to set
542 public void setShowGroupConsensus(boolean showGroupConsensus)
544 this.showGroupConsensus = showGroupConsensus;
549 * @return flag to indicate if the consensus histogram should be rendered by
553 public boolean isShowConsensusHistogram()
555 return this.showConsensusHistogram;
559 * show non-conserved residues only
561 protected boolean showUnconserved = false;
564 * when set, updateAlignment will always ensure sequences are of equal length
566 private boolean padGaps = false;
569 * when set, alignment should be reordered according to a newly opened tree
571 public boolean sortByTree = false;
573 public boolean getShowUnconserved()
575 return showUnconserved;
578 public void setShowUnconserved(boolean showunconserved)
580 showUnconserved = showunconserved;
584 * @param showNonconserved
585 * the showUnconserved to set
587 public void setShowunconserved(boolean displayNonconserved)
589 this.showUnconserved = displayNonconserved;
595 * @return null or the currently selected sequence region
598 public SequenceGroup getSelectionGroup()
600 return selectionGroup;
604 * Set the selection group for this window.
607 * - group holding references to sequences in this alignment view
611 public void setSelectionGroup(SequenceGroup sg)
616 public void setHiddenColumns(ColumnSelection colsel)
618 this.colSel = colsel;
619 if (colSel.getHiddenColumns() != null)
621 hasHiddenColumns = true;
626 public ColumnSelection getColumnSelection()
631 public void setColumnSelection(ColumnSelection colSel)
633 this.colSel = colSel;
641 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
643 return hiddenRepSequences;
647 public void setHiddenRepSequences(
648 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
650 this.hiddenRepSequences = hiddenRepSequences;
653 protected boolean hasHiddenColumns = false;
655 public void updateHiddenColumns()
657 hasHiddenColumns = colSel.getHiddenColumns() != null;
660 protected boolean hasHiddenRows = false;
662 public boolean hasHiddenRows()
664 return hasHiddenRows;
667 protected SequenceGroup selectionGroup;
669 public void setSequenceSetId(String newid)
671 if (sequenceSetID != null)
674 .println("Warning - overwriting a sequenceSetId for a viewport!");
676 sequenceSetID = new String(newid);
679 public String getSequenceSetId()
681 if (sequenceSetID == null)
683 sequenceSetID = alignment.hashCode() + "";
686 return sequenceSetID;
690 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
693 protected String viewId = null;
695 public String getViewId()
699 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
704 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
706 ignoreGapsInConsensusCalculation = b;
710 if (globalColourScheme != null)
712 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
713 ignoreGapsInConsensusCalculation);
719 private long sgrouphash = -1, colselhash = -1;
722 * checks current SelectionGroup against record of last hash value, and
726 * update the record of last hash value
728 * @return true if SelectionGroup changed since last call (when b is true)
730 public boolean isSelectionGroupChanged(boolean b)
732 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
733 : selectionGroup.hashCode();
734 if (hc != -1 && hc != sgrouphash)
746 * checks current colsel against record of last hash value, and optionally
750 * update the record of last hash value
751 * @return true if colsel changed since last call (when b is true)
753 public boolean isColSelChanged(boolean b)
755 int hc = (colSel == null || colSel.size() == 0) ? -1 : colSel
757 if (hc != -1 && hc != colselhash)
769 public boolean getIgnoreGapsConsensus()
771 return ignoreGapsInConsensusCalculation;
774 // / property change stuff
776 // JBPNote Prolly only need this in the applet version.
777 private final java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
780 protected boolean showConservation = true;
782 protected boolean showQuality = true;
784 protected boolean showConsensus = true;
787 * Property change listener for changes in alignment
792 public void addPropertyChangeListener(
793 java.beans.PropertyChangeListener listener)
795 changeSupport.addPropertyChangeListener(listener);
804 public void removePropertyChangeListener(
805 java.beans.PropertyChangeListener listener)
807 changeSupport.removePropertyChangeListener(listener);
811 * Property change listener for changes in alignment
820 public void firePropertyChange(String prop, Object oldvalue,
823 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
826 // common hide/show column stuff
828 public void hideSelectedColumns()
830 if (colSel.size() < 1)
835 colSel.hideSelectedColumns();
836 setSelectionGroup(null);
838 hasHiddenColumns = true;
841 public void hideColumns(int start, int end)
845 colSel.hideColumns(start);
849 colSel.hideColumns(start, end);
852 hasHiddenColumns = true;
855 public void showColumn(int col)
857 colSel.revealHiddenColumns(col);
858 if (colSel.getHiddenColumns() == null)
860 hasHiddenColumns = false;
864 public void showAllHiddenColumns()
866 colSel.revealAllHiddenColumns();
867 hasHiddenColumns = false;
870 // common hide/show seq stuff
871 public void showAllHiddenSeqs()
873 if (alignment.getHiddenSequences().getSize() > 0)
875 if (selectionGroup == null)
877 selectionGroup = new SequenceGroup();
878 selectionGroup.setEndRes(alignment.getWidth() - 1);
880 Vector tmp = alignment.getHiddenSequences().showAll(
882 for (int t = 0; t < tmp.size(); t++)
884 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
887 hasHiddenRows = false;
888 hiddenRepSequences = null;
890 firePropertyChange("alignment", null, alignment.getSequences());
891 // used to set hasHiddenRows/hiddenRepSequences here, after the property
897 public void showSequence(int index)
899 Vector tmp = alignment.getHiddenSequences().showSequence(index,
903 if (selectionGroup == null)
905 selectionGroup = new SequenceGroup();
906 selectionGroup.setEndRes(alignment.getWidth() - 1);
909 for (int t = 0; t < tmp.size(); t++)
911 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
913 // JBPNote: refactor: only update flag if we modified visiblity (used to
914 // do this regardless)
915 if (alignment.getHiddenSequences().getSize() < 1)
917 hasHiddenRows = false;
919 firePropertyChange("alignment", null, alignment.getSequences());
924 public void hideAllSelectedSeqs()
926 if (selectionGroup == null || selectionGroup.getSize() < 1)
931 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
935 setSelectionGroup(null);
938 public void hideSequence(SequenceI[] seq)
942 for (int i = 0; i < seq.length; i++)
944 alignment.getHiddenSequences().hideSequence(seq[i]);
946 hasHiddenRows = true;
947 firePropertyChange("alignment", null, alignment.getSequences());
951 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
953 int sSize = sg.getSize();
959 if (hiddenRepSequences == null)
961 hiddenRepSequences = new Hashtable();
964 hiddenRepSequences.put(repSequence, sg);
966 // Hide all sequences except the repSequence
967 SequenceI[] seqs = new SequenceI[sSize - 1];
969 for (int i = 0; i < sSize; i++)
971 if (sg.getSequenceAt(i) != repSequence)
973 if (index == sSize - 1)
978 seqs[index++] = sg.getSequenceAt(i);
981 sg.setSeqrep(repSequence); // note: not done in 2.7applet
982 sg.setHidereps(true); // note: not done in 2.7applet
987 public boolean isHiddenRepSequence(SequenceI seq)
989 return hiddenRepSequences != null
990 && hiddenRepSequences.containsKey(seq);
993 public SequenceGroup getRepresentedSequences(SequenceI seq)
995 return (SequenceGroup) (hiddenRepSequences == null ? null
996 : hiddenRepSequences.get(seq));
999 public int adjustForHiddenSeqs(int alignmentIndex)
1001 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1005 // Selection manipulation
1007 * broadcast selection to any interested parties
1009 public abstract void sendSelection();
1011 public void invertColumnSelection()
1013 colSel.invertColumnSelection(0, alignment.getWidth());
1017 * This method returns an array of new SequenceI objects derived from the
1018 * whole alignment or just the current selection with start and end points
1021 * @note if you need references to the actual SequenceI objects in the
1022 * alignment or currently selected then use getSequenceSelection()
1023 * @return selection as new sequenceI objects
1025 public SequenceI[] getSelectionAsNewSequence()
1027 SequenceI[] sequences;
1028 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1029 // this was the only caller in the applet for this method
1030 // JBPNote: in applet, this method returned references to the alignment
1031 // sequences, and it did not honour the presence/absence of annotation
1032 // attached to the alignment (probably!)
1033 if (selectionGroup == null || selectionGroup.getSize() == 0)
1035 sequences = alignment.getSequencesArray();
1036 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1037 for (int i = 0; i < sequences.length; i++)
1039 sequences[i] = new Sequence(sequences[i], annots); // construct new
1041 // subset of visible
1047 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1054 * get the currently selected sequence objects or all the sequences in the
1057 * @return array of references to sequence objects
1060 public SequenceI[] getSequenceSelection()
1062 SequenceI[] sequences = null;
1063 if (selectionGroup != null)
1065 sequences = selectionGroup.getSequencesInOrder(alignment);
1067 if (sequences == null)
1069 sequences = alignment.getSequencesArray();
1075 * This method returns the visible alignment as text, as seen on the GUI, ie
1076 * if columns are hidden they will not be returned in the result. Use this for
1077 * calculating trees, PCA, redundancy etc on views which contain hidden
1083 public jalview.datamodel.CigarArray getViewAsCigars(
1084 boolean selectedRegionOnly)
1086 return new jalview.datamodel.CigarArray(alignment,
1087 (hasHiddenColumns ? colSel : null),
1088 (selectedRegionOnly ? selectionGroup : null));
1092 * return a compact representation of the current alignment selection to pass
1093 * to an analysis function
1095 * @param selectedOnly
1096 * boolean true to just return the selected view
1097 * @return AlignmentView
1100 public jalview.datamodel.AlignmentView getAlignmentView(
1101 boolean selectedOnly)
1103 return getAlignmentView(selectedOnly, false);
1107 * return a compact representation of the current alignment selection to pass
1108 * to an analysis function
1110 * @param selectedOnly
1111 * boolean true to just return the selected view
1113 * boolean true to annotate the alignment view with groups on the
1114 * alignment (and intersecting with selected region if selectedOnly
1116 * @return AlignmentView
1119 public jalview.datamodel.AlignmentView getAlignmentView(
1120 boolean selectedOnly, boolean markGroups)
1122 return new AlignmentView(alignment, colSel, selectionGroup,
1123 hasHiddenColumns, selectedOnly, markGroups);
1127 * This method returns the visible alignment as text, as seen on the GUI, ie
1128 * if columns are hidden they will not be returned in the result. Use this for
1129 * calculating trees, PCA, redundancy etc on views which contain hidden
1135 public String[] getViewAsString(boolean selectedRegionOnly)
1137 String[] selection = null;
1138 SequenceI[] seqs = null;
1140 int start = 0, end = 0;
1141 if (selectedRegionOnly && selectionGroup != null)
1143 iSize = selectionGroup.getSize();
1144 seqs = selectionGroup.getSequencesInOrder(alignment);
1145 start = selectionGroup.getStartRes();
1146 end = selectionGroup.getEndRes() + 1;
1150 iSize = alignment.getHeight();
1151 seqs = alignment.getSequencesArray();
1152 end = alignment.getWidth();
1155 selection = new String[iSize];
1156 if (hasHiddenColumns)
1158 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1162 for (i = 0; i < iSize; i++)
1164 selection[i] = seqs[i].getSequenceAsString(start, end);
1172 * return visible region boundaries within given column range
1175 * first column (inclusive, from 0)
1177 * last column (exclusive)
1178 * @return int[][] range of {start,end} visible positions
1180 public int[][] getVisibleRegionBoundaries(int min, int max)
1182 Vector regions = new Vector();
1188 if (hasHiddenColumns)
1192 start = colSel.adjustForHiddenColumns(start);
1195 end = colSel.getHiddenBoundaryRight(start);
1206 regions.addElement(new int[]
1209 if (hasHiddenColumns)
1211 start = colSel.adjustForHiddenColumns(end);
1212 start = colSel.getHiddenBoundaryLeft(start) + 1;
1214 } while (end < max);
1216 int[][] startEnd = new int[regions.size()][2];
1218 regions.copyInto(startEnd);
1225 * @return the padGaps
1227 public boolean isPadGaps()
1234 * the padGaps to set
1236 public void setPadGaps(boolean padGaps)
1238 this.padGaps = padGaps;
1242 * apply any post-edit constraints and trigger any calculations needed after
1243 * an edit has been performed on the alignment
1247 public void alignmentChanged(AlignmentViewPanel ap)
1251 alignment.padGaps();
1253 if (autoCalculateConsensus)
1255 updateConsensus(ap);
1257 if (hconsensus != null && autoCalculateConsensus)
1259 updateConservation(ap);
1261 if (autoCalculateStrucConsensus)
1263 updateStrucConsensus(ap);
1266 // Reset endRes of groups if beyond alignment width
1267 int alWidth = alignment.getWidth();
1268 List<SequenceGroup> groups = alignment.getGroups();
1271 for (SequenceGroup sg : groups)
1273 if (sg.getEndRes() > alWidth)
1275 sg.setEndRes(alWidth - 1);
1280 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1282 selectionGroup.setEndRes(alWidth - 1);
1285 resetAllColourSchemes();
1286 calculator.restartWorkers();
1287 // alignment.adjustSequenceAnnotations();
1291 * reset scope and do calculations for all applied colourschemes on alignment
1293 void resetAllColourSchemes()
1295 ColourSchemeI cs = globalColourScheme;
1298 cs.alignmentChanged(alignment, null);
1300 cs.setConsensus(hconsensus);
1301 if (cs.conservationApplied())
1303 cs.setConservation(Conservation.calculateConservation("All",
1304 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1305 alignment.getWidth(), false, getConsPercGaps(), false));
1309 for (SequenceGroup sg : alignment.getGroups())
1313 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1315 sg.recalcConservation();
1319 protected void initAutoAnnotation()
1321 // TODO: add menu option action that nulls or creates consensus object
1322 // depending on if the user wants to see the annotation or not in a
1323 // specific alignment
1325 if (hconsensus == null && !isDataset)
1327 if (!alignment.isNucleotide())
1340 private void initConsensus()
1343 consensus = new AlignmentAnnotation("Consensus", "PID",
1344 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1345 consensus.hasText = true;
1346 consensus.autoCalculated = true;
1350 alignment.addAnnotation(consensus);
1354 private void initConservation()
1356 if (showConservation)
1358 if (conservation == null)
1360 conservation = new AlignmentAnnotation("Conservation",
1361 "Conservation of total alignment less than "
1362 + getConsPercGaps() + "% gaps",
1363 new Annotation[1], 0f, 11f,
1364 AlignmentAnnotation.BAR_GRAPH);
1365 conservation.hasText = true;
1366 conservation.autoCalculated = true;
1367 alignment.addAnnotation(conservation);
1371 private void initQuality()
1375 if (quality == null)
1377 quality = new AlignmentAnnotation("Quality",
1378 "Alignment Quality based on Blosum62 scores",
1379 new Annotation[1], 0f, 11f,
1380 AlignmentAnnotation.BAR_GRAPH);
1381 quality.hasText = true;
1382 quality.autoCalculated = true;
1383 alignment.addAnnotation(quality);
1387 private void initRNAStructure()
1389 if (alignment.hasRNAStructure() && strucConsensus==null)
1391 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1392 new Annotation[1], 0f, 100f,
1393 AlignmentAnnotation.BAR_GRAPH);
1394 strucConsensus.hasText = true;
1395 strucConsensus.autoCalculated = true;
1399 alignment.addAnnotation(strucConsensus);
1406 * @see jalview.api.AlignViewportI#calcPanelHeight()
1408 public int calcPanelHeight()
1410 // setHeight of panels
1411 AlignmentAnnotation[] aa = getAlignment().getAlignmentAnnotation();
1413 int charHeight = getCharHeight();
1416 boolean graphgrp[] = null;
1417 for (int i = 0; i < aa.length; i++)
1421 System.err.println("Null annotation row: ignoring.");
1428 if (aa[i].graphGroup > -1)
1430 if (graphgrp == null)
1432 graphgrp = new boolean[aa.length];
1434 if (graphgrp[aa[i].graphGroup])
1440 graphgrp[aa[i].graphGroup] = true;
1447 aa[i].height += charHeight;
1455 if (aa[i].graph > 0)
1457 aa[i].height += aa[i].graphHeight;
1460 if (aa[i].height == 0)
1465 height += aa[i].height;
1477 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1478 boolean preserveNewGroupSettings)
1480 boolean updateCalcs = false;
1481 boolean conv = isShowGroupConservation();
1482 boolean cons = isShowGroupConsensus();
1483 boolean showprf = isShowSequenceLogo();
1484 boolean showConsHist = isShowConsensusHistogram();
1485 boolean normLogo = isNormaliseSequenceLogo();
1488 * TODO reorder the annotation rows according to group/sequence ordering on
1491 boolean sortg = true;
1493 // remove old automatic annotation
1494 // add any new annotation
1496 // intersect alignment annotation with alignment groups
1498 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
1499 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
1502 for (int an = 0; an < aan.length; an++)
1504 if (aan[an].autoCalculated && aan[an].groupRef != null)
1506 oldrfs.add(aan[an].groupRef);
1507 alignment.deleteAnnotation(aan[an]);
1512 if (alignment.getGroups() != null)
1514 for (SequenceGroup sg : alignment.getGroups())
1516 updateCalcs = false;
1517 if (applyGlobalSettings
1518 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
1520 // set defaults for this group's conservation/consensus
1521 sg.setshowSequenceLogo(showprf);
1522 sg.setShowConsensusHistogram(showConsHist);
1523 sg.setNormaliseSequenceLogo(normLogo);
1528 alignment.addAnnotation(sg.getConservationRow(), 0);
1533 alignment.addAnnotation(sg.getConsensus(), 0);
1535 // refresh the annotation rows
1538 sg.recalcConservation();