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.CigarArray;
33 import jalview.datamodel.ColumnSelection;
34 import jalview.datamodel.Sequence;
35 import jalview.datamodel.SequenceCollectionI;
36 import jalview.datamodel.SequenceGroup;
37 import jalview.datamodel.SequenceI;
38 import jalview.schemes.Blosum62ColourScheme;
39 import jalview.schemes.ColourSchemeI;
40 import jalview.schemes.PIDColourScheme;
41 import jalview.schemes.ResidueProperties;
42 import jalview.workers.AlignCalcManager;
43 import jalview.workers.ConsensusThread;
44 import jalview.workers.StrucConsensusThread;
46 import java.awt.Color;
47 import java.util.ArrayList;
48 import java.util.BitSet;
49 import java.util.HashMap;
50 import java.util.Hashtable;
51 import java.util.List;
53 import java.util.Vector;
56 * base class holding visualization and analysis attributes and common logic for
57 * an active alignment view displayed in the GUI
62 public abstract class AlignmentViewport implements AlignViewportI
65 * A viewport that hosts the cDna view of this (protein), or vice versa (if
68 AlignViewportI codingComplement = null;
71 * alignment displayed in the viewport. Please use get/setter
73 protected AlignmentI alignment;
75 protected String sequenceSetID;
78 * probably unused indicator that view is of a dataset rather than an
81 protected boolean isDataset = false;
83 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
85 protected ColumnSelection colSel = new ColumnSelection();
87 public boolean autoCalculateConsensus = true;
89 protected boolean autoCalculateStrucConsensus = true;
91 protected boolean ignoreGapsInConsensusCalculation = false;
93 protected ColourSchemeI globalColourScheme = null;
96 * gui state - changes to colour scheme propagated to all groups
98 private boolean colourAppliesToAllGroups;
102 * indicating if subsequent colourscheme changes will be propagated
105 public void setColourAppliesToAllGroups(boolean b)
107 colourAppliesToAllGroups = b;
113 * @return flag indicating if colourchanges propagated to all groups
115 public boolean getColourAppliesToAllGroups()
117 return colourAppliesToAllGroups;
120 boolean abovePIDThreshold = false;
125 * @return true if percent identity threshold is applied to shading
127 public boolean getAbovePIDThreshold()
129 return abovePIDThreshold;
137 * indicate if percent identity threshold is applied to shading
139 public void setAbovePIDThreshold(boolean b)
141 abovePIDThreshold = b;
152 public void setThreshold(int thresh)
160 * @return DOCUMENT ME!
162 public int getThreshold()
172 * set the scalar for bleaching colourschemes according to degree of
175 public void setIncrement(int inc)
183 * @return get scalar for bleaching colourschemes by conservation
185 public int getIncrement()
190 boolean conservationColourSelected = false;
195 * @return true if conservation based shading is enabled
197 public boolean getConservationSelected()
199 return conservationColourSelected;
206 * enable conservation based shading
208 public void setConservationSelected(boolean b)
210 conservationColourSelected = b;
214 public void setGlobalColourScheme(ColourSchemeI cs)
216 // TODO: logic refactored from AlignFrame changeColour -
217 // autorecalc stuff should be changed to rely on the worker system
218 // check to see if we should implement a changeColour(cs) method rather than
219 // put th logic in here
220 // - means that caller decides if they want to just modify state and defer
221 // calculation till later or to do all calculations in thread.
223 globalColourScheme = cs;
224 boolean recalc = false;
227 cs.setConservationApplied(recalc = getConservationSelected());
228 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
229 || cs instanceof Blosum62ColourScheme)
232 cs.setThreshold(threshold, ignoreGapsInConsensusCalculation);
236 cs.setThreshold(0, ignoreGapsInConsensusCalculation);
240 cs.setConsensus(hconsensus);
241 cs.setConservation(hconservation);
243 cs.alignmentChanged(alignment, hiddenRepSequences);
245 if (getColourAppliesToAllGroups())
247 for (SequenceGroup sg : getAlignment().getGroups())
254 sg.cs = cs.applyTo(sg, getHiddenRepSequences());
255 sg.setConsPercGaps(ConsPercGaps);
256 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
257 || cs instanceof Blosum62ColourScheme)
259 sg.cs.setThreshold(threshold, getIgnoreGapsConsensus());
264 sg.cs.setThreshold(0, getIgnoreGapsConsensus());
267 if (getConservationSelected())
269 sg.cs.setConservationApplied(true);
274 sg.cs.setConservation(null);
275 // sg.cs.setThreshold(0, getIgnoreGapsConsensus());
279 sg.recalcConservation();
283 sg.cs.alignmentChanged(sg, hiddenRepSequences);
291 public ColourSchemeI getGlobalColourScheme()
293 return globalColourScheme;
296 protected AlignmentAnnotation consensus;
298 protected AlignmentAnnotation strucConsensus;
300 protected AlignmentAnnotation conservation;
302 protected AlignmentAnnotation quality;
304 protected AlignmentAnnotation[] groupConsensus;
306 protected AlignmentAnnotation[] groupConservation;
309 * results of alignment consensus analysis for visible portion of view
311 protected Hashtable[] hconsensus = null;
314 * results of secondary structure base pair consensus for visible portion of
317 protected Hashtable[] hStrucConsensus = null;
319 protected Conservation hconservation = null;
322 public void setConservation(Conservation cons)
324 hconservation = cons;
328 * percentage gaps allowed in a column before all amino acid properties should
329 * be considered unconserved
331 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
334 public int getConsPercGaps()
340 public void setSequenceConsensusHash(Hashtable[] hconsensus)
342 this.hconsensus = hconsensus;
347 public Hashtable[] getSequenceConsensusHash()
353 public Hashtable[] getRnaStructureConsensusHash()
355 return hStrucConsensus;
359 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
361 this.hStrucConsensus = hStrucConsensus;
366 public AlignmentAnnotation getAlignmentQualityAnnot()
372 public AlignmentAnnotation getAlignmentConservationAnnotation()
378 public AlignmentAnnotation getAlignmentConsensusAnnotation()
384 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
386 return strucConsensus;
389 protected AlignCalcManagerI calculator = new AlignCalcManager();
392 * trigger update of conservation annotation
394 public void updateConservation(final AlignmentViewPanel ap)
396 // see note in mantis : issue number 8585
397 if (alignment.isNucleotide() || conservation == null
398 || !autoCalculateConsensus)
403 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
405 calculator.registerWorker(new jalview.workers.ConservationThread(
411 * trigger update of consensus annotation
413 public void updateConsensus(final AlignmentViewPanel ap)
415 // see note in mantis : issue number 8585
416 if (consensus == null || !autoCalculateConsensus)
420 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
422 calculator.registerWorker(new ConsensusThread(this, ap));
426 // --------START Structure Conservation
427 public void updateStrucConsensus(final AlignmentViewPanel ap)
429 if (autoCalculateStrucConsensus && strucConsensus == null
430 && alignment.isNucleotide() && alignment.hasRNAStructure())
432 // secondary structure has been added - so init the consensus line
436 // see note in mantis : issue number 8585
437 if (strucConsensus == null || !autoCalculateStrucConsensus)
441 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
443 calculator.registerWorker(new StrucConsensusThread(this, ap));
447 public boolean isCalcInProgress()
449 return calculator.isWorking();
453 public boolean isCalculationInProgress(
454 AlignmentAnnotation alignmentAnnotation)
456 if (!alignmentAnnotation.autoCalculated)
460 if (calculator.workingInvolvedWith(alignmentAnnotation))
462 // System.err.println("grey out ("+alignmentAnnotation.label+")");
469 public boolean isClosed()
471 // TODO: check that this isClosed is only true after panel is closed, not
472 // before it is fully constructed.
473 return alignment == null;
477 public AlignCalcManagerI getCalcManager()
483 * should conservation rows be shown for groups
485 protected boolean showGroupConservation = false;
488 * should consensus rows be shown for groups
490 protected boolean showGroupConsensus = false;
493 * should consensus profile be rendered by default
495 protected boolean showSequenceLogo = false;
498 * should consensus profile be rendered normalised to row height
500 protected boolean normaliseSequenceLogo = false;
503 * should consensus histograms be rendered by default
505 protected boolean showConsensusHistogram = true;
508 * @return the showConsensusProfile
511 public boolean isShowSequenceLogo()
513 return showSequenceLogo;
517 * @param showSequenceLogo
520 public void setShowSequenceLogo(boolean showSequenceLogo)
522 if (showSequenceLogo != this.showSequenceLogo)
524 // TODO: decouple settings setting from calculation when refactoring
525 // annotation update method from alignframe to viewport
526 this.showSequenceLogo = showSequenceLogo;
527 calculator.updateAnnotationFor(ConsensusThread.class);
528 calculator.updateAnnotationFor(StrucConsensusThread.class);
530 this.showSequenceLogo = showSequenceLogo;
534 * @param showConsensusHistogram
535 * the showConsensusHistogram to set
537 public void setShowConsensusHistogram(boolean showConsensusHistogram)
539 this.showConsensusHistogram = showConsensusHistogram;
543 * @return the showGroupConservation
545 public boolean isShowGroupConservation()
547 return showGroupConservation;
551 * @param showGroupConservation
552 * the showGroupConservation to set
554 public void setShowGroupConservation(boolean showGroupConservation)
556 this.showGroupConservation = showGroupConservation;
560 * @return the showGroupConsensus
562 public boolean isShowGroupConsensus()
564 return showGroupConsensus;
568 * @param showGroupConsensus
569 * the showGroupConsensus to set
571 public void setShowGroupConsensus(boolean showGroupConsensus)
573 this.showGroupConsensus = showGroupConsensus;
578 * @return flag to indicate if the consensus histogram should be rendered by
582 public boolean isShowConsensusHistogram()
584 return this.showConsensusHistogram;
588 * show non-conserved residues only
590 protected boolean showUnconserved = false;
593 * when set, updateAlignment will always ensure sequences are of equal length
595 private boolean padGaps = false;
598 * when set, alignment should be reordered according to a newly opened tree
600 public boolean sortByTree = false;
602 public boolean getShowUnconserved()
604 return showUnconserved;
607 public void setShowUnconserved(boolean showunconserved)
609 showUnconserved = showunconserved;
613 * @param showNonconserved
614 * the showUnconserved to set
616 public void setShowunconserved(boolean displayNonconserved)
618 this.showUnconserved = displayNonconserved;
624 * @return null or the currently selected sequence region
627 public SequenceGroup getSelectionGroup()
629 return selectionGroup;
633 * Set the selection group for this window.
636 * - group holding references to sequences in this alignment view
640 public void setSelectionGroup(SequenceGroup sg)
645 public void setHiddenColumns(ColumnSelection colsel)
647 this.colSel = colsel;
651 public ColumnSelection getColumnSelection()
657 public void setColumnSelection(ColumnSelection colSel)
659 this.colSel = colSel;
662 updateHiddenColumns();
671 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
673 return hiddenRepSequences;
677 public void setHiddenRepSequences(
678 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
680 this.hiddenRepSequences = hiddenRepSequences;
684 public boolean hasHiddenColumns()
686 return colSel != null && colSel.hasHiddenColumns();
689 public void updateHiddenColumns()
691 // this method doesn't really do anything now. But - it could, since a
692 // column Selection could be in the process of modification
693 // hasHiddenColumns = colSel.hasHiddenColumns();
696 protected boolean hasHiddenRows = false;
699 public boolean hasHiddenRows()
701 return hasHiddenRows;
704 protected SequenceGroup selectionGroup;
706 public void setSequenceSetId(String newid)
708 if (sequenceSetID != null)
711 .println("Warning - overwriting a sequenceSetId for a viewport!");
713 sequenceSetID = new String(newid);
717 public String getSequenceSetId()
719 if (sequenceSetID == null)
721 sequenceSetID = alignment.hashCode() + "";
724 return sequenceSetID;
728 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
731 protected String viewId = null;
733 public String getViewId()
737 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
742 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
744 ignoreGapsInConsensusCalculation = b;
748 if (globalColourScheme != null)
750 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
751 ignoreGapsInConsensusCalculation);
757 private long sgrouphash = -1, colselhash = -1;
760 * checks current SelectionGroup against record of last hash value, and
764 * update the record of last hash value
766 * @return true if SelectionGroup changed since last call (when b is true)
768 public boolean isSelectionGroupChanged(boolean b)
770 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
771 : selectionGroup.hashCode();
772 if (hc != -1 && hc != sgrouphash)
784 * checks current colsel against record of last hash value, and optionally
788 * update the record of last hash value
789 * @return true if colsel changed since last call (when b is true)
791 public boolean isColSelChanged(boolean b)
793 int hc = (colSel == null || colSel.size() == 0) ? -1 : colSel
795 if (hc != -1 && hc != colselhash)
807 public boolean getIgnoreGapsConsensus()
809 return ignoreGapsInConsensusCalculation;
812 // / property change stuff
814 // JBPNote Prolly only need this in the applet version.
815 private final java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
818 protected boolean showConservation = true;
820 protected boolean showQuality = true;
822 protected boolean showConsensus = true;
824 private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
827 * Property change listener for changes in alignment
832 public void addPropertyChangeListener(
833 java.beans.PropertyChangeListener listener)
835 changeSupport.addPropertyChangeListener(listener);
844 public void removePropertyChangeListener(
845 java.beans.PropertyChangeListener listener)
847 changeSupport.removePropertyChangeListener(listener);
851 * Property change listener for changes in alignment
860 public void firePropertyChange(String prop, Object oldvalue,
863 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
866 // common hide/show column stuff
868 public void hideSelectedColumns()
870 if (colSel.size() < 1)
875 colSel.hideSelectedColumns();
876 setSelectionGroup(null);
880 public void hideColumns(int start, int end)
884 colSel.hideColumns(start);
888 colSel.hideColumns(start, end);
892 public void showColumn(int col)
894 colSel.revealHiddenColumns(col);
898 public void showAllHiddenColumns()
900 colSel.revealAllHiddenColumns();
903 // common hide/show seq stuff
904 public void showAllHiddenSeqs()
906 if (alignment.getHiddenSequences().getSize() > 0)
908 if (selectionGroup == null)
910 selectionGroup = new SequenceGroup();
911 selectionGroup.setEndRes(alignment.getWidth() - 1);
913 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
915 for (SequenceI seq : tmp)
917 selectionGroup.addSequence(seq, false);
918 setSequenceAnnotationsVisible(seq, true);
921 hasHiddenRows = false;
922 hiddenRepSequences = null;
924 firePropertyChange("alignment", null, alignment.getSequences());
925 // used to set hasHiddenRows/hiddenRepSequences here, after the property
931 public void showSequence(int index)
933 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
938 if (selectionGroup == null)
940 selectionGroup = new SequenceGroup();
941 selectionGroup.setEndRes(alignment.getWidth() - 1);
944 for (SequenceI seq : tmp)
946 selectionGroup.addSequence(seq, false);
947 setSequenceAnnotationsVisible(seq, true);
949 // JBPNote: refactor: only update flag if we modified visiblity (used to
950 // do this regardless)
951 if (alignment.getHiddenSequences().getSize() < 1)
953 hasHiddenRows = false;
955 firePropertyChange("alignment", null, alignment.getSequences());
960 public void hideAllSelectedSeqs()
962 if (selectionGroup == null || selectionGroup.getSize() < 1)
967 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
971 setSelectionGroup(null);
974 public void hideSequence(SequenceI[] seq)
978 for (int i = 0; i < seq.length; i++)
980 alignment.getHiddenSequences().hideSequence(seq[i]);
981 setSequenceAnnotationsVisible(seq[i], false);
983 hasHiddenRows = true;
984 firePropertyChange("alignment", null, alignment.getSequences());
989 * Set visibility for any annotations for the given sequence.
993 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
996 for (AlignmentAnnotation ann : alignment.getAlignmentAnnotation())
998 if (ann.sequenceRef == sequenceI)
1000 ann.visible = visible;
1005 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1007 int sSize = sg.getSize();
1013 if (hiddenRepSequences == null)
1015 hiddenRepSequences = new Hashtable();
1018 hiddenRepSequences.put(repSequence, sg);
1020 // Hide all sequences except the repSequence
1021 SequenceI[] seqs = new SequenceI[sSize - 1];
1023 for (int i = 0; i < sSize; i++)
1025 if (sg.getSequenceAt(i) != repSequence)
1027 if (index == sSize - 1)
1032 seqs[index++] = sg.getSequenceAt(i);
1035 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1036 sg.setHidereps(true); // note: not done in 2.7applet
1041 public boolean isHiddenRepSequence(SequenceI seq)
1043 return alignment.getSeqrep()==seq || (hiddenRepSequences != null
1044 && hiddenRepSequences.containsKey(seq));
1047 public SequenceGroup getRepresentedSequences(SequenceI seq)
1049 return (SequenceGroup) (hiddenRepSequences == null ? null
1050 : hiddenRepSequences.get(seq));
1054 public int adjustForHiddenSeqs(int alignmentIndex)
1056 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1061 public void invertColumnSelection()
1063 colSel.invertColumnSelection(0, alignment.getWidth());
1068 public SequenceI[] getSelectionAsNewSequence()
1070 SequenceI[] sequences;
1071 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1072 // this was the only caller in the applet for this method
1073 // JBPNote: in applet, this method returned references to the alignment
1074 // sequences, and it did not honour the presence/absence of annotation
1075 // attached to the alignment (probably!)
1076 if (selectionGroup == null || selectionGroup.getSize() == 0)
1078 sequences = alignment.getSequencesArray();
1079 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1080 for (int i = 0; i < sequences.length; i++)
1082 sequences[i] = new Sequence(sequences[i], annots); // construct new
1084 // subset of visible
1090 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1098 public SequenceI[] getSequenceSelection()
1100 SequenceI[] sequences = null;
1101 if (selectionGroup != null)
1103 sequences = selectionGroup.getSequencesInOrder(alignment);
1105 if (sequences == null)
1107 sequences = alignment.getSequencesArray();
1114 public CigarArray getViewAsCigars(
1115 boolean selectedRegionOnly)
1117 return new CigarArray(alignment, colSel,
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 colSel != null && colSel.hasHiddenColumns(), selectedOnly,
1141 public String[] getViewAsString(boolean selectedRegionOnly)
1143 String[] selection = null;
1144 SequenceI[] seqs = null;
1146 int start = 0, end = 0;
1147 if (selectedRegionOnly && selectionGroup != null)
1149 iSize = selectionGroup.getSize();
1150 seqs = selectionGroup.getSequencesInOrder(alignment);
1151 start = selectionGroup.getStartRes();
1152 end = selectionGroup.getEndRes() + 1;
1156 iSize = alignment.getHeight();
1157 seqs = alignment.getSequencesArray();
1158 end = alignment.getWidth();
1161 selection = new String[iSize];
1162 if (colSel != null && colSel.hasHiddenColumns())
1164 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1168 for (i = 0; i < iSize; i++)
1170 selection[i] = seqs[i].getSequenceAsString(start, end);
1179 public int[][] getVisibleRegionBoundaries(int min, int max)
1181 Vector regions = new Vector();
1187 if (colSel != null && colSel.hasHiddenColumns())
1191 start = colSel.adjustForHiddenColumns(start);
1194 end = colSel.getHiddenBoundaryRight(start);
1205 regions.addElement(new int[]
1208 if (colSel != null && colSel.hasHiddenColumns())
1210 start = colSel.adjustForHiddenColumns(end);
1211 start = colSel.getHiddenBoundaryLeft(start) + 1;
1213 } while (end < max);
1215 int[][] startEnd = new int[regions.size()][2];
1217 regions.copyInto(startEnd);
1224 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(boolean selectedOnly)
1226 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1227 AlignmentAnnotation[] aa;
1228 if ((aa=alignment.getAlignmentAnnotation())!=null)
1230 for (AlignmentAnnotation annot:aa)
1232 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1233 if (selectedOnly && selectionGroup!=null)
1235 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(), selectionGroup.getEndRes(),clone);
1237 colSel.makeVisibleAnnotation(clone);
1247 public boolean isPadGaps()
1254 public void setPadGaps(boolean padGaps)
1256 this.padGaps = padGaps;
1260 * apply any post-edit constraints and trigger any calculations needed after
1261 * an edit has been performed on the alignment
1266 public void alignmentChanged(AlignmentViewPanel ap)
1270 alignment.padGaps();
1272 if (autoCalculateConsensus)
1274 updateConsensus(ap);
1276 if (hconsensus != null && autoCalculateConsensus)
1278 updateConservation(ap);
1280 if (autoCalculateStrucConsensus)
1282 updateStrucConsensus(ap);
1285 // Reset endRes of groups if beyond alignment width
1286 int alWidth = alignment.getWidth();
1287 List<SequenceGroup> groups = alignment.getGroups();
1290 for (SequenceGroup sg : groups)
1292 if (sg.getEndRes() > alWidth)
1294 sg.setEndRes(alWidth - 1);
1299 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1301 selectionGroup.setEndRes(alWidth - 1);
1304 resetAllColourSchemes();
1305 calculator.restartWorkers();
1306 // alignment.adjustSequenceAnnotations();
1310 * reset scope and do calculations for all applied colourschemes on alignment
1312 void resetAllColourSchemes()
1314 ColourSchemeI cs = globalColourScheme;
1317 cs.alignmentChanged(alignment, hiddenRepSequences);
1319 cs.setConsensus(hconsensus);
1320 if (cs.conservationApplied())
1322 cs.setConservation(Conservation.calculateConservation("All",
1323 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1324 alignment.getWidth(), false, getConsPercGaps(), false));
1328 for (SequenceGroup sg : alignment.getGroups())
1332 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1334 sg.recalcConservation();
1338 protected void initAutoAnnotation()
1340 // TODO: add menu option action that nulls or creates consensus object
1341 // depending on if the user wants to see the annotation or not in a
1342 // specific alignment
1344 if (hconsensus == null && !isDataset)
1346 if (!alignment.isNucleotide())
1359 private void initConsensus()
1362 consensus = new AlignmentAnnotation("Consensus", "PID",
1363 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1364 consensus.hasText = true;
1365 consensus.autoCalculated = true;
1369 alignment.addAnnotation(consensus);
1373 private void initConservation()
1375 if (showConservation)
1377 if (conservation == null)
1379 conservation = new AlignmentAnnotation("Conservation",
1380 "Conservation of total alignment less than "
1381 + getConsPercGaps() + "% gaps", new Annotation[1],
1382 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1383 conservation.hasText = true;
1384 conservation.autoCalculated = true;
1385 alignment.addAnnotation(conservation);
1390 private void initQuality()
1394 if (quality == null)
1396 quality = new AlignmentAnnotation("Quality",
1397 "Alignment Quality based on Blosum62 scores",
1398 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1399 quality.hasText = true;
1400 quality.autoCalculated = true;
1401 alignment.addAnnotation(quality);
1406 private void initRNAStructure()
1408 if (alignment.hasRNAStructure() && strucConsensus == null)
1410 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1411 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1412 strucConsensus.hasText = true;
1413 strucConsensus.autoCalculated = true;
1417 alignment.addAnnotation(strucConsensus);
1425 * @see jalview.api.AlignViewportI#calcPanelHeight()
1428 public int calcPanelHeight()
1430 // setHeight of panels
1431 AlignmentAnnotation[] aa = getAlignment().getAlignmentAnnotation();
1433 int charHeight = getCharHeight();
1436 BitSet graphgrp = new BitSet();
1437 for (int i = 0; i < aa.length; i++)
1441 System.err.println("Null annotation row: ignoring.");
1448 if (aa[i].graphGroup > -1)
1450 if (graphgrp.get(aa[i].graphGroup))
1456 graphgrp.set(aa[i].graphGroup);
1463 aa[i].height += charHeight;
1471 if (aa[i].graph > 0)
1473 aa[i].height += aa[i].graphHeight;
1476 if (aa[i].height == 0)
1481 height += aa[i].height;
1493 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1494 boolean preserveNewGroupSettings)
1496 boolean updateCalcs = false;
1497 boolean conv = isShowGroupConservation();
1498 boolean cons = isShowGroupConsensus();
1499 boolean showprf = isShowSequenceLogo();
1500 boolean showConsHist = isShowConsensusHistogram();
1501 boolean normLogo = isNormaliseSequenceLogo();
1504 * TODO reorder the annotation rows according to group/sequence ordering on
1507 boolean sortg = true;
1509 // remove old automatic annotation
1510 // add any new annotation
1512 // intersect alignment annotation with alignment groups
1514 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
1515 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
1518 for (int an = 0; an < aan.length; an++)
1520 if (aan[an].autoCalculated && aan[an].groupRef != null)
1522 oldrfs.add(aan[an].groupRef);
1523 alignment.deleteAnnotation(aan[an], false);
1527 if (alignment.getGroups() != null)
1529 for (SequenceGroup sg : alignment.getGroups())
1531 updateCalcs = false;
1532 if (applyGlobalSettings
1533 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
1535 // set defaults for this group's conservation/consensus
1536 sg.setshowSequenceLogo(showprf);
1537 sg.setShowConsensusHistogram(showConsHist);
1538 sg.setNormaliseSequenceLogo(normLogo);
1543 alignment.addAnnotation(sg.getConservationRow(), 0);
1548 alignment.addAnnotation(sg.getConsensus(), 0);
1550 // refresh the annotation rows
1553 sg.recalcConservation();
1560 * show the reference sequence in the alignment view
1562 private boolean displayReferenceSeq=false;
1564 * colour according to the reference sequence defined on the alignment
1566 private boolean colourByReferenceSeq=false;
1569 public boolean isDisplayReferenceSeq()
1571 return alignment.hasSeqrep() && displayReferenceSeq;
1575 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
1577 this.displayReferenceSeq = displayReferenceSeq;
1581 public boolean isColourByReferenceSeq()
1583 return alignment.hasSeqrep() && colourByReferenceSeq;
1587 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
1589 this.colourByReferenceSeq = colourByReferenceSeq;
1593 public Color getSequenceColour(SequenceI seq)
1595 Color sqc = sequenceColours.get(seq);
1596 return (sqc == null ? Color.white : sqc);
1600 public void setSequenceColour(SequenceI seq, Color col)
1604 sequenceColours.remove(seq);
1608 sequenceColours.put(seq, col);
1613 public void updateSequenceIdColours()
1615 for (SequenceGroup sg : alignment.getGroups())
1617 if (sg.idColour != null)
1619 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
1621 sequenceColours.put(s, sg.idColour);
1628 public void clearSequenceColours()
1630 sequenceColours.clear();
1634 public AlignViewportI getCodingComplement()
1636 return this.codingComplement;
1640 * Set this as the (cDna/protein) complement of the given viewport. Also
1641 * ensures the reverse relationship is set on the given viewport.
1644 public void setCodingComplement(AlignViewportI av)
1648 System.err.println("Ignoring recursive setCodingComplement request");
1652 this.codingComplement = av;
1653 // avoid infinite recursion!
1654 if (av.getCodingComplement() != this)
1656 av.setCodingComplement(this);
1662 public boolean isNucleotide()
1664 return getAlignment() == null ? false : getAlignment().isNucleotide();
1667 FeaturesDisplayedI featuresDisplayed = null;
1670 public FeaturesDisplayedI getFeaturesDisplayed()
1672 return featuresDisplayed;
1676 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
1678 featuresDisplayed = featuresDisplayedI;
1682 public boolean areFeaturesDisplayed()
1684 return featuresDisplayed != null && featuresDisplayed.getRegisterdFeaturesCount()>0;
1688 * display setting for showing/hiding sequence features on alignment view
1690 boolean showSequenceFeatures = false;
1696 * features are displayed if true
1699 public void setShowSequenceFeatures(boolean b)
1701 showSequenceFeatures = b;
1704 public boolean isShowSequenceFeatures()
1706 return showSequenceFeatures;
1709 boolean showSeqFeaturesHeight;
1712 public void setShowSequenceFeaturesHeight(boolean selected)
1714 showSeqFeaturesHeight = selected;
1718 public boolean isShowSequenceFeaturesHeight()
1720 return showSeqFeaturesHeight;
1723 private boolean showAnnotation = true;
1725 private boolean rightAlignIds = false;
1729 public void setShowAnnotation(boolean b)
1735 public boolean isShowAnnotation()
1737 return showAnnotation;
1741 public boolean isRightAlignIds()
1743 return rightAlignIds;
1747 public void setRightAlignIds(boolean rightAlignIds)
1749 this.rightAlignIds = rightAlignIds;