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.api.FeaturesDisplayedI;
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.ColourSchemeI;
39 import jalview.schemes.PIDColourScheme;
40 import jalview.schemes.ResidueProperties;
41 import jalview.workers.AlignCalcManager;
42 import jalview.workers.ConsensusThread;
43 import jalview.workers.StrucConsensusThread;
45 import java.awt.Color;
46 import java.util.ArrayList;
47 import java.util.BitSet;
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 * alignment displayed in the viewport. Please use get/setter
65 protected AlignmentI alignment;
67 protected String sequenceSetID;
70 * probably unused indicator that view is of a dataset rather than an
73 protected boolean isDataset = false;
75 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
77 protected ColumnSelection colSel = new ColumnSelection();
79 public boolean autoCalculateConsensus = true;
81 protected boolean autoCalculateStrucConsensus = true;
83 protected boolean ignoreGapsInConsensusCalculation = false;
85 protected ColourSchemeI globalColourScheme = null;
88 * gui state - changes to colour scheme propagated to all groups
90 private boolean colourAppliesToAllGroups;
94 * indicating if subsequent colourscheme changes will be propagated
97 public void setColourAppliesToAllGroups(boolean b)
99 colourAppliesToAllGroups = b;
105 * @return flag indicating if colourchanges propagated to all groups
107 public boolean getColourAppliesToAllGroups()
109 return colourAppliesToAllGroups;
112 boolean abovePIDThreshold = false;
117 * @return true if percent identity threshold is applied to shading
119 public boolean getAbovePIDThreshold()
121 return abovePIDThreshold;
129 * indicate if percent identity threshold is applied to shading
131 public void setAbovePIDThreshold(boolean b)
133 abovePIDThreshold = b;
144 public void setThreshold(int thresh)
152 * @return DOCUMENT ME!
154 public int getThreshold()
164 * set the scalar for bleaching colourschemes according to degree of
167 public void setIncrement(int inc)
175 * @return get scalar for bleaching colourschemes by conservation
177 public int getIncrement()
182 boolean conservationColourSelected = false;
187 * @return true if conservation based shading is enabled
189 public boolean getConservationSelected()
191 return conservationColourSelected;
198 * enable conservation based shading
200 public void setConservationSelected(boolean b)
202 conservationColourSelected = b;
206 public void setGlobalColourScheme(ColourSchemeI cs)
208 // TODO: logic refactored from AlignFrame changeColour -
209 // autorecalc stuff should be changed to rely on the worker system
210 // check to see if we should implement a changeColour(cs) method rather than
211 // put th logic in here
212 // - means that caller decides if they want to just modify state and defer
213 // calculation till later or to do all calculations in thread.
215 globalColourScheme = cs;
216 boolean recalc = false;
219 cs.setConservationApplied(recalc = getConservationSelected());
220 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
221 || cs instanceof Blosum62ColourScheme)
224 cs.setThreshold(threshold, ignoreGapsInConsensusCalculation);
228 cs.setThreshold(0, ignoreGapsInConsensusCalculation);
232 cs.setConsensus(hconsensus);
233 cs.setConservation(hconservation);
235 cs.alignmentChanged(alignment, hiddenRepSequences);
237 if (getColourAppliesToAllGroups())
239 for (SequenceGroup sg : getAlignment().getGroups())
246 sg.cs = cs.applyTo(sg, getHiddenRepSequences());
247 sg.setConsPercGaps(ConsPercGaps);
248 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
249 || cs instanceof Blosum62ColourScheme)
251 sg.cs.setThreshold(threshold, getIgnoreGapsConsensus());
256 sg.cs.setThreshold(0, getIgnoreGapsConsensus());
259 if (getConservationSelected())
261 sg.cs.setConservationApplied(true);
266 sg.cs.setConservation(null);
267 // sg.cs.setThreshold(0, getIgnoreGapsConsensus());
271 sg.recalcConservation();
275 sg.cs.alignmentChanged(sg, hiddenRepSequences);
283 public ColourSchemeI getGlobalColourScheme()
285 return globalColourScheme;
288 protected AlignmentAnnotation consensus;
290 protected AlignmentAnnotation strucConsensus;
292 protected AlignmentAnnotation conservation;
294 protected AlignmentAnnotation quality;
296 protected AlignmentAnnotation[] groupConsensus;
298 protected AlignmentAnnotation[] groupConservation;
301 * results of alignment consensus analysis for visible portion of view
303 protected Hashtable[] hconsensus = null;
306 * results of secondary structure base pair consensus for visible portion of
309 protected Hashtable[] hStrucConsensus = null;
311 protected Conservation hconservation = null;
314 public void setConservation(Conservation cons)
316 hconservation = cons;
320 * percentage gaps allowed in a column before all amino acid properties should
321 * be considered unconserved
323 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
326 public int getConsPercGaps()
332 public void setSequenceConsensusHash(Hashtable[] hconsensus)
334 this.hconsensus = hconsensus;
339 public Hashtable[] getSequenceConsensusHash()
345 public Hashtable[] getRnaStructureConsensusHash()
347 return hStrucConsensus;
351 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
353 this.hStrucConsensus = hStrucConsensus;
358 public AlignmentAnnotation getAlignmentQualityAnnot()
364 public AlignmentAnnotation getAlignmentConservationAnnotation()
370 public AlignmentAnnotation getAlignmentConsensusAnnotation()
376 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
378 return strucConsensus;
381 protected AlignCalcManagerI calculator = new AlignCalcManager();
384 * trigger update of conservation annotation
386 public void updateConservation(final AlignmentViewPanel ap)
388 // see note in mantis : issue number 8585
389 if (alignment.isNucleotide() || conservation == null
390 || !autoCalculateConsensus)
395 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
397 calculator.registerWorker(new jalview.workers.ConservationThread(
403 * trigger update of consensus annotation
405 public void updateConsensus(final AlignmentViewPanel ap)
407 // see note in mantis : issue number 8585
408 if (consensus == null || !autoCalculateConsensus)
412 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
414 calculator.registerWorker(new ConsensusThread(this, ap));
418 // --------START Structure Conservation
419 public void updateStrucConsensus(final AlignmentViewPanel ap)
421 if (autoCalculateStrucConsensus && strucConsensus == null
422 && alignment.isNucleotide() && alignment.hasRNAStructure())
424 // secondary structure has been added - so init the consensus line
428 // see note in mantis : issue number 8585
429 if (strucConsensus == null || !autoCalculateStrucConsensus)
433 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
435 calculator.registerWorker(new StrucConsensusThread(this, ap));
439 public boolean isCalcInProgress()
441 return calculator.isWorking();
445 public boolean isCalculationInProgress(
446 AlignmentAnnotation alignmentAnnotation)
448 if (!alignmentAnnotation.autoCalculated)
452 if (calculator.workingInvolvedWith(alignmentAnnotation))
454 // System.err.println("grey out ("+alignmentAnnotation.label+")");
461 public boolean isClosed()
463 // TODO: check that this isClosed is only true after panel is closed, not
464 // before it is fully constructed.
465 return alignment == null;
469 public AlignCalcManagerI getCalcManager()
475 * should conservation rows be shown for groups
477 protected boolean showGroupConservation = false;
480 * should consensus rows be shown for groups
482 protected boolean showGroupConsensus = false;
485 * should consensus profile be rendered by default
487 protected boolean showSequenceLogo = false;
490 * should consensus profile be rendered normalised to row height
492 protected boolean normaliseSequenceLogo = false;
495 * should consensus histograms be rendered by default
497 protected boolean showConsensusHistogram = true;
500 * @return the showConsensusProfile
503 public boolean isShowSequenceLogo()
505 return showSequenceLogo;
509 * @param showSequenceLogo
512 public void setShowSequenceLogo(boolean showSequenceLogo)
514 if (showSequenceLogo != this.showSequenceLogo)
516 // TODO: decouple settings setting from calculation when refactoring
517 // annotation update method from alignframe to viewport
518 this.showSequenceLogo = showSequenceLogo;
519 calculator.updateAnnotationFor(ConsensusThread.class);
520 calculator.updateAnnotationFor(StrucConsensusThread.class);
522 this.showSequenceLogo = showSequenceLogo;
526 * @param showConsensusHistogram
527 * the showConsensusHistogram to set
529 public void setShowConsensusHistogram(boolean showConsensusHistogram)
531 this.showConsensusHistogram = showConsensusHistogram;
535 * @return the showGroupConservation
537 public boolean isShowGroupConservation()
539 return showGroupConservation;
543 * @param showGroupConservation
544 * the showGroupConservation to set
546 public void setShowGroupConservation(boolean showGroupConservation)
548 this.showGroupConservation = showGroupConservation;
552 * @return the showGroupConsensus
554 public boolean isShowGroupConsensus()
556 return showGroupConsensus;
560 * @param showGroupConsensus
561 * the showGroupConsensus to set
563 public void setShowGroupConsensus(boolean showGroupConsensus)
565 this.showGroupConsensus = showGroupConsensus;
570 * @return flag to indicate if the consensus histogram should be rendered by
574 public boolean isShowConsensusHistogram()
576 return this.showConsensusHistogram;
580 * show non-conserved residues only
582 protected boolean showUnconserved = false;
585 * when set, updateAlignment will always ensure sequences are of equal length
587 private boolean padGaps = false;
590 * when set, alignment should be reordered according to a newly opened tree
592 public boolean sortByTree = false;
594 public boolean getShowUnconserved()
596 return showUnconserved;
599 public void setShowUnconserved(boolean showunconserved)
601 showUnconserved = showunconserved;
605 * @param showNonconserved
606 * the showUnconserved to set
608 public void setShowunconserved(boolean displayNonconserved)
610 this.showUnconserved = displayNonconserved;
616 * @return null or the currently selected sequence region
619 public SequenceGroup getSelectionGroup()
621 return selectionGroup;
625 * Set the selection group for this window.
628 * - group holding references to sequences in this alignment view
632 public void setSelectionGroup(SequenceGroup sg)
637 public void setHiddenColumns(ColumnSelection colsel)
639 this.colSel = colsel;
640 if (colSel.getHiddenColumns() != null)
642 hasHiddenColumns = true;
647 public ColumnSelection getColumnSelection()
652 public void setColumnSelection(ColumnSelection colSel)
654 this.colSel = colSel;
662 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
664 return hiddenRepSequences;
668 public void setHiddenRepSequences(
669 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
671 this.hiddenRepSequences = hiddenRepSequences;
674 protected boolean hasHiddenColumns = false;
676 public void updateHiddenColumns()
678 hasHiddenColumns = colSel.getHiddenColumns() != null;
681 protected boolean hasHiddenRows = false;
683 public boolean hasHiddenRows()
685 return hasHiddenRows;
688 protected SequenceGroup selectionGroup;
690 public void setSequenceSetId(String newid)
692 if (sequenceSetID != null)
695 .println("Warning - overwriting a sequenceSetId for a viewport!");
697 sequenceSetID = new String(newid);
701 public String getSequenceSetId()
703 if (sequenceSetID == null)
705 sequenceSetID = alignment.hashCode() + "";
708 return sequenceSetID;
712 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
715 protected String viewId = null;
717 public String getViewId()
721 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
726 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
728 ignoreGapsInConsensusCalculation = b;
732 if (globalColourScheme != null)
734 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
735 ignoreGapsInConsensusCalculation);
741 private long sgrouphash = -1, colselhash = -1;
744 * checks current SelectionGroup against record of last hash value, and
748 * update the record of last hash value
750 * @return true if SelectionGroup changed since last call (when b is true)
752 public boolean isSelectionGroupChanged(boolean b)
754 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
755 : selectionGroup.hashCode();
756 if (hc != -1 && hc != sgrouphash)
768 * checks current colsel against record of last hash value, and optionally
772 * update the record of last hash value
773 * @return true if colsel changed since last call (when b is true)
775 public boolean isColSelChanged(boolean b)
777 int hc = (colSel == null || colSel.size() == 0) ? -1 : colSel
779 if (hc != -1 && hc != colselhash)
791 public boolean getIgnoreGapsConsensus()
793 return ignoreGapsInConsensusCalculation;
796 // / property change stuff
798 // JBPNote Prolly only need this in the applet version.
799 private final java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
802 protected boolean showConservation = true;
804 protected boolean showQuality = true;
806 protected boolean showConsensus = true;
808 Hashtable sequenceColours;
811 * Property change listener for changes in alignment
816 public void addPropertyChangeListener(
817 java.beans.PropertyChangeListener listener)
819 changeSupport.addPropertyChangeListener(listener);
828 public void removePropertyChangeListener(
829 java.beans.PropertyChangeListener listener)
831 changeSupport.removePropertyChangeListener(listener);
835 * Property change listener for changes in alignment
844 public void firePropertyChange(String prop, Object oldvalue,
847 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
850 // common hide/show column stuff
852 public void hideSelectedColumns()
854 if (colSel.size() < 1)
859 colSel.hideSelectedColumns();
860 setSelectionGroup(null);
862 hasHiddenColumns = true;
865 public void hideColumns(int start, int end)
869 colSel.hideColumns(start);
873 colSel.hideColumns(start, end);
876 hasHiddenColumns = true;
879 public void showColumn(int col)
881 colSel.revealHiddenColumns(col);
882 if (colSel.getHiddenColumns() == null)
884 hasHiddenColumns = false;
888 public void showAllHiddenColumns()
890 colSel.revealAllHiddenColumns();
891 hasHiddenColumns = false;
894 // common hide/show seq stuff
895 public void showAllHiddenSeqs()
897 if (alignment.getHiddenSequences().getSize() > 0)
899 if (selectionGroup == null)
901 selectionGroup = new SequenceGroup();
902 selectionGroup.setEndRes(alignment.getWidth() - 1);
904 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
906 for (SequenceI seq : tmp)
908 selectionGroup.addSequence(seq, false);
909 setSequenceAnnotationsVisible(seq, true);
912 hasHiddenRows = false;
913 hiddenRepSequences = null;
915 firePropertyChange("alignment", null, alignment.getSequences());
916 // used to set hasHiddenRows/hiddenRepSequences here, after the property
922 public void showSequence(int index)
924 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
929 if (selectionGroup == null)
931 selectionGroup = new SequenceGroup();
932 selectionGroup.setEndRes(alignment.getWidth() - 1);
935 for (SequenceI seq : tmp)
937 selectionGroup.addSequence(seq, false);
938 setSequenceAnnotationsVisible(seq, true);
940 // JBPNote: refactor: only update flag if we modified visiblity (used to
941 // do this regardless)
942 if (alignment.getHiddenSequences().getSize() < 1)
944 hasHiddenRows = false;
946 firePropertyChange("alignment", null, alignment.getSequences());
951 public void hideAllSelectedSeqs()
953 if (selectionGroup == null || selectionGroup.getSize() < 1)
958 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
962 setSelectionGroup(null);
965 public void hideSequence(SequenceI[] seq)
969 for (int i = 0; i < seq.length; i++)
971 alignment.getHiddenSequences().hideSequence(seq[i]);
972 setSequenceAnnotationsVisible(seq[i], false);
974 hasHiddenRows = true;
975 firePropertyChange("alignment", null, alignment.getSequences());
980 * Set visibility for any annotations for the given sequence.
984 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
987 for (AlignmentAnnotation ann : alignment.getAlignmentAnnotation())
989 if (ann.sequenceRef == sequenceI)
991 ann.visible = visible;
996 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
998 int sSize = sg.getSize();
1004 if (hiddenRepSequences == null)
1006 hiddenRepSequences = new Hashtable();
1009 hiddenRepSequences.put(repSequence, sg);
1011 // Hide all sequences except the repSequence
1012 SequenceI[] seqs = new SequenceI[sSize - 1];
1014 for (int i = 0; i < sSize; i++)
1016 if (sg.getSequenceAt(i) != repSequence)
1018 if (index == sSize - 1)
1023 seqs[index++] = sg.getSequenceAt(i);
1026 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1027 sg.setHidereps(true); // note: not done in 2.7applet
1032 public boolean isHiddenRepSequence(SequenceI seq)
1034 return hiddenRepSequences != null
1035 && hiddenRepSequences.containsKey(seq);
1038 public SequenceGroup getRepresentedSequences(SequenceI seq)
1040 return (SequenceGroup) (hiddenRepSequences == null ? null
1041 : hiddenRepSequences.get(seq));
1044 public int adjustForHiddenSeqs(int alignmentIndex)
1046 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1050 // Selection manipulation
1052 * broadcast selection to any interested parties
1054 public abstract void sendSelection();
1056 public void invertColumnSelection()
1058 colSel.invertColumnSelection(0, alignment.getWidth());
1062 * This method returns an array of new SequenceI objects derived from the
1063 * whole alignment or just the current selection with start and end points
1066 * @note if you need references to the actual SequenceI objects in the
1067 * alignment or currently selected then use getSequenceSelection()
1068 * @return selection as new sequenceI objects
1070 public SequenceI[] getSelectionAsNewSequence()
1072 SequenceI[] sequences;
1073 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1074 // this was the only caller in the applet for this method
1075 // JBPNote: in applet, this method returned references to the alignment
1076 // sequences, and it did not honour the presence/absence of annotation
1077 // attached to the alignment (probably!)
1078 if (selectionGroup == null || selectionGroup.getSize() == 0)
1080 sequences = alignment.getSequencesArray();
1081 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1082 for (int i = 0; i < sequences.length; i++)
1084 sequences[i] = new Sequence(sequences[i], annots); // construct new
1086 // subset of visible
1092 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1099 * get the currently selected sequence objects or all the sequences in the
1102 * @return array of references to sequence objects
1105 public SequenceI[] getSequenceSelection()
1107 SequenceI[] sequences = null;
1108 if (selectionGroup != null)
1110 sequences = selectionGroup.getSequencesInOrder(alignment);
1112 if (sequences == null)
1114 sequences = alignment.getSequencesArray();
1120 * This method returns the visible alignment as text, as seen on the GUI, ie
1121 * if columns are hidden they will not be returned in the result. Use this for
1122 * calculating trees, PCA, redundancy etc on views which contain hidden
1128 public jalview.datamodel.CigarArray getViewAsCigars(
1129 boolean selectedRegionOnly)
1131 return new jalview.datamodel.CigarArray(alignment,
1132 (hasHiddenColumns ? colSel : null),
1133 (selectedRegionOnly ? selectionGroup : null));
1137 * return a compact representation of the current alignment selection to pass
1138 * to an analysis function
1140 * @param selectedOnly
1141 * boolean true to just return the selected view
1142 * @return AlignmentView
1145 public jalview.datamodel.AlignmentView getAlignmentView(
1146 boolean selectedOnly)
1148 return getAlignmentView(selectedOnly, false);
1152 * return a compact representation of the current alignment selection to pass
1153 * to an analysis function
1155 * @param selectedOnly
1156 * boolean true to just return the selected view
1158 * boolean true to annotate the alignment view with groups on the
1159 * alignment (and intersecting with selected region if selectedOnly
1161 * @return AlignmentView
1164 public jalview.datamodel.AlignmentView getAlignmentView(
1165 boolean selectedOnly, boolean markGroups)
1167 return new AlignmentView(alignment, colSel, selectionGroup,
1168 hasHiddenColumns, selectedOnly, markGroups);
1172 * This method returns the visible alignment as text, as seen on the GUI, ie
1173 * if columns are hidden they will not be returned in the result. Use this for
1174 * calculating trees, PCA, redundancy etc on views which contain hidden
1180 public String[] getViewAsString(boolean selectedRegionOnly)
1182 String[] selection = null;
1183 SequenceI[] seqs = null;
1185 int start = 0, end = 0;
1186 if (selectedRegionOnly && selectionGroup != null)
1188 iSize = selectionGroup.getSize();
1189 seqs = selectionGroup.getSequencesInOrder(alignment);
1190 start = selectionGroup.getStartRes();
1191 end = selectionGroup.getEndRes() + 1;
1195 iSize = alignment.getHeight();
1196 seqs = alignment.getSequencesArray();
1197 end = alignment.getWidth();
1200 selection = new String[iSize];
1201 if (hasHiddenColumns)
1203 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1207 for (i = 0; i < iSize; i++)
1209 selection[i] = seqs[i].getSequenceAsString(start, end);
1217 * return visible region boundaries within given column range
1220 * first column (inclusive, from 0)
1222 * last column (exclusive)
1223 * @return int[][] range of {start,end} visible positions
1225 public int[][] getVisibleRegionBoundaries(int min, int max)
1227 Vector regions = new Vector();
1233 if (hasHiddenColumns)
1237 start = colSel.adjustForHiddenColumns(start);
1240 end = colSel.getHiddenBoundaryRight(start);
1251 regions.addElement(new int[]
1254 if (hasHiddenColumns)
1256 start = colSel.adjustForHiddenColumns(end);
1257 start = colSel.getHiddenBoundaryLeft(start) + 1;
1259 } while (end < max);
1261 int[][] startEnd = new int[regions.size()][2];
1263 regions.copyInto(startEnd);
1270 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(boolean selectedOnly)
1272 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1273 AlignmentAnnotation[] aa;
1274 if ((aa=alignment.getAlignmentAnnotation())!=null)
1276 for (AlignmentAnnotation annot:aa)
1278 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1279 if (selectedOnly && selectionGroup!=null)
1281 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(), selectionGroup.getEndRes(),clone);
1283 colSel.makeVisibleAnnotation(clone);
1292 * @return the padGaps
1294 public boolean isPadGaps()
1301 * the padGaps to set
1303 public void setPadGaps(boolean padGaps)
1305 this.padGaps = padGaps;
1309 * apply any post-edit constraints and trigger any calculations needed after
1310 * an edit has been performed on the alignment
1314 public void alignmentChanged(AlignmentViewPanel ap)
1318 alignment.padGaps();
1320 if (autoCalculateConsensus)
1322 updateConsensus(ap);
1324 if (hconsensus != null && autoCalculateConsensus)
1326 updateConservation(ap);
1328 if (autoCalculateStrucConsensus)
1330 updateStrucConsensus(ap);
1333 // Reset endRes of groups if beyond alignment width
1334 int alWidth = alignment.getWidth();
1335 List<SequenceGroup> groups = alignment.getGroups();
1338 for (SequenceGroup sg : groups)
1340 if (sg.getEndRes() > alWidth)
1342 sg.setEndRes(alWidth - 1);
1347 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1349 selectionGroup.setEndRes(alWidth - 1);
1352 resetAllColourSchemes();
1353 calculator.restartWorkers();
1354 // alignment.adjustSequenceAnnotations();
1358 * reset scope and do calculations for all applied colourschemes on alignment
1360 void resetAllColourSchemes()
1362 ColourSchemeI cs = globalColourScheme;
1365 cs.alignmentChanged(alignment, hiddenRepSequences);
1367 cs.setConsensus(hconsensus);
1368 if (cs.conservationApplied())
1370 cs.setConservation(Conservation.calculateConservation("All",
1371 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1372 alignment.getWidth(), false, getConsPercGaps(), false));
1376 for (SequenceGroup sg : alignment.getGroups())
1380 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1382 sg.recalcConservation();
1386 protected void initAutoAnnotation()
1388 // TODO: add menu option action that nulls or creates consensus object
1389 // depending on if the user wants to see the annotation or not in a
1390 // specific alignment
1392 if (hconsensus == null && !isDataset)
1394 if (!alignment.isNucleotide())
1407 private void initConsensus()
1410 consensus = new AlignmentAnnotation("Consensus", "PID",
1411 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1412 consensus.hasText = true;
1413 consensus.autoCalculated = true;
1417 alignment.addAnnotation(consensus);
1421 private void initConservation()
1423 if (showConservation)
1425 if (conservation == null)
1427 conservation = new AlignmentAnnotation("Conservation",
1428 "Conservation of total alignment less than "
1429 + getConsPercGaps() + "% gaps", new Annotation[1],
1430 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1431 conservation.hasText = true;
1432 conservation.autoCalculated = true;
1433 alignment.addAnnotation(conservation);
1438 private void initQuality()
1442 if (quality == null)
1444 quality = new AlignmentAnnotation("Quality",
1445 "Alignment Quality based on Blosum62 scores",
1446 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1447 quality.hasText = true;
1448 quality.autoCalculated = true;
1449 alignment.addAnnotation(quality);
1454 private void initRNAStructure()
1456 if (alignment.hasRNAStructure() && strucConsensus == null)
1458 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1459 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1460 strucConsensus.hasText = true;
1461 strucConsensus.autoCalculated = true;
1465 alignment.addAnnotation(strucConsensus);
1473 * @see jalview.api.AlignViewportI#calcPanelHeight()
1475 public int calcPanelHeight()
1477 // setHeight of panels
1478 AlignmentAnnotation[] aa = getAlignment().getAlignmentAnnotation();
1480 int charHeight = getCharHeight();
1483 BitSet graphgrp = new BitSet();
1484 for (int i = 0; i < aa.length; i++)
1488 System.err.println("Null annotation row: ignoring.");
1495 if (aa[i].graphGroup > -1)
1497 if (graphgrp.get(aa[i].graphGroup))
1503 graphgrp.set(aa[i].graphGroup);
1510 aa[i].height += charHeight;
1518 if (aa[i].graph > 0)
1520 aa[i].height += aa[i].graphHeight;
1523 if (aa[i].height == 0)
1528 height += aa[i].height;
1540 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1541 boolean preserveNewGroupSettings)
1543 boolean updateCalcs = false;
1544 boolean conv = isShowGroupConservation();
1545 boolean cons = isShowGroupConsensus();
1546 boolean showprf = isShowSequenceLogo();
1547 boolean showConsHist = isShowConsensusHistogram();
1548 boolean normLogo = isNormaliseSequenceLogo();
1551 * TODO reorder the annotation rows according to group/sequence ordering on
1554 boolean sortg = true;
1556 // remove old automatic annotation
1557 // add any new annotation
1559 // intersect alignment annotation with alignment groups
1561 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
1562 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
1565 for (int an = 0; an < aan.length; an++)
1567 if (aan[an].autoCalculated && aan[an].groupRef != null)
1569 oldrfs.add(aan[an].groupRef);
1570 alignment.deleteAnnotation(aan[an], false);
1574 if (alignment.getGroups() != null)
1576 for (SequenceGroup sg : alignment.getGroups())
1578 updateCalcs = false;
1579 if (applyGlobalSettings
1580 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
1582 // set defaults for this group's conservation/consensus
1583 sg.setshowSequenceLogo(showprf);
1584 sg.setShowConsensusHistogram(showConsHist);
1585 sg.setNormaliseSequenceLogo(normLogo);
1590 alignment.addAnnotation(sg.getConservationRow(), 0);
1595 alignment.addAnnotation(sg.getConsensus(), 0);
1597 // refresh the annotation rows
1600 sg.recalcConservation();
1608 public Color getSequenceColour(SequenceI seq)
1610 Color sqc = Color.white;
1611 if (sequenceColours != null)
1613 sqc = (Color) sequenceColours.get(seq);
1623 public void setSequenceColour(SequenceI seq, Color col)
1625 if (sequenceColours == null)
1627 sequenceColours = new Hashtable();
1632 sequenceColours.remove(seq);
1636 sequenceColours.put(seq, col);
1641 public void updateSequenceIdColours()
1643 if (sequenceColours == null)
1645 sequenceColours = new Hashtable();
1647 for (SequenceGroup sg : alignment.getGroups())
1649 if (sg.idColour != null)
1651 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
1653 sequenceColours.put(s, sg.idColour);
1660 public void clearSequenceColours()
1662 sequenceColours = null;
1665 FeaturesDisplayedI featuresDisplayed = null;
1668 public FeaturesDisplayedI getFeaturesDisplayed()
1670 return featuresDisplayed;
1673 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
1675 featuresDisplayed = featuresDisplayedI;
1678 public boolean areFeaturesDisplayed()
1680 return featuresDisplayed != null && featuresDisplayed.getRegisterdFeaturesCount()>0;
1684 * display setting for showing/hiding sequence features on alignment view
1686 boolean showSequenceFeatures = false;
1692 * features are displayed if true
1695 public void setShowSequenceFeatures(boolean b)
1697 showSequenceFeatures = b;
1700 public boolean isShowSequenceFeatures()
1702 return showSequenceFeatures;
1705 boolean showSeqFeaturesHeight;
1707 public void setShowSequenceFeaturesHeight(boolean selected)
1709 showSeqFeaturesHeight = selected;
1712 public boolean isShowSequenceFeaturesHeight()
1714 return showSeqFeaturesHeight;
1717 private boolean showAnnotation = true;
1719 private boolean rightAlignIds = false;
1724 * @return DOCUMENT ME!
1726 public boolean getShowAnnotation()
1728 return isShowAnnotation();
1737 public void setShowAnnotation(boolean b)
1742 public boolean isShowAnnotation()
1744 return showAnnotation;
1747 public boolean isRightAlignIds()
1749 return rightAlignIds;
1752 public void setRightAlignIds(boolean rightAlignIds)
1754 this.rightAlignIds = rightAlignIds;