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.analysis.TreeModel;
26 import jalview.api.AlignCalcManagerI;
27 import jalview.api.AlignViewportI;
28 import jalview.api.AlignmentViewPanel;
29 import jalview.api.FeaturesDisplayedI;
30 import jalview.api.ViewStyleI;
31 import jalview.commands.CommandI;
32 import jalview.datamodel.AlignedCodonFrame;
33 import jalview.datamodel.AlignmentAnnotation;
34 import jalview.datamodel.AlignmentI;
35 import jalview.datamodel.AlignmentView;
36 import jalview.datamodel.Annotation;
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.Iterator;
71 import java.util.List;
75 * base class holding visualization and analysis attributes and common logic for
76 * an active alignment view displayed in the GUI
81 public abstract class AlignmentViewport
82 implements AlignViewportI, CommandListener, VamsasSource
84 protected ViewportRanges ranges;
86 protected ViewStyleI viewStyle = new ViewStyle();
89 * A viewport that hosts the cDna view of this (protein), or vice versa (if
92 AlignViewportI codingComplement = null;
94 FeaturesDisplayedI featuresDisplayed = null;
96 protected Deque<CommandI> historyList = new ArrayDeque<>();
98 protected Deque<CommandI> redoList = new ArrayDeque<>();
101 * alignment displayed in the viewport. Please use get/setter
103 protected AlignmentI alignment;
105 public AlignmentViewport(AlignmentI al)
108 ranges = new ViewportRanges(al);
113 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
116 public void setFontName(String name)
118 viewStyle.setFontName(name);
123 * @see jalview.api.ViewStyleI#setFontStyle(int)
126 public void setFontStyle(int style)
128 viewStyle.setFontStyle(style);
133 * @see jalview.api.ViewStyleI#setFontSize(int)
136 public void setFontSize(int size)
138 viewStyle.setFontSize(size);
143 * @see jalview.api.ViewStyleI#getFontStyle()
146 public int getFontStyle()
148 return viewStyle.getFontStyle();
153 * @see jalview.api.ViewStyleI#getFontName()
156 public String getFontName()
158 return viewStyle.getFontName();
163 * @see jalview.api.ViewStyleI#getFontSize()
166 public int getFontSize()
168 return viewStyle.getFontSize();
172 * @param upperCasebold
173 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
176 public void setUpperCasebold(boolean upperCasebold)
178 viewStyle.setUpperCasebold(upperCasebold);
183 * @see jalview.api.ViewStyleI#isUpperCasebold()
186 public boolean isUpperCasebold()
188 return viewStyle.isUpperCasebold();
193 * @see jalview.api.ViewStyleI#isSeqNameItalics()
196 public boolean isSeqNameItalics()
198 return viewStyle.isSeqNameItalics();
202 * @param colourByReferenceSeq
203 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
206 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
208 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
213 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
216 public void setColourAppliesToAllGroups(boolean b)
218 viewStyle.setColourAppliesToAllGroups(b);
223 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
226 public boolean getColourAppliesToAllGroups()
228 return viewStyle.getColourAppliesToAllGroups();
233 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
236 public boolean getAbovePIDThreshold()
238 return viewStyle.getAbovePIDThreshold();
243 * @see jalview.api.ViewStyleI#setIncrement(int)
246 public void setIncrement(int inc)
248 viewStyle.setIncrement(inc);
253 * @see jalview.api.ViewStyleI#getIncrement()
256 public int getIncrement()
258 return viewStyle.getIncrement();
263 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
266 public void setConservationSelected(boolean b)
268 viewStyle.setConservationSelected(b);
273 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
276 public void setShowHiddenMarkers(boolean show)
278 viewStyle.setShowHiddenMarkers(show);
283 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
286 public boolean getShowHiddenMarkers()
288 return viewStyle.getShowHiddenMarkers();
293 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
296 public void setScaleRightWrapped(boolean b)
298 viewStyle.setScaleRightWrapped(b);
303 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
306 public void setScaleLeftWrapped(boolean b)
308 viewStyle.setScaleLeftWrapped(b);
313 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
316 public void setScaleAboveWrapped(boolean b)
318 viewStyle.setScaleAboveWrapped(b);
323 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
326 public boolean getScaleLeftWrapped()
328 return viewStyle.getScaleLeftWrapped();
333 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
336 public boolean getScaleAboveWrapped()
338 return viewStyle.getScaleAboveWrapped();
343 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
346 public boolean getScaleRightWrapped()
348 return viewStyle.getScaleRightWrapped();
353 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
356 public void setAbovePIDThreshold(boolean b)
358 viewStyle.setAbovePIDThreshold(b);
363 * @see jalview.api.ViewStyleI#setThreshold(int)
366 public void setThreshold(int thresh)
368 viewStyle.setThreshold(thresh);
373 * @see jalview.api.ViewStyleI#getThreshold()
376 public int getThreshold()
378 return viewStyle.getThreshold();
383 * @see jalview.api.ViewStyleI#getShowJVSuffix()
386 public boolean getShowJVSuffix()
388 return viewStyle.getShowJVSuffix();
393 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
396 public void setShowJVSuffix(boolean b)
398 viewStyle.setShowJVSuffix(b);
403 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
406 public void setWrapAlignment(boolean state)
408 viewStyle.setWrapAlignment(state);
409 ranges.setWrappedMode(state);
414 * @see jalview.api.ViewStyleI#setShowText(boolean)
417 public void setShowText(boolean state)
419 viewStyle.setShowText(state);
424 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
427 public void setRenderGaps(boolean state)
429 viewStyle.setRenderGaps(state);
434 * @see jalview.api.ViewStyleI#getColourText()
437 public boolean getColourText()
439 return viewStyle.getColourText();
444 * @see jalview.api.ViewStyleI#setColourText(boolean)
447 public void setColourText(boolean state)
449 viewStyle.setColourText(state);
454 * @see jalview.api.ViewStyleI#getWrapAlignment()
457 public boolean getWrapAlignment()
459 return viewStyle.getWrapAlignment();
464 * @see jalview.api.ViewStyleI#getShowText()
467 public boolean getShowText()
469 return viewStyle.getShowText();
474 * @see jalview.api.ViewStyleI#getWrappedWidth()
477 public int getWrappedWidth()
479 return viewStyle.getWrappedWidth();
484 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
487 public void setWrappedWidth(int w)
489 viewStyle.setWrappedWidth(w);
494 * @see jalview.api.ViewStyleI#getCharHeight()
497 public int getCharHeight()
499 return viewStyle.getCharHeight();
504 * @see jalview.api.ViewStyleI#setCharHeight(int)
507 public void setCharHeight(int h)
509 viewStyle.setCharHeight(h);
514 * @see jalview.api.ViewStyleI#getCharWidth()
517 public int getCharWidth()
519 return viewStyle.getCharWidth();
524 * @see jalview.api.ViewStyleI#setCharWidth(int)
527 public void setCharWidth(int w)
529 viewStyle.setCharWidth(w);
534 * @see jalview.api.ViewStyleI#getShowBoxes()
537 public boolean getShowBoxes()
539 return viewStyle.getShowBoxes();
544 * @see jalview.api.ViewStyleI#getShowUnconserved()
547 public boolean getShowUnconserved()
549 return viewStyle.getShowUnconserved();
553 * @param showunconserved
554 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
557 public void setShowUnconserved(boolean showunconserved)
559 viewStyle.setShowUnconserved(showunconserved);
564 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
567 public void setSeqNameItalics(boolean default1)
569 viewStyle.setSeqNameItalics(default1);
573 public AlignmentI getAlignment()
579 public char getGapCharacter()
581 return alignment.getGapCharacter();
584 protected String sequenceSetID;
587 * probably unused indicator that view is of a dataset rather than an
590 protected boolean isDataset = false;
592 public void setDataset(boolean b)
597 public boolean isDataset()
602 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
604 protected ColumnSelection colSel = new ColumnSelection();
606 public boolean autoCalculateConsensus = true;
608 protected boolean autoCalculateStrucConsensus = true;
610 protected boolean ignoreGapsInConsensusCalculation = false;
612 protected ResidueShaderI residueShading = new ResidueShader();
615 public void setGlobalColourScheme(ColourSchemeI cs)
617 // TODO: logic refactored from AlignFrame changeColour -
618 // TODO: autorecalc stuff should be changed to rely on the worker system
619 // check to see if we should implement a changeColour(cs) method rather than
620 // put the logic in here
621 // - means that caller decides if they want to just modify state and defer
622 // calculation till later or to do all calculations in thread.
626 * only instantiate alignment colouring once, thereafter update it;
627 * this means that any conservation or PID threshold settings
628 * persist when the alignment colour scheme is changed
630 if (residueShading == null)
632 residueShading = new ResidueShader(viewStyle);
634 residueShading.setColourScheme(cs);
636 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
637 // ...problem: groups need these, but do not currently have a ViewStyle
641 if (getConservationSelected())
643 residueShading.setConservation(hconservation);
646 * reset conservation flag in case just set to false if
647 * Conservation was null (calculation still in progress)
649 residueShading.setConservationApplied(getConservationSelected());
650 residueShading.alignmentChanged(alignment, hiddenRepSequences);
654 * if 'apply colour to all groups' is selected... do so
655 * (but don't transfer any colour threshold settings to groups)
657 if (getColourAppliesToAllGroups())
659 for (SequenceGroup sg : getAlignment().getGroups())
662 * retain any colour thresholds per group while
663 * changing choice of colour scheme (JAL-2386)
665 sg.setColourScheme(cs.getInstance(sg, hiddenRepSequences));
668 sg.getGroupColourScheme().alignmentChanged(sg,
676 public ColourSchemeI getGlobalColourScheme()
678 return residueShading == null ? null : residueShading.getColourScheme();
682 public ResidueShaderI getResidueShading()
684 return residueShading;
687 protected AlignmentAnnotation consensus;
689 protected AlignmentAnnotation complementConsensus;
691 protected AlignmentAnnotation gapcounts;
693 protected AlignmentAnnotation strucConsensus;
695 protected AlignmentAnnotation conservation;
697 protected AlignmentAnnotation quality;
699 protected AlignmentAnnotation[] groupConsensus;
701 protected AlignmentAnnotation[] groupConservation;
704 * results of alignment consensus analysis for visible portion of view
706 protected ProfilesI hconsensus = null;
709 * results of cDNA complement consensus visible portion of view
711 protected Hashtable[] hcomplementConsensus = null;
714 * results of secondary structure base pair consensus for visible portion of
717 protected Hashtable[] hStrucConsensus = null;
719 protected Conservation hconservation = null;
722 public void setConservation(Conservation cons)
724 hconservation = cons;
728 * percentage gaps allowed in a column before all amino acid properties should
729 * be considered unconserved
731 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
734 public int getConsPercGaps()
740 public void setSequenceConsensusHash(ProfilesI hconsensus)
742 this.hconsensus = hconsensus;
746 public void setComplementConsensusHash(Hashtable[] hconsensus)
748 this.hcomplementConsensus = hconsensus;
752 public ProfilesI getSequenceConsensusHash()
758 public Hashtable[] getComplementConsensusHash()
760 return hcomplementConsensus;
764 public Hashtable[] getRnaStructureConsensusHash()
766 return hStrucConsensus;
770 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
772 this.hStrucConsensus = hStrucConsensus;
777 public AlignmentAnnotation getAlignmentQualityAnnot()
783 public AlignmentAnnotation getAlignmentConservationAnnotation()
789 public AlignmentAnnotation getAlignmentConsensusAnnotation()
795 public AlignmentAnnotation getAlignmentGapAnnotation()
801 public AlignmentAnnotation getComplementConsensusAnnotation()
803 return complementConsensus;
807 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
809 return strucConsensus;
812 protected AlignCalcManagerI calculator = new AlignCalcManager();
815 * trigger update of conservation annotation
817 public void updateConservation(final AlignmentViewPanel ap)
819 // see note in mantis : issue number 8585
820 if (alignment.isNucleotide()
821 || (conservation == null && quality == null)
822 || !autoCalculateConsensus)
826 if (calculator.getRegisteredWorkersOfClass(
827 jalview.workers.ConservationThread.class) == null)
829 calculator.registerWorker(
830 new jalview.workers.ConservationThread(this, ap));
835 * trigger update of consensus annotation
837 public void updateConsensus(final AlignmentViewPanel ap)
839 // see note in mantis : issue number 8585
840 if (consensus == null || !autoCalculateConsensus)
845 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
847 calculator.registerWorker(new ConsensusThread(this, ap));
851 * A separate thread to compute cDNA consensus for a protein alignment
852 * which has mapping to cDNA
854 final AlignmentI al = this.getAlignment();
855 if (!al.isNucleotide() && al.getCodonFrames() != null
856 && !al.getCodonFrames().isEmpty())
859 * fudge - check first for protein-to-nucleotide mappings
860 * (we don't want to do this for protein-to-protein)
862 boolean doConsensus = false;
863 for (AlignedCodonFrame mapping : al.getCodonFrames())
865 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
866 MapList[] mapLists = mapping.getdnaToProt();
867 // mapLists can be empty if project load has not finished resolving seqs
868 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
876 if (calculator.getRegisteredWorkersOfClass(
877 ComplementConsensusThread.class) == null)
880 .registerWorker(new ComplementConsensusThread(this, ap));
886 // --------START Structure Conservation
887 public void updateStrucConsensus(final AlignmentViewPanel ap)
889 if (autoCalculateStrucConsensus && strucConsensus == null
890 && alignment.isNucleotide() && alignment.hasRNAStructure())
892 // secondary structure has been added - so init the consensus line
896 // see note in mantis : issue number 8585
897 if (strucConsensus == null || !autoCalculateStrucConsensus)
901 if (calculator.getRegisteredWorkersOfClass(
902 StrucConsensusThread.class) == null)
904 calculator.registerWorker(new StrucConsensusThread(this, ap));
908 public boolean isCalcInProgress()
910 return calculator.isWorking();
914 public boolean isCalculationInProgress(
915 AlignmentAnnotation alignmentAnnotation)
917 if (!alignmentAnnotation.autoCalculated)
921 if (calculator.workingInvolvedWith(alignmentAnnotation))
923 // System.err.println("grey out ("+alignmentAnnotation.label+")");
929 public void setAlignment(AlignmentI align)
931 this.alignment = align;
935 * Clean up references when this viewport is closed
938 public void dispose()
941 * defensively null out references to large objects in case
942 * this object is not garbage collected (as if!)
945 complementConsensus = null;
946 strucConsensus = null;
949 groupConsensus = null;
950 groupConservation = null;
952 hconservation = null;
953 hcomplementConsensus = null;
956 residueShading = null; // may hold a reference to Consensus
957 changeSupport = null;
960 selectionGroup = null;
965 public boolean isClosed()
967 // TODO: check that this isClosed is only true after panel is closed, not
968 // before it is fully constructed.
969 return alignment == null;
973 public AlignCalcManagerI getCalcManager()
979 * should conservation rows be shown for groups
981 protected boolean showGroupConservation = false;
984 * should consensus rows be shown for groups
986 protected boolean showGroupConsensus = false;
989 * should consensus profile be rendered by default
991 protected boolean showSequenceLogo = false;
994 * should consensus profile be rendered normalised to row height
996 protected boolean normaliseSequenceLogo = false;
999 * should consensus histograms be rendered by default
1001 protected boolean showConsensusHistogram = true;
1004 * @return the showConsensusProfile
1007 public boolean isShowSequenceLogo()
1009 return showSequenceLogo;
1013 * @param showSequenceLogo
1016 public void setShowSequenceLogo(boolean showSequenceLogo)
1018 if (showSequenceLogo != this.showSequenceLogo)
1020 // TODO: decouple settings setting from calculation when refactoring
1021 // annotation update method from alignframe to viewport
1022 this.showSequenceLogo = showSequenceLogo;
1023 calculator.updateAnnotationFor(ConsensusThread.class);
1024 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1025 calculator.updateAnnotationFor(StrucConsensusThread.class);
1027 this.showSequenceLogo = showSequenceLogo;
1031 * @param showConsensusHistogram
1032 * the showConsensusHistogram to set
1034 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1036 this.showConsensusHistogram = showConsensusHistogram;
1040 * @return the showGroupConservation
1042 public boolean isShowGroupConservation()
1044 return showGroupConservation;
1048 * @param showGroupConservation
1049 * the showGroupConservation to set
1051 public void setShowGroupConservation(boolean showGroupConservation)
1053 this.showGroupConservation = showGroupConservation;
1057 * @return the showGroupConsensus
1059 public boolean isShowGroupConsensus()
1061 return showGroupConsensus;
1065 * @param showGroupConsensus
1066 * the showGroupConsensus to set
1068 public void setShowGroupConsensus(boolean showGroupConsensus)
1070 this.showGroupConsensus = showGroupConsensus;
1075 * @return flag to indicate if the consensus histogram should be rendered by
1079 public boolean isShowConsensusHistogram()
1081 return this.showConsensusHistogram;
1085 * when set, updateAlignment will always ensure sequences are of equal length
1087 private boolean padGaps = false;
1090 * when set, alignment should be reordered according to a newly opened tree
1092 public boolean sortByTree = false;
1097 * @return null or the currently selected sequence region
1100 public SequenceGroup getSelectionGroup()
1102 return selectionGroup;
1106 * Set the selection group for this window. Also sets the current alignment as
1107 * the context for the group, if it does not already have one.
1110 * - group holding references to sequences in this alignment view
1114 public void setSelectionGroup(SequenceGroup sg)
1116 selectionGroup = sg;
1117 if (sg != null && sg.getContext() == null)
1119 sg.setContext(alignment);
1123 public void setHiddenColumns(HiddenColumns hidden)
1125 this.alignment.setHiddenColumns(hidden);
1129 public ColumnSelection getColumnSelection()
1135 public void setColumnSelection(ColumnSelection colSel)
1137 this.colSel = colSel;
1140 updateHiddenColumns();
1142 isColSelChanged(true);
1150 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1152 return hiddenRepSequences;
1156 public void setHiddenRepSequences(
1157 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1159 this.hiddenRepSequences = hiddenRepSequences;
1163 public boolean hasSelectedColumns()
1165 ColumnSelection columnSelection = getColumnSelection();
1166 return columnSelection != null && columnSelection.hasSelectedColumns();
1170 public boolean hasHiddenColumns()
1172 return alignment.getHiddenColumns() != null
1173 && alignment.getHiddenColumns().hasHiddenColumns();
1176 public void updateHiddenColumns()
1178 // this method doesn't really do anything now. But - it could, since a
1179 // column Selection could be in the process of modification
1180 // hasHiddenColumns = colSel.hasHiddenColumns();
1184 public boolean hasHiddenRows()
1186 return alignment.getHiddenSequences().getSize() > 0;
1189 protected SequenceGroup selectionGroup;
1191 public void setSequenceSetId(String newid)
1193 if (sequenceSetID != null)
1196 "Warning - overwriting a sequenceSetId for a viewport!");
1198 sequenceSetID = new String(newid);
1202 public String getSequenceSetId()
1204 if (sequenceSetID == null)
1206 sequenceSetID = alignment.hashCode() + "";
1209 return sequenceSetID;
1213 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1216 protected String viewId = null;
1219 public String getViewId()
1223 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1228 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1230 ignoreGapsInConsensusCalculation = b;
1233 updateConsensus(ap);
1234 if (residueShading != null)
1236 residueShading.setThreshold(residueShading.getThreshold(),
1237 ignoreGapsInConsensusCalculation);
1243 private long sgrouphash = -1, colselhash = -1;
1246 * checks current SelectionGroup against record of last hash value, and
1250 * update the record of last hash value
1252 * @return true if SelectionGroup changed since last call (when b is true)
1254 public boolean isSelectionGroupChanged(boolean b)
1256 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1257 : selectionGroup.hashCode();
1258 if (hc != -1 && hc != sgrouphash)
1270 * checks current colsel against record of last hash value, and optionally
1274 * update the record of last hash value
1275 * @return true if colsel changed since last call (when b is true)
1277 public boolean isColSelChanged(boolean b)
1279 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1280 if (hc != -1 && hc != colselhash)
1292 public boolean isIgnoreGapsConsensus()
1294 return ignoreGapsInConsensusCalculation;
1297 // property change stuff
1298 // JBPNote Prolly only need this in the applet version.
1299 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1302 protected boolean showConservation = true;
1304 protected boolean showQuality = true;
1306 protected boolean showConsensus = true;
1308 protected boolean showOccupancy = true;
1310 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1312 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1314 protected boolean showAutocalculatedAbove;
1317 * when set, view will scroll to show the highlighted position
1319 private boolean followHighlight = true;
1322 * Property change listener for changes in alignment
1327 public void addPropertyChangeListener(
1328 java.beans.PropertyChangeListener listener)
1330 changeSupport.addPropertyChangeListener(listener);
1339 public void removePropertyChangeListener(
1340 java.beans.PropertyChangeListener listener)
1342 if (changeSupport != null)
1344 changeSupport.removePropertyChangeListener(listener);
1349 * Property change listener for changes in alignment
1358 public void firePropertyChange(String prop, Object oldvalue,
1361 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1364 // common hide/show column stuff
1366 public void hideSelectedColumns()
1368 if (colSel.isEmpty())
1373 colSel.hideSelectedColumns(alignment);
1374 setSelectionGroup(null);
1375 isColSelChanged(true);
1378 public void hideColumns(int start, int end)
1382 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1386 alignment.getHiddenColumns().hideColumns(start, end);
1388 isColSelChanged(true);
1391 public void showColumn(int col)
1393 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1394 isColSelChanged(true);
1397 public void showAllHiddenColumns()
1399 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1400 isColSelChanged(true);
1403 // common hide/show seq stuff
1404 public void showAllHiddenSeqs()
1406 int startSeq = ranges.getStartSeq();
1407 int endSeq = ranges.getEndSeq();
1409 if (alignment.getHiddenSequences().getSize() > 0)
1411 if (selectionGroup == null)
1413 selectionGroup = new SequenceGroup();
1414 selectionGroup.setEndRes(alignment.getWidth() - 1);
1416 List<SequenceI> tmp = alignment.getHiddenSequences()
1417 .showAll(hiddenRepSequences);
1418 for (SequenceI seq : tmp)
1420 selectionGroup.addSequence(seq, false);
1421 setSequenceAnnotationsVisible(seq, true);
1424 hiddenRepSequences = null;
1426 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1428 firePropertyChange("alignment", null, alignment.getSequences());
1429 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1435 public void showSequence(int index)
1437 int startSeq = ranges.getStartSeq();
1438 int endSeq = ranges.getEndSeq();
1440 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1441 hiddenRepSequences);
1444 if (selectionGroup == null)
1446 selectionGroup = new SequenceGroup();
1447 selectionGroup.setEndRes(alignment.getWidth() - 1);
1450 for (SequenceI seq : tmp)
1452 selectionGroup.addSequence(seq, false);
1453 setSequenceAnnotationsVisible(seq, true);
1456 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1458 firePropertyChange("alignment", null, alignment.getSequences());
1463 public void hideAllSelectedSeqs()
1465 if (selectionGroup == null || selectionGroup.getSize() < 1)
1470 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1474 setSelectionGroup(null);
1477 public void hideSequence(SequenceI[] seq)
1480 * cache offset to first visible sequence
1482 int startSeq = ranges.getStartSeq();
1486 for (int i = 0; i < seq.length; i++)
1488 alignment.getHiddenSequences().hideSequence(seq[i]);
1489 setSequenceAnnotationsVisible(seq[i], false);
1491 ranges.setStartSeq(startSeq);
1492 firePropertyChange("alignment", null, alignment.getSequences());
1497 * Hides the specified sequence, or the sequences it represents
1500 * the sequence to hide, or keep as representative
1501 * @param representGroup
1502 * if true, hide the current selection group except for the
1503 * representative sequence
1505 public void hideSequences(SequenceI sequence, boolean representGroup)
1507 if (selectionGroup == null || selectionGroup.getSize() < 1)
1509 hideSequence(new SequenceI[] { sequence });
1515 hideRepSequences(sequence, selectionGroup);
1516 setSelectionGroup(null);
1520 int gsize = selectionGroup.getSize();
1521 SequenceI[] hseqs = selectionGroup.getSequences()
1522 .toArray(new SequenceI[gsize]);
1524 hideSequence(hseqs);
1525 setSelectionGroup(null);
1530 * Set visibility for any annotations for the given sequence.
1534 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1537 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1540 for (AlignmentAnnotation ann : anns)
1542 if (ann.sequenceRef == sequenceI)
1544 ann.visible = visible;
1550 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1552 int sSize = sg.getSize();
1558 if (hiddenRepSequences == null)
1560 hiddenRepSequences = new Hashtable<>();
1563 hiddenRepSequences.put(repSequence, sg);
1565 // Hide all sequences except the repSequence
1566 SequenceI[] seqs = new SequenceI[sSize - 1];
1568 for (int i = 0; i < sSize; i++)
1570 if (sg.getSequenceAt(i) != repSequence)
1572 if (index == sSize - 1)
1577 seqs[index++] = sg.getSequenceAt(i);
1580 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1581 sg.setHidereps(true); // note: not done in 2.7applet
1588 * @return null or the current reference sequence
1590 public SequenceI getReferenceSeq()
1592 return alignment.getSeqrep();
1597 * @return true iff seq is the reference for the alignment
1599 public boolean isReferenceSeq(SequenceI seq)
1601 return alignment.getSeqrep() == seq;
1607 * @return true if there are sequences represented by this sequence that are
1610 public boolean isHiddenRepSequence(SequenceI seq)
1612 return (hiddenRepSequences != null
1613 && hiddenRepSequences.containsKey(seq));
1619 * @return null or a sequence group containing the sequences that seq
1622 public SequenceGroup getRepresentedSequences(SequenceI seq)
1624 return (SequenceGroup) (hiddenRepSequences == null ? null
1625 : hiddenRepSequences.get(seq));
1629 public int adjustForHiddenSeqs(int alignmentIndex)
1631 return alignment.getHiddenSequences()
1632 .adjustForHiddenSeqs(alignmentIndex);
1636 public void invertColumnSelection()
1638 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1639 isColSelChanged(true);
1643 public SequenceI[] getSelectionAsNewSequence()
1645 SequenceI[] sequences;
1646 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1647 // this was the only caller in the applet for this method
1648 // JBPNote: in applet, this method returned references to the alignment
1649 // sequences, and it did not honour the presence/absence of annotation
1650 // attached to the alignment (probably!)
1651 if (selectionGroup == null || selectionGroup.getSize() == 0)
1653 sequences = alignment.getSequencesArray();
1654 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1655 for (int i = 0; i < sequences.length; i++)
1657 // construct new sequence with subset of visible annotation
1658 sequences[i] = new Sequence(sequences[i], annots);
1663 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1670 public SequenceI[] getSequenceSelection()
1672 SequenceI[] sequences = null;
1673 if (selectionGroup != null)
1675 sequences = selectionGroup.getSequencesInOrder(alignment);
1677 if (sequences == null)
1679 sequences = alignment.getSequencesArray();
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 for (i = 0; i < iSize; i++)
1747 Iterator<int[]> blocks = alignment.getHiddenColumns()
1748 .getVisContigsIterator(start, end + 1, false);
1749 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1754 for (i = 0; i < iSize; i++)
1756 selection[i] = seqs[i].getSequenceAsString(start, end);
1764 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1766 ArrayList<int[]> regions = new ArrayList<>();
1772 HiddenColumns hidden = alignment.getHiddenColumns();
1773 if (hidden != null && hidden.hasHiddenColumns())
1777 start = hidden.visibleToAbsoluteColumn(start);
1780 end = hidden.getNextHiddenBoundary(false, start);
1791 regions.add(new int[] { start, end });
1793 if (hidden != null && hidden.hasHiddenColumns())
1795 start = hidden.visibleToAbsoluteColumn(end);
1796 start = hidden.getNextHiddenBoundary(true, start) + 1;
1798 } while (end < max);
1800 int[][] startEnd = new int[regions.size()][2];
1806 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1807 boolean selectedOnly)
1809 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1810 AlignmentAnnotation[] aa;
1811 if ((aa = alignment.getAlignmentAnnotation()) != null)
1813 for (AlignmentAnnotation annot : aa)
1815 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1816 if (selectedOnly && selectionGroup != null)
1818 clone.makeVisibleAnnotation(
1819 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1820 alignment.getHiddenColumns());
1824 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1833 public boolean isPadGaps()
1839 public void setPadGaps(boolean padGaps)
1841 this.padGaps = padGaps;
1845 * apply any post-edit constraints and trigger any calculations needed after
1846 * an edit has been performed on the alignment
1851 public void alignmentChanged(AlignmentViewPanel ap)
1855 alignment.padGaps();
1857 if (autoCalculateConsensus)
1859 updateConsensus(ap);
1861 if (hconsensus != null && autoCalculateConsensus)
1863 updateConservation(ap);
1865 if (autoCalculateStrucConsensus)
1867 updateStrucConsensus(ap);
1870 // Reset endRes of groups if beyond alignment width
1871 int alWidth = alignment.getWidth();
1872 List<SequenceGroup> groups = alignment.getGroups();
1875 for (SequenceGroup sg : groups)
1877 if (sg.getEndRes() > alWidth)
1879 sg.setEndRes(alWidth - 1);
1884 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1886 selectionGroup.setEndRes(alWidth - 1);
1889 updateAllColourSchemes();
1890 calculator.restartWorkers();
1891 // alignment.adjustSequenceAnnotations();
1895 * reset scope and do calculations for all applied colourschemes on alignment
1897 void updateAllColourSchemes()
1899 ResidueShaderI rs = residueShading;
1902 rs.alignmentChanged(alignment, hiddenRepSequences);
1904 rs.setConsensus(hconsensus);
1905 if (rs.conservationApplied())
1907 rs.setConservation(Conservation.calculateConservation("All",
1908 alignment.getSequences(), 0, alignment.getWidth(), false,
1909 getConsPercGaps(), false));
1913 for (SequenceGroup sg : alignment.getGroups())
1917 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1919 sg.recalcConservation();
1923 protected void initAutoAnnotation()
1925 // TODO: add menu option action that nulls or creates consensus object
1926 // depending on if the user wants to see the annotation or not in a
1927 // specific alignment
1929 if (hconsensus == null && !isDataset)
1931 if (!alignment.isNucleotide())
1940 consensus = new AlignmentAnnotation("Consensus",
1941 MessageManager.getString("label.consensus_descr"),
1942 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1943 initConsensus(consensus);
1946 initComplementConsensus();
1951 * If this is a protein alignment and there are mappings to cDNA, adds the
1952 * cDNA consensus annotation and returns true, else returns false.
1954 public boolean initComplementConsensus()
1956 if (!alignment.isNucleotide())
1958 final List<AlignedCodonFrame> codonMappings = alignment
1960 if (codonMappings != null && !codonMappings.isEmpty())
1962 boolean doConsensus = false;
1963 for (AlignedCodonFrame mapping : codonMappings)
1965 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1966 MapList[] mapLists = mapping.getdnaToProt();
1967 // mapLists can be empty if project load has not finished resolving
1969 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1977 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1979 .getString("label.complement_consensus_descr"),
1980 new Annotation[1], 0f, 100f,
1981 AlignmentAnnotation.BAR_GRAPH);
1982 initConsensus(complementConsensus);
1990 private void initConsensus(AlignmentAnnotation aa)
1993 aa.autoCalculated = true;
1997 alignment.addAnnotation(aa);
2001 // these should be extracted from the view model - style and settings for
2002 // derived annotation
2003 private void initGapCounts()
2007 gapcounts = new AlignmentAnnotation("Occupancy",
2008 MessageManager.getString("label.occupancy_descr"),
2009 new Annotation[1], 0f, alignment.getHeight(),
2010 AlignmentAnnotation.BAR_GRAPH);
2011 gapcounts.hasText = true;
2012 gapcounts.autoCalculated = true;
2013 gapcounts.scaleColLabel = true;
2014 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2016 alignment.addAnnotation(gapcounts);
2020 private void initConservation()
2022 if (showConservation)
2024 if (conservation == null)
2026 conservation = new AlignmentAnnotation("Conservation",
2027 MessageManager.formatMessage("label.conservation_descr",
2029 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2030 conservation.hasText = true;
2031 conservation.autoCalculated = true;
2032 alignment.addAnnotation(conservation);
2037 private void initQuality()
2041 if (quality == null)
2043 quality = new AlignmentAnnotation("Quality",
2044 MessageManager.getString("label.quality_descr"),
2045 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2046 quality.hasText = true;
2047 quality.autoCalculated = true;
2048 alignment.addAnnotation(quality);
2053 private void initRNAStructure()
2055 if (alignment.hasRNAStructure() && strucConsensus == null)
2057 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2058 MessageManager.getString("label.strucconsensus_descr"),
2059 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2060 strucConsensus.hasText = true;
2061 strucConsensus.autoCalculated = true;
2065 alignment.addAnnotation(strucConsensus);
2073 * @see jalview.api.AlignViewportI#calcPanelHeight()
2076 public int calcPanelHeight()
2078 // setHeight of panels
2079 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2081 int charHeight = getCharHeight();
2084 BitSet graphgrp = new BitSet();
2085 for (AlignmentAnnotation aa : anns)
2089 System.err.println("Null annotation row: ignoring.");
2096 if (aa.graphGroup > -1)
2098 if (graphgrp.get(aa.graphGroup))
2104 graphgrp.set(aa.graphGroup);
2111 aa.height += charHeight;
2121 aa.height += aa.graphHeight;
2129 height += aa.height;
2141 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2142 boolean preserveNewGroupSettings)
2144 boolean updateCalcs = false;
2145 boolean conv = isShowGroupConservation();
2146 boolean cons = isShowGroupConsensus();
2147 boolean showprf = isShowSequenceLogo();
2148 boolean showConsHist = isShowConsensusHistogram();
2149 boolean normLogo = isNormaliseSequenceLogo();
2152 * TODO reorder the annotation rows according to group/sequence ordering on
2155 boolean sortg = true;
2157 // remove old automatic annotation
2158 // add any new annotation
2160 // intersect alignment annotation with alignment groups
2162 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2163 List<SequenceGroup> oldrfs = new ArrayList<>();
2166 for (int an = 0; an < aan.length; an++)
2168 if (aan[an].autoCalculated && aan[an].groupRef != null)
2170 oldrfs.add(aan[an].groupRef);
2171 alignment.deleteAnnotation(aan[an], false);
2175 if (alignment.getGroups() != null)
2177 for (SequenceGroup sg : alignment.getGroups())
2179 updateCalcs = false;
2180 if (applyGlobalSettings
2181 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2183 // set defaults for this group's conservation/consensus
2184 sg.setshowSequenceLogo(showprf);
2185 sg.setShowConsensusHistogram(showConsHist);
2186 sg.setNormaliseSequenceLogo(normLogo);
2191 alignment.addAnnotation(sg.getConservationRow(), 0);
2196 alignment.addAnnotation(sg.getConsensus(), 0);
2198 // refresh the annotation rows
2201 sg.recalcConservation();
2209 public boolean isDisplayReferenceSeq()
2211 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2215 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2217 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2221 public boolean isColourByReferenceSeq()
2223 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2227 public Color getSequenceColour(SequenceI seq)
2229 Color sqc = sequenceColours.get(seq);
2230 return (sqc == null ? Color.white : sqc);
2234 public void setSequenceColour(SequenceI seq, Color col)
2238 sequenceColours.remove(seq);
2242 sequenceColours.put(seq, col);
2247 public void updateSequenceIdColours()
2249 for (SequenceGroup sg : alignment.getGroups())
2251 if (sg.idColour != null)
2253 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2255 sequenceColours.put(s, sg.idColour);
2262 public void clearSequenceColours()
2264 sequenceColours.clear();
2268 public AlignViewportI getCodingComplement()
2270 return this.codingComplement;
2274 * Set this as the (cDna/protein) complement of the given viewport. Also
2275 * ensures the reverse relationship is set on the given viewport.
2278 public void setCodingComplement(AlignViewportI av)
2282 System.err.println("Ignoring recursive setCodingComplement request");
2286 this.codingComplement = av;
2287 // avoid infinite recursion!
2288 if (av.getCodingComplement() != this)
2290 av.setCodingComplement(this);
2296 public boolean isNucleotide()
2298 return getAlignment() == null ? false : getAlignment().isNucleotide();
2302 public FeaturesDisplayedI getFeaturesDisplayed()
2304 return featuresDisplayed;
2308 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2310 featuresDisplayed = featuresDisplayedI;
2314 public boolean areFeaturesDisplayed()
2316 return featuresDisplayed != null
2317 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2324 * features are displayed if true
2327 public void setShowSequenceFeatures(boolean b)
2329 viewStyle.setShowSequenceFeatures(b);
2333 public boolean isShowSequenceFeatures()
2335 return viewStyle.isShowSequenceFeatures();
2339 public void setShowSequenceFeaturesHeight(boolean selected)
2341 viewStyle.setShowSequenceFeaturesHeight(selected);
2345 public boolean isShowSequenceFeaturesHeight()
2347 return viewStyle.isShowSequenceFeaturesHeight();
2351 public void setShowAnnotation(boolean b)
2353 viewStyle.setShowAnnotation(b);
2357 public boolean isShowAnnotation()
2359 return viewStyle.isShowAnnotation();
2363 public boolean isRightAlignIds()
2365 return viewStyle.isRightAlignIds();
2369 public void setRightAlignIds(boolean rightAlignIds)
2371 viewStyle.setRightAlignIds(rightAlignIds);
2375 public boolean getConservationSelected()
2377 return viewStyle.getConservationSelected();
2381 public void setShowBoxes(boolean state)
2383 viewStyle.setShowBoxes(state);
2388 * @see jalview.api.ViewStyleI#getTextColour()
2391 public Color getTextColour()
2393 return viewStyle.getTextColour();
2398 * @see jalview.api.ViewStyleI#getTextColour2()
2401 public Color getTextColour2()
2403 return viewStyle.getTextColour2();
2408 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2411 public int getThresholdTextColour()
2413 return viewStyle.getThresholdTextColour();
2418 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2421 public boolean isConservationColourSelected()
2423 return viewStyle.isConservationColourSelected();
2428 * @see jalview.api.ViewStyleI#isRenderGaps()
2431 public boolean isRenderGaps()
2433 return viewStyle.isRenderGaps();
2438 * @see jalview.api.ViewStyleI#isShowColourText()
2441 public boolean isShowColourText()
2443 return viewStyle.isShowColourText();
2447 * @param conservationColourSelected
2448 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2451 public void setConservationColourSelected(
2452 boolean conservationColourSelected)
2454 viewStyle.setConservationColourSelected(conservationColourSelected);
2458 * @param showColourText
2459 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2462 public void setShowColourText(boolean showColourText)
2464 viewStyle.setShowColourText(showColourText);
2469 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2472 public void setTextColour(Color textColour)
2474 viewStyle.setTextColour(textColour);
2478 * @param thresholdTextColour
2479 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2482 public void setThresholdTextColour(int thresholdTextColour)
2484 viewStyle.setThresholdTextColour(thresholdTextColour);
2488 * @param textColour2
2489 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2492 public void setTextColour2(Color textColour2)
2494 viewStyle.setTextColour2(textColour2);
2498 public ViewStyleI getViewStyle()
2500 return new ViewStyle(viewStyle);
2504 public void setViewStyle(ViewStyleI settingsForView)
2506 viewStyle = new ViewStyle(settingsForView);
2507 if (residueShading != null)
2509 residueShading.setConservationApplied(
2510 settingsForView.isConservationColourSelected());
2515 public boolean sameStyle(ViewStyleI them)
2517 return viewStyle.sameStyle(them);
2522 * @see jalview.api.ViewStyleI#getIdWidth()
2525 public int getIdWidth()
2527 return viewStyle.getIdWidth();
2532 * @see jalview.api.ViewStyleI#setIdWidth(int)
2535 public void setIdWidth(int i)
2537 viewStyle.setIdWidth(i);
2542 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2545 public boolean isCentreColumnLabels()
2547 return viewStyle.isCentreColumnLabels();
2551 * @param centreColumnLabels
2552 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2555 public void setCentreColumnLabels(boolean centreColumnLabels)
2557 viewStyle.setCentreColumnLabels(centreColumnLabels);
2562 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2565 public void setShowDBRefs(boolean showdbrefs)
2567 viewStyle.setShowDBRefs(showdbrefs);
2572 * @see jalview.api.ViewStyleI#isShowDBRefs()
2575 public boolean isShowDBRefs()
2577 return viewStyle.isShowDBRefs();
2582 * @see jalview.api.ViewStyleI#isShowNPFeats()
2585 public boolean isShowNPFeats()
2587 return viewStyle.isShowNPFeats();
2591 * @param shownpfeats
2592 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2595 public void setShowNPFeats(boolean shownpfeats)
2597 viewStyle.setShowNPFeats(shownpfeats);
2600 public abstract StructureSelectionManager getStructureSelectionManager();
2603 * Add one command to the command history list.
2607 public void addToHistoryList(CommandI command)
2609 if (this.historyList != null)
2611 this.historyList.push(command);
2612 broadcastCommand(command, false);
2616 protected void broadcastCommand(CommandI command, boolean undo)
2618 getStructureSelectionManager().commandPerformed(command, undo,
2623 * Add one command to the command redo list.
2627 public void addToRedoList(CommandI command)
2629 if (this.redoList != null)
2631 this.redoList.push(command);
2633 broadcastCommand(command, true);
2637 * Clear the command redo list.
2639 public void clearRedoList()
2641 if (this.redoList != null)
2643 this.redoList.clear();
2647 public void setHistoryList(Deque<CommandI> list)
2649 this.historyList = list;
2652 public Deque<CommandI> getHistoryList()
2654 return this.historyList;
2657 public void setRedoList(Deque<CommandI> list)
2659 this.redoList = list;
2662 public Deque<CommandI> getRedoList()
2664 return this.redoList;
2668 public VamsasSource getVamsasSource()
2673 public SequenceAnnotationOrder getSortAnnotationsBy()
2675 return sortAnnotationsBy;
2678 public void setSortAnnotationsBy(
2679 SequenceAnnotationOrder sortAnnotationsBy)
2681 this.sortAnnotationsBy = sortAnnotationsBy;
2684 public boolean isShowAutocalculatedAbove()
2686 return showAutocalculatedAbove;
2689 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2691 this.showAutocalculatedAbove = showAutocalculatedAbove;
2695 public boolean isScaleProteinAsCdna()
2697 return viewStyle.isScaleProteinAsCdna();
2701 public void setScaleProteinAsCdna(boolean b)
2703 viewStyle.setScaleProteinAsCdna(b);
2707 public boolean isProteinFontAsCdna()
2709 return viewStyle.isProteinFontAsCdna();
2713 public void setProteinFontAsCdna(boolean b)
2715 viewStyle.setProteinFontAsCdna(b);
2719 * @return true if view should scroll to show the highlighted region of a
2724 public final boolean isFollowHighlight()
2726 return followHighlight;
2730 public final void setFollowHighlight(boolean b)
2732 this.followHighlight = b;
2736 public ViewportRanges getRanges()
2742 * Helper method to populate the SearchResults with the location in the
2743 * complementary alignment to scroll to, in order to match this one.
2746 * the SearchResults to add to
2747 * @return the offset (below top of visible region) of the matched sequence
2749 protected int findComplementScrollTarget(SearchResultsI sr)
2751 final AlignViewportI complement = getCodingComplement();
2752 if (complement == null || !complement.isFollowHighlight())
2756 boolean iAmProtein = !getAlignment().isNucleotide();
2757 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2758 : complement.getAlignment();
2759 if (proteinAlignment == null)
2763 final List<AlignedCodonFrame> mappings = proteinAlignment
2767 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2768 * residue in the middle column of the visible region. Scroll the
2769 * complementary alignment to line up the corresponding residue.
2772 SequenceI sequence = null;
2775 * locate 'middle' column (true middle if an odd number visible, left of
2776 * middle if an even number visible)
2778 int middleColumn = ranges.getStartRes()
2779 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2780 final HiddenSequences hiddenSequences = getAlignment()
2781 .getHiddenSequences();
2784 * searching to the bottom of the alignment gives smoother scrolling across
2785 * all gapped visible regions
2787 int lastSeq = alignment.getHeight() - 1;
2788 List<AlignedCodonFrame> seqMappings = null;
2789 for (int seqNo = ranges
2790 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2792 sequence = getAlignment().getSequenceAt(seqNo);
2793 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2797 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2801 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2803 getCodingComplement().getAlignment().getSequences());
2804 if (!seqMappings.isEmpty())
2810 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2813 * No ungapped mapped sequence in middle column - do nothing
2817 MappingUtils.addSearchResults(sr, sequence,
2818 sequence.findPosition(middleColumn), seqMappings);
2823 * synthesize a column selection if none exists so it covers the given
2824 * selection group. if wholewidth is false, no column selection is made if the
2825 * selection group covers the whole alignment width.
2830 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2833 if (sg != null && (sgs = sg.getStartRes()) >= 0
2834 && sg.getStartRes() <= (sge = sg.getEndRes())
2835 && !this.hasSelectedColumns())
2837 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2844 colSel = new ColumnSelection();
2846 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2848 colSel.addElement(cspos);
2854 * hold status of current selection group - defined on alignment or not.
2856 private boolean selectionIsDefinedGroup = false;
2859 public boolean isSelectionDefinedGroup()
2861 if (selectionGroup == null)
2865 if (isSelectionGroupChanged(true))
2867 selectionIsDefinedGroup = false;
2868 List<SequenceGroup> gps = alignment.getGroups();
2869 if (gps == null || gps.size() == 0)
2871 selectionIsDefinedGroup = false;
2875 selectionIsDefinedGroup = gps.contains(selectionGroup);
2878 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2882 * null, or currently highlighted results on this view
2884 private SearchResultsI searchResults = null;
2886 protected TreeModel currentTree = null;
2889 public boolean hasSearchResults()
2891 return searchResults != null;
2895 public void setSearchResults(SearchResultsI results)
2897 searchResults = results;
2901 public SearchResultsI getSearchResults()
2903 return searchResults;
2907 * get the consensus sequence as displayed under the PID consensus annotation
2910 * @return consensus sequence as a new sequence object
2912 public SequenceI getConsensusSeq()
2914 if (consensus == null)
2916 updateConsensus(null);
2918 if (consensus == null)
2922 StringBuffer seqs = new StringBuffer();
2923 for (int i = 0; i < consensus.annotations.length; i++)
2925 Annotation annotation = consensus.annotations[i];
2926 if (annotation != null)
2928 String description = annotation.description;
2929 if (description != null && description.startsWith("["))
2931 // consensus is a tie - just pick the first one
2932 seqs.append(description.charAt(1));
2936 seqs.append(annotation.displayCharacter);
2941 SequenceI sq = new Sequence("Consensus", seqs.toString());
2942 sq.setDescription("Percentage Identity Consensus "
2943 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
2948 public void setCurrentTree(TreeModel tree)
2954 public TreeModel getCurrentTree()