2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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.AnnotationSorter.SequenceAnnotationOrder;
24 import jalview.analysis.Conservation;
25 import jalview.api.AlignCalcManagerI;
26 import jalview.api.AlignViewportI;
27 import jalview.api.AlignmentViewPanel;
28 import jalview.api.FeaturesDisplayedI;
29 import jalview.api.ViewStyleI;
30 import jalview.commands.CommandI;
31 import jalview.datamodel.AlignedCodonFrame;
32 import jalview.datamodel.AlignmentAnnotation;
33 import jalview.datamodel.AlignmentI;
34 import jalview.datamodel.AlignmentView;
35 import jalview.datamodel.Annotation;
36 import jalview.datamodel.CigarArray;
37 import jalview.datamodel.ColumnSelection;
38 import jalview.datamodel.HiddenColumns;
39 import jalview.datamodel.HiddenSequences;
40 import jalview.datamodel.ProfilesI;
41 import jalview.datamodel.SearchResultsI;
42 import jalview.datamodel.Sequence;
43 import jalview.datamodel.SequenceCollectionI;
44 import jalview.datamodel.SequenceGroup;
45 import jalview.datamodel.SequenceI;
46 import jalview.renderer.ResidueShader;
47 import jalview.renderer.ResidueShaderI;
48 import jalview.schemes.ColourSchemeI;
49 import jalview.structure.CommandListener;
50 import jalview.structure.StructureSelectionManager;
51 import jalview.structure.VamsasSource;
52 import jalview.util.Comparison;
53 import jalview.util.MapList;
54 import jalview.util.MappingUtils;
55 import jalview.util.MessageManager;
56 import jalview.viewmodel.styles.ViewStyle;
57 import jalview.workers.AlignCalcManager;
58 import jalview.workers.ComplementConsensusThread;
59 import jalview.workers.ConsensusThread;
60 import jalview.workers.StrucConsensusThread;
62 import java.awt.Color;
63 import java.beans.PropertyChangeSupport;
64 import java.util.ArrayDeque;
65 import java.util.ArrayList;
66 import java.util.BitSet;
67 import java.util.Deque;
68 import java.util.HashMap;
69 import java.util.Hashtable;
70 import java.util.List;
74 * base class holding visualization and analysis attributes and common logic for
75 * an active alignment view displayed in the GUI
80 public abstract class AlignmentViewport implements AlignViewportI,
81 CommandListener, VamsasSource
83 final protected ViewportRanges ranges;
85 protected ViewStyleI viewStyle = new ViewStyle();
88 * A viewport that hosts the cDna view of this (protein), or vice versa (if
91 AlignViewportI codingComplement = null;
93 FeaturesDisplayedI featuresDisplayed = null;
95 protected Deque<CommandI> historyList = new ArrayDeque<>();
97 protected Deque<CommandI> redoList = new ArrayDeque<>();
100 * alignment displayed in the viewport. Please use get/setter
102 protected AlignmentI alignment;
104 public AlignmentViewport(AlignmentI al)
107 ranges = new ViewportRanges(al);
112 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
115 public void setFontName(String name)
117 viewStyle.setFontName(name);
122 * @see jalview.api.ViewStyleI#setFontStyle(int)
125 public void setFontStyle(int style)
127 viewStyle.setFontStyle(style);
132 * @see jalview.api.ViewStyleI#setFontSize(int)
135 public void setFontSize(int size)
137 viewStyle.setFontSize(size);
142 * @see jalview.api.ViewStyleI#getFontStyle()
145 public int getFontStyle()
147 return viewStyle.getFontStyle();
152 * @see jalview.api.ViewStyleI#getFontName()
155 public String getFontName()
157 return viewStyle.getFontName();
162 * @see jalview.api.ViewStyleI#getFontSize()
165 public int getFontSize()
167 return viewStyle.getFontSize();
171 * @param upperCasebold
172 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
175 public void setUpperCasebold(boolean upperCasebold)
177 viewStyle.setUpperCasebold(upperCasebold);
182 * @see jalview.api.ViewStyleI#isUpperCasebold()
185 public boolean isUpperCasebold()
187 return viewStyle.isUpperCasebold();
192 * @see jalview.api.ViewStyleI#isSeqNameItalics()
195 public boolean isSeqNameItalics()
197 return viewStyle.isSeqNameItalics();
201 * @param colourByReferenceSeq
202 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
205 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
207 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
212 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
215 public void setColourAppliesToAllGroups(boolean b)
217 viewStyle.setColourAppliesToAllGroups(b);
222 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
225 public boolean getColourAppliesToAllGroups()
227 return viewStyle.getColourAppliesToAllGroups();
232 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
235 public boolean getAbovePIDThreshold()
237 return viewStyle.getAbovePIDThreshold();
242 * @see jalview.api.ViewStyleI#setIncrement(int)
245 public void setIncrement(int inc)
247 viewStyle.setIncrement(inc);
252 * @see jalview.api.ViewStyleI#getIncrement()
255 public int getIncrement()
257 return viewStyle.getIncrement();
262 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
265 public void setConservationSelected(boolean b)
267 viewStyle.setConservationSelected(b);
272 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
275 public void setShowHiddenMarkers(boolean show)
277 viewStyle.setShowHiddenMarkers(show);
282 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
285 public boolean getShowHiddenMarkers()
287 return viewStyle.getShowHiddenMarkers();
292 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
295 public void setScaleRightWrapped(boolean b)
297 viewStyle.setScaleRightWrapped(b);
302 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
305 public void setScaleLeftWrapped(boolean b)
307 viewStyle.setScaleLeftWrapped(b);
312 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
315 public void setScaleAboveWrapped(boolean b)
317 viewStyle.setScaleAboveWrapped(b);
322 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
325 public boolean getScaleLeftWrapped()
327 return viewStyle.getScaleLeftWrapped();
332 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
335 public boolean getScaleAboveWrapped()
337 return viewStyle.getScaleAboveWrapped();
342 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
345 public boolean getScaleRightWrapped()
347 return viewStyle.getScaleRightWrapped();
352 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
355 public void setAbovePIDThreshold(boolean b)
357 viewStyle.setAbovePIDThreshold(b);
362 * @see jalview.api.ViewStyleI#setThreshold(int)
365 public void setThreshold(int thresh)
367 viewStyle.setThreshold(thresh);
372 * @see jalview.api.ViewStyleI#getThreshold()
375 public int getThreshold()
377 return viewStyle.getThreshold();
382 * @see jalview.api.ViewStyleI#getShowJVSuffix()
385 public boolean getShowJVSuffix()
387 return viewStyle.getShowJVSuffix();
392 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
395 public void setShowJVSuffix(boolean b)
397 viewStyle.setShowJVSuffix(b);
402 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
405 public void setWrapAlignment(boolean state)
407 viewStyle.setWrapAlignment(state);
408 ranges.setWrappedMode(state);
413 * @see jalview.api.ViewStyleI#setShowText(boolean)
416 public void setShowText(boolean state)
418 viewStyle.setShowText(state);
423 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
426 public void setRenderGaps(boolean state)
428 viewStyle.setRenderGaps(state);
433 * @see jalview.api.ViewStyleI#getColourText()
436 public boolean getColourText()
438 return viewStyle.getColourText();
443 * @see jalview.api.ViewStyleI#setColourText(boolean)
446 public void setColourText(boolean state)
448 viewStyle.setColourText(state);
453 * @see jalview.api.ViewStyleI#getWrapAlignment()
456 public boolean getWrapAlignment()
458 return viewStyle.getWrapAlignment();
463 * @see jalview.api.ViewStyleI#getShowText()
466 public boolean getShowText()
468 return viewStyle.getShowText();
473 * @see jalview.api.ViewStyleI#getWrappedWidth()
476 public int getWrappedWidth()
478 return viewStyle.getWrappedWidth();
483 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
486 public void setWrappedWidth(int w)
488 viewStyle.setWrappedWidth(w);
493 * @see jalview.api.ViewStyleI#getCharHeight()
496 public int getCharHeight()
498 return viewStyle.getCharHeight();
503 * @see jalview.api.ViewStyleI#setCharHeight(int)
506 public void setCharHeight(int h)
508 viewStyle.setCharHeight(h);
513 * @see jalview.api.ViewStyleI#getCharWidth()
516 public int getCharWidth()
518 return viewStyle.getCharWidth();
523 * @see jalview.api.ViewStyleI#setCharWidth(int)
526 public void setCharWidth(int w)
528 viewStyle.setCharWidth(w);
533 * @see jalview.api.ViewStyleI#getShowBoxes()
536 public boolean getShowBoxes()
538 return viewStyle.getShowBoxes();
543 * @see jalview.api.ViewStyleI#getShowUnconserved()
546 public boolean getShowUnconserved()
548 return viewStyle.getShowUnconserved();
552 * @param showunconserved
553 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
556 public void setShowUnconserved(boolean showunconserved)
558 viewStyle.setShowUnconserved(showunconserved);
563 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
566 public void setSeqNameItalics(boolean default1)
568 viewStyle.setSeqNameItalics(default1);
574 public AlignmentI getAlignment()
580 public char getGapCharacter()
582 return alignment.getGapCharacter();
585 protected String sequenceSetID;
588 * probably unused indicator that view is of a dataset rather than an
591 protected boolean isDataset = false;
593 public void setDataset(boolean b)
598 public boolean isDataset()
603 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
605 protected ColumnSelection colSel = new ColumnSelection();
607 public boolean autoCalculateConsensus = true;
609 protected boolean autoCalculateStrucConsensus = true;
611 protected boolean ignoreGapsInConsensusCalculation = false;
613 protected ResidueShaderI residueShading = new ResidueShader();
616 public void setGlobalColourScheme(ColourSchemeI cs)
618 // TODO: logic refactored from AlignFrame changeColour -
619 // TODO: autorecalc stuff should be changed to rely on the worker system
620 // check to see if we should implement a changeColour(cs) method rather than
621 // put the logic in here
622 // - means that caller decides if they want to just modify state and defer
623 // calculation till later or to do all calculations in thread.
627 * only instantiate alignment colouring once, thereafter update it;
628 * this means that any conservation or PID threshold settings
629 * persist when the alignment colour scheme is changed
631 if (residueShading == null)
633 residueShading = new ResidueShader(viewStyle);
635 residueShading.setColourScheme(cs);
637 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
638 // ...problem: groups need these, but do not currently have a ViewStyle
642 if (getConservationSelected())
644 residueShading.setConservation(hconservation);
646 residueShading.alignmentChanged(alignment, hiddenRepSequences);
650 * if 'apply colour to all groups' is selected... do so
651 * (but don't transfer any colour threshold settings to groups)
653 if (getColourAppliesToAllGroups())
655 for (SequenceGroup sg : getAlignment().getGroups())
658 * retain any colour thresholds per group while
659 * changing choice of colour scheme (JAL-2386)
661 sg.setColourScheme(cs);
664 sg.getGroupColourScheme()
665 .alignmentChanged(sg, hiddenRepSequences);
672 public ColourSchemeI getGlobalColourScheme()
674 return residueShading == null ? null : residueShading
679 public ResidueShaderI getResidueShading()
681 return residueShading;
684 protected AlignmentAnnotation consensus;
686 protected AlignmentAnnotation complementConsensus;
688 protected AlignmentAnnotation gapcounts;
690 protected AlignmentAnnotation strucConsensus;
692 protected AlignmentAnnotation conservation;
694 protected AlignmentAnnotation quality;
696 protected AlignmentAnnotation[] groupConsensus;
698 protected AlignmentAnnotation[] groupConservation;
701 * results of alignment consensus analysis for visible portion of view
703 protected ProfilesI hconsensus = null;
706 * results of cDNA complement consensus visible portion of view
708 protected Hashtable[] hcomplementConsensus = null;
711 * results of secondary structure base pair consensus for visible portion of
714 protected Hashtable[] hStrucConsensus = null;
716 protected Conservation hconservation = null;
719 public void setConservation(Conservation cons)
721 hconservation = cons;
725 * percentage gaps allowed in a column before all amino acid properties should
726 * be considered unconserved
728 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
731 public int getConsPercGaps()
737 public void setSequenceConsensusHash(ProfilesI hconsensus)
739 this.hconsensus = hconsensus;
743 public void setComplementConsensusHash(Hashtable[] hconsensus)
745 this.hcomplementConsensus = hconsensus;
749 public ProfilesI getSequenceConsensusHash()
755 public Hashtable[] getComplementConsensusHash()
757 return hcomplementConsensus;
761 public Hashtable[] getRnaStructureConsensusHash()
763 return hStrucConsensus;
767 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
769 this.hStrucConsensus = hStrucConsensus;
774 public AlignmentAnnotation getAlignmentQualityAnnot()
780 public AlignmentAnnotation getAlignmentConservationAnnotation()
786 public AlignmentAnnotation getAlignmentConsensusAnnotation()
792 public AlignmentAnnotation getAlignmentGapAnnotation()
798 public AlignmentAnnotation getComplementConsensusAnnotation()
800 return complementConsensus;
804 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
806 return strucConsensus;
809 protected AlignCalcManagerI calculator = new AlignCalcManager();
812 * trigger update of conservation annotation
814 public void updateConservation(final AlignmentViewPanel ap)
816 // see note in mantis : issue number 8585
817 if (alignment.isNucleotide()
818 || (conservation == null && quality == null)
819 || !autoCalculateConsensus)
824 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
826 calculator.registerWorker(new jalview.workers.ConservationThread(
832 * trigger update of consensus annotation
834 public void updateConsensus(final AlignmentViewPanel ap)
836 // see note in mantis : issue number 8585
837 if (consensus == null || !autoCalculateConsensus)
841 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
843 calculator.registerWorker(new ConsensusThread(this, ap));
847 * A separate thread to compute cDNA consensus for a protein alignment
848 * which has mapping to cDNA
850 final AlignmentI al = this.getAlignment();
851 if (!al.isNucleotide() && al.getCodonFrames() != null
852 && !al.getCodonFrames().isEmpty())
855 * fudge - check first for protein-to-nucleotide mappings
856 * (we don't want to do this for protein-to-protein)
858 boolean doConsensus = false;
859 for (AlignedCodonFrame mapping : al.getCodonFrames())
861 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
862 MapList[] mapLists = mapping.getdnaToProt();
863 // mapLists can be empty if project load has not finished resolving seqs
864 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
873 .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null)
876 .registerWorker(new ComplementConsensusThread(this, ap));
882 // --------START Structure Conservation
883 public void updateStrucConsensus(final AlignmentViewPanel ap)
885 if (autoCalculateStrucConsensus && strucConsensus == null
886 && alignment.isNucleotide() && alignment.hasRNAStructure())
888 // secondary structure has been added - so init the consensus line
892 // see note in mantis : issue number 8585
893 if (strucConsensus == null || !autoCalculateStrucConsensus)
897 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
899 calculator.registerWorker(new StrucConsensusThread(this, ap));
903 public boolean isCalcInProgress()
905 return calculator.isWorking();
909 public boolean isCalculationInProgress(
910 AlignmentAnnotation alignmentAnnotation)
912 if (!alignmentAnnotation.autoCalculated)
916 if (calculator.workingInvolvedWith(alignmentAnnotation))
918 // System.err.println("grey out ("+alignmentAnnotation.label+")");
924 public void setAlignment(AlignmentI align)
926 this.alignment = align;
930 * Clean up references when this viewport is closed
933 public void dispose()
936 * defensively null out references to large objects in case
937 * this object is not garbage collected (as if!)
940 complementConsensus = null;
941 strucConsensus = null;
944 groupConsensus = null;
945 groupConservation = null;
947 hcomplementConsensus = null;
948 // colour scheme may hold reference to consensus
949 residueShading = null;
950 // TODO remove listeners from changeSupport?
951 changeSupport = null;
956 public boolean isClosed()
958 // TODO: check that this isClosed is only true after panel is closed, not
959 // before it is fully constructed.
960 return alignment == null;
964 public AlignCalcManagerI getCalcManager()
970 * should conservation rows be shown for groups
972 protected boolean showGroupConservation = false;
975 * should consensus rows be shown for groups
977 protected boolean showGroupConsensus = false;
980 * should consensus profile be rendered by default
982 protected boolean showSequenceLogo = false;
985 * should consensus profile be rendered normalised to row height
987 protected boolean normaliseSequenceLogo = false;
990 * should consensus histograms be rendered by default
992 protected boolean showConsensusHistogram = true;
995 * @return the showConsensusProfile
998 public boolean isShowSequenceLogo()
1000 return showSequenceLogo;
1004 * @param showSequenceLogo
1007 public void setShowSequenceLogo(boolean showSequenceLogo)
1009 if (showSequenceLogo != this.showSequenceLogo)
1011 // TODO: decouple settings setting from calculation when refactoring
1012 // annotation update method from alignframe to viewport
1013 this.showSequenceLogo = showSequenceLogo;
1014 calculator.updateAnnotationFor(ConsensusThread.class);
1015 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1016 calculator.updateAnnotationFor(StrucConsensusThread.class);
1018 this.showSequenceLogo = showSequenceLogo;
1022 * @param showConsensusHistogram
1023 * the showConsensusHistogram to set
1025 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1027 this.showConsensusHistogram = showConsensusHistogram;
1031 * @return the showGroupConservation
1033 public boolean isShowGroupConservation()
1035 return showGroupConservation;
1039 * @param showGroupConservation
1040 * the showGroupConservation to set
1042 public void setShowGroupConservation(boolean showGroupConservation)
1044 this.showGroupConservation = showGroupConservation;
1048 * @return the showGroupConsensus
1050 public boolean isShowGroupConsensus()
1052 return showGroupConsensus;
1056 * @param showGroupConsensus
1057 * the showGroupConsensus to set
1059 public void setShowGroupConsensus(boolean showGroupConsensus)
1061 this.showGroupConsensus = showGroupConsensus;
1066 * @return flag to indicate if the consensus histogram should be rendered by
1070 public boolean isShowConsensusHistogram()
1072 return this.showConsensusHistogram;
1076 * when set, updateAlignment will always ensure sequences are of equal length
1078 private boolean padGaps = false;
1081 * when set, alignment should be reordered according to a newly opened tree
1083 public boolean sortByTree = false;
1088 * @return null or the currently selected sequence region
1091 public SequenceGroup getSelectionGroup()
1093 return selectionGroup;
1097 * Set the selection group for this window. Also sets the current alignment as
1098 * the context for the group, if it does not already have one.
1101 * - group holding references to sequences in this alignment view
1105 public void setSelectionGroup(SequenceGroup sg)
1107 selectionGroup = sg;
1108 if (sg != null && sg.getContext() == null)
1110 sg.setContext(alignment);
1114 public void setHiddenColumns(HiddenColumns hidden)
1116 this.alignment.setHiddenColumns(hidden);
1120 public ColumnSelection getColumnSelection()
1126 public void setColumnSelection(ColumnSelection colSel)
1128 this.colSel = colSel;
1131 updateHiddenColumns();
1133 isColSelChanged(true);
1141 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1143 return hiddenRepSequences;
1147 public void setHiddenRepSequences(
1148 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1150 this.hiddenRepSequences = hiddenRepSequences;
1154 public boolean hasSelectedColumns()
1156 ColumnSelection columnSelection = getColumnSelection();
1157 return columnSelection != null && columnSelection.hasSelectedColumns();
1161 public boolean hasHiddenColumns()
1163 return alignment.getHiddenColumns() != null
1164 && alignment.getHiddenColumns().hasHiddenColumns();
1167 public void updateHiddenColumns()
1169 // this method doesn't really do anything now. But - it could, since a
1170 // column Selection could be in the process of modification
1171 // hasHiddenColumns = colSel.hasHiddenColumns();
1175 public boolean hasHiddenRows()
1177 return alignment.getHiddenSequences().getSize() > 0;
1180 protected SequenceGroup selectionGroup;
1182 public void setSequenceSetId(String newid)
1184 if (sequenceSetID != null)
1187 .println("Warning - overwriting a sequenceSetId for a viewport!");
1189 sequenceSetID = new String(newid);
1193 public String getSequenceSetId()
1195 if (sequenceSetID == null)
1197 sequenceSetID = alignment.hashCode() + "";
1200 return sequenceSetID;
1204 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1207 protected String viewId = null;
1210 public String getViewId()
1214 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1219 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1221 ignoreGapsInConsensusCalculation = b;
1224 updateConsensus(ap);
1225 if (residueShading != null)
1227 residueShading.setThreshold(residueShading.getThreshold(),
1228 ignoreGapsInConsensusCalculation);
1234 private long sgrouphash = -1, colselhash = -1;
1237 * checks current SelectionGroup against record of last hash value, and
1241 * update the record of last hash value
1243 * @return true if SelectionGroup changed since last call (when b is true)
1245 public boolean isSelectionGroupChanged(boolean b)
1247 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1248 : selectionGroup.hashCode();
1249 if (hc != -1 && hc != sgrouphash)
1261 * checks current colsel against record of last hash value, and optionally
1265 * update the record of last hash value
1266 * @return true if colsel changed since last call (when b is true)
1268 public boolean isColSelChanged(boolean b)
1270 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1271 if (hc != -1 && hc != colselhash)
1283 public boolean isIgnoreGapsConsensus()
1285 return ignoreGapsInConsensusCalculation;
1288 // property change stuff
1289 // JBPNote Prolly only need this in the applet version.
1290 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1293 protected boolean showConservation = true;
1295 protected boolean showQuality = true;
1297 protected boolean showConsensus = true;
1299 protected boolean showOccupancy = true;
1301 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1303 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1305 protected boolean showAutocalculatedAbove;
1308 * when set, view will scroll to show the highlighted position
1310 private boolean followHighlight = true;
1313 * Property change listener for changes in alignment
1318 public void addPropertyChangeListener(
1319 java.beans.PropertyChangeListener listener)
1321 changeSupport.addPropertyChangeListener(listener);
1330 public void removePropertyChangeListener(
1331 java.beans.PropertyChangeListener listener)
1333 changeSupport.removePropertyChangeListener(listener);
1337 * Property change listener for changes in alignment
1346 public void firePropertyChange(String prop, Object oldvalue,
1349 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1352 // common hide/show column stuff
1354 public void hideSelectedColumns()
1356 if (colSel.isEmpty())
1361 colSel.hideSelectedColumns(alignment);
1362 setSelectionGroup(null);
1363 isColSelChanged(true);
1366 public void hideColumns(int start, int end)
1370 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1374 alignment.getHiddenColumns().hideColumns(start, end);
1376 isColSelChanged(true);
1379 public void showColumn(int col)
1381 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1382 isColSelChanged(true);
1385 public void showAllHiddenColumns()
1387 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1388 isColSelChanged(true);
1391 // common hide/show seq stuff
1392 public void showAllHiddenSeqs()
1394 int startSeq = ranges.getStartSeq();
1395 int endSeq = ranges.getEndSeq();
1397 if (alignment.getHiddenSequences().getSize() > 0)
1399 if (selectionGroup == null)
1401 selectionGroup = new SequenceGroup();
1402 selectionGroup.setEndRes(alignment.getWidth() - 1);
1404 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1405 hiddenRepSequences);
1406 for (SequenceI seq : tmp)
1408 selectionGroup.addSequence(seq, false);
1409 setSequenceAnnotationsVisible(seq, true);
1412 hiddenRepSequences = null;
1414 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1416 firePropertyChange("alignment", null, alignment.getSequences());
1417 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1423 public void showSequence(int index)
1425 int startSeq = ranges.getStartSeq();
1426 int endSeq = ranges.getEndSeq();
1428 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1429 index, hiddenRepSequences);
1432 if (selectionGroup == null)
1434 selectionGroup = new SequenceGroup();
1435 selectionGroup.setEndRes(alignment.getWidth() - 1);
1438 for (SequenceI seq : tmp)
1440 selectionGroup.addSequence(seq, false);
1441 setSequenceAnnotationsVisible(seq, true);
1444 // ranges.setStartSeq(startSeq);
1445 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1447 firePropertyChange("alignment", null, alignment.getSequences());
1452 public void hideAllSelectedSeqs()
1454 if (selectionGroup == null || selectionGroup.getSize() < 1)
1459 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1463 setSelectionGroup(null);
1466 public void hideSequence(SequenceI[] seq)
1469 * cache offset to first visible sequence
1471 int startSeq = ranges.getStartSeq();
1475 for (int i = 0; i < seq.length; i++)
1477 alignment.getHiddenSequences().hideSequence(seq[i]);
1478 setSequenceAnnotationsVisible(seq[i], false);
1480 ranges.setStartSeq(startSeq);
1481 firePropertyChange("alignment", null, alignment.getSequences());
1486 * Hides the specified sequence, or the sequences it represents
1489 * the sequence to hide, or keep as representative
1490 * @param representGroup
1491 * if true, hide the current selection group except for the
1492 * representative sequence
1494 public void hideSequences(SequenceI sequence, boolean representGroup)
1496 if (selectionGroup == null || selectionGroup.getSize() < 1)
1498 hideSequence(new SequenceI[] { sequence });
1504 hideRepSequences(sequence, selectionGroup);
1505 setSelectionGroup(null);
1509 int gsize = selectionGroup.getSize();
1510 SequenceI[] hseqs = selectionGroup.getSequences().toArray(
1511 new SequenceI[gsize]);
1513 hideSequence(hseqs);
1514 setSelectionGroup(null);
1519 * Set visibility for any annotations for the given sequence.
1523 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1526 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1529 for (AlignmentAnnotation ann : anns)
1531 if (ann.sequenceRef == sequenceI)
1533 ann.visible = visible;
1539 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1541 int sSize = sg.getSize();
1547 if (hiddenRepSequences == null)
1549 hiddenRepSequences = new Hashtable<>();
1552 hiddenRepSequences.put(repSequence, sg);
1554 // Hide all sequences except the repSequence
1555 SequenceI[] seqs = new SequenceI[sSize - 1];
1557 for (int i = 0; i < sSize; i++)
1559 if (sg.getSequenceAt(i) != repSequence)
1561 if (index == sSize - 1)
1566 seqs[index++] = sg.getSequenceAt(i);
1569 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1570 sg.setHidereps(true); // note: not done in 2.7applet
1577 * @return null or the current reference sequence
1579 public SequenceI getReferenceSeq()
1581 return alignment.getSeqrep();
1586 * @return true iff seq is the reference for the alignment
1588 public boolean isReferenceSeq(SequenceI seq)
1590 return alignment.getSeqrep() == seq;
1596 * @return true if there are sequences represented by this sequence that are
1599 public boolean isHiddenRepSequence(SequenceI seq)
1601 return (hiddenRepSequences != null && hiddenRepSequences
1608 * @return null or a sequence group containing the sequences that seq
1611 public SequenceGroup getRepresentedSequences(SequenceI seq)
1613 return (SequenceGroup) (hiddenRepSequences == null ? null
1614 : hiddenRepSequences.get(seq));
1618 public int adjustForHiddenSeqs(int alignmentIndex)
1620 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1625 public void invertColumnSelection()
1627 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1631 public SequenceI[] getSelectionAsNewSequence()
1633 SequenceI[] sequences;
1634 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1635 // this was the only caller in the applet for this method
1636 // JBPNote: in applet, this method returned references to the alignment
1637 // sequences, and it did not honour the presence/absence of annotation
1638 // attached to the alignment (probably!)
1639 if (selectionGroup == null || selectionGroup.getSize() == 0)
1641 sequences = alignment.getSequencesArray();
1642 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1643 for (int i = 0; i < sequences.length; i++)
1645 // construct new sequence with subset of visible annotation
1646 sequences[i] = new Sequence(sequences[i], annots);
1651 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1658 public SequenceI[] getSequenceSelection()
1660 SequenceI[] sequences = null;
1661 if (selectionGroup != null)
1663 sequences = selectionGroup.getSequencesInOrder(alignment);
1665 if (sequences == null)
1667 sequences = alignment.getSequencesArray();
1673 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1675 return new CigarArray(alignment, alignment.getHiddenColumns(),
1676 (selectedRegionOnly ? selectionGroup : null));
1680 public jalview.datamodel.AlignmentView getAlignmentView(
1681 boolean selectedOnly)
1683 return getAlignmentView(selectedOnly, false);
1687 public jalview.datamodel.AlignmentView getAlignmentView(
1688 boolean selectedOnly, boolean markGroups)
1690 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1691 selectionGroup, alignment.getHiddenColumns() != null
1692 && alignment.getHiddenColumns().hasHiddenColumns(),
1698 public String[] getViewAsString(boolean selectedRegionOnly)
1700 return getViewAsString(selectedRegionOnly, true);
1704 public String[] getViewAsString(boolean selectedRegionOnly,
1705 boolean exportHiddenSeqs)
1707 String[] selection = null;
1708 SequenceI[] seqs = null;
1710 int start = 0, end = 0;
1711 if (selectedRegionOnly && selectionGroup != null)
1713 iSize = selectionGroup.getSize();
1714 seqs = selectionGroup.getSequencesInOrder(alignment);
1715 start = selectionGroup.getStartRes();
1716 end = selectionGroup.getEndRes() + 1;
1720 if (hasHiddenRows() && exportHiddenSeqs)
1722 AlignmentI fullAlignment = alignment.getHiddenSequences()
1723 .getFullAlignment();
1724 iSize = fullAlignment.getHeight();
1725 seqs = fullAlignment.getSequencesArray();
1726 end = fullAlignment.getWidth();
1730 iSize = alignment.getHeight();
1731 seqs = alignment.getSequencesArray();
1732 end = alignment.getWidth();
1736 selection = new String[iSize];
1737 if (alignment.getHiddenColumns() != null
1738 && alignment.getHiddenColumns().hasHiddenColumns())
1740 selection = alignment.getHiddenColumns().getVisibleSequenceStrings(
1745 for (i = 0; i < iSize; i++)
1747 selection[i] = seqs[i].getSequenceAsString(start, end);
1755 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1757 ArrayList<int[]> regions = new ArrayList<>();
1763 HiddenColumns hidden = alignment.getHiddenColumns();
1764 if (hidden != null && hidden.hasHiddenColumns())
1768 start = hidden.adjustForHiddenColumns(start);
1771 end = hidden.getHiddenBoundaryRight(start);
1782 regions.add(new int[] { start, end });
1784 if (hidden != null && hidden.hasHiddenColumns())
1786 start = hidden.adjustForHiddenColumns(end);
1787 start = hidden.getHiddenBoundaryLeft(start) + 1;
1789 } while (end < max);
1791 int[][] startEnd = new int[regions.size()][2];
1797 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1798 boolean selectedOnly)
1800 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1801 AlignmentAnnotation[] aa;
1802 if ((aa = alignment.getAlignmentAnnotation()) != null)
1804 for (AlignmentAnnotation annot : aa)
1806 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1807 if (selectedOnly && selectionGroup != null)
1809 alignment.getHiddenColumns().makeVisibleAnnotation(
1810 selectionGroup.getStartRes(),
1811 selectionGroup.getEndRes(), clone);
1815 alignment.getHiddenColumns().makeVisibleAnnotation(clone);
1824 public boolean isPadGaps()
1830 public void setPadGaps(boolean padGaps)
1832 this.padGaps = padGaps;
1836 * apply any post-edit constraints and trigger any calculations needed after
1837 * an edit has been performed on the alignment
1842 public void alignmentChanged(AlignmentViewPanel ap)
1846 alignment.padGaps();
1848 if (autoCalculateConsensus)
1850 updateConsensus(ap);
1852 if (hconsensus != null && autoCalculateConsensus)
1854 updateConservation(ap);
1856 if (autoCalculateStrucConsensus)
1858 updateStrucConsensus(ap);
1861 // Reset endRes of groups if beyond alignment width
1862 int alWidth = alignment.getWidth();
1863 List<SequenceGroup> groups = alignment.getGroups();
1866 for (SequenceGroup sg : groups)
1868 if (sg.getEndRes() > alWidth)
1870 sg.setEndRes(alWidth - 1);
1875 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1877 selectionGroup.setEndRes(alWidth - 1);
1880 updateAllColourSchemes();
1881 calculator.restartWorkers();
1882 // alignment.adjustSequenceAnnotations();
1886 * reset scope and do calculations for all applied colourschemes on alignment
1888 void updateAllColourSchemes()
1890 ResidueShaderI rs = residueShading;
1893 rs.alignmentChanged(alignment, hiddenRepSequences);
1895 rs.setConsensus(hconsensus);
1896 if (rs.conservationApplied())
1898 rs.setConservation(Conservation.calculateConservation("All",
1899 alignment.getSequences(), 0, alignment.getWidth(), false,
1900 getConsPercGaps(), false));
1904 for (SequenceGroup sg : alignment.getGroups())
1908 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1910 sg.recalcConservation();
1914 protected void initAutoAnnotation()
1916 // TODO: add menu option action that nulls or creates consensus object
1917 // depending on if the user wants to see the annotation or not in a
1918 // specific alignment
1920 if (hconsensus == null && !isDataset)
1922 if (!alignment.isNucleotide())
1931 consensus = new AlignmentAnnotation("Consensus",
1932 MessageManager.getString("label.consensus_descr"),
1933 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1934 initConsensus(consensus);
1937 initComplementConsensus();
1942 * If this is a protein alignment and there are mappings to cDNA, adds the
1943 * cDNA consensus annotation and returns true, else returns false.
1945 public boolean initComplementConsensus()
1947 if (!alignment.isNucleotide())
1949 final List<AlignedCodonFrame> codonMappings = alignment
1951 if (codonMappings != null && !codonMappings.isEmpty())
1953 boolean doConsensus = false;
1954 for (AlignedCodonFrame mapping : codonMappings)
1956 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1957 MapList[] mapLists = mapping.getdnaToProt();
1958 // mapLists can be empty if project load has not finished resolving
1960 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1968 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1970 .getString("label.complement_consensus_descr"),
1971 new Annotation[1], 0f, 100f,
1972 AlignmentAnnotation.BAR_GRAPH);
1973 initConsensus(complementConsensus);
1981 private void initConsensus(AlignmentAnnotation aa)
1984 aa.autoCalculated = true;
1988 alignment.addAnnotation(aa);
1992 // these should be extracted from the view model - style and settings for
1993 // derived annotation
1994 private void initGapCounts()
1998 gapcounts = new AlignmentAnnotation("Occupancy",
1999 MessageManager.getString("label.occupancy_descr"),
2000 new Annotation[1], 0f,
2001 alignment.getHeight(), AlignmentAnnotation.BAR_GRAPH);
2002 gapcounts.hasText = true;
2003 gapcounts.autoCalculated = true;
2004 gapcounts.scaleColLabel = true;
2005 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2007 alignment.addAnnotation(gapcounts);
2011 private void initConservation()
2013 if (showConservation)
2015 if (conservation == null)
2017 conservation = new AlignmentAnnotation("Conservation",
2018 MessageManager.formatMessage("label.conservation_descr",
2019 getConsPercGaps()), new Annotation[1],
2020 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2021 conservation.hasText = true;
2022 conservation.autoCalculated = true;
2023 alignment.addAnnotation(conservation);
2028 private void initQuality()
2032 if (quality == null)
2034 quality = new AlignmentAnnotation("Quality",
2035 MessageManager.getString("label.quality_descr"),
2036 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2037 quality.hasText = true;
2038 quality.autoCalculated = true;
2039 alignment.addAnnotation(quality);
2044 private void initRNAStructure()
2046 if (alignment.hasRNAStructure() && strucConsensus == null)
2048 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2049 MessageManager.getString("label.strucconsensus_descr"),
2050 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2051 strucConsensus.hasText = true;
2052 strucConsensus.autoCalculated = true;
2056 alignment.addAnnotation(strucConsensus);
2064 * @see jalview.api.AlignViewportI#calcPanelHeight()
2067 public int calcPanelHeight()
2069 // setHeight of panels
2070 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2072 int charHeight = getCharHeight();
2075 BitSet graphgrp = new BitSet();
2076 for (AlignmentAnnotation aa : anns)
2080 System.err.println("Null annotation row: ignoring.");
2087 if (aa.graphGroup > -1)
2089 if (graphgrp.get(aa.graphGroup))
2095 graphgrp.set(aa.graphGroup);
2102 aa.height += charHeight;
2112 aa.height += aa.graphHeight;
2120 height += aa.height;
2132 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2133 boolean preserveNewGroupSettings)
2135 boolean updateCalcs = false;
2136 boolean conv = isShowGroupConservation();
2137 boolean cons = isShowGroupConsensus();
2138 boolean showprf = isShowSequenceLogo();
2139 boolean showConsHist = isShowConsensusHistogram();
2140 boolean normLogo = isNormaliseSequenceLogo();
2143 * TODO reorder the annotation rows according to group/sequence ordering on
2146 boolean sortg = true;
2148 // remove old automatic annotation
2149 // add any new annotation
2151 // intersect alignment annotation with alignment groups
2153 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2154 List<SequenceGroup> oldrfs = new ArrayList<>();
2157 for (int an = 0; an < aan.length; an++)
2159 if (aan[an].autoCalculated && aan[an].groupRef != null)
2161 oldrfs.add(aan[an].groupRef);
2162 alignment.deleteAnnotation(aan[an], false);
2166 if (alignment.getGroups() != null)
2168 for (SequenceGroup sg : alignment.getGroups())
2170 updateCalcs = false;
2171 if (applyGlobalSettings
2172 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2174 // set defaults for this group's conservation/consensus
2175 sg.setshowSequenceLogo(showprf);
2176 sg.setShowConsensusHistogram(showConsHist);
2177 sg.setNormaliseSequenceLogo(normLogo);
2182 alignment.addAnnotation(sg.getConservationRow(), 0);
2187 alignment.addAnnotation(sg.getConsensus(), 0);
2189 // refresh the annotation rows
2192 sg.recalcConservation();
2200 public boolean isDisplayReferenceSeq()
2202 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2206 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2208 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2212 public boolean isColourByReferenceSeq()
2214 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2218 public Color getSequenceColour(SequenceI seq)
2220 Color sqc = sequenceColours.get(seq);
2221 return (sqc == null ? Color.white : sqc);
2225 public void setSequenceColour(SequenceI seq, Color col)
2229 sequenceColours.remove(seq);
2233 sequenceColours.put(seq, col);
2238 public void updateSequenceIdColours()
2240 for (SequenceGroup sg : alignment.getGroups())
2242 if (sg.idColour != null)
2244 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2246 sequenceColours.put(s, sg.idColour);
2253 public void clearSequenceColours()
2255 sequenceColours.clear();
2259 public AlignViewportI getCodingComplement()
2261 return this.codingComplement;
2265 * Set this as the (cDna/protein) complement of the given viewport. Also
2266 * ensures the reverse relationship is set on the given viewport.
2269 public void setCodingComplement(AlignViewportI av)
2273 System.err.println("Ignoring recursive setCodingComplement request");
2277 this.codingComplement = av;
2278 // avoid infinite recursion!
2279 if (av.getCodingComplement() != this)
2281 av.setCodingComplement(this);
2287 public boolean isNucleotide()
2289 return getAlignment() == null ? false : getAlignment().isNucleotide();
2293 public FeaturesDisplayedI getFeaturesDisplayed()
2295 return featuresDisplayed;
2299 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2301 featuresDisplayed = featuresDisplayedI;
2305 public boolean areFeaturesDisplayed()
2307 return featuresDisplayed != null
2308 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2315 * features are displayed if true
2318 public void setShowSequenceFeatures(boolean b)
2320 viewStyle.setShowSequenceFeatures(b);
2324 public boolean isShowSequenceFeatures()
2326 return viewStyle.isShowSequenceFeatures();
2330 public void setShowSequenceFeaturesHeight(boolean selected)
2332 viewStyle.setShowSequenceFeaturesHeight(selected);
2336 public boolean isShowSequenceFeaturesHeight()
2338 return viewStyle.isShowSequenceFeaturesHeight();
2342 public void setShowAnnotation(boolean b)
2344 viewStyle.setShowAnnotation(b);
2348 public boolean isShowAnnotation()
2350 return viewStyle.isShowAnnotation();
2354 public boolean isRightAlignIds()
2356 return viewStyle.isRightAlignIds();
2360 public void setRightAlignIds(boolean rightAlignIds)
2362 viewStyle.setRightAlignIds(rightAlignIds);
2366 public boolean getConservationSelected()
2368 return viewStyle.getConservationSelected();
2372 public void setShowBoxes(boolean state)
2374 viewStyle.setShowBoxes(state);
2379 * @see jalview.api.ViewStyleI#getTextColour()
2382 public Color getTextColour()
2384 return viewStyle.getTextColour();
2389 * @see jalview.api.ViewStyleI#getTextColour2()
2392 public Color getTextColour2()
2394 return viewStyle.getTextColour2();
2399 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2402 public int getThresholdTextColour()
2404 return viewStyle.getThresholdTextColour();
2409 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2412 public boolean isConservationColourSelected()
2414 return viewStyle.isConservationColourSelected();
2419 * @see jalview.api.ViewStyleI#isRenderGaps()
2422 public boolean isRenderGaps()
2424 return viewStyle.isRenderGaps();
2429 * @see jalview.api.ViewStyleI#isShowColourText()
2432 public boolean isShowColourText()
2434 return viewStyle.isShowColourText();
2438 * @param conservationColourSelected
2439 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2442 public void setConservationColourSelected(
2443 boolean conservationColourSelected)
2445 viewStyle.setConservationColourSelected(conservationColourSelected);
2449 * @param showColourText
2450 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2453 public void setShowColourText(boolean showColourText)
2455 viewStyle.setShowColourText(showColourText);
2460 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2463 public void setTextColour(Color textColour)
2465 viewStyle.setTextColour(textColour);
2469 * @param thresholdTextColour
2470 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2473 public void setThresholdTextColour(int thresholdTextColour)
2475 viewStyle.setThresholdTextColour(thresholdTextColour);
2479 * @param textColour2
2480 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2483 public void setTextColour2(Color textColour2)
2485 viewStyle.setTextColour2(textColour2);
2489 public ViewStyleI getViewStyle()
2491 return new ViewStyle(viewStyle);
2495 public void setViewStyle(ViewStyleI settingsForView)
2497 viewStyle = new ViewStyle(settingsForView);
2498 if (residueShading != null)
2500 residueShading.setConservationApplied(settingsForView
2501 .isConservationColourSelected());
2506 public boolean sameStyle(ViewStyleI them)
2508 return viewStyle.sameStyle(them);
2513 * @see jalview.api.ViewStyleI#getIdWidth()
2516 public int getIdWidth()
2518 return viewStyle.getIdWidth();
2523 * @see jalview.api.ViewStyleI#setIdWidth(int)
2526 public void setIdWidth(int i)
2528 viewStyle.setIdWidth(i);
2533 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2536 public boolean isCentreColumnLabels()
2538 return viewStyle.isCentreColumnLabels();
2542 * @param centreColumnLabels
2543 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2546 public void setCentreColumnLabels(boolean centreColumnLabels)
2548 viewStyle.setCentreColumnLabels(centreColumnLabels);
2553 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2556 public void setShowDBRefs(boolean showdbrefs)
2558 viewStyle.setShowDBRefs(showdbrefs);
2563 * @see jalview.api.ViewStyleI#isShowDBRefs()
2566 public boolean isShowDBRefs()
2568 return viewStyle.isShowDBRefs();
2573 * @see jalview.api.ViewStyleI#isShowNPFeats()
2576 public boolean isShowNPFeats()
2578 return viewStyle.isShowNPFeats();
2582 * @param shownpfeats
2583 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2586 public void setShowNPFeats(boolean shownpfeats)
2588 viewStyle.setShowNPFeats(shownpfeats);
2591 public abstract StructureSelectionManager getStructureSelectionManager();
2594 * Add one command to the command history list.
2598 public void addToHistoryList(CommandI command)
2600 if (this.historyList != null)
2602 this.historyList.push(command);
2603 broadcastCommand(command, false);
2607 protected void broadcastCommand(CommandI command, boolean undo)
2609 getStructureSelectionManager().commandPerformed(command, undo,
2614 * Add one command to the command redo list.
2618 public void addToRedoList(CommandI command)
2620 if (this.redoList != null)
2622 this.redoList.push(command);
2624 broadcastCommand(command, true);
2628 * Clear the command redo list.
2630 public void clearRedoList()
2632 if (this.redoList != null)
2634 this.redoList.clear();
2638 public void setHistoryList(Deque<CommandI> list)
2640 this.historyList = list;
2643 public Deque<CommandI> getHistoryList()
2645 return this.historyList;
2648 public void setRedoList(Deque<CommandI> list)
2650 this.redoList = list;
2653 public Deque<CommandI> getRedoList()
2655 return this.redoList;
2659 public VamsasSource getVamsasSource()
2664 public SequenceAnnotationOrder getSortAnnotationsBy()
2666 return sortAnnotationsBy;
2669 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2671 this.sortAnnotationsBy = sortAnnotationsBy;
2674 public boolean isShowAutocalculatedAbove()
2676 return showAutocalculatedAbove;
2679 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2681 this.showAutocalculatedAbove = showAutocalculatedAbove;
2685 public boolean isScaleProteinAsCdna()
2687 return viewStyle.isScaleProteinAsCdna();
2691 public void setScaleProteinAsCdna(boolean b)
2693 viewStyle.setScaleProteinAsCdna(b);
2697 public boolean isProteinFontAsCdna()
2699 return viewStyle.isProteinFontAsCdna();
2703 public void setProteinFontAsCdna(boolean b)
2705 viewStyle.setProteinFontAsCdna(b);
2709 * @return true if view should scroll to show the highlighted region of a
2714 public final boolean isFollowHighlight()
2716 return followHighlight;
2720 public final void setFollowHighlight(boolean b)
2722 this.followHighlight = b;
2726 public ViewportRanges getRanges()
2732 * Helper method to populate the SearchResults with the location in the
2733 * complementary alignment to scroll to, in order to match this one.
2736 * the SearchResults to add to
2737 * @return the offset (below top of visible region) of the matched sequence
2739 protected int findComplementScrollTarget(SearchResultsI sr)
2741 final AlignViewportI complement = getCodingComplement();
2742 if (complement == null || !complement.isFollowHighlight())
2746 boolean iAmProtein = !getAlignment().isNucleotide();
2747 AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement
2749 if (proteinAlignment == null)
2753 final List<AlignedCodonFrame> mappings = proteinAlignment
2757 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2758 * residue in the middle column of the visible region. Scroll the
2759 * complementary alignment to line up the corresponding residue.
2762 SequenceI sequence = null;
2765 * locate 'middle' column (true middle if an odd number visible, left of
2766 * middle if an even number visible)
2768 int middleColumn = ranges.getStartRes()
2769 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2770 final HiddenSequences hiddenSequences = getAlignment()
2771 .getHiddenSequences();
2774 * searching to the bottom of the alignment gives smoother scrolling across
2775 * all gapped visible regions
2777 int lastSeq = alignment.getHeight() - 1;
2778 List<AlignedCodonFrame> seqMappings = null;
2779 for (int seqNo = ranges.getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2781 sequence = getAlignment().getSequenceAt(seqNo);
2782 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2786 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2790 seqMappings = MappingUtils
2791 .findMappingsForSequenceAndOthers(sequence, mappings,
2792 getCodingComplement().getAlignment().getSequences());
2793 if (!seqMappings.isEmpty())
2799 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2802 * No ungapped mapped sequence in middle column - do nothing
2806 MappingUtils.addSearchResults(sr, sequence,
2807 sequence.findPosition(middleColumn), seqMappings);
2812 * synthesize a column selection if none exists so it covers the given
2813 * selection group. if wholewidth is false, no column selection is made if the
2814 * selection group covers the whole alignment width.
2819 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2822 if (sg != null && (sgs = sg.getStartRes()) >= 0
2823 && sg.getStartRes() <= (sge = sg.getEndRes())
2824 && !this.hasSelectedColumns())
2826 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2833 colSel = new ColumnSelection();
2835 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2837 colSel.addElement(cspos);
2843 * hold status of current selection group - defined on alignment or not.
2845 private boolean selectionIsDefinedGroup = false;
2848 public boolean isSelectionDefinedGroup()
2850 if (selectionGroup == null)
2854 if (isSelectionGroupChanged(true))
2856 selectionIsDefinedGroup = false;
2857 List<SequenceGroup> gps = alignment.getGroups();
2858 if (gps == null || gps.size() == 0)
2860 selectionIsDefinedGroup = false;
2864 selectionIsDefinedGroup = gps.contains(selectionGroup);
2867 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2871 * null, or currently highlighted results on this view
2873 private SearchResultsI searchResults = null;
2876 public boolean hasSearchResults()
2878 return searchResults != null;
2882 public void setSearchResults(SearchResultsI results)
2884 searchResults = results;
2888 public SearchResultsI getSearchResults()
2890 return searchResults;
2894 * get the consensus sequence as displayed under the PID consensus annotation
2897 * @return consensus sequence as a new sequence object
2899 public SequenceI getConsensusSeq()
2901 if (consensus == null)
2903 updateConsensus(null);
2905 if (consensus == null)
2909 StringBuffer seqs = new StringBuffer();
2910 for (int i = 0; i < consensus.annotations.length; i++)
2912 Annotation annotation = consensus.annotations[i];
2913 if (annotation != null)
2915 String description = annotation.description;
2916 if (description != null && description.startsWith("["))
2918 // consensus is a tie - just pick the first one
2919 seqs.append(description.charAt(1));
2923 seqs.append(annotation.displayCharacter);
2928 SequenceI sq = new Sequence("Consensus", seqs.toString());
2929 sq.setDescription("Percentage Identity Consensus "
2930 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));