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
85 * An enum for auto-calculated annotations, with constants for the
86 * annotation's label, and the key for the property to show it or not
88 public enum AutoAnnotation
90 CONSERVATION("Conservation", "SHOW_CONSERVATION"),
91 QUALITY("Quality", "SHOW_QUALITY"),
92 CONSENSUS("Consensus", "SHOW_IDENTITY"),
93 OCCUPANCY("Occupancy", "SHOW_OCCUPANCY");
95 public final String label;
96 public final String preferenceKey;
98 private AutoAnnotation(String lbl, String prefKey)
101 this.preferenceKey = prefKey;
105 protected ViewportRanges ranges;
107 protected ViewStyleI viewStyle = new ViewStyle();
110 * A viewport that hosts the cDna view of this (protein), or vice versa (if
113 AlignViewportI codingComplement = null;
115 FeaturesDisplayedI featuresDisplayed = null;
117 protected Deque<CommandI> historyList = new ArrayDeque<>();
119 protected Deque<CommandI> redoList = new ArrayDeque<>();
122 * alignment displayed in the viewport. Please use get/setter
124 protected AlignmentI alignment;
126 public AlignmentViewport(AlignmentI al)
129 ranges = new ViewportRanges(al);
134 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
137 public void setFontName(String name)
139 viewStyle.setFontName(name);
144 * @see jalview.api.ViewStyleI#setFontStyle(int)
147 public void setFontStyle(int style)
149 viewStyle.setFontStyle(style);
154 * @see jalview.api.ViewStyleI#setFontSize(int)
157 public void setFontSize(int size)
159 viewStyle.setFontSize(size);
164 * @see jalview.api.ViewStyleI#getFontStyle()
167 public int getFontStyle()
169 return viewStyle.getFontStyle();
174 * @see jalview.api.ViewStyleI#getFontName()
177 public String getFontName()
179 return viewStyle.getFontName();
184 * @see jalview.api.ViewStyleI#getFontSize()
187 public int getFontSize()
189 return viewStyle.getFontSize();
193 * @param upperCasebold
194 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
197 public void setUpperCasebold(boolean upperCasebold)
199 viewStyle.setUpperCasebold(upperCasebold);
204 * @see jalview.api.ViewStyleI#isUpperCasebold()
207 public boolean isUpperCasebold()
209 return viewStyle.isUpperCasebold();
214 * @see jalview.api.ViewStyleI#isSeqNameItalics()
217 public boolean isSeqNameItalics()
219 return viewStyle.isSeqNameItalics();
223 * @param colourByReferenceSeq
224 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
227 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
229 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
234 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
237 public void setColourAppliesToAllGroups(boolean b)
239 viewStyle.setColourAppliesToAllGroups(b);
244 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
247 public boolean getColourAppliesToAllGroups()
249 return viewStyle.getColourAppliesToAllGroups();
254 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
257 public boolean getAbovePIDThreshold()
259 return viewStyle.getAbovePIDThreshold();
264 * @see jalview.api.ViewStyleI#setIncrement(int)
267 public void setIncrement(int inc)
269 viewStyle.setIncrement(inc);
274 * @see jalview.api.ViewStyleI#getIncrement()
277 public int getIncrement()
279 return viewStyle.getIncrement();
284 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
287 public void setConservationSelected(boolean b)
289 viewStyle.setConservationSelected(b);
294 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
297 public void setShowHiddenMarkers(boolean show)
299 viewStyle.setShowHiddenMarkers(show);
304 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
307 public boolean getShowHiddenMarkers()
309 return viewStyle.getShowHiddenMarkers();
314 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
317 public void setScaleRightWrapped(boolean b)
319 viewStyle.setScaleRightWrapped(b);
324 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
327 public void setScaleLeftWrapped(boolean b)
329 viewStyle.setScaleLeftWrapped(b);
334 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
337 public void setScaleAboveWrapped(boolean b)
339 viewStyle.setScaleAboveWrapped(b);
344 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
347 public boolean getScaleLeftWrapped()
349 return viewStyle.getScaleLeftWrapped();
354 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
357 public boolean getScaleAboveWrapped()
359 return viewStyle.getScaleAboveWrapped();
364 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
367 public boolean getScaleRightWrapped()
369 return viewStyle.getScaleRightWrapped();
374 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
377 public void setAbovePIDThreshold(boolean b)
379 viewStyle.setAbovePIDThreshold(b);
384 * @see jalview.api.ViewStyleI#setThreshold(int)
387 public void setThreshold(int thresh)
389 viewStyle.setThreshold(thresh);
394 * @see jalview.api.ViewStyleI#getThreshold()
397 public int getThreshold()
399 return viewStyle.getThreshold();
404 * @see jalview.api.ViewStyleI#getShowJVSuffix()
407 public boolean getShowJVSuffix()
409 return viewStyle.getShowJVSuffix();
414 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
417 public void setShowJVSuffix(boolean b)
419 viewStyle.setShowJVSuffix(b);
424 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
427 public void setWrapAlignment(boolean state)
429 viewStyle.setWrapAlignment(state);
430 ranges.setWrappedMode(state);
435 * @see jalview.api.ViewStyleI#setShowText(boolean)
438 public void setShowText(boolean state)
440 viewStyle.setShowText(state);
445 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
448 public void setRenderGaps(boolean state)
450 viewStyle.setRenderGaps(state);
455 * @see jalview.api.ViewStyleI#getColourText()
458 public boolean getColourText()
460 return viewStyle.getColourText();
465 * @see jalview.api.ViewStyleI#setColourText(boolean)
468 public void setColourText(boolean state)
470 viewStyle.setColourText(state);
475 * @see jalview.api.ViewStyleI#getWrapAlignment()
478 public boolean getWrapAlignment()
480 return viewStyle.getWrapAlignment();
485 * @see jalview.api.ViewStyleI#getShowText()
488 public boolean getShowText()
490 return viewStyle.getShowText();
495 * @see jalview.api.ViewStyleI#getWrappedWidth()
498 public int getWrappedWidth()
500 return viewStyle.getWrappedWidth();
505 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
508 public void setWrappedWidth(int w)
510 viewStyle.setWrappedWidth(w);
515 * @see jalview.api.ViewStyleI#getCharHeight()
518 public int getCharHeight()
520 return viewStyle.getCharHeight();
525 * @see jalview.api.ViewStyleI#setCharHeight(int)
528 public void setCharHeight(int h)
530 viewStyle.setCharHeight(h);
535 * @see jalview.api.ViewStyleI#getCharWidth()
538 public int getCharWidth()
540 return viewStyle.getCharWidth();
545 * @see jalview.api.ViewStyleI#setCharWidth(int)
548 public void setCharWidth(int w)
550 viewStyle.setCharWidth(w);
555 * @see jalview.api.ViewStyleI#getShowBoxes()
558 public boolean getShowBoxes()
560 return viewStyle.getShowBoxes();
565 * @see jalview.api.ViewStyleI#getShowUnconserved()
568 public boolean getShowUnconserved()
570 return viewStyle.getShowUnconserved();
574 * @param showunconserved
575 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
578 public void setShowUnconserved(boolean showunconserved)
580 viewStyle.setShowUnconserved(showunconserved);
585 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
588 public void setSeqNameItalics(boolean default1)
590 viewStyle.setSeqNameItalics(default1);
594 public AlignmentI getAlignment()
600 public char getGapCharacter()
602 return alignment.getGapCharacter();
605 protected String sequenceSetID;
608 * probably unused indicator that view is of a dataset rather than an
611 protected boolean isDataset = false;
613 public void setDataset(boolean b)
618 public boolean isDataset()
623 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
625 protected ColumnSelection colSel = new ColumnSelection();
627 public boolean autoCalculateConsensus = true;
629 protected boolean autoCalculateStrucConsensus = true;
631 protected boolean ignoreGapsInConsensusCalculation = false;
633 protected ResidueShaderI residueShading = new ResidueShader();
636 public void setGlobalColourScheme(ColourSchemeI cs)
638 // TODO: logic refactored from AlignFrame changeColour -
639 // TODO: autorecalc stuff should be changed to rely on the worker system
640 // check to see if we should implement a changeColour(cs) method rather than
641 // put the logic in here
642 // - means that caller decides if they want to just modify state and defer
643 // calculation till later or to do all calculations in thread.
647 * only instantiate alignment colouring once, thereafter update it;
648 * this means that any conservation or PID threshold settings
649 * persist when the alignment colour scheme is changed
651 if (residueShading == null)
653 residueShading = new ResidueShader(viewStyle);
655 residueShading.setColourScheme(cs);
657 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
658 // ...problem: groups need these, but do not currently have a ViewStyle
662 if (getConservationSelected())
664 residueShading.setConservation(hconservation);
667 * reset conservation flag in case just set to false if
668 * Conservation was null (calculation still in progress)
670 residueShading.setConservationApplied(getConservationSelected());
671 residueShading.alignmentChanged(alignment, hiddenRepSequences);
675 * if 'apply colour to all groups' is selected... do so
676 * (but don't transfer any colour threshold settings to groups)
678 if (getColourAppliesToAllGroups())
680 for (SequenceGroup sg : getAlignment().getGroups())
683 * retain any colour thresholds per group while
684 * changing choice of colour scheme (JAL-2386)
687 cs == null ? null : cs.getInstance(this, sg));
690 sg.getGroupColourScheme().alignmentChanged(sg,
698 public ColourSchemeI getGlobalColourScheme()
700 return residueShading == null ? null : residueShading.getColourScheme();
704 public ResidueShaderI getResidueShading()
706 return residueShading;
709 protected AlignmentAnnotation consensus;
711 protected AlignmentAnnotation complementConsensus;
713 protected AlignmentAnnotation gapcounts;
715 protected AlignmentAnnotation strucConsensus;
717 protected AlignmentAnnotation conservation;
719 protected AlignmentAnnotation quality;
721 protected AlignmentAnnotation[] groupConsensus;
723 protected AlignmentAnnotation[] groupConservation;
726 * results of alignment consensus analysis for visible portion of view
728 protected ProfilesI hconsensus = null;
731 * results of cDNA complement consensus visible portion of view
733 protected Hashtable[] hcomplementConsensus = null;
736 * results of secondary structure base pair consensus for visible portion of
739 protected Hashtable[] hStrucConsensus = null;
741 protected Conservation hconservation = null;
744 public void setConservation(Conservation cons)
746 hconservation = cons;
750 * percentage gaps allowed in a column before all amino acid properties should
751 * be considered unconserved
753 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
756 public int getConsPercGaps()
762 public void setSequenceConsensusHash(ProfilesI hconsensus)
764 this.hconsensus = hconsensus;
768 public void setComplementConsensusHash(Hashtable[] hconsensus)
770 this.hcomplementConsensus = hconsensus;
774 public ProfilesI getSequenceConsensusHash()
780 public Hashtable[] getComplementConsensusHash()
782 return hcomplementConsensus;
786 public Hashtable[] getRnaStructureConsensusHash()
788 return hStrucConsensus;
792 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
794 this.hStrucConsensus = hStrucConsensus;
799 public AlignmentAnnotation getAlignmentQualityAnnot()
805 public AlignmentAnnotation getAlignmentConservationAnnotation()
811 public AlignmentAnnotation getAlignmentConsensusAnnotation()
817 public AlignmentAnnotation getAlignmentGapAnnotation()
823 public AlignmentAnnotation getComplementConsensusAnnotation()
825 return complementConsensus;
829 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
831 return strucConsensus;
834 protected AlignCalcManagerI calculator = new AlignCalcManager();
837 * trigger update of conservation annotation
839 public void updateConservation(final AlignmentViewPanel ap)
841 // see note in mantis : issue number 8585
842 if (alignment.isNucleotide()
843 || (conservation == null && quality == null)
844 || !autoCalculateConsensus)
848 if (calculator.getRegisteredWorkersOfClass(
849 jalview.workers.ConservationThread.class) == null)
851 calculator.registerWorker(
852 new jalview.workers.ConservationThread(this, ap));
857 * trigger update of consensus annotation
859 public void updateConsensus(final AlignmentViewPanel ap)
861 // see note in mantis : issue number 8585
862 if (consensus == null || !autoCalculateConsensus)
867 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
869 calculator.registerWorker(new ConsensusThread(this, ap));
873 * A separate thread to compute cDNA consensus for a protein alignment
874 * which has mapping to cDNA
876 final AlignmentI al = this.getAlignment();
877 if (!al.isNucleotide() && al.getCodonFrames() != null
878 && !al.getCodonFrames().isEmpty())
881 * fudge - check first for protein-to-nucleotide mappings
882 * (we don't want to do this for protein-to-protein)
884 boolean doConsensus = false;
885 for (AlignedCodonFrame mapping : al.getCodonFrames())
887 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
888 MapList[] mapLists = mapping.getdnaToProt();
889 // mapLists can be empty if project load has not finished resolving seqs
890 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
898 if (calculator.getRegisteredWorkersOfClass(
899 ComplementConsensusThread.class) == null)
902 .registerWorker(new ComplementConsensusThread(this, ap));
908 // --------START Structure Conservation
909 public void updateStrucConsensus(final AlignmentViewPanel ap)
911 if (autoCalculateStrucConsensus && strucConsensus == null
912 && alignment.isNucleotide() && alignment.hasRNAStructure())
914 // secondary structure has been added - so init the consensus line
918 // see note in mantis : issue number 8585
919 if (strucConsensus == null || !autoCalculateStrucConsensus)
923 if (calculator.getRegisteredWorkersOfClass(
924 StrucConsensusThread.class) == null)
926 calculator.registerWorker(new StrucConsensusThread(this, ap));
930 public boolean isCalcInProgress()
932 return calculator.isWorking();
936 public boolean isCalculationInProgress(
937 AlignmentAnnotation alignmentAnnotation)
939 if (!alignmentAnnotation.autoCalculated)
943 if (calculator.workingInvolvedWith(alignmentAnnotation))
945 // System.err.println("grey out ("+alignmentAnnotation.label+")");
951 public void setAlignment(AlignmentI align)
953 this.alignment = align;
957 * Clean up references when this viewport is closed
960 public void dispose()
963 * defensively null out references to large objects in case
964 * this object is not garbage collected (as if!)
967 complementConsensus = null;
968 strucConsensus = null;
971 groupConsensus = null;
972 groupConservation = null;
974 hconservation = null;
975 hcomplementConsensus = null;
978 residueShading = null; // may hold a reference to Consensus
979 changeSupport = null;
982 selectionGroup = null;
987 public boolean isClosed()
989 // TODO: check that this isClosed is only true after panel is closed, not
990 // before it is fully constructed.
991 return alignment == null;
995 public AlignCalcManagerI getCalcManager()
1001 * should conservation rows be shown for groups
1003 protected boolean showGroupConservation = false;
1006 * should consensus rows be shown for groups
1008 protected boolean showGroupConsensus = false;
1011 * should consensus profile be rendered by default
1013 protected boolean showSequenceLogo = false;
1016 * should consensus profile be rendered normalised to row height
1018 protected boolean normaliseSequenceLogo = false;
1021 * should consensus histograms be rendered by default
1023 protected boolean showConsensusHistogram = true;
1026 * @return the showConsensusProfile
1029 public boolean isShowSequenceLogo()
1031 return showSequenceLogo;
1035 * @param showSequenceLogo
1038 public void setShowSequenceLogo(boolean showSequenceLogo)
1040 if (showSequenceLogo != this.showSequenceLogo)
1042 // TODO: decouple settings setting from calculation when refactoring
1043 // annotation update method from alignframe to viewport
1044 this.showSequenceLogo = showSequenceLogo;
1045 calculator.updateAnnotationFor(ConsensusThread.class);
1046 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1047 calculator.updateAnnotationFor(StrucConsensusThread.class);
1049 this.showSequenceLogo = showSequenceLogo;
1053 * @param showConsensusHistogram
1054 * the showConsensusHistogram to set
1056 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1058 this.showConsensusHistogram = showConsensusHistogram;
1062 * @return the showGroupConservation
1064 public boolean isShowGroupConservation()
1066 return showGroupConservation;
1070 * @param showGroupConservation
1071 * the showGroupConservation to set
1073 public void setShowGroupConservation(boolean showGroupConservation)
1075 this.showGroupConservation = showGroupConservation;
1079 * @return the showGroupConsensus
1081 public boolean isShowGroupConsensus()
1083 return showGroupConsensus;
1087 * @param showGroupConsensus
1088 * the showGroupConsensus to set
1090 public void setShowGroupConsensus(boolean showGroupConsensus)
1092 this.showGroupConsensus = showGroupConsensus;
1097 * @return flag to indicate if the consensus histogram should be rendered by
1101 public boolean isShowConsensusHistogram()
1103 return this.showConsensusHistogram;
1107 * when set, updateAlignment will always ensure sequences are of equal length
1109 private boolean padGaps = false;
1112 * when set, alignment should be reordered according to a newly opened tree
1114 public boolean sortByTree = false;
1119 * @return null or the currently selected sequence region
1122 public SequenceGroup getSelectionGroup()
1124 return selectionGroup;
1128 * Set the selection group for this window. Also sets the current alignment as
1129 * the context for the group, if it does not already have one.
1132 * - group holding references to sequences in this alignment view
1136 public void setSelectionGroup(SequenceGroup sg)
1138 selectionGroup = sg;
1139 if (sg != null && sg.getContext() == null)
1141 sg.setContext(alignment);
1145 public void setHiddenColumns(HiddenColumns hidden)
1147 this.alignment.setHiddenColumns(hidden);
1151 public ColumnSelection getColumnSelection()
1157 public void setColumnSelection(ColumnSelection colSel)
1159 this.colSel = colSel;
1162 updateHiddenColumns();
1164 isColSelChanged(true);
1172 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1174 return hiddenRepSequences;
1178 public void setHiddenRepSequences(
1179 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1181 this.hiddenRepSequences = hiddenRepSequences;
1185 public boolean hasSelectedColumns()
1187 ColumnSelection columnSelection = getColumnSelection();
1188 return columnSelection != null && columnSelection.hasSelectedColumns();
1192 public boolean hasHiddenColumns()
1194 return alignment.getHiddenColumns() != null
1195 && alignment.getHiddenColumns().hasHiddenColumns();
1198 public void updateHiddenColumns()
1200 // this method doesn't really do anything now. But - it could, since a
1201 // column Selection could be in the process of modification
1202 // hasHiddenColumns = colSel.hasHiddenColumns();
1206 public boolean hasHiddenRows()
1208 return alignment.getHiddenSequences().getSize() > 0;
1211 protected SequenceGroup selectionGroup;
1213 public void setSequenceSetId(String newid)
1215 if (sequenceSetID != null)
1218 "Warning - overwriting a sequenceSetId for a viewport!");
1220 sequenceSetID = new String(newid);
1224 public String getSequenceSetId()
1226 if (sequenceSetID == null)
1228 sequenceSetID = alignment.hashCode() + "";
1231 return sequenceSetID;
1235 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1238 protected String viewId = null;
1241 public String getViewId()
1245 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1250 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1252 ignoreGapsInConsensusCalculation = b;
1255 updateConsensus(ap);
1256 if (residueShading != null)
1258 residueShading.setThreshold(residueShading.getThreshold(),
1259 ignoreGapsInConsensusCalculation);
1265 private long sgrouphash = -1, colselhash = -1;
1268 * checks current SelectionGroup against record of last hash value, and
1272 * update the record of last hash value
1274 * @return true if SelectionGroup changed since last call (when b is true)
1276 public boolean isSelectionGroupChanged(boolean b)
1278 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1279 : selectionGroup.hashCode();
1280 if (hc != -1 && hc != sgrouphash)
1292 * checks current colsel against record of last hash value, and optionally
1296 * update the record of last hash value
1297 * @return true if colsel changed since last call (when b is true)
1299 public boolean isColSelChanged(boolean b)
1301 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1302 if (hc != -1 && hc != colselhash)
1314 public boolean isIgnoreGapsConsensus()
1316 return ignoreGapsInConsensusCalculation;
1319 // property change stuff
1320 // JBPNote Prolly only need this in the applet version.
1321 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1324 protected boolean showConservation = true;
1326 protected boolean showQuality = true;
1328 protected boolean showConsensus = true;
1330 protected boolean showOccupancy = true;
1332 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1334 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1336 protected boolean showAutocalculatedAbove;
1339 * when set, view will scroll to show the highlighted position
1341 private boolean followHighlight = true;
1344 * Property change listener for changes in alignment
1349 public void addPropertyChangeListener(
1350 java.beans.PropertyChangeListener listener)
1352 changeSupport.addPropertyChangeListener(listener);
1361 public void removePropertyChangeListener(
1362 java.beans.PropertyChangeListener listener)
1364 if (changeSupport != null)
1366 changeSupport.removePropertyChangeListener(listener);
1371 * Property change listener for changes in alignment
1380 public void firePropertyChange(String prop, Object oldvalue,
1383 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1386 // common hide/show column stuff
1388 public void hideSelectedColumns()
1390 if (colSel.isEmpty())
1395 colSel.hideSelectedColumns(alignment);
1396 setSelectionGroup(null);
1397 isColSelChanged(true);
1400 public void hideColumns(int start, int end)
1404 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1408 alignment.getHiddenColumns().hideColumns(start, end);
1410 isColSelChanged(true);
1413 public void showColumn(int col)
1415 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1416 isColSelChanged(true);
1419 public void showAllHiddenColumns()
1421 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1422 isColSelChanged(true);
1425 // common hide/show seq stuff
1426 public void showAllHiddenSeqs()
1428 int startSeq = ranges.getStartSeq();
1429 int endSeq = ranges.getEndSeq();
1431 if (alignment.getHiddenSequences().getSize() > 0)
1433 if (selectionGroup == null)
1435 selectionGroup = new SequenceGroup();
1436 selectionGroup.setEndRes(alignment.getWidth() - 1);
1438 List<SequenceI> tmp = alignment.getHiddenSequences()
1439 .showAll(hiddenRepSequences);
1440 for (SequenceI seq : tmp)
1442 selectionGroup.addSequence(seq, false);
1443 setSequenceAnnotationsVisible(seq, true);
1446 hiddenRepSequences = null;
1448 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1450 firePropertyChange("alignment", null, alignment.getSequences());
1451 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1457 public void showSequence(int index)
1459 int startSeq = ranges.getStartSeq();
1460 int endSeq = ranges.getEndSeq();
1462 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1463 hiddenRepSequences);
1466 if (selectionGroup == null)
1468 selectionGroup = new SequenceGroup();
1469 selectionGroup.setEndRes(alignment.getWidth() - 1);
1472 for (SequenceI seq : tmp)
1474 selectionGroup.addSequence(seq, false);
1475 setSequenceAnnotationsVisible(seq, true);
1478 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1480 firePropertyChange("alignment", null, alignment.getSequences());
1485 public void hideAllSelectedSeqs()
1487 if (selectionGroup == null || selectionGroup.getSize() < 1)
1492 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1496 setSelectionGroup(null);
1499 public void hideSequence(SequenceI[] seq)
1502 * cache offset to first visible sequence
1504 int startSeq = ranges.getStartSeq();
1508 for (int i = 0; i < seq.length; i++)
1510 alignment.getHiddenSequences().hideSequence(seq[i]);
1511 setSequenceAnnotationsVisible(seq[i], false);
1513 ranges.setStartSeq(startSeq);
1514 firePropertyChange("alignment", null, alignment.getSequences());
1519 * Hides the specified sequence, or the sequences it represents
1522 * the sequence to hide, or keep as representative
1523 * @param representGroup
1524 * if true, hide the current selection group except for the
1525 * representative sequence
1527 public void hideSequences(SequenceI sequence, boolean representGroup)
1529 if (selectionGroup == null || selectionGroup.getSize() < 1)
1531 hideSequence(new SequenceI[] { sequence });
1537 hideRepSequences(sequence, selectionGroup);
1538 setSelectionGroup(null);
1542 int gsize = selectionGroup.getSize();
1543 SequenceI[] hseqs = selectionGroup.getSequences()
1544 .toArray(new SequenceI[gsize]);
1546 hideSequence(hseqs);
1547 setSelectionGroup(null);
1552 * Set visibility for any annotations for the given sequence.
1556 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1559 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1562 for (AlignmentAnnotation ann : anns)
1564 if (ann.sequenceRef == sequenceI)
1566 ann.visible = visible;
1572 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1574 int sSize = sg.getSize();
1580 if (hiddenRepSequences == null)
1582 hiddenRepSequences = new Hashtable<>();
1585 hiddenRepSequences.put(repSequence, sg);
1587 // Hide all sequences except the repSequence
1588 SequenceI[] seqs = new SequenceI[sSize - 1];
1590 for (int i = 0; i < sSize; i++)
1592 if (sg.getSequenceAt(i) != repSequence)
1594 if (index == sSize - 1)
1599 seqs[index++] = sg.getSequenceAt(i);
1602 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1603 sg.setHidereps(true); // note: not done in 2.7applet
1610 * @return null or the current reference sequence
1612 public SequenceI getReferenceSeq()
1614 return alignment.getSeqrep();
1619 * @return true iff seq is the reference for the alignment
1621 public boolean isReferenceSeq(SequenceI seq)
1623 return alignment.getSeqrep() == seq;
1629 * @return true if there are sequences represented by this sequence that are
1632 public boolean isHiddenRepSequence(SequenceI seq)
1634 return (hiddenRepSequences != null
1635 && hiddenRepSequences.containsKey(seq));
1641 * @return null or a sequence group containing the sequences that seq
1644 public SequenceGroup getRepresentedSequences(SequenceI seq)
1646 return (SequenceGroup) (hiddenRepSequences == null ? null
1647 : hiddenRepSequences.get(seq));
1651 public int adjustForHiddenSeqs(int alignmentIndex)
1653 return alignment.getHiddenSequences()
1654 .adjustForHiddenSeqs(alignmentIndex);
1658 public void invertColumnSelection()
1660 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1661 isColSelChanged(true);
1665 public SequenceI[] getSelectionAsNewSequence()
1667 SequenceI[] sequences;
1668 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1669 // this was the only caller in the applet for this method
1670 // JBPNote: in applet, this method returned references to the alignment
1671 // sequences, and it did not honour the presence/absence of annotation
1672 // attached to the alignment (probably!)
1673 if (selectionGroup == null || selectionGroup.getSize() == 0)
1675 sequences = alignment.getSequencesArray();
1676 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1677 for (int i = 0; i < sequences.length; i++)
1679 // construct new sequence with subset of visible annotation
1680 sequences[i] = new Sequence(sequences[i], annots);
1685 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1692 public SequenceI[] getSequenceSelection()
1694 SequenceI[] sequences = null;
1695 if (selectionGroup != null)
1697 sequences = selectionGroup.getSequencesInOrder(alignment);
1699 if (sequences == null)
1701 sequences = alignment.getSequencesArray();
1707 public jalview.datamodel.AlignmentView getAlignmentView(
1708 boolean selectedOnly)
1710 return getAlignmentView(selectedOnly, false);
1714 public jalview.datamodel.AlignmentView getAlignmentView(
1715 boolean selectedOnly, boolean markGroups)
1717 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1719 alignment.getHiddenColumns() != null
1720 && alignment.getHiddenColumns().hasHiddenColumns(),
1721 selectedOnly, markGroups);
1725 public String[] getViewAsString(boolean selectedRegionOnly)
1727 return getViewAsString(selectedRegionOnly, true);
1731 public String[] getViewAsString(boolean selectedRegionOnly,
1732 boolean exportHiddenSeqs)
1734 String[] selection = null;
1735 SequenceI[] seqs = null;
1737 int start = 0, end = 0;
1738 if (selectedRegionOnly && selectionGroup != null)
1740 iSize = selectionGroup.getSize();
1741 seqs = selectionGroup.getSequencesInOrder(alignment);
1742 start = selectionGroup.getStartRes();
1743 end = selectionGroup.getEndRes() + 1;
1747 if (hasHiddenRows() && exportHiddenSeqs)
1749 AlignmentI fullAlignment = alignment.getHiddenSequences()
1750 .getFullAlignment();
1751 iSize = fullAlignment.getHeight();
1752 seqs = fullAlignment.getSequencesArray();
1753 end = fullAlignment.getWidth();
1757 iSize = alignment.getHeight();
1758 seqs = alignment.getSequencesArray();
1759 end = alignment.getWidth();
1763 selection = new String[iSize];
1764 if (alignment.getHiddenColumns() != null
1765 && alignment.getHiddenColumns().hasHiddenColumns())
1767 for (i = 0; i < iSize; i++)
1769 Iterator<int[]> blocks = alignment.getHiddenColumns()
1770 .getVisContigsIterator(start, end + 1, false);
1771 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1776 for (i = 0; i < iSize; i++)
1778 selection[i] = seqs[i].getSequenceAsString(start, end);
1786 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1788 ArrayList<int[]> regions = new ArrayList<>();
1794 HiddenColumns hidden = alignment.getHiddenColumns();
1795 if (hidden != null && hidden.hasHiddenColumns())
1799 start = hidden.visibleToAbsoluteColumn(start);
1802 end = hidden.getNextHiddenBoundary(false, start);
1813 regions.add(new int[] { start, end });
1815 if (hidden != null && hidden.hasHiddenColumns())
1817 start = hidden.visibleToAbsoluteColumn(end);
1818 start = hidden.getNextHiddenBoundary(true, start) + 1;
1820 } while (end < max);
1822 int[][] startEnd = new int[regions.size()][2];
1828 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1829 boolean selectedOnly)
1831 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1832 AlignmentAnnotation[] aa;
1833 if ((aa = alignment.getAlignmentAnnotation()) != null)
1835 for (AlignmentAnnotation annot : aa)
1837 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1838 if (selectedOnly && selectionGroup != null)
1840 clone.makeVisibleAnnotation(
1841 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1842 alignment.getHiddenColumns());
1846 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1855 public boolean isPadGaps()
1861 public void setPadGaps(boolean padGaps)
1863 this.padGaps = padGaps;
1867 * apply any post-edit constraints and trigger any calculations needed after
1868 * an edit has been performed on the alignment
1873 public void alignmentChanged(AlignmentViewPanel ap)
1877 alignment.padGaps();
1879 if (autoCalculateConsensus)
1881 updateConsensus(ap);
1883 if (hconsensus != null && autoCalculateConsensus)
1885 updateConservation(ap);
1887 if (autoCalculateStrucConsensus)
1889 updateStrucConsensus(ap);
1892 // Reset endRes of groups if beyond alignment width
1893 int alWidth = alignment.getWidth();
1894 List<SequenceGroup> groups = alignment.getGroups();
1897 for (SequenceGroup sg : groups)
1899 if (sg.getEndRes() > alWidth)
1901 sg.setEndRes(alWidth - 1);
1906 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1908 selectionGroup.setEndRes(alWidth - 1);
1911 updateAllColourSchemes();
1912 calculator.restartWorkers();
1913 // alignment.adjustSequenceAnnotations();
1917 * reset scope and do calculations for all applied colourschemes on alignment
1919 void updateAllColourSchemes()
1921 ResidueShaderI rs = residueShading;
1924 rs.alignmentChanged(alignment, hiddenRepSequences);
1926 rs.setConsensus(hconsensus);
1927 if (rs.conservationApplied())
1929 rs.setConservation(Conservation.calculateConservation("All",
1930 alignment.getSequences(), 0, alignment.getWidth(), false,
1931 getConsPercGaps(), false));
1935 for (SequenceGroup sg : alignment.getGroups())
1939 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1941 sg.recalcConservation();
1945 protected void initAutoAnnotation()
1947 // TODO: add menu option action that nulls or creates consensus object
1948 // depending on if the user wants to see the annotation or not in a
1949 // specific alignment
1951 if (hconsensus == null && !isDataset)
1953 if (!alignment.isNucleotide())
1962 consensus = new AlignmentAnnotation(AutoAnnotation.CONSENSUS.label,
1963 MessageManager.getString("label.consensus_descr"),
1964 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1965 initConsensus(consensus);
1968 initComplementConsensus();
1973 * If this is a protein alignment and there are mappings to cDNA, adds the
1974 * cDNA consensus annotation and returns true, else returns false.
1976 public boolean initComplementConsensus()
1978 if (!alignment.isNucleotide())
1980 final List<AlignedCodonFrame> codonMappings = alignment
1982 if (codonMappings != null && !codonMappings.isEmpty())
1984 boolean doConsensus = false;
1985 for (AlignedCodonFrame mapping : codonMappings)
1987 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1988 MapList[] mapLists = mapping.getdnaToProt();
1989 // mapLists can be empty if project load has not finished resolving
1991 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1999 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2001 .getString("label.complement_consensus_descr"),
2002 new Annotation[1], 0f, 100f,
2003 AlignmentAnnotation.BAR_GRAPH);
2004 initConsensus(complementConsensus);
2012 private void initConsensus(AlignmentAnnotation aa)
2015 aa.autoCalculated = true;
2019 alignment.addAnnotation(aa);
2023 private void initGapCounts()
2027 gapcounts = new AlignmentAnnotation(AutoAnnotation.OCCUPANCY.label,
2028 MessageManager.getString("label.occupancy_descr"),
2029 new Annotation[1], 0f, alignment.getHeight(),
2030 AlignmentAnnotation.BAR_GRAPH);
2031 gapcounts.hasText = true;
2032 gapcounts.autoCalculated = true;
2033 gapcounts.scaleColLabel = true;
2034 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2036 alignment.addAnnotation(gapcounts);
2040 private void initConservation()
2042 if (showConservation)
2044 if (conservation == null)
2046 conservation = new AlignmentAnnotation(
2047 AutoAnnotation.CONSERVATION.label,
2048 MessageManager.formatMessage("label.conservation_descr",
2050 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2051 conservation.hasText = true;
2052 conservation.autoCalculated = true;
2053 alignment.addAnnotation(conservation);
2058 private void initQuality()
2062 if (quality == null)
2064 quality = new AlignmentAnnotation(AutoAnnotation.QUALITY.label,
2065 MessageManager.getString("label.quality_descr"),
2066 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2067 quality.hasText = true;
2068 quality.autoCalculated = true;
2069 alignment.addAnnotation(quality);
2074 private void initRNAStructure()
2076 if (alignment.hasRNAStructure() && strucConsensus == null)
2078 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2079 MessageManager.getString("label.strucconsensus_descr"),
2080 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2081 strucConsensus.hasText = true;
2082 strucConsensus.autoCalculated = true;
2086 alignment.addAnnotation(strucConsensus);
2094 * @see jalview.api.AlignViewportI#calcPanelHeight()
2097 public int calcPanelHeight()
2099 // setHeight of panels
2100 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2102 int charHeight = getCharHeight();
2105 BitSet graphgrp = new BitSet();
2106 for (AlignmentAnnotation aa : anns)
2110 System.err.println("Null annotation row: ignoring.");
2117 if (aa.graphGroup > -1)
2119 if (graphgrp.get(aa.graphGroup))
2125 graphgrp.set(aa.graphGroup);
2132 aa.height += charHeight;
2142 aa.height += aa.graphHeight;
2150 height += aa.height;
2162 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2163 boolean preserveNewGroupSettings)
2165 boolean updateCalcs = false;
2166 boolean conv = isShowGroupConservation();
2167 boolean cons = isShowGroupConsensus();
2168 boolean showprf = isShowSequenceLogo();
2169 boolean showConsHist = isShowConsensusHistogram();
2170 boolean normLogo = isNormaliseSequenceLogo();
2173 * TODO reorder the annotation rows according to group/sequence ordering on
2176 boolean sortg = true;
2178 // remove old automatic annotation
2179 // add any new annotation
2181 // intersect alignment annotation with alignment groups
2183 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2184 List<SequenceGroup> oldrfs = new ArrayList<>();
2187 for (int an = 0; an < aan.length; an++)
2189 if (aan[an].autoCalculated && aan[an].groupRef != null)
2191 oldrfs.add(aan[an].groupRef);
2192 alignment.deleteAnnotation(aan[an], false);
2196 if (alignment.getGroups() != null)
2198 for (SequenceGroup sg : alignment.getGroups())
2200 updateCalcs = false;
2201 if (applyGlobalSettings
2202 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2204 // set defaults for this group's conservation/consensus
2205 sg.setshowSequenceLogo(showprf);
2206 sg.setShowConsensusHistogram(showConsHist);
2207 sg.setNormaliseSequenceLogo(normLogo);
2212 alignment.addAnnotation(sg.getConservationRow(), 0);
2217 alignment.addAnnotation(sg.getConsensus(), 0);
2219 // refresh the annotation rows
2222 sg.recalcConservation();
2230 public boolean isDisplayReferenceSeq()
2232 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2236 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2238 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2242 public boolean isColourByReferenceSeq()
2244 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2248 public Color getSequenceColour(SequenceI seq)
2250 Color sqc = sequenceColours.get(seq);
2251 return (sqc == null ? Color.white : sqc);
2255 public void setSequenceColour(SequenceI seq, Color col)
2259 sequenceColours.remove(seq);
2263 sequenceColours.put(seq, col);
2268 public void updateSequenceIdColours()
2270 for (SequenceGroup sg : alignment.getGroups())
2272 if (sg.idColour != null)
2274 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2276 sequenceColours.put(s, sg.idColour);
2283 public void clearSequenceColours()
2285 sequenceColours.clear();
2289 public AlignViewportI getCodingComplement()
2291 return this.codingComplement;
2295 * Set this as the (cDna/protein) complement of the given viewport. Also
2296 * ensures the reverse relationship is set on the given viewport.
2299 public void setCodingComplement(AlignViewportI av)
2303 System.err.println("Ignoring recursive setCodingComplement request");
2307 this.codingComplement = av;
2308 // avoid infinite recursion!
2309 if (av.getCodingComplement() != this)
2311 av.setCodingComplement(this);
2317 public boolean isNucleotide()
2319 return getAlignment() == null ? false : getAlignment().isNucleotide();
2323 public FeaturesDisplayedI getFeaturesDisplayed()
2325 return featuresDisplayed;
2329 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2331 featuresDisplayed = featuresDisplayedI;
2335 public boolean areFeaturesDisplayed()
2337 return featuresDisplayed != null
2338 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2345 * features are displayed if true
2348 public void setShowSequenceFeatures(boolean b)
2350 viewStyle.setShowSequenceFeatures(b);
2354 public boolean isShowSequenceFeatures()
2356 return viewStyle.isShowSequenceFeatures();
2360 public void setShowSequenceFeaturesHeight(boolean selected)
2362 viewStyle.setShowSequenceFeaturesHeight(selected);
2366 public boolean isShowSequenceFeaturesHeight()
2368 return viewStyle.isShowSequenceFeaturesHeight();
2372 public void setShowAnnotation(boolean b)
2374 viewStyle.setShowAnnotation(b);
2378 public boolean isShowAnnotation()
2380 return viewStyle.isShowAnnotation();
2384 public boolean isRightAlignIds()
2386 return viewStyle.isRightAlignIds();
2390 public void setRightAlignIds(boolean rightAlignIds)
2392 viewStyle.setRightAlignIds(rightAlignIds);
2396 public boolean getConservationSelected()
2398 return viewStyle.getConservationSelected();
2402 public void setShowBoxes(boolean state)
2404 viewStyle.setShowBoxes(state);
2409 * @see jalview.api.ViewStyleI#getTextColour()
2412 public Color getTextColour()
2414 return viewStyle.getTextColour();
2419 * @see jalview.api.ViewStyleI#getTextColour2()
2422 public Color getTextColour2()
2424 return viewStyle.getTextColour2();
2429 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2432 public int getThresholdTextColour()
2434 return viewStyle.getThresholdTextColour();
2439 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2442 public boolean isConservationColourSelected()
2444 return viewStyle.isConservationColourSelected();
2449 * @see jalview.api.ViewStyleI#isRenderGaps()
2452 public boolean isRenderGaps()
2454 return viewStyle.isRenderGaps();
2459 * @see jalview.api.ViewStyleI#isShowColourText()
2462 public boolean isShowColourText()
2464 return viewStyle.isShowColourText();
2468 * @param conservationColourSelected
2469 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2472 public void setConservationColourSelected(
2473 boolean conservationColourSelected)
2475 viewStyle.setConservationColourSelected(conservationColourSelected);
2479 * @param showColourText
2480 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2483 public void setShowColourText(boolean showColourText)
2485 viewStyle.setShowColourText(showColourText);
2490 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2493 public void setTextColour(Color textColour)
2495 viewStyle.setTextColour(textColour);
2499 * @param thresholdTextColour
2500 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2503 public void setThresholdTextColour(int thresholdTextColour)
2505 viewStyle.setThresholdTextColour(thresholdTextColour);
2509 * @param textColour2
2510 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2513 public void setTextColour2(Color textColour2)
2515 viewStyle.setTextColour2(textColour2);
2519 public ViewStyleI getViewStyle()
2521 return new ViewStyle(viewStyle);
2525 public void setViewStyle(ViewStyleI settingsForView)
2527 viewStyle = new ViewStyle(settingsForView);
2528 if (residueShading != null)
2530 residueShading.setConservationApplied(
2531 settingsForView.isConservationColourSelected());
2536 public boolean sameStyle(ViewStyleI them)
2538 return viewStyle.sameStyle(them);
2543 * @see jalview.api.ViewStyleI#getIdWidth()
2546 public int getIdWidth()
2548 return viewStyle.getIdWidth();
2553 * @see jalview.api.ViewStyleI#setIdWidth(int)
2556 public void setIdWidth(int i)
2558 viewStyle.setIdWidth(i);
2563 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2566 public boolean isCentreColumnLabels()
2568 return viewStyle.isCentreColumnLabels();
2572 * @param centreColumnLabels
2573 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2576 public void setCentreColumnLabels(boolean centreColumnLabels)
2578 viewStyle.setCentreColumnLabels(centreColumnLabels);
2583 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2586 public void setShowDBRefs(boolean showdbrefs)
2588 viewStyle.setShowDBRefs(showdbrefs);
2593 * @see jalview.api.ViewStyleI#isShowDBRefs()
2596 public boolean isShowDBRefs()
2598 return viewStyle.isShowDBRefs();
2603 * @see jalview.api.ViewStyleI#isShowNPFeats()
2606 public boolean isShowNPFeats()
2608 return viewStyle.isShowNPFeats();
2612 * @param shownpfeats
2613 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2616 public void setShowNPFeats(boolean shownpfeats)
2618 viewStyle.setShowNPFeats(shownpfeats);
2621 public abstract StructureSelectionManager getStructureSelectionManager();
2624 * Add one command to the command history list.
2628 public void addToHistoryList(CommandI command)
2630 if (this.historyList != null)
2632 this.historyList.push(command);
2633 broadcastCommand(command, false);
2637 protected void broadcastCommand(CommandI command, boolean undo)
2639 getStructureSelectionManager().commandPerformed(command, undo,
2644 * Add one command to the command redo list.
2648 public void addToRedoList(CommandI command)
2650 if (this.redoList != null)
2652 this.redoList.push(command);
2654 broadcastCommand(command, true);
2658 * Clear the command redo list.
2660 public void clearRedoList()
2662 if (this.redoList != null)
2664 this.redoList.clear();
2668 public void setHistoryList(Deque<CommandI> list)
2670 this.historyList = list;
2673 public Deque<CommandI> getHistoryList()
2675 return this.historyList;
2678 public void setRedoList(Deque<CommandI> list)
2680 this.redoList = list;
2683 public Deque<CommandI> getRedoList()
2685 return this.redoList;
2689 public VamsasSource getVamsasSource()
2694 public SequenceAnnotationOrder getSortAnnotationsBy()
2696 return sortAnnotationsBy;
2700 public void setSortAnnotationsBy(
2701 SequenceAnnotationOrder sortAnnotationsBy)
2703 this.sortAnnotationsBy = sortAnnotationsBy;
2707 public boolean isShowAutocalculatedAbove()
2709 return showAutocalculatedAbove;
2713 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2715 this.showAutocalculatedAbove = showAutocalculatedAbove;
2719 public boolean isScaleProteinAsCdna()
2721 return viewStyle.isScaleProteinAsCdna();
2725 public void setScaleProteinAsCdna(boolean b)
2727 viewStyle.setScaleProteinAsCdna(b);
2731 public boolean isProteinFontAsCdna()
2733 return viewStyle.isProteinFontAsCdna();
2737 public void setProteinFontAsCdna(boolean b)
2739 viewStyle.setProteinFontAsCdna(b);
2743 * @return true if view should scroll to show the highlighted region of a
2748 public final boolean isFollowHighlight()
2750 return followHighlight;
2754 public final void setFollowHighlight(boolean b)
2756 this.followHighlight = b;
2760 public ViewportRanges getRanges()
2766 * Helper method to populate the SearchResults with the location in the
2767 * complementary alignment to scroll to, in order to match this one.
2770 * the SearchResults to add to
2771 * @return the offset (below top of visible region) of the matched sequence
2773 protected int findComplementScrollTarget(SearchResultsI sr)
2775 final AlignViewportI complement = getCodingComplement();
2776 if (complement == null || !complement.isFollowHighlight())
2780 boolean iAmProtein = !getAlignment().isNucleotide();
2781 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2782 : complement.getAlignment();
2783 if (proteinAlignment == null)
2787 final List<AlignedCodonFrame> mappings = proteinAlignment
2791 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2792 * residue in the middle column of the visible region. Scroll the
2793 * complementary alignment to line up the corresponding residue.
2796 SequenceI sequence = null;
2799 * locate 'middle' column (true middle if an odd number visible, left of
2800 * middle if an even number visible)
2802 int middleColumn = ranges.getStartRes()
2803 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2804 final HiddenSequences hiddenSequences = getAlignment()
2805 .getHiddenSequences();
2808 * searching to the bottom of the alignment gives smoother scrolling across
2809 * all gapped visible regions
2811 int lastSeq = alignment.getHeight() - 1;
2812 List<AlignedCodonFrame> seqMappings = null;
2813 for (int seqNo = ranges
2814 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2816 sequence = getAlignment().getSequenceAt(seqNo);
2817 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2821 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2825 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2827 getCodingComplement().getAlignment().getSequences());
2828 if (!seqMappings.isEmpty())
2834 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2837 * No ungapped mapped sequence in middle column - do nothing
2841 MappingUtils.addSearchResults(sr, sequence,
2842 sequence.findPosition(middleColumn), seqMappings);
2847 * synthesize a column selection if none exists so it covers the given
2848 * selection group. if wholewidth is false, no column selection is made if the
2849 * selection group covers the whole alignment width.
2854 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2857 if (sg != null && (sgs = sg.getStartRes()) >= 0
2858 && sg.getStartRes() <= (sge = sg.getEndRes())
2859 && !this.hasSelectedColumns())
2861 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2868 colSel = new ColumnSelection();
2870 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2872 colSel.addElement(cspos);
2878 * hold status of current selection group - defined on alignment or not.
2880 private boolean selectionIsDefinedGroup = false;
2883 public boolean isSelectionDefinedGroup()
2885 if (selectionGroup == null)
2889 if (isSelectionGroupChanged(true))
2891 selectionIsDefinedGroup = false;
2892 List<SequenceGroup> gps = alignment.getGroups();
2893 if (gps == null || gps.size() == 0)
2895 selectionIsDefinedGroup = false;
2899 selectionIsDefinedGroup = gps.contains(selectionGroup);
2902 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2906 * null, or currently highlighted results on this view
2908 private SearchResultsI searchResults = null;
2910 protected TreeModel currentTree = null;
2913 public boolean hasSearchResults()
2915 return searchResults != null;
2919 public void setSearchResults(SearchResultsI results)
2921 searchResults = results;
2925 public SearchResultsI getSearchResults()
2927 return searchResults;
2931 * get the consensus sequence as displayed under the PID consensus annotation
2934 * @return consensus sequence as a new sequence object
2936 public SequenceI getConsensusSeq()
2938 if (consensus == null)
2940 updateConsensus(null);
2942 if (consensus == null)
2946 StringBuffer seqs = new StringBuffer();
2947 for (int i = 0; i < consensus.annotations.length; i++)
2949 Annotation annotation = consensus.annotations[i];
2950 if (annotation != null)
2952 String description = annotation.description;
2953 if (description != null && description.startsWith("["))
2955 // consensus is a tie - just pick the first one
2956 seqs.append(description.charAt(1));
2960 seqs.append(annotation.displayCharacter);
2965 SequenceI sq = new Sequence("Consensus", seqs.toString());
2966 sq.setDescription("Percentage Identity Consensus "
2967 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
2972 public void setCurrentTree(TreeModel tree)
2978 public TreeModel getCurrentTree()
2984 * flag set to indicate if structure views might be out of sync with sequences
2988 private boolean needToUpdateStructureViews = false;
2991 public boolean isUpdateStructures()
2993 return needToUpdateStructureViews;
2997 public void setUpdateStructures(boolean update)
2999 needToUpdateStructureViews = update;
3003 public boolean needToUpdateStructureViews()
3005 boolean update = needToUpdateStructureViews;
3006 needToUpdateStructureViews = false;
3011 public void addSequenceGroup(SequenceGroup sequenceGroup)
3013 alignment.addGroup(sequenceGroup);
3015 Color col = sequenceGroup.idColour;
3018 col = col.brighter();
3020 for (SequenceI sq : sequenceGroup.getSequences())
3022 setSequenceColour(sq, col);
3026 if (codingComplement != null)
3028 SequenceGroup mappedGroup = MappingUtils
3029 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3030 if (mappedGroup.getSequences().size() > 0)
3032 codingComplement.getAlignment().addGroup(mappedGroup);
3036 for (SequenceI seq : mappedGroup.getSequences())
3038 codingComplement.setSequenceColour(seq, col);
3042 // propagate the structure view update flag according to our own setting
3043 codingComplement.setUpdateStructures(needToUpdateStructureViews);