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.Conservation;
24 import jalview.api.AlignCalcManagerI;
25 import jalview.api.AlignViewportI;
26 import jalview.api.AlignmentViewPanel;
27 import jalview.datamodel.AlignmentAnnotation;
28 import jalview.datamodel.AlignmentI;
29 import jalview.datamodel.AlignmentView;
30 import jalview.datamodel.Annotation;
31 import jalview.datamodel.ColumnSelection;
32 import jalview.datamodel.Sequence;
33 import jalview.datamodel.SequenceCollectionI;
34 import jalview.datamodel.SequenceGroup;
35 import jalview.datamodel.SequenceI;
36 import jalview.schemes.Blosum62ColourScheme;
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.HashMap;
48 import java.util.Hashtable;
49 import java.util.List;
51 import java.util.Vector;
54 * base class holding visualization and analysis attributes and common logic for
55 * an active alignment view displayed in the GUI
60 public abstract class AlignmentViewport implements AlignViewportI
63 * A viewport that is a slave of (driven by) this one in some sense.
65 AlignViewportI slave = null;
68 * alignment displayed in the viewport. Please use get/setter
70 protected AlignmentI alignment;
72 protected String sequenceSetID;
75 * probably unused indicator that view is of a dataset rather than an
78 protected boolean isDataset = false;
80 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
82 protected ColumnSelection colSel = new ColumnSelection();
84 public boolean autoCalculateConsensus = true;
86 protected boolean autoCalculateStrucConsensus = true;
88 protected boolean ignoreGapsInConsensusCalculation = false;
90 protected ColourSchemeI globalColourScheme = null;
93 * gui state - changes to colour scheme propagated to all groups
95 private boolean colourAppliesToAllGroups;
99 * indicating if subsequent colourscheme changes will be propagated
102 public void setColourAppliesToAllGroups(boolean b)
104 colourAppliesToAllGroups = b;
110 * @return flag indicating if colourchanges propagated to all groups
112 public boolean getColourAppliesToAllGroups()
114 return colourAppliesToAllGroups;
117 boolean abovePIDThreshold = false;
122 * @return true if percent identity threshold is applied to shading
124 public boolean getAbovePIDThreshold()
126 return abovePIDThreshold;
134 * indicate if percent identity threshold is applied to shading
136 public void setAbovePIDThreshold(boolean b)
138 abovePIDThreshold = b;
149 public void setThreshold(int thresh)
157 * @return DOCUMENT ME!
159 public int getThreshold()
169 * set the scalar for bleaching colourschemes according to degree of
172 public void setIncrement(int inc)
180 * @return get scalar for bleaching colourschemes by conservation
182 public int getIncrement()
187 boolean conservationColourSelected = false;
192 * @return true if conservation based shading is enabled
194 public boolean getConservationSelected()
196 return conservationColourSelected;
203 * enable conservation based shading
205 public void setConservationSelected(boolean b)
207 conservationColourSelected = b;
211 public void setGlobalColourScheme(ColourSchemeI cs)
213 // TODO: logic refactored from AlignFrame changeColour -
214 // autorecalc stuff should be changed to rely on the worker system
215 // check to see if we should implement a changeColour(cs) method rather than
216 // put th logic in here
217 // - means that caller decides if they want to just modify state and defer
218 // calculation till later or to do all calculations in thread.
220 globalColourScheme = cs;
221 boolean recalc = false;
224 cs.setConservationApplied(recalc = getConservationSelected());
225 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
226 || cs instanceof Blosum62ColourScheme)
229 cs.setThreshold(threshold, ignoreGapsInConsensusCalculation);
233 cs.setThreshold(0, ignoreGapsInConsensusCalculation);
237 cs.setConsensus(hconsensus);
238 cs.setConservation(hconservation);
240 cs.alignmentChanged(alignment, hiddenRepSequences);
242 if (getColourAppliesToAllGroups())
244 for (SequenceGroup sg : getAlignment().getGroups())
251 sg.cs = cs.applyTo(sg, getHiddenRepSequences());
252 sg.setConsPercGaps(ConsPercGaps);
253 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
254 || cs instanceof Blosum62ColourScheme)
256 sg.cs.setThreshold(threshold, getIgnoreGapsConsensus());
261 sg.cs.setThreshold(0, getIgnoreGapsConsensus());
264 if (getConservationSelected())
266 sg.cs.setConservationApplied(true);
271 sg.cs.setConservation(null);
272 // sg.cs.setThreshold(0, getIgnoreGapsConsensus());
276 sg.recalcConservation();
280 sg.cs.alignmentChanged(sg, hiddenRepSequences);
288 public ColourSchemeI getGlobalColourScheme()
290 return globalColourScheme;
293 protected AlignmentAnnotation consensus;
295 protected AlignmentAnnotation strucConsensus;
297 protected AlignmentAnnotation conservation;
299 protected AlignmentAnnotation quality;
301 protected AlignmentAnnotation[] groupConsensus;
303 protected AlignmentAnnotation[] groupConservation;
306 * results of alignment consensus analysis for visible portion of view
308 protected Hashtable[] hconsensus = null;
311 * results of secondary structure base pair consensus for visible portion of
314 protected Hashtable[] hStrucConsensus = null;
316 protected Conservation hconservation = null;
319 public void setConservation(Conservation cons)
321 hconservation = cons;
325 * percentage gaps allowed in a column before all amino acid properties should
326 * be considered unconserved
328 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
331 public int getConsPercGaps()
337 public void setSequenceConsensusHash(Hashtable[] hconsensus)
339 this.hconsensus = hconsensus;
344 public Hashtable[] getSequenceConsensusHash()
350 public Hashtable[] getRnaStructureConsensusHash()
352 return hStrucConsensus;
356 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
358 this.hStrucConsensus = hStrucConsensus;
363 public AlignmentAnnotation getAlignmentQualityAnnot()
369 public AlignmentAnnotation getAlignmentConservationAnnotation()
375 public AlignmentAnnotation getAlignmentConsensusAnnotation()
381 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
383 return strucConsensus;
386 protected AlignCalcManagerI calculator = new AlignCalcManager();
389 * trigger update of conservation annotation
391 public void updateConservation(final AlignmentViewPanel ap)
393 // see note in mantis : issue number 8585
394 if (alignment.isNucleotide() || conservation == null
395 || !autoCalculateConsensus)
400 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
402 calculator.registerWorker(new jalview.workers.ConservationThread(
408 * trigger update of consensus annotation
410 public void updateConsensus(final AlignmentViewPanel ap)
412 // see note in mantis : issue number 8585
413 if (consensus == null || !autoCalculateConsensus)
417 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
419 calculator.registerWorker(new ConsensusThread(this, ap));
423 // --------START Structure Conservation
424 public void updateStrucConsensus(final AlignmentViewPanel ap)
426 if (autoCalculateStrucConsensus && strucConsensus == null
427 && alignment.isNucleotide() && alignment.hasRNAStructure())
429 // secondary structure has been added - so init the consensus line
433 // see note in mantis : issue number 8585
434 if (strucConsensus == null || !autoCalculateStrucConsensus)
438 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
440 calculator.registerWorker(new StrucConsensusThread(this, ap));
444 public boolean isCalcInProgress()
446 return calculator.isWorking();
450 public boolean isCalculationInProgress(
451 AlignmentAnnotation alignmentAnnotation)
453 if (!alignmentAnnotation.autoCalculated)
457 if (calculator.workingInvolvedWith(alignmentAnnotation))
459 // System.err.println("grey out ("+alignmentAnnotation.label+")");
466 public boolean isClosed()
468 // TODO: check that this isClosed is only true after panel is closed, not
469 // before it is fully constructed.
470 return alignment == null;
474 public AlignCalcManagerI getCalcManager()
480 * should conservation rows be shown for groups
482 protected boolean showGroupConservation = false;
485 * should consensus rows be shown for groups
487 protected boolean showGroupConsensus = false;
490 * should consensus profile be rendered by default
492 protected boolean showSequenceLogo = false;
495 * should consensus profile be rendered normalised to row height
497 protected boolean normaliseSequenceLogo = false;
500 * should consensus histograms be rendered by default
502 protected boolean showConsensusHistogram = true;
505 * @return the showConsensusProfile
508 public boolean isShowSequenceLogo()
510 return showSequenceLogo;
514 * @param showSequenceLogo
517 public void setShowSequenceLogo(boolean showSequenceLogo)
519 if (showSequenceLogo != this.showSequenceLogo)
521 // TODO: decouple settings setting from calculation when refactoring
522 // annotation update method from alignframe to viewport
523 this.showSequenceLogo = showSequenceLogo;
524 calculator.updateAnnotationFor(ConsensusThread.class);
525 calculator.updateAnnotationFor(StrucConsensusThread.class);
527 this.showSequenceLogo = showSequenceLogo;
531 * @param showConsensusHistogram
532 * the showConsensusHistogram to set
534 public void setShowConsensusHistogram(boolean showConsensusHistogram)
536 this.showConsensusHistogram = showConsensusHistogram;
540 * @return the showGroupConservation
542 public boolean isShowGroupConservation()
544 return showGroupConservation;
548 * @param showGroupConservation
549 * the showGroupConservation to set
551 public void setShowGroupConservation(boolean showGroupConservation)
553 this.showGroupConservation = showGroupConservation;
557 * @return the showGroupConsensus
559 public boolean isShowGroupConsensus()
561 return showGroupConsensus;
565 * @param showGroupConsensus
566 * the showGroupConsensus to set
568 public void setShowGroupConsensus(boolean showGroupConsensus)
570 this.showGroupConsensus = showGroupConsensus;
575 * @return flag to indicate if the consensus histogram should be rendered by
579 public boolean isShowConsensusHistogram()
581 return this.showConsensusHistogram;
585 * show non-conserved residues only
587 protected boolean showUnconserved = false;
590 * when set, updateAlignment will always ensure sequences are of equal length
592 private boolean padGaps = false;
595 * when set, alignment should be reordered according to a newly opened tree
597 public boolean sortByTree = false;
599 public boolean getShowUnconserved()
601 return showUnconserved;
604 public void setShowUnconserved(boolean showunconserved)
606 showUnconserved = showunconserved;
610 * @param showNonconserved
611 * the showUnconserved to set
613 public void setShowunconserved(boolean displayNonconserved)
615 this.showUnconserved = displayNonconserved;
621 * @return null or the currently selected sequence region
624 public SequenceGroup getSelectionGroup()
626 return selectionGroup;
630 * Set the selection group for this window.
633 * - group holding references to sequences in this alignment view
637 public void setSelectionGroup(SequenceGroup sg)
642 public void setHiddenColumns(ColumnSelection colsel)
644 this.colSel = colsel;
645 if (colSel.getHiddenColumns() != null)
647 hasHiddenColumns = true;
652 public ColumnSelection getColumnSelection()
657 public void setColumnSelection(ColumnSelection colSel)
659 this.colSel = colSel;
667 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
669 return hiddenRepSequences;
673 public void setHiddenRepSequences(
674 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
676 this.hiddenRepSequences = hiddenRepSequences;
679 protected boolean hasHiddenColumns = false;
681 public void updateHiddenColumns()
683 hasHiddenColumns = colSel.getHiddenColumns() != null;
686 protected boolean hasHiddenRows = false;
688 public boolean hasHiddenRows()
690 return hasHiddenRows;
693 protected SequenceGroup selectionGroup;
695 public void setSequenceSetId(String newid)
697 if (sequenceSetID != null)
700 .println("Warning - overwriting a sequenceSetId for a viewport!");
702 sequenceSetID = new String(newid);
705 public String getSequenceSetId()
707 if (sequenceSetID == null)
709 sequenceSetID = alignment.hashCode() + "";
712 return sequenceSetID;
716 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
719 protected String viewId = null;
721 public String getViewId()
725 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
730 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
732 ignoreGapsInConsensusCalculation = b;
736 if (globalColourScheme != null)
738 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
739 ignoreGapsInConsensusCalculation);
745 private long sgrouphash = -1, colselhash = -1;
748 * checks current SelectionGroup against record of last hash value, and
752 * update the record of last hash value
754 * @return true if SelectionGroup changed since last call (when b is true)
756 public boolean isSelectionGroupChanged(boolean b)
758 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
759 : selectionGroup.hashCode();
760 if (hc != -1 && hc != sgrouphash)
772 * checks current colsel against record of last hash value, and optionally
776 * update the record of last hash value
777 * @return true if colsel changed since last call (when b is true)
779 public boolean isColSelChanged(boolean b)
781 int hc = (colSel == null || colSel.size() == 0) ? -1 : colSel
783 if (hc != -1 && hc != colselhash)
795 public boolean getIgnoreGapsConsensus()
797 return ignoreGapsInConsensusCalculation;
800 // / property change stuff
802 // JBPNote Prolly only need this in the applet version.
803 private final java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
806 protected boolean showConservation = true;
808 protected boolean showQuality = true;
810 protected boolean showConsensus = true;
812 private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
815 * Property change listener for changes in alignment
820 public void addPropertyChangeListener(
821 java.beans.PropertyChangeListener listener)
823 changeSupport.addPropertyChangeListener(listener);
832 public void removePropertyChangeListener(
833 java.beans.PropertyChangeListener listener)
835 changeSupport.removePropertyChangeListener(listener);
839 * Property change listener for changes in alignment
848 public void firePropertyChange(String prop, Object oldvalue,
851 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
854 // common hide/show column stuff
856 public void hideSelectedColumns()
858 if (colSel.size() < 1)
863 colSel.hideSelectedColumns();
864 setSelectionGroup(null);
866 hasHiddenColumns = true;
869 public void hideColumns(int start, int end)
873 colSel.hideColumns(start);
877 colSel.hideColumns(start, end);
880 hasHiddenColumns = true;
883 public void showColumn(int col)
885 colSel.revealHiddenColumns(col);
886 if (colSel.getHiddenColumns() == null)
888 hasHiddenColumns = false;
892 public void showAllHiddenColumns()
894 colSel.revealAllHiddenColumns();
895 hasHiddenColumns = false;
898 // common hide/show seq stuff
899 public void showAllHiddenSeqs()
901 if (alignment.getHiddenSequences().getSize() > 0)
903 if (selectionGroup == null)
905 selectionGroup = new SequenceGroup();
906 selectionGroup.setEndRes(alignment.getWidth() - 1);
908 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
910 for (SequenceI seq : tmp)
912 selectionGroup.addSequence(seq, false);
913 setSequenceAnnotationsVisible(seq, true);
916 hasHiddenRows = false;
917 hiddenRepSequences = null;
919 firePropertyChange("alignment", null, alignment.getSequences());
920 // used to set hasHiddenRows/hiddenRepSequences here, after the property
926 public void showSequence(int index)
928 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
933 if (selectionGroup == null)
935 selectionGroup = new SequenceGroup();
936 selectionGroup.setEndRes(alignment.getWidth() - 1);
939 for (SequenceI seq : tmp)
941 selectionGroup.addSequence(seq, false);
942 setSequenceAnnotationsVisible(seq, true);
944 // JBPNote: refactor: only update flag if we modified visiblity (used to
945 // do this regardless)
946 if (alignment.getHiddenSequences().getSize() < 1)
948 hasHiddenRows = false;
950 firePropertyChange("alignment", null, alignment.getSequences());
955 public void hideAllSelectedSeqs()
957 if (selectionGroup == null || selectionGroup.getSize() < 1)
962 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
966 setSelectionGroup(null);
969 public void hideSequence(SequenceI[] seq)
973 for (int i = 0; i < seq.length; i++)
975 alignment.getHiddenSequences().hideSequence(seq[i]);
976 setSequenceAnnotationsVisible(seq[i], false);
978 hasHiddenRows = true;
979 firePropertyChange("alignment", null, alignment.getSequences());
984 * Set visibility for any annotations for the given sequence.
988 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
991 for (AlignmentAnnotation ann : alignment.getAlignmentAnnotation())
993 if (ann.sequenceRef == sequenceI)
995 ann.visible = visible;
1000 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1002 int sSize = sg.getSize();
1008 if (hiddenRepSequences == null)
1010 hiddenRepSequences = new Hashtable();
1013 hiddenRepSequences.put(repSequence, sg);
1015 // Hide all sequences except the repSequence
1016 SequenceI[] seqs = new SequenceI[sSize - 1];
1018 for (int i = 0; i < sSize; i++)
1020 if (sg.getSequenceAt(i) != repSequence)
1022 if (index == sSize - 1)
1027 seqs[index++] = sg.getSequenceAt(i);
1030 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1031 sg.setHidereps(true); // note: not done in 2.7applet
1036 public boolean isHiddenRepSequence(SequenceI seq)
1038 return hiddenRepSequences != null
1039 && hiddenRepSequences.containsKey(seq);
1042 public SequenceGroup getRepresentedSequences(SequenceI seq)
1044 return (SequenceGroup) (hiddenRepSequences == null ? null
1045 : hiddenRepSequences.get(seq));
1048 public int adjustForHiddenSeqs(int alignmentIndex)
1050 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1054 // Selection manipulation
1056 * broadcast selection to any interested parties
1058 public abstract void sendSelection();
1060 public void invertColumnSelection()
1062 colSel.invertColumnSelection(0, alignment.getWidth());
1066 * This method returns an array of new SequenceI objects derived from the
1067 * whole alignment or just the current selection with start and end points
1070 * @note if you need references to the actual SequenceI objects in the
1071 * alignment or currently selected then use getSequenceSelection()
1072 * @return selection as new sequenceI objects
1074 public SequenceI[] getSelectionAsNewSequence()
1076 SequenceI[] sequences;
1077 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1078 // this was the only caller in the applet for this method
1079 // JBPNote: in applet, this method returned references to the alignment
1080 // sequences, and it did not honour the presence/absence of annotation
1081 // attached to the alignment (probably!)
1082 if (selectionGroup == null || selectionGroup.getSize() == 0)
1084 sequences = alignment.getSequencesArray();
1085 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1086 for (int i = 0; i < sequences.length; i++)
1088 sequences[i] = new Sequence(sequences[i], annots); // construct new
1090 // subset of visible
1096 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1103 * get the currently selected sequence objects or all the sequences in the
1106 * @return array of references to sequence objects
1109 public SequenceI[] getSequenceSelection()
1111 SequenceI[] sequences = null;
1112 if (selectionGroup != null)
1114 sequences = selectionGroup.getSequencesInOrder(alignment);
1116 if (sequences == null)
1118 sequences = alignment.getSequencesArray();
1124 * This method returns the visible alignment as text, as seen on the GUI, ie
1125 * if columns are hidden they will not be returned in the result. Use this for
1126 * calculating trees, PCA, redundancy etc on views which contain hidden
1132 public jalview.datamodel.CigarArray getViewAsCigars(
1133 boolean selectedRegionOnly)
1135 return new jalview.datamodel.CigarArray(alignment,
1136 (hasHiddenColumns ? colSel : null),
1137 (selectedRegionOnly ? selectionGroup : null));
1141 * return a compact representation of the current alignment selection to pass
1142 * to an analysis function
1144 * @param selectedOnly
1145 * boolean true to just return the selected view
1146 * @return AlignmentView
1149 public jalview.datamodel.AlignmentView getAlignmentView(
1150 boolean selectedOnly)
1152 return getAlignmentView(selectedOnly, false);
1156 * return a compact representation of the current alignment selection to pass
1157 * to an analysis function
1159 * @param selectedOnly
1160 * boolean true to just return the selected view
1162 * boolean true to annotate the alignment view with groups on the
1163 * alignment (and intersecting with selected region if selectedOnly
1165 * @return AlignmentView
1168 public jalview.datamodel.AlignmentView getAlignmentView(
1169 boolean selectedOnly, boolean markGroups)
1171 return new AlignmentView(alignment, colSel, selectionGroup,
1172 hasHiddenColumns, selectedOnly, markGroups);
1176 * This method returns the visible alignment as text, as seen on the GUI, ie
1177 * if columns are hidden they will not be returned in the result. Use this for
1178 * calculating trees, PCA, redundancy etc on views which contain hidden
1184 public String[] getViewAsString(boolean selectedRegionOnly)
1186 String[] selection = null;
1187 SequenceI[] seqs = null;
1189 int start = 0, end = 0;
1190 if (selectedRegionOnly && selectionGroup != null)
1192 iSize = selectionGroup.getSize();
1193 seqs = selectionGroup.getSequencesInOrder(alignment);
1194 start = selectionGroup.getStartRes();
1195 end = selectionGroup.getEndRes() + 1;
1199 iSize = alignment.getHeight();
1200 seqs = alignment.getSequencesArray();
1201 end = alignment.getWidth();
1204 selection = new String[iSize];
1205 if (hasHiddenColumns)
1207 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1211 for (i = 0; i < iSize; i++)
1213 selection[i] = seqs[i].getSequenceAsString(start, end);
1221 * return visible region boundaries within given column range
1224 * first column (inclusive, from 0)
1226 * last column (exclusive)
1227 * @return int[][] range of {start,end} visible positions
1229 public int[][] getVisibleRegionBoundaries(int min, int max)
1231 Vector regions = new Vector();
1237 if (hasHiddenColumns)
1241 start = colSel.adjustForHiddenColumns(start);
1244 end = colSel.getHiddenBoundaryRight(start);
1255 regions.addElement(new int[]
1258 if (hasHiddenColumns)
1260 start = colSel.adjustForHiddenColumns(end);
1261 start = colSel.getHiddenBoundaryLeft(start) + 1;
1263 } while (end < max);
1265 int[][] startEnd = new int[regions.size()][2];
1267 regions.copyInto(startEnd);
1274 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(boolean selectedOnly)
1276 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1277 AlignmentAnnotation[] aa;
1278 if ((aa=alignment.getAlignmentAnnotation())!=null)
1280 for (AlignmentAnnotation annot:aa)
1282 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1283 if (selectedOnly && selectionGroup!=null)
1285 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(), selectionGroup.getEndRes(),clone);
1287 colSel.makeVisibleAnnotation(clone);
1296 * @return the padGaps
1298 public boolean isPadGaps()
1305 * the padGaps to set
1307 public void setPadGaps(boolean padGaps)
1309 this.padGaps = padGaps;
1313 * apply any post-edit constraints and trigger any calculations needed after
1314 * an edit has been performed on the alignment
1318 public void alignmentChanged(AlignmentViewPanel ap)
1322 alignment.padGaps();
1324 if (autoCalculateConsensus)
1326 updateConsensus(ap);
1328 if (hconsensus != null && autoCalculateConsensus)
1330 updateConservation(ap);
1332 if (autoCalculateStrucConsensus)
1334 updateStrucConsensus(ap);
1337 // Reset endRes of groups if beyond alignment width
1338 int alWidth = alignment.getWidth();
1339 List<SequenceGroup> groups = alignment.getGroups();
1342 for (SequenceGroup sg : groups)
1344 if (sg.getEndRes() > alWidth)
1346 sg.setEndRes(alWidth - 1);
1351 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1353 selectionGroup.setEndRes(alWidth - 1);
1356 resetAllColourSchemes();
1357 calculator.restartWorkers();
1358 // alignment.adjustSequenceAnnotations();
1362 * reset scope and do calculations for all applied colourschemes on alignment
1364 void resetAllColourSchemes()
1366 ColourSchemeI cs = globalColourScheme;
1369 cs.alignmentChanged(alignment, hiddenRepSequences);
1371 cs.setConsensus(hconsensus);
1372 if (cs.conservationApplied())
1374 cs.setConservation(Conservation.calculateConservation("All",
1375 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1376 alignment.getWidth(), false, getConsPercGaps(), false));
1380 for (SequenceGroup sg : alignment.getGroups())
1384 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1386 sg.recalcConservation();
1390 protected void initAutoAnnotation()
1392 // TODO: add menu option action that nulls or creates consensus object
1393 // depending on if the user wants to see the annotation or not in a
1394 // specific alignment
1396 if (hconsensus == null && !isDataset)
1398 if (!alignment.isNucleotide())
1411 private void initConsensus()
1414 consensus = new AlignmentAnnotation("Consensus", "PID",
1415 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1416 consensus.hasText = true;
1417 consensus.autoCalculated = true;
1421 alignment.addAnnotation(consensus);
1425 private void initConservation()
1427 if (showConservation)
1429 if (conservation == null)
1431 conservation = new AlignmentAnnotation("Conservation",
1432 "Conservation of total alignment less than "
1433 + getConsPercGaps() + "% gaps", new Annotation[1],
1434 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1435 conservation.hasText = true;
1436 conservation.autoCalculated = true;
1437 alignment.addAnnotation(conservation);
1442 private void initQuality()
1446 if (quality == null)
1448 quality = new AlignmentAnnotation("Quality",
1449 "Alignment Quality based on Blosum62 scores",
1450 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1451 quality.hasText = true;
1452 quality.autoCalculated = true;
1453 alignment.addAnnotation(quality);
1458 private void initRNAStructure()
1460 if (alignment.hasRNAStructure() && strucConsensus == null)
1462 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1463 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1464 strucConsensus.hasText = true;
1465 strucConsensus.autoCalculated = true;
1469 alignment.addAnnotation(strucConsensus);
1477 * @see jalview.api.AlignViewportI#calcPanelHeight()
1479 public int calcPanelHeight()
1481 // setHeight of panels
1482 AlignmentAnnotation[] aa = getAlignment().getAlignmentAnnotation();
1484 int charHeight = getCharHeight();
1487 BitSet graphgrp = new BitSet();
1488 for (int i = 0; i < aa.length; i++)
1492 System.err.println("Null annotation row: ignoring.");
1499 if (aa[i].graphGroup > -1)
1501 if (graphgrp.get(aa[i].graphGroup))
1507 graphgrp.set(aa[i].graphGroup);
1514 aa[i].height += charHeight;
1522 if (aa[i].graph > 0)
1524 aa[i].height += aa[i].graphHeight;
1527 if (aa[i].height == 0)
1532 height += aa[i].height;
1544 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1545 boolean preserveNewGroupSettings)
1547 boolean updateCalcs = false;
1548 boolean conv = isShowGroupConservation();
1549 boolean cons = isShowGroupConsensus();
1550 boolean showprf = isShowSequenceLogo();
1551 boolean showConsHist = isShowConsensusHistogram();
1552 boolean normLogo = isNormaliseSequenceLogo();
1555 * TODO reorder the annotation rows according to group/sequence ordering on
1558 boolean sortg = true;
1560 // remove old automatic annotation
1561 // add any new annotation
1563 // intersect alignment annotation with alignment groups
1565 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
1566 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
1569 for (int an = 0; an < aan.length; an++)
1571 if (aan[an].autoCalculated && aan[an].groupRef != null)
1573 oldrfs.add(aan[an].groupRef);
1574 alignment.deleteAnnotation(aan[an], false);
1578 if (alignment.getGroups() != null)
1580 for (SequenceGroup sg : alignment.getGroups())
1582 updateCalcs = false;
1583 if (applyGlobalSettings
1584 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
1586 // set defaults for this group's conservation/consensus
1587 sg.setshowSequenceLogo(showprf);
1588 sg.setShowConsensusHistogram(showConsHist);
1589 sg.setNormaliseSequenceLogo(normLogo);
1594 alignment.addAnnotation(sg.getConservationRow(), 0);
1599 alignment.addAnnotation(sg.getConsensus(), 0);
1601 // refresh the annotation rows
1604 sg.recalcConservation();
1612 public Color getSequenceColour(SequenceI seq)
1614 Color sqc = sequenceColours.get(seq);
1615 return (sqc == null ? Color.white : sqc);
1619 public void setSequenceColour(SequenceI seq, Color col)
1623 sequenceColours.remove(seq);
1627 sequenceColours.put(seq, col);
1632 public void updateSequenceIdColours()
1634 for (SequenceGroup sg : alignment.getGroups())
1636 if (sg.idColour != null)
1638 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
1640 sequenceColours.put(s, sg.idColour);
1647 public void clearSequenceColours()
1649 sequenceColours.clear();
1653 public AlignViewportI getSlave()
1659 public void setSlave(AlignViewportI sl)
1661 if (this == sl.getSlave())
1663 System.err.println("Ignoring recursive setSlave request");