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
597 public SequenceGroup getSelectionGroup()
599 return selectionGroup;
603 * Set the selection group for this window.
606 * - group holding references to sequences in this alignment view
609 public void setSelectionGroup(SequenceGroup sg)
614 public void setHiddenColumns(ColumnSelection colsel)
616 this.colSel = colsel;
617 if (colSel.getHiddenColumns() != null)
619 hasHiddenColumns = true;
624 public ColumnSelection getColumnSelection()
629 public void setColumnSelection(ColumnSelection colSel)
631 this.colSel = colSel;
639 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
641 return hiddenRepSequences;
645 public void setHiddenRepSequences(
646 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
648 this.hiddenRepSequences = hiddenRepSequences;
651 protected boolean hasHiddenColumns = false;
653 public void updateHiddenColumns()
655 hasHiddenColumns = colSel.getHiddenColumns() != null;
658 protected boolean hasHiddenRows = false;
660 public boolean hasHiddenRows()
662 return hasHiddenRows;
665 protected SequenceGroup selectionGroup;
667 public void setSequenceSetId(String newid)
669 if (sequenceSetID != null)
672 .println("Warning - overwriting a sequenceSetId for a viewport!");
674 sequenceSetID = new String(newid);
677 public String getSequenceSetId()
679 if (sequenceSetID == null)
681 sequenceSetID = alignment.hashCode() + "";
684 return sequenceSetID;
688 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
691 protected String viewId = null;
693 public String getViewId()
697 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
702 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
704 ignoreGapsInConsensusCalculation = b;
708 if (globalColourScheme != null)
710 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
711 ignoreGapsInConsensusCalculation);
717 private long sgrouphash = -1, colselhash = -1;
720 * checks current SelectionGroup against record of last hash value, and
724 * update the record of last hash value
726 * @return true if SelectionGroup changed since last call (when b is true)
728 public boolean isSelectionGroupChanged(boolean b)
730 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
731 : selectionGroup.hashCode();
732 if (hc != -1 && hc != sgrouphash)
744 * checks current colsel against record of last hash value, and optionally
748 * update the record of last hash value
749 * @return true if colsel changed since last call (when b is true)
751 public boolean isColSelChanged(boolean b)
753 int hc = (colSel == null || colSel.size() == 0) ? -1 : colSel
755 if (hc != -1 && hc != colselhash)
767 public boolean getIgnoreGapsConsensus()
769 return ignoreGapsInConsensusCalculation;
772 // / property change stuff
774 // JBPNote Prolly only need this in the applet version.
775 private final java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
778 protected boolean showConservation = true;
780 protected boolean showQuality = true;
782 protected boolean showConsensus = true;
785 * Property change listener for changes in alignment
790 public void addPropertyChangeListener(
791 java.beans.PropertyChangeListener listener)
793 changeSupport.addPropertyChangeListener(listener);
802 public void removePropertyChangeListener(
803 java.beans.PropertyChangeListener listener)
805 changeSupport.removePropertyChangeListener(listener);
809 * Property change listener for changes in alignment
818 public void firePropertyChange(String prop, Object oldvalue,
821 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
824 // common hide/show column stuff
826 public void hideSelectedColumns()
828 if (colSel.size() < 1)
833 colSel.hideSelectedColumns();
834 setSelectionGroup(null);
836 hasHiddenColumns = true;
839 public void hideColumns(int start, int end)
843 colSel.hideColumns(start);
847 colSel.hideColumns(start, end);
850 hasHiddenColumns = true;
853 public void showColumn(int col)
855 colSel.revealHiddenColumns(col);
856 if (colSel.getHiddenColumns() == null)
858 hasHiddenColumns = false;
862 public void showAllHiddenColumns()
864 colSel.revealAllHiddenColumns();
865 hasHiddenColumns = false;
868 // common hide/show seq stuff
869 public void showAllHiddenSeqs()
871 if (alignment.getHiddenSequences().getSize() > 0)
873 if (selectionGroup == null)
875 selectionGroup = new SequenceGroup();
876 selectionGroup.setEndRes(alignment.getWidth() - 1);
878 Vector tmp = alignment.getHiddenSequences().showAll(
880 for (int t = 0; t < tmp.size(); t++)
882 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
885 hasHiddenRows = false;
886 hiddenRepSequences = null;
888 firePropertyChange("alignment", null, alignment.getSequences());
889 // used to set hasHiddenRows/hiddenRepSequences here, after the property
895 public void showSequence(int index)
897 Vector tmp = alignment.getHiddenSequences().showSequence(index,
901 if (selectionGroup == null)
903 selectionGroup = new SequenceGroup();
904 selectionGroup.setEndRes(alignment.getWidth() - 1);
907 for (int t = 0; t < tmp.size(); t++)
909 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
911 // JBPNote: refactor: only update flag if we modified visiblity (used to
912 // do this regardless)
913 if (alignment.getHiddenSequences().getSize() < 1)
915 hasHiddenRows = false;
917 firePropertyChange("alignment", null, alignment.getSequences());
922 public void hideAllSelectedSeqs()
924 if (selectionGroup == null || selectionGroup.getSize() < 1)
929 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
933 setSelectionGroup(null);
936 public void hideSequence(SequenceI[] seq)
940 for (int i = 0; i < seq.length; i++)
942 alignment.getHiddenSequences().hideSequence(seq[i]);
944 hasHiddenRows = true;
945 firePropertyChange("alignment", null, alignment.getSequences());
949 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
951 int sSize = sg.getSize();
957 if (hiddenRepSequences == null)
959 hiddenRepSequences = new Hashtable();
962 hiddenRepSequences.put(repSequence, sg);
964 // Hide all sequences except the repSequence
965 SequenceI[] seqs = new SequenceI[sSize - 1];
967 for (int i = 0; i < sSize; i++)
969 if (sg.getSequenceAt(i) != repSequence)
971 if (index == sSize - 1)
976 seqs[index++] = sg.getSequenceAt(i);
979 sg.setSeqrep(repSequence); // note: not done in 2.7applet
980 sg.setHidereps(true); // note: not done in 2.7applet
985 public boolean isHiddenRepSequence(SequenceI seq)
987 return alignment.getSeqrep()==seq || (hiddenRepSequences != null
988 && hiddenRepSequences.containsKey(seq));
991 public SequenceGroup getRepresentedSequences(SequenceI seq)
993 return (SequenceGroup) (hiddenRepSequences == null ? null
994 : hiddenRepSequences.get(seq));
997 public int adjustForHiddenSeqs(int alignmentIndex)
999 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1003 // Selection manipulation
1005 * broadcast selection to any interested parties
1007 public abstract void sendSelection();
1009 public void invertColumnSelection()
1011 colSel.invertColumnSelection(0, alignment.getWidth());
1015 * This method returns an array of new SequenceI objects derived from the
1016 * whole alignment or just the current selection with start and end points
1019 * @note if you need references to the actual SequenceI objects in the
1020 * alignment or currently selected then use getSequenceSelection()
1021 * @return selection as new sequenceI objects
1023 public SequenceI[] getSelectionAsNewSequence()
1025 SequenceI[] sequences;
1026 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1027 // this was the only caller in the applet for this method
1028 // JBPNote: in applet, this method returned references to the alignment
1029 // sequences, and it did not honour the presence/absence of annotation
1030 // attached to the alignment (probably!)
1031 if (selectionGroup == null || selectionGroup.getSize() == 0)
1033 sequences = alignment.getSequencesArray();
1034 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1035 for (int i = 0; i < sequences.length; i++)
1037 sequences[i] = new Sequence(sequences[i], annots); // construct new
1039 // subset of visible
1045 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1052 * get the currently selected sequence objects or all the sequences in the
1055 * @return array of references to sequence objects
1057 public SequenceI[] getSequenceSelection()
1059 SequenceI[] sequences = null;
1060 if (selectionGroup != null)
1062 sequences = selectionGroup.getSequencesInOrder(alignment);
1064 if (sequences == null)
1066 sequences = alignment.getSequencesArray();
1072 * This method returns the visible alignment as text, as seen on the GUI, ie
1073 * if columns are hidden they will not be returned in the result. Use this for
1074 * calculating trees, PCA, redundancy etc on views which contain hidden
1079 public jalview.datamodel.CigarArray getViewAsCigars(
1080 boolean selectedRegionOnly)
1082 return new jalview.datamodel.CigarArray(alignment,
1083 (hasHiddenColumns ? colSel : null),
1084 (selectedRegionOnly ? selectionGroup : null));
1088 * return a compact representation of the current alignment selection to pass
1089 * to an analysis function
1091 * @param selectedOnly
1092 * boolean true to just return the selected view
1093 * @return AlignmentView
1095 public jalview.datamodel.AlignmentView getAlignmentView(
1096 boolean selectedOnly)
1098 return getAlignmentView(selectedOnly, false);
1102 * return a compact representation of the current alignment selection to pass
1103 * to an analysis function
1105 * @param selectedOnly
1106 * boolean true to just return the selected view
1108 * boolean true to annotate the alignment view with groups on the
1109 * alignment (and intersecting with selected region if selectedOnly
1111 * @return AlignmentView
1113 public jalview.datamodel.AlignmentView getAlignmentView(
1114 boolean selectedOnly, boolean markGroups)
1116 return new AlignmentView(alignment, colSel, selectionGroup,
1117 hasHiddenColumns, selectedOnly, markGroups);
1121 * This method returns the visible alignment as text, as seen on the GUI, ie
1122 * if columns are hidden they will not be returned in the result. Use this for
1123 * calculating trees, PCA, redundancy etc on views which contain hidden
1128 public String[] getViewAsString(boolean selectedRegionOnly)
1130 String[] selection = null;
1131 SequenceI[] seqs = null;
1133 int start = 0, end = 0;
1134 if (selectedRegionOnly && selectionGroup != null)
1136 iSize = selectionGroup.getSize();
1137 seqs = selectionGroup.getSequencesInOrder(alignment);
1138 start = selectionGroup.getStartRes();
1139 end = selectionGroup.getEndRes() + 1;
1143 iSize = alignment.getHeight();
1144 seqs = alignment.getSequencesArray();
1145 end = alignment.getWidth();
1148 selection = new String[iSize];
1149 if (hasHiddenColumns)
1151 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1155 for (i = 0; i < iSize; i++)
1157 selection[i] = seqs[i].getSequenceAsString(start, end);
1165 * return visible region boundaries within given column range
1168 * first column (inclusive, from 0)
1170 * last column (exclusive)
1171 * @return int[][] range of {start,end} visible positions
1173 public int[][] getVisibleRegionBoundaries(int min, int max)
1175 Vector regions = new Vector();
1181 if (hasHiddenColumns)
1185 start = colSel.adjustForHiddenColumns(start);
1188 end = colSel.getHiddenBoundaryRight(start);
1199 regions.addElement(new int[]
1202 if (hasHiddenColumns)
1204 start = colSel.adjustForHiddenColumns(end);
1205 start = colSel.getHiddenBoundaryLeft(start) + 1;
1207 } while (end < max);
1209 int[][] startEnd = new int[regions.size()][2];
1211 regions.copyInto(startEnd);
1218 * @return the padGaps
1220 public boolean isPadGaps()
1227 * the padGaps to set
1229 public void setPadGaps(boolean padGaps)
1231 this.padGaps = padGaps;
1235 * apply any post-edit constraints and trigger any calculations needed after
1236 * an edit has been performed on the alignment
1240 public void alignmentChanged(AlignmentViewPanel ap)
1244 alignment.padGaps();
1246 if (autoCalculateConsensus)
1248 updateConsensus(ap);
1250 if (hconsensus != null && autoCalculateConsensus)
1252 updateConservation(ap);
1254 if (autoCalculateStrucConsensus)
1256 updateStrucConsensus(ap);
1259 // Reset endRes of groups if beyond alignment width
1260 int alWidth = alignment.getWidth();
1261 List<SequenceGroup> groups = alignment.getGroups();
1264 for (SequenceGroup sg : groups)
1266 if (sg.getEndRes() > alWidth)
1268 sg.setEndRes(alWidth - 1);
1273 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1275 selectionGroup.setEndRes(alWidth - 1);
1278 resetAllColourSchemes();
1279 calculator.restartWorkers();
1280 // alignment.adjustSequenceAnnotations();
1284 * reset scope and do calculations for all applied colourschemes on alignment
1286 void resetAllColourSchemes()
1288 ColourSchemeI cs = globalColourScheme;
1291 cs.alignmentChanged(alignment, null);
1293 cs.setConsensus(hconsensus);
1294 if (cs.conservationApplied())
1296 cs.setConservation(Conservation.calculateConservation("All",
1297 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1298 alignment.getWidth(), false, getConsPercGaps(), false));
1302 for (SequenceGroup sg : alignment.getGroups())
1306 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1308 sg.recalcConservation();
1312 protected void initAutoAnnotation()
1314 // TODO: add menu option action that nulls or creates consensus object
1315 // depending on if the user wants to see the annotation or not in a
1316 // specific alignment
1318 if (hconsensus == null && !isDataset)
1320 if (!alignment.isNucleotide())
1333 private void initConsensus()
1336 consensus = new AlignmentAnnotation("Consensus", "PID",
1337 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1338 consensus.hasText = true;
1339 consensus.autoCalculated = true;
1343 alignment.addAnnotation(consensus);
1347 private void initConservation()
1349 if (showConservation)
1351 if (conservation == null)
1353 conservation = new AlignmentAnnotation("Conservation",
1354 "Conservation of total alignment less than "
1355 + getConsPercGaps() + "% gaps",
1356 new Annotation[1], 0f, 11f,
1357 AlignmentAnnotation.BAR_GRAPH);
1358 conservation.hasText = true;
1359 conservation.autoCalculated = true;
1360 alignment.addAnnotation(conservation);
1364 private void initQuality()
1368 if (quality == null)
1370 quality = new AlignmentAnnotation("Quality",
1371 "Alignment Quality based on Blosum62 scores",
1372 new Annotation[1], 0f, 11f,
1373 AlignmentAnnotation.BAR_GRAPH);
1374 quality.hasText = true;
1375 quality.autoCalculated = true;
1376 alignment.addAnnotation(quality);
1380 private void initRNAStructure()
1382 if (alignment.hasRNAStructure() && strucConsensus==null)
1384 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1385 new Annotation[1], 0f, 100f,
1386 AlignmentAnnotation.BAR_GRAPH);
1387 strucConsensus.hasText = true;
1388 strucConsensus.autoCalculated = true;
1392 alignment.addAnnotation(strucConsensus);
1399 * @see jalview.api.AlignViewportI#calcPanelHeight()
1401 public int calcPanelHeight()
1403 // setHeight of panels
1404 AlignmentAnnotation[] aa = getAlignment().getAlignmentAnnotation();
1406 int charHeight = getCharHeight();
1409 boolean graphgrp[] = null;
1410 for (int i = 0; i < aa.length; i++)
1414 System.err.println("Null annotation row: ignoring.");
1421 if (aa[i].graphGroup > -1)
1423 if (graphgrp == null)
1425 graphgrp = new boolean[aa.length];
1427 if (graphgrp[aa[i].graphGroup])
1433 graphgrp[aa[i].graphGroup] = true;
1440 aa[i].height += charHeight;
1448 if (aa[i].graph > 0)
1450 aa[i].height += aa[i].graphHeight;
1453 if (aa[i].height == 0)
1458 height += aa[i].height;
1470 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1471 boolean preserveNewGroupSettings)
1473 boolean updateCalcs = false;
1474 boolean conv = isShowGroupConservation();
1475 boolean cons = isShowGroupConsensus();
1476 boolean showprf = isShowSequenceLogo();
1477 boolean showConsHist = isShowConsensusHistogram();
1478 boolean normLogo = isNormaliseSequenceLogo();
1481 * TODO reorder the annotation rows according to group/sequence ordering on
1484 boolean sortg = true;
1486 // remove old automatic annotation
1487 // add any new annotation
1489 // intersect alignment annotation with alignment groups
1491 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
1492 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
1495 for (int an = 0; an < aan.length; an++)
1497 if (aan[an].autoCalculated && aan[an].groupRef != null)
1499 oldrfs.add(aan[an].groupRef);
1500 alignment.deleteAnnotation(aan[an]);
1505 if (alignment.getGroups() != null)
1507 for (SequenceGroup sg : alignment.getGroups())
1509 updateCalcs = false;
1510 if (applyGlobalSettings
1511 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
1513 // set defaults for this group's conservation/consensus
1514 sg.setshowSequenceLogo(showprf);
1515 sg.setShowConsensusHistogram(showConsHist);
1516 sg.setNormaliseSequenceLogo(normLogo);
1521 alignment.addAnnotation(sg.getConservationRow(), 0);
1526 alignment.addAnnotation(sg.getConsensus(), 0);
1528 // refresh the annotation rows
1531 sg.recalcConservation();
1538 * show the reference sequence in the alignment view
1540 private boolean displayReferenceSeq=false;
1542 * colour according to the reference sequence defined on the alignment
1544 private boolean colourByReferenceSeq=false;
1546 public boolean isDisplayReferenceSeq()
1548 return alignment.hasSeqrep() && displayReferenceSeq;
1551 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
1553 this.displayReferenceSeq = displayReferenceSeq;
1556 public boolean isColourByReferenceSeq()
1558 return alignment.hasSeqrep() && colourByReferenceSeq;
1561 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
1563 this.colourByReferenceSeq = colourByReferenceSeq;