2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3 * Copyright (C) 2014 The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
19 package jalview.viewmodel;
21 import jalview.analysis.AAFrequency;
22 import jalview.analysis.Conservation;
23 import jalview.api.AlignCalcManagerI;
24 import jalview.api.AlignViewportI;
25 import jalview.api.AlignmentViewPanel;
26 import jalview.datamodel.AlignmentAnnotation;
27 import jalview.datamodel.AlignmentI;
28 import jalview.datamodel.AlignmentView;
29 import jalview.datamodel.Annotation;
30 import jalview.datamodel.ColumnSelection;
31 import jalview.datamodel.Sequence;
32 import jalview.datamodel.SequenceCollectionI;
33 import jalview.datamodel.SequenceGroup;
34 import jalview.datamodel.SequenceI;
35 import jalview.schemes.Blosum62ColourScheme;
36 import jalview.schemes.ClustalxColourScheme;
37 import jalview.schemes.ColourSchemeI;
38 import jalview.schemes.PIDColourScheme;
39 import jalview.schemes.ResidueProperties;
40 import jalview.workers.AlignCalcManager;
41 import jalview.workers.ConsensusThread;
42 import jalview.workers.StrucConsensusThread;
44 import java.awt.Color;
45 import java.util.ArrayList;
46 import java.util.BitSet;
47 import java.util.Hashtable;
48 import java.util.List;
50 import java.util.Vector;
53 * base class holding visualization and analysis attributes and common logic for
54 * an active alignment view displayed in the GUI
59 public abstract class AlignmentViewport implements AlignViewportI
62 * alignment displayed in the viewport. Please use get/setter
64 protected AlignmentI alignment;
66 protected String sequenceSetID;
69 * probably unused indicator that view is of a dataset rather than an
72 protected boolean isDataset = false;
74 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
76 protected ColumnSelection colSel = new ColumnSelection();
78 public boolean autoCalculateConsensus = true;
80 protected boolean autoCalculateStrucConsensus = true;
82 protected boolean ignoreGapsInConsensusCalculation = false;
84 protected ColourSchemeI globalColourScheme = null;
87 * gui state - changes to colour scheme propagated to all groups
89 private boolean colourAppliesToAllGroups;
93 * indicating if subsequent colourscheme changes will be propagated
96 public void setColourAppliesToAllGroups(boolean b)
98 colourAppliesToAllGroups = b;
104 * @return flag indicating if colourchanges propagated to all groups
106 public boolean getColourAppliesToAllGroups()
108 return colourAppliesToAllGroups;
111 boolean abovePIDThreshold = false;
116 * @return true if percent identity threshold is applied to shading
118 public boolean getAbovePIDThreshold()
120 return abovePIDThreshold;
128 * indicate if percent identity threshold is applied to shading
130 public void setAbovePIDThreshold(boolean b)
132 abovePIDThreshold = b;
143 public void setThreshold(int thresh)
151 * @return DOCUMENT ME!
153 public int getThreshold()
163 * set the scalar for bleaching colourschemes according to degree of
166 public void setIncrement(int inc)
174 * @return get scalar for bleaching colourschemes by conservation
176 public int getIncrement()
181 boolean conservationColourSelected = false;
186 * @return true if conservation based shading is enabled
188 public boolean getConservationSelected()
190 return conservationColourSelected;
197 * enable conservation based shading
199 public void setConservationSelected(boolean b)
201 conservationColourSelected = b;
205 public void setGlobalColourScheme(ColourSchemeI cs)
207 // TODO: logic refactored from AlignFrame changeColour -
208 // autorecalc stuff should be changed to rely on the worker system
209 // check to see if we should implement a changeColour(cs) method rather than
210 // put th logic in here
211 // - means that caller decides if they want to just modify state and defer
212 // calculation till later or to do all calculations in thread.
214 globalColourScheme = cs;
215 if (getColourAppliesToAllGroups())
217 for (SequenceGroup sg : getAlignment().getGroups())
224 if (cs instanceof ClustalxColourScheme)
226 sg.cs = new ClustalxColourScheme(sg, getHiddenRepSequences());
232 sg.cs = cs.getClass().newInstance();
233 } catch (Exception ex)
235 ex.printStackTrace();
240 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
241 || cs instanceof Blosum62ColourScheme)
243 sg.cs.setThreshold(threshold, getIgnoreGapsConsensus());
244 sg.cs.setConsensus(AAFrequency.calculate(
245 sg.getSequences(getHiddenRepSequences()), 0,
250 sg.cs.setThreshold(0, getIgnoreGapsConsensus());
253 if (getConservationSelected())
255 Conservation c = new Conservation("Group",
256 ResidueProperties.propHash, 3,
257 sg.getSequences(getHiddenRepSequences()), 0,
258 getAlignment().getWidth() - 1);
260 c.verdict(false, getConsPercGaps());
261 sg.cs.setConservation(c);
265 sg.cs.setConservation(null);
266 sg.cs.setThreshold(0, getIgnoreGapsConsensus());
275 public ColourSchemeI getGlobalColourScheme()
277 return globalColourScheme;
280 protected AlignmentAnnotation consensus;
282 protected AlignmentAnnotation strucConsensus;
284 protected AlignmentAnnotation conservation;
286 protected AlignmentAnnotation quality;
288 protected AlignmentAnnotation[] groupConsensus;
290 protected AlignmentAnnotation[] groupConservation;
293 * results of alignment consensus analysis for visible portion of view
295 protected Hashtable[] hconsensus = null;
298 * results of secondary structure base pair consensus for visible portion of
301 protected Hashtable[] hStrucConsensus = null;
303 protected Conservation hconservation = null;
305 public void setConservation(Conservation cons)
307 hconservation = cons;
310 * percentage gaps allowed in a column before all amino acid properties should
311 * be considered unconserved
313 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
316 public int getConsPercGaps()
322 public void setSequenceConsensusHash(Hashtable[] hconsensus)
324 this.hconsensus = hconsensus;
329 public Hashtable[] getSequenceConsensusHash()
335 public Hashtable[] getRnaStructureConsensusHash()
337 return hStrucConsensus;
341 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
343 this.hStrucConsensus = hStrucConsensus;
348 public AlignmentAnnotation getAlignmentQualityAnnot()
354 public AlignmentAnnotation getAlignmentConservationAnnotation()
360 public AlignmentAnnotation getAlignmentConsensusAnnotation()
366 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
368 return strucConsensus;
371 protected AlignCalcManagerI calculator = new AlignCalcManager();
374 * trigger update of conservation annotation
376 public void updateConservation(final AlignmentViewPanel ap)
378 // see note in mantis : issue number 8585
379 if (alignment.isNucleotide() || conservation == null
380 || !autoCalculateConsensus)
385 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
387 calculator.registerWorker(new jalview.workers.ConservationThread(
393 * trigger update of consensus annotation
395 public void updateConsensus(final AlignmentViewPanel ap)
397 // see note in mantis : issue number 8585
398 if (consensus == null || !autoCalculateConsensus)
402 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
404 calculator.registerWorker(new ConsensusThread(this, ap));
408 // --------START Structure Conservation
409 public void updateStrucConsensus(final AlignmentViewPanel ap)
411 if (autoCalculateStrucConsensus && strucConsensus == null
412 && alignment.isNucleotide() && alignment.hasRNAStructure())
414 // secondary structure has been added - so init the consensus line
418 // see note in mantis : issue number 8585
419 if (strucConsensus == null || !autoCalculateStrucConsensus)
423 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
425 calculator.registerWorker(new StrucConsensusThread(this, ap));
429 public boolean isCalcInProgress()
431 return calculator.isWorking();
435 public boolean isCalculationInProgress(
436 AlignmentAnnotation alignmentAnnotation)
438 if (!alignmentAnnotation.autoCalculated)
440 if (calculator.workingInvolvedWith(alignmentAnnotation))
442 // System.err.println("grey out ("+alignmentAnnotation.label+")");
449 public boolean isClosed()
451 // TODO: check that this isClosed is only true after panel is closed, not
452 // before it is fully constructed.
453 return alignment == null;
457 public AlignCalcManagerI getCalcManager()
463 * should conservation rows be shown for groups
465 protected boolean showGroupConservation = false;
468 * should consensus rows be shown for groups
470 protected boolean showGroupConsensus = false;
473 * should consensus profile be rendered by default
475 protected boolean showSequenceLogo = false;
478 * should consensus profile be rendered normalised to row height
480 protected boolean normaliseSequenceLogo = false;
483 * should consensus histograms be rendered by default
485 protected boolean showConsensusHistogram = true;
488 * @return the showConsensusProfile
491 public boolean isShowSequenceLogo()
493 return showSequenceLogo;
497 * @param showSequenceLogo
500 public void setShowSequenceLogo(boolean showSequenceLogo)
502 if (showSequenceLogo != this.showSequenceLogo)
504 // TODO: decouple settings setting from calculation when refactoring
505 // annotation update method from alignframe to viewport
506 this.showSequenceLogo = showSequenceLogo;
507 calculator.updateAnnotationFor(ConsensusThread.class);
508 calculator.updateAnnotationFor(StrucConsensusThread.class);
510 this.showSequenceLogo = showSequenceLogo;
514 * @param showConsensusHistogram
515 * the showConsensusHistogram to set
517 public void setShowConsensusHistogram(boolean showConsensusHistogram)
519 this.showConsensusHistogram = showConsensusHistogram;
523 * @return the showGroupConservation
525 public boolean isShowGroupConservation()
527 return showGroupConservation;
531 * @param showGroupConservation
532 * the showGroupConservation to set
534 public void setShowGroupConservation(boolean showGroupConservation)
536 this.showGroupConservation = showGroupConservation;
540 * @return the showGroupConsensus
542 public boolean isShowGroupConsensus()
544 return showGroupConsensus;
548 * @param showGroupConsensus
549 * the showGroupConsensus to set
551 public void setShowGroupConsensus(boolean showGroupConsensus)
553 this.showGroupConsensus = showGroupConsensus;
558 * @return flag to indicate if the consensus histogram should be rendered by
562 public boolean isShowConsensusHistogram()
564 return this.showConsensusHistogram;
568 * show non-conserved residues only
570 protected boolean showUnconserved = false;
573 * when set, updateAlignment will always ensure sequences are of equal length
575 private boolean padGaps = false;
578 * when set, alignment should be reordered according to a newly opened tree
580 public boolean sortByTree = false;
582 public boolean getShowUnconserved()
584 return showUnconserved;
587 public void setShowUnconserved(boolean showunconserved)
589 showUnconserved = showunconserved;
593 * @param showNonconserved
594 * the showUnconserved to set
596 public void setShowunconserved(boolean displayNonconserved)
598 this.showUnconserved = displayNonconserved;
604 * @return null or the currently selected sequence region
607 public SequenceGroup getSelectionGroup()
609 return selectionGroup;
613 * Set the selection group for this window.
616 * - group holding references to sequences in this alignment view
620 public void setSelectionGroup(SequenceGroup sg)
625 public void setHiddenColumns(ColumnSelection colsel)
627 this.colSel = colsel;
628 if (colSel.getHiddenColumns() != null)
630 hasHiddenColumns = true;
635 public ColumnSelection getColumnSelection()
640 public void setColumnSelection(ColumnSelection colSel)
642 this.colSel = colSel;
650 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
652 return hiddenRepSequences;
656 public void setHiddenRepSequences(
657 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
659 this.hiddenRepSequences = hiddenRepSequences;
662 protected boolean hasHiddenColumns = false;
664 public void updateHiddenColumns()
666 hasHiddenColumns = colSel.getHiddenColumns() != null;
669 protected boolean hasHiddenRows = false;
671 public boolean hasHiddenRows()
673 return hasHiddenRows;
676 protected SequenceGroup selectionGroup;
678 public void setSequenceSetId(String newid)
680 if (sequenceSetID != null)
683 .println("Warning - overwriting a sequenceSetId for a viewport!");
685 sequenceSetID = new String(newid);
688 public String getSequenceSetId()
690 if (sequenceSetID == null)
692 sequenceSetID = alignment.hashCode() + "";
695 return sequenceSetID;
699 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
702 protected String viewId = null;
704 public String getViewId()
708 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
713 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
715 ignoreGapsInConsensusCalculation = b;
719 if (globalColourScheme != null)
721 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
722 ignoreGapsInConsensusCalculation);
728 private long sgrouphash = -1, colselhash = -1;
731 * checks current SelectionGroup against record of last hash value, and
735 * update the record of last hash value
737 * @return true if SelectionGroup changed since last call (when b is true)
739 public boolean isSelectionGroupChanged(boolean b)
741 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
742 : selectionGroup.hashCode();
743 if (hc != -1 && hc != sgrouphash)
755 * checks current colsel against record of last hash value, and optionally
759 * update the record of last hash value
760 * @return true if colsel changed since last call (when b is true)
762 public boolean isColSelChanged(boolean b)
764 int hc = (colSel == null || colSel.size() == 0) ? -1 : colSel
766 if (hc != -1 && hc != colselhash)
778 public boolean getIgnoreGapsConsensus()
780 return ignoreGapsInConsensusCalculation;
783 // / property change stuff
785 // JBPNote Prolly only need this in the applet version.
786 private final java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
789 protected boolean showConservation = true;
791 protected boolean showQuality = true;
793 protected boolean showConsensus = true;
795 Hashtable sequenceColours;
798 * Property change listener for changes in alignment
803 public void addPropertyChangeListener(
804 java.beans.PropertyChangeListener listener)
806 changeSupport.addPropertyChangeListener(listener);
815 public void removePropertyChangeListener(
816 java.beans.PropertyChangeListener listener)
818 changeSupport.removePropertyChangeListener(listener);
822 * Property change listener for changes in alignment
831 public void firePropertyChange(String prop, Object oldvalue,
834 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
837 // common hide/show column stuff
839 public void hideSelectedColumns()
841 if (colSel.size() < 1)
846 colSel.hideSelectedColumns();
847 setSelectionGroup(null);
849 hasHiddenColumns = true;
852 public void hideColumns(int start, int end)
856 colSel.hideColumns(start);
860 colSel.hideColumns(start, end);
863 hasHiddenColumns = true;
866 public void showColumn(int col)
868 colSel.revealHiddenColumns(col);
869 if (colSel.getHiddenColumns() == null)
871 hasHiddenColumns = false;
875 public void showAllHiddenColumns()
877 colSel.revealAllHiddenColumns();
878 hasHiddenColumns = false;
881 // common hide/show seq stuff
882 public void showAllHiddenSeqs()
884 if (alignment.getHiddenSequences().getSize() > 0)
886 if (selectionGroup == null)
888 selectionGroup = new SequenceGroup();
889 selectionGroup.setEndRes(alignment.getWidth() - 1);
891 Vector tmp = alignment.getHiddenSequences().showAll(
893 for (int t = 0; t < tmp.size(); t++)
895 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
898 hasHiddenRows = false;
899 hiddenRepSequences = null;
901 firePropertyChange("alignment", null, alignment.getSequences());
902 // used to set hasHiddenRows/hiddenRepSequences here, after the property
908 public void showSequence(int index)
910 Vector tmp = alignment.getHiddenSequences().showSequence(index,
914 if (selectionGroup == null)
916 selectionGroup = new SequenceGroup();
917 selectionGroup.setEndRes(alignment.getWidth() - 1);
920 for (int t = 0; t < tmp.size(); t++)
922 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
924 // JBPNote: refactor: only update flag if we modified visiblity (used to
925 // do this regardless)
926 if (alignment.getHiddenSequences().getSize() < 1)
928 hasHiddenRows = false;
930 firePropertyChange("alignment", null, alignment.getSequences());
935 public void hideAllSelectedSeqs()
937 if (selectionGroup == null || selectionGroup.getSize() < 1)
942 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
946 setSelectionGroup(null);
949 public void hideSequence(SequenceI[] seq)
953 for (int i = 0; i < seq.length; i++)
955 alignment.getHiddenSequences().hideSequence(seq[i]);
957 hasHiddenRows = true;
958 firePropertyChange("alignment", null, alignment.getSequences());
962 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
964 int sSize = sg.getSize();
970 if (hiddenRepSequences == null)
972 hiddenRepSequences = new Hashtable();
975 hiddenRepSequences.put(repSequence, sg);
977 // Hide all sequences except the repSequence
978 SequenceI[] seqs = new SequenceI[sSize - 1];
980 for (int i = 0; i < sSize; i++)
982 if (sg.getSequenceAt(i) != repSequence)
984 if (index == sSize - 1)
989 seqs[index++] = sg.getSequenceAt(i);
992 sg.setSeqrep(repSequence); // note: not done in 2.7applet
993 sg.setHidereps(true); // note: not done in 2.7applet
998 public boolean isHiddenRepSequence(SequenceI seq)
1000 return hiddenRepSequences != null
1001 && hiddenRepSequences.containsKey(seq);
1004 public SequenceGroup getRepresentedSequences(SequenceI seq)
1006 return (SequenceGroup) (hiddenRepSequences == null ? null
1007 : hiddenRepSequences.get(seq));
1010 public int adjustForHiddenSeqs(int alignmentIndex)
1012 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1016 // Selection manipulation
1018 * broadcast selection to any interested parties
1020 public abstract void sendSelection();
1022 public void invertColumnSelection()
1024 colSel.invertColumnSelection(0, alignment.getWidth());
1028 * This method returns an array of new SequenceI objects derived from the
1029 * whole alignment or just the current selection with start and end points
1032 * @note if you need references to the actual SequenceI objects in the
1033 * alignment or currently selected then use getSequenceSelection()
1034 * @return selection as new sequenceI objects
1036 public SequenceI[] getSelectionAsNewSequence()
1038 SequenceI[] sequences;
1039 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1040 // this was the only caller in the applet for this method
1041 // JBPNote: in applet, this method returned references to the alignment
1042 // sequences, and it did not honour the presence/absence of annotation
1043 // attached to the alignment (probably!)
1044 if (selectionGroup == null || selectionGroup.getSize() == 0)
1046 sequences = alignment.getSequencesArray();
1047 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1048 for (int i = 0; i < sequences.length; i++)
1050 sequences[i] = new Sequence(sequences[i], annots); // construct new
1052 // subset of visible
1058 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1065 * get the currently selected sequence objects or all the sequences in the
1068 * @return array of references to sequence objects
1071 public SequenceI[] getSequenceSelection()
1073 SequenceI[] sequences = null;
1074 if (selectionGroup != null)
1076 sequences = selectionGroup.getSequencesInOrder(alignment);
1078 if (sequences == null)
1080 sequences = alignment.getSequencesArray();
1086 * This method returns the visible alignment as text, as seen on the GUI, ie
1087 * if columns are hidden they will not be returned in the result. Use this for
1088 * calculating trees, PCA, redundancy etc on views which contain hidden
1094 public jalview.datamodel.CigarArray getViewAsCigars(
1095 boolean selectedRegionOnly)
1097 return new jalview.datamodel.CigarArray(alignment,
1098 (hasHiddenColumns ? colSel : null),
1099 (selectedRegionOnly ? selectionGroup : null));
1103 * return a compact representation of the current alignment selection to pass
1104 * to an analysis function
1106 * @param selectedOnly
1107 * boolean true to just return the selected view
1108 * @return AlignmentView
1111 public jalview.datamodel.AlignmentView getAlignmentView(
1112 boolean selectedOnly)
1114 return getAlignmentView(selectedOnly, false);
1118 * return a compact representation of the current alignment selection to pass
1119 * to an analysis function
1121 * @param selectedOnly
1122 * boolean true to just return the selected view
1124 * boolean true to annotate the alignment view with groups on the
1125 * alignment (and intersecting with selected region if selectedOnly
1127 * @return AlignmentView
1130 public jalview.datamodel.AlignmentView getAlignmentView(
1131 boolean selectedOnly, boolean markGroups)
1133 return new AlignmentView(alignment, colSel, selectionGroup,
1134 hasHiddenColumns, selectedOnly, markGroups);
1138 * This method returns the visible alignment as text, as seen on the GUI, ie
1139 * if columns are hidden they will not be returned in the result. Use this for
1140 * calculating trees, PCA, redundancy etc on views which contain hidden
1146 public String[] getViewAsString(boolean selectedRegionOnly)
1148 String[] selection = null;
1149 SequenceI[] seqs = null;
1151 int start = 0, end = 0;
1152 if (selectedRegionOnly && selectionGroup != null)
1154 iSize = selectionGroup.getSize();
1155 seqs = selectionGroup.getSequencesInOrder(alignment);
1156 start = selectionGroup.getStartRes();
1157 end = selectionGroup.getEndRes() + 1;
1161 iSize = alignment.getHeight();
1162 seqs = alignment.getSequencesArray();
1163 end = alignment.getWidth();
1166 selection = new String[iSize];
1167 if (hasHiddenColumns)
1169 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1173 for (i = 0; i < iSize; i++)
1175 selection[i] = seqs[i].getSequenceAsString(start, end);
1183 * return visible region boundaries within given column range
1186 * first column (inclusive, from 0)
1188 * last column (exclusive)
1189 * @return int[][] range of {start,end} visible positions
1191 public int[][] getVisibleRegionBoundaries(int min, int max)
1193 Vector regions = new Vector();
1199 if (hasHiddenColumns)
1203 start = colSel.adjustForHiddenColumns(start);
1206 end = colSel.getHiddenBoundaryRight(start);
1217 regions.addElement(new int[]
1220 if (hasHiddenColumns)
1222 start = colSel.adjustForHiddenColumns(end);
1223 start = colSel.getHiddenBoundaryLeft(start) + 1;
1225 } while (end < max);
1227 int[][] startEnd = new int[regions.size()][2];
1229 regions.copyInto(startEnd);
1236 * @return the padGaps
1238 public boolean isPadGaps()
1245 * the padGaps to set
1247 public void setPadGaps(boolean padGaps)
1249 this.padGaps = padGaps;
1253 * apply any post-edit constraints and trigger any calculations needed after
1254 * an edit has been performed on the alignment
1258 public void alignmentChanged(AlignmentViewPanel ap)
1262 alignment.padGaps();
1264 if (autoCalculateConsensus)
1266 updateConsensus(ap);
1268 if (hconsensus != null && autoCalculateConsensus)
1270 updateConservation(ap);
1272 if (autoCalculateStrucConsensus)
1274 updateStrucConsensus(ap);
1277 // Reset endRes of groups if beyond alignment width
1278 int alWidth = alignment.getWidth();
1279 List<SequenceGroup> groups = alignment.getGroups();
1282 for (SequenceGroup sg : groups)
1284 if (sg.getEndRes() > alWidth)
1286 sg.setEndRes(alWidth - 1);
1291 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1293 selectionGroup.setEndRes(alWidth - 1);
1296 resetAllColourSchemes();
1297 calculator.restartWorkers();
1298 // alignment.adjustSequenceAnnotations();
1302 * reset scope and do calculations for all applied colourschemes on alignment
1304 void resetAllColourSchemes()
1306 ColourSchemeI cs = globalColourScheme;
1309 cs.alignmentChanged(alignment, null);
1311 cs.setConsensus(hconsensus);
1312 if (cs.conservationApplied())
1314 cs.setConservation(Conservation.calculateConservation("All",
1315 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1316 alignment.getWidth(), false, getConsPercGaps(), false));
1320 for (SequenceGroup sg : alignment.getGroups())
1324 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1326 sg.recalcConservation();
1330 protected void initAutoAnnotation()
1332 // TODO: add menu option action that nulls or creates consensus object
1333 // depending on if the user wants to see the annotation or not in a
1334 // specific alignment
1336 if (hconsensus == null && !isDataset)
1338 if (!alignment.isNucleotide())
1351 private void initConsensus()
1354 consensus = new AlignmentAnnotation("Consensus", "PID",
1355 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1356 consensus.hasText = true;
1357 consensus.autoCalculated = true;
1361 alignment.addAnnotation(consensus);
1365 private void initConservation()
1367 if (showConservation)
1369 if (conservation == null)
1371 conservation = new AlignmentAnnotation("Conservation",
1372 "Conservation of total alignment less than "
1373 + getConsPercGaps() + "% gaps",
1374 new Annotation[1], 0f, 11f,
1375 AlignmentAnnotation.BAR_GRAPH);
1376 conservation.hasText = true;
1377 conservation.autoCalculated = true;
1378 alignment.addAnnotation(conservation);
1382 private void initQuality()
1386 if (quality == null)
1388 quality = new AlignmentAnnotation("Quality",
1389 "Alignment Quality based on Blosum62 scores",
1390 new Annotation[1], 0f, 11f,
1391 AlignmentAnnotation.BAR_GRAPH);
1392 quality.hasText = true;
1393 quality.autoCalculated = true;
1394 alignment.addAnnotation(quality);
1398 private void initRNAStructure()
1400 if (alignment.hasRNAStructure() && strucConsensus==null)
1402 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1403 new Annotation[1], 0f, 100f,
1404 AlignmentAnnotation.BAR_GRAPH);
1405 strucConsensus.hasText = true;
1406 strucConsensus.autoCalculated = true;
1410 alignment.addAnnotation(strucConsensus);
1417 * @see jalview.api.AlignViewportI#calcPanelHeight()
1419 public int calcPanelHeight()
1421 // setHeight of panels
1422 AlignmentAnnotation[] aa = getAlignment().getAlignmentAnnotation();
1424 int charHeight = getCharHeight();
1427 BitSet graphgrp = new BitSet();
1428 for (int i = 0; i < aa.length; i++)
1432 System.err.println("Null annotation row: ignoring.");
1439 if (aa[i].graphGroup > -1)
1441 if (graphgrp.get(aa[i].graphGroup))
1447 graphgrp.set(aa[i].graphGroup);
1454 aa[i].height += charHeight;
1462 if (aa[i].graph > 0)
1464 aa[i].height += aa[i].graphHeight;
1467 if (aa[i].height == 0)
1472 height += aa[i].height;
1484 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1485 boolean preserveNewGroupSettings)
1487 boolean updateCalcs = false;
1488 boolean conv = isShowGroupConservation();
1489 boolean cons = isShowGroupConsensus();
1490 boolean showprf = isShowSequenceLogo();
1491 boolean showConsHist = isShowConsensusHistogram();
1492 boolean normLogo = isNormaliseSequenceLogo();
1495 * TODO reorder the annotation rows according to group/sequence ordering on
1498 boolean sortg = true;
1500 // remove old automatic annotation
1501 // add any new annotation
1503 // intersect alignment annotation with alignment groups
1505 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
1506 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
1509 for (int an = 0; an < aan.length; an++)
1511 if (aan[an].autoCalculated && aan[an].groupRef != null)
1513 oldrfs.add(aan[an].groupRef);
1514 alignment.deleteAnnotation(aan[an],false);
1518 if (alignment.getGroups() != null)
1520 for (SequenceGroup sg : alignment.getGroups())
1522 updateCalcs = false;
1523 if (applyGlobalSettings
1524 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
1526 // set defaults for this group's conservation/consensus
1527 sg.setshowSequenceLogo(showprf);
1528 sg.setShowConsensusHistogram(showConsHist);
1529 sg.setNormaliseSequenceLogo(normLogo);
1534 alignment.addAnnotation(sg.getConservationRow(), 0);
1539 alignment.addAnnotation(sg.getConsensus(), 0);
1541 // refresh the annotation rows
1544 sg.recalcConservation();
1552 public Color getSequenceColour(SequenceI seq)
1554 Color sqc=Color.white;
1555 if (sequenceColours != null)
1557 sqc = (Color) sequenceColours.get(seq);
1566 public void setSequenceColour(SequenceI seq, Color col)
1568 if (sequenceColours == null)
1570 sequenceColours = new Hashtable();
1575 sequenceColours.remove(seq);
1579 sequenceColours.put(seq, col);
1584 public void updateSequenceIdColours()
1586 if (sequenceColours == null)
1588 sequenceColours = new Hashtable();
1590 for (SequenceGroup sg : alignment.getGroups())
1592 if (sg.idColour != null)
1594 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
1596 sequenceColours.put(s, sg.idColour);
1603 public void clearSequenceColours()
1605 sequenceColours = null;