2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.viewmodel;
23 import jalview.analysis.AAFrequency;
24 import jalview.analysis.Conservation;
25 import jalview.api.AlignCalcManagerI;
26 import jalview.api.AlignViewportI;
27 import jalview.api.AlignmentViewPanel;
28 import jalview.api.FeaturesDisplayedI;
29 import jalview.datamodel.AlignmentAnnotation;
30 import jalview.datamodel.AlignmentI;
31 import jalview.datamodel.AlignmentView;
32 import jalview.datamodel.Annotation;
33 import jalview.datamodel.ColumnSelection;
34 import jalview.datamodel.Sequence;
35 import jalview.datamodel.SequenceCollectionI;
36 import jalview.datamodel.SequenceGroup;
37 import jalview.datamodel.SequenceI;
38 import jalview.schemes.Blosum62ColourScheme;
39 import jalview.schemes.ClustalxColourScheme;
40 import jalview.schemes.ColourSchemeI;
41 import jalview.schemes.PIDColourScheme;
42 import jalview.schemes.ResidueProperties;
43 import jalview.viewmodel.seqfeatures.FeaturesDisplayed;
44 import jalview.workers.AlignCalcManager;
45 import jalview.workers.ConsensusThread;
46 import jalview.workers.StrucConsensusThread;
48 import java.awt.Color;
49 import java.util.ArrayList;
50 import java.util.BitSet;
51 import java.util.Hashtable;
52 import java.util.List;
54 import java.util.Vector;
57 * base class holding visualization and analysis attributes and common logic for
58 * an active alignment view displayed in the GUI
63 public abstract class AlignmentViewport implements AlignViewportI
66 * alignment displayed in the viewport. Please use get/setter
68 protected AlignmentI alignment;
70 protected String sequenceSetID;
73 * probably unused indicator that view is of a dataset rather than an
76 protected boolean isDataset = false;
78 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
80 protected ColumnSelection colSel = new ColumnSelection();
82 public boolean autoCalculateConsensus = true;
84 protected boolean autoCalculateStrucConsensus = true;
86 protected boolean ignoreGapsInConsensusCalculation = false;
88 protected ColourSchemeI globalColourScheme = null;
91 * gui state - changes to colour scheme propagated to all groups
93 private boolean colourAppliesToAllGroups;
97 * indicating if subsequent colourscheme changes will be propagated
100 public void setColourAppliesToAllGroups(boolean b)
102 colourAppliesToAllGroups = b;
108 * @return flag indicating if colourchanges propagated to all groups
110 public boolean getColourAppliesToAllGroups()
112 return colourAppliesToAllGroups;
115 boolean abovePIDThreshold = false;
120 * @return true if percent identity threshold is applied to shading
122 public boolean getAbovePIDThreshold()
124 return abovePIDThreshold;
132 * indicate if percent identity threshold is applied to shading
134 public void setAbovePIDThreshold(boolean b)
136 abovePIDThreshold = b;
147 public void setThreshold(int thresh)
155 * @return DOCUMENT ME!
157 public int getThreshold()
167 * set the scalar for bleaching colourschemes according to degree of
170 public void setIncrement(int inc)
178 * @return get scalar for bleaching colourschemes by conservation
180 public int getIncrement()
185 boolean conservationColourSelected = false;
190 * @return true if conservation based shading is enabled
192 public boolean getConservationSelected()
194 return conservationColourSelected;
201 * enable conservation based shading
203 public void setConservationSelected(boolean b)
205 conservationColourSelected = b;
209 public void setGlobalColourScheme(ColourSchemeI cs)
211 // TODO: logic refactored from AlignFrame changeColour -
212 // autorecalc stuff should be changed to rely on the worker system
213 // check to see if we should implement a changeColour(cs) method rather than
214 // put th logic in here
215 // - means that caller decides if they want to just modify state and defer
216 // calculation till later or to do all calculations in thread.
218 globalColourScheme = cs;
219 boolean recalc = false;
222 cs.setConservationApplied(recalc = getConservationSelected());
223 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
224 || cs instanceof Blosum62ColourScheme)
227 cs.setThreshold(threshold, ignoreGapsInConsensusCalculation);
231 cs.setThreshold(0, ignoreGapsInConsensusCalculation);
235 cs.setConsensus(hconsensus);
236 cs.setConservation(hconservation);
238 cs.alignmentChanged(alignment, hiddenRepSequences);
240 if (getColourAppliesToAllGroups())
242 for (SequenceGroup sg : getAlignment().getGroups())
249 sg.cs = cs.applyTo(sg, getHiddenRepSequences());
250 sg.setConsPercGaps(ConsPercGaps);
251 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
252 || cs instanceof Blosum62ColourScheme)
254 sg.cs.setThreshold(threshold, getIgnoreGapsConsensus());
259 sg.cs.setThreshold(0, getIgnoreGapsConsensus());
262 if (getConservationSelected())
264 sg.cs.setConservationApplied(true);
269 sg.cs.setConservation(null);
270 // sg.cs.setThreshold(0, getIgnoreGapsConsensus());
274 sg.recalcConservation();
278 sg.cs.alignmentChanged(sg, hiddenRepSequences);
286 public ColourSchemeI getGlobalColourScheme()
288 return globalColourScheme;
291 protected AlignmentAnnotation consensus;
293 protected AlignmentAnnotation strucConsensus;
295 protected AlignmentAnnotation conservation;
297 protected AlignmentAnnotation quality;
299 protected AlignmentAnnotation[] groupConsensus;
301 protected AlignmentAnnotation[] groupConservation;
304 * results of alignment consensus analysis for visible portion of view
306 protected Hashtable[] hconsensus = null;
309 * results of secondary structure base pair consensus for visible portion of
312 protected Hashtable[] hStrucConsensus = null;
314 protected Conservation hconservation = null;
317 public void setConservation(Conservation cons)
319 hconservation = cons;
323 * percentage gaps allowed in a column before all amino acid properties should
324 * be considered unconserved
326 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
329 public int getConsPercGaps()
335 public void setSequenceConsensusHash(Hashtable[] hconsensus)
337 this.hconsensus = hconsensus;
342 public Hashtable[] getSequenceConsensusHash()
348 public Hashtable[] getRnaStructureConsensusHash()
350 return hStrucConsensus;
354 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
356 this.hStrucConsensus = hStrucConsensus;
361 public AlignmentAnnotation getAlignmentQualityAnnot()
367 public AlignmentAnnotation getAlignmentConservationAnnotation()
373 public AlignmentAnnotation getAlignmentConsensusAnnotation()
379 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
381 return strucConsensus;
384 protected AlignCalcManagerI calculator = new AlignCalcManager();
387 * trigger update of conservation annotation
389 public void updateConservation(final AlignmentViewPanel ap)
391 // see note in mantis : issue number 8585
392 if (alignment.isNucleotide() || conservation == null
393 || !autoCalculateConsensus)
398 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
400 calculator.registerWorker(new jalview.workers.ConservationThread(
406 * trigger update of consensus annotation
408 public void updateConsensus(final AlignmentViewPanel ap)
410 // see note in mantis : issue number 8585
411 if (consensus == null || !autoCalculateConsensus)
415 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
417 calculator.registerWorker(new ConsensusThread(this, ap));
421 // --------START Structure Conservation
422 public void updateStrucConsensus(final AlignmentViewPanel ap)
424 if (autoCalculateStrucConsensus && strucConsensus == null
425 && alignment.isNucleotide() && alignment.hasRNAStructure())
427 // secondary structure has been added - so init the consensus line
431 // see note in mantis : issue number 8585
432 if (strucConsensus == null || !autoCalculateStrucConsensus)
436 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
438 calculator.registerWorker(new StrucConsensusThread(this, ap));
442 public boolean isCalcInProgress()
444 return calculator.isWorking();
448 public boolean isCalculationInProgress(
449 AlignmentAnnotation alignmentAnnotation)
451 if (!alignmentAnnotation.autoCalculated)
453 if (calculator.workingInvolvedWith(alignmentAnnotation))
455 // System.err.println("grey out ("+alignmentAnnotation.label+")");
462 public boolean isClosed()
464 // TODO: check that this isClosed is only true after panel is closed, not
465 // before it is fully constructed.
466 return alignment == null;
470 public AlignCalcManagerI getCalcManager()
476 * should conservation rows be shown for groups
478 protected boolean showGroupConservation = false;
481 * should consensus rows be shown for groups
483 protected boolean showGroupConsensus = false;
486 * should consensus profile be rendered by default
488 protected boolean showSequenceLogo = false;
491 * should consensus profile be rendered normalised to row height
493 protected boolean normaliseSequenceLogo = false;
496 * should consensus histograms be rendered by default
498 protected boolean showConsensusHistogram = true;
501 * @return the showConsensusProfile
504 public boolean isShowSequenceLogo()
506 return showSequenceLogo;
510 * @param showSequenceLogo
513 public void setShowSequenceLogo(boolean showSequenceLogo)
515 if (showSequenceLogo != this.showSequenceLogo)
517 // TODO: decouple settings setting from calculation when refactoring
518 // annotation update method from alignframe to viewport
519 this.showSequenceLogo = showSequenceLogo;
520 calculator.updateAnnotationFor(ConsensusThread.class);
521 calculator.updateAnnotationFor(StrucConsensusThread.class);
523 this.showSequenceLogo = showSequenceLogo;
527 * @param showConsensusHistogram
528 * the showConsensusHistogram to set
530 public void setShowConsensusHistogram(boolean showConsensusHistogram)
532 this.showConsensusHistogram = showConsensusHistogram;
536 * @return the showGroupConservation
538 public boolean isShowGroupConservation()
540 return showGroupConservation;
544 * @param showGroupConservation
545 * the showGroupConservation to set
547 public void setShowGroupConservation(boolean showGroupConservation)
549 this.showGroupConservation = showGroupConservation;
553 * @return the showGroupConsensus
555 public boolean isShowGroupConsensus()
557 return showGroupConsensus;
561 * @param showGroupConsensus
562 * the showGroupConsensus to set
564 public void setShowGroupConsensus(boolean showGroupConsensus)
566 this.showGroupConsensus = showGroupConsensus;
571 * @return flag to indicate if the consensus histogram should be rendered by
575 public boolean isShowConsensusHistogram()
577 return this.showConsensusHistogram;
581 * show non-conserved residues only
583 protected boolean showUnconserved = false;
586 * when set, updateAlignment will always ensure sequences are of equal length
588 private boolean padGaps = false;
591 * when set, alignment should be reordered according to a newly opened tree
593 public boolean sortByTree = false;
595 public boolean getShowUnconserved()
597 return showUnconserved;
600 public void setShowUnconserved(boolean showunconserved)
602 showUnconserved = showunconserved;
606 * @param showNonconserved
607 * the showUnconserved to set
609 public void setShowunconserved(boolean displayNonconserved)
611 this.showUnconserved = displayNonconserved;
617 * @return null or the currently selected sequence region
620 public SequenceGroup getSelectionGroup()
622 return selectionGroup;
626 * Set the selection group for this window.
629 * - group holding references to sequences in this alignment view
633 public void setSelectionGroup(SequenceGroup sg)
638 public void setHiddenColumns(ColumnSelection colsel)
640 this.colSel = colsel;
641 if (colSel.getHiddenColumns() != null)
643 hasHiddenColumns = true;
648 public ColumnSelection getColumnSelection()
653 public void setColumnSelection(ColumnSelection colSel)
655 this.colSel = colSel;
663 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
665 return hiddenRepSequences;
669 public void setHiddenRepSequences(
670 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
672 this.hiddenRepSequences = hiddenRepSequences;
675 protected boolean hasHiddenColumns = false;
677 public void updateHiddenColumns()
679 hasHiddenColumns = colSel.getHiddenColumns() != null;
682 protected boolean hasHiddenRows = false;
684 public boolean hasHiddenRows()
686 return hasHiddenRows;
689 protected SequenceGroup selectionGroup;
691 public void setSequenceSetId(String newid)
693 if (sequenceSetID != null)
696 .println("Warning - overwriting a sequenceSetId for a viewport!");
698 sequenceSetID = new String(newid);
701 public String getSequenceSetId()
703 if (sequenceSetID == null)
705 sequenceSetID = alignment.hashCode() + "";
708 return sequenceSetID;
712 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
715 protected String viewId = null;
717 public String getViewId()
721 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
726 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
728 ignoreGapsInConsensusCalculation = b;
732 if (globalColourScheme != null)
734 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
735 ignoreGapsInConsensusCalculation);
741 private long sgrouphash = -1, colselhash = -1;
744 * checks current SelectionGroup against record of last hash value, and
748 * update the record of last hash value
750 * @return true if SelectionGroup changed since last call (when b is true)
752 public boolean isSelectionGroupChanged(boolean b)
754 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
755 : selectionGroup.hashCode();
756 if (hc != -1 && hc != sgrouphash)
768 * checks current colsel against record of last hash value, and optionally
772 * update the record of last hash value
773 * @return true if colsel changed since last call (when b is true)
775 public boolean isColSelChanged(boolean b)
777 int hc = (colSel == null || colSel.size() == 0) ? -1 : colSel
779 if (hc != -1 && hc != colselhash)
791 public boolean getIgnoreGapsConsensus()
793 return ignoreGapsInConsensusCalculation;
796 // / property change stuff
798 // JBPNote Prolly only need this in the applet version.
799 private final java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
802 protected boolean showConservation = true;
804 protected boolean showQuality = true;
806 protected boolean showConsensus = true;
808 Hashtable sequenceColours;
811 * Property change listener for changes in alignment
816 public void addPropertyChangeListener(
817 java.beans.PropertyChangeListener listener)
819 changeSupport.addPropertyChangeListener(listener);
828 public void removePropertyChangeListener(
829 java.beans.PropertyChangeListener listener)
831 changeSupport.removePropertyChangeListener(listener);
835 * Property change listener for changes in alignment
844 public void firePropertyChange(String prop, Object oldvalue,
847 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
850 // common hide/show column stuff
852 public void hideSelectedColumns()
854 if (colSel.size() < 1)
859 colSel.hideSelectedColumns();
860 setSelectionGroup(null);
862 hasHiddenColumns = true;
865 public void hideColumns(int start, int end)
869 colSel.hideColumns(start);
873 colSel.hideColumns(start, end);
876 hasHiddenColumns = true;
879 public void showColumn(int col)
881 colSel.revealHiddenColumns(col);
882 if (colSel.getHiddenColumns() == null)
884 hasHiddenColumns = false;
888 public void showAllHiddenColumns()
890 colSel.revealAllHiddenColumns();
891 hasHiddenColumns = false;
894 // common hide/show seq stuff
895 public void showAllHiddenSeqs()
897 if (alignment.getHiddenSequences().getSize() > 0)
899 if (selectionGroup == null)
901 selectionGroup = new SequenceGroup();
902 selectionGroup.setEndRes(alignment.getWidth() - 1);
904 Vector tmp = alignment.getHiddenSequences().showAll(
906 for (int t = 0; t < tmp.size(); t++)
908 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
911 hasHiddenRows = false;
912 hiddenRepSequences = null;
914 firePropertyChange("alignment", null, alignment.getSequences());
915 // used to set hasHiddenRows/hiddenRepSequences here, after the property
921 public void showSequence(int index)
923 Vector tmp = alignment.getHiddenSequences().showSequence(index,
927 if (selectionGroup == null)
929 selectionGroup = new SequenceGroup();
930 selectionGroup.setEndRes(alignment.getWidth() - 1);
933 for (int t = 0; t < tmp.size(); t++)
935 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
937 // JBPNote: refactor: only update flag if we modified visiblity (used to
938 // do this regardless)
939 if (alignment.getHiddenSequences().getSize() < 1)
941 hasHiddenRows = false;
943 firePropertyChange("alignment", null, alignment.getSequences());
948 public void hideAllSelectedSeqs()
950 if (selectionGroup == null || selectionGroup.getSize() < 1)
955 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
959 setSelectionGroup(null);
962 public void hideSequence(SequenceI[] seq)
966 for (int i = 0; i < seq.length; i++)
968 alignment.getHiddenSequences().hideSequence(seq[i]);
970 hasHiddenRows = true;
971 firePropertyChange("alignment", null, alignment.getSequences());
975 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
977 int sSize = sg.getSize();
983 if (hiddenRepSequences == null)
985 hiddenRepSequences = new Hashtable();
988 hiddenRepSequences.put(repSequence, sg);
990 // Hide all sequences except the repSequence
991 SequenceI[] seqs = new SequenceI[sSize - 1];
993 for (int i = 0; i < sSize; i++)
995 if (sg.getSequenceAt(i) != repSequence)
997 if (index == sSize - 1)
1002 seqs[index++] = sg.getSequenceAt(i);
1005 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1006 sg.setHidereps(true); // note: not done in 2.7applet
1011 public boolean isHiddenRepSequence(SequenceI seq)
1013 return hiddenRepSequences != null
1014 && hiddenRepSequences.containsKey(seq);
1017 public SequenceGroup getRepresentedSequences(SequenceI seq)
1019 return (SequenceGroup) (hiddenRepSequences == null ? null
1020 : hiddenRepSequences.get(seq));
1023 public int adjustForHiddenSeqs(int alignmentIndex)
1025 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1029 // Selection manipulation
1031 * broadcast selection to any interested parties
1033 public abstract void sendSelection();
1035 public void invertColumnSelection()
1037 colSel.invertColumnSelection(0, alignment.getWidth());
1041 * This method returns an array of new SequenceI objects derived from the
1042 * whole alignment or just the current selection with start and end points
1045 * @note if you need references to the actual SequenceI objects in the
1046 * alignment or currently selected then use getSequenceSelection()
1047 * @return selection as new sequenceI objects
1049 public SequenceI[] getSelectionAsNewSequence()
1051 SequenceI[] sequences;
1052 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1053 // this was the only caller in the applet for this method
1054 // JBPNote: in applet, this method returned references to the alignment
1055 // sequences, and it did not honour the presence/absence of annotation
1056 // attached to the alignment (probably!)
1057 if (selectionGroup == null || selectionGroup.getSize() == 0)
1059 sequences = alignment.getSequencesArray();
1060 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1061 for (int i = 0; i < sequences.length; i++)
1063 sequences[i] = new Sequence(sequences[i], annots); // construct new
1065 // subset of visible
1071 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1078 * get the currently selected sequence objects or all the sequences in the
1081 * @return array of references to sequence objects
1084 public SequenceI[] getSequenceSelection()
1086 SequenceI[] sequences = null;
1087 if (selectionGroup != null)
1089 sequences = selectionGroup.getSequencesInOrder(alignment);
1091 if (sequences == null)
1093 sequences = alignment.getSequencesArray();
1099 * This method returns the visible alignment as text, as seen on the GUI, ie
1100 * if columns are hidden they will not be returned in the result. Use this for
1101 * calculating trees, PCA, redundancy etc on views which contain hidden
1107 public jalview.datamodel.CigarArray getViewAsCigars(
1108 boolean selectedRegionOnly)
1110 return new jalview.datamodel.CigarArray(alignment,
1111 (hasHiddenColumns ? colSel : null),
1112 (selectedRegionOnly ? selectionGroup : null));
1116 * return a compact representation of the current alignment selection to pass
1117 * to an analysis function
1119 * @param selectedOnly
1120 * boolean true to just return the selected view
1121 * @return AlignmentView
1124 public jalview.datamodel.AlignmentView getAlignmentView(
1125 boolean selectedOnly)
1127 return getAlignmentView(selectedOnly, false);
1131 * return a compact representation of the current alignment selection to pass
1132 * to an analysis function
1134 * @param selectedOnly
1135 * boolean true to just return the selected view
1137 * boolean true to annotate the alignment view with groups on the
1138 * alignment (and intersecting with selected region if selectedOnly
1140 * @return AlignmentView
1143 public jalview.datamodel.AlignmentView getAlignmentView(
1144 boolean selectedOnly, boolean markGroups)
1146 return new AlignmentView(alignment, colSel, selectionGroup,
1147 hasHiddenColumns, selectedOnly, markGroups);
1151 * This method returns the visible alignment as text, as seen on the GUI, ie
1152 * if columns are hidden they will not be returned in the result. Use this for
1153 * calculating trees, PCA, redundancy etc on views which contain hidden
1159 public String[] getViewAsString(boolean selectedRegionOnly)
1161 String[] selection = null;
1162 SequenceI[] seqs = null;
1164 int start = 0, end = 0;
1165 if (selectedRegionOnly && selectionGroup != null)
1167 iSize = selectionGroup.getSize();
1168 seqs = selectionGroup.getSequencesInOrder(alignment);
1169 start = selectionGroup.getStartRes();
1170 end = selectionGroup.getEndRes() + 1;
1174 iSize = alignment.getHeight();
1175 seqs = alignment.getSequencesArray();
1176 end = alignment.getWidth();
1179 selection = new String[iSize];
1180 if (hasHiddenColumns)
1182 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1186 for (i = 0; i < iSize; i++)
1188 selection[i] = seqs[i].getSequenceAsString(start, end);
1196 * return visible region boundaries within given column range
1199 * first column (inclusive, from 0)
1201 * last column (exclusive)
1202 * @return int[][] range of {start,end} visible positions
1204 public int[][] getVisibleRegionBoundaries(int min, int max)
1206 Vector regions = new Vector();
1212 if (hasHiddenColumns)
1216 start = colSel.adjustForHiddenColumns(start);
1219 end = colSel.getHiddenBoundaryRight(start);
1230 regions.addElement(new int[]
1233 if (hasHiddenColumns)
1235 start = colSel.adjustForHiddenColumns(end);
1236 start = colSel.getHiddenBoundaryLeft(start) + 1;
1238 } while (end < max);
1240 int[][] startEnd = new int[regions.size()][2];
1242 regions.copyInto(startEnd);
1249 * @return the padGaps
1251 public boolean isPadGaps()
1258 * the padGaps to set
1260 public void setPadGaps(boolean padGaps)
1262 this.padGaps = padGaps;
1266 * apply any post-edit constraints and trigger any calculations needed after
1267 * an edit has been performed on the alignment
1271 public void alignmentChanged(AlignmentViewPanel ap)
1275 alignment.padGaps();
1277 if (autoCalculateConsensus)
1279 updateConsensus(ap);
1281 if (hconsensus != null && autoCalculateConsensus)
1283 updateConservation(ap);
1285 if (autoCalculateStrucConsensus)
1287 updateStrucConsensus(ap);
1290 // Reset endRes of groups if beyond alignment width
1291 int alWidth = alignment.getWidth();
1292 List<SequenceGroup> groups = alignment.getGroups();
1295 for (SequenceGroup sg : groups)
1297 if (sg.getEndRes() > alWidth)
1299 sg.setEndRes(alWidth - 1);
1304 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1306 selectionGroup.setEndRes(alWidth - 1);
1309 resetAllColourSchemes();
1310 calculator.restartWorkers();
1311 // alignment.adjustSequenceAnnotations();
1315 * reset scope and do calculations for all applied colourschemes on alignment
1317 void resetAllColourSchemes()
1319 ColourSchemeI cs = globalColourScheme;
1322 cs.alignmentChanged(alignment, hiddenRepSequences);
1324 cs.setConsensus(hconsensus);
1325 if (cs.conservationApplied())
1327 cs.setConservation(Conservation.calculateConservation("All",
1328 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1329 alignment.getWidth(), false, getConsPercGaps(), false));
1333 for (SequenceGroup sg : alignment.getGroups())
1337 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1339 sg.recalcConservation();
1343 protected void initAutoAnnotation()
1345 // TODO: add menu option action that nulls or creates consensus object
1346 // depending on if the user wants to see the annotation or not in a
1347 // specific alignment
1349 if (hconsensus == null && !isDataset)
1351 if (!alignment.isNucleotide())
1364 private void initConsensus()
1367 consensus = new AlignmentAnnotation("Consensus", "PID",
1368 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1369 consensus.hasText = true;
1370 consensus.autoCalculated = true;
1374 alignment.addAnnotation(consensus);
1378 private void initConservation()
1380 if (showConservation)
1382 if (conservation == null)
1384 conservation = new AlignmentAnnotation("Conservation",
1385 "Conservation of total alignment less than "
1386 + getConsPercGaps() + "% gaps", new Annotation[1],
1387 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1388 conservation.hasText = true;
1389 conservation.autoCalculated = true;
1390 alignment.addAnnotation(conservation);
1395 private void initQuality()
1399 if (quality == null)
1401 quality = new AlignmentAnnotation("Quality",
1402 "Alignment Quality based on Blosum62 scores",
1403 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1404 quality.hasText = true;
1405 quality.autoCalculated = true;
1406 alignment.addAnnotation(quality);
1411 private void initRNAStructure()
1413 if (alignment.hasRNAStructure() && strucConsensus == null)
1415 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1416 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1417 strucConsensus.hasText = true;
1418 strucConsensus.autoCalculated = true;
1422 alignment.addAnnotation(strucConsensus);
1430 * @see jalview.api.AlignViewportI#calcPanelHeight()
1432 public int calcPanelHeight()
1434 // setHeight of panels
1435 AlignmentAnnotation[] aa = getAlignment().getAlignmentAnnotation();
1437 int charHeight = getCharHeight();
1440 BitSet graphgrp = new BitSet();
1441 for (int i = 0; i < aa.length; i++)
1445 System.err.println("Null annotation row: ignoring.");
1452 if (aa[i].graphGroup > -1)
1454 if (graphgrp.get(aa[i].graphGroup))
1460 graphgrp.set(aa[i].graphGroup);
1467 aa[i].height += charHeight;
1475 if (aa[i].graph > 0)
1477 aa[i].height += aa[i].graphHeight;
1480 if (aa[i].height == 0)
1485 height += aa[i].height;
1497 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1498 boolean preserveNewGroupSettings)
1500 boolean updateCalcs = false;
1501 boolean conv = isShowGroupConservation();
1502 boolean cons = isShowGroupConsensus();
1503 boolean showprf = isShowSequenceLogo();
1504 boolean showConsHist = isShowConsensusHistogram();
1505 boolean normLogo = isNormaliseSequenceLogo();
1508 * TODO reorder the annotation rows according to group/sequence ordering on
1511 boolean sortg = true;
1513 // remove old automatic annotation
1514 // add any new annotation
1516 // intersect alignment annotation with alignment groups
1518 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
1519 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
1522 for (int an = 0; an < aan.length; an++)
1524 if (aan[an].autoCalculated && aan[an].groupRef != null)
1526 oldrfs.add(aan[an].groupRef);
1527 alignment.deleteAnnotation(aan[an], false);
1531 if (alignment.getGroups() != null)
1533 for (SequenceGroup sg : alignment.getGroups())
1535 updateCalcs = false;
1536 if (applyGlobalSettings
1537 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
1539 // set defaults for this group's conservation/consensus
1540 sg.setshowSequenceLogo(showprf);
1541 sg.setShowConsensusHistogram(showConsHist);
1542 sg.setNormaliseSequenceLogo(normLogo);
1547 alignment.addAnnotation(sg.getConservationRow(), 0);
1552 alignment.addAnnotation(sg.getConsensus(), 0);
1554 // refresh the annotation rows
1557 sg.recalcConservation();
1565 public Color getSequenceColour(SequenceI seq)
1567 Color sqc = Color.white;
1568 if (sequenceColours != null)
1570 sqc = (Color) sequenceColours.get(seq);
1580 public void setSequenceColour(SequenceI seq, Color col)
1582 if (sequenceColours == null)
1584 sequenceColours = new Hashtable();
1589 sequenceColours.remove(seq);
1593 sequenceColours.put(seq, col);
1598 public void updateSequenceIdColours()
1600 if (sequenceColours == null)
1602 sequenceColours = new Hashtable();
1604 for (SequenceGroup sg : alignment.getGroups())
1606 if (sg.idColour != null)
1608 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
1610 sequenceColours.put(s, sg.idColour);
1617 public void clearSequenceColours()
1619 sequenceColours = null;
1622 FeaturesDisplayedI featuresDisplayed = null;
1625 public FeaturesDisplayedI getFeaturesDisplayed()
1627 return featuresDisplayed;
1630 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
1632 featuresDisplayed = featuresDisplayedI;
1635 public boolean areFeaturesDisplayed()
1637 return featuresDisplayed != null && featuresDisplayed.getRegisterdFeaturesCount()>0;