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 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);
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;
952 // colour scheme may hold reference to consensus
953 residueShading = null;
954 // TODO remove listeners from changeSupport?
955 changeSupport = null;
960 public boolean isClosed()
962 // TODO: check that this isClosed is only true after panel is closed, not
963 // before it is fully constructed.
964 return alignment == null;
968 public AlignCalcManagerI getCalcManager()
974 * should conservation rows be shown for groups
976 protected boolean showGroupConservation = false;
979 * should consensus rows be shown for groups
981 protected boolean showGroupConsensus = false;
984 * should consensus profile be rendered by default
986 protected boolean showSequenceLogo = false;
989 * should consensus profile be rendered normalised to row height
991 protected boolean normaliseSequenceLogo = false;
994 * should consensus histograms be rendered by default
996 protected boolean showConsensusHistogram = true;
999 * @return the showConsensusProfile
1002 public boolean isShowSequenceLogo()
1004 return showSequenceLogo;
1008 * @param showSequenceLogo
1011 public void setShowSequenceLogo(boolean showSequenceLogo)
1013 if (showSequenceLogo != this.showSequenceLogo)
1015 // TODO: decouple settings setting from calculation when refactoring
1016 // annotation update method from alignframe to viewport
1017 this.showSequenceLogo = showSequenceLogo;
1018 calculator.updateAnnotationFor(ConsensusThread.class);
1019 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1020 calculator.updateAnnotationFor(StrucConsensusThread.class);
1022 this.showSequenceLogo = showSequenceLogo;
1026 * @param showConsensusHistogram
1027 * the showConsensusHistogram to set
1029 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1031 this.showConsensusHistogram = showConsensusHistogram;
1035 * @return the showGroupConservation
1037 public boolean isShowGroupConservation()
1039 return showGroupConservation;
1043 * @param showGroupConservation
1044 * the showGroupConservation to set
1046 public void setShowGroupConservation(boolean showGroupConservation)
1048 this.showGroupConservation = showGroupConservation;
1052 * @return the showGroupConsensus
1054 public boolean isShowGroupConsensus()
1056 return showGroupConsensus;
1060 * @param showGroupConsensus
1061 * the showGroupConsensus to set
1063 public void setShowGroupConsensus(boolean showGroupConsensus)
1065 this.showGroupConsensus = showGroupConsensus;
1070 * @return flag to indicate if the consensus histogram should be rendered by
1074 public boolean isShowConsensusHistogram()
1076 return this.showConsensusHistogram;
1080 * when set, updateAlignment will always ensure sequences are of equal length
1082 private boolean padGaps = false;
1085 * when set, alignment should be reordered according to a newly opened tree
1087 public boolean sortByTree = false;
1092 * @return null or the currently selected sequence region
1095 public SequenceGroup getSelectionGroup()
1097 return selectionGroup;
1101 * Set the selection group for this window. Also sets the current alignment as
1102 * the context for the group, if it does not already have one.
1105 * - group holding references to sequences in this alignment view
1109 public void setSelectionGroup(SequenceGroup sg)
1111 selectionGroup = sg;
1112 if (sg != null && sg.getContext() == null)
1114 sg.setContext(alignment);
1118 public void setHiddenColumns(HiddenColumns hidden)
1120 this.alignment.setHiddenColumns(hidden);
1124 public ColumnSelection getColumnSelection()
1130 public void setColumnSelection(ColumnSelection colSel)
1132 this.colSel = colSel;
1135 updateHiddenColumns();
1137 isColSelChanged(true);
1145 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1147 return hiddenRepSequences;
1151 public void setHiddenRepSequences(
1152 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1154 this.hiddenRepSequences = hiddenRepSequences;
1158 public boolean hasSelectedColumns()
1160 ColumnSelection columnSelection = getColumnSelection();
1161 return columnSelection != null && columnSelection.hasSelectedColumns();
1165 public boolean hasHiddenColumns()
1167 return alignment.getHiddenColumns() != null
1168 && alignment.getHiddenColumns().hasHiddenColumns();
1171 public void updateHiddenColumns()
1173 // this method doesn't really do anything now. But - it could, since a
1174 // column Selection could be in the process of modification
1175 // hasHiddenColumns = colSel.hasHiddenColumns();
1179 public boolean hasHiddenRows()
1181 return alignment.getHiddenSequences().getSize() > 0;
1184 protected SequenceGroup selectionGroup;
1186 public void setSequenceSetId(String newid)
1188 if (sequenceSetID != null)
1191 "Warning - overwriting a sequenceSetId for a viewport!");
1193 sequenceSetID = new String(newid);
1197 public String getSequenceSetId()
1199 if (sequenceSetID == null)
1201 sequenceSetID = alignment.hashCode() + "";
1204 return sequenceSetID;
1208 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1211 protected String viewId = null;
1214 public String getViewId()
1218 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1223 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1225 ignoreGapsInConsensusCalculation = b;
1228 updateConsensus(ap);
1229 if (residueShading != null)
1231 residueShading.setThreshold(residueShading.getThreshold(),
1232 ignoreGapsInConsensusCalculation);
1238 private long sgrouphash = -1, colselhash = -1;
1241 * checks current SelectionGroup against record of last hash value, and
1245 * update the record of last hash value
1247 * @return true if SelectionGroup changed since last call (when b is true)
1249 public boolean isSelectionGroupChanged(boolean b)
1251 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1252 : selectionGroup.hashCode();
1253 if (hc != -1 && hc != sgrouphash)
1265 * checks current colsel against record of last hash value, and optionally
1269 * update the record of last hash value
1270 * @return true if colsel changed since last call (when b is true)
1272 public boolean isColSelChanged(boolean b)
1274 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1275 if (hc != -1 && hc != colselhash)
1287 public boolean isIgnoreGapsConsensus()
1289 return ignoreGapsInConsensusCalculation;
1292 // property change stuff
1293 // JBPNote Prolly only need this in the applet version.
1294 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1297 protected boolean showConservation = true;
1299 protected boolean showQuality = true;
1301 protected boolean showConsensus = true;
1303 protected boolean showOccupancy = true;
1305 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1307 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1309 protected boolean showAutocalculatedAbove;
1312 * when set, view will scroll to show the highlighted position
1314 private boolean followHighlight = true;
1317 * Property change listener for changes in alignment
1322 public void addPropertyChangeListener(
1323 java.beans.PropertyChangeListener listener)
1325 changeSupport.addPropertyChangeListener(listener);
1334 public void removePropertyChangeListener(
1335 java.beans.PropertyChangeListener listener)
1337 changeSupport.removePropertyChangeListener(listener);
1341 * Property change listener for changes in alignment
1350 public void firePropertyChange(String prop, Object oldvalue,
1353 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1356 // common hide/show column stuff
1358 public void hideSelectedColumns()
1360 if (colSel.isEmpty())
1365 colSel.hideSelectedColumns(alignment);
1366 setSelectionGroup(null);
1367 isColSelChanged(true);
1370 public void hideColumns(int start, int end)
1374 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1378 alignment.getHiddenColumns().hideColumns(start, end);
1380 isColSelChanged(true);
1383 public void showColumn(int col)
1385 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1386 isColSelChanged(true);
1389 public void showAllHiddenColumns()
1391 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1392 isColSelChanged(true);
1395 // common hide/show seq stuff
1396 public void showAllHiddenSeqs()
1398 int startSeq = ranges.getStartSeq();
1399 int endSeq = ranges.getEndSeq();
1401 if (alignment.getHiddenSequences().getSize() > 0)
1403 if (selectionGroup == null)
1405 selectionGroup = new SequenceGroup();
1406 selectionGroup.setEndRes(alignment.getWidth() - 1);
1408 List<SequenceI> tmp = alignment.getHiddenSequences()
1409 .showAll(hiddenRepSequences);
1410 for (SequenceI seq : tmp)
1412 selectionGroup.addSequence(seq, false);
1413 setSequenceAnnotationsVisible(seq, true);
1416 hiddenRepSequences = null;
1418 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1420 firePropertyChange("alignment", null, alignment.getSequences());
1421 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1427 public void showSequence(int index)
1429 int startSeq = ranges.getStartSeq();
1430 int endSeq = ranges.getEndSeq();
1432 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1433 hiddenRepSequences);
1436 if (selectionGroup == null)
1438 selectionGroup = new SequenceGroup();
1439 selectionGroup.setEndRes(alignment.getWidth() - 1);
1442 for (SequenceI seq : tmp)
1444 selectionGroup.addSequence(seq, false);
1445 setSequenceAnnotationsVisible(seq, true);
1448 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1450 firePropertyChange("alignment", null, alignment.getSequences());
1455 public void hideAllSelectedSeqs()
1457 if (selectionGroup == null || selectionGroup.getSize() < 1)
1462 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1466 setSelectionGroup(null);
1469 public void hideSequence(SequenceI[] seq)
1472 * cache offset to first visible sequence
1474 int startSeq = ranges.getStartSeq();
1478 for (int i = 0; i < seq.length; i++)
1480 alignment.getHiddenSequences().hideSequence(seq[i]);
1481 setSequenceAnnotationsVisible(seq[i], false);
1483 ranges.setStartSeq(startSeq);
1484 firePropertyChange("alignment", null, alignment.getSequences());
1489 * Hides the specified sequence, or the sequences it represents
1492 * the sequence to hide, or keep as representative
1493 * @param representGroup
1494 * if true, hide the current selection group except for the
1495 * representative sequence
1497 public void hideSequences(SequenceI sequence, boolean representGroup)
1499 if (selectionGroup == null || selectionGroup.getSize() < 1)
1501 hideSequence(new SequenceI[] { sequence });
1507 hideRepSequences(sequence, selectionGroup);
1508 setSelectionGroup(null);
1512 int gsize = selectionGroup.getSize();
1513 SequenceI[] hseqs = selectionGroup.getSequences()
1514 .toArray(new SequenceI[gsize]);
1516 hideSequence(hseqs);
1517 setSelectionGroup(null);
1522 * Set visibility for any annotations for the given sequence.
1526 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1529 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1532 for (AlignmentAnnotation ann : anns)
1534 if (ann.sequenceRef == sequenceI)
1536 ann.visible = visible;
1542 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1544 int sSize = sg.getSize();
1550 if (hiddenRepSequences == null)
1552 hiddenRepSequences = new Hashtable<>();
1555 hiddenRepSequences.put(repSequence, sg);
1557 // Hide all sequences except the repSequence
1558 SequenceI[] seqs = new SequenceI[sSize - 1];
1560 for (int i = 0; i < sSize; i++)
1562 if (sg.getSequenceAt(i) != repSequence)
1564 if (index == sSize - 1)
1569 seqs[index++] = sg.getSequenceAt(i);
1572 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1573 sg.setHidereps(true); // note: not done in 2.7applet
1580 * @return null or the current reference sequence
1582 public SequenceI getReferenceSeq()
1584 return alignment.getSeqrep();
1589 * @return true iff seq is the reference for the alignment
1591 public boolean isReferenceSeq(SequenceI seq)
1593 return alignment.getSeqrep() == seq;
1599 * @return true if there are sequences represented by this sequence that are
1602 public boolean isHiddenRepSequence(SequenceI seq)
1604 return (hiddenRepSequences != null
1605 && hiddenRepSequences.containsKey(seq));
1611 * @return null or a sequence group containing the sequences that seq
1614 public SequenceGroup getRepresentedSequences(SequenceI seq)
1616 return (SequenceGroup) (hiddenRepSequences == null ? null
1617 : hiddenRepSequences.get(seq));
1621 public int adjustForHiddenSeqs(int alignmentIndex)
1623 return alignment.getHiddenSequences()
1624 .adjustForHiddenSeqs(alignmentIndex);
1628 public void invertColumnSelection()
1630 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1634 public SequenceI[] getSelectionAsNewSequence()
1636 SequenceI[] sequences;
1637 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1638 // this was the only caller in the applet for this method
1639 // JBPNote: in applet, this method returned references to the alignment
1640 // sequences, and it did not honour the presence/absence of annotation
1641 // attached to the alignment (probably!)
1642 if (selectionGroup == null || selectionGroup.getSize() == 0)
1644 sequences = alignment.getSequencesArray();
1645 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1646 for (int i = 0; i < sequences.length; i++)
1648 // construct new sequence with subset of visible annotation
1649 sequences[i] = new Sequence(sequences[i], annots);
1654 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1661 public SequenceI[] getSequenceSelection()
1663 SequenceI[] sequences = null;
1664 if (selectionGroup != null)
1666 sequences = selectionGroup.getSequencesInOrder(alignment);
1668 if (sequences == null)
1670 sequences = alignment.getSequencesArray();
1676 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1678 return new CigarArray(alignment, alignment.getHiddenColumns(),
1679 (selectedRegionOnly ? selectionGroup : null));
1683 public jalview.datamodel.AlignmentView getAlignmentView(
1684 boolean selectedOnly)
1686 return getAlignmentView(selectedOnly, false);
1690 public jalview.datamodel.AlignmentView getAlignmentView(
1691 boolean selectedOnly, boolean markGroups)
1693 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1695 alignment.getHiddenColumns() != null
1696 && alignment.getHiddenColumns().hasHiddenColumns(),
1697 selectedOnly, markGroups);
1701 public String[] getViewAsString(boolean selectedRegionOnly)
1703 return getViewAsString(selectedRegionOnly, true);
1707 public String[] getViewAsString(boolean selectedRegionOnly,
1708 boolean exportHiddenSeqs)
1710 String[] selection = null;
1711 SequenceI[] seqs = null;
1713 int start = 0, end = 0;
1714 if (selectedRegionOnly && selectionGroup != null)
1716 iSize = selectionGroup.getSize();
1717 seqs = selectionGroup.getSequencesInOrder(alignment);
1718 start = selectionGroup.getStartRes();
1719 end = selectionGroup.getEndRes() + 1;
1723 if (hasHiddenRows() && exportHiddenSeqs)
1725 AlignmentI fullAlignment = alignment.getHiddenSequences()
1726 .getFullAlignment();
1727 iSize = fullAlignment.getHeight();
1728 seqs = fullAlignment.getSequencesArray();
1729 end = fullAlignment.getWidth();
1733 iSize = alignment.getHeight();
1734 seqs = alignment.getSequencesArray();
1735 end = alignment.getWidth();
1739 selection = new String[iSize];
1740 if (alignment.getHiddenColumns() != null
1741 && alignment.getHiddenColumns().hasHiddenColumns())
1743 selection = alignment.getHiddenColumns()
1744 .getVisibleSequenceStrings(start, end, seqs);
1748 for (i = 0; i < iSize; i++)
1750 selection[i] = seqs[i].getSequenceAsString(start, end);
1758 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1760 ArrayList<int[]> regions = new ArrayList<>();
1766 HiddenColumns hidden = alignment.getHiddenColumns();
1767 if (hidden != null && hidden.hasHiddenColumns())
1771 start = hidden.adjustForHiddenColumns(start);
1774 end = hidden.getHiddenBoundaryRight(start);
1785 regions.add(new int[] { start, end });
1787 if (hidden != null && hidden.hasHiddenColumns())
1789 start = hidden.adjustForHiddenColumns(end);
1790 start = hidden.getHiddenBoundaryLeft(start) + 1;
1792 } while (end < max);
1794 int[][] startEnd = new int[regions.size()][2];
1800 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1801 boolean selectedOnly)
1803 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1804 AlignmentAnnotation[] aa;
1805 if ((aa = alignment.getAlignmentAnnotation()) != null)
1807 for (AlignmentAnnotation annot : aa)
1809 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1810 if (selectedOnly && selectionGroup != null)
1812 alignment.getHiddenColumns().makeVisibleAnnotation(
1813 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1818 alignment.getHiddenColumns().makeVisibleAnnotation(clone);
1827 public boolean isPadGaps()
1833 public void setPadGaps(boolean padGaps)
1835 this.padGaps = padGaps;
1839 * apply any post-edit constraints and trigger any calculations needed after
1840 * an edit has been performed on the alignment
1845 public void alignmentChanged(AlignmentViewPanel ap)
1849 alignment.padGaps();
1851 if (autoCalculateConsensus)
1853 updateConsensus(ap);
1855 if (hconsensus != null && autoCalculateConsensus)
1857 updateConservation(ap);
1859 if (autoCalculateStrucConsensus)
1861 updateStrucConsensus(ap);
1864 // Reset endRes of groups if beyond alignment width
1865 int alWidth = alignment.getWidth();
1866 List<SequenceGroup> groups = alignment.getGroups();
1869 for (SequenceGroup sg : groups)
1871 if (sg.getEndRes() > alWidth)
1873 sg.setEndRes(alWidth - 1);
1878 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1880 selectionGroup.setEndRes(alWidth - 1);
1883 updateAllColourSchemes();
1884 calculator.restartWorkers();
1885 // alignment.adjustSequenceAnnotations();
1889 * reset scope and do calculations for all applied colourschemes on alignment
1891 void updateAllColourSchemes()
1893 ResidueShaderI rs = residueShading;
1896 rs.alignmentChanged(alignment, hiddenRepSequences);
1898 rs.setConsensus(hconsensus);
1899 if (rs.conservationApplied())
1901 rs.setConservation(Conservation.calculateConservation("All",
1902 alignment.getSequences(), 0, alignment.getWidth(), false,
1903 getConsPercGaps(), false));
1907 for (SequenceGroup sg : alignment.getGroups())
1911 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1913 sg.recalcConservation();
1917 protected void initAutoAnnotation()
1919 // TODO: add menu option action that nulls or creates consensus object
1920 // depending on if the user wants to see the annotation or not in a
1921 // specific alignment
1923 if (hconsensus == null && !isDataset)
1925 if (!alignment.isNucleotide())
1934 consensus = new AlignmentAnnotation("Consensus",
1935 MessageManager.getString("label.consensus_descr"),
1936 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1937 initConsensus(consensus);
1940 initComplementConsensus();
1945 * If this is a protein alignment and there are mappings to cDNA, adds the
1946 * cDNA consensus annotation and returns true, else returns false.
1948 public boolean initComplementConsensus()
1950 if (!alignment.isNucleotide())
1952 final List<AlignedCodonFrame> codonMappings = alignment
1954 if (codonMappings != null && !codonMappings.isEmpty())
1956 boolean doConsensus = false;
1957 for (AlignedCodonFrame mapping : codonMappings)
1959 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1960 MapList[] mapLists = mapping.getdnaToProt();
1961 // mapLists can be empty if project load has not finished resolving
1963 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1971 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1973 .getString("label.complement_consensus_descr"),
1974 new Annotation[1], 0f, 100f,
1975 AlignmentAnnotation.BAR_GRAPH);
1976 initConsensus(complementConsensus);
1984 private void initConsensus(AlignmentAnnotation aa)
1987 aa.autoCalculated = true;
1991 alignment.addAnnotation(aa);
1995 // these should be extracted from the view model - style and settings for
1996 // derived annotation
1997 private void initGapCounts()
2001 gapcounts = new AlignmentAnnotation("Occupancy",
2002 MessageManager.getString("label.occupancy_descr"),
2003 new Annotation[1], 0f, alignment.getHeight(),
2004 AlignmentAnnotation.BAR_GRAPH);
2005 gapcounts.hasText = true;
2006 gapcounts.autoCalculated = true;
2007 gapcounts.scaleColLabel = true;
2008 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2010 alignment.addAnnotation(gapcounts);
2014 private void initConservation()
2016 if (showConservation)
2018 if (conservation == null)
2020 conservation = new AlignmentAnnotation("Conservation",
2021 MessageManager.formatMessage("label.conservation_descr",
2023 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2024 conservation.hasText = true;
2025 conservation.autoCalculated = true;
2026 alignment.addAnnotation(conservation);
2031 private void initQuality()
2035 if (quality == null)
2037 quality = new AlignmentAnnotation("Quality",
2038 MessageManager.getString("label.quality_descr"),
2039 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2040 quality.hasText = true;
2041 quality.autoCalculated = true;
2042 alignment.addAnnotation(quality);
2047 private void initRNAStructure()
2049 if (alignment.hasRNAStructure() && strucConsensus == null)
2051 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2052 MessageManager.getString("label.strucconsensus_descr"),
2053 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2054 strucConsensus.hasText = true;
2055 strucConsensus.autoCalculated = true;
2059 alignment.addAnnotation(strucConsensus);
2067 * @see jalview.api.AlignViewportI#calcPanelHeight()
2070 public int calcPanelHeight()
2072 // setHeight of panels
2073 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2075 int charHeight = getCharHeight();
2078 BitSet graphgrp = new BitSet();
2079 for (AlignmentAnnotation aa : anns)
2083 System.err.println("Null annotation row: ignoring.");
2090 if (aa.graphGroup > -1)
2092 if (graphgrp.get(aa.graphGroup))
2098 graphgrp.set(aa.graphGroup);
2105 aa.height += charHeight;
2115 aa.height += aa.graphHeight;
2123 height += aa.height;
2135 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2136 boolean preserveNewGroupSettings)
2138 boolean updateCalcs = false;
2139 boolean conv = isShowGroupConservation();
2140 boolean cons = isShowGroupConsensus();
2141 boolean showprf = isShowSequenceLogo();
2142 boolean showConsHist = isShowConsensusHistogram();
2143 boolean normLogo = isNormaliseSequenceLogo();
2146 * TODO reorder the annotation rows according to group/sequence ordering on
2149 boolean sortg = true;
2151 // remove old automatic annotation
2152 // add any new annotation
2154 // intersect alignment annotation with alignment groups
2156 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2157 List<SequenceGroup> oldrfs = new ArrayList<>();
2160 for (int an = 0; an < aan.length; an++)
2162 if (aan[an].autoCalculated && aan[an].groupRef != null)
2164 oldrfs.add(aan[an].groupRef);
2165 alignment.deleteAnnotation(aan[an], false);
2169 if (alignment.getGroups() != null)
2171 for (SequenceGroup sg : alignment.getGroups())
2173 updateCalcs = false;
2174 if (applyGlobalSettings
2175 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2177 // set defaults for this group's conservation/consensus
2178 sg.setshowSequenceLogo(showprf);
2179 sg.setShowConsensusHistogram(showConsHist);
2180 sg.setNormaliseSequenceLogo(normLogo);
2185 alignment.addAnnotation(sg.getConservationRow(), 0);
2190 alignment.addAnnotation(sg.getConsensus(), 0);
2192 // refresh the annotation rows
2195 sg.recalcConservation();
2203 public boolean isDisplayReferenceSeq()
2205 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2209 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2211 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2215 public boolean isColourByReferenceSeq()
2217 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2221 public Color getSequenceColour(SequenceI seq)
2223 Color sqc = sequenceColours.get(seq);
2224 return (sqc == null ? Color.white : sqc);
2228 public void setSequenceColour(SequenceI seq, Color col)
2232 sequenceColours.remove(seq);
2236 sequenceColours.put(seq, col);
2241 public void updateSequenceIdColours()
2243 for (SequenceGroup sg : alignment.getGroups())
2245 if (sg.idColour != null)
2247 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2249 sequenceColours.put(s, sg.idColour);
2256 public void clearSequenceColours()
2258 sequenceColours.clear();
2262 public AlignViewportI getCodingComplement()
2264 return this.codingComplement;
2268 * Set this as the (cDna/protein) complement of the given viewport. Also
2269 * ensures the reverse relationship is set on the given viewport.
2272 public void setCodingComplement(AlignViewportI av)
2276 System.err.println("Ignoring recursive setCodingComplement request");
2280 this.codingComplement = av;
2281 // avoid infinite recursion!
2282 if (av.getCodingComplement() != this)
2284 av.setCodingComplement(this);
2290 public boolean isNucleotide()
2292 return getAlignment() == null ? false : getAlignment().isNucleotide();
2296 public FeaturesDisplayedI getFeaturesDisplayed()
2298 return featuresDisplayed;
2302 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2304 featuresDisplayed = featuresDisplayedI;
2308 public boolean areFeaturesDisplayed()
2310 return featuresDisplayed != null
2311 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2318 * features are displayed if true
2321 public void setShowSequenceFeatures(boolean b)
2323 viewStyle.setShowSequenceFeatures(b);
2327 public boolean isShowSequenceFeatures()
2329 return viewStyle.isShowSequenceFeatures();
2333 public void setShowSequenceFeaturesHeight(boolean selected)
2335 viewStyle.setShowSequenceFeaturesHeight(selected);
2339 public boolean isShowSequenceFeaturesHeight()
2341 return viewStyle.isShowSequenceFeaturesHeight();
2345 public void setShowAnnotation(boolean b)
2347 viewStyle.setShowAnnotation(b);
2351 public boolean isShowAnnotation()
2353 return viewStyle.isShowAnnotation();
2357 public boolean isRightAlignIds()
2359 return viewStyle.isRightAlignIds();
2363 public void setRightAlignIds(boolean rightAlignIds)
2365 viewStyle.setRightAlignIds(rightAlignIds);
2369 public boolean getConservationSelected()
2371 return viewStyle.getConservationSelected();
2375 public void setShowBoxes(boolean state)
2377 viewStyle.setShowBoxes(state);
2382 * @see jalview.api.ViewStyleI#getTextColour()
2385 public Color getTextColour()
2387 return viewStyle.getTextColour();
2392 * @see jalview.api.ViewStyleI#getTextColour2()
2395 public Color getTextColour2()
2397 return viewStyle.getTextColour2();
2402 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2405 public int getThresholdTextColour()
2407 return viewStyle.getThresholdTextColour();
2412 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2415 public boolean isConservationColourSelected()
2417 return viewStyle.isConservationColourSelected();
2422 * @see jalview.api.ViewStyleI#isRenderGaps()
2425 public boolean isRenderGaps()
2427 return viewStyle.isRenderGaps();
2432 * @see jalview.api.ViewStyleI#isShowColourText()
2435 public boolean isShowColourText()
2437 return viewStyle.isShowColourText();
2441 * @param conservationColourSelected
2442 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2445 public void setConservationColourSelected(
2446 boolean conservationColourSelected)
2448 viewStyle.setConservationColourSelected(conservationColourSelected);
2452 * @param showColourText
2453 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2456 public void setShowColourText(boolean showColourText)
2458 viewStyle.setShowColourText(showColourText);
2463 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2466 public void setTextColour(Color textColour)
2468 viewStyle.setTextColour(textColour);
2472 * @param thresholdTextColour
2473 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2476 public void setThresholdTextColour(int thresholdTextColour)
2478 viewStyle.setThresholdTextColour(thresholdTextColour);
2482 * @param textColour2
2483 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2486 public void setTextColour2(Color textColour2)
2488 viewStyle.setTextColour2(textColour2);
2492 public ViewStyleI getViewStyle()
2494 return new ViewStyle(viewStyle);
2498 public void setViewStyle(ViewStyleI settingsForView)
2500 viewStyle = new ViewStyle(settingsForView);
2501 if (residueShading != null)
2503 residueShading.setConservationApplied(
2504 settingsForView.isConservationColourSelected());
2509 public boolean sameStyle(ViewStyleI them)
2511 return viewStyle.sameStyle(them);
2516 * @see jalview.api.ViewStyleI#getIdWidth()
2519 public int getIdWidth()
2521 return viewStyle.getIdWidth();
2526 * @see jalview.api.ViewStyleI#setIdWidth(int)
2529 public void setIdWidth(int i)
2531 viewStyle.setIdWidth(i);
2536 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2539 public boolean isCentreColumnLabels()
2541 return viewStyle.isCentreColumnLabels();
2545 * @param centreColumnLabels
2546 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2549 public void setCentreColumnLabels(boolean centreColumnLabels)
2551 viewStyle.setCentreColumnLabels(centreColumnLabels);
2556 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2559 public void setShowDBRefs(boolean showdbrefs)
2561 viewStyle.setShowDBRefs(showdbrefs);
2566 * @see jalview.api.ViewStyleI#isShowDBRefs()
2569 public boolean isShowDBRefs()
2571 return viewStyle.isShowDBRefs();
2576 * @see jalview.api.ViewStyleI#isShowNPFeats()
2579 public boolean isShowNPFeats()
2581 return viewStyle.isShowNPFeats();
2585 * @param shownpfeats
2586 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2589 public void setShowNPFeats(boolean shownpfeats)
2591 viewStyle.setShowNPFeats(shownpfeats);
2594 public abstract StructureSelectionManager getStructureSelectionManager();
2597 * Add one command to the command history list.
2601 public void addToHistoryList(CommandI command)
2603 if (this.historyList != null)
2605 this.historyList.push(command);
2606 broadcastCommand(command, false);
2610 protected void broadcastCommand(CommandI command, boolean undo)
2612 getStructureSelectionManager().commandPerformed(command, undo,
2617 * Add one command to the command redo list.
2621 public void addToRedoList(CommandI command)
2623 if (this.redoList != null)
2625 this.redoList.push(command);
2627 broadcastCommand(command, true);
2631 * Clear the command redo list.
2633 public void clearRedoList()
2635 if (this.redoList != null)
2637 this.redoList.clear();
2641 public void setHistoryList(Deque<CommandI> list)
2643 this.historyList = list;
2646 public Deque<CommandI> getHistoryList()
2648 return this.historyList;
2651 public void setRedoList(Deque<CommandI> list)
2653 this.redoList = list;
2656 public Deque<CommandI> getRedoList()
2658 return this.redoList;
2662 public VamsasSource getVamsasSource()
2667 public SequenceAnnotationOrder getSortAnnotationsBy()
2669 return sortAnnotationsBy;
2672 public void setSortAnnotationsBy(
2673 SequenceAnnotationOrder sortAnnotationsBy)
2675 this.sortAnnotationsBy = sortAnnotationsBy;
2678 public boolean isShowAutocalculatedAbove()
2680 return showAutocalculatedAbove;
2683 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2685 this.showAutocalculatedAbove = showAutocalculatedAbove;
2689 public boolean isScaleProteinAsCdna()
2691 return viewStyle.isScaleProteinAsCdna();
2695 public void setScaleProteinAsCdna(boolean b)
2697 viewStyle.setScaleProteinAsCdna(b);
2701 public boolean isProteinFontAsCdna()
2703 return viewStyle.isProteinFontAsCdna();
2707 public void setProteinFontAsCdna(boolean b)
2709 viewStyle.setProteinFontAsCdna(b);
2713 * @return true if view should scroll to show the highlighted region of a
2718 public final boolean isFollowHighlight()
2720 return followHighlight;
2724 public final void setFollowHighlight(boolean b)
2726 this.followHighlight = b;
2730 public ViewportRanges getRanges()
2736 * Helper method to populate the SearchResults with the location in the
2737 * complementary alignment to scroll to, in order to match this one.
2740 * the SearchResults to add to
2741 * @return the offset (below top of visible region) of the matched sequence
2743 protected int findComplementScrollTarget(SearchResultsI sr)
2745 final AlignViewportI complement = getCodingComplement();
2746 if (complement == null || !complement.isFollowHighlight())
2750 boolean iAmProtein = !getAlignment().isNucleotide();
2751 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2752 : complement.getAlignment();
2753 if (proteinAlignment == null)
2757 final List<AlignedCodonFrame> mappings = proteinAlignment
2761 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2762 * residue in the middle column of the visible region. Scroll the
2763 * complementary alignment to line up the corresponding residue.
2766 SequenceI sequence = null;
2769 * locate 'middle' column (true middle if an odd number visible, left of
2770 * middle if an even number visible)
2772 int middleColumn = ranges.getStartRes()
2773 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2774 final HiddenSequences hiddenSequences = getAlignment()
2775 .getHiddenSequences();
2778 * searching to the bottom of the alignment gives smoother scrolling across
2779 * all gapped visible regions
2781 int lastSeq = alignment.getHeight() - 1;
2782 List<AlignedCodonFrame> seqMappings = null;
2783 for (int seqNo = ranges
2784 .getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2786 sequence = getAlignment().getSequenceAt(seqNo);
2787 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2791 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2795 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2797 getCodingComplement().getAlignment().getSequences());
2798 if (!seqMappings.isEmpty())
2804 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2807 * No ungapped mapped sequence in middle column - do nothing
2811 MappingUtils.addSearchResults(sr, sequence,
2812 sequence.findPosition(middleColumn), seqMappings);
2817 * synthesize a column selection if none exists so it covers the given
2818 * selection group. if wholewidth is false, no column selection is made if the
2819 * selection group covers the whole alignment width.
2824 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2827 if (sg != null && (sgs = sg.getStartRes()) >= 0
2828 && sg.getStartRes() <= (sge = sg.getEndRes())
2829 && !this.hasSelectedColumns())
2831 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2838 colSel = new ColumnSelection();
2840 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2842 colSel.addElement(cspos);
2848 * hold status of current selection group - defined on alignment or not.
2850 private boolean selectionIsDefinedGroup = false;
2853 public boolean isSelectionDefinedGroup()
2855 if (selectionGroup == null)
2859 if (isSelectionGroupChanged(true))
2861 selectionIsDefinedGroup = false;
2862 List<SequenceGroup> gps = alignment.getGroups();
2863 if (gps == null || gps.size() == 0)
2865 selectionIsDefinedGroup = false;
2869 selectionIsDefinedGroup = gps.contains(selectionGroup);
2872 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2876 * null, or currently highlighted results on this view
2878 private SearchResultsI searchResults = null;
2881 public boolean hasSearchResults()
2883 return searchResults != null;
2887 public void setSearchResults(SearchResultsI results)
2889 searchResults = results;
2893 public SearchResultsI getSearchResults()
2895 return searchResults;
2899 * get the consensus sequence as displayed under the PID consensus annotation
2902 * @return consensus sequence as a new sequence object
2904 public SequenceI getConsensusSeq()
2906 if (consensus == null)
2908 updateConsensus(null);
2910 if (consensus == null)
2914 StringBuffer seqs = new StringBuffer();
2915 for (int i = 0; i < consensus.annotations.length; i++)
2917 Annotation annotation = consensus.annotations[i];
2918 if (annotation != null)
2920 String description = annotation.description;
2921 if (description != null && description.startsWith("["))
2923 // consensus is a tie - just pick the first one
2924 seqs.append(description.charAt(1));
2928 seqs.append(annotation.displayCharacter);
2933 SequenceI sq = new Sequence("Consensus", seqs.toString());
2934 sq.setDescription("Percentage Identity Consensus "
2935 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));