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.awt.Color;
45 import java.util.ArrayList;
46 import java.util.BitSet;
47 import java.util.Hashtable;
48 import java.util.List;
50 import java.util.Vector;
53 * base class holding visualization and analysis attributes and common logic for
54 * an active alignment view displayed in the GUI
59 public abstract class AlignmentViewport implements AlignViewportI
62 * alignment displayed in the viewport. Please use get/setter
64 protected AlignmentI alignment;
66 protected String sequenceSetID;
69 * probably unused indicator that view is of a dataset rather than an
72 protected boolean isDataset = false;
74 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
76 protected ColumnSelection colSel = new ColumnSelection();
78 public boolean autoCalculateConsensus = true;
80 protected boolean autoCalculateStrucConsensus = true;
82 protected boolean ignoreGapsInConsensusCalculation = false;
84 protected ColourSchemeI globalColourScheme = null;
87 * gui state - changes to colour scheme propagated to all groups
89 private boolean colourAppliesToAllGroups;
93 * indicating if subsequent colourscheme changes will be propagated
96 public void setColourAppliesToAllGroups(boolean b)
98 colourAppliesToAllGroups = b;
104 * @return flag indicating if colourchanges propagated to all groups
106 public boolean getColourAppliesToAllGroups()
108 return colourAppliesToAllGroups;
111 boolean abovePIDThreshold = false;
116 * @return true if percent identity threshold is applied to shading
118 public boolean getAbovePIDThreshold()
120 return abovePIDThreshold;
128 * indicate if percent identity threshold is applied to shading
130 public void setAbovePIDThreshold(boolean b)
132 abovePIDThreshold = b;
143 public void setThreshold(int thresh)
151 * @return DOCUMENT ME!
153 public int getThreshold()
163 * set the scalar for bleaching colourschemes according to degree of
166 public void setIncrement(int inc)
174 * @return get scalar for bleaching colourschemes by conservation
176 public int getIncrement()
181 boolean conservationColourSelected = false;
186 * @return true if conservation based shading is enabled
188 public boolean getConservationSelected()
190 return conservationColourSelected;
197 * enable conservation based shading
199 public void setConservationSelected(boolean b)
201 conservationColourSelected = b;
205 public void setGlobalColourScheme(ColourSchemeI cs)
207 // TODO: logic refactored from AlignFrame changeColour -
208 // autorecalc stuff should be changed to rely on the worker system
209 // check to see if we should implement a changeColour(cs) method rather than
210 // put th logic in here
211 // - means that caller decides if they want to just modify state and defer
212 // calculation till later or to do all calculations in thread.
214 globalColourScheme = cs;
215 if (getColourAppliesToAllGroups())
217 for (SequenceGroup sg : getAlignment().getGroups())
224 if (cs instanceof ClustalxColourScheme)
226 sg.cs = new ClustalxColourScheme(sg, getHiddenRepSequences());
232 sg.cs = cs.getClass().newInstance();
233 } catch (Exception ex)
235 ex.printStackTrace();
240 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
241 || cs instanceof Blosum62ColourScheme)
243 sg.cs.setThreshold(threshold, getIgnoreGapsConsensus());
244 sg.cs.setConsensus(AAFrequency.calculate(
245 sg.getSequences(getHiddenRepSequences()), 0,
250 sg.cs.setThreshold(0, getIgnoreGapsConsensus());
253 if (getConservationSelected())
255 Conservation c = new Conservation("Group",
256 ResidueProperties.propHash, 3,
257 sg.getSequences(getHiddenRepSequences()), 0,
258 getAlignment().getWidth() - 1);
260 c.verdict(false, getConsPercGaps());
261 sg.cs.setConservation(c);
265 sg.cs.setConservation(null);
266 sg.cs.setThreshold(0, getIgnoreGapsConsensus());
275 public ColourSchemeI getGlobalColourScheme()
277 return globalColourScheme;
280 protected AlignmentAnnotation consensus;
282 protected AlignmentAnnotation strucConsensus;
284 protected AlignmentAnnotation conservation;
286 protected AlignmentAnnotation quality;
288 protected AlignmentAnnotation[] groupConsensus;
290 protected AlignmentAnnotation[] groupConservation;
293 * results of alignment consensus analysis for visible portion of view
295 protected Hashtable[] hconsensus = null;
298 * results of secondary structure base pair consensus for visible portion of
301 protected Hashtable[] hStrucConsensus = null;
304 * percentage gaps allowed in a column before all amino acid properties should
305 * be considered unconserved
307 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
310 public int getConsPercGaps()
316 public void setSequenceConsensusHash(Hashtable[] hconsensus)
318 this.hconsensus = hconsensus;
323 public Hashtable[] getSequenceConsensusHash()
329 public Hashtable[] getRnaStructureConsensusHash()
331 return hStrucConsensus;
335 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
337 this.hStrucConsensus = hStrucConsensus;
342 public AlignmentAnnotation getAlignmentQualityAnnot()
348 public AlignmentAnnotation getAlignmentConservationAnnotation()
354 public AlignmentAnnotation getAlignmentConsensusAnnotation()
360 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
362 return strucConsensus;
365 protected AlignCalcManagerI calculator = new AlignCalcManager();
368 * trigger update of conservation annotation
370 public void updateConservation(final AlignmentViewPanel ap)
372 // see note in mantis : issue number 8585
373 if (alignment.isNucleotide() || conservation == null
374 || !autoCalculateConsensus)
379 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
381 calculator.registerWorker(new jalview.workers.ConservationThread(
387 * trigger update of consensus annotation
389 public void updateConsensus(final AlignmentViewPanel ap)
391 // see note in mantis : issue number 8585
392 if (consensus == null || !autoCalculateConsensus)
396 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
398 calculator.registerWorker(new ConsensusThread(this, ap));
402 // --------START Structure Conservation
403 public void updateStrucConsensus(final AlignmentViewPanel ap)
405 if (autoCalculateStrucConsensus && strucConsensus == null
406 && alignment.isNucleotide() && alignment.hasRNAStructure())
408 // secondary structure has been added - so init the consensus line
412 // see note in mantis : issue number 8585
413 if (strucConsensus == null || !autoCalculateStrucConsensus)
417 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
419 calculator.registerWorker(new StrucConsensusThread(this, ap));
423 public boolean isCalcInProgress()
425 return calculator.isWorking();
429 public boolean isCalculationInProgress(
430 AlignmentAnnotation alignmentAnnotation)
432 if (!alignmentAnnotation.autoCalculated)
434 if (calculator.workingInvolvedWith(alignmentAnnotation))
436 // System.err.println("grey out ("+alignmentAnnotation.label+")");
443 public boolean isClosed()
445 // TODO: check that this isClosed is only true after panel is closed, not
446 // before it is fully constructed.
447 return alignment == null;
451 public AlignCalcManagerI getCalcManager()
457 * should conservation rows be shown for groups
459 protected boolean showGroupConservation = false;
462 * should consensus rows be shown for groups
464 protected boolean showGroupConsensus = false;
467 * should consensus profile be rendered by default
469 protected boolean showSequenceLogo = false;
472 * should consensus profile be rendered normalised to row height
474 protected boolean normaliseSequenceLogo = false;
477 * should consensus histograms be rendered by default
479 protected boolean showConsensusHistogram = true;
482 * @return the showConsensusProfile
485 public boolean isShowSequenceLogo()
487 return showSequenceLogo;
491 * @param showSequenceLogo
494 public void setShowSequenceLogo(boolean showSequenceLogo)
496 if (showSequenceLogo != this.showSequenceLogo)
498 // TODO: decouple settings setting from calculation when refactoring
499 // annotation update method from alignframe to viewport
500 this.showSequenceLogo = showSequenceLogo;
501 calculator.updateAnnotationFor(ConsensusThread.class);
502 calculator.updateAnnotationFor(StrucConsensusThread.class);
504 this.showSequenceLogo = showSequenceLogo;
508 * @param showConsensusHistogram
509 * the showConsensusHistogram to set
511 public void setShowConsensusHistogram(boolean showConsensusHistogram)
513 this.showConsensusHistogram = showConsensusHistogram;
517 * @return the showGroupConservation
519 public boolean isShowGroupConservation()
521 return showGroupConservation;
525 * @param showGroupConservation
526 * the showGroupConservation to set
528 public void setShowGroupConservation(boolean showGroupConservation)
530 this.showGroupConservation = showGroupConservation;
534 * @return the showGroupConsensus
536 public boolean isShowGroupConsensus()
538 return showGroupConsensus;
542 * @param showGroupConsensus
543 * the showGroupConsensus to set
545 public void setShowGroupConsensus(boolean showGroupConsensus)
547 this.showGroupConsensus = showGroupConsensus;
552 * @return flag to indicate if the consensus histogram should be rendered by
556 public boolean isShowConsensusHistogram()
558 return this.showConsensusHistogram;
562 * show non-conserved residues only
564 protected boolean showUnconserved = false;
567 * when set, updateAlignment will always ensure sequences are of equal length
569 private boolean padGaps = false;
572 * when set, alignment should be reordered according to a newly opened tree
574 public boolean sortByTree = false;
576 public boolean getShowUnconserved()
578 return showUnconserved;
581 public void setShowUnconserved(boolean showunconserved)
583 showUnconserved = showunconserved;
587 * @param showNonconserved
588 * the showUnconserved to set
590 public void setShowunconserved(boolean displayNonconserved)
592 this.showUnconserved = displayNonconserved;
598 * @return null or the currently selected sequence region
601 public SequenceGroup getSelectionGroup()
603 return selectionGroup;
607 * Set the selection group for this window.
610 * - group holding references to sequences in this alignment view
614 public void setSelectionGroup(SequenceGroup sg)
619 public void setHiddenColumns(ColumnSelection colsel)
621 this.colSel = colsel;
622 if (colSel.getHiddenColumns() != null)
624 hasHiddenColumns = true;
629 public ColumnSelection getColumnSelection()
634 public void setColumnSelection(ColumnSelection colSel)
636 this.colSel = colSel;
644 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
646 return hiddenRepSequences;
650 public void setHiddenRepSequences(
651 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
653 this.hiddenRepSequences = hiddenRepSequences;
656 protected boolean hasHiddenColumns = false;
658 public void updateHiddenColumns()
660 hasHiddenColumns = colSel.getHiddenColumns() != null;
663 protected boolean hasHiddenRows = false;
665 public boolean hasHiddenRows()
667 return hasHiddenRows;
670 protected SequenceGroup selectionGroup;
672 public void setSequenceSetId(String newid)
674 if (sequenceSetID != null)
677 .println("Warning - overwriting a sequenceSetId for a viewport!");
679 sequenceSetID = new String(newid);
682 public String getSequenceSetId()
684 if (sequenceSetID == null)
686 sequenceSetID = alignment.hashCode() + "";
689 return sequenceSetID;
693 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
696 protected String viewId = null;
698 public String getViewId()
702 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
707 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
709 ignoreGapsInConsensusCalculation = b;
713 if (globalColourScheme != null)
715 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
716 ignoreGapsInConsensusCalculation);
722 private long sgrouphash = -1, colselhash = -1;
725 * checks current SelectionGroup against record of last hash value, and
729 * update the record of last hash value
731 * @return true if SelectionGroup changed since last call (when b is true)
733 public boolean isSelectionGroupChanged(boolean b)
735 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
736 : selectionGroup.hashCode();
737 if (hc != -1 && hc != sgrouphash)
749 * checks current colsel against record of last hash value, and optionally
753 * update the record of last hash value
754 * @return true if colsel changed since last call (when b is true)
756 public boolean isColSelChanged(boolean b)
758 int hc = (colSel == null || colSel.size() == 0) ? -1 : colSel
760 if (hc != -1 && hc != colselhash)
772 public boolean getIgnoreGapsConsensus()
774 return ignoreGapsInConsensusCalculation;
777 // / property change stuff
779 // JBPNote Prolly only need this in the applet version.
780 private final java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
783 protected boolean showConservation = true;
785 protected boolean showQuality = true;
787 protected boolean showConsensus = true;
789 Hashtable sequenceColours;
792 * Property change listener for changes in alignment
797 public void addPropertyChangeListener(
798 java.beans.PropertyChangeListener listener)
800 changeSupport.addPropertyChangeListener(listener);
809 public void removePropertyChangeListener(
810 java.beans.PropertyChangeListener listener)
812 changeSupport.removePropertyChangeListener(listener);
816 * Property change listener for changes in alignment
825 public void firePropertyChange(String prop, Object oldvalue,
828 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
831 // common hide/show column stuff
833 public void hideSelectedColumns()
835 if (colSel.size() < 1)
840 colSel.hideSelectedColumns();
841 setSelectionGroup(null);
843 hasHiddenColumns = true;
846 public void hideColumns(int start, int end)
850 colSel.hideColumns(start);
854 colSel.hideColumns(start, end);
857 hasHiddenColumns = true;
860 public void showColumn(int col)
862 colSel.revealHiddenColumns(col);
863 if (colSel.getHiddenColumns() == null)
865 hasHiddenColumns = false;
869 public void showAllHiddenColumns()
871 colSel.revealAllHiddenColumns();
872 hasHiddenColumns = false;
875 // common hide/show seq stuff
876 public void showAllHiddenSeqs()
878 if (alignment.getHiddenSequences().getSize() > 0)
880 if (selectionGroup == null)
882 selectionGroup = new SequenceGroup();
883 selectionGroup.setEndRes(alignment.getWidth() - 1);
885 Vector tmp = alignment.getHiddenSequences().showAll(
887 for (int t = 0; t < tmp.size(); t++)
889 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
892 hasHiddenRows = false;
893 hiddenRepSequences = null;
895 firePropertyChange("alignment", null, alignment.getSequences());
896 // used to set hasHiddenRows/hiddenRepSequences here, after the property
902 public void showSequence(int index)
904 Vector tmp = alignment.getHiddenSequences().showSequence(index,
908 if (selectionGroup == null)
910 selectionGroup = new SequenceGroup();
911 selectionGroup.setEndRes(alignment.getWidth() - 1);
914 for (int t = 0; t < tmp.size(); t++)
916 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
918 // JBPNote: refactor: only update flag if we modified visiblity (used to
919 // do this regardless)
920 if (alignment.getHiddenSequences().getSize() < 1)
922 hasHiddenRows = false;
924 firePropertyChange("alignment", null, alignment.getSequences());
929 public void hideAllSelectedSeqs()
931 if (selectionGroup == null || selectionGroup.getSize() < 1)
936 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
940 setSelectionGroup(null);
943 public void hideSequence(SequenceI[] seq)
947 for (int i = 0; i < seq.length; i++)
949 alignment.getHiddenSequences().hideSequence(seq[i]);
951 hasHiddenRows = true;
952 firePropertyChange("alignment", null, alignment.getSequences());
956 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
958 int sSize = sg.getSize();
964 if (hiddenRepSequences == null)
966 hiddenRepSequences = new Hashtable();
969 hiddenRepSequences.put(repSequence, sg);
971 // Hide all sequences except the repSequence
972 SequenceI[] seqs = new SequenceI[sSize - 1];
974 for (int i = 0; i < sSize; i++)
976 if (sg.getSequenceAt(i) != repSequence)
978 if (index == sSize - 1)
983 seqs[index++] = sg.getSequenceAt(i);
986 sg.setSeqrep(repSequence); // note: not done in 2.7applet
987 sg.setHidereps(true); // note: not done in 2.7applet
992 public boolean isHiddenRepSequence(SequenceI seq)
994 return hiddenRepSequences != null
995 && hiddenRepSequences.containsKey(seq);
998 public SequenceGroup getRepresentedSequences(SequenceI seq)
1000 return (SequenceGroup) (hiddenRepSequences == null ? null
1001 : hiddenRepSequences.get(seq));
1004 public int adjustForHiddenSeqs(int alignmentIndex)
1006 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1010 // Selection manipulation
1012 * broadcast selection to any interested parties
1014 public abstract void sendSelection();
1016 public void invertColumnSelection()
1018 colSel.invertColumnSelection(0, alignment.getWidth());
1022 * This method returns an array of new SequenceI objects derived from the
1023 * whole alignment or just the current selection with start and end points
1026 * @note if you need references to the actual SequenceI objects in the
1027 * alignment or currently selected then use getSequenceSelection()
1028 * @return selection as new sequenceI objects
1030 public SequenceI[] getSelectionAsNewSequence()
1032 SequenceI[] sequences;
1033 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1034 // this was the only caller in the applet for this method
1035 // JBPNote: in applet, this method returned references to the alignment
1036 // sequences, and it did not honour the presence/absence of annotation
1037 // attached to the alignment (probably!)
1038 if (selectionGroup == null || selectionGroup.getSize() == 0)
1040 sequences = alignment.getSequencesArray();
1041 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1042 for (int i = 0; i < sequences.length; i++)
1044 sequences[i] = new Sequence(sequences[i], annots); // construct new
1046 // subset of visible
1052 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1059 * get the currently selected sequence objects or all the sequences in the
1062 * @return array of references to sequence objects
1065 public SequenceI[] getSequenceSelection()
1067 SequenceI[] sequences = null;
1068 if (selectionGroup != null)
1070 sequences = selectionGroup.getSequencesInOrder(alignment);
1072 if (sequences == null)
1074 sequences = alignment.getSequencesArray();
1080 * This method returns the visible alignment as text, as seen on the GUI, ie
1081 * if columns are hidden they will not be returned in the result. Use this for
1082 * calculating trees, PCA, redundancy etc on views which contain hidden
1088 public jalview.datamodel.CigarArray getViewAsCigars(
1089 boolean selectedRegionOnly)
1091 return new jalview.datamodel.CigarArray(alignment,
1092 (hasHiddenColumns ? colSel : null),
1093 (selectedRegionOnly ? selectionGroup : null));
1097 * return a compact representation of the current alignment selection to pass
1098 * to an analysis function
1100 * @param selectedOnly
1101 * boolean true to just return the selected view
1102 * @return AlignmentView
1105 public jalview.datamodel.AlignmentView getAlignmentView(
1106 boolean selectedOnly)
1108 return getAlignmentView(selectedOnly, false);
1112 * return a compact representation of the current alignment selection to pass
1113 * to an analysis function
1115 * @param selectedOnly
1116 * boolean true to just return the selected view
1118 * boolean true to annotate the alignment view with groups on the
1119 * alignment (and intersecting with selected region if selectedOnly
1121 * @return AlignmentView
1124 public jalview.datamodel.AlignmentView getAlignmentView(
1125 boolean selectedOnly, boolean markGroups)
1127 return new AlignmentView(alignment, colSel, selectionGroup,
1128 hasHiddenColumns, selectedOnly, markGroups);
1132 * This method returns the visible alignment as text, as seen on the GUI, ie
1133 * if columns are hidden they will not be returned in the result. Use this for
1134 * calculating trees, PCA, redundancy etc on views which contain hidden
1140 public String[] getViewAsString(boolean selectedRegionOnly)
1142 String[] selection = null;
1143 SequenceI[] seqs = null;
1145 int start = 0, end = 0;
1146 if (selectedRegionOnly && selectionGroup != null)
1148 iSize = selectionGroup.getSize();
1149 seqs = selectionGroup.getSequencesInOrder(alignment);
1150 start = selectionGroup.getStartRes();
1151 end = selectionGroup.getEndRes() + 1;
1155 iSize = alignment.getHeight();
1156 seqs = alignment.getSequencesArray();
1157 end = alignment.getWidth();
1160 selection = new String[iSize];
1161 if (hasHiddenColumns)
1163 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1167 for (i = 0; i < iSize; i++)
1169 selection[i] = seqs[i].getSequenceAsString(start, end);
1177 * return visible region boundaries within given column range
1180 * first column (inclusive, from 0)
1182 * last column (exclusive)
1183 * @return int[][] range of {start,end} visible positions
1185 public int[][] getVisibleRegionBoundaries(int min, int max)
1187 Vector regions = new Vector();
1193 if (hasHiddenColumns)
1197 start = colSel.adjustForHiddenColumns(start);
1200 end = colSel.getHiddenBoundaryRight(start);
1211 regions.addElement(new int[]
1214 if (hasHiddenColumns)
1216 start = colSel.adjustForHiddenColumns(end);
1217 start = colSel.getHiddenBoundaryLeft(start) + 1;
1219 } while (end < max);
1221 int[][] startEnd = new int[regions.size()][2];
1223 regions.copyInto(startEnd);
1230 * @return the padGaps
1232 public boolean isPadGaps()
1239 * the padGaps to set
1241 public void setPadGaps(boolean padGaps)
1243 this.padGaps = padGaps;
1247 * apply any post-edit constraints and trigger any calculations needed after
1248 * an edit has been performed on the alignment
1252 public void alignmentChanged(AlignmentViewPanel ap)
1256 alignment.padGaps();
1258 if (autoCalculateConsensus)
1260 updateConsensus(ap);
1262 if (hconsensus != null && autoCalculateConsensus)
1264 updateConservation(ap);
1266 if (autoCalculateStrucConsensus)
1268 updateStrucConsensus(ap);
1271 // Reset endRes of groups if beyond alignment width
1272 int alWidth = alignment.getWidth();
1273 List<SequenceGroup> groups = alignment.getGroups();
1276 for (SequenceGroup sg : groups)
1278 if (sg.getEndRes() > alWidth)
1280 sg.setEndRes(alWidth - 1);
1285 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1287 selectionGroup.setEndRes(alWidth - 1);
1290 resetAllColourSchemes();
1291 calculator.restartWorkers();
1292 // alignment.adjustSequenceAnnotations();
1296 * reset scope and do calculations for all applied colourschemes on alignment
1298 void resetAllColourSchemes()
1300 ColourSchemeI cs = globalColourScheme;
1303 cs.alignmentChanged(alignment, null);
1305 cs.setConsensus(hconsensus);
1306 if (cs.conservationApplied())
1308 cs.setConservation(Conservation.calculateConservation("All",
1309 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1310 alignment.getWidth(), false, getConsPercGaps(), false));
1314 for (SequenceGroup sg : alignment.getGroups())
1318 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1320 sg.recalcConservation();
1324 protected void initAutoAnnotation()
1326 // TODO: add menu option action that nulls or creates consensus object
1327 // depending on if the user wants to see the annotation or not in a
1328 // specific alignment
1330 if (hconsensus == null && !isDataset)
1332 if (!alignment.isNucleotide())
1345 private void initConsensus()
1348 consensus = new AlignmentAnnotation("Consensus", "PID",
1349 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1350 consensus.hasText = true;
1351 consensus.autoCalculated = true;
1355 alignment.addAnnotation(consensus);
1359 private void initConservation()
1361 if (showConservation)
1363 if (conservation == null)
1365 conservation = new AlignmentAnnotation("Conservation",
1366 "Conservation of total alignment less than "
1367 + getConsPercGaps() + "% gaps",
1368 new Annotation[1], 0f, 11f,
1369 AlignmentAnnotation.BAR_GRAPH);
1370 conservation.hasText = true;
1371 conservation.autoCalculated = true;
1372 alignment.addAnnotation(conservation);
1376 private void initQuality()
1380 if (quality == null)
1382 quality = new AlignmentAnnotation("Quality",
1383 "Alignment Quality based on Blosum62 scores",
1384 new Annotation[1], 0f, 11f,
1385 AlignmentAnnotation.BAR_GRAPH);
1386 quality.hasText = true;
1387 quality.autoCalculated = true;
1388 alignment.addAnnotation(quality);
1392 private void initRNAStructure()
1394 if (alignment.hasRNAStructure() && strucConsensus==null)
1396 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1397 new Annotation[1], 0f, 100f,
1398 AlignmentAnnotation.BAR_GRAPH);
1399 strucConsensus.hasText = true;
1400 strucConsensus.autoCalculated = true;
1404 alignment.addAnnotation(strucConsensus);
1411 * @see jalview.api.AlignViewportI#calcPanelHeight()
1413 public int calcPanelHeight()
1415 // setHeight of panels
1416 AlignmentAnnotation[] aa = getAlignment().getAlignmentAnnotation();
1418 int charHeight = getCharHeight();
1421 BitSet graphgrp = new BitSet();
1422 for (int i = 0; i < aa.length; i++)
1426 System.err.println("Null annotation row: ignoring.");
1433 if (aa[i].graphGroup > -1)
1435 if (graphgrp.get(aa[i].graphGroup))
1441 graphgrp.set(aa[i].graphGroup);
1448 aa[i].height += charHeight;
1456 if (aa[i].graph > 0)
1458 aa[i].height += aa[i].graphHeight;
1461 if (aa[i].height == 0)
1466 height += aa[i].height;
1478 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1479 boolean preserveNewGroupSettings)
1481 boolean updateCalcs = false;
1482 boolean conv = isShowGroupConservation();
1483 boolean cons = isShowGroupConsensus();
1484 boolean showprf = isShowSequenceLogo();
1485 boolean showConsHist = isShowConsensusHistogram();
1486 boolean normLogo = isNormaliseSequenceLogo();
1489 * TODO reorder the annotation rows according to group/sequence ordering on
1492 boolean sortg = true;
1494 // remove old automatic annotation
1495 // add any new annotation
1497 // intersect alignment annotation with alignment groups
1499 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
1500 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
1503 for (int an = 0; an < aan.length; an++)
1505 if (aan[an].autoCalculated && aan[an].groupRef != null)
1507 oldrfs.add(aan[an].groupRef);
1508 alignment.deleteAnnotation(aan[an]);
1513 if (alignment.getGroups() != null)
1515 for (SequenceGroup sg : alignment.getGroups())
1517 updateCalcs = false;
1518 if (applyGlobalSettings
1519 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
1521 // set defaults for this group's conservation/consensus
1522 sg.setshowSequenceLogo(showprf);
1523 sg.setShowConsensusHistogram(showConsHist);
1524 sg.setNormaliseSequenceLogo(normLogo);
1529 alignment.addAnnotation(sg.getConservationRow(), 0);
1534 alignment.addAnnotation(sg.getConsensus(), 0);
1536 // refresh the annotation rows
1539 sg.recalcConservation();
1547 public Color getSequenceColour(SequenceI seq)
1549 Color sqc=Color.white;
1550 if (sequenceColours != null)
1552 sqc = (Color) sequenceColours.get(seq);
1561 public void setSequenceColour(SequenceI seq, Color col)
1563 if (sequenceColours == null)
1565 sequenceColours = new Hashtable();
1570 sequenceColours.remove(seq);
1574 sequenceColours.put(seq, col);
1579 public void updateSequenceIdColours()
1581 if (sequenceColours == null)
1583 sequenceColours = new Hashtable();
1585 for (SequenceGroup sg : alignment.getGroups())
1587 if (sg.idColour != null)
1589 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
1591 sequenceColours.put(s, sg.idColour);
1598 public void clearSequenceColours()
1600 sequenceColours = null;