2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.viewmodel;
23 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
24 import jalview.analysis.Conservation;
25 import jalview.api.AlignCalcManagerI;
26 import jalview.api.AlignViewportI;
27 import jalview.api.AlignmentViewPanel;
28 import jalview.api.FeaturesDisplayedI;
29 import jalview.api.ViewStyleI;
30 import jalview.commands.CommandI;
31 import jalview.datamodel.AlignedCodonFrame;
32 import jalview.datamodel.AlignmentAnnotation;
33 import jalview.datamodel.AlignmentI;
34 import jalview.datamodel.AlignmentView;
35 import jalview.datamodel.Annotation;
36 import jalview.datamodel.CigarArray;
37 import jalview.datamodel.ColumnSelection;
38 import jalview.datamodel.HiddenColumns;
39 import jalview.datamodel.HiddenSequences;
40 import jalview.datamodel.ProfilesI;
41 import jalview.datamodel.SearchResultsI;
42 import jalview.datamodel.Sequence;
43 import jalview.datamodel.SequenceCollectionI;
44 import jalview.datamodel.SequenceGroup;
45 import jalview.datamodel.SequenceI;
46 import jalview.renderer.ResidueShader;
47 import jalview.renderer.ResidueShaderI;
48 import jalview.schemes.ColourSchemeI;
49 import jalview.structure.CommandListener;
50 import jalview.structure.StructureSelectionManager;
51 import jalview.structure.VamsasSource;
52 import jalview.util.Comparison;
53 import jalview.util.MapList;
54 import jalview.util.MappingUtils;
55 import jalview.util.MessageManager;
56 import jalview.viewmodel.styles.ViewStyle;
57 import jalview.workers.AlignCalcManager;
58 import jalview.workers.ComplementConsensusThread;
59 import jalview.workers.ConsensusThread;
60 import jalview.workers.StrucConsensusThread;
62 import java.awt.Color;
63 import java.beans.PropertyChangeSupport;
64 import java.util.ArrayDeque;
65 import java.util.ArrayList;
66 import java.util.BitSet;
67 import java.util.Deque;
68 import java.util.HashMap;
69 import java.util.Hashtable;
70 import java.util.List;
74 * base class holding visualization and analysis attributes and common logic for
75 * an active alignment view displayed in the GUI
80 public abstract class AlignmentViewport implements AlignViewportI,
81 CommandListener, VamsasSource
83 final protected ViewportRanges ranges;
85 protected ViewStyleI viewStyle = new ViewStyle();
88 * A viewport that hosts the cDna view of this (protein), or vice versa (if
91 AlignViewportI codingComplement = null;
93 FeaturesDisplayedI featuresDisplayed = null;
95 protected Deque<CommandI> historyList = new ArrayDeque<>();
97 protected Deque<CommandI> redoList = new ArrayDeque<>();
100 * alignment displayed in the viewport. Please use get/setter
102 protected AlignmentI alignment;
104 public AlignmentViewport(AlignmentI al)
107 ranges = new ViewportRanges(al);
112 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
115 public void setFontName(String name)
117 viewStyle.setFontName(name);
122 * @see jalview.api.ViewStyleI#setFontStyle(int)
125 public void setFontStyle(int style)
127 viewStyle.setFontStyle(style);
132 * @see jalview.api.ViewStyleI#setFontSize(int)
135 public void setFontSize(int size)
137 viewStyle.setFontSize(size);
142 * @see jalview.api.ViewStyleI#getFontStyle()
145 public int getFontStyle()
147 return viewStyle.getFontStyle();
152 * @see jalview.api.ViewStyleI#getFontName()
155 public String getFontName()
157 return viewStyle.getFontName();
162 * @see jalview.api.ViewStyleI#getFontSize()
165 public int getFontSize()
167 return viewStyle.getFontSize();
171 * @param upperCasebold
172 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
175 public void setUpperCasebold(boolean upperCasebold)
177 viewStyle.setUpperCasebold(upperCasebold);
182 * @see jalview.api.ViewStyleI#isUpperCasebold()
185 public boolean isUpperCasebold()
187 return viewStyle.isUpperCasebold();
192 * @see jalview.api.ViewStyleI#isSeqNameItalics()
195 public boolean isSeqNameItalics()
197 return viewStyle.isSeqNameItalics();
201 * @param colourByReferenceSeq
202 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
205 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
207 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
212 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
215 public void setColourAppliesToAllGroups(boolean b)
217 viewStyle.setColourAppliesToAllGroups(b);
222 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
225 public boolean getColourAppliesToAllGroups()
227 return viewStyle.getColourAppliesToAllGroups();
232 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
235 public boolean getAbovePIDThreshold()
237 return viewStyle.getAbovePIDThreshold();
242 * @see jalview.api.ViewStyleI#setIncrement(int)
245 public void setIncrement(int inc)
247 viewStyle.setIncrement(inc);
252 * @see jalview.api.ViewStyleI#getIncrement()
255 public int getIncrement()
257 return viewStyle.getIncrement();
262 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
265 public void setConservationSelected(boolean b)
267 viewStyle.setConservationSelected(b);
272 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
275 public void setShowHiddenMarkers(boolean show)
277 viewStyle.setShowHiddenMarkers(show);
282 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
285 public boolean getShowHiddenMarkers()
287 return viewStyle.getShowHiddenMarkers();
292 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
295 public void setScaleRightWrapped(boolean b)
297 viewStyle.setScaleRightWrapped(b);
302 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
305 public void setScaleLeftWrapped(boolean b)
307 viewStyle.setScaleLeftWrapped(b);
312 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
315 public void setScaleAboveWrapped(boolean b)
317 viewStyle.setScaleAboveWrapped(b);
322 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
325 public boolean getScaleLeftWrapped()
327 return viewStyle.getScaleLeftWrapped();
332 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
335 public boolean getScaleAboveWrapped()
337 return viewStyle.getScaleAboveWrapped();
342 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
345 public boolean getScaleRightWrapped()
347 return viewStyle.getScaleRightWrapped();
352 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
355 public void setAbovePIDThreshold(boolean b)
357 viewStyle.setAbovePIDThreshold(b);
362 * @see jalview.api.ViewStyleI#setThreshold(int)
365 public void setThreshold(int thresh)
367 viewStyle.setThreshold(thresh);
372 * @see jalview.api.ViewStyleI#getThreshold()
375 public int getThreshold()
377 return viewStyle.getThreshold();
382 * @see jalview.api.ViewStyleI#getShowJVSuffix()
385 public boolean getShowJVSuffix()
387 return viewStyle.getShowJVSuffix();
392 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
395 public void setShowJVSuffix(boolean b)
397 viewStyle.setShowJVSuffix(b);
402 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
405 public void setWrapAlignment(boolean state)
407 viewStyle.setWrapAlignment(state);
408 ranges.setWrappedMode(state);
413 * @see jalview.api.ViewStyleI#setShowText(boolean)
416 public void setShowText(boolean state)
418 viewStyle.setShowText(state);
423 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
426 public void setRenderGaps(boolean state)
428 viewStyle.setRenderGaps(state);
433 * @see jalview.api.ViewStyleI#getColourText()
436 public boolean getColourText()
438 return viewStyle.getColourText();
443 * @see jalview.api.ViewStyleI#setColourText(boolean)
446 public void setColourText(boolean state)
448 viewStyle.setColourText(state);
453 * @see jalview.api.ViewStyleI#getWrapAlignment()
456 public boolean getWrapAlignment()
458 return viewStyle.getWrapAlignment();
463 * @see jalview.api.ViewStyleI#getShowText()
466 public boolean getShowText()
468 return viewStyle.getShowText();
473 * @see jalview.api.ViewStyleI#getWrappedWidth()
476 public int getWrappedWidth()
478 return viewStyle.getWrappedWidth();
483 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
486 public void setWrappedWidth(int w)
488 viewStyle.setWrappedWidth(w);
493 * @see jalview.api.ViewStyleI#getCharHeight()
496 public int getCharHeight()
498 return viewStyle.getCharHeight();
503 * @see jalview.api.ViewStyleI#setCharHeight(int)
506 public void setCharHeight(int h)
508 viewStyle.setCharHeight(h);
513 * @see jalview.api.ViewStyleI#getCharWidth()
516 public int getCharWidth()
518 return viewStyle.getCharWidth();
523 * @see jalview.api.ViewStyleI#setCharWidth(int)
526 public void setCharWidth(int w)
528 viewStyle.setCharWidth(w);
533 * @see jalview.api.ViewStyleI#getShowBoxes()
536 public boolean getShowBoxes()
538 return viewStyle.getShowBoxes();
543 * @see jalview.api.ViewStyleI#getShowUnconserved()
546 public boolean getShowUnconserved()
548 return viewStyle.getShowUnconserved();
552 * @param showunconserved
553 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
556 public void setShowUnconserved(boolean showunconserved)
558 viewStyle.setShowUnconserved(showunconserved);
563 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
566 public void setSeqNameItalics(boolean default1)
568 viewStyle.setSeqNameItalics(default1);
574 public AlignmentI getAlignment()
580 public char getGapCharacter()
582 return alignment.getGapCharacter();
585 protected String sequenceSetID;
588 * probably unused indicator that view is of a dataset rather than an
591 protected boolean isDataset = false;
593 public void setDataset(boolean b)
598 public boolean isDataset()
603 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
605 protected ColumnSelection colSel = new ColumnSelection();
607 public boolean autoCalculateConsensus = true;
609 protected boolean autoCalculateStrucConsensus = true;
611 protected boolean ignoreGapsInConsensusCalculation = false;
613 protected ResidueShaderI residueShading = new ResidueShader();
616 public void setGlobalColourScheme(ColourSchemeI cs)
618 // TODO: logic refactored from AlignFrame changeColour -
619 // TODO: autorecalc stuff should be changed to rely on the worker system
620 // check to see if we should implement a changeColour(cs) method rather than
621 // put the logic in here
622 // - means that caller decides if they want to just modify state and defer
623 // calculation till later or to do all calculations in thread.
627 * only instantiate alignment colouring once, thereafter update it;
628 * this means that any conservation or PID threshold settings
629 * persist when the alignment colour scheme is changed
631 if (residueShading == null)
633 residueShading = new ResidueShader(viewStyle);
635 residueShading.setColourScheme(cs);
637 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
638 // ...problem: groups need these, but do not currently have a ViewStyle
642 if (getConservationSelected())
647 while (isCalcInProgress() && retry < 10)
653 } catch (InterruptedException e)
658 residueShading.setConservation(hconservation);
660 residueShading.alignmentChanged(alignment, hiddenRepSequences);
664 * if 'apply colour to all groups' is selected... do so
665 * (but don't transfer any colour threshold settings to groups)
667 if (getColourAppliesToAllGroups())
669 for (SequenceGroup sg : getAlignment().getGroups())
672 * retain any colour thresholds per group while
673 * changing choice of colour scheme (JAL-2386)
675 sg.setColourScheme(cs);
678 sg.getGroupColourScheme()
679 .alignmentChanged(sg, hiddenRepSequences);
686 public ColourSchemeI getGlobalColourScheme()
688 return residueShading == null ? null : residueShading
693 public ResidueShaderI getResidueShading()
695 return residueShading;
698 protected AlignmentAnnotation consensus;
700 protected AlignmentAnnotation complementConsensus;
702 protected AlignmentAnnotation gapcounts;
704 protected AlignmentAnnotation strucConsensus;
706 protected AlignmentAnnotation conservation;
708 protected AlignmentAnnotation quality;
710 protected AlignmentAnnotation[] groupConsensus;
712 protected AlignmentAnnotation[] groupConservation;
715 * results of alignment consensus analysis for visible portion of view
717 protected ProfilesI hconsensus = null;
720 * results of cDNA complement consensus visible portion of view
722 protected Hashtable[] hcomplementConsensus = null;
725 * results of secondary structure base pair consensus for visible portion of
728 protected Hashtable[] hStrucConsensus = null;
730 protected Conservation hconservation = null;
733 public void setConservation(Conservation cons)
735 hconservation = cons;
739 * percentage gaps allowed in a column before all amino acid properties should
740 * be considered unconserved
742 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
745 public int getConsPercGaps()
751 public void setSequenceConsensusHash(ProfilesI hconsensus)
753 this.hconsensus = hconsensus;
757 public void setComplementConsensusHash(Hashtable[] hconsensus)
759 this.hcomplementConsensus = hconsensus;
763 public ProfilesI getSequenceConsensusHash()
769 public Hashtable[] getComplementConsensusHash()
771 return hcomplementConsensus;
775 public Hashtable[] getRnaStructureConsensusHash()
777 return hStrucConsensus;
781 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
783 this.hStrucConsensus = hStrucConsensus;
788 public AlignmentAnnotation getAlignmentQualityAnnot()
794 public AlignmentAnnotation getAlignmentConservationAnnotation()
800 public AlignmentAnnotation getAlignmentConsensusAnnotation()
806 public AlignmentAnnotation getAlignmentGapAnnotation()
812 public AlignmentAnnotation getComplementConsensusAnnotation()
814 return complementConsensus;
818 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
820 return strucConsensus;
823 protected AlignCalcManagerI calculator = new AlignCalcManager();
826 * trigger update of conservation annotation
828 public void updateConservation(final AlignmentViewPanel ap)
830 // see note in mantis : issue number 8585
831 if (alignment.isNucleotide()
832 || (conservation == null && quality == null)
833 || !autoCalculateConsensus)
838 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
840 calculator.registerWorker(new jalview.workers.ConservationThread(
846 * trigger update of consensus annotation
848 public void updateConsensus(final AlignmentViewPanel ap)
850 // see note in mantis : issue number 8585
851 if (consensus == null || !autoCalculateConsensus)
855 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
857 calculator.registerWorker(new ConsensusThread(this, ap));
861 * A separate thread to compute cDNA consensus for a protein alignment
862 * which has mapping to cDNA
864 final AlignmentI al = this.getAlignment();
865 if (!al.isNucleotide() && al.getCodonFrames() != null
866 && !al.getCodonFrames().isEmpty())
869 * fudge - check first for protein-to-nucleotide mappings
870 * (we don't want to do this for protein-to-protein)
872 boolean doConsensus = false;
873 for (AlignedCodonFrame mapping : al.getCodonFrames())
875 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
876 MapList[] mapLists = mapping.getdnaToProt();
877 // mapLists can be empty if project load has not finished resolving seqs
878 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
887 .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null)
890 .registerWorker(new ComplementConsensusThread(this, ap));
896 // --------START Structure Conservation
897 public void updateStrucConsensus(final AlignmentViewPanel ap)
899 if (autoCalculateStrucConsensus && strucConsensus == null
900 && alignment.isNucleotide() && alignment.hasRNAStructure())
902 // secondary structure has been added - so init the consensus line
906 // see note in mantis : issue number 8585
907 if (strucConsensus == null || !autoCalculateStrucConsensus)
911 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
913 calculator.registerWorker(new StrucConsensusThread(this, ap));
917 public boolean isCalcInProgress()
919 return calculator.isWorking();
923 public boolean isCalculationInProgress(
924 AlignmentAnnotation alignmentAnnotation)
926 if (!alignmentAnnotation.autoCalculated)
930 if (calculator.workingInvolvedWith(alignmentAnnotation))
932 // System.err.println("grey out ("+alignmentAnnotation.label+")");
938 public void setAlignment(AlignmentI align)
940 this.alignment = align;
944 * Clean up references when this viewport is closed
947 public void dispose()
950 * defensively null out references to large objects in case
951 * this object is not garbage collected (as if!)
954 complementConsensus = null;
955 strucConsensus = null;
958 groupConsensus = null;
959 groupConservation = null;
961 hcomplementConsensus = null;
962 // colour scheme may hold reference to consensus
963 residueShading = null;
964 // TODO remove listeners from changeSupport?
965 changeSupport = null;
970 public boolean isClosed()
972 // TODO: check that this isClosed is only true after panel is closed, not
973 // before it is fully constructed.
974 return alignment == null;
978 public AlignCalcManagerI getCalcManager()
984 * should conservation rows be shown for groups
986 protected boolean showGroupConservation = false;
989 * should consensus rows be shown for groups
991 protected boolean showGroupConsensus = false;
994 * should consensus profile be rendered by default
996 protected boolean showSequenceLogo = false;
999 * should consensus profile be rendered normalised to row height
1001 protected boolean normaliseSequenceLogo = false;
1004 * should consensus histograms be rendered by default
1006 protected boolean showConsensusHistogram = true;
1009 * @return the showConsensusProfile
1012 public boolean isShowSequenceLogo()
1014 return showSequenceLogo;
1018 * @param showSequenceLogo
1021 public void setShowSequenceLogo(boolean showSequenceLogo)
1023 if (showSequenceLogo != this.showSequenceLogo)
1025 // TODO: decouple settings setting from calculation when refactoring
1026 // annotation update method from alignframe to viewport
1027 this.showSequenceLogo = showSequenceLogo;
1028 calculator.updateAnnotationFor(ConsensusThread.class);
1029 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1030 calculator.updateAnnotationFor(StrucConsensusThread.class);
1032 this.showSequenceLogo = showSequenceLogo;
1036 * @param showConsensusHistogram
1037 * the showConsensusHistogram to set
1039 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1041 this.showConsensusHistogram = showConsensusHistogram;
1045 * @return the showGroupConservation
1047 public boolean isShowGroupConservation()
1049 return showGroupConservation;
1053 * @param showGroupConservation
1054 * the showGroupConservation to set
1056 public void setShowGroupConservation(boolean showGroupConservation)
1058 this.showGroupConservation = showGroupConservation;
1062 * @return the showGroupConsensus
1064 public boolean isShowGroupConsensus()
1066 return showGroupConsensus;
1070 * @param showGroupConsensus
1071 * the showGroupConsensus to set
1073 public void setShowGroupConsensus(boolean showGroupConsensus)
1075 this.showGroupConsensus = showGroupConsensus;
1080 * @return flag to indicate if the consensus histogram should be rendered by
1084 public boolean isShowConsensusHistogram()
1086 return this.showConsensusHistogram;
1090 * when set, updateAlignment will always ensure sequences are of equal length
1092 private boolean padGaps = false;
1095 * when set, alignment should be reordered according to a newly opened tree
1097 public boolean sortByTree = false;
1102 * @return null or the currently selected sequence region
1105 public SequenceGroup getSelectionGroup()
1107 return selectionGroup;
1111 * Set the selection group for this window. Also sets the current alignment as
1112 * the context for the group, if it does not already have one.
1115 * - group holding references to sequences in this alignment view
1119 public void setSelectionGroup(SequenceGroup sg)
1121 selectionGroup = sg;
1122 if (sg != null && sg.getContext() == null)
1124 sg.setContext(alignment);
1128 public void setHiddenColumns(HiddenColumns hidden)
1130 this.alignment.setHiddenColumns(hidden);
1134 public ColumnSelection getColumnSelection()
1140 public void setColumnSelection(ColumnSelection colSel)
1142 this.colSel = colSel;
1145 updateHiddenColumns();
1147 isColSelChanged(true);
1155 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1157 return hiddenRepSequences;
1161 public void setHiddenRepSequences(
1162 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1164 this.hiddenRepSequences = hiddenRepSequences;
1168 public boolean hasSelectedColumns()
1170 ColumnSelection columnSelection = getColumnSelection();
1171 return columnSelection != null && columnSelection.hasSelectedColumns();
1175 public boolean hasHiddenColumns()
1177 return alignment.getHiddenColumns() != null
1178 && alignment.getHiddenColumns().hasHiddenColumns();
1181 public void updateHiddenColumns()
1183 // this method doesn't really do anything now. But - it could, since a
1184 // column Selection could be in the process of modification
1185 // hasHiddenColumns = colSel.hasHiddenColumns();
1189 public boolean hasHiddenRows()
1191 return alignment.getHiddenSequences().getSize() > 0;
1194 protected SequenceGroup selectionGroup;
1196 public void setSequenceSetId(String newid)
1198 if (sequenceSetID != null)
1201 .println("Warning - overwriting a sequenceSetId for a viewport!");
1203 sequenceSetID = new String(newid);
1207 public String getSequenceSetId()
1209 if (sequenceSetID == null)
1211 sequenceSetID = alignment.hashCode() + "";
1214 return sequenceSetID;
1218 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1221 protected String viewId = null;
1224 public String getViewId()
1228 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1233 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1235 ignoreGapsInConsensusCalculation = b;
1238 updateConsensus(ap);
1239 if (residueShading != null)
1241 residueShading.setThreshold(residueShading.getThreshold(),
1242 ignoreGapsInConsensusCalculation);
1248 private long sgrouphash = -1, colselhash = -1;
1251 * checks current SelectionGroup against record of last hash value, and
1255 * update the record of last hash value
1257 * @return true if SelectionGroup changed since last call (when b is true)
1259 public boolean isSelectionGroupChanged(boolean b)
1261 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1262 : selectionGroup.hashCode();
1263 if (hc != -1 && hc != sgrouphash)
1275 * checks current colsel against record of last hash value, and optionally
1279 * update the record of last hash value
1280 * @return true if colsel changed since last call (when b is true)
1282 public boolean isColSelChanged(boolean b)
1284 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1285 if (hc != -1 && hc != colselhash)
1297 public boolean isIgnoreGapsConsensus()
1299 return ignoreGapsInConsensusCalculation;
1302 // property change stuff
1303 // JBPNote Prolly only need this in the applet version.
1304 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1307 protected boolean showConservation = true;
1309 protected boolean showQuality = true;
1311 protected boolean showConsensus = true;
1313 protected boolean showOccupancy = true;
1315 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1317 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1319 protected boolean showAutocalculatedAbove;
1322 * when set, view will scroll to show the highlighted position
1324 private boolean followHighlight = true;
1327 * Property change listener for changes in alignment
1332 public void addPropertyChangeListener(
1333 java.beans.PropertyChangeListener listener)
1335 changeSupport.addPropertyChangeListener(listener);
1344 public void removePropertyChangeListener(
1345 java.beans.PropertyChangeListener listener)
1347 changeSupport.removePropertyChangeListener(listener);
1351 * Property change listener for changes in alignment
1360 public void firePropertyChange(String prop, Object oldvalue,
1363 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1366 // common hide/show column stuff
1368 public void hideSelectedColumns()
1370 if (colSel.isEmpty())
1375 colSel.hideSelectedColumns(alignment);
1376 setSelectionGroup(null);
1377 isColSelChanged(true);
1380 public void hideColumns(int start, int end)
1384 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1388 alignment.getHiddenColumns().hideColumns(start, end);
1390 isColSelChanged(true);
1393 public void showColumn(int col)
1395 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1396 isColSelChanged(true);
1399 public void showAllHiddenColumns()
1401 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1402 isColSelChanged(true);
1405 // common hide/show seq stuff
1406 public void showAllHiddenSeqs()
1408 int startSeq = ranges.getStartSeq();
1409 int endSeq = ranges.getEndSeq();
1411 if (alignment.getHiddenSequences().getSize() > 0)
1413 if (selectionGroup == null)
1415 selectionGroup = new SequenceGroup();
1416 selectionGroup.setEndRes(alignment.getWidth() - 1);
1418 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1419 hiddenRepSequences);
1420 for (SequenceI seq : tmp)
1422 selectionGroup.addSequence(seq, false);
1423 setSequenceAnnotationsVisible(seq, true);
1426 hiddenRepSequences = null;
1428 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1430 firePropertyChange("alignment", null, alignment.getSequences());
1431 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1437 public void showSequence(int index)
1439 int startSeq = ranges.getStartSeq();
1440 int endSeq = ranges.getEndSeq();
1442 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1443 index, hiddenRepSequences);
1446 if (selectionGroup == null)
1448 selectionGroup = new SequenceGroup();
1449 selectionGroup.setEndRes(alignment.getWidth() - 1);
1452 for (SequenceI seq : tmp)
1454 selectionGroup.addSequence(seq, false);
1455 setSequenceAnnotationsVisible(seq, true);
1458 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1460 firePropertyChange("alignment", null, alignment.getSequences());
1465 public void hideAllSelectedSeqs()
1467 if (selectionGroup == null || selectionGroup.getSize() < 1)
1472 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1476 setSelectionGroup(null);
1479 public void hideSequence(SequenceI[] seq)
1482 * cache offset to first visible sequence
1484 int startSeq = ranges.getStartSeq();
1488 for (int i = 0; i < seq.length; i++)
1490 alignment.getHiddenSequences().hideSequence(seq[i]);
1491 setSequenceAnnotationsVisible(seq[i], false);
1493 ranges.setStartSeq(startSeq);
1494 firePropertyChange("alignment", null, alignment.getSequences());
1499 * Hides the specified sequence, or the sequences it represents
1502 * the sequence to hide, or keep as representative
1503 * @param representGroup
1504 * if true, hide the current selection group except for the
1505 * representative sequence
1507 public void hideSequences(SequenceI sequence, boolean representGroup)
1509 if (selectionGroup == null || selectionGroup.getSize() < 1)
1511 hideSequence(new SequenceI[] { sequence });
1517 hideRepSequences(sequence, selectionGroup);
1518 setSelectionGroup(null);
1522 int gsize = selectionGroup.getSize();
1523 SequenceI[] hseqs = selectionGroup.getSequences().toArray(
1524 new SequenceI[gsize]);
1526 hideSequence(hseqs);
1527 setSelectionGroup(null);
1532 * Set visibility for any annotations for the given sequence.
1536 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1539 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1542 for (AlignmentAnnotation ann : anns)
1544 if (ann.sequenceRef == sequenceI)
1546 ann.visible = visible;
1552 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1554 int sSize = sg.getSize();
1560 if (hiddenRepSequences == null)
1562 hiddenRepSequences = new Hashtable<>();
1565 hiddenRepSequences.put(repSequence, sg);
1567 // Hide all sequences except the repSequence
1568 SequenceI[] seqs = new SequenceI[sSize - 1];
1570 for (int i = 0; i < sSize; i++)
1572 if (sg.getSequenceAt(i) != repSequence)
1574 if (index == sSize - 1)
1579 seqs[index++] = sg.getSequenceAt(i);
1582 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1583 sg.setHidereps(true); // note: not done in 2.7applet
1590 * @return null or the current reference sequence
1592 public SequenceI getReferenceSeq()
1594 return alignment.getSeqrep();
1599 * @return true iff seq is the reference for the alignment
1601 public boolean isReferenceSeq(SequenceI seq)
1603 return alignment.getSeqrep() == seq;
1609 * @return true if there are sequences represented by this sequence that are
1612 public boolean isHiddenRepSequence(SequenceI seq)
1614 return (hiddenRepSequences != null && hiddenRepSequences
1621 * @return null or a sequence group containing the sequences that seq
1624 public SequenceGroup getRepresentedSequences(SequenceI seq)
1626 return (SequenceGroup) (hiddenRepSequences == null ? null
1627 : hiddenRepSequences.get(seq));
1631 public int adjustForHiddenSeqs(int alignmentIndex)
1633 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1638 public void invertColumnSelection()
1640 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1644 public SequenceI[] getSelectionAsNewSequence()
1646 SequenceI[] sequences;
1647 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1648 // this was the only caller in the applet for this method
1649 // JBPNote: in applet, this method returned references to the alignment
1650 // sequences, and it did not honour the presence/absence of annotation
1651 // attached to the alignment (probably!)
1652 if (selectionGroup == null || selectionGroup.getSize() == 0)
1654 sequences = alignment.getSequencesArray();
1655 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1656 for (int i = 0; i < sequences.length; i++)
1658 // construct new sequence with subset of visible annotation
1659 sequences[i] = new Sequence(sequences[i], annots);
1664 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1671 public SequenceI[] getSequenceSelection()
1673 SequenceI[] sequences = null;
1674 if (selectionGroup != null)
1676 sequences = selectionGroup.getSequencesInOrder(alignment);
1678 if (sequences == null)
1680 sequences = alignment.getSequencesArray();
1686 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1688 return new CigarArray(alignment, alignment.getHiddenColumns(),
1689 (selectedRegionOnly ? selectionGroup : null));
1693 public jalview.datamodel.AlignmentView getAlignmentView(
1694 boolean selectedOnly)
1696 return getAlignmentView(selectedOnly, false);
1700 public jalview.datamodel.AlignmentView getAlignmentView(
1701 boolean selectedOnly, boolean markGroups)
1703 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1704 selectionGroup, alignment.getHiddenColumns() != null
1705 && alignment.getHiddenColumns().hasHiddenColumns(),
1711 public String[] getViewAsString(boolean selectedRegionOnly)
1713 return getViewAsString(selectedRegionOnly, true);
1717 public String[] getViewAsString(boolean selectedRegionOnly,
1718 boolean exportHiddenSeqs)
1720 String[] selection = null;
1721 SequenceI[] seqs = null;
1723 int start = 0, end = 0;
1724 if (selectedRegionOnly && selectionGroup != null)
1726 iSize = selectionGroup.getSize();
1727 seqs = selectionGroup.getSequencesInOrder(alignment);
1728 start = selectionGroup.getStartRes();
1729 end = selectionGroup.getEndRes() + 1;
1733 if (hasHiddenRows() && exportHiddenSeqs)
1735 AlignmentI fullAlignment = alignment.getHiddenSequences()
1736 .getFullAlignment();
1737 iSize = fullAlignment.getHeight();
1738 seqs = fullAlignment.getSequencesArray();
1739 end = fullAlignment.getWidth();
1743 iSize = alignment.getHeight();
1744 seqs = alignment.getSequencesArray();
1745 end = alignment.getWidth();
1749 selection = new String[iSize];
1750 if (alignment.getHiddenColumns() != null
1751 && alignment.getHiddenColumns().hasHiddenColumns())
1753 selection = alignment.getHiddenColumns().getVisibleSequenceStrings(
1758 for (i = 0; i < iSize; i++)
1760 selection[i] = seqs[i].getSequenceAsString(start, end);
1768 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1770 ArrayList<int[]> regions = new ArrayList<>();
1776 HiddenColumns hidden = alignment.getHiddenColumns();
1777 if (hidden != null && hidden.hasHiddenColumns())
1781 start = hidden.adjustForHiddenColumns(start);
1784 end = hidden.getHiddenBoundaryRight(start);
1795 regions.add(new int[] { start, end });
1797 if (hidden != null && hidden.hasHiddenColumns())
1799 start = hidden.adjustForHiddenColumns(end);
1800 start = hidden.getHiddenBoundaryLeft(start) + 1;
1802 } while (end < max);
1804 int[][] startEnd = new int[regions.size()][2];
1810 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1811 boolean selectedOnly)
1813 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1814 AlignmentAnnotation[] aa;
1815 if ((aa = alignment.getAlignmentAnnotation()) != null)
1817 for (AlignmentAnnotation annot : aa)
1819 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1820 if (selectedOnly && selectionGroup != null)
1822 alignment.getHiddenColumns().makeVisibleAnnotation(
1823 selectionGroup.getStartRes(),
1824 selectionGroup.getEndRes(), clone);
1828 alignment.getHiddenColumns().makeVisibleAnnotation(clone);
1837 public boolean isPadGaps()
1843 public void setPadGaps(boolean padGaps)
1845 this.padGaps = padGaps;
1849 * apply any post-edit constraints and trigger any calculations needed after
1850 * an edit has been performed on the alignment
1855 public void alignmentChanged(AlignmentViewPanel ap)
1859 alignment.padGaps();
1861 if (autoCalculateConsensus)
1863 updateConsensus(ap);
1865 if (hconsensus != null && autoCalculateConsensus)
1867 updateConservation(ap);
1869 if (autoCalculateStrucConsensus)
1871 updateStrucConsensus(ap);
1874 // Reset endRes of groups if beyond alignment width
1875 int alWidth = alignment.getWidth();
1876 List<SequenceGroup> groups = alignment.getGroups();
1879 for (SequenceGroup sg : groups)
1881 if (sg.getEndRes() > alWidth)
1883 sg.setEndRes(alWidth - 1);
1888 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1890 selectionGroup.setEndRes(alWidth - 1);
1893 updateAllColourSchemes();
1894 calculator.restartWorkers();
1895 // alignment.adjustSequenceAnnotations();
1899 * reset scope and do calculations for all applied colourschemes on alignment
1901 void updateAllColourSchemes()
1903 ResidueShaderI rs = residueShading;
1906 rs.alignmentChanged(alignment, hiddenRepSequences);
1908 rs.setConsensus(hconsensus);
1909 if (rs.conservationApplied())
1911 rs.setConservation(Conservation.calculateConservation("All",
1912 alignment.getSequences(), 0, alignment.getWidth(), false,
1913 getConsPercGaps(), false));
1917 for (SequenceGroup sg : alignment.getGroups())
1921 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1923 sg.recalcConservation();
1927 protected void initAutoAnnotation()
1929 // TODO: add menu option action that nulls or creates consensus object
1930 // depending on if the user wants to see the annotation or not in a
1931 // specific alignment
1933 if (hconsensus == null && !isDataset)
1935 if (!alignment.isNucleotide())
1944 consensus = new AlignmentAnnotation("Consensus",
1945 MessageManager.getString("label.consensus_descr"),
1946 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1947 initConsensus(consensus);
1950 initComplementConsensus();
1955 * If this is a protein alignment and there are mappings to cDNA, adds the
1956 * cDNA consensus annotation and returns true, else returns false.
1958 public boolean initComplementConsensus()
1960 if (!alignment.isNucleotide())
1962 final List<AlignedCodonFrame> codonMappings = alignment
1964 if (codonMappings != null && !codonMappings.isEmpty())
1966 boolean doConsensus = false;
1967 for (AlignedCodonFrame mapping : codonMappings)
1969 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1970 MapList[] mapLists = mapping.getdnaToProt();
1971 // mapLists can be empty if project load has not finished resolving
1973 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1981 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1983 .getString("label.complement_consensus_descr"),
1984 new Annotation[1], 0f, 100f,
1985 AlignmentAnnotation.BAR_GRAPH);
1986 initConsensus(complementConsensus);
1994 private void initConsensus(AlignmentAnnotation aa)
1997 aa.autoCalculated = true;
2001 alignment.addAnnotation(aa);
2005 // these should be extracted from the view model - style and settings for
2006 // derived annotation
2007 private void initGapCounts()
2011 gapcounts = new AlignmentAnnotation("Occupancy",
2012 MessageManager.getString("label.occupancy_descr"),
2013 new Annotation[1], 0f,
2014 alignment.getHeight(), AlignmentAnnotation.BAR_GRAPH);
2015 gapcounts.hasText = true;
2016 gapcounts.autoCalculated = true;
2017 gapcounts.scaleColLabel = true;
2018 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2020 alignment.addAnnotation(gapcounts);
2024 private void initConservation()
2026 if (showConservation)
2028 if (conservation == null)
2030 conservation = new AlignmentAnnotation("Conservation",
2031 MessageManager.formatMessage("label.conservation_descr",
2032 getConsPercGaps()), new Annotation[1],
2033 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2034 conservation.hasText = true;
2035 conservation.autoCalculated = true;
2036 alignment.addAnnotation(conservation);
2041 private void initQuality()
2045 if (quality == null)
2047 quality = new AlignmentAnnotation("Quality",
2048 MessageManager.getString("label.quality_descr"),
2049 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2050 quality.hasText = true;
2051 quality.autoCalculated = true;
2052 alignment.addAnnotation(quality);
2057 private void initRNAStructure()
2059 if (alignment.hasRNAStructure() && strucConsensus == null)
2061 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2062 MessageManager.getString("label.strucconsensus_descr"),
2063 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2064 strucConsensus.hasText = true;
2065 strucConsensus.autoCalculated = true;
2069 alignment.addAnnotation(strucConsensus);
2077 * @see jalview.api.AlignViewportI#calcPanelHeight()
2080 public int calcPanelHeight()
2082 // setHeight of panels
2083 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2085 int charHeight = getCharHeight();
2088 BitSet graphgrp = new BitSet();
2089 for (AlignmentAnnotation aa : anns)
2093 System.err.println("Null annotation row: ignoring.");
2100 if (aa.graphGroup > -1)
2102 if (graphgrp.get(aa.graphGroup))
2108 graphgrp.set(aa.graphGroup);
2115 aa.height += charHeight;
2125 aa.height += aa.graphHeight;
2133 height += aa.height;
2145 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2146 boolean preserveNewGroupSettings)
2148 boolean updateCalcs = false;
2149 boolean conv = isShowGroupConservation();
2150 boolean cons = isShowGroupConsensus();
2151 boolean showprf = isShowSequenceLogo();
2152 boolean showConsHist = isShowConsensusHistogram();
2153 boolean normLogo = isNormaliseSequenceLogo();
2156 * TODO reorder the annotation rows according to group/sequence ordering on
2159 boolean sortg = true;
2161 // remove old automatic annotation
2162 // add any new annotation
2164 // intersect alignment annotation with alignment groups
2166 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2167 List<SequenceGroup> oldrfs = new ArrayList<>();
2170 for (int an = 0; an < aan.length; an++)
2172 if (aan[an].autoCalculated && aan[an].groupRef != null)
2174 oldrfs.add(aan[an].groupRef);
2175 alignment.deleteAnnotation(aan[an], false);
2179 if (alignment.getGroups() != null)
2181 for (SequenceGroup sg : alignment.getGroups())
2183 updateCalcs = false;
2184 if (applyGlobalSettings
2185 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2187 // set defaults for this group's conservation/consensus
2188 sg.setshowSequenceLogo(showprf);
2189 sg.setShowConsensusHistogram(showConsHist);
2190 sg.setNormaliseSequenceLogo(normLogo);
2195 alignment.addAnnotation(sg.getConservationRow(), 0);
2200 alignment.addAnnotation(sg.getConsensus(), 0);
2202 // refresh the annotation rows
2205 sg.recalcConservation();
2213 public boolean isDisplayReferenceSeq()
2215 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2219 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2221 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2225 public boolean isColourByReferenceSeq()
2227 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2231 public Color getSequenceColour(SequenceI seq)
2233 Color sqc = sequenceColours.get(seq);
2234 return (sqc == null ? Color.white : sqc);
2238 public void setSequenceColour(SequenceI seq, Color col)
2242 sequenceColours.remove(seq);
2246 sequenceColours.put(seq, col);
2251 public void updateSequenceIdColours()
2253 for (SequenceGroup sg : alignment.getGroups())
2255 if (sg.idColour != null)
2257 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2259 sequenceColours.put(s, sg.idColour);
2266 public void clearSequenceColours()
2268 sequenceColours.clear();
2272 public AlignViewportI getCodingComplement()
2274 return this.codingComplement;
2278 * Set this as the (cDna/protein) complement of the given viewport. Also
2279 * ensures the reverse relationship is set on the given viewport.
2282 public void setCodingComplement(AlignViewportI av)
2286 System.err.println("Ignoring recursive setCodingComplement request");
2290 this.codingComplement = av;
2291 // avoid infinite recursion!
2292 if (av.getCodingComplement() != this)
2294 av.setCodingComplement(this);
2300 public boolean isNucleotide()
2302 return getAlignment() == null ? false : getAlignment().isNucleotide();
2306 public FeaturesDisplayedI getFeaturesDisplayed()
2308 return featuresDisplayed;
2312 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2314 featuresDisplayed = featuresDisplayedI;
2318 public boolean areFeaturesDisplayed()
2320 return featuresDisplayed != null
2321 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2328 * features are displayed if true
2331 public void setShowSequenceFeatures(boolean b)
2333 viewStyle.setShowSequenceFeatures(b);
2337 public boolean isShowSequenceFeatures()
2339 return viewStyle.isShowSequenceFeatures();
2343 public void setShowSequenceFeaturesHeight(boolean selected)
2345 viewStyle.setShowSequenceFeaturesHeight(selected);
2349 public boolean isShowSequenceFeaturesHeight()
2351 return viewStyle.isShowSequenceFeaturesHeight();
2355 public void setShowAnnotation(boolean b)
2357 viewStyle.setShowAnnotation(b);
2361 public boolean isShowAnnotation()
2363 return viewStyle.isShowAnnotation();
2367 public boolean isRightAlignIds()
2369 return viewStyle.isRightAlignIds();
2373 public void setRightAlignIds(boolean rightAlignIds)
2375 viewStyle.setRightAlignIds(rightAlignIds);
2379 public boolean getConservationSelected()
2381 return viewStyle.getConservationSelected();
2385 public void setShowBoxes(boolean state)
2387 viewStyle.setShowBoxes(state);
2392 * @see jalview.api.ViewStyleI#getTextColour()
2395 public Color getTextColour()
2397 return viewStyle.getTextColour();
2402 * @see jalview.api.ViewStyleI#getTextColour2()
2405 public Color getTextColour2()
2407 return viewStyle.getTextColour2();
2412 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2415 public int getThresholdTextColour()
2417 return viewStyle.getThresholdTextColour();
2422 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2425 public boolean isConservationColourSelected()
2427 return viewStyle.isConservationColourSelected();
2432 * @see jalview.api.ViewStyleI#isRenderGaps()
2435 public boolean isRenderGaps()
2437 return viewStyle.isRenderGaps();
2442 * @see jalview.api.ViewStyleI#isShowColourText()
2445 public boolean isShowColourText()
2447 return viewStyle.isShowColourText();
2451 * @param conservationColourSelected
2452 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2455 public void setConservationColourSelected(
2456 boolean conservationColourSelected)
2458 viewStyle.setConservationColourSelected(conservationColourSelected);
2462 * @param showColourText
2463 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2466 public void setShowColourText(boolean showColourText)
2468 viewStyle.setShowColourText(showColourText);
2473 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2476 public void setTextColour(Color textColour)
2478 viewStyle.setTextColour(textColour);
2482 * @param thresholdTextColour
2483 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2486 public void setThresholdTextColour(int thresholdTextColour)
2488 viewStyle.setThresholdTextColour(thresholdTextColour);
2492 * @param textColour2
2493 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2496 public void setTextColour2(Color textColour2)
2498 viewStyle.setTextColour2(textColour2);
2502 public ViewStyleI getViewStyle()
2504 return new ViewStyle(viewStyle);
2508 public void setViewStyle(ViewStyleI settingsForView)
2510 viewStyle = new ViewStyle(settingsForView);
2511 if (residueShading != null)
2513 residueShading.setConservationApplied(settingsForView
2514 .isConservationColourSelected());
2519 public boolean sameStyle(ViewStyleI them)
2521 return viewStyle.sameStyle(them);
2526 * @see jalview.api.ViewStyleI#getIdWidth()
2529 public int getIdWidth()
2531 return viewStyle.getIdWidth();
2536 * @see jalview.api.ViewStyleI#setIdWidth(int)
2539 public void setIdWidth(int i)
2541 viewStyle.setIdWidth(i);
2546 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2549 public boolean isCentreColumnLabels()
2551 return viewStyle.isCentreColumnLabels();
2555 * @param centreColumnLabels
2556 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2559 public void setCentreColumnLabels(boolean centreColumnLabels)
2561 viewStyle.setCentreColumnLabels(centreColumnLabels);
2566 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2569 public void setShowDBRefs(boolean showdbrefs)
2571 viewStyle.setShowDBRefs(showdbrefs);
2576 * @see jalview.api.ViewStyleI#isShowDBRefs()
2579 public boolean isShowDBRefs()
2581 return viewStyle.isShowDBRefs();
2586 * @see jalview.api.ViewStyleI#isShowNPFeats()
2589 public boolean isShowNPFeats()
2591 return viewStyle.isShowNPFeats();
2595 * @param shownpfeats
2596 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2599 public void setShowNPFeats(boolean shownpfeats)
2601 viewStyle.setShowNPFeats(shownpfeats);
2604 public abstract StructureSelectionManager getStructureSelectionManager();
2607 * Add one command to the command history list.
2611 public void addToHistoryList(CommandI command)
2613 if (this.historyList != null)
2615 this.historyList.push(command);
2616 broadcastCommand(command, false);
2620 protected void broadcastCommand(CommandI command, boolean undo)
2622 getStructureSelectionManager().commandPerformed(command, undo,
2627 * Add one command to the command redo list.
2631 public void addToRedoList(CommandI command)
2633 if (this.redoList != null)
2635 this.redoList.push(command);
2637 broadcastCommand(command, true);
2641 * Clear the command redo list.
2643 public void clearRedoList()
2645 if (this.redoList != null)
2647 this.redoList.clear();
2651 public void setHistoryList(Deque<CommandI> list)
2653 this.historyList = list;
2656 public Deque<CommandI> getHistoryList()
2658 return this.historyList;
2661 public void setRedoList(Deque<CommandI> list)
2663 this.redoList = list;
2666 public Deque<CommandI> getRedoList()
2668 return this.redoList;
2672 public VamsasSource getVamsasSource()
2677 public SequenceAnnotationOrder getSortAnnotationsBy()
2679 return sortAnnotationsBy;
2682 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2684 this.sortAnnotationsBy = sortAnnotationsBy;
2687 public boolean isShowAutocalculatedAbove()
2689 return showAutocalculatedAbove;
2692 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2694 this.showAutocalculatedAbove = showAutocalculatedAbove;
2698 public boolean isScaleProteinAsCdna()
2700 return viewStyle.isScaleProteinAsCdna();
2704 public void setScaleProteinAsCdna(boolean b)
2706 viewStyle.setScaleProteinAsCdna(b);
2710 public boolean isProteinFontAsCdna()
2712 return viewStyle.isProteinFontAsCdna();
2716 public void setProteinFontAsCdna(boolean b)
2718 viewStyle.setProteinFontAsCdna(b);
2722 * @return true if view should scroll to show the highlighted region of a
2727 public final boolean isFollowHighlight()
2729 return followHighlight;
2733 public final void setFollowHighlight(boolean b)
2735 this.followHighlight = b;
2739 public ViewportRanges getRanges()
2745 * Helper method to populate the SearchResults with the location in the
2746 * complementary alignment to scroll to, in order to match this one.
2749 * the SearchResults to add to
2750 * @return the offset (below top of visible region) of the matched sequence
2752 protected int findComplementScrollTarget(SearchResultsI sr)
2754 final AlignViewportI complement = getCodingComplement();
2755 if (complement == null || !complement.isFollowHighlight())
2759 boolean iAmProtein = !getAlignment().isNucleotide();
2760 AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement
2762 if (proteinAlignment == null)
2766 final List<AlignedCodonFrame> mappings = proteinAlignment
2770 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2771 * residue in the middle column of the visible region. Scroll the
2772 * complementary alignment to line up the corresponding residue.
2775 SequenceI sequence = null;
2778 * locate 'middle' column (true middle if an odd number visible, left of
2779 * middle if an even number visible)
2781 int middleColumn = ranges.getStartRes()
2782 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2783 final HiddenSequences hiddenSequences = getAlignment()
2784 .getHiddenSequences();
2787 * searching to the bottom of the alignment gives smoother scrolling across
2788 * all gapped visible regions
2790 int lastSeq = alignment.getHeight() - 1;
2791 List<AlignedCodonFrame> seqMappings = null;
2792 for (int seqNo = ranges.getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2794 sequence = getAlignment().getSequenceAt(seqNo);
2795 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2799 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2803 seqMappings = MappingUtils
2804 .findMappingsForSequenceAndOthers(sequence, mappings,
2805 getCodingComplement().getAlignment().getSequences());
2806 if (!seqMappings.isEmpty())
2812 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2815 * No ungapped mapped sequence in middle column - do nothing
2819 MappingUtils.addSearchResults(sr, sequence,
2820 sequence.findPosition(middleColumn), seqMappings);
2825 * synthesize a column selection if none exists so it covers the given
2826 * selection group. if wholewidth is false, no column selection is made if the
2827 * selection group covers the whole alignment width.
2832 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2835 if (sg != null && (sgs = sg.getStartRes()) >= 0
2836 && sg.getStartRes() <= (sge = sg.getEndRes())
2837 && !this.hasSelectedColumns())
2839 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2846 colSel = new ColumnSelection();
2848 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2850 colSel.addElement(cspos);
2856 * hold status of current selection group - defined on alignment or not.
2858 private boolean selectionIsDefinedGroup = false;
2861 public boolean isSelectionDefinedGroup()
2863 if (selectionGroup == null)
2867 if (isSelectionGroupChanged(true))
2869 selectionIsDefinedGroup = false;
2870 List<SequenceGroup> gps = alignment.getGroups();
2871 if (gps == null || gps.size() == 0)
2873 selectionIsDefinedGroup = false;
2877 selectionIsDefinedGroup = gps.contains(selectionGroup);
2880 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2884 * null, or currently highlighted results on this view
2886 private SearchResultsI searchResults = 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" : ""));