2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
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/>.
18 package jalview.viewmodel;
20 import jalview.analysis.AAFrequency;
21 import jalview.analysis.Conservation;
22 import jalview.api.AlignCalcManagerI;
23 import jalview.api.AlignViewportI;
24 import jalview.api.AlignmentViewPanel;
25 import jalview.datamodel.AlignmentAnnotation;
26 import jalview.datamodel.AlignmentI;
27 import jalview.datamodel.AlignmentView;
28 import jalview.datamodel.Annotation;
29 import jalview.datamodel.ColumnSelection;
30 import jalview.datamodel.Sequence;
31 import jalview.datamodel.SequenceCollectionI;
32 import jalview.datamodel.SequenceGroup;
33 import jalview.datamodel.SequenceI;
34 import jalview.schemes.Blosum62ColourScheme;
35 import jalview.schemes.ClustalxColourScheme;
36 import jalview.schemes.ColourSchemeI;
37 import jalview.schemes.PIDColourScheme;
38 import jalview.schemes.ResidueProperties;
39 import jalview.workers.AlignCalcManager;
40 import jalview.workers.ConsensusThread;
41 import jalview.workers.StrucConsensusThread;
43 import java.awt.Color;
44 import java.util.ArrayList;
45 import java.util.BitSet;
46 import java.util.Hashtable;
47 import java.util.List;
49 import java.util.Vector;
52 * base class holding visualization and analysis attributes and common logic for
53 * an active alignment view displayed in the GUI
58 public abstract class AlignmentViewport implements AlignViewportI
61 * alignment displayed in the viewport. Please use get/setter
63 protected AlignmentI alignment;
65 protected String sequenceSetID;
68 * probably unused indicator that view is of a dataset rather than an
71 protected boolean isDataset = false;
73 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
75 protected ColumnSelection colSel = new ColumnSelection();
77 public boolean autoCalculateConsensus = true;
79 protected boolean autoCalculateStrucConsensus = true;
81 protected boolean ignoreGapsInConsensusCalculation = false;
83 protected ColourSchemeI globalColourScheme = null;
86 * gui state - changes to colour scheme propagated to all groups
88 private boolean colourAppliesToAllGroups;
92 * indicating if subsequent colourscheme changes will be propagated
95 public void setColourAppliesToAllGroups(boolean b)
97 colourAppliesToAllGroups = b;
103 * @return flag indicating if colourchanges propagated to all groups
105 public boolean getColourAppliesToAllGroups()
107 return colourAppliesToAllGroups;
110 boolean abovePIDThreshold = false;
115 * @return true if percent identity threshold is applied to shading
117 public boolean getAbovePIDThreshold()
119 return abovePIDThreshold;
127 * indicate if percent identity threshold is applied to shading
129 public void setAbovePIDThreshold(boolean b)
131 abovePIDThreshold = b;
142 public void setThreshold(int thresh)
150 * @return DOCUMENT ME!
152 public int getThreshold()
162 * set the scalar for bleaching colourschemes according to degree of
165 public void setIncrement(int inc)
173 * @return get scalar for bleaching colourschemes by conservation
175 public int getIncrement()
180 boolean conservationColourSelected = false;
185 * @return true if conservation based shading is enabled
187 public boolean getConservationSelected()
189 return conservationColourSelected;
196 * enable conservation based shading
198 public void setConservationSelected(boolean b)
200 conservationColourSelected = b;
204 public void setGlobalColourScheme(ColourSchemeI cs)
206 // TODO: logic refactored from AlignFrame changeColour -
207 // autorecalc stuff should be changed to rely on the worker system
208 // check to see if we should implement a changeColour(cs) method rather than
209 // put th logic in here
210 // - means that caller decides if they want to just modify state and defer
211 // calculation till later or to do all calculations in thread.
213 globalColourScheme = cs;
214 if (getColourAppliesToAllGroups())
216 for (SequenceGroup sg : getAlignment().getGroups())
223 if (cs instanceof ClustalxColourScheme)
225 sg.cs = new ClustalxColourScheme(sg, getHiddenRepSequences());
231 sg.cs = cs.getClass().newInstance();
232 } catch (Exception ex)
234 ex.printStackTrace();
239 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
240 || cs instanceof Blosum62ColourScheme)
242 sg.cs.setThreshold(threshold, getIgnoreGapsConsensus());
243 sg.cs.setConsensus(AAFrequency.calculate(
244 sg.getSequences(getHiddenRepSequences()), 0,
249 sg.cs.setThreshold(0, getIgnoreGapsConsensus());
252 if (getConservationSelected())
254 Conservation c = new Conservation("Group",
255 ResidueProperties.propHash, 3,
256 sg.getSequences(getHiddenRepSequences()), 0,
257 getAlignment().getWidth() - 1);
259 c.verdict(false, getConsPercGaps());
260 sg.cs.setConservation(c);
264 sg.cs.setConservation(null);
265 sg.cs.setThreshold(0, getIgnoreGapsConsensus());
274 public ColourSchemeI getGlobalColourScheme()
276 return globalColourScheme;
279 protected AlignmentAnnotation consensus;
281 protected AlignmentAnnotation strucConsensus;
283 protected AlignmentAnnotation conservation;
285 protected AlignmentAnnotation quality;
287 protected AlignmentAnnotation[] groupConsensus;
289 protected AlignmentAnnotation[] groupConservation;
292 * results of alignment consensus analysis for visible portion of view
294 protected Hashtable[] hconsensus = null;
297 * results of secondary structure base pair consensus for visible portion of
300 protected Hashtable[] hStrucConsensus = null;
303 * percentage gaps allowed in a column before all amino acid properties should
304 * be considered unconserved
306 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
309 public int getConsPercGaps()
315 public void setSequenceConsensusHash(Hashtable[] hconsensus)
317 this.hconsensus = hconsensus;
322 public Hashtable[] getSequenceConsensusHash()
328 public Hashtable[] getRnaStructureConsensusHash()
330 return hStrucConsensus;
334 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
336 this.hStrucConsensus = hStrucConsensus;
341 public AlignmentAnnotation getAlignmentQualityAnnot()
347 public AlignmentAnnotation getAlignmentConservationAnnotation()
353 public AlignmentAnnotation getAlignmentConsensusAnnotation()
359 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
361 return strucConsensus;
364 protected AlignCalcManagerI calculator = new AlignCalcManager();
367 * trigger update of conservation annotation
369 public void updateConservation(final AlignmentViewPanel ap)
371 // see note in mantis : issue number 8585
372 if (alignment.isNucleotide() || conservation == null
373 || !autoCalculateConsensus)
378 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
380 calculator.registerWorker(new jalview.workers.ConservationThread(
386 * trigger update of consensus annotation
388 public void updateConsensus(final AlignmentViewPanel ap)
390 // see note in mantis : issue number 8585
391 if (consensus == null || !autoCalculateConsensus)
395 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
397 calculator.registerWorker(new ConsensusThread(this, ap));
401 // --------START Structure Conservation
402 public void updateStrucConsensus(final AlignmentViewPanel ap)
404 if (autoCalculateStrucConsensus && strucConsensus == null
405 && alignment.isNucleotide() && alignment.hasRNAStructure())
407 // secondary structure has been added - so init the consensus line
411 // see note in mantis : issue number 8585
412 if (strucConsensus == null || !autoCalculateStrucConsensus)
416 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
418 calculator.registerWorker(new StrucConsensusThread(this, ap));
422 public boolean isCalcInProgress()
424 return calculator.isWorking();
428 public boolean isCalculationInProgress(
429 AlignmentAnnotation alignmentAnnotation)
431 if (!alignmentAnnotation.autoCalculated)
433 if (calculator.workingInvolvedWith(alignmentAnnotation))
435 // System.err.println("grey out ("+alignmentAnnotation.label+")");
442 public boolean isClosed()
444 // TODO: check that this isClosed is only true after panel is closed, not
445 // before it is fully constructed.
446 return alignment == null;
450 public AlignCalcManagerI getCalcManager()
456 * should conservation rows be shown for groups
458 protected boolean showGroupConservation = false;
461 * should consensus rows be shown for groups
463 protected boolean showGroupConsensus = false;
466 * should consensus profile be rendered by default
468 protected boolean showSequenceLogo = false;
471 * should consensus profile be rendered normalised to row height
473 protected boolean normaliseSequenceLogo = false;
476 * should consensus histograms be rendered by default
478 protected boolean showConsensusHistogram = true;
481 * @return the showConsensusProfile
484 public boolean isShowSequenceLogo()
486 return showSequenceLogo;
490 * @param showSequenceLogo
493 public void setShowSequenceLogo(boolean showSequenceLogo)
495 if (showSequenceLogo != this.showSequenceLogo)
497 // TODO: decouple settings setting from calculation when refactoring
498 // annotation update method from alignframe to viewport
499 this.showSequenceLogo = showSequenceLogo;
500 calculator.updateAnnotationFor(ConsensusThread.class);
501 calculator.updateAnnotationFor(StrucConsensusThread.class);
503 this.showSequenceLogo = showSequenceLogo;
507 * @param showConsensusHistogram
508 * the showConsensusHistogram to set
510 public void setShowConsensusHistogram(boolean showConsensusHistogram)
512 this.showConsensusHistogram = showConsensusHistogram;
516 * @return the showGroupConservation
518 public boolean isShowGroupConservation()
520 return showGroupConservation;
524 * @param showGroupConservation
525 * the showGroupConservation to set
527 public void setShowGroupConservation(boolean showGroupConservation)
529 this.showGroupConservation = showGroupConservation;
533 * @return the showGroupConsensus
535 public boolean isShowGroupConsensus()
537 return showGroupConsensus;
541 * @param showGroupConsensus
542 * the showGroupConsensus to set
544 public void setShowGroupConsensus(boolean showGroupConsensus)
546 this.showGroupConsensus = showGroupConsensus;
551 * @return flag to indicate if the consensus histogram should be rendered by
555 public boolean isShowConsensusHistogram()
557 return this.showConsensusHistogram;
561 * show non-conserved residues only
563 protected boolean showUnconserved = false;
566 * when set, updateAlignment will always ensure sequences are of equal length
568 private boolean padGaps = false;
571 * when set, alignment should be reordered according to a newly opened tree
573 public boolean sortByTree = false;
575 public boolean getShowUnconserved()
577 return showUnconserved;
580 public void setShowUnconserved(boolean showunconserved)
582 showUnconserved = showunconserved;
586 * @param showNonconserved
587 * the showUnconserved to set
589 public void setShowunconserved(boolean displayNonconserved)
591 this.showUnconserved = displayNonconserved;
597 * @return null or the currently selected sequence region
600 public SequenceGroup getSelectionGroup()
602 return selectionGroup;
606 * Set the selection group for this window.
609 * - group holding references to sequences in this alignment view
613 public void setSelectionGroup(SequenceGroup sg)
618 public void setHiddenColumns(ColumnSelection colsel)
620 this.colSel = colsel;
621 if (colSel.getHiddenColumns() != null)
623 hasHiddenColumns = true;
628 public ColumnSelection getColumnSelection()
633 public void setColumnSelection(ColumnSelection colSel)
635 this.colSel = colSel;
643 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
645 return hiddenRepSequences;
649 public void setHiddenRepSequences(
650 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
652 this.hiddenRepSequences = hiddenRepSequences;
655 protected boolean hasHiddenColumns = false;
657 public void updateHiddenColumns()
659 hasHiddenColumns = colSel.getHiddenColumns() != null;
662 protected boolean hasHiddenRows = false;
664 public boolean hasHiddenRows()
666 return hasHiddenRows;
669 protected SequenceGroup selectionGroup;
671 public void setSequenceSetId(String newid)
673 if (sequenceSetID != null)
676 .println("Warning - overwriting a sequenceSetId for a viewport!");
678 sequenceSetID = new String(newid);
681 public String getSequenceSetId()
683 if (sequenceSetID == null)
685 sequenceSetID = alignment.hashCode() + "";
688 return sequenceSetID;
692 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
695 protected String viewId = null;
697 public String getViewId()
701 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
706 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
708 ignoreGapsInConsensusCalculation = b;
712 if (globalColourScheme != null)
714 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
715 ignoreGapsInConsensusCalculation);
721 private long sgrouphash = -1, colselhash = -1;
724 * checks current SelectionGroup against record of last hash value, and
728 * update the record of last hash value
730 * @return true if SelectionGroup changed since last call (when b is true)
732 public boolean isSelectionGroupChanged(boolean b)
734 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
735 : selectionGroup.hashCode();
736 if (hc != -1 && hc != sgrouphash)
748 * checks current colsel against record of last hash value, and optionally
752 * update the record of last hash value
753 * @return true if colsel changed since last call (when b is true)
755 public boolean isColSelChanged(boolean b)
757 int hc = (colSel == null || colSel.size() == 0) ? -1 : colSel
759 if (hc != -1 && hc != colselhash)
771 public boolean getIgnoreGapsConsensus()
773 return ignoreGapsInConsensusCalculation;
776 // / property change stuff
778 // JBPNote Prolly only need this in the applet version.
779 private final java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
782 protected boolean showConservation = true;
784 protected boolean showQuality = true;
786 protected boolean showConsensus = true;
788 Hashtable sequenceColours;
791 * Property change listener for changes in alignment
796 public void addPropertyChangeListener(
797 java.beans.PropertyChangeListener listener)
799 changeSupport.addPropertyChangeListener(listener);
808 public void removePropertyChangeListener(
809 java.beans.PropertyChangeListener listener)
811 changeSupport.removePropertyChangeListener(listener);
815 * Property change listener for changes in alignment
824 public void firePropertyChange(String prop, Object oldvalue,
827 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
830 // common hide/show column stuff
832 public void hideSelectedColumns()
834 if (colSel.size() < 1)
839 colSel.hideSelectedColumns();
840 setSelectionGroup(null);
842 hasHiddenColumns = true;
845 public void hideColumns(int start, int end)
849 colSel.hideColumns(start);
853 colSel.hideColumns(start, end);
856 hasHiddenColumns = true;
859 public void showColumn(int col)
861 colSel.revealHiddenColumns(col);
862 if (colSel.getHiddenColumns() == null)
864 hasHiddenColumns = false;
868 public void showAllHiddenColumns()
870 colSel.revealAllHiddenColumns();
871 hasHiddenColumns = false;
874 // common hide/show seq stuff
875 public void showAllHiddenSeqs()
877 if (alignment.getHiddenSequences().getSize() > 0)
879 if (selectionGroup == null)
881 selectionGroup = new SequenceGroup();
882 selectionGroup.setEndRes(alignment.getWidth() - 1);
884 Vector tmp = alignment.getHiddenSequences().showAll(
886 for (int t = 0; t < tmp.size(); t++)
888 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
891 hasHiddenRows = false;
892 hiddenRepSequences = null;
894 firePropertyChange("alignment", null, alignment.getSequences());
895 // used to set hasHiddenRows/hiddenRepSequences here, after the property
901 public void showSequence(int index)
903 Vector tmp = alignment.getHiddenSequences().showSequence(index,
907 if (selectionGroup == null)
909 selectionGroup = new SequenceGroup();
910 selectionGroup.setEndRes(alignment.getWidth() - 1);
913 for (int t = 0; t < tmp.size(); t++)
915 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
917 // JBPNote: refactor: only update flag if we modified visiblity (used to
918 // do this regardless)
919 if (alignment.getHiddenSequences().getSize() < 1)
921 hasHiddenRows = false;
923 firePropertyChange("alignment", null, alignment.getSequences());
928 public void hideAllSelectedSeqs()
930 if (selectionGroup == null || selectionGroup.getSize() < 1)
935 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
939 setSelectionGroup(null);
942 public void hideSequence(SequenceI[] seq)
946 for (int i = 0; i < seq.length; i++)
948 alignment.getHiddenSequences().hideSequence(seq[i]);
950 hasHiddenRows = true;
951 firePropertyChange("alignment", null, alignment.getSequences());
955 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
957 int sSize = sg.getSize();
963 if (hiddenRepSequences == null)
965 hiddenRepSequences = new Hashtable();
968 hiddenRepSequences.put(repSequence, sg);
970 // Hide all sequences except the repSequence
971 SequenceI[] seqs = new SequenceI[sSize - 1];
973 for (int i = 0; i < sSize; i++)
975 if (sg.getSequenceAt(i) != repSequence)
977 if (index == sSize - 1)
982 seqs[index++] = sg.getSequenceAt(i);
985 sg.setSeqrep(repSequence); // note: not done in 2.7applet
986 sg.setHidereps(true); // note: not done in 2.7applet
991 public boolean isHiddenRepSequence(SequenceI seq)
993 return hiddenRepSequences != null
994 && hiddenRepSequences.containsKey(seq);
997 public SequenceGroup getRepresentedSequences(SequenceI seq)
999 return (SequenceGroup) (hiddenRepSequences == null ? null
1000 : hiddenRepSequences.get(seq));
1003 public int adjustForHiddenSeqs(int alignmentIndex)
1005 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1009 // Selection manipulation
1011 * broadcast selection to any interested parties
1013 public abstract void sendSelection();
1015 public void invertColumnSelection()
1017 colSel.invertColumnSelection(0, alignment.getWidth());
1021 * This method returns an array of new SequenceI objects derived from the
1022 * whole alignment or just the current selection with start and end points
1025 * @note if you need references to the actual SequenceI objects in the
1026 * alignment or currently selected then use getSequenceSelection()
1027 * @return selection as new sequenceI objects
1029 public SequenceI[] getSelectionAsNewSequence()
1031 SequenceI[] sequences;
1032 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1033 // this was the only caller in the applet for this method
1034 // JBPNote: in applet, this method returned references to the alignment
1035 // sequences, and it did not honour the presence/absence of annotation
1036 // attached to the alignment (probably!)
1037 if (selectionGroup == null || selectionGroup.getSize() == 0)
1039 sequences = alignment.getSequencesArray();
1040 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1041 for (int i = 0; i < sequences.length; i++)
1043 sequences[i] = new Sequence(sequences[i], annots); // construct new
1045 // subset of visible
1051 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1058 * get the currently selected sequence objects or all the sequences in the
1061 * @return array of references to sequence objects
1064 public SequenceI[] getSequenceSelection()
1066 SequenceI[] sequences = null;
1067 if (selectionGroup != null)
1069 sequences = selectionGroup.getSequencesInOrder(alignment);
1071 if (sequences == null)
1073 sequences = alignment.getSequencesArray();
1079 * This method returns the visible alignment as text, as seen on the GUI, ie
1080 * if columns are hidden they will not be returned in the result. Use this for
1081 * calculating trees, PCA, redundancy etc on views which contain hidden
1087 public jalview.datamodel.CigarArray getViewAsCigars(
1088 boolean selectedRegionOnly)
1090 return new jalview.datamodel.CigarArray(alignment,
1091 (hasHiddenColumns ? colSel : null),
1092 (selectedRegionOnly ? selectionGroup : null));
1096 * return a compact representation of the current alignment selection to pass
1097 * to an analysis function
1099 * @param selectedOnly
1100 * boolean true to just return the selected view
1101 * @return AlignmentView
1104 public jalview.datamodel.AlignmentView getAlignmentView(
1105 boolean selectedOnly)
1107 return getAlignmentView(selectedOnly, false);
1111 * return a compact representation of the current alignment selection to pass
1112 * to an analysis function
1114 * @param selectedOnly
1115 * boolean true to just return the selected view
1117 * boolean true to annotate the alignment view with groups on the
1118 * alignment (and intersecting with selected region if selectedOnly
1120 * @return AlignmentView
1123 public jalview.datamodel.AlignmentView getAlignmentView(
1124 boolean selectedOnly, boolean markGroups)
1126 return new AlignmentView(alignment, colSel, selectionGroup,
1127 hasHiddenColumns, selectedOnly, markGroups);
1131 * This method returns the visible alignment as text, as seen on the GUI, ie
1132 * if columns are hidden they will not be returned in the result. Use this for
1133 * calculating trees, PCA, redundancy etc on views which contain hidden
1139 public String[] getViewAsString(boolean selectedRegionOnly)
1141 String[] selection = null;
1142 SequenceI[] seqs = null;
1144 int start = 0, end = 0;
1145 if (selectedRegionOnly && selectionGroup != null)
1147 iSize = selectionGroup.getSize();
1148 seqs = selectionGroup.getSequencesInOrder(alignment);
1149 start = selectionGroup.getStartRes();
1150 end = selectionGroup.getEndRes() + 1;
1154 iSize = alignment.getHeight();
1155 seqs = alignment.getSequencesArray();
1156 end = alignment.getWidth();
1159 selection = new String[iSize];
1160 if (hasHiddenColumns)
1162 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1166 for (i = 0; i < iSize; i++)
1168 selection[i] = seqs[i].getSequenceAsString(start, end);
1176 * return visible region boundaries within given column range
1179 * first column (inclusive, from 0)
1181 * last column (exclusive)
1182 * @return int[][] range of {start,end} visible positions
1184 public int[][] getVisibleRegionBoundaries(int min, int max)
1186 Vector regions = new Vector();
1192 if (hasHiddenColumns)
1196 start = colSel.adjustForHiddenColumns(start);
1199 end = colSel.getHiddenBoundaryRight(start);
1210 regions.addElement(new int[]
1213 if (hasHiddenColumns)
1215 start = colSel.adjustForHiddenColumns(end);
1216 start = colSel.getHiddenBoundaryLeft(start) + 1;
1218 } while (end < max);
1220 int[][] startEnd = new int[regions.size()][2];
1222 regions.copyInto(startEnd);
1229 * @return the padGaps
1231 public boolean isPadGaps()
1238 * the padGaps to set
1240 public void setPadGaps(boolean padGaps)
1242 this.padGaps = padGaps;
1246 * apply any post-edit constraints and trigger any calculations needed after
1247 * an edit has been performed on the alignment
1251 public void alignmentChanged(AlignmentViewPanel ap)
1255 alignment.padGaps();
1257 if (autoCalculateConsensus)
1259 updateConsensus(ap);
1261 if (hconsensus != null && autoCalculateConsensus)
1263 updateConservation(ap);
1265 if (autoCalculateStrucConsensus)
1267 updateStrucConsensus(ap);
1270 // Reset endRes of groups if beyond alignment width
1271 int alWidth = alignment.getWidth();
1272 List<SequenceGroup> groups = alignment.getGroups();
1275 for (SequenceGroup sg : groups)
1277 if (sg.getEndRes() > alWidth)
1279 sg.setEndRes(alWidth - 1);
1284 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1286 selectionGroup.setEndRes(alWidth - 1);
1289 resetAllColourSchemes();
1290 calculator.restartWorkers();
1291 // alignment.adjustSequenceAnnotations();
1295 * reset scope and do calculations for all applied colourschemes on alignment
1297 void resetAllColourSchemes()
1299 ColourSchemeI cs = globalColourScheme;
1302 cs.alignmentChanged(alignment, null);
1304 cs.setConsensus(hconsensus);
1305 if (cs.conservationApplied())
1307 cs.setConservation(Conservation.calculateConservation("All",
1308 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1309 alignment.getWidth(), false, getConsPercGaps(), false));
1313 for (SequenceGroup sg : alignment.getGroups())
1317 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1319 sg.recalcConservation();
1323 protected void initAutoAnnotation()
1325 // TODO: add menu option action that nulls or creates consensus object
1326 // depending on if the user wants to see the annotation or not in a
1327 // specific alignment
1329 if (hconsensus == null && !isDataset)
1331 if (!alignment.isNucleotide())
1344 private void initConsensus()
1347 consensus = new AlignmentAnnotation("Consensus", "PID",
1348 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1349 consensus.hasText = true;
1350 consensus.autoCalculated = true;
1354 alignment.addAnnotation(consensus);
1358 private void initConservation()
1360 if (showConservation)
1362 if (conservation == null)
1364 conservation = new AlignmentAnnotation("Conservation",
1365 "Conservation of total alignment less than "
1366 + getConsPercGaps() + "% gaps",
1367 new Annotation[1], 0f, 11f,
1368 AlignmentAnnotation.BAR_GRAPH);
1369 conservation.hasText = true;
1370 conservation.autoCalculated = true;
1371 alignment.addAnnotation(conservation);
1375 private void initQuality()
1379 if (quality == null)
1381 quality = new AlignmentAnnotation("Quality",
1382 "Alignment Quality based on Blosum62 scores",
1383 new Annotation[1], 0f, 11f,
1384 AlignmentAnnotation.BAR_GRAPH);
1385 quality.hasText = true;
1386 quality.autoCalculated = true;
1387 alignment.addAnnotation(quality);
1391 private void initRNAStructure()
1393 if (alignment.hasRNAStructure() && strucConsensus==null)
1395 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1396 new Annotation[1], 0f, 100f,
1397 AlignmentAnnotation.BAR_GRAPH);
1398 strucConsensus.hasText = true;
1399 strucConsensus.autoCalculated = true;
1403 alignment.addAnnotation(strucConsensus);
1410 * @see jalview.api.AlignViewportI#calcPanelHeight()
1412 public int calcPanelHeight()
1414 // setHeight of panels
1415 AlignmentAnnotation[] aa = getAlignment().getAlignmentAnnotation();
1417 int charHeight = getCharHeight();
1420 BitSet graphgrp = new BitSet();
1421 for (int i = 0; i < aa.length; i++)
1425 System.err.println("Null annotation row: ignoring.");
1432 if (aa[i].graphGroup > -1)
1434 if (graphgrp.get(aa[i].graphGroup))
1440 graphgrp.set(aa[i].graphGroup);
1447 aa[i].height += charHeight;
1455 if (aa[i].graph > 0)
1457 aa[i].height += aa[i].graphHeight;
1460 if (aa[i].height == 0)
1465 height += aa[i].height;
1477 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1478 boolean preserveNewGroupSettings)
1480 boolean updateCalcs = false;
1481 boolean conv = isShowGroupConservation();
1482 boolean cons = isShowGroupConsensus();
1483 boolean showprf = isShowSequenceLogo();
1484 boolean showConsHist = isShowConsensusHistogram();
1485 boolean normLogo = isNormaliseSequenceLogo();
1488 * TODO reorder the annotation rows according to group/sequence ordering on
1491 boolean sortg = true;
1493 // remove old automatic annotation
1494 // add any new annotation
1496 // intersect alignment annotation with alignment groups
1498 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
1499 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
1502 for (int an = 0; an < aan.length; an++)
1504 if (aan[an].autoCalculated && aan[an].groupRef != null)
1506 oldrfs.add(aan[an].groupRef);
1507 alignment.deleteAnnotation(aan[an]);
1512 if (alignment.getGroups() != null)
1514 for (SequenceGroup sg : alignment.getGroups())
1516 updateCalcs = false;
1517 if (applyGlobalSettings
1518 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
1520 // set defaults for this group's conservation/consensus
1521 sg.setshowSequenceLogo(showprf);
1522 sg.setShowConsensusHistogram(showConsHist);
1523 sg.setNormaliseSequenceLogo(normLogo);
1528 alignment.addAnnotation(sg.getConservationRow(), 0);
1533 alignment.addAnnotation(sg.getConsensus(), 0);
1535 // refresh the annotation rows
1538 sg.recalcConservation();
1546 public Color getSequenceColour(SequenceI seq)
1548 Color sqc=Color.white;
1549 if (sequenceColours != null)
1551 sqc = (Color) sequenceColours.get(seq);
1560 public void setSequenceColour(SequenceI seq, Color col)
1562 if (sequenceColours == null)
1564 sequenceColours = new Hashtable();
1569 sequenceColours.remove(seq);
1573 sequenceColours.put(seq, col);
1578 public void updateSequenceIdColours()
1580 if (sequenceColours == null)
1582 sequenceColours = new Hashtable();
1584 for (SequenceGroup sg : alignment.getGroups())
1586 if (sg.idColour != null)
1588 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
1590 sequenceColours.put(s, sg.idColour);
1597 public void clearSequenceColours()
1599 sequenceColours = null;