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));
1050 public int adjustForHiddenSeqs(int alignmentIndex)
1052 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1057 public abstract void sendSelection();
1060 public void invertColumnSelection()
1062 colSel.invertColumnSelection(0, alignment.getWidth());
1067 public SequenceI[] getSelectionAsNewSequence()
1069 SequenceI[] sequences;
1070 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1071 // this was the only caller in the applet for this method
1072 // JBPNote: in applet, this method returned references to the alignment
1073 // sequences, and it did not honour the presence/absence of annotation
1074 // attached to the alignment (probably!)
1075 if (selectionGroup == null || selectionGroup.getSize() == 0)
1077 sequences = alignment.getSequencesArray();
1078 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1079 for (int i = 0; i < sequences.length; i++)
1081 sequences[i] = new Sequence(sequences[i], annots); // construct new
1083 // subset of visible
1089 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1097 public SequenceI[] getSequenceSelection()
1099 SequenceI[] sequences = null;
1100 if (selectionGroup != null)
1102 sequences = selectionGroup.getSequencesInOrder(alignment);
1104 if (sequences == null)
1106 sequences = alignment.getSequencesArray();
1113 public jalview.datamodel.CigarArray getViewAsCigars(
1114 boolean selectedRegionOnly)
1116 return new jalview.datamodel.CigarArray(alignment,
1117 (hasHiddenColumns ? colSel : null),
1118 (selectedRegionOnly ? selectionGroup : null));
1123 public jalview.datamodel.AlignmentView getAlignmentView(
1124 boolean selectedOnly)
1126 return getAlignmentView(selectedOnly, false);
1131 public jalview.datamodel.AlignmentView getAlignmentView(
1132 boolean selectedOnly, boolean markGroups)
1134 return new AlignmentView(alignment, colSel, selectionGroup,
1135 hasHiddenColumns, selectedOnly, markGroups);
1140 public String[] getViewAsString(boolean selectedRegionOnly)
1142 String[] selection = null;
1143 SequenceI[] seqs = null;
1145 int start = 0, end = 0;
1146 if (selectedRegionOnly && selectionGroup != null)
1148 iSize = selectionGroup.getSize();
1149 seqs = selectionGroup.getSequencesInOrder(alignment);
1150 start = selectionGroup.getStartRes();
1151 end = selectionGroup.getEndRes() + 1;
1155 iSize = alignment.getHeight();
1156 seqs = alignment.getSequencesArray();
1157 end = alignment.getWidth();
1160 selection = new String[iSize];
1161 if (hasHiddenColumns)
1163 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1167 for (i = 0; i < iSize; i++)
1169 selection[i] = seqs[i].getSequenceAsString(start, end);
1178 public int[][] getVisibleRegionBoundaries(int min, int max)
1180 Vector regions = new Vector();
1186 if (hasHiddenColumns)
1190 start = colSel.adjustForHiddenColumns(start);
1193 end = colSel.getHiddenBoundaryRight(start);
1204 regions.addElement(new int[]
1207 if (hasHiddenColumns)
1209 start = colSel.adjustForHiddenColumns(end);
1210 start = colSel.getHiddenBoundaryLeft(start) + 1;
1212 } while (end < max);
1214 int[][] startEnd = new int[regions.size()][2];
1216 regions.copyInto(startEnd);
1223 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(boolean selectedOnly)
1225 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1226 AlignmentAnnotation[] aa;
1227 if ((aa=alignment.getAlignmentAnnotation())!=null)
1229 for (AlignmentAnnotation annot:aa)
1231 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1232 if (selectedOnly && selectionGroup!=null)
1234 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(), selectionGroup.getEndRes(),clone);
1236 colSel.makeVisibleAnnotation(clone);
1246 public boolean isPadGaps()
1253 public void setPadGaps(boolean padGaps)
1255 this.padGaps = padGaps;
1259 * apply any post-edit constraints and trigger any calculations needed after
1260 * an edit has been performed on the alignment
1265 public void alignmentChanged(AlignmentViewPanel ap)
1269 alignment.padGaps();
1271 if (autoCalculateConsensus)
1273 updateConsensus(ap);
1275 if (hconsensus != null && autoCalculateConsensus)
1277 updateConservation(ap);
1279 if (autoCalculateStrucConsensus)
1281 updateStrucConsensus(ap);
1284 // Reset endRes of groups if beyond alignment width
1285 int alWidth = alignment.getWidth();
1286 List<SequenceGroup> groups = alignment.getGroups();
1289 for (SequenceGroup sg : groups)
1291 if (sg.getEndRes() > alWidth)
1293 sg.setEndRes(alWidth - 1);
1298 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1300 selectionGroup.setEndRes(alWidth - 1);
1303 resetAllColourSchemes();
1304 calculator.restartWorkers();
1305 // alignment.adjustSequenceAnnotations();
1309 * reset scope and do calculations for all applied colourschemes on alignment
1311 void resetAllColourSchemes()
1313 ColourSchemeI cs = globalColourScheme;
1316 cs.alignmentChanged(alignment, hiddenRepSequences);
1318 cs.setConsensus(hconsensus);
1319 if (cs.conservationApplied())
1321 cs.setConservation(Conservation.calculateConservation("All",
1322 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1323 alignment.getWidth(), false, getConsPercGaps(), false));
1327 for (SequenceGroup sg : alignment.getGroups())
1331 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1333 sg.recalcConservation();
1337 protected void initAutoAnnotation()
1339 // TODO: add menu option action that nulls or creates consensus object
1340 // depending on if the user wants to see the annotation or not in a
1341 // specific alignment
1343 if (hconsensus == null && !isDataset)
1345 if (!alignment.isNucleotide())
1358 private void initConsensus()
1361 consensus = new AlignmentAnnotation("Consensus", "PID",
1362 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1363 consensus.hasText = true;
1364 consensus.autoCalculated = true;
1368 alignment.addAnnotation(consensus);
1372 private void initConservation()
1374 if (showConservation)
1376 if (conservation == null)
1378 conservation = new AlignmentAnnotation("Conservation",
1379 "Conservation of total alignment less than "
1380 + getConsPercGaps() + "% gaps", new Annotation[1],
1381 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1382 conservation.hasText = true;
1383 conservation.autoCalculated = true;
1384 alignment.addAnnotation(conservation);
1389 private void initQuality()
1393 if (quality == null)
1395 quality = new AlignmentAnnotation("Quality",
1396 "Alignment Quality based on Blosum62 scores",
1397 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1398 quality.hasText = true;
1399 quality.autoCalculated = true;
1400 alignment.addAnnotation(quality);
1405 private void initRNAStructure()
1407 if (alignment.hasRNAStructure() && strucConsensus == null)
1409 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1410 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1411 strucConsensus.hasText = true;
1412 strucConsensus.autoCalculated = true;
1416 alignment.addAnnotation(strucConsensus);
1424 * @see jalview.api.AlignViewportI#calcPanelHeight()
1427 public int calcPanelHeight()
1429 // setHeight of panels
1430 AlignmentAnnotation[] aa = getAlignment().getAlignmentAnnotation();
1432 int charHeight = getCharHeight();
1435 BitSet graphgrp = new BitSet();
1436 for (int i = 0; i < aa.length; i++)
1440 System.err.println("Null annotation row: ignoring.");
1447 if (aa[i].graphGroup > -1)
1449 if (graphgrp.get(aa[i].graphGroup))
1455 graphgrp.set(aa[i].graphGroup);
1462 aa[i].height += charHeight;
1470 if (aa[i].graph > 0)
1472 aa[i].height += aa[i].graphHeight;
1475 if (aa[i].height == 0)
1480 height += aa[i].height;
1492 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1493 boolean preserveNewGroupSettings)
1495 boolean updateCalcs = false;
1496 boolean conv = isShowGroupConservation();
1497 boolean cons = isShowGroupConsensus();
1498 boolean showprf = isShowSequenceLogo();
1499 boolean showConsHist = isShowConsensusHistogram();
1500 boolean normLogo = isNormaliseSequenceLogo();
1503 * TODO reorder the annotation rows according to group/sequence ordering on
1506 boolean sortg = true;
1508 // remove old automatic annotation
1509 // add any new annotation
1511 // intersect alignment annotation with alignment groups
1513 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
1514 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
1517 for (int an = 0; an < aan.length; an++)
1519 if (aan[an].autoCalculated && aan[an].groupRef != null)
1521 oldrfs.add(aan[an].groupRef);
1522 alignment.deleteAnnotation(aan[an], false);
1526 if (alignment.getGroups() != null)
1528 for (SequenceGroup sg : alignment.getGroups())
1530 updateCalcs = false;
1531 if (applyGlobalSettings
1532 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
1534 // set defaults for this group's conservation/consensus
1535 sg.setshowSequenceLogo(showprf);
1536 sg.setShowConsensusHistogram(showConsHist);
1537 sg.setNormaliseSequenceLogo(normLogo);
1542 alignment.addAnnotation(sg.getConservationRow(), 0);
1547 alignment.addAnnotation(sg.getConsensus(), 0);
1549 // refresh the annotation rows
1552 sg.recalcConservation();
1559 * show the reference sequence in the alignment view
1561 private boolean displayReferenceSeq=false;
1563 * colour according to the reference sequence defined on the alignment
1565 private boolean colourByReferenceSeq=false;
1568 public boolean isDisplayReferenceSeq()
1570 return alignment.hasSeqrep() && displayReferenceSeq;
1574 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
1576 this.displayReferenceSeq = displayReferenceSeq;
1579 public boolean isColourByReferenceSeq()
1581 return alignment.hasSeqrep() && colourByReferenceSeq;
1584 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
1586 this.colourByReferenceSeq = colourByReferenceSeq;
1590 public Color getSequenceColour(SequenceI seq)
1592 Color sqc = Color.white;
1593 if (sequenceColours != null)
1595 sqc = (Color) sequenceColours.get(seq);
1605 public void setSequenceColour(SequenceI seq, Color col)
1607 if (sequenceColours == null)
1609 sequenceColours = new Hashtable();
1614 sequenceColours.remove(seq);
1618 sequenceColours.put(seq, col);
1623 public void updateSequenceIdColours()
1625 if (sequenceColours == null)
1627 sequenceColours = new Hashtable();
1629 for (SequenceGroup sg : alignment.getGroups())
1631 if (sg.idColour != null)
1633 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
1635 sequenceColours.put(s, sg.idColour);
1642 public void clearSequenceColours()
1644 sequenceColours = null;
1647 FeaturesDisplayedI featuresDisplayed = null;
1650 public FeaturesDisplayedI getFeaturesDisplayed()
1652 return featuresDisplayed;
1656 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
1658 featuresDisplayed = featuresDisplayedI;
1662 public boolean areFeaturesDisplayed()
1664 return featuresDisplayed != null && featuresDisplayed.getRegisterdFeaturesCount()>0;
1668 * display setting for showing/hiding sequence features on alignment view
1670 boolean showSequenceFeatures = false;
1676 * features are displayed if true
1679 public void setShowSequenceFeatures(boolean b)
1681 showSequenceFeatures = b;
1684 public boolean isShowSequenceFeatures()
1686 return showSequenceFeatures;
1689 boolean showSeqFeaturesHeight;
1692 public void setShowSequenceFeaturesHeight(boolean selected)
1694 showSeqFeaturesHeight = selected;
1698 public boolean isShowSequenceFeaturesHeight()
1700 return showSeqFeaturesHeight;
1703 private boolean showAnnotation = true;
1705 private boolean rightAlignIds = false;
1709 public void setShowAnnotation(boolean b)
1715 public boolean isShowAnnotation()
1717 return showAnnotation;
1721 public boolean isRightAlignIds()
1723 return rightAlignIds;
1727 public void setRightAlignIds(boolean rightAlignIds)
1729 this.rightAlignIds = rightAlignIds;