2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3 * Copyright (C) 2014 The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
19 package jalview.viewmodel;
21 import jalview.analysis.AAFrequency;
22 import jalview.analysis.Conservation;
23 import jalview.api.AlignCalcManagerI;
24 import jalview.api.AlignViewportI;
25 import jalview.api.AlignmentViewPanel;
26 import jalview.datamodel.AlignmentAnnotation;
27 import jalview.datamodel.AlignmentI;
28 import jalview.datamodel.AlignmentView;
29 import jalview.datamodel.Annotation;
30 import jalview.datamodel.ColumnSelection;
31 import jalview.datamodel.Sequence;
32 import jalview.datamodel.SequenceCollectionI;
33 import jalview.datamodel.SequenceGroup;
34 import jalview.datamodel.SequenceI;
35 import jalview.schemes.Blosum62ColourScheme;
36 import jalview.schemes.ClustalxColourScheme;
37 import jalview.schemes.ColourSchemeI;
38 import jalview.schemes.PIDColourScheme;
39 import jalview.schemes.ResidueProperties;
40 import jalview.workers.AlignCalcManager;
41 import jalview.workers.ConsensusThread;
42 import jalview.workers.StrucConsensusThread;
44 import java.util.ArrayList;
45 import java.util.BitSet;
46 import java.util.Hashtable;
47 import java.util.List;
49 import java.util.Vector;
52 * base class holding visualization and analysis attributes and common logic for
53 * an active alignment view displayed in the GUI
58 public abstract class AlignmentViewport implements AlignViewportI
61 * alignment displayed in the viewport. Please use get/setter
63 protected AlignmentI alignment;
65 protected String sequenceSetID;
68 * probably unused indicator that view is of a dataset rather than an
71 protected boolean isDataset = false;
73 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
75 protected ColumnSelection colSel = new ColumnSelection();
77 public boolean autoCalculateConsensus = true;
79 protected boolean autoCalculateStrucConsensus = true;
81 protected boolean ignoreGapsInConsensusCalculation = false;
83 protected ColourSchemeI globalColourScheme = null;
86 * gui state - changes to colour scheme propagated to all groups
88 private boolean colourAppliesToAllGroups;
92 * indicating if subsequent colourscheme changes will be propagated
95 public void setColourAppliesToAllGroups(boolean b)
97 colourAppliesToAllGroups = b;
103 * @return flag indicating if colourchanges propagated to all groups
105 public boolean getColourAppliesToAllGroups()
107 return colourAppliesToAllGroups;
110 boolean abovePIDThreshold = false;
115 * @return true if percent identity threshold is applied to shading
117 public boolean getAbovePIDThreshold()
119 return abovePIDThreshold;
127 * indicate if percent identity threshold is applied to shading
129 public void setAbovePIDThreshold(boolean b)
131 abovePIDThreshold = b;
142 public void setThreshold(int thresh)
150 * @return DOCUMENT ME!
152 public int getThreshold()
162 * set the scalar for bleaching colourschemes according to degree of
165 public void setIncrement(int inc)
173 * @return get scalar for bleaching colourschemes by conservation
175 public int getIncrement()
180 boolean conservationColourSelected = false;
185 * @return true if conservation based shading is enabled
187 public boolean getConservationSelected()
189 return conservationColourSelected;
196 * enable conservation based shading
198 public void setConservationSelected(boolean b)
200 conservationColourSelected = b;
204 public void setGlobalColourScheme(ColourSchemeI cs)
206 // TODO: logic refactored from AlignFrame changeColour -
207 // autorecalc stuff should be changed to rely on the worker system
208 // check to see if we should implement a changeColour(cs) method rather than
209 // put th logic in here
210 // - means that caller decides if they want to just modify state and defer
211 // calculation till later or to do all calculations in thread.
213 globalColourScheme = cs;
214 if (getColourAppliesToAllGroups())
216 for (SequenceGroup sg : getAlignment().getGroups())
223 if (cs instanceof ClustalxColourScheme)
225 sg.cs = new ClustalxColourScheme(sg, getHiddenRepSequences());
231 sg.cs = cs.getClass().newInstance();
232 } catch (Exception ex)
234 ex.printStackTrace();
239 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
240 || cs instanceof Blosum62ColourScheme)
242 sg.cs.setThreshold(threshold, getIgnoreGapsConsensus());
243 sg.cs.setConsensus(AAFrequency.calculate(
244 sg.getSequences(getHiddenRepSequences()), 0,
249 sg.cs.setThreshold(0, getIgnoreGapsConsensus());
252 if (getConservationSelected())
254 Conservation c = new Conservation("Group",
255 ResidueProperties.propHash, 3,
256 sg.getSequences(getHiddenRepSequences()), 0,
257 getAlignment().getWidth() - 1);
259 c.verdict(false, getConsPercGaps());
260 sg.cs.setConservation(c);
264 sg.cs.setConservation(null);
265 sg.cs.setThreshold(0, getIgnoreGapsConsensus());
274 public ColourSchemeI getGlobalColourScheme()
276 return globalColourScheme;
279 protected AlignmentAnnotation consensus;
281 protected AlignmentAnnotation strucConsensus;
283 protected AlignmentAnnotation conservation;
285 protected AlignmentAnnotation quality;
287 protected AlignmentAnnotation[] groupConsensus;
289 protected AlignmentAnnotation[] groupConservation;
292 * results of alignment consensus analysis for visible portion of view
294 protected Hashtable[] hconsensus = null;
297 * results of secondary structure base pair consensus for visible portion of
300 protected Hashtable[] hStrucConsensus = null;
303 * percentage gaps allowed in a column before all amino acid properties should
304 * be considered unconserved
306 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
309 public int getConsPercGaps()
315 public void setSequenceConsensusHash(Hashtable[] hconsensus)
317 this.hconsensus = hconsensus;
322 public Hashtable[] getSequenceConsensusHash()
328 public Hashtable[] getRnaStructureConsensusHash()
330 return hStrucConsensus;
334 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
336 this.hStrucConsensus = hStrucConsensus;
341 public AlignmentAnnotation getAlignmentQualityAnnot()
347 public AlignmentAnnotation getAlignmentConservationAnnotation()
353 public AlignmentAnnotation getAlignmentConsensusAnnotation()
359 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
361 return strucConsensus;
364 protected AlignCalcManagerI calculator = new AlignCalcManager();
367 * trigger update of conservation annotation
369 public void updateConservation(final AlignmentViewPanel ap)
371 // see note in mantis : issue number 8585
372 if (alignment.isNucleotide() || conservation == null
373 || !autoCalculateConsensus)
378 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
380 calculator.registerWorker(new jalview.workers.ConservationThread(
386 * trigger update of consensus annotation
388 public void updateConsensus(final AlignmentViewPanel ap)
390 // see note in mantis : issue number 8585
391 if (consensus == null || !autoCalculateConsensus)
395 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
397 calculator.registerWorker(new ConsensusThread(this, ap));
401 // --------START Structure Conservation
402 public void updateStrucConsensus(final AlignmentViewPanel ap)
404 if (autoCalculateStrucConsensus && strucConsensus == null
405 && alignment.isNucleotide() && alignment.hasRNAStructure())
407 // secondary structure has been added - so init the consensus line
411 // see note in mantis : issue number 8585
412 if (strucConsensus == null || !autoCalculateStrucConsensus)
416 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
418 calculator.registerWorker(new StrucConsensusThread(this, ap));
422 public boolean isCalcInProgress()
424 return calculator.isWorking();
428 public boolean isCalculationInProgress(
429 AlignmentAnnotation alignmentAnnotation)
431 if (!alignmentAnnotation.autoCalculated)
433 if (calculator.workingInvolvedWith(alignmentAnnotation))
435 // System.err.println("grey out ("+alignmentAnnotation.label+")");
442 public boolean isClosed()
444 // TODO: check that this isClosed is only true after panel is closed, not
445 // before it is fully constructed.
446 return alignment == null;
450 public AlignCalcManagerI getCalcManager()
456 * should conservation rows be shown for groups
458 protected boolean showGroupConservation = false;
461 * should consensus rows be shown for groups
463 protected boolean showGroupConsensus = false;
466 * should consensus profile be rendered by default
468 protected boolean showSequenceLogo = false;
471 * should consensus profile be rendered normalised to row height
473 protected boolean normaliseSequenceLogo = false;
476 * should consensus histograms be rendered by default
478 protected boolean showConsensusHistogram = true;
481 * @return the showConsensusProfile
484 public boolean isShowSequenceLogo()
486 return showSequenceLogo;
490 * @param showSequenceLogo
493 public void setShowSequenceLogo(boolean showSequenceLogo)
495 if (showSequenceLogo != this.showSequenceLogo)
497 // TODO: decouple settings setting from calculation when refactoring
498 // annotation update method from alignframe to viewport
499 this.showSequenceLogo = showSequenceLogo;
500 calculator.updateAnnotationFor(ConsensusThread.class);
501 calculator.updateAnnotationFor(StrucConsensusThread.class);
503 this.showSequenceLogo = showSequenceLogo;
507 * @param showConsensusHistogram
508 * the showConsensusHistogram to set
510 public void setShowConsensusHistogram(boolean showConsensusHistogram)
512 this.showConsensusHistogram = showConsensusHistogram;
516 * @return the showGroupConservation
518 public boolean isShowGroupConservation()
520 return showGroupConservation;
524 * @param showGroupConservation
525 * the showGroupConservation to set
527 public void setShowGroupConservation(boolean showGroupConservation)
529 this.showGroupConservation = showGroupConservation;
533 * @return the showGroupConsensus
535 public boolean isShowGroupConsensus()
537 return showGroupConsensus;
541 * @param showGroupConsensus
542 * the showGroupConsensus to set
544 public void setShowGroupConsensus(boolean showGroupConsensus)
546 this.showGroupConsensus = showGroupConsensus;
551 * @return flag to indicate if the consensus histogram should be rendered by
555 public boolean isShowConsensusHistogram()
557 return this.showConsensusHistogram;
561 * show non-conserved residues only
563 protected boolean showUnconserved = false;
566 * when set, updateAlignment will always ensure sequences are of equal length
568 private boolean padGaps = false;
571 * when set, alignment should be reordered according to a newly opened tree
573 public boolean sortByTree = false;
575 public boolean getShowUnconserved()
577 return showUnconserved;
580 public void setShowUnconserved(boolean showunconserved)
582 showUnconserved = showunconserved;
586 * @param showNonconserved
587 * the showUnconserved to set
589 public void setShowunconserved(boolean displayNonconserved)
591 this.showUnconserved = displayNonconserved;
597 * @return null or the currently selected sequence region
600 public SequenceGroup getSelectionGroup()
602 return selectionGroup;
606 * Set the selection group for this window.
609 * - group holding references to sequences in this alignment view
613 public void setSelectionGroup(SequenceGroup sg)
618 public void setHiddenColumns(ColumnSelection colsel)
620 this.colSel = colsel;
621 if (colSel.getHiddenColumns() != null)
623 hasHiddenColumns = true;
628 public ColumnSelection getColumnSelection()
633 public void setColumnSelection(ColumnSelection colSel)
635 this.colSel = colSel;
643 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
645 return hiddenRepSequences;
649 public void setHiddenRepSequences(
650 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
652 this.hiddenRepSequences = hiddenRepSequences;
655 protected boolean hasHiddenColumns = false;
657 public void updateHiddenColumns()
659 hasHiddenColumns = colSel.getHiddenColumns() != null;
662 protected boolean hasHiddenRows = false;
664 public boolean hasHiddenRows()
666 return hasHiddenRows;
669 protected SequenceGroup selectionGroup;
671 public void setSequenceSetId(String newid)
673 if (sequenceSetID != null)
676 .println("Warning - overwriting a sequenceSetId for a viewport!");
678 sequenceSetID = new String(newid);
681 public String getSequenceSetId()
683 if (sequenceSetID == null)
685 sequenceSetID = alignment.hashCode() + "";
688 return sequenceSetID;
692 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
695 protected String viewId = null;
697 public String getViewId()
701 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
706 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
708 ignoreGapsInConsensusCalculation = b;
712 if (globalColourScheme != null)
714 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
715 ignoreGapsInConsensusCalculation);
721 private long sgrouphash = -1, colselhash = -1;
724 * checks current SelectionGroup against record of last hash value, and
728 * update the record of last hash value
730 * @return true if SelectionGroup changed since last call (when b is true)
732 public boolean isSelectionGroupChanged(boolean b)
734 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
735 : selectionGroup.hashCode();
736 if (hc != -1 && hc != sgrouphash)
748 * checks current colsel against record of last hash value, and optionally
752 * update the record of last hash value
753 * @return true if colsel changed since last call (when b is true)
755 public boolean isColSelChanged(boolean b)
757 int hc = (colSel == null || colSel.size() == 0) ? -1 : colSel
759 if (hc != -1 && hc != colselhash)
771 public boolean getIgnoreGapsConsensus()
773 return ignoreGapsInConsensusCalculation;
776 // / property change stuff
778 // JBPNote Prolly only need this in the applet version.
779 private final java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
782 protected boolean showConservation = true;
784 protected boolean showQuality = true;
786 protected boolean showConsensus = true;
789 * Property change listener for changes in alignment
794 public void addPropertyChangeListener(
795 java.beans.PropertyChangeListener listener)
797 changeSupport.addPropertyChangeListener(listener);
806 public void removePropertyChangeListener(
807 java.beans.PropertyChangeListener listener)
809 changeSupport.removePropertyChangeListener(listener);
813 * Property change listener for changes in alignment
822 public void firePropertyChange(String prop, Object oldvalue,
825 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
828 // common hide/show column stuff
830 public void hideSelectedColumns()
832 if (colSel.size() < 1)
837 colSel.hideSelectedColumns();
838 setSelectionGroup(null);
840 hasHiddenColumns = true;
843 public void hideColumns(int start, int end)
847 colSel.hideColumns(start);
851 colSel.hideColumns(start, end);
854 hasHiddenColumns = true;
857 public void showColumn(int col)
859 colSel.revealHiddenColumns(col);
860 if (colSel.getHiddenColumns() == null)
862 hasHiddenColumns = false;
866 public void showAllHiddenColumns()
868 colSel.revealAllHiddenColumns();
869 hasHiddenColumns = false;
872 // common hide/show seq stuff
873 public void showAllHiddenSeqs()
875 if (alignment.getHiddenSequences().getSize() > 0)
877 if (selectionGroup == null)
879 selectionGroup = new SequenceGroup();
880 selectionGroup.setEndRes(alignment.getWidth() - 1);
882 Vector tmp = alignment.getHiddenSequences().showAll(
884 for (int t = 0; t < tmp.size(); t++)
886 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
889 hasHiddenRows = false;
890 hiddenRepSequences = null;
892 firePropertyChange("alignment", null, alignment.getSequences());
893 // used to set hasHiddenRows/hiddenRepSequences here, after the property
899 public void showSequence(int index)
901 Vector tmp = alignment.getHiddenSequences().showSequence(index,
905 if (selectionGroup == null)
907 selectionGroup = new SequenceGroup();
908 selectionGroup.setEndRes(alignment.getWidth() - 1);
911 for (int t = 0; t < tmp.size(); t++)
913 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
915 // JBPNote: refactor: only update flag if we modified visiblity (used to
916 // do this regardless)
917 if (alignment.getHiddenSequences().getSize() < 1)
919 hasHiddenRows = false;
921 firePropertyChange("alignment", null, alignment.getSequences());
926 public void hideAllSelectedSeqs()
928 if (selectionGroup == null || selectionGroup.getSize() < 1)
933 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
937 setSelectionGroup(null);
940 public void hideSequence(SequenceI[] seq)
944 for (int i = 0; i < seq.length; i++)
946 alignment.getHiddenSequences().hideSequence(seq[i]);
948 hasHiddenRows = true;
949 firePropertyChange("alignment", null, alignment.getSequences());
953 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
955 int sSize = sg.getSize();
961 if (hiddenRepSequences == null)
963 hiddenRepSequences = new Hashtable();
966 hiddenRepSequences.put(repSequence, sg);
968 // Hide all sequences except the repSequence
969 SequenceI[] seqs = new SequenceI[sSize - 1];
971 for (int i = 0; i < sSize; i++)
973 if (sg.getSequenceAt(i) != repSequence)
975 if (index == sSize - 1)
980 seqs[index++] = sg.getSequenceAt(i);
983 sg.setSeqrep(repSequence); // note: not done in 2.7applet
984 sg.setHidereps(true); // note: not done in 2.7applet
989 public boolean isHiddenRepSequence(SequenceI seq)
991 return hiddenRepSequences != null
992 && hiddenRepSequences.containsKey(seq);
995 public SequenceGroup getRepresentedSequences(SequenceI seq)
997 return (SequenceGroup) (hiddenRepSequences == null ? null
998 : hiddenRepSequences.get(seq));
1001 public int adjustForHiddenSeqs(int alignmentIndex)
1003 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1007 // Selection manipulation
1009 * broadcast selection to any interested parties
1011 public abstract void sendSelection();
1013 public void invertColumnSelection()
1015 colSel.invertColumnSelection(0, alignment.getWidth());
1019 * This method returns an array of new SequenceI objects derived from the
1020 * whole alignment or just the current selection with start and end points
1023 * @note if you need references to the actual SequenceI objects in the
1024 * alignment or currently selected then use getSequenceSelection()
1025 * @return selection as new sequenceI objects
1027 public SequenceI[] getSelectionAsNewSequence()
1029 SequenceI[] sequences;
1030 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1031 // this was the only caller in the applet for this method
1032 // JBPNote: in applet, this method returned references to the alignment
1033 // sequences, and it did not honour the presence/absence of annotation
1034 // attached to the alignment (probably!)
1035 if (selectionGroup == null || selectionGroup.getSize() == 0)
1037 sequences = alignment.getSequencesArray();
1038 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1039 for (int i = 0; i < sequences.length; i++)
1041 sequences[i] = new Sequence(sequences[i], annots); // construct new
1043 // subset of visible
1049 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1056 * get the currently selected sequence objects or all the sequences in the
1059 * @return array of references to sequence objects
1062 public SequenceI[] getSequenceSelection()
1064 SequenceI[] sequences = null;
1065 if (selectionGroup != null)
1067 sequences = selectionGroup.getSequencesInOrder(alignment);
1069 if (sequences == null)
1071 sequences = alignment.getSequencesArray();
1077 * This method returns the visible alignment as text, as seen on the GUI, ie
1078 * if columns are hidden they will not be returned in the result. Use this for
1079 * calculating trees, PCA, redundancy etc on views which contain hidden
1085 public jalview.datamodel.CigarArray getViewAsCigars(
1086 boolean selectedRegionOnly)
1088 return new jalview.datamodel.CigarArray(alignment,
1089 (hasHiddenColumns ? colSel : null),
1090 (selectedRegionOnly ? selectionGroup : null));
1094 * return a compact representation of the current alignment selection to pass
1095 * to an analysis function
1097 * @param selectedOnly
1098 * boolean true to just return the selected view
1099 * @return AlignmentView
1102 public jalview.datamodel.AlignmentView getAlignmentView(
1103 boolean selectedOnly)
1105 return getAlignmentView(selectedOnly, false);
1109 * return a compact representation of the current alignment selection to pass
1110 * to an analysis function
1112 * @param selectedOnly
1113 * boolean true to just return the selected view
1115 * boolean true to annotate the alignment view with groups on the
1116 * alignment (and intersecting with selected region if selectedOnly
1118 * @return AlignmentView
1121 public jalview.datamodel.AlignmentView getAlignmentView(
1122 boolean selectedOnly, boolean markGroups)
1124 return new AlignmentView(alignment, colSel, selectionGroup,
1125 hasHiddenColumns, selectedOnly, markGroups);
1129 * This method returns the visible alignment as text, as seen on the GUI, ie
1130 * if columns are hidden they will not be returned in the result. Use this for
1131 * calculating trees, PCA, redundancy etc on views which contain hidden
1137 public String[] getViewAsString(boolean selectedRegionOnly)
1139 String[] selection = null;
1140 SequenceI[] seqs = null;
1142 int start = 0, end = 0;
1143 if (selectedRegionOnly && selectionGroup != null)
1145 iSize = selectionGroup.getSize();
1146 seqs = selectionGroup.getSequencesInOrder(alignment);
1147 start = selectionGroup.getStartRes();
1148 end = selectionGroup.getEndRes() + 1;
1152 iSize = alignment.getHeight();
1153 seqs = alignment.getSequencesArray();
1154 end = alignment.getWidth();
1157 selection = new String[iSize];
1158 if (hasHiddenColumns)
1160 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1164 for (i = 0; i < iSize; i++)
1166 selection[i] = seqs[i].getSequenceAsString(start, end);
1174 * return visible region boundaries within given column range
1177 * first column (inclusive, from 0)
1179 * last column (exclusive)
1180 * @return int[][] range of {start,end} visible positions
1182 public int[][] getVisibleRegionBoundaries(int min, int max)
1184 Vector regions = new Vector();
1190 if (hasHiddenColumns)
1194 start = colSel.adjustForHiddenColumns(start);
1197 end = colSel.getHiddenBoundaryRight(start);
1208 regions.addElement(new int[]
1211 if (hasHiddenColumns)
1213 start = colSel.adjustForHiddenColumns(end);
1214 start = colSel.getHiddenBoundaryLeft(start) + 1;
1216 } while (end < max);
1218 int[][] startEnd = new int[regions.size()][2];
1220 regions.copyInto(startEnd);
1227 * @return the padGaps
1229 public boolean isPadGaps()
1236 * the padGaps to set
1238 public void setPadGaps(boolean padGaps)
1240 this.padGaps = padGaps;
1244 * apply any post-edit constraints and trigger any calculations needed after
1245 * an edit has been performed on the alignment
1249 public void alignmentChanged(AlignmentViewPanel ap)
1253 alignment.padGaps();
1255 if (autoCalculateConsensus)
1257 updateConsensus(ap);
1259 if (hconsensus != null && autoCalculateConsensus)
1261 updateConservation(ap);
1263 if (autoCalculateStrucConsensus)
1265 updateStrucConsensus(ap);
1268 // Reset endRes of groups if beyond alignment width
1269 int alWidth = alignment.getWidth();
1270 List<SequenceGroup> groups = alignment.getGroups();
1273 for (SequenceGroup sg : groups)
1275 if (sg.getEndRes() > alWidth)
1277 sg.setEndRes(alWidth - 1);
1282 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1284 selectionGroup.setEndRes(alWidth - 1);
1287 resetAllColourSchemes();
1288 calculator.restartWorkers();
1289 // alignment.adjustSequenceAnnotations();
1293 * reset scope and do calculations for all applied colourschemes on alignment
1295 void resetAllColourSchemes()
1297 ColourSchemeI cs = globalColourScheme;
1300 cs.alignmentChanged(alignment, null);
1302 cs.setConsensus(hconsensus);
1303 if (cs.conservationApplied())
1305 cs.setConservation(Conservation.calculateConservation("All",
1306 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1307 alignment.getWidth(), false, getConsPercGaps(), false));
1311 for (SequenceGroup sg : alignment.getGroups())
1315 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1317 sg.recalcConservation();
1321 protected void initAutoAnnotation()
1323 // TODO: add menu option action that nulls or creates consensus object
1324 // depending on if the user wants to see the annotation or not in a
1325 // specific alignment
1327 if (hconsensus == null && !isDataset)
1329 if (!alignment.isNucleotide())
1342 private void initConsensus()
1345 consensus = new AlignmentAnnotation("Consensus", "PID",
1346 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1347 consensus.hasText = true;
1348 consensus.autoCalculated = true;
1352 alignment.addAnnotation(consensus);
1356 private void initConservation()
1358 if (showConservation)
1360 if (conservation == null)
1362 conservation = new AlignmentAnnotation("Conservation",
1363 "Conservation of total alignment less than "
1364 + getConsPercGaps() + "% gaps",
1365 new Annotation[1], 0f, 11f,
1366 AlignmentAnnotation.BAR_GRAPH);
1367 conservation.hasText = true;
1368 conservation.autoCalculated = true;
1369 alignment.addAnnotation(conservation);
1373 private void initQuality()
1377 if (quality == null)
1379 quality = new AlignmentAnnotation("Quality",
1380 "Alignment Quality based on Blosum62 scores",
1381 new Annotation[1], 0f, 11f,
1382 AlignmentAnnotation.BAR_GRAPH);
1383 quality.hasText = true;
1384 quality.autoCalculated = true;
1385 alignment.addAnnotation(quality);
1389 private void initRNAStructure()
1391 if (alignment.hasRNAStructure() && strucConsensus==null)
1393 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1394 new Annotation[1], 0f, 100f,
1395 AlignmentAnnotation.BAR_GRAPH);
1396 strucConsensus.hasText = true;
1397 strucConsensus.autoCalculated = true;
1401 alignment.addAnnotation(strucConsensus);
1408 * @see jalview.api.AlignViewportI#calcPanelHeight()
1410 public int calcPanelHeight()
1412 // setHeight of panels
1413 AlignmentAnnotation[] aa = getAlignment().getAlignmentAnnotation();
1415 int charHeight = getCharHeight();
1418 BitSet graphgrp = new BitSet();
1419 for (int i = 0; i < aa.length; i++)
1423 System.err.println("Null annotation row: ignoring.");
1430 if (aa[i].graphGroup > -1)
1432 if (graphgrp.get(aa[i].graphGroup))
1438 graphgrp.set(aa[i].graphGroup);
1445 aa[i].height += charHeight;
1453 if (aa[i].graph > 0)
1455 aa[i].height += aa[i].graphHeight;
1458 if (aa[i].height == 0)
1463 height += aa[i].height;
1475 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1476 boolean preserveNewGroupSettings)
1478 boolean updateCalcs = false;
1479 boolean conv = isShowGroupConservation();
1480 boolean cons = isShowGroupConsensus();
1481 boolean showprf = isShowSequenceLogo();
1482 boolean showConsHist = isShowConsensusHistogram();
1483 boolean normLogo = isNormaliseSequenceLogo();
1486 * TODO reorder the annotation rows according to group/sequence ordering on
1489 boolean sortg = true;
1491 // remove old automatic annotation
1492 // add any new annotation
1494 // intersect alignment annotation with alignment groups
1496 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
1497 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
1500 for (int an = 0; an < aan.length; an++)
1502 if (aan[an].autoCalculated && aan[an].groupRef != null)
1504 oldrfs.add(aan[an].groupRef);
1505 alignment.deleteAnnotation(aan[an]);
1510 if (alignment.getGroups() != null)
1512 for (SequenceGroup sg : alignment.getGroups())
1514 updateCalcs = false;
1515 if (applyGlobalSettings
1516 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
1518 // set defaults for this group's conservation/consensus
1519 sg.setshowSequenceLogo(showprf);
1520 sg.setShowConsensusHistogram(showConsHist);
1521 sg.setNormaliseSequenceLogo(normLogo);
1526 alignment.addAnnotation(sg.getConservationRow(), 0);
1531 alignment.addAnnotation(sg.getConsensus(), 0);
1533 // refresh the annotation rows
1536 sg.recalcConservation();