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
81 implements AlignViewportI, CommandListener, VamsasSource
83 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);
572 public AlignmentI getAlignment()
578 public char getGapCharacter()
580 return alignment.getGapCharacter();
583 protected String sequenceSetID;
586 * probably unused indicator that view is of a dataset rather than an
589 protected boolean isDataset = false;
591 public void setDataset(boolean b)
596 public boolean isDataset()
601 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
603 protected ColumnSelection colSel = new ColumnSelection();
605 public boolean autoCalculateConsensus = true;
607 protected boolean autoCalculateStrucConsensus = true;
609 protected boolean ignoreGapsInConsensusCalculation = false;
611 protected ResidueShaderI residueShading = new ResidueShader();
614 public void setGlobalColourScheme(ColourSchemeI cs)
616 // TODO: logic refactored from AlignFrame changeColour -
617 // TODO: autorecalc stuff should be changed to rely on the worker system
618 // check to see if we should implement a changeColour(cs) method rather than
619 // put the logic in here
620 // - means that caller decides if they want to just modify state and defer
621 // calculation till later or to do all calculations in thread.
625 * only instantiate alignment colouring once, thereafter update it;
626 * this means that any conservation or PID threshold settings
627 * persist when the alignment colour scheme is changed
629 if (residueShading == null)
631 residueShading = new ResidueShader(viewStyle);
633 residueShading.setColourScheme(cs);
635 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
636 // ...problem: groups need these, but do not currently have a ViewStyle
640 if (getConservationSelected())
642 residueShading.setConservation(hconservation);
645 * reset conservation flag in case just set to false if
646 * Conservation was null (calculation still in progress)
648 residueShading.setConservationApplied(getConservationSelected());
649 residueShading.alignmentChanged(alignment, hiddenRepSequences);
653 * if 'apply colour to all groups' is selected... do so
654 * (but don't transfer any colour threshold settings to groups)
656 if (getColourAppliesToAllGroups())
658 for (SequenceGroup sg : getAlignment().getGroups())
661 * retain any colour thresholds per group while
662 * changing choice of colour scheme (JAL-2386)
664 sg.setColourScheme(cs);
667 sg.getGroupColourScheme().alignmentChanged(sg,
675 public ColourSchemeI getGlobalColourScheme()
677 return residueShading == null ? null : residueShading.getColourScheme();
681 public ResidueShaderI getResidueShading()
683 return residueShading;
686 protected AlignmentAnnotation consensus;
688 protected AlignmentAnnotation complementConsensus;
690 protected AlignmentAnnotation gapcounts;
692 protected AlignmentAnnotation strucConsensus;
694 protected AlignmentAnnotation conservation;
696 protected AlignmentAnnotation quality;
698 protected AlignmentAnnotation[] groupConsensus;
700 protected AlignmentAnnotation[] groupConservation;
703 * results of alignment consensus analysis for visible portion of view
705 protected ProfilesI hconsensus = null;
708 * results of cDNA complement consensus visible portion of view
710 protected Hashtable[] hcomplementConsensus = null;
713 * results of secondary structure base pair consensus for visible portion of
716 protected Hashtable[] hStrucConsensus = null;
718 protected Conservation hconservation = null;
721 public void setConservation(Conservation cons)
723 hconservation = cons;
727 * percentage gaps allowed in a column before all amino acid properties should
728 * be considered unconserved
730 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
733 public int getConsPercGaps()
739 public void setSequenceConsensusHash(ProfilesI hconsensus)
741 this.hconsensus = hconsensus;
745 public void setComplementConsensusHash(Hashtable[] hconsensus)
747 this.hcomplementConsensus = hconsensus;
751 public ProfilesI getSequenceConsensusHash()
757 public Hashtable[] getComplementConsensusHash()
759 return hcomplementConsensus;
763 public Hashtable[] getRnaStructureConsensusHash()
765 return hStrucConsensus;
769 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
771 this.hStrucConsensus = hStrucConsensus;
776 public AlignmentAnnotation getAlignmentQualityAnnot()
782 public AlignmentAnnotation getAlignmentConservationAnnotation()
788 public AlignmentAnnotation getAlignmentConsensusAnnotation()
794 public AlignmentAnnotation getAlignmentGapAnnotation()
800 public AlignmentAnnotation getComplementConsensusAnnotation()
802 return complementConsensus;
806 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
808 return strucConsensus;
811 protected AlignCalcManagerI calculator = new AlignCalcManager();
814 * trigger update of conservation annotation
816 public void updateConservation(final AlignmentViewPanel ap)
818 // see note in mantis : issue number 8585
819 if (alignment.isNucleotide()
820 || (conservation == null && quality == null)
821 || !autoCalculateConsensus)
825 if (calculator.getRegisteredWorkersOfClass(
826 jalview.workers.ConservationThread.class) == null)
828 calculator.registerWorker(
829 new jalview.workers.ConservationThread(this, ap));
834 * trigger update of consensus annotation
836 public void updateConsensus(final AlignmentViewPanel ap)
838 // see note in mantis : issue number 8585
839 if (consensus == null || !autoCalculateConsensus)
844 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
846 calculator.registerWorker(new ConsensusThread(this, ap));
850 * A separate thread to compute cDNA consensus for a protein alignment
851 * which has mapping to cDNA
853 final AlignmentI al = this.getAlignment();
854 if (!al.isNucleotide() && al.getCodonFrames() != null
855 && !al.getCodonFrames().isEmpty())
858 * fudge - check first for protein-to-nucleotide mappings
859 * (we don't want to do this for protein-to-protein)
861 boolean doConsensus = false;
862 for (AlignedCodonFrame mapping : al.getCodonFrames())
864 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
865 MapList[] mapLists = mapping.getdnaToProt();
866 // mapLists can be empty if project load has not finished resolving seqs
867 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
875 if (calculator.getRegisteredWorkersOfClass(
876 ComplementConsensusThread.class) == null)
879 .registerWorker(new ComplementConsensusThread(this, ap));
885 // --------START Structure Conservation
886 public void updateStrucConsensus(final AlignmentViewPanel ap)
888 if (autoCalculateStrucConsensus && strucConsensus == null
889 && alignment.isNucleotide() && alignment.hasRNAStructure())
891 // secondary structure has been added - so init the consensus line
895 // see note in mantis : issue number 8585
896 if (strucConsensus == null || !autoCalculateStrucConsensus)
900 if (calculator.getRegisteredWorkersOfClass(
901 StrucConsensusThread.class) == null)
903 calculator.registerWorker(new StrucConsensusThread(this, ap));
907 public boolean isCalcInProgress()
909 return calculator.isWorking();
913 public boolean isCalculationInProgress(
914 AlignmentAnnotation alignmentAnnotation)
916 if (!alignmentAnnotation.autoCalculated)
920 if (calculator.workingInvolvedWith(alignmentAnnotation))
922 // System.err.println("grey out ("+alignmentAnnotation.label+")");
928 public void setAlignment(AlignmentI align)
930 this.alignment = align;
934 * Clean up references when this viewport is closed
937 public void dispose()
940 * defensively null out references to large objects in case
941 * this object is not garbage collected (as if!)
944 complementConsensus = null;
945 strucConsensus = null;
948 groupConsensus = null;
949 groupConservation = null;
951 hcomplementConsensus = null;
953 // colour scheme may hold reference to consensus
954 residueShading = null;
955 // TODO remove listeners from changeSupport?
956 changeSupport = null;
962 public boolean isClosed()
964 // TODO: check that this isClosed is only true after panel is closed, not
965 // before it is fully constructed.
966 return alignment == null;
970 public AlignCalcManagerI getCalcManager()
976 * should conservation rows be shown for groups
978 protected boolean showGroupConservation = false;
981 * should consensus rows be shown for groups
983 protected boolean showGroupConsensus = false;
986 * should consensus profile be rendered by default
988 protected boolean showSequenceLogo = false;
991 * should consensus profile be rendered normalised to row height
993 protected boolean normaliseSequenceLogo = false;
996 * should consensus histograms be rendered by default
998 protected boolean showConsensusHistogram = true;
1001 * @return the showConsensusProfile
1004 public boolean isShowSequenceLogo()
1006 return showSequenceLogo;
1010 * @param showSequenceLogo
1013 public void setShowSequenceLogo(boolean showSequenceLogo)
1015 if (showSequenceLogo != this.showSequenceLogo)
1017 // TODO: decouple settings setting from calculation when refactoring
1018 // annotation update method from alignframe to viewport
1019 this.showSequenceLogo = showSequenceLogo;
1020 calculator.updateAnnotationFor(ConsensusThread.class);
1021 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1022 calculator.updateAnnotationFor(StrucConsensusThread.class);
1024 this.showSequenceLogo = showSequenceLogo;
1028 * @param showConsensusHistogram
1029 * the showConsensusHistogram to set
1031 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1033 this.showConsensusHistogram = showConsensusHistogram;
1037 * @return the showGroupConservation
1039 public boolean isShowGroupConservation()
1041 return showGroupConservation;
1045 * @param showGroupConservation
1046 * the showGroupConservation to set
1048 public void setShowGroupConservation(boolean showGroupConservation)
1050 this.showGroupConservation = showGroupConservation;
1054 * @return the showGroupConsensus
1056 public boolean isShowGroupConsensus()
1058 return showGroupConsensus;
1062 * @param showGroupConsensus
1063 * the showGroupConsensus to set
1065 public void setShowGroupConsensus(boolean showGroupConsensus)
1067 this.showGroupConsensus = showGroupConsensus;
1072 * @return flag to indicate if the consensus histogram should be rendered by
1076 public boolean isShowConsensusHistogram()
1078 return this.showConsensusHistogram;
1082 * when set, updateAlignment will always ensure sequences are of equal length
1084 private boolean padGaps = false;
1087 * when set, alignment should be reordered according to a newly opened tree
1089 public boolean sortByTree = false;
1094 * @return null or the currently selected sequence region
1097 public SequenceGroup getSelectionGroup()
1099 return selectionGroup;
1103 * Set the selection group for this window. Also sets the current alignment as
1104 * the context for the group, if it does not already have one.
1107 * - group holding references to sequences in this alignment view
1111 public void setSelectionGroup(SequenceGroup sg)
1113 selectionGroup = sg;
1114 if (sg != null && sg.getContext() == null)
1116 sg.setContext(alignment);
1120 public void setHiddenColumns(HiddenColumns hidden)
1122 this.alignment.setHiddenColumns(hidden);
1126 public ColumnSelection getColumnSelection()
1132 public void setColumnSelection(ColumnSelection colSel)
1134 this.colSel = colSel;
1137 updateHiddenColumns();
1139 isColSelChanged(true);
1147 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1149 return hiddenRepSequences;
1153 public void setHiddenRepSequences(
1154 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1156 this.hiddenRepSequences = hiddenRepSequences;
1160 public boolean hasSelectedColumns()
1162 ColumnSelection columnSelection = getColumnSelection();
1163 return columnSelection != null && columnSelection.hasSelectedColumns();
1167 public boolean hasHiddenColumns()
1169 return alignment.getHiddenColumns() != null
1170 && alignment.getHiddenColumns().hasHiddenColumns();
1173 public void updateHiddenColumns()
1175 // this method doesn't really do anything now. But - it could, since a
1176 // column Selection could be in the process of modification
1177 // hasHiddenColumns = colSel.hasHiddenColumns();
1181 public boolean hasHiddenRows()
1183 return alignment.getHiddenSequences().getSize() > 0;
1186 protected SequenceGroup selectionGroup;
1188 public void setSequenceSetId(String newid)
1190 if (sequenceSetID != null)
1193 "Warning - overwriting a sequenceSetId for a viewport!");
1195 sequenceSetID = new String(newid);
1199 public String getSequenceSetId()
1201 if (sequenceSetID == null)
1203 sequenceSetID = alignment.hashCode() + "";
1206 return sequenceSetID;
1210 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1213 protected String viewId = null;
1216 public String getViewId()
1220 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1225 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1227 ignoreGapsInConsensusCalculation = b;
1230 updateConsensus(ap);
1231 if (residueShading != null)
1233 residueShading.setThreshold(residueShading.getThreshold(),
1234 ignoreGapsInConsensusCalculation);
1240 private long sgrouphash = -1, colselhash = -1;
1243 * checks current SelectionGroup against record of last hash value, and
1247 * update the record of last hash value
1249 * @return true if SelectionGroup changed since last call (when b is true)
1251 public boolean isSelectionGroupChanged(boolean b)
1253 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1254 : selectionGroup.hashCode();
1255 if (hc != -1 && hc != sgrouphash)
1267 * checks current colsel against record of last hash value, and optionally
1271 * update the record of last hash value
1272 * @return true if colsel changed since last call (when b is true)
1274 public boolean isColSelChanged(boolean b)
1276 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1277 if (hc != -1 && hc != colselhash)
1289 public boolean isIgnoreGapsConsensus()
1291 return ignoreGapsInConsensusCalculation;
1294 // property change stuff
1295 // JBPNote Prolly only need this in the applet version.
1296 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1299 protected boolean showConservation = true;
1301 protected boolean showQuality = true;
1303 protected boolean showConsensus = true;
1305 protected boolean showOccupancy = true;
1307 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1309 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1311 protected boolean showAutocalculatedAbove;
1314 * when set, view will scroll to show the highlighted position
1316 private boolean followHighlight = true;
1319 * Property change listener for changes in alignment
1324 public void addPropertyChangeListener(
1325 java.beans.PropertyChangeListener listener)
1327 changeSupport.addPropertyChangeListener(listener);
1336 public void removePropertyChangeListener(
1337 java.beans.PropertyChangeListener listener)
1339 changeSupport.removePropertyChangeListener(listener);
1343 * Property change listener for changes in alignment
1352 public void firePropertyChange(String prop, Object oldvalue,
1355 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1358 // common hide/show column stuff
1360 public void hideSelectedColumns()
1362 if (colSel.isEmpty())
1367 colSel.hideSelectedColumns(alignment);
1368 setSelectionGroup(null);
1369 isColSelChanged(true);
1372 public void hideColumns(int start, int end)
1376 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1380 alignment.getHiddenColumns().hideColumns(start, end);
1382 isColSelChanged(true);
1385 public void showColumn(int col)
1387 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1388 isColSelChanged(true);
1391 public void showAllHiddenColumns()
1393 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1394 isColSelChanged(true);
1397 // common hide/show seq stuff
1398 public void showAllHiddenSeqs()
1400 int startSeq = ranges.getStartSeq();
1401 int endSeq = ranges.getEndSeq();
1403 if (alignment.getHiddenSequences().getSize() > 0)
1405 if (selectionGroup == null)
1407 selectionGroup = new SequenceGroup();
1408 selectionGroup.setEndRes(alignment.getWidth() - 1);
1410 List<SequenceI> tmp = alignment.getHiddenSequences()
1411 .showAll(hiddenRepSequences);
1412 for (SequenceI seq : tmp)
1414 selectionGroup.addSequence(seq, false);
1415 setSequenceAnnotationsVisible(seq, true);
1418 hiddenRepSequences = null;
1420 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1422 firePropertyChange("alignment", null, alignment.getSequences());
1423 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1429 public void showSequence(int index)
1431 int startSeq = ranges.getStartSeq();
1432 int endSeq = ranges.getEndSeq();
1434 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1435 hiddenRepSequences);
1438 if (selectionGroup == null)
1440 selectionGroup = new SequenceGroup();
1441 selectionGroup.setEndRes(alignment.getWidth() - 1);
1444 for (SequenceI seq : tmp)
1446 selectionGroup.addSequence(seq, false);
1447 setSequenceAnnotationsVisible(seq, true);
1450 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1452 firePropertyChange("alignment", null, alignment.getSequences());
1457 public void hideAllSelectedSeqs()
1459 if (selectionGroup == null || selectionGroup.getSize() < 1)
1464 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1468 setSelectionGroup(null);
1471 public void hideSequence(SequenceI[] seq)
1474 * cache offset to first visible sequence
1476 int startSeq = ranges.getStartSeq();
1480 for (int i = 0; i < seq.length; i++)
1482 alignment.getHiddenSequences().hideSequence(seq[i]);
1483 setSequenceAnnotationsVisible(seq[i], false);
1485 ranges.setStartSeq(startSeq);
1486 firePropertyChange("alignment", null, alignment.getSequences());
1491 * Hides the specified sequence, or the sequences it represents
1494 * the sequence to hide, or keep as representative
1495 * @param representGroup
1496 * if true, hide the current selection group except for the
1497 * representative sequence
1499 public void hideSequences(SequenceI sequence, boolean representGroup)
1501 if (selectionGroup == null || selectionGroup.getSize() < 1)
1503 hideSequence(new SequenceI[] { sequence });
1509 hideRepSequences(sequence, selectionGroup);
1510 setSelectionGroup(null);
1514 int gsize = selectionGroup.getSize();
1515 SequenceI[] hseqs = selectionGroup.getSequences()
1516 .toArray(new SequenceI[gsize]);
1518 hideSequence(hseqs);
1519 setSelectionGroup(null);
1524 * Set visibility for any annotations for the given sequence.
1528 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1531 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1534 for (AlignmentAnnotation ann : anns)
1536 if (ann.sequenceRef == sequenceI)
1538 ann.visible = visible;
1544 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1546 int sSize = sg.getSize();
1552 if (hiddenRepSequences == null)
1554 hiddenRepSequences = new Hashtable<>();
1557 hiddenRepSequences.put(repSequence, sg);
1559 // Hide all sequences except the repSequence
1560 SequenceI[] seqs = new SequenceI[sSize - 1];
1562 for (int i = 0; i < sSize; i++)
1564 if (sg.getSequenceAt(i) != repSequence)
1566 if (index == sSize - 1)
1571 seqs[index++] = sg.getSequenceAt(i);
1574 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1575 sg.setHidereps(true); // note: not done in 2.7applet
1582 * @return null or the current reference sequence
1584 public SequenceI getReferenceSeq()
1586 return alignment.getSeqrep();
1591 * @return true iff seq is the reference for the alignment
1593 public boolean isReferenceSeq(SequenceI seq)
1595 return alignment.getSeqrep() == seq;
1601 * @return true if there are sequences represented by this sequence that are
1604 public boolean isHiddenRepSequence(SequenceI seq)
1606 return (hiddenRepSequences != null
1607 && hiddenRepSequences.containsKey(seq));
1613 * @return null or a sequence group containing the sequences that seq
1616 public SequenceGroup getRepresentedSequences(SequenceI seq)
1618 return (SequenceGroup) (hiddenRepSequences == null ? null
1619 : hiddenRepSequences.get(seq));
1623 public int adjustForHiddenSeqs(int alignmentIndex)
1625 return alignment.getHiddenSequences()
1626 .adjustForHiddenSeqs(alignmentIndex);
1630 public void invertColumnSelection()
1632 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1636 public SequenceI[] getSelectionAsNewSequence()
1638 SequenceI[] sequences;
1639 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1640 // this was the only caller in the applet for this method
1641 // JBPNote: in applet, this method returned references to the alignment
1642 // sequences, and it did not honour the presence/absence of annotation
1643 // attached to the alignment (probably!)
1644 if (selectionGroup == null || selectionGroup.getSize() == 0)
1646 sequences = alignment.getSequencesArray();
1647 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1648 for (int i = 0; i < sequences.length; i++)
1650 // construct new sequence with subset of visible annotation
1651 sequences[i] = new Sequence(sequences[i], annots);
1656 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1663 public SequenceI[] getSequenceSelection()
1665 SequenceI[] sequences = null;
1666 if (selectionGroup != null)
1668 sequences = selectionGroup.getSequencesInOrder(alignment);
1670 if (sequences == null)
1672 sequences = alignment.getSequencesArray();
1678 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1680 return new CigarArray(alignment, alignment.getHiddenColumns(),
1681 (selectedRegionOnly ? selectionGroup : null));
1685 public jalview.datamodel.AlignmentView getAlignmentView(
1686 boolean selectedOnly)
1688 return getAlignmentView(selectedOnly, false);
1692 public jalview.datamodel.AlignmentView getAlignmentView(
1693 boolean selectedOnly, boolean markGroups)
1695 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1697 alignment.getHiddenColumns() != null
1698 && alignment.getHiddenColumns().hasHiddenColumns(),
1699 selectedOnly, markGroups);
1703 public String[] getViewAsString(boolean selectedRegionOnly)
1705 return getViewAsString(selectedRegionOnly, true);
1709 public String[] getViewAsString(boolean selectedRegionOnly,
1710 boolean exportHiddenSeqs)
1712 String[] selection = null;
1713 SequenceI[] seqs = null;
1715 int start = 0, end = 0;
1716 if (selectedRegionOnly && selectionGroup != null)
1718 iSize = selectionGroup.getSize();
1719 seqs = selectionGroup.getSequencesInOrder(alignment);
1720 start = selectionGroup.getStartRes();
1721 end = selectionGroup.getEndRes() + 1;
1725 if (hasHiddenRows() && exportHiddenSeqs)
1727 AlignmentI fullAlignment = alignment.getHiddenSequences()
1728 .getFullAlignment();
1729 iSize = fullAlignment.getHeight();
1730 seqs = fullAlignment.getSequencesArray();
1731 end = fullAlignment.getWidth();
1735 iSize = alignment.getHeight();
1736 seqs = alignment.getSequencesArray();
1737 end = alignment.getWidth();
1741 selection = new String[iSize];
1742 if (alignment.getHiddenColumns() != null
1743 && alignment.getHiddenColumns().hasHiddenColumns())
1745 selection = alignment.getHiddenColumns()
1746 .getVisibleSequenceStrings(start, end, seqs);
1750 for (i = 0; i < iSize; i++)
1752 selection[i] = seqs[i].getSequenceAsString(start, end);
1760 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1762 ArrayList<int[]> regions = new ArrayList<>();
1768 HiddenColumns hidden = alignment.getHiddenColumns();
1769 if (hidden != null && hidden.hasHiddenColumns())
1773 start = hidden.adjustForHiddenColumns(start);
1776 end = hidden.getHiddenBoundaryRight(start);
1787 regions.add(new int[] { start, end });
1789 if (hidden != null && hidden.hasHiddenColumns())
1791 start = hidden.adjustForHiddenColumns(end);
1792 start = hidden.getHiddenBoundaryLeft(start) + 1;
1794 } while (end < max);
1796 int[][] startEnd = new int[regions.size()][2];
1802 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1803 boolean selectedOnly)
1805 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1806 AlignmentAnnotation[] aa;
1807 if ((aa = alignment.getAlignmentAnnotation()) != null)
1809 for (AlignmentAnnotation annot : aa)
1811 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1812 if (selectedOnly && selectionGroup != null)
1814 alignment.getHiddenColumns().makeVisibleAnnotation(
1815 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1820 alignment.getHiddenColumns().makeVisibleAnnotation(clone);
1829 public boolean isPadGaps()
1835 public void setPadGaps(boolean padGaps)
1837 this.padGaps = padGaps;
1841 * apply any post-edit constraints and trigger any calculations needed after
1842 * an edit has been performed on the alignment
1847 public void alignmentChanged(AlignmentViewPanel ap)
1851 alignment.padGaps();
1853 if (autoCalculateConsensus)
1855 updateConsensus(ap);
1857 if (hconsensus != null && autoCalculateConsensus)
1859 updateConservation(ap);
1861 if (autoCalculateStrucConsensus)
1863 updateStrucConsensus(ap);
1866 // Reset endRes of groups if beyond alignment width
1867 int alWidth = alignment.getWidth();
1868 List<SequenceGroup> groups = alignment.getGroups();
1871 for (SequenceGroup sg : groups)
1873 if (sg.getEndRes() > alWidth)
1875 sg.setEndRes(alWidth - 1);
1880 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1882 selectionGroup.setEndRes(alWidth - 1);
1885 updateAllColourSchemes();
1886 calculator.restartWorkers();
1887 // alignment.adjustSequenceAnnotations();
1891 * reset scope and do calculations for all applied colourschemes on alignment
1893 void updateAllColourSchemes()
1895 ResidueShaderI rs = residueShading;
1898 rs.alignmentChanged(alignment, hiddenRepSequences);
1900 rs.setConsensus(hconsensus);
1901 if (rs.conservationApplied())
1903 rs.setConservation(Conservation.calculateConservation("All",
1904 alignment.getSequences(), 0, alignment.getWidth(), false,
1905 getConsPercGaps(), false));
1909 for (SequenceGroup sg : alignment.getGroups())
1913 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1915 sg.recalcConservation();
1919 protected void initAutoAnnotation()
1921 // TODO: add menu option action that nulls or creates consensus object
1922 // depending on if the user wants to see the annotation or not in a
1923 // specific alignment
1925 if (hconsensus == null && !isDataset)
1927 if (!alignment.isNucleotide())
1936 consensus = new AlignmentAnnotation("Consensus",
1937 MessageManager.getString("label.consensus_descr"),
1938 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1939 initConsensus(consensus);
1942 initComplementConsensus();
1947 * If this is a protein alignment and there are mappings to cDNA, adds the
1948 * cDNA consensus annotation and returns true, else returns false.
1950 public boolean initComplementConsensus()
1952 if (!alignment.isNucleotide())
1954 final List<AlignedCodonFrame> codonMappings = alignment
1956 if (codonMappings != null && !codonMappings.isEmpty())
1958 boolean doConsensus = false;
1959 for (AlignedCodonFrame mapping : codonMappings)
1961 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1962 MapList[] mapLists = mapping.getdnaToProt();
1963 // mapLists can be empty if project load has not finished resolving
1965 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1973 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1975 .getString("label.complement_consensus_descr"),
1976 new Annotation[1], 0f, 100f,
1977 AlignmentAnnotation.BAR_GRAPH);
1978 initConsensus(complementConsensus);
1986 private void initConsensus(AlignmentAnnotation aa)
1989 aa.autoCalculated = true;
1993 alignment.addAnnotation(aa);
1997 // these should be extracted from the view model - style and settings for
1998 // derived annotation
1999 private void initGapCounts()
2003 gapcounts = new AlignmentAnnotation("Occupancy",
2004 MessageManager.getString("label.occupancy_descr"),
2005 new Annotation[1], 0f, alignment.getHeight(),
2006 AlignmentAnnotation.BAR_GRAPH);
2007 gapcounts.hasText = true;
2008 gapcounts.autoCalculated = true;
2009 gapcounts.scaleColLabel = true;
2010 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2012 alignment.addAnnotation(gapcounts);
2016 private void initConservation()
2018 if (showConservation)
2020 if (conservation == null)
2022 conservation = new AlignmentAnnotation("Conservation",
2023 MessageManager.formatMessage("label.conservation_descr",
2025 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2026 conservation.hasText = true;
2027 conservation.autoCalculated = true;
2028 alignment.addAnnotation(conservation);
2033 private void initQuality()
2037 if (quality == null)
2039 quality = new AlignmentAnnotation("Quality",
2040 MessageManager.getString("label.quality_descr"),
2041 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2042 quality.hasText = true;
2043 quality.autoCalculated = true;
2044 alignment.addAnnotation(quality);
2049 private void initRNAStructure()
2051 if (alignment.hasRNAStructure() && strucConsensus == null)
2053 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2054 MessageManager.getString("label.strucconsensus_descr"),
2055 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2056 strucConsensus.hasText = true;
2057 strucConsensus.autoCalculated = true;
2061 alignment.addAnnotation(strucConsensus);
2069 * @see jalview.api.AlignViewportI#calcPanelHeight()
2072 public int calcPanelHeight()
2074 // setHeight of panels
2075 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2077 int charHeight = getCharHeight();
2080 BitSet graphgrp = new BitSet();
2081 for (AlignmentAnnotation aa : anns)
2085 System.err.println("Null annotation row: ignoring.");
2092 if (aa.graphGroup > -1)
2094 if (graphgrp.get(aa.graphGroup))
2100 graphgrp.set(aa.graphGroup);
2107 aa.height += charHeight;
2117 aa.height += aa.graphHeight;
2125 height += aa.height;
2137 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2138 boolean preserveNewGroupSettings)
2140 boolean updateCalcs = false;
2141 boolean conv = isShowGroupConservation();
2142 boolean cons = isShowGroupConsensus();
2143 boolean showprf = isShowSequenceLogo();
2144 boolean showConsHist = isShowConsensusHistogram();
2145 boolean normLogo = isNormaliseSequenceLogo();
2148 * TODO reorder the annotation rows according to group/sequence ordering on
2151 boolean sortg = true;
2153 // remove old automatic annotation
2154 // add any new annotation
2156 // intersect alignment annotation with alignment groups
2158 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2159 List<SequenceGroup> oldrfs = new ArrayList<>();
2162 for (int an = 0; an < aan.length; an++)
2164 if (aan[an].autoCalculated && aan[an].groupRef != null)
2166 oldrfs.add(aan[an].groupRef);
2167 alignment.deleteAnnotation(aan[an], false);
2171 if (alignment.getGroups() != null)
2173 for (SequenceGroup sg : alignment.getGroups())
2175 updateCalcs = false;
2176 if (applyGlobalSettings
2177 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2179 // set defaults for this group's conservation/consensus
2180 sg.setshowSequenceLogo(showprf);
2181 sg.setShowConsensusHistogram(showConsHist);
2182 sg.setNormaliseSequenceLogo(normLogo);
2187 alignment.addAnnotation(sg.getConservationRow(), 0);
2192 alignment.addAnnotation(sg.getConsensus(), 0);
2194 // refresh the annotation rows
2197 sg.recalcConservation();
2205 public boolean isDisplayReferenceSeq()
2207 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2211 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2213 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2217 public boolean isColourByReferenceSeq()
2219 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2223 public Color getSequenceColour(SequenceI seq)
2225 Color sqc = sequenceColours.get(seq);
2226 return (sqc == null ? Color.white : sqc);
2230 public void setSequenceColour(SequenceI seq, Color col)
2234 sequenceColours.remove(seq);
2238 sequenceColours.put(seq, col);
2243 public void updateSequenceIdColours()
2245 for (SequenceGroup sg : alignment.getGroups())
2247 if (sg.idColour != null)
2249 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2251 sequenceColours.put(s, sg.idColour);
2258 public void clearSequenceColours()
2260 sequenceColours.clear();
2264 public AlignViewportI getCodingComplement()
2266 return this.codingComplement;
2270 * Set this as the (cDna/protein) complement of the given viewport. Also
2271 * ensures the reverse relationship is set on the given viewport.
2274 public void setCodingComplement(AlignViewportI av)
2278 System.err.println("Ignoring recursive setCodingComplement request");
2282 this.codingComplement = av;
2283 // avoid infinite recursion!
2284 if (av.getCodingComplement() != this)
2286 av.setCodingComplement(this);
2292 public boolean isNucleotide()
2294 return getAlignment() == null ? false : getAlignment().isNucleotide();
2298 public FeaturesDisplayedI getFeaturesDisplayed()
2300 return featuresDisplayed;
2304 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2306 featuresDisplayed = featuresDisplayedI;
2310 public boolean areFeaturesDisplayed()
2312 return featuresDisplayed != null
2313 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2320 * features are displayed if true
2323 public void setShowSequenceFeatures(boolean b)
2325 viewStyle.setShowSequenceFeatures(b);
2329 public boolean isShowSequenceFeatures()
2331 return viewStyle.isShowSequenceFeatures();
2335 public void setShowSequenceFeaturesHeight(boolean selected)
2337 viewStyle.setShowSequenceFeaturesHeight(selected);
2341 public boolean isShowSequenceFeaturesHeight()
2343 return viewStyle.isShowSequenceFeaturesHeight();
2347 public void setShowAnnotation(boolean b)
2349 viewStyle.setShowAnnotation(b);
2353 public boolean isShowAnnotation()
2355 return viewStyle.isShowAnnotation();
2359 public boolean isRightAlignIds()
2361 return viewStyle.isRightAlignIds();
2365 public void setRightAlignIds(boolean rightAlignIds)
2367 viewStyle.setRightAlignIds(rightAlignIds);
2371 public boolean getConservationSelected()
2373 return viewStyle.getConservationSelected();
2377 public void setShowBoxes(boolean state)
2379 viewStyle.setShowBoxes(state);
2384 * @see jalview.api.ViewStyleI#getTextColour()
2387 public Color getTextColour()
2389 return viewStyle.getTextColour();
2394 * @see jalview.api.ViewStyleI#getTextColour2()
2397 public Color getTextColour2()
2399 return viewStyle.getTextColour2();
2404 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2407 public int getThresholdTextColour()
2409 return viewStyle.getThresholdTextColour();
2414 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2417 public boolean isConservationColourSelected()
2419 return viewStyle.isConservationColourSelected();
2424 * @see jalview.api.ViewStyleI#isRenderGaps()
2427 public boolean isRenderGaps()
2429 return viewStyle.isRenderGaps();
2434 * @see jalview.api.ViewStyleI#isShowColourText()
2437 public boolean isShowColourText()
2439 return viewStyle.isShowColourText();
2443 * @param conservationColourSelected
2444 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2447 public void setConservationColourSelected(
2448 boolean conservationColourSelected)
2450 viewStyle.setConservationColourSelected(conservationColourSelected);
2454 * @param showColourText
2455 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2458 public void setShowColourText(boolean showColourText)
2460 viewStyle.setShowColourText(showColourText);
2465 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2468 public void setTextColour(Color textColour)
2470 viewStyle.setTextColour(textColour);
2474 * @param thresholdTextColour
2475 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2478 public void setThresholdTextColour(int thresholdTextColour)
2480 viewStyle.setThresholdTextColour(thresholdTextColour);
2484 * @param textColour2
2485 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2488 public void setTextColour2(Color textColour2)
2490 viewStyle.setTextColour2(textColour2);
2494 public ViewStyleI getViewStyle()
2496 return new ViewStyle(viewStyle);
2500 public void setViewStyle(ViewStyleI settingsForView)
2502 viewStyle = new ViewStyle(settingsForView);
2503 if (residueShading != null)
2505 residueShading.setConservationApplied(
2506 settingsForView.isConservationColourSelected());
2511 public boolean sameStyle(ViewStyleI them)
2513 return viewStyle.sameStyle(them);
2518 * @see jalview.api.ViewStyleI#getIdWidth()
2521 public int getIdWidth()
2523 return viewStyle.getIdWidth();
2528 * @see jalview.api.ViewStyleI#setIdWidth(int)
2531 public void setIdWidth(int i)
2533 viewStyle.setIdWidth(i);
2538 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2541 public boolean isCentreColumnLabels()
2543 return viewStyle.isCentreColumnLabels();
2547 * @param centreColumnLabels
2548 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2551 public void setCentreColumnLabels(boolean centreColumnLabels)
2553 viewStyle.setCentreColumnLabels(centreColumnLabels);
2558 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2561 public void setShowDBRefs(boolean showdbrefs)
2563 viewStyle.setShowDBRefs(showdbrefs);
2568 * @see jalview.api.ViewStyleI#isShowDBRefs()
2571 public boolean isShowDBRefs()
2573 return viewStyle.isShowDBRefs();
2578 * @see jalview.api.ViewStyleI#isShowNPFeats()
2581 public boolean isShowNPFeats()
2583 return viewStyle.isShowNPFeats();
2587 * @param shownpfeats
2588 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2591 public void setShowNPFeats(boolean shownpfeats)
2593 viewStyle.setShowNPFeats(shownpfeats);
2596 public abstract StructureSelectionManager getStructureSelectionManager();
2599 * Add one command to the command history list.
2603 public void addToHistoryList(CommandI command)
2605 if (this.historyList != null)
2607 this.historyList.push(command);
2608 broadcastCommand(command, false);
2612 protected void broadcastCommand(CommandI command, boolean undo)
2614 getStructureSelectionManager().commandPerformed(command, undo,
2619 * Add one command to the command redo list.
2623 public void addToRedoList(CommandI command)
2625 if (this.redoList != null)
2627 this.redoList.push(command);
2629 broadcastCommand(command, true);
2633 * Clear the command redo list.
2635 public void clearRedoList()
2637 if (this.redoList != null)
2639 this.redoList.clear();
2643 public void setHistoryList(Deque<CommandI> list)
2645 this.historyList = list;
2648 public Deque<CommandI> getHistoryList()
2650 return this.historyList;
2653 public void setRedoList(Deque<CommandI> list)
2655 this.redoList = list;
2658 public Deque<CommandI> getRedoList()
2660 return this.redoList;
2664 public VamsasSource getVamsasSource()
2669 public SequenceAnnotationOrder getSortAnnotationsBy()
2671 return sortAnnotationsBy;
2674 public void setSortAnnotationsBy(
2675 SequenceAnnotationOrder sortAnnotationsBy)
2677 this.sortAnnotationsBy = sortAnnotationsBy;
2680 public boolean isShowAutocalculatedAbove()
2682 return showAutocalculatedAbove;
2685 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2687 this.showAutocalculatedAbove = showAutocalculatedAbove;
2691 public boolean isScaleProteinAsCdna()
2693 return viewStyle.isScaleProteinAsCdna();
2697 public void setScaleProteinAsCdna(boolean b)
2699 viewStyle.setScaleProteinAsCdna(b);
2703 public boolean isProteinFontAsCdna()
2705 return viewStyle.isProteinFontAsCdna();
2709 public void setProteinFontAsCdna(boolean b)
2711 viewStyle.setProteinFontAsCdna(b);
2715 * @return true if view should scroll to show the highlighted region of a
2720 public final boolean isFollowHighlight()
2722 return followHighlight;
2726 public final void setFollowHighlight(boolean b)
2728 this.followHighlight = b;
2732 public ViewportRanges getRanges()
2738 * Helper method to populate the SearchResults with the location in the
2739 * complementary alignment to scroll to, in order to match this one.
2742 * the SearchResults to add to
2743 * @return the offset (below top of visible region) of the matched sequence
2745 protected int findComplementScrollTarget(SearchResultsI sr)
2747 final AlignViewportI complement = getCodingComplement();
2748 if (complement == null || !complement.isFollowHighlight())
2752 boolean iAmProtein = !getAlignment().isNucleotide();
2753 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2754 : complement.getAlignment();
2755 if (proteinAlignment == null)
2759 final List<AlignedCodonFrame> mappings = proteinAlignment
2763 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2764 * residue in the middle column of the visible region. Scroll the
2765 * complementary alignment to line up the corresponding residue.
2768 SequenceI sequence = null;
2771 * locate 'middle' column (true middle if an odd number visible, left of
2772 * middle if an even number visible)
2774 int middleColumn = ranges.getStartRes()
2775 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2776 final HiddenSequences hiddenSequences = getAlignment()
2777 .getHiddenSequences();
2780 * searching to the bottom of the alignment gives smoother scrolling across
2781 * all gapped visible regions
2783 int lastSeq = alignment.getHeight() - 1;
2784 List<AlignedCodonFrame> seqMappings = null;
2785 for (int seqNo = ranges
2786 .getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2788 sequence = getAlignment().getSequenceAt(seqNo);
2789 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2793 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2797 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2799 getCodingComplement().getAlignment().getSequences());
2800 if (!seqMappings.isEmpty())
2806 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2809 * No ungapped mapped sequence in middle column - do nothing
2813 MappingUtils.addSearchResults(sr, sequence,
2814 sequence.findPosition(middleColumn), seqMappings);
2819 * synthesize a column selection if none exists so it covers the given
2820 * selection group. if wholewidth is false, no column selection is made if the
2821 * selection group covers the whole alignment width.
2826 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2829 if (sg != null && (sgs = sg.getStartRes()) >= 0
2830 && sg.getStartRes() <= (sge = sg.getEndRes())
2831 && !this.hasSelectedColumns())
2833 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2840 colSel = new ColumnSelection();
2842 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2844 colSel.addElement(cspos);
2850 * hold status of current selection group - defined on alignment or not.
2852 private boolean selectionIsDefinedGroup = false;
2855 public boolean isSelectionDefinedGroup()
2857 if (selectionGroup == null)
2861 if (isSelectionGroupChanged(true))
2863 selectionIsDefinedGroup = false;
2864 List<SequenceGroup> gps = alignment.getGroups();
2865 if (gps == null || gps.size() == 0)
2867 selectionIsDefinedGroup = false;
2871 selectionIsDefinedGroup = gps.contains(selectionGroup);
2874 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2878 * null, or currently highlighted results on this view
2880 private SearchResultsI searchResults = null;
2883 public boolean hasSearchResults()
2885 return searchResults != null;
2889 public void setSearchResults(SearchResultsI results)
2891 searchResults = results;
2895 public SearchResultsI getSearchResults()
2897 return searchResults;
2901 * get the consensus sequence as displayed under the PID consensus annotation
2904 * @return consensus sequence as a new sequence object
2906 public SequenceI getConsensusSeq()
2908 if (consensus == null)
2910 updateConsensus(null);
2912 if (consensus == null)
2916 StringBuffer seqs = new StringBuffer();
2917 for (int i = 0; i < consensus.annotations.length; i++)
2919 Annotation annotation = consensus.annotations[i];
2920 if (annotation != null)
2922 String description = annotation.description;
2923 if (description != null && description.startsWith("["))
2925 // consensus is a tie - just pick the first one
2926 seqs.append(description.charAt(1));
2930 seqs.append(annotation.displayCharacter);
2935 SequenceI sq = new Sequence("Consensus", seqs.toString());
2936 sq.setDescription("Percentage Identity Consensus "
2937 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));