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 boolean recalc=false;
218 cs.setConservationApplied(recalc = getConservationSelected());
219 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme || cs instanceof Blosum62ColourScheme)
222 cs.setThreshold(threshold, ignoreGapsInConsensusCalculation);
224 cs.setThreshold(0, ignoreGapsInConsensusCalculation);
228 cs.setConsensus(hconsensus);
229 cs.setConservation(hconservation);
231 cs.alignmentChanged(alignment, hiddenRepSequences);
233 if (getColourAppliesToAllGroups())
235 for (SequenceGroup sg : getAlignment().getGroups())
242 sg.cs = cs.applyTo(sg, getHiddenRepSequences());
243 sg.setConsPercGaps(ConsPercGaps);
244 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
245 || cs instanceof Blosum62ColourScheme)
247 sg.cs.setThreshold(threshold, getIgnoreGapsConsensus());
252 sg.cs.setThreshold(0, getIgnoreGapsConsensus());
255 if (getConservationSelected())
257 sg.cs.setConservationApplied(true);
262 sg.cs.setConservation(null);
263 // sg.cs.setThreshold(0, getIgnoreGapsConsensus());
266 sg.recalcConservation();
268 sg.cs.alignmentChanged(sg, hiddenRepSequences);
276 public ColourSchemeI getGlobalColourScheme()
278 return globalColourScheme;
281 protected AlignmentAnnotation consensus;
283 protected AlignmentAnnotation strucConsensus;
285 protected AlignmentAnnotation conservation;
287 protected AlignmentAnnotation quality;
289 protected AlignmentAnnotation[] groupConsensus;
291 protected AlignmentAnnotation[] groupConservation;
294 * results of alignment consensus analysis for visible portion of view
296 protected Hashtable[] hconsensus = null;
299 * results of secondary structure base pair consensus for visible portion of
302 protected Hashtable[] hStrucConsensus = null;
304 protected Conservation hconservation = null;
306 public void setConservation(Conservation cons)
308 hconservation = cons;
311 * percentage gaps allowed in a column before all amino acid properties should
312 * be considered unconserved
314 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
317 public int getConsPercGaps()
323 public void setSequenceConsensusHash(Hashtable[] hconsensus)
325 this.hconsensus = hconsensus;
330 public Hashtable[] getSequenceConsensusHash()
336 public Hashtable[] getRnaStructureConsensusHash()
338 return hStrucConsensus;
342 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
344 this.hStrucConsensus = hStrucConsensus;
349 public AlignmentAnnotation getAlignmentQualityAnnot()
355 public AlignmentAnnotation getAlignmentConservationAnnotation()
361 public AlignmentAnnotation getAlignmentConsensusAnnotation()
367 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
369 return strucConsensus;
372 protected AlignCalcManagerI calculator = new AlignCalcManager();
375 * trigger update of conservation annotation
377 public void updateConservation(final AlignmentViewPanel ap)
379 // see note in mantis : issue number 8585
380 if (alignment.isNucleotide() || conservation == null
381 || !autoCalculateConsensus)
386 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
388 calculator.registerWorker(new jalview.workers.ConservationThread(
394 * trigger update of consensus annotation
396 public void updateConsensus(final AlignmentViewPanel ap)
398 // see note in mantis : issue number 8585
399 if (consensus == null || !autoCalculateConsensus)
403 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
405 calculator.registerWorker(new ConsensusThread(this, ap));
409 // --------START Structure Conservation
410 public void updateStrucConsensus(final AlignmentViewPanel ap)
412 if (autoCalculateStrucConsensus && strucConsensus == null
413 && alignment.isNucleotide() && alignment.hasRNAStructure())
415 // secondary structure has been added - so init the consensus line
419 // see note in mantis : issue number 8585
420 if (strucConsensus == null || !autoCalculateStrucConsensus)
424 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
426 calculator.registerWorker(new StrucConsensusThread(this, ap));
430 public boolean isCalcInProgress()
432 return calculator.isWorking();
436 public boolean isCalculationInProgress(
437 AlignmentAnnotation alignmentAnnotation)
439 if (!alignmentAnnotation.autoCalculated)
441 if (calculator.workingInvolvedWith(alignmentAnnotation))
443 // System.err.println("grey out ("+alignmentAnnotation.label+")");
450 public boolean isClosed()
452 // TODO: check that this isClosed is only true after panel is closed, not
453 // before it is fully constructed.
454 return alignment == null;
458 public AlignCalcManagerI getCalcManager()
464 * should conservation rows be shown for groups
466 protected boolean showGroupConservation = false;
469 * should consensus rows be shown for groups
471 protected boolean showGroupConsensus = false;
474 * should consensus profile be rendered by default
476 protected boolean showSequenceLogo = false;
479 * should consensus profile be rendered normalised to row height
481 protected boolean normaliseSequenceLogo = false;
484 * should consensus histograms be rendered by default
486 protected boolean showConsensusHistogram = true;
489 * @return the showConsensusProfile
492 public boolean isShowSequenceLogo()
494 return showSequenceLogo;
498 * @param showSequenceLogo
501 public void setShowSequenceLogo(boolean showSequenceLogo)
503 if (showSequenceLogo != this.showSequenceLogo)
505 // TODO: decouple settings setting from calculation when refactoring
506 // annotation update method from alignframe to viewport
507 this.showSequenceLogo = showSequenceLogo;
508 calculator.updateAnnotationFor(ConsensusThread.class);
509 calculator.updateAnnotationFor(StrucConsensusThread.class);
511 this.showSequenceLogo = showSequenceLogo;
515 * @param showConsensusHistogram
516 * the showConsensusHistogram to set
518 public void setShowConsensusHistogram(boolean showConsensusHistogram)
520 this.showConsensusHistogram = showConsensusHistogram;
524 * @return the showGroupConservation
526 public boolean isShowGroupConservation()
528 return showGroupConservation;
532 * @param showGroupConservation
533 * the showGroupConservation to set
535 public void setShowGroupConservation(boolean showGroupConservation)
537 this.showGroupConservation = showGroupConservation;
541 * @return the showGroupConsensus
543 public boolean isShowGroupConsensus()
545 return showGroupConsensus;
549 * @param showGroupConsensus
550 * the showGroupConsensus to set
552 public void setShowGroupConsensus(boolean showGroupConsensus)
554 this.showGroupConsensus = showGroupConsensus;
559 * @return flag to indicate if the consensus histogram should be rendered by
563 public boolean isShowConsensusHistogram()
565 return this.showConsensusHistogram;
569 * show non-conserved residues only
571 protected boolean showUnconserved = false;
574 * when set, updateAlignment will always ensure sequences are of equal length
576 private boolean padGaps = false;
579 * when set, alignment should be reordered according to a newly opened tree
581 public boolean sortByTree = false;
583 public boolean getShowUnconserved()
585 return showUnconserved;
588 public void setShowUnconserved(boolean showunconserved)
590 showUnconserved = showunconserved;
594 * @param showNonconserved
595 * the showUnconserved to set
597 public void setShowunconserved(boolean displayNonconserved)
599 this.showUnconserved = displayNonconserved;
605 * @return null or the currently selected sequence region
608 public SequenceGroup getSelectionGroup()
610 return selectionGroup;
614 * Set the selection group for this window.
617 * - group holding references to sequences in this alignment view
621 public void setSelectionGroup(SequenceGroup sg)
626 public void setHiddenColumns(ColumnSelection colsel)
628 this.colSel = colsel;
629 if (colSel.getHiddenColumns() != null)
631 hasHiddenColumns = true;
636 public ColumnSelection getColumnSelection()
641 public void setColumnSelection(ColumnSelection colSel)
643 this.colSel = colSel;
651 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
653 return hiddenRepSequences;
657 public void setHiddenRepSequences(
658 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
660 this.hiddenRepSequences = hiddenRepSequences;
663 protected boolean hasHiddenColumns = false;
665 public void updateHiddenColumns()
667 hasHiddenColumns = colSel.getHiddenColumns() != null;
670 protected boolean hasHiddenRows = false;
672 public boolean hasHiddenRows()
674 return hasHiddenRows;
677 protected SequenceGroup selectionGroup;
679 public void setSequenceSetId(String newid)
681 if (sequenceSetID != null)
684 .println("Warning - overwriting a sequenceSetId for a viewport!");
686 sequenceSetID = new String(newid);
689 public String getSequenceSetId()
691 if (sequenceSetID == null)
693 sequenceSetID = alignment.hashCode() + "";
696 return sequenceSetID;
700 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
703 protected String viewId = null;
705 public String getViewId()
709 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
714 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
716 ignoreGapsInConsensusCalculation = b;
720 if (globalColourScheme != null)
722 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
723 ignoreGapsInConsensusCalculation);
729 private long sgrouphash = -1, colselhash = -1;
732 * checks current SelectionGroup against record of last hash value, and
736 * update the record of last hash value
738 * @return true if SelectionGroup changed since last call (when b is true)
740 public boolean isSelectionGroupChanged(boolean b)
742 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
743 : selectionGroup.hashCode();
744 if (hc != -1 && hc != sgrouphash)
756 * checks current colsel against record of last hash value, and optionally
760 * update the record of last hash value
761 * @return true if colsel changed since last call (when b is true)
763 public boolean isColSelChanged(boolean b)
765 int hc = (colSel == null || colSel.size() == 0) ? -1 : colSel
767 if (hc != -1 && hc != colselhash)
779 public boolean getIgnoreGapsConsensus()
781 return ignoreGapsInConsensusCalculation;
784 // / property change stuff
786 // JBPNote Prolly only need this in the applet version.
787 private final java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
790 protected boolean showConservation = true;
792 protected boolean showQuality = true;
794 protected boolean showConsensus = true;
796 Hashtable sequenceColours;
799 * Property change listener for changes in alignment
804 public void addPropertyChangeListener(
805 java.beans.PropertyChangeListener listener)
807 changeSupport.addPropertyChangeListener(listener);
816 public void removePropertyChangeListener(
817 java.beans.PropertyChangeListener listener)
819 changeSupport.removePropertyChangeListener(listener);
823 * Property change listener for changes in alignment
832 public void firePropertyChange(String prop, Object oldvalue,
835 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
838 // common hide/show column stuff
840 public void hideSelectedColumns()
842 if (colSel.size() < 1)
847 colSel.hideSelectedColumns();
848 setSelectionGroup(null);
850 hasHiddenColumns = true;
853 public void hideColumns(int start, int end)
857 colSel.hideColumns(start);
861 colSel.hideColumns(start, end);
864 hasHiddenColumns = true;
867 public void showColumn(int col)
869 colSel.revealHiddenColumns(col);
870 if (colSel.getHiddenColumns() == null)
872 hasHiddenColumns = false;
876 public void showAllHiddenColumns()
878 colSel.revealAllHiddenColumns();
879 hasHiddenColumns = false;
882 // common hide/show seq stuff
883 public void showAllHiddenSeqs()
885 if (alignment.getHiddenSequences().getSize() > 0)
887 if (selectionGroup == null)
889 selectionGroup = new SequenceGroup();
890 selectionGroup.setEndRes(alignment.getWidth() - 1);
892 Vector tmp = alignment.getHiddenSequences().showAll(
894 for (int t = 0; t < tmp.size(); t++)
896 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
899 hasHiddenRows = false;
900 hiddenRepSequences = null;
902 firePropertyChange("alignment", null, alignment.getSequences());
903 // used to set hasHiddenRows/hiddenRepSequences here, after the property
909 public void showSequence(int index)
911 Vector tmp = alignment.getHiddenSequences().showSequence(index,
915 if (selectionGroup == null)
917 selectionGroup = new SequenceGroup();
918 selectionGroup.setEndRes(alignment.getWidth() - 1);
921 for (int t = 0; t < tmp.size(); t++)
923 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
925 // JBPNote: refactor: only update flag if we modified visiblity (used to
926 // do this regardless)
927 if (alignment.getHiddenSequences().getSize() < 1)
929 hasHiddenRows = false;
931 firePropertyChange("alignment", null, alignment.getSequences());
936 public void hideAllSelectedSeqs()
938 if (selectionGroup == null || selectionGroup.getSize() < 1)
943 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
947 setSelectionGroup(null);
950 public void hideSequence(SequenceI[] seq)
954 for (int i = 0; i < seq.length; i++)
956 alignment.getHiddenSequences().hideSequence(seq[i]);
958 hasHiddenRows = true;
959 firePropertyChange("alignment", null, alignment.getSequences());
963 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
965 int sSize = sg.getSize();
971 if (hiddenRepSequences == null)
973 hiddenRepSequences = new Hashtable();
976 hiddenRepSequences.put(repSequence, sg);
978 // Hide all sequences except the repSequence
979 SequenceI[] seqs = new SequenceI[sSize - 1];
981 for (int i = 0; i < sSize; i++)
983 if (sg.getSequenceAt(i) != repSequence)
985 if (index == sSize - 1)
990 seqs[index++] = sg.getSequenceAt(i);
993 sg.setSeqrep(repSequence); // note: not done in 2.7applet
994 sg.setHidereps(true); // note: not done in 2.7applet
999 public boolean isHiddenRepSequence(SequenceI seq)
1001 return hiddenRepSequences != null
1002 && hiddenRepSequences.containsKey(seq);
1005 public SequenceGroup getRepresentedSequences(SequenceI seq)
1007 return (SequenceGroup) (hiddenRepSequences == null ? null
1008 : hiddenRepSequences.get(seq));
1011 public int adjustForHiddenSeqs(int alignmentIndex)
1013 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1017 // Selection manipulation
1019 * broadcast selection to any interested parties
1021 public abstract void sendSelection();
1023 public void invertColumnSelection()
1025 colSel.invertColumnSelection(0, alignment.getWidth());
1029 * This method returns an array of new SequenceI objects derived from the
1030 * whole alignment or just the current selection with start and end points
1033 * @note if you need references to the actual SequenceI objects in the
1034 * alignment or currently selected then use getSequenceSelection()
1035 * @return selection as new sequenceI objects
1037 public SequenceI[] getSelectionAsNewSequence()
1039 SequenceI[] sequences;
1040 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1041 // this was the only caller in the applet for this method
1042 // JBPNote: in applet, this method returned references to the alignment
1043 // sequences, and it did not honour the presence/absence of annotation
1044 // attached to the alignment (probably!)
1045 if (selectionGroup == null || selectionGroup.getSize() == 0)
1047 sequences = alignment.getSequencesArray();
1048 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1049 for (int i = 0; i < sequences.length; i++)
1051 sequences[i] = new Sequence(sequences[i], annots); // construct new
1053 // subset of visible
1059 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1066 * get the currently selected sequence objects or all the sequences in the
1069 * @return array of references to sequence objects
1072 public SequenceI[] getSequenceSelection()
1074 SequenceI[] sequences = null;
1075 if (selectionGroup != null)
1077 sequences = selectionGroup.getSequencesInOrder(alignment);
1079 if (sequences == null)
1081 sequences = alignment.getSequencesArray();
1087 * This method returns the visible alignment as text, as seen on the GUI, ie
1088 * if columns are hidden they will not be returned in the result. Use this for
1089 * calculating trees, PCA, redundancy etc on views which contain hidden
1095 public jalview.datamodel.CigarArray getViewAsCigars(
1096 boolean selectedRegionOnly)
1098 return new jalview.datamodel.CigarArray(alignment,
1099 (hasHiddenColumns ? colSel : null),
1100 (selectedRegionOnly ? selectionGroup : null));
1104 * return a compact representation of the current alignment selection to pass
1105 * to an analysis function
1107 * @param selectedOnly
1108 * boolean true to just return the selected view
1109 * @return AlignmentView
1112 public jalview.datamodel.AlignmentView getAlignmentView(
1113 boolean selectedOnly)
1115 return getAlignmentView(selectedOnly, false);
1119 * return a compact representation of the current alignment selection to pass
1120 * to an analysis function
1122 * @param selectedOnly
1123 * boolean true to just return the selected view
1125 * boolean true to annotate the alignment view with groups on the
1126 * alignment (and intersecting with selected region if selectedOnly
1128 * @return AlignmentView
1131 public jalview.datamodel.AlignmentView getAlignmentView(
1132 boolean selectedOnly, boolean markGroups)
1134 return new AlignmentView(alignment, colSel, selectionGroup,
1135 hasHiddenColumns, selectedOnly, markGroups);
1139 * This method returns the visible alignment as text, as seen on the GUI, ie
1140 * if columns are hidden they will not be returned in the result. Use this for
1141 * calculating trees, PCA, redundancy etc on views which contain hidden
1147 public String[] getViewAsString(boolean selectedRegionOnly)
1149 String[] selection = null;
1150 SequenceI[] seqs = null;
1152 int start = 0, end = 0;
1153 if (selectedRegionOnly && selectionGroup != null)
1155 iSize = selectionGroup.getSize();
1156 seqs = selectionGroup.getSequencesInOrder(alignment);
1157 start = selectionGroup.getStartRes();
1158 end = selectionGroup.getEndRes() + 1;
1162 iSize = alignment.getHeight();
1163 seqs = alignment.getSequencesArray();
1164 end = alignment.getWidth();
1167 selection = new String[iSize];
1168 if (hasHiddenColumns)
1170 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1174 for (i = 0; i < iSize; i++)
1176 selection[i] = seqs[i].getSequenceAsString(start, end);
1184 * return visible region boundaries within given column range
1187 * first column (inclusive, from 0)
1189 * last column (exclusive)
1190 * @return int[][] range of {start,end} visible positions
1192 public int[][] getVisibleRegionBoundaries(int min, int max)
1194 Vector regions = new Vector();
1200 if (hasHiddenColumns)
1204 start = colSel.adjustForHiddenColumns(start);
1207 end = colSel.getHiddenBoundaryRight(start);
1218 regions.addElement(new int[]
1221 if (hasHiddenColumns)
1223 start = colSel.adjustForHiddenColumns(end);
1224 start = colSel.getHiddenBoundaryLeft(start) + 1;
1226 } while (end < max);
1228 int[][] startEnd = new int[regions.size()][2];
1230 regions.copyInto(startEnd);
1237 * @return the padGaps
1239 public boolean isPadGaps()
1246 * the padGaps to set
1248 public void setPadGaps(boolean padGaps)
1250 this.padGaps = padGaps;
1254 * apply any post-edit constraints and trigger any calculations needed after
1255 * an edit has been performed on the alignment
1259 public void alignmentChanged(AlignmentViewPanel ap)
1263 alignment.padGaps();
1265 if (autoCalculateConsensus)
1267 updateConsensus(ap);
1269 if (hconsensus != null && autoCalculateConsensus)
1271 updateConservation(ap);
1273 if (autoCalculateStrucConsensus)
1275 updateStrucConsensus(ap);
1278 // Reset endRes of groups if beyond alignment width
1279 int alWidth = alignment.getWidth();
1280 List<SequenceGroup> groups = alignment.getGroups();
1283 for (SequenceGroup sg : groups)
1285 if (sg.getEndRes() > alWidth)
1287 sg.setEndRes(alWidth - 1);
1292 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1294 selectionGroup.setEndRes(alWidth - 1);
1297 resetAllColourSchemes();
1298 calculator.restartWorkers();
1299 // alignment.adjustSequenceAnnotations();
1303 * reset scope and do calculations for all applied colourschemes on alignment
1305 void resetAllColourSchemes()
1307 ColourSchemeI cs = globalColourScheme;
1310 cs.alignmentChanged(alignment, hiddenRepSequences);
1312 cs.setConsensus(hconsensus);
1313 if (cs.conservationApplied())
1315 cs.setConservation(Conservation.calculateConservation("All",
1316 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1317 alignment.getWidth(), false, getConsPercGaps(), false));
1321 for (SequenceGroup sg : alignment.getGroups())
1325 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1327 sg.recalcConservation();
1331 protected void initAutoAnnotation()
1333 // TODO: add menu option action that nulls or creates consensus object
1334 // depending on if the user wants to see the annotation or not in a
1335 // specific alignment
1337 if (hconsensus == null && !isDataset)
1339 if (!alignment.isNucleotide())
1352 private void initConsensus()
1355 consensus = new AlignmentAnnotation("Consensus", "PID",
1356 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1357 consensus.hasText = true;
1358 consensus.autoCalculated = true;
1362 alignment.addAnnotation(consensus);
1366 private void initConservation()
1368 if (showConservation)
1370 if (conservation == null)
1372 conservation = new AlignmentAnnotation("Conservation",
1373 "Conservation of total alignment less than "
1374 + getConsPercGaps() + "% gaps",
1375 new Annotation[1], 0f, 11f,
1376 AlignmentAnnotation.BAR_GRAPH);
1377 conservation.hasText = true;
1378 conservation.autoCalculated = true;
1379 alignment.addAnnotation(conservation);
1383 private void initQuality()
1387 if (quality == null)
1389 quality = new AlignmentAnnotation("Quality",
1390 "Alignment Quality based on Blosum62 scores",
1391 new Annotation[1], 0f, 11f,
1392 AlignmentAnnotation.BAR_GRAPH);
1393 quality.hasText = true;
1394 quality.autoCalculated = true;
1395 alignment.addAnnotation(quality);
1399 private void initRNAStructure()
1401 if (alignment.hasRNAStructure() && strucConsensus==null)
1403 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1404 new Annotation[1], 0f, 100f,
1405 AlignmentAnnotation.BAR_GRAPH);
1406 strucConsensus.hasText = true;
1407 strucConsensus.autoCalculated = true;
1411 alignment.addAnnotation(strucConsensus);
1418 * @see jalview.api.AlignViewportI#calcPanelHeight()
1420 public int calcPanelHeight()
1422 // setHeight of panels
1423 AlignmentAnnotation[] aa = getAlignment().getAlignmentAnnotation();
1425 int charHeight = getCharHeight();
1428 BitSet graphgrp = new BitSet();
1429 for (int i = 0; i < aa.length; i++)
1433 System.err.println("Null annotation row: ignoring.");
1440 if (aa[i].graphGroup > -1)
1442 if (graphgrp.get(aa[i].graphGroup))
1448 graphgrp.set(aa[i].graphGroup);
1455 aa[i].height += charHeight;
1463 if (aa[i].graph > 0)
1465 aa[i].height += aa[i].graphHeight;
1468 if (aa[i].height == 0)
1473 height += aa[i].height;
1485 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1486 boolean preserveNewGroupSettings)
1488 boolean updateCalcs = false;
1489 boolean conv = isShowGroupConservation();
1490 boolean cons = isShowGroupConsensus();
1491 boolean showprf = isShowSequenceLogo();
1492 boolean showConsHist = isShowConsensusHistogram();
1493 boolean normLogo = isNormaliseSequenceLogo();
1496 * TODO reorder the annotation rows according to group/sequence ordering on
1499 boolean sortg = true;
1501 // remove old automatic annotation
1502 // add any new annotation
1504 // intersect alignment annotation with alignment groups
1506 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
1507 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
1510 for (int an = 0; an < aan.length; an++)
1512 if (aan[an].autoCalculated && aan[an].groupRef != null)
1514 oldrfs.add(aan[an].groupRef);
1515 alignment.deleteAnnotation(aan[an],false);
1519 if (alignment.getGroups() != null)
1521 for (SequenceGroup sg : alignment.getGroups())
1523 updateCalcs = false;
1524 if (applyGlobalSettings
1525 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
1527 // set defaults for this group's conservation/consensus
1528 sg.setshowSequenceLogo(showprf);
1529 sg.setShowConsensusHistogram(showConsHist);
1530 sg.setNormaliseSequenceLogo(normLogo);
1535 alignment.addAnnotation(sg.getConservationRow(), 0);
1540 alignment.addAnnotation(sg.getConsensus(), 0);
1542 // refresh the annotation rows
1545 sg.recalcConservation();
1553 public Color getSequenceColour(SequenceI seq)
1555 Color sqc=Color.white;
1556 if (sequenceColours != null)
1558 sqc = (Color) sequenceColours.get(seq);
1567 public void setSequenceColour(SequenceI seq, Color col)
1569 if (sequenceColours == null)
1571 sequenceColours = new Hashtable();
1576 sequenceColours.remove(seq);
1580 sequenceColours.put(seq, col);
1585 public void updateSequenceIdColours()
1587 if (sequenceColours == null)
1589 sequenceColours = new Hashtable();
1591 for (SequenceGroup sg : alignment.getGroups())
1593 if (sg.idColour != null)
1595 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
1597 sequenceColours.put(s, sg.idColour);
1604 public void clearSequenceColours()
1606 sequenceColours = null;