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()
653 public void setColumnSelection(ColumnSelection colSel)
655 this.colSel = colSel;
658 updateHiddenColumns();
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.hasHiddenColumns();
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);
706 public String getSequenceSetId()
708 if (sequenceSetID == null)
710 sequenceSetID = alignment.hashCode() + "";
713 return sequenceSetID;
717 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
720 protected String viewId = null;
722 public String getViewId()
726 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
731 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
733 ignoreGapsInConsensusCalculation = b;
737 if (globalColourScheme != null)
739 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
740 ignoreGapsInConsensusCalculation);
746 private long sgrouphash = -1, colselhash = -1;
749 * checks current SelectionGroup against record of last hash value, and
753 * update the record of last hash value
755 * @return true if SelectionGroup changed since last call (when b is true)
757 public boolean isSelectionGroupChanged(boolean b)
759 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
760 : selectionGroup.hashCode();
761 if (hc != -1 && hc != sgrouphash)
773 * checks current colsel against record of last hash value, and optionally
777 * update the record of last hash value
778 * @return true if colsel changed since last call (when b is true)
780 public boolean isColSelChanged(boolean b)
782 int hc = (colSel == null || colSel.size() == 0) ? -1 : colSel
784 if (hc != -1 && hc != colselhash)
796 public boolean getIgnoreGapsConsensus()
798 return ignoreGapsInConsensusCalculation;
801 // / property change stuff
803 // JBPNote Prolly only need this in the applet version.
804 private final java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
807 protected boolean showConservation = true;
809 protected boolean showQuality = true;
811 protected boolean showConsensus = true;
813 Hashtable sequenceColours;
816 * Property change listener for changes in alignment
821 public void addPropertyChangeListener(
822 java.beans.PropertyChangeListener listener)
824 changeSupport.addPropertyChangeListener(listener);
833 public void removePropertyChangeListener(
834 java.beans.PropertyChangeListener listener)
836 changeSupport.removePropertyChangeListener(listener);
840 * Property change listener for changes in alignment
849 public void firePropertyChange(String prop, Object oldvalue,
852 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
855 // common hide/show column stuff
857 public void hideSelectedColumns()
859 if (colSel.size() < 1)
864 colSel.hideSelectedColumns();
865 setSelectionGroup(null);
867 hasHiddenColumns = true;
870 public void hideColumns(int start, int end)
874 colSel.hideColumns(start);
878 colSel.hideColumns(start, end);
881 hasHiddenColumns = true;
884 public void showColumn(int col)
886 colSel.revealHiddenColumns(col);
887 if (colSel.getHiddenColumns() == null)
889 hasHiddenColumns = false;
893 public void showAllHiddenColumns()
895 colSel.revealAllHiddenColumns();
896 hasHiddenColumns = false;
899 // common hide/show seq stuff
900 public void showAllHiddenSeqs()
902 if (alignment.getHiddenSequences().getSize() > 0)
904 if (selectionGroup == null)
906 selectionGroup = new SequenceGroup();
907 selectionGroup.setEndRes(alignment.getWidth() - 1);
909 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
911 for (SequenceI seq : tmp)
913 selectionGroup.addSequence(seq, false);
914 setSequenceAnnotationsVisible(seq, true);
917 hasHiddenRows = false;
918 hiddenRepSequences = null;
920 firePropertyChange("alignment", null, alignment.getSequences());
921 // used to set hasHiddenRows/hiddenRepSequences here, after the property
927 public void showSequence(int index)
929 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
934 if (selectionGroup == null)
936 selectionGroup = new SequenceGroup();
937 selectionGroup.setEndRes(alignment.getWidth() - 1);
940 for (SequenceI seq : tmp)
942 selectionGroup.addSequence(seq, false);
943 setSequenceAnnotationsVisible(seq, true);
945 // JBPNote: refactor: only update flag if we modified visiblity (used to
946 // do this regardless)
947 if (alignment.getHiddenSequences().getSize() < 1)
949 hasHiddenRows = false;
951 firePropertyChange("alignment", null, alignment.getSequences());
956 public void hideAllSelectedSeqs()
958 if (selectionGroup == null || selectionGroup.getSize() < 1)
963 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
967 setSelectionGroup(null);
970 public void hideSequence(SequenceI[] seq)
974 for (int i = 0; i < seq.length; i++)
976 alignment.getHiddenSequences().hideSequence(seq[i]);
977 setSequenceAnnotationsVisible(seq[i], false);
979 hasHiddenRows = true;
980 firePropertyChange("alignment", null, alignment.getSequences());
985 * Set visibility for any annotations for the given sequence.
989 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
992 for (AlignmentAnnotation ann : alignment.getAlignmentAnnotation())
994 if (ann.sequenceRef == sequenceI)
996 ann.visible = visible;
1001 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1003 int sSize = sg.getSize();
1009 if (hiddenRepSequences == null)
1011 hiddenRepSequences = new Hashtable();
1014 hiddenRepSequences.put(repSequence, sg);
1016 // Hide all sequences except the repSequence
1017 SequenceI[] seqs = new SequenceI[sSize - 1];
1019 for (int i = 0; i < sSize; i++)
1021 if (sg.getSequenceAt(i) != repSequence)
1023 if (index == sSize - 1)
1028 seqs[index++] = sg.getSequenceAt(i);
1031 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1032 sg.setHidereps(true); // note: not done in 2.7applet
1037 public boolean isHiddenRepSequence(SequenceI seq)
1039 return alignment.getSeqrep()==seq || (hiddenRepSequences != null
1040 && hiddenRepSequences.containsKey(seq));
1043 public SequenceGroup getRepresentedSequences(SequenceI seq)
1045 return (SequenceGroup) (hiddenRepSequences == null ? null
1046 : hiddenRepSequences.get(seq));
1049 public int adjustForHiddenSeqs(int alignmentIndex)
1051 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1055 // Selection manipulation
1057 * broadcast selection to any interested parties
1059 public abstract void sendSelection();
1061 public void invertColumnSelection()
1063 colSel.invertColumnSelection(0, alignment.getWidth());
1067 * This method returns an array of new SequenceI objects derived from the
1068 * whole alignment or just the current selection with start and end points
1071 * @note if you need references to the actual SequenceI objects in the
1072 * alignment or currently selected then use getSequenceSelection()
1073 * @return selection as new sequenceI objects
1075 public SequenceI[] getSelectionAsNewSequence()
1077 SequenceI[] sequences;
1078 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1079 // this was the only caller in the applet for this method
1080 // JBPNote: in applet, this method returned references to the alignment
1081 // sequences, and it did not honour the presence/absence of annotation
1082 // attached to the alignment (probably!)
1083 if (selectionGroup == null || selectionGroup.getSize() == 0)
1085 sequences = alignment.getSequencesArray();
1086 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1087 for (int i = 0; i < sequences.length; i++)
1089 sequences[i] = new Sequence(sequences[i], annots); // construct new
1091 // subset of visible
1097 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1104 * get the currently selected sequence objects or all the sequences in the
1107 * @return array of references to sequence objects
1110 public SequenceI[] getSequenceSelection()
1112 SequenceI[] sequences = null;
1113 if (selectionGroup != null)
1115 sequences = selectionGroup.getSequencesInOrder(alignment);
1117 if (sequences == null)
1119 sequences = alignment.getSequencesArray();
1125 * This method returns the visible alignment as text, as seen on the GUI, ie
1126 * if columns are hidden they will not be returned in the result. Use this for
1127 * calculating trees, PCA, redundancy etc on views which contain hidden
1133 public jalview.datamodel.CigarArray getViewAsCigars(
1134 boolean selectedRegionOnly)
1136 return new jalview.datamodel.CigarArray(alignment,
1137 (hasHiddenColumns ? colSel : null),
1138 (selectedRegionOnly ? selectionGroup : null));
1142 * return a compact representation of the current alignment selection to pass
1143 * to an analysis function
1145 * @param selectedOnly
1146 * boolean true to just return the selected view
1147 * @return AlignmentView
1150 public jalview.datamodel.AlignmentView getAlignmentView(
1151 boolean selectedOnly)
1153 return getAlignmentView(selectedOnly, false);
1157 * return a compact representation of the current alignment selection to pass
1158 * to an analysis function
1160 * @param selectedOnly
1161 * boolean true to just return the selected view
1163 * boolean true to annotate the alignment view with groups on the
1164 * alignment (and intersecting with selected region if selectedOnly
1166 * @return AlignmentView
1169 public jalview.datamodel.AlignmentView getAlignmentView(
1170 boolean selectedOnly, boolean markGroups)
1172 return new AlignmentView(alignment, colSel, selectionGroup,
1173 hasHiddenColumns, selectedOnly, markGroups);
1177 * This method returns the visible alignment as text, as seen on the GUI, ie
1178 * if columns are hidden they will not be returned in the result. Use this for
1179 * calculating trees, PCA, redundancy etc on views which contain hidden
1185 public String[] getViewAsString(boolean selectedRegionOnly)
1187 String[] selection = null;
1188 SequenceI[] seqs = null;
1190 int start = 0, end = 0;
1191 if (selectedRegionOnly && selectionGroup != null)
1193 iSize = selectionGroup.getSize();
1194 seqs = selectionGroup.getSequencesInOrder(alignment);
1195 start = selectionGroup.getStartRes();
1196 end = selectionGroup.getEndRes() + 1;
1200 iSize = alignment.getHeight();
1201 seqs = alignment.getSequencesArray();
1202 end = alignment.getWidth();
1205 selection = new String[iSize];
1206 if (hasHiddenColumns)
1208 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1212 for (i = 0; i < iSize; i++)
1214 selection[i] = seqs[i].getSequenceAsString(start, end);
1222 * return visible region boundaries within given column range
1225 * first column (inclusive, from 0)
1227 * last column (exclusive)
1228 * @return int[][] range of {start,end} visible positions
1230 public int[][] getVisibleRegionBoundaries(int min, int max)
1232 Vector regions = new Vector();
1238 if (hasHiddenColumns)
1242 start = colSel.adjustForHiddenColumns(start);
1245 end = colSel.getHiddenBoundaryRight(start);
1256 regions.addElement(new int[]
1259 if (hasHiddenColumns)
1261 start = colSel.adjustForHiddenColumns(end);
1262 start = colSel.getHiddenBoundaryLeft(start) + 1;
1264 } while (end < max);
1266 int[][] startEnd = new int[regions.size()][2];
1268 regions.copyInto(startEnd);
1275 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(boolean selectedOnly)
1277 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1278 AlignmentAnnotation[] aa;
1279 if ((aa=alignment.getAlignmentAnnotation())!=null)
1281 for (AlignmentAnnotation annot:aa)
1283 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1284 if (selectedOnly && selectionGroup!=null)
1286 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(), selectionGroup.getEndRes(),clone);
1288 colSel.makeVisibleAnnotation(clone);
1297 * @return the padGaps
1299 public boolean isPadGaps()
1306 * the padGaps to set
1308 public void setPadGaps(boolean padGaps)
1310 this.padGaps = padGaps;
1314 * apply any post-edit constraints and trigger any calculations needed after
1315 * an edit has been performed on the alignment
1319 public void alignmentChanged(AlignmentViewPanel ap)
1323 alignment.padGaps();
1325 if (autoCalculateConsensus)
1327 updateConsensus(ap);
1329 if (hconsensus != null && autoCalculateConsensus)
1331 updateConservation(ap);
1333 if (autoCalculateStrucConsensus)
1335 updateStrucConsensus(ap);
1338 // Reset endRes of groups if beyond alignment width
1339 int alWidth = alignment.getWidth();
1340 List<SequenceGroup> groups = alignment.getGroups();
1343 for (SequenceGroup sg : groups)
1345 if (sg.getEndRes() > alWidth)
1347 sg.setEndRes(alWidth - 1);
1352 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1354 selectionGroup.setEndRes(alWidth - 1);
1357 resetAllColourSchemes();
1358 calculator.restartWorkers();
1359 // alignment.adjustSequenceAnnotations();
1363 * reset scope and do calculations for all applied colourschemes on alignment
1365 void resetAllColourSchemes()
1367 ColourSchemeI cs = globalColourScheme;
1370 cs.alignmentChanged(alignment, hiddenRepSequences);
1372 cs.setConsensus(hconsensus);
1373 if (cs.conservationApplied())
1375 cs.setConservation(Conservation.calculateConservation("All",
1376 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1377 alignment.getWidth(), false, getConsPercGaps(), false));
1381 for (SequenceGroup sg : alignment.getGroups())
1385 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1387 sg.recalcConservation();
1391 protected void initAutoAnnotation()
1393 // TODO: add menu option action that nulls or creates consensus object
1394 // depending on if the user wants to see the annotation or not in a
1395 // specific alignment
1397 if (hconsensus == null && !isDataset)
1399 if (!alignment.isNucleotide())
1412 private void initConsensus()
1415 consensus = new AlignmentAnnotation("Consensus", "PID",
1416 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1417 consensus.hasText = true;
1418 consensus.autoCalculated = true;
1422 alignment.addAnnotation(consensus);
1426 private void initConservation()
1428 if (showConservation)
1430 if (conservation == null)
1432 conservation = new AlignmentAnnotation("Conservation",
1433 "Conservation of total alignment less than "
1434 + getConsPercGaps() + "% gaps", new Annotation[1],
1435 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1436 conservation.hasText = true;
1437 conservation.autoCalculated = true;
1438 alignment.addAnnotation(conservation);
1443 private void initQuality()
1447 if (quality == null)
1449 quality = new AlignmentAnnotation("Quality",
1450 "Alignment Quality based on Blosum62 scores",
1451 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1452 quality.hasText = true;
1453 quality.autoCalculated = true;
1454 alignment.addAnnotation(quality);
1459 private void initRNAStructure()
1461 if (alignment.hasRNAStructure() && strucConsensus == null)
1463 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1464 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1465 strucConsensus.hasText = true;
1466 strucConsensus.autoCalculated = true;
1470 alignment.addAnnotation(strucConsensus);
1478 * @see jalview.api.AlignViewportI#calcPanelHeight()
1480 public int calcPanelHeight()
1482 // setHeight of panels
1483 AlignmentAnnotation[] aa = getAlignment().getAlignmentAnnotation();
1485 int charHeight = getCharHeight();
1488 BitSet graphgrp = new BitSet();
1489 for (int i = 0; i < aa.length; i++)
1493 System.err.println("Null annotation row: ignoring.");
1500 if (aa[i].graphGroup > -1)
1502 if (graphgrp.get(aa[i].graphGroup))
1508 graphgrp.set(aa[i].graphGroup);
1515 aa[i].height += charHeight;
1523 if (aa[i].graph > 0)
1525 aa[i].height += aa[i].graphHeight;
1528 if (aa[i].height == 0)
1533 height += aa[i].height;
1545 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1546 boolean preserveNewGroupSettings)
1548 boolean updateCalcs = false;
1549 boolean conv = isShowGroupConservation();
1550 boolean cons = isShowGroupConsensus();
1551 boolean showprf = isShowSequenceLogo();
1552 boolean showConsHist = isShowConsensusHistogram();
1553 boolean normLogo = isNormaliseSequenceLogo();
1556 * TODO reorder the annotation rows according to group/sequence ordering on
1559 boolean sortg = true;
1561 // remove old automatic annotation
1562 // add any new annotation
1564 // intersect alignment annotation with alignment groups
1566 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
1567 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
1570 for (int an = 0; an < aan.length; an++)
1572 if (aan[an].autoCalculated && aan[an].groupRef != null)
1574 oldrfs.add(aan[an].groupRef);
1575 alignment.deleteAnnotation(aan[an], false);
1579 if (alignment.getGroups() != null)
1581 for (SequenceGroup sg : alignment.getGroups())
1583 updateCalcs = false;
1584 if (applyGlobalSettings
1585 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
1587 // set defaults for this group's conservation/consensus
1588 sg.setshowSequenceLogo(showprf);
1589 sg.setShowConsensusHistogram(showConsHist);
1590 sg.setNormaliseSequenceLogo(normLogo);
1595 alignment.addAnnotation(sg.getConservationRow(), 0);
1600 alignment.addAnnotation(sg.getConsensus(), 0);
1602 // refresh the annotation rows
1605 sg.recalcConservation();
1612 * show the reference sequence in the alignment view
1614 private boolean displayReferenceSeq=false;
1616 * colour according to the reference sequence defined on the alignment
1618 private boolean colourByReferenceSeq=false;
1620 public boolean isDisplayReferenceSeq()
1622 return alignment.hasSeqrep() && displayReferenceSeq;
1625 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
1627 this.displayReferenceSeq = displayReferenceSeq;
1630 public boolean isColourByReferenceSeq()
1632 return alignment.hasSeqrep() && colourByReferenceSeq;
1635 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
1637 this.colourByReferenceSeq = colourByReferenceSeq;
1641 public Color getSequenceColour(SequenceI seq)
1643 Color sqc = Color.white;
1644 if (sequenceColours != null)
1646 sqc = (Color) sequenceColours.get(seq);
1656 public void setSequenceColour(SequenceI seq, Color col)
1658 if (sequenceColours == null)
1660 sequenceColours = new Hashtable();
1665 sequenceColours.remove(seq);
1669 sequenceColours.put(seq, col);
1674 public void updateSequenceIdColours()
1676 if (sequenceColours == null)
1678 sequenceColours = new Hashtable();
1680 for (SequenceGroup sg : alignment.getGroups())
1682 if (sg.idColour != null)
1684 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
1686 sequenceColours.put(s, sg.idColour);
1693 public void clearSequenceColours()
1695 sequenceColours = null;
1698 FeaturesDisplayedI featuresDisplayed = null;
1701 public FeaturesDisplayedI getFeaturesDisplayed()
1703 return featuresDisplayed;
1706 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
1708 featuresDisplayed = featuresDisplayedI;
1711 public boolean areFeaturesDisplayed()
1713 return featuresDisplayed != null && featuresDisplayed.getRegisterdFeaturesCount()>0;
1717 * display setting for showing/hiding sequence features on alignment view
1719 boolean showSequenceFeatures = false;
1725 * features are displayed if true
1728 public void setShowSequenceFeatures(boolean b)
1730 showSequenceFeatures = b;
1733 public boolean isShowSequenceFeatures()
1735 return showSequenceFeatures;
1738 boolean showSeqFeaturesHeight;
1740 public void setShowSequenceFeaturesHeight(boolean selected)
1742 showSeqFeaturesHeight = selected;
1745 public boolean isShowSequenceFeaturesHeight()
1747 return showSeqFeaturesHeight;
1750 private boolean showAnnotation = true;
1752 private boolean rightAlignIds = false;
1757 * @return DOCUMENT ME!
1759 public boolean getShowAnnotation()
1761 return isShowAnnotation();
1770 public void setShowAnnotation(boolean b)
1775 public boolean isShowAnnotation()
1777 return showAnnotation;
1780 public boolean isRightAlignIds()
1782 return rightAlignIds;
1785 public void setRightAlignIds(boolean rightAlignIds)
1787 this.rightAlignIds = rightAlignIds;