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.datamodel.AlignmentAnnotation;
29 import jalview.datamodel.AlignmentI;
30 import jalview.datamodel.AlignmentView;
31 import jalview.datamodel.Annotation;
32 import jalview.datamodel.ColumnSelection;
33 import jalview.datamodel.Sequence;
34 import jalview.datamodel.SequenceCollectionI;
35 import jalview.datamodel.SequenceGroup;
36 import jalview.datamodel.SequenceI;
37 import jalview.schemes.Blosum62ColourScheme;
38 import jalview.schemes.ClustalxColourScheme;
39 import jalview.schemes.ColourSchemeI;
40 import jalview.schemes.PIDColourScheme;
41 import jalview.schemes.ResidueProperties;
42 import jalview.workers.AlignCalcManager;
43 import jalview.workers.ConsensusThread;
44 import jalview.workers.StrucConsensusThread;
46 import java.awt.Color;
47 import java.util.ArrayList;
48 import java.util.BitSet;
49 import java.util.Hashtable;
50 import java.util.List;
52 import java.util.Vector;
55 * base class holding visualization and analysis attributes and common logic for
56 * an active alignment view displayed in the GUI
61 public abstract class AlignmentViewport implements AlignViewportI
64 * alignment displayed in the viewport. Please use get/setter
66 protected AlignmentI alignment;
68 protected String sequenceSetID;
71 * probably unused indicator that view is of a dataset rather than an
74 protected boolean isDataset = false;
76 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
78 protected ColumnSelection colSel = new ColumnSelection();
80 public boolean autoCalculateConsensus = true;
82 protected boolean autoCalculateStrucConsensus = true;
84 protected boolean ignoreGapsInConsensusCalculation = false;
86 protected ColourSchemeI globalColourScheme = null;
89 * gui state - changes to colour scheme propagated to all groups
91 private boolean colourAppliesToAllGroups;
95 * indicating if subsequent colourscheme changes will be propagated
98 public void setColourAppliesToAllGroups(boolean b)
100 colourAppliesToAllGroups = b;
106 * @return flag indicating if colourchanges propagated to all groups
108 public boolean getColourAppliesToAllGroups()
110 return colourAppliesToAllGroups;
113 boolean abovePIDThreshold = false;
118 * @return true if percent identity threshold is applied to shading
120 public boolean getAbovePIDThreshold()
122 return abovePIDThreshold;
130 * indicate if percent identity threshold is applied to shading
132 public void setAbovePIDThreshold(boolean b)
134 abovePIDThreshold = b;
145 public void setThreshold(int thresh)
153 * @return DOCUMENT ME!
155 public int getThreshold()
165 * set the scalar for bleaching colourschemes according to degree of
168 public void setIncrement(int inc)
176 * @return get scalar for bleaching colourschemes by conservation
178 public int getIncrement()
183 boolean conservationColourSelected = false;
188 * @return true if conservation based shading is enabled
190 public boolean getConservationSelected()
192 return conservationColourSelected;
199 * enable conservation based shading
201 public void setConservationSelected(boolean b)
203 conservationColourSelected = b;
207 public void setGlobalColourScheme(ColourSchemeI cs)
209 // TODO: logic refactored from AlignFrame changeColour -
210 // autorecalc stuff should be changed to rely on the worker system
211 // check to see if we should implement a changeColour(cs) method rather than
212 // put th logic in here
213 // - means that caller decides if they want to just modify state and defer
214 // calculation till later or to do all calculations in thread.
216 globalColourScheme = cs;
217 boolean recalc=false;
220 cs.setConservationApplied(recalc = getConservationSelected());
221 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme || cs instanceof Blosum62ColourScheme)
224 cs.setThreshold(threshold, ignoreGapsInConsensusCalculation);
226 cs.setThreshold(0, ignoreGapsInConsensusCalculation);
230 cs.setConsensus(hconsensus);
231 cs.setConservation(hconservation);
233 cs.alignmentChanged(alignment, hiddenRepSequences);
235 if (getColourAppliesToAllGroups())
237 for (SequenceGroup sg : getAlignment().getGroups())
244 sg.cs = cs.applyTo(sg, getHiddenRepSequences());
245 sg.setConsPercGaps(ConsPercGaps);
246 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
247 || cs instanceof Blosum62ColourScheme)
249 sg.cs.setThreshold(threshold, getIgnoreGapsConsensus());
254 sg.cs.setThreshold(0, getIgnoreGapsConsensus());
257 if (getConservationSelected())
259 sg.cs.setConservationApplied(true);
264 sg.cs.setConservation(null);
265 // sg.cs.setThreshold(0, getIgnoreGapsConsensus());
268 sg.recalcConservation();
270 sg.cs.alignmentChanged(sg, hiddenRepSequences);
278 public ColourSchemeI getGlobalColourScheme()
280 return globalColourScheme;
283 protected AlignmentAnnotation consensus;
285 protected AlignmentAnnotation strucConsensus;
287 protected AlignmentAnnotation conservation;
289 protected AlignmentAnnotation quality;
291 protected AlignmentAnnotation[] groupConsensus;
293 protected AlignmentAnnotation[] groupConservation;
296 * results of alignment consensus analysis for visible portion of view
298 protected Hashtable[] hconsensus = null;
301 * results of secondary structure base pair consensus for visible portion of
304 protected Hashtable[] hStrucConsensus = null;
306 protected Conservation hconservation = null;
308 public void setConservation(Conservation cons)
310 hconservation = cons;
313 * percentage gaps allowed in a column before all amino acid properties should
314 * be considered unconserved
316 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
319 public int getConsPercGaps()
325 public void setSequenceConsensusHash(Hashtable[] hconsensus)
327 this.hconsensus = hconsensus;
332 public Hashtable[] getSequenceConsensusHash()
338 public Hashtable[] getRnaStructureConsensusHash()
340 return hStrucConsensus;
344 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
346 this.hStrucConsensus = hStrucConsensus;
351 public AlignmentAnnotation getAlignmentQualityAnnot()
357 public AlignmentAnnotation getAlignmentConservationAnnotation()
363 public AlignmentAnnotation getAlignmentConsensusAnnotation()
369 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
371 return strucConsensus;
374 protected AlignCalcManagerI calculator = new AlignCalcManager();
377 * trigger update of conservation annotation
379 public void updateConservation(final AlignmentViewPanel ap)
381 // see note in mantis : issue number 8585
382 if (alignment.isNucleotide() || conservation == null
383 || !autoCalculateConsensus)
388 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
390 calculator.registerWorker(new jalview.workers.ConservationThread(
396 * trigger update of consensus annotation
398 public void updateConsensus(final AlignmentViewPanel ap)
400 // see note in mantis : issue number 8585
401 if (consensus == null || !autoCalculateConsensus)
405 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
407 calculator.registerWorker(new ConsensusThread(this, ap));
411 // --------START Structure Conservation
412 public void updateStrucConsensus(final AlignmentViewPanel ap)
414 if (autoCalculateStrucConsensus && strucConsensus == null
415 && alignment.isNucleotide() && alignment.hasRNAStructure())
417 // secondary structure has been added - so init the consensus line
421 // see note in mantis : issue number 8585
422 if (strucConsensus == null || !autoCalculateStrucConsensus)
426 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
428 calculator.registerWorker(new StrucConsensusThread(this, ap));
432 public boolean isCalcInProgress()
434 return calculator.isWorking();
438 public boolean isCalculationInProgress(
439 AlignmentAnnotation alignmentAnnotation)
441 if (!alignmentAnnotation.autoCalculated)
443 if (calculator.workingInvolvedWith(alignmentAnnotation))
445 // System.err.println("grey out ("+alignmentAnnotation.label+")");
452 public boolean isClosed()
454 // TODO: check that this isClosed is only true after panel is closed, not
455 // before it is fully constructed.
456 return alignment == null;
460 public AlignCalcManagerI getCalcManager()
466 * should conservation rows be shown for groups
468 protected boolean showGroupConservation = false;
471 * should consensus rows be shown for groups
473 protected boolean showGroupConsensus = false;
476 * should consensus profile be rendered by default
478 protected boolean showSequenceLogo = false;
481 * should consensus profile be rendered normalised to row height
483 protected boolean normaliseSequenceLogo = false;
486 * should consensus histograms be rendered by default
488 protected boolean showConsensusHistogram = true;
491 * @return the showConsensusProfile
494 public boolean isShowSequenceLogo()
496 return showSequenceLogo;
500 * @param showSequenceLogo
503 public void setShowSequenceLogo(boolean showSequenceLogo)
505 if (showSequenceLogo != this.showSequenceLogo)
507 // TODO: decouple settings setting from calculation when refactoring
508 // annotation update method from alignframe to viewport
509 this.showSequenceLogo = showSequenceLogo;
510 calculator.updateAnnotationFor(ConsensusThread.class);
511 calculator.updateAnnotationFor(StrucConsensusThread.class);
513 this.showSequenceLogo = showSequenceLogo;
517 * @param showConsensusHistogram
518 * the showConsensusHistogram to set
520 public void setShowConsensusHistogram(boolean showConsensusHistogram)
522 this.showConsensusHistogram = showConsensusHistogram;
526 * @return the showGroupConservation
528 public boolean isShowGroupConservation()
530 return showGroupConservation;
534 * @param showGroupConservation
535 * the showGroupConservation to set
537 public void setShowGroupConservation(boolean showGroupConservation)
539 this.showGroupConservation = showGroupConservation;
543 * @return the showGroupConsensus
545 public boolean isShowGroupConsensus()
547 return showGroupConsensus;
551 * @param showGroupConsensus
552 * the showGroupConsensus to set
554 public void setShowGroupConsensus(boolean showGroupConsensus)
556 this.showGroupConsensus = showGroupConsensus;
561 * @return flag to indicate if the consensus histogram should be rendered by
565 public boolean isShowConsensusHistogram()
567 return this.showConsensusHistogram;
571 * show non-conserved residues only
573 protected boolean showUnconserved = false;
576 * when set, updateAlignment will always ensure sequences are of equal length
578 private boolean padGaps = false;
581 * when set, alignment should be reordered according to a newly opened tree
583 public boolean sortByTree = false;
585 public boolean getShowUnconserved()
587 return showUnconserved;
590 public void setShowUnconserved(boolean showunconserved)
592 showUnconserved = showunconserved;
596 * @param showNonconserved
597 * the showUnconserved to set
599 public void setShowunconserved(boolean displayNonconserved)
601 this.showUnconserved = displayNonconserved;
607 * @return null or the currently selected sequence region
610 public SequenceGroup getSelectionGroup()
612 return selectionGroup;
616 * Set the selection group for this window.
619 * - group holding references to sequences in this alignment view
623 public void setSelectionGroup(SequenceGroup sg)
628 public void setHiddenColumns(ColumnSelection colsel)
630 this.colSel = colsel;
631 if (colSel.getHiddenColumns() != null)
633 hasHiddenColumns = true;
638 public ColumnSelection getColumnSelection()
643 public void setColumnSelection(ColumnSelection colSel)
645 this.colSel = colSel;
653 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
655 return hiddenRepSequences;
659 public void setHiddenRepSequences(
660 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
662 this.hiddenRepSequences = hiddenRepSequences;
665 protected boolean hasHiddenColumns = false;
667 public void updateHiddenColumns()
669 hasHiddenColumns = colSel.getHiddenColumns() != null;
672 protected boolean hasHiddenRows = false;
674 public boolean hasHiddenRows()
676 return hasHiddenRows;
679 protected SequenceGroup selectionGroup;
681 public void setSequenceSetId(String newid)
683 if (sequenceSetID != null)
686 .println("Warning - overwriting a sequenceSetId for a viewport!");
688 sequenceSetID = new String(newid);
691 public String getSequenceSetId()
693 if (sequenceSetID == null)
695 sequenceSetID = alignment.hashCode() + "";
698 return sequenceSetID;
702 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
705 protected String viewId = null;
707 public String getViewId()
711 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
716 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
718 ignoreGapsInConsensusCalculation = b;
722 if (globalColourScheme != null)
724 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
725 ignoreGapsInConsensusCalculation);
731 private long sgrouphash = -1, colselhash = -1;
734 * checks current SelectionGroup against record of last hash value, and
738 * update the record of last hash value
740 * @return true if SelectionGroup changed since last call (when b is true)
742 public boolean isSelectionGroupChanged(boolean b)
744 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
745 : selectionGroup.hashCode();
746 if (hc != -1 && hc != sgrouphash)
758 * checks current colsel against record of last hash value, and optionally
762 * update the record of last hash value
763 * @return true if colsel changed since last call (when b is true)
765 public boolean isColSelChanged(boolean b)
767 int hc = (colSel == null || colSel.size() == 0) ? -1 : colSel
769 if (hc != -1 && hc != colselhash)
781 public boolean getIgnoreGapsConsensus()
783 return ignoreGapsInConsensusCalculation;
786 // / property change stuff
788 // JBPNote Prolly only need this in the applet version.
789 private final java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
792 protected boolean showConservation = true;
794 protected boolean showQuality = true;
796 protected boolean showConsensus = true;
798 Hashtable sequenceColours;
801 * Property change listener for changes in alignment
806 public void addPropertyChangeListener(
807 java.beans.PropertyChangeListener listener)
809 changeSupport.addPropertyChangeListener(listener);
818 public void removePropertyChangeListener(
819 java.beans.PropertyChangeListener listener)
821 changeSupport.removePropertyChangeListener(listener);
825 * Property change listener for changes in alignment
834 public void firePropertyChange(String prop, Object oldvalue,
837 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
840 // common hide/show column stuff
842 public void hideSelectedColumns()
844 if (colSel.size() < 1)
849 colSel.hideSelectedColumns();
850 setSelectionGroup(null);
852 hasHiddenColumns = true;
855 public void hideColumns(int start, int end)
859 colSel.hideColumns(start);
863 colSel.hideColumns(start, end);
866 hasHiddenColumns = true;
869 public void showColumn(int col)
871 colSel.revealHiddenColumns(col);
872 if (colSel.getHiddenColumns() == null)
874 hasHiddenColumns = false;
878 public void showAllHiddenColumns()
880 colSel.revealAllHiddenColumns();
881 hasHiddenColumns = false;
884 // common hide/show seq stuff
885 public void showAllHiddenSeqs()
887 if (alignment.getHiddenSequences().getSize() > 0)
889 if (selectionGroup == null)
891 selectionGroup = new SequenceGroup();
892 selectionGroup.setEndRes(alignment.getWidth() - 1);
894 Vector tmp = alignment.getHiddenSequences().showAll(
896 for (int t = 0; t < tmp.size(); t++)
898 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
901 hasHiddenRows = false;
902 hiddenRepSequences = null;
904 firePropertyChange("alignment", null, alignment.getSequences());
905 // used to set hasHiddenRows/hiddenRepSequences here, after the property
911 public void showSequence(int index)
913 Vector tmp = alignment.getHiddenSequences().showSequence(index,
917 if (selectionGroup == null)
919 selectionGroup = new SequenceGroup();
920 selectionGroup.setEndRes(alignment.getWidth() - 1);
923 for (int t = 0; t < tmp.size(); t++)
925 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
927 // JBPNote: refactor: only update flag if we modified visiblity (used to
928 // do this regardless)
929 if (alignment.getHiddenSequences().getSize() < 1)
931 hasHiddenRows = false;
933 firePropertyChange("alignment", null, alignment.getSequences());
938 public void hideAllSelectedSeqs()
940 if (selectionGroup == null || selectionGroup.getSize() < 1)
945 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
949 setSelectionGroup(null);
952 public void hideSequence(SequenceI[] seq)
956 for (int i = 0; i < seq.length; i++)
958 alignment.getHiddenSequences().hideSequence(seq[i]);
960 hasHiddenRows = true;
961 firePropertyChange("alignment", null, alignment.getSequences());
965 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
967 int sSize = sg.getSize();
973 if (hiddenRepSequences == null)
975 hiddenRepSequences = new Hashtable();
978 hiddenRepSequences.put(repSequence, sg);
980 // Hide all sequences except the repSequence
981 SequenceI[] seqs = new SequenceI[sSize - 1];
983 for (int i = 0; i < sSize; i++)
985 if (sg.getSequenceAt(i) != repSequence)
987 if (index == sSize - 1)
992 seqs[index++] = sg.getSequenceAt(i);
995 sg.setSeqrep(repSequence); // note: not done in 2.7applet
996 sg.setHidereps(true); // note: not done in 2.7applet
1001 public boolean isHiddenRepSequence(SequenceI seq)
1003 return hiddenRepSequences != null
1004 && hiddenRepSequences.containsKey(seq);
1007 public SequenceGroup getRepresentedSequences(SequenceI seq)
1009 return (SequenceGroup) (hiddenRepSequences == null ? null
1010 : hiddenRepSequences.get(seq));
1013 public int adjustForHiddenSeqs(int alignmentIndex)
1015 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1019 // Selection manipulation
1021 * broadcast selection to any interested parties
1023 public abstract void sendSelection();
1025 public void invertColumnSelection()
1027 colSel.invertColumnSelection(0, alignment.getWidth());
1031 * This method returns an array of new SequenceI objects derived from the
1032 * whole alignment or just the current selection with start and end points
1035 * @note if you need references to the actual SequenceI objects in the
1036 * alignment or currently selected then use getSequenceSelection()
1037 * @return selection as new sequenceI objects
1039 public SequenceI[] getSelectionAsNewSequence()
1041 SequenceI[] sequences;
1042 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1043 // this was the only caller in the applet for this method
1044 // JBPNote: in applet, this method returned references to the alignment
1045 // sequences, and it did not honour the presence/absence of annotation
1046 // attached to the alignment (probably!)
1047 if (selectionGroup == null || selectionGroup.getSize() == 0)
1049 sequences = alignment.getSequencesArray();
1050 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1051 for (int i = 0; i < sequences.length; i++)
1053 sequences[i] = new Sequence(sequences[i], annots); // construct new
1055 // subset of visible
1061 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1068 * get the currently selected sequence objects or all the sequences in the
1071 * @return array of references to sequence objects
1074 public SequenceI[] getSequenceSelection()
1076 SequenceI[] sequences = null;
1077 if (selectionGroup != null)
1079 sequences = selectionGroup.getSequencesInOrder(alignment);
1081 if (sequences == null)
1083 sequences = alignment.getSequencesArray();
1089 * This method returns the visible alignment as text, as seen on the GUI, ie
1090 * if columns are hidden they will not be returned in the result. Use this for
1091 * calculating trees, PCA, redundancy etc on views which contain hidden
1097 public jalview.datamodel.CigarArray getViewAsCigars(
1098 boolean selectedRegionOnly)
1100 return new jalview.datamodel.CigarArray(alignment,
1101 (hasHiddenColumns ? colSel : null),
1102 (selectedRegionOnly ? selectionGroup : null));
1106 * return a compact representation of the current alignment selection to pass
1107 * to an analysis function
1109 * @param selectedOnly
1110 * boolean true to just return the selected view
1111 * @return AlignmentView
1114 public jalview.datamodel.AlignmentView getAlignmentView(
1115 boolean selectedOnly)
1117 return getAlignmentView(selectedOnly, false);
1121 * return a compact representation of the current alignment selection to pass
1122 * to an analysis function
1124 * @param selectedOnly
1125 * boolean true to just return the selected view
1127 * boolean true to annotate the alignment view with groups on the
1128 * alignment (and intersecting with selected region if selectedOnly
1130 * @return AlignmentView
1133 public jalview.datamodel.AlignmentView getAlignmentView(
1134 boolean selectedOnly, boolean markGroups)
1136 return new AlignmentView(alignment, colSel, selectionGroup,
1137 hasHiddenColumns, selectedOnly, markGroups);
1141 * This method returns the visible alignment as text, as seen on the GUI, ie
1142 * if columns are hidden they will not be returned in the result. Use this for
1143 * calculating trees, PCA, redundancy etc on views which contain hidden
1149 public String[] getViewAsString(boolean selectedRegionOnly)
1151 String[] selection = null;
1152 SequenceI[] seqs = null;
1154 int start = 0, end = 0;
1155 if (selectedRegionOnly && selectionGroup != null)
1157 iSize = selectionGroup.getSize();
1158 seqs = selectionGroup.getSequencesInOrder(alignment);
1159 start = selectionGroup.getStartRes();
1160 end = selectionGroup.getEndRes() + 1;
1164 iSize = alignment.getHeight();
1165 seqs = alignment.getSequencesArray();
1166 end = alignment.getWidth();
1169 selection = new String[iSize];
1170 if (hasHiddenColumns)
1172 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1176 for (i = 0; i < iSize; i++)
1178 selection[i] = seqs[i].getSequenceAsString(start, end);
1186 * return visible region boundaries within given column range
1189 * first column (inclusive, from 0)
1191 * last column (exclusive)
1192 * @return int[][] range of {start,end} visible positions
1194 public int[][] getVisibleRegionBoundaries(int min, int max)
1196 Vector regions = new Vector();
1202 if (hasHiddenColumns)
1206 start = colSel.adjustForHiddenColumns(start);
1209 end = colSel.getHiddenBoundaryRight(start);
1220 regions.addElement(new int[]
1223 if (hasHiddenColumns)
1225 start = colSel.adjustForHiddenColumns(end);
1226 start = colSel.getHiddenBoundaryLeft(start) + 1;
1228 } while (end < max);
1230 int[][] startEnd = new int[regions.size()][2];
1232 regions.copyInto(startEnd);
1239 * @return the padGaps
1241 public boolean isPadGaps()
1248 * the padGaps to set
1250 public void setPadGaps(boolean padGaps)
1252 this.padGaps = padGaps;
1256 * apply any post-edit constraints and trigger any calculations needed after
1257 * an edit has been performed on the alignment
1261 public void alignmentChanged(AlignmentViewPanel ap)
1265 alignment.padGaps();
1267 if (autoCalculateConsensus)
1269 updateConsensus(ap);
1271 if (hconsensus != null && autoCalculateConsensus)
1273 updateConservation(ap);
1275 if (autoCalculateStrucConsensus)
1277 updateStrucConsensus(ap);
1280 // Reset endRes of groups if beyond alignment width
1281 int alWidth = alignment.getWidth();
1282 List<SequenceGroup> groups = alignment.getGroups();
1285 for (SequenceGroup sg : groups)
1287 if (sg.getEndRes() > alWidth)
1289 sg.setEndRes(alWidth - 1);
1294 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1296 selectionGroup.setEndRes(alWidth - 1);
1299 resetAllColourSchemes();
1300 calculator.restartWorkers();
1301 // alignment.adjustSequenceAnnotations();
1305 * reset scope and do calculations for all applied colourschemes on alignment
1307 void resetAllColourSchemes()
1309 ColourSchemeI cs = globalColourScheme;
1312 cs.alignmentChanged(alignment, hiddenRepSequences);
1314 cs.setConsensus(hconsensus);
1315 if (cs.conservationApplied())
1317 cs.setConservation(Conservation.calculateConservation("All",
1318 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1319 alignment.getWidth(), false, getConsPercGaps(), false));
1323 for (SequenceGroup sg : alignment.getGroups())
1327 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1329 sg.recalcConservation();
1333 protected void initAutoAnnotation()
1335 // TODO: add menu option action that nulls or creates consensus object
1336 // depending on if the user wants to see the annotation or not in a
1337 // specific alignment
1339 if (hconsensus == null && !isDataset)
1341 if (!alignment.isNucleotide())
1354 private void initConsensus()
1357 consensus = new AlignmentAnnotation("Consensus", "PID",
1358 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1359 consensus.hasText = true;
1360 consensus.autoCalculated = true;
1364 alignment.addAnnotation(consensus);
1368 private void initConservation()
1370 if (showConservation)
1372 if (conservation == null)
1374 conservation = new AlignmentAnnotation("Conservation",
1375 "Conservation of total alignment less than "
1376 + getConsPercGaps() + "% gaps",
1377 new Annotation[1], 0f, 11f,
1378 AlignmentAnnotation.BAR_GRAPH);
1379 conservation.hasText = true;
1380 conservation.autoCalculated = true;
1381 alignment.addAnnotation(conservation);
1385 private void initQuality()
1389 if (quality == null)
1391 quality = new AlignmentAnnotation("Quality",
1392 "Alignment Quality based on Blosum62 scores",
1393 new Annotation[1], 0f, 11f,
1394 AlignmentAnnotation.BAR_GRAPH);
1395 quality.hasText = true;
1396 quality.autoCalculated = true;
1397 alignment.addAnnotation(quality);
1401 private void initRNAStructure()
1403 if (alignment.hasRNAStructure() && strucConsensus==null)
1405 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1406 new Annotation[1], 0f, 100f,
1407 AlignmentAnnotation.BAR_GRAPH);
1408 strucConsensus.hasText = true;
1409 strucConsensus.autoCalculated = true;
1413 alignment.addAnnotation(strucConsensus);
1420 * @see jalview.api.AlignViewportI#calcPanelHeight()
1422 public int calcPanelHeight()
1424 // setHeight of panels
1425 AlignmentAnnotation[] aa = getAlignment().getAlignmentAnnotation();
1427 int charHeight = getCharHeight();
1430 BitSet graphgrp = new BitSet();
1431 for (int i = 0; i < aa.length; i++)
1435 System.err.println("Null annotation row: ignoring.");
1442 if (aa[i].graphGroup > -1)
1444 if (graphgrp.get(aa[i].graphGroup))
1450 graphgrp.set(aa[i].graphGroup);
1457 aa[i].height += charHeight;
1465 if (aa[i].graph > 0)
1467 aa[i].height += aa[i].graphHeight;
1470 if (aa[i].height == 0)
1475 height += aa[i].height;
1487 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1488 boolean preserveNewGroupSettings)
1490 boolean updateCalcs = false;
1491 boolean conv = isShowGroupConservation();
1492 boolean cons = isShowGroupConsensus();
1493 boolean showprf = isShowSequenceLogo();
1494 boolean showConsHist = isShowConsensusHistogram();
1495 boolean normLogo = isNormaliseSequenceLogo();
1498 * TODO reorder the annotation rows according to group/sequence ordering on
1501 boolean sortg = true;
1503 // remove old automatic annotation
1504 // add any new annotation
1506 // intersect alignment annotation with alignment groups
1508 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
1509 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
1512 for (int an = 0; an < aan.length; an++)
1514 if (aan[an].autoCalculated && aan[an].groupRef != null)
1516 oldrfs.add(aan[an].groupRef);
1517 alignment.deleteAnnotation(aan[an],false);
1521 if (alignment.getGroups() != null)
1523 for (SequenceGroup sg : alignment.getGroups())
1525 updateCalcs = false;
1526 if (applyGlobalSettings
1527 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
1529 // set defaults for this group's conservation/consensus
1530 sg.setshowSequenceLogo(showprf);
1531 sg.setShowConsensusHistogram(showConsHist);
1532 sg.setNormaliseSequenceLogo(normLogo);
1537 alignment.addAnnotation(sg.getConservationRow(), 0);
1542 alignment.addAnnotation(sg.getConsensus(), 0);
1544 // refresh the annotation rows
1547 sg.recalcConservation();
1555 public Color getSequenceColour(SequenceI seq)
1557 Color sqc=Color.white;
1558 if (sequenceColours != null)
1560 sqc = (Color) sequenceColours.get(seq);
1569 public void setSequenceColour(SequenceI seq, Color col)
1571 if (sequenceColours == null)
1573 sequenceColours = new Hashtable();
1578 sequenceColours.remove(seq);
1582 sequenceColours.put(seq, col);
1587 public void updateSequenceIdColours()
1589 if (sequenceColours == null)
1591 sequenceColours = new Hashtable();
1593 for (SequenceGroup sg : alignment.getGroups())
1595 if (sg.idColour != null)
1597 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
1599 sequenceColours.put(s, sg.idColour);
1606 public void clearSequenceColours()
1608 sequenceColours = null;