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.ProfileI;
41 import jalview.datamodel.Profiles;
42 import jalview.datamodel.ProfilesI;
43 import jalview.datamodel.SearchResultsI;
44 import jalview.datamodel.Sequence;
45 import jalview.datamodel.SequenceCollectionI;
46 import jalview.datamodel.SequenceGroup;
47 import jalview.datamodel.SequenceI;
48 import jalview.renderer.ResidueShader;
49 import jalview.renderer.ResidueShaderI;
50 import jalview.schemes.ColourSchemeI;
51 import jalview.structure.CommandListener;
52 import jalview.structure.StructureSelectionManager;
53 import jalview.structure.VamsasSource;
54 import jalview.util.Comparison;
55 import jalview.util.MapList;
56 import jalview.util.MappingUtils;
57 import jalview.util.MessageManager;
58 import jalview.viewmodel.styles.ViewStyle;
59 import jalview.workers.AlignCalcManager;
60 import jalview.workers.ComplementConsensusThread;
61 import jalview.workers.ConsensusThread;
62 import jalview.workers.InformationThread;
63 import jalview.workers.StrucConsensusThread;
65 import java.awt.Color;
66 import java.beans.PropertyChangeSupport;
67 import java.util.ArrayDeque;
68 import java.util.ArrayList;
69 import java.util.BitSet;
70 import java.util.Deque;
71 import java.util.HashMap;
72 import java.util.Hashtable;
73 import java.util.List;
77 * base class holding visualization and analysis attributes and common logic for
78 * an active alignment view displayed in the GUI
83 public abstract class AlignmentViewport
84 implements AlignViewportI, CommandListener, VamsasSource
86 protected ViewportRanges ranges;
88 protected ViewStyleI viewStyle = new ViewStyle();
91 * A viewport that hosts the cDna view of this (protein), or vice versa (if
94 AlignViewportI codingComplement = null;
96 FeaturesDisplayedI featuresDisplayed = null;
98 protected Deque<CommandI> historyList = new ArrayDeque<>();
100 protected Deque<CommandI> redoList = new ArrayDeque<>();
104 * alignment displayed in the viewport. Please use get/setter
106 protected AlignmentI alignment;
108 public AlignmentViewport(AlignmentI al)
111 ranges = new ViewportRanges(al);
116 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
119 public void setFontName(String name)
121 viewStyle.setFontName(name);
126 * @see jalview.api.ViewStyleI#setFontStyle(int)
129 public void setFontStyle(int style)
131 viewStyle.setFontStyle(style);
136 * @see jalview.api.ViewStyleI#setFontSize(int)
139 public void setFontSize(int size)
141 viewStyle.setFontSize(size);
146 * @see jalview.api.ViewStyleI#getFontStyle()
149 public int getFontStyle()
151 return viewStyle.getFontStyle();
156 * @see jalview.api.ViewStyleI#getFontName()
159 public String getFontName()
161 return viewStyle.getFontName();
166 * @see jalview.api.ViewStyleI#getFontSize()
169 public int getFontSize()
171 return viewStyle.getFontSize();
175 * @param upperCasebold
176 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
179 public void setUpperCasebold(boolean upperCasebold)
181 viewStyle.setUpperCasebold(upperCasebold);
186 * @see jalview.api.ViewStyleI#isUpperCasebold()
189 public boolean isUpperCasebold()
191 return viewStyle.isUpperCasebold();
196 * @see jalview.api.ViewStyleI#isSeqNameItalics()
199 public boolean isSeqNameItalics()
201 return viewStyle.isSeqNameItalics();
205 * @param colourByReferenceSeq
206 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
209 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
211 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
216 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
219 public void setColourAppliesToAllGroups(boolean b)
221 viewStyle.setColourAppliesToAllGroups(b);
226 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
229 public boolean getColourAppliesToAllGroups()
231 return viewStyle.getColourAppliesToAllGroups();
236 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
239 public boolean getAbovePIDThreshold()
241 return viewStyle.getAbovePIDThreshold();
246 * @see jalview.api.ViewStyleI#setIncrement(int)
249 public void setIncrement(int inc)
251 viewStyle.setIncrement(inc);
256 * @see jalview.api.ViewStyleI#getIncrement()
259 public int getIncrement()
261 return viewStyle.getIncrement();
266 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
269 public void setConservationSelected(boolean b)
271 viewStyle.setConservationSelected(b);
276 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
279 public void setShowHiddenMarkers(boolean show)
281 viewStyle.setShowHiddenMarkers(show);
286 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
289 public boolean getShowHiddenMarkers()
291 return viewStyle.getShowHiddenMarkers();
296 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
299 public void setScaleRightWrapped(boolean b)
301 viewStyle.setScaleRightWrapped(b);
306 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
309 public void setScaleLeftWrapped(boolean b)
311 viewStyle.setScaleLeftWrapped(b);
316 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
319 public void setScaleAboveWrapped(boolean b)
321 viewStyle.setScaleAboveWrapped(b);
326 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
329 public boolean getScaleLeftWrapped()
331 return viewStyle.getScaleLeftWrapped();
336 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
339 public boolean getScaleAboveWrapped()
341 return viewStyle.getScaleAboveWrapped();
346 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
349 public boolean getScaleRightWrapped()
351 return viewStyle.getScaleRightWrapped();
356 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
359 public void setAbovePIDThreshold(boolean b)
361 viewStyle.setAbovePIDThreshold(b);
366 * @see jalview.api.ViewStyleI#setThreshold(int)
369 public void setThreshold(int thresh)
371 viewStyle.setThreshold(thresh);
376 * @see jalview.api.ViewStyleI#getThreshold()
379 public int getThreshold()
381 return viewStyle.getThreshold();
386 * @see jalview.api.ViewStyleI#getShowJVSuffix()
389 public boolean getShowJVSuffix()
391 return viewStyle.getShowJVSuffix();
396 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
399 public void setShowJVSuffix(boolean b)
401 viewStyle.setShowJVSuffix(b);
406 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
409 public void setWrapAlignment(boolean state)
411 viewStyle.setWrapAlignment(state);
412 ranges.setWrappedMode(state);
417 * @see jalview.api.ViewStyleI#setShowText(boolean)
420 public void setShowText(boolean state)
422 viewStyle.setShowText(state);
427 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
430 public void setRenderGaps(boolean state)
432 viewStyle.setRenderGaps(state);
437 * @see jalview.api.ViewStyleI#getColourText()
440 public boolean getColourText()
442 return viewStyle.getColourText();
447 * @see jalview.api.ViewStyleI#setColourText(boolean)
450 public void setColourText(boolean state)
452 viewStyle.setColourText(state);
457 * @see jalview.api.ViewStyleI#getWrapAlignment()
460 public boolean getWrapAlignment()
462 return viewStyle.getWrapAlignment();
467 * @see jalview.api.ViewStyleI#getShowText()
470 public boolean getShowText()
472 return viewStyle.getShowText();
477 * @see jalview.api.ViewStyleI#getWrappedWidth()
480 public int getWrappedWidth()
482 return viewStyle.getWrappedWidth();
487 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
490 public void setWrappedWidth(int w)
492 viewStyle.setWrappedWidth(w);
497 * @see jalview.api.ViewStyleI#getCharHeight()
500 public int getCharHeight()
502 return viewStyle.getCharHeight();
507 * @see jalview.api.ViewStyleI#setCharHeight(int)
510 public void setCharHeight(int h)
512 viewStyle.setCharHeight(h);
517 * @see jalview.api.ViewStyleI#getCharWidth()
520 public int getCharWidth()
522 return viewStyle.getCharWidth();
527 * @see jalview.api.ViewStyleI#setCharWidth(int)
530 public void setCharWidth(int w)
532 viewStyle.setCharWidth(w);
537 * @see jalview.api.ViewStyleI#getShowBoxes()
540 public boolean getShowBoxes()
542 return viewStyle.getShowBoxes();
547 * @see jalview.api.ViewStyleI#getShowUnconserved()
550 public boolean getShowUnconserved()
552 return viewStyle.getShowUnconserved();
556 * @param showunconserved
557 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
560 public void setShowUnconserved(boolean showunconserved)
562 viewStyle.setShowUnconserved(showunconserved);
567 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
570 public void setSeqNameItalics(boolean default1)
572 viewStyle.setSeqNameItalics(default1);
576 public AlignmentI getAlignment()
582 public char getGapCharacter()
584 return alignment.getGapCharacter();
587 protected String sequenceSetID;
590 * probably unused indicator that view is of a dataset rather than an
593 protected boolean isDataset = false;
595 public void setDataset(boolean b)
600 public boolean isDataset()
605 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
607 protected ColumnSelection colSel = new ColumnSelection();
609 public boolean autoCalculateConsensus = true;
611 public boolean autoCalculateInformation = true;
613 protected boolean autoCalculateStrucConsensus = true;
615 protected boolean ignoreGapsInConsensusCalculation = false;
617 protected boolean ignoreBelowBackGroundFrequencyCalculation = false;
619 protected boolean infoLetterHeight = false;
621 protected ResidueShaderI residueShading = new ResidueShader();
624 public void setGlobalColourScheme(ColourSchemeI cs)
626 // TODO: logic refactored from AlignFrame changeColour -
627 // TODO: autorecalc stuff should be changed to rely on the worker system
628 // check to see if we should implement a changeColour(cs) method rather than
629 // put the logic in here
630 // - means that caller decides if they want to just modify state and defer
631 // calculation till later or to do all calculations in thread.
635 * only instantiate alignment colouring once, thereafter update it;
636 * this means that any conservation or PID threshold settings
637 * persist when the alignment colour scheme is changed
639 if (residueShading == null)
641 residueShading = new ResidueShader(viewStyle);
643 residueShading.setColourScheme(cs);
645 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
646 // ...problem: groups need these, but do not currently have a ViewStyle
650 if (getConservationSelected())
652 residueShading.setConservation(hconservation);
655 * reset conservation flag in case just set to false if
656 * Conservation was null (calculation still in progress)
658 residueShading.setConservationApplied(getConservationSelected());
659 residueShading.alignmentChanged(alignment, hiddenRepSequences);
663 * if 'apply colour to all groups' is selected... do so
664 * (but don't transfer any colour threshold settings to groups)
666 if (getColourAppliesToAllGroups())
668 for (SequenceGroup sg : getAlignment().getGroups())
671 * retain any colour thresholds per group while
672 * changing choice of colour scheme (JAL-2386)
674 sg.setColourScheme(cs);
677 sg.getGroupColourScheme().alignmentChanged(sg,
685 public ColourSchemeI getGlobalColourScheme()
687 return residueShading == null ? null : residueShading.getColourScheme();
691 public ResidueShaderI getResidueShading()
693 return residueShading;
696 protected AlignmentAnnotation consensus;
698 protected AlignmentAnnotation complementConsensus;
700 protected AlignmentAnnotation gapcounts;
702 protected AlignmentAnnotation strucConsensus;
704 protected AlignmentAnnotation conservation;
706 protected AlignmentAnnotation quality;
708 protected AlignmentAnnotation[] groupConsensus;
710 protected AlignmentAnnotation[] groupConservation;
712 protected List<AlignmentAnnotation> groupInformation = new ArrayList<>();
714 protected List<AlignmentAnnotation> information = new ArrayList<>();
717 * results of alignment consensus analysis for visible portion of view
719 protected ProfilesI hconsensus = null;
722 * results of information annotation analysis for the visible portion of view
724 protected List<ProfilesI> hinformation = new ArrayList<>();
727 * results of cDNA complement consensus visible portion of view
729 protected Hashtable[] hcomplementConsensus = null;
732 * results of secondary structure base pair consensus for visible portion of
735 protected Hashtable[] hStrucConsensus = null;
737 protected Conservation hconservation = null;
740 public void setConservation(Conservation cons)
742 hconservation = cons;
746 * percentage gaps allowed in a column before all amino acid properties should
747 * be considered unconserved
749 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
752 public int getConsPercGaps()
758 public void setSequenceConsensusHash(ProfilesI hconsensus)
760 this.hconsensus = hconsensus;
764 public void setComplementConsensusHash(Hashtable[] hconsensus)
766 this.hcomplementConsensus = hconsensus;
770 public ProfilesI getSequenceConsensusHash()
776 public void setSequenceInformationHashes(List<ProfilesI> info)
782 public void setSequenceInformationHash(ProfilesI info, int index)
784 if (hinformation.size() < index + 1)
788 hinformation.set(index, info);
792 public List<ProfilesI> getSequenceInformationHashes()
798 public ProfilesI getSequenceInformationHash(int index)
800 return hinformation.get(index);
804 public Hashtable[] getComplementConsensusHash()
806 return hcomplementConsensus;
810 public Hashtable[] getRnaStructureConsensusHash()
812 return hStrucConsensus;
816 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
818 this.hStrucConsensus = hStrucConsensus;
823 public AlignmentAnnotation getAlignmentQualityAnnot()
829 public AlignmentAnnotation getAlignmentConservationAnnotation()
835 public AlignmentAnnotation getAlignmentConsensusAnnotation()
841 public List<AlignmentAnnotation> getInformationAnnotations()
847 public AlignmentAnnotation getInformationAnnotation(int index)
849 return information.get(index);
853 public AlignmentAnnotation getAlignmentGapAnnotation()
859 public AlignmentAnnotation getComplementConsensusAnnotation()
861 return complementConsensus;
865 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
867 return strucConsensus;
870 protected AlignCalcManagerI calculator = new AlignCalcManager();
873 * trigger update of conservation annotation
875 public void updateConservation(final AlignmentViewPanel ap)
877 // see note in mantis : issue number 8585
878 if (alignment.isNucleotide()
879 || (conservation == null && quality == null)
880 || !autoCalculateConsensus)
884 if (calculator.getRegisteredWorkersOfClass(
885 jalview.workers.ConservationThread.class) == null)
887 calculator.registerWorker(
888 new jalview.workers.ConservationThread(this, ap));
893 * trigger update of consensus annotation
895 public void updateConsensus(final AlignmentViewPanel ap)
897 // see note in mantis : issue number 8585
898 if (consensus == null || !autoCalculateConsensus)
903 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
905 calculator.registerWorker(new ConsensusThread(this, ap));
909 * A separate thread to compute cDNA consensus for a protein alignment
910 * which has mapping to cDNA
912 final AlignmentI al = this.getAlignment();
913 if (!al.isNucleotide() && al.getCodonFrames() != null
914 && !al.getCodonFrames().isEmpty())
917 * fudge - check first for protein-to-nucleotide mappings
918 * (we don't want to do this for protein-to-protein)
920 boolean doConsensus = false;
921 for (AlignedCodonFrame mapping : al.getCodonFrames())
923 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
924 MapList[] mapLists = mapping.getdnaToProt();
925 // mapLists can be empty if project load has not finished resolving seqs
926 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
934 if (calculator.getRegisteredWorkersOfClass(
935 ComplementConsensusThread.class) == null)
938 .registerWorker(new ComplementConsensusThread(this, ap));
945 * trigger update of information annotation
948 public void updateInformation(final AlignmentViewPanel ap)
951 .getRegisteredWorkersOfClass(InformationThread.class) == null)
953 calculator.registerWorker(new InformationThread(this, ap));
958 // --------START Structure Conservation
959 public void updateStrucConsensus(final AlignmentViewPanel ap)
961 if (autoCalculateStrucConsensus && strucConsensus == null
962 && alignment.isNucleotide() && alignment.hasRNAStructure())
964 // secondary structure has been added - so init the consensus line
968 // see note in mantis : issue number 8585
969 if (strucConsensus == null || !autoCalculateStrucConsensus)
973 if (calculator.getRegisteredWorkersOfClass(
974 StrucConsensusThread.class) == null)
976 calculator.registerWorker(new StrucConsensusThread(this, ap));
980 public boolean isCalcInProgress()
982 return calculator.isWorking();
986 public boolean isCalculationInProgress(
987 AlignmentAnnotation alignmentAnnotation)
989 if (!alignmentAnnotation.autoCalculated)
993 if (calculator.workingInvolvedWith(alignmentAnnotation))
995 // System.err.println("grey out ("+alignmentAnnotation.label+")");
1001 public void setAlignment(AlignmentI align)
1003 this.alignment = align;
1007 * Clean up references when this viewport is closed
1010 public void dispose()
1013 * defensively null out references to large objects in case
1014 * this object is not garbage collected (as if!)
1017 complementConsensus = null;
1018 strucConsensus = null;
1019 conservation = null;
1021 groupConsensus = null;
1022 groupConservation = null;
1024 hconservation = null;
1025 hcomplementConsensus = null;
1028 residueShading = null; // may hold a reference to Consensus
1029 changeSupport = null;
1032 selectionGroup = null;
1037 public boolean isClosed()
1039 // TODO: check that this isClosed is only true after panel is closed, not
1040 // before it is fully constructed.
1041 return alignment == null;
1045 public AlignCalcManagerI getCalcManager()
1051 * should conservation rows be shown for groups
1053 protected boolean showGroupConservation = false;
1056 * should consensus rows be shown for groups
1058 protected boolean showGroupConsensus = false;
1061 * should consensus profile be rendered by default
1063 protected boolean showSequenceLogo = false;
1066 * should consensus profile be rendered normalised to row height
1068 protected boolean normaliseSequenceLogo = false;
1071 * should consensus histograms be rendered by default
1073 protected boolean showConsensusHistogram = true;
1076 * should hmm profile be rendered by default
1078 protected boolean showHMMSequenceLogo = false;
1081 * should hmm profile be rendered normalised to row height
1083 protected boolean normaliseHMMSequenceLogo = false;
1086 * should information histograms be rendered by default
1088 protected boolean showInformationHistogram = true;
1091 * @return the showConsensusProfile
1094 public boolean isShowSequenceLogo()
1096 return showSequenceLogo;
1100 * @return the showInformationProfile
1103 public boolean isShowHMMSequenceLogo()
1105 return showHMMSequenceLogo;
1109 * @param showSequenceLogo
1112 public void setShowSequenceLogo(boolean showSequenceLogo)
1114 if (showSequenceLogo != this.showSequenceLogo)
1116 // TODO: decouple settings setting from calculation when refactoring
1117 // annotation update method from alignframe to viewport
1118 this.showSequenceLogo = showSequenceLogo;
1119 calculator.updateAnnotationFor(ConsensusThread.class);
1120 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1121 calculator.updateAnnotationFor(StrucConsensusThread.class);
1123 this.showSequenceLogo = showSequenceLogo;
1126 public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo)
1128 if (showHMMSequenceLogo != this.showHMMSequenceLogo)
1130 this.showHMMSequenceLogo = showHMMSequenceLogo;
1131 calculator.updateAnnotationFor(InformationThread.class);
1133 this.showHMMSequenceLogo = showHMMSequenceLogo;
1137 * @param showConsensusHistogram
1138 * the showConsensusHistogram to set
1140 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1142 this.showConsensusHistogram = showConsensusHistogram;
1146 * @param showInformationHistogram
1147 * the showInformationHistogram to set
1149 public void setShowInformationHistogram(boolean showInformationHistogram)
1151 this.showInformationHistogram = showInformationHistogram;
1155 * @return the showGroupConservation
1157 public boolean isShowGroupConservation()
1159 return showGroupConservation;
1163 * @param showGroupConservation
1164 * the showGroupConservation to set
1166 public void setShowGroupConservation(boolean showGroupConservation)
1168 this.showGroupConservation = showGroupConservation;
1172 * @return the showGroupConsensus
1174 public boolean isShowGroupConsensus()
1176 return showGroupConsensus;
1180 * @param showGroupConsensus
1181 * the showGroupConsensus to set
1183 public void setShowGroupConsensus(boolean showGroupConsensus)
1185 this.showGroupConsensus = showGroupConsensus;
1190 * @return flag to indicate if the consensus histogram should be rendered by
1194 public boolean isShowConsensusHistogram()
1196 return this.showConsensusHistogram;
1201 * @return flag to indicate if the information content histogram should be
1202 * rendered by default
1205 public boolean isShowInformationHistogram()
1207 return this.showInformationHistogram;
1211 * when set, updateAlignment will always ensure sequences are of equal length
1213 private boolean padGaps = false;
1216 * when set, alignment should be reordered according to a newly opened tree
1218 public boolean sortByTree = false;
1223 * @return null or the currently selected sequence region
1226 public SequenceGroup getSelectionGroup()
1228 return selectionGroup;
1232 * Set the selection group for this window. Also sets the current alignment as
1233 * the context for the group, if it does not already have one.
1236 * - group holding references to sequences in this alignment view
1240 public void setSelectionGroup(SequenceGroup sg)
1242 selectionGroup = sg;
1243 if (sg != null && sg.getContext() == null)
1245 sg.setContext(alignment);
1249 public void setHiddenColumns(HiddenColumns hidden)
1251 this.alignment.setHiddenColumns(hidden);
1255 public ColumnSelection getColumnSelection()
1261 public void setColumnSelection(ColumnSelection colSel)
1263 this.colSel = colSel;
1266 updateHiddenColumns();
1268 isColSelChanged(true);
1276 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1278 return hiddenRepSequences;
1282 public void setHiddenRepSequences(
1283 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1285 this.hiddenRepSequences = hiddenRepSequences;
1289 public boolean hasSelectedColumns()
1291 ColumnSelection columnSelection = getColumnSelection();
1292 return columnSelection != null && columnSelection.hasSelectedColumns();
1296 public boolean hasHiddenColumns()
1298 return alignment.getHiddenColumns() != null
1299 && alignment.getHiddenColumns().hasHiddenColumns();
1302 public void updateHiddenColumns()
1304 // this method doesn't really do anything now. But - it could, since a
1305 // column Selection could be in the process of modification
1306 // hasHiddenColumns = colSel.hasHiddenColumns();
1310 public boolean hasHiddenRows()
1312 return alignment.getHiddenSequences().getSize() > 0;
1315 protected SequenceGroup selectionGroup;
1317 public void setSequenceSetId(String newid)
1319 if (sequenceSetID != null)
1322 "Warning - overwriting a sequenceSetId for a viewport!");
1324 sequenceSetID = new String(newid);
1328 public String getSequenceSetId()
1330 if (sequenceSetID == null)
1332 sequenceSetID = alignment.hashCode() + "";
1335 return sequenceSetID;
1339 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1342 protected String viewId = null;
1345 public String getViewId()
1349 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1354 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1356 ignoreGapsInConsensusCalculation = b;
1359 updateConsensus(ap);
1360 if (residueShading != null)
1362 residueShading.setThreshold(residueShading.getThreshold(),
1363 ignoreGapsInConsensusCalculation);
1369 public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap)
1371 ignoreBelowBackGroundFrequencyCalculation = b;
1374 updateInformation(ap);
1379 public void setInfoLetterHeight(boolean b, AlignmentViewPanel ap)
1381 infoLetterHeight = b;
1384 updateInformation(ap);
1389 private long sgrouphash = -1, colselhash = -1;
1392 * checks current SelectionGroup against record of last hash value, and
1396 * update the record of last hash value
1398 * @return true if SelectionGroup changed since last call (when b is true)
1400 public boolean isSelectionGroupChanged(boolean b)
1402 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1403 : selectionGroup.hashCode();
1404 if (hc != -1 && hc != sgrouphash)
1416 * checks current colsel against record of last hash value, and optionally
1420 * update the record of last hash value
1421 * @return true if colsel changed since last call (when b is true)
1423 public boolean isColSelChanged(boolean b)
1425 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1426 if (hc != -1 && hc != colselhash)
1438 public boolean isIgnoreGapsConsensus()
1440 return ignoreGapsInConsensusCalculation;
1444 public boolean isIgnoreBelowBackground()
1446 return ignoreBelowBackGroundFrequencyCalculation;
1450 public boolean isInfoLetterHeight()
1452 return infoLetterHeight;
1455 // property change stuff
1456 // JBPNote Prolly only need this in the applet version.
1457 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1460 protected boolean showConservation = true;
1462 protected boolean showQuality = true;
1464 protected boolean showConsensus = true;
1466 protected boolean showOccupancy = true;
1468 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1470 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1472 protected boolean showAutocalculatedAbove;
1475 * when set, view will scroll to show the highlighted position
1477 private boolean followHighlight = true;
1480 * Property change listener for changes in alignment
1485 public void addPropertyChangeListener(
1486 java.beans.PropertyChangeListener listener)
1488 changeSupport.addPropertyChangeListener(listener);
1497 public void removePropertyChangeListener(
1498 java.beans.PropertyChangeListener listener)
1500 if (changeSupport != null)
1502 changeSupport.removePropertyChangeListener(listener);
1507 * Property change listener for changes in alignment
1516 public void firePropertyChange(String prop, Object oldvalue,
1519 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1522 // common hide/show column stuff
1524 public void hideSelectedColumns()
1526 if (colSel.isEmpty())
1531 colSel.hideSelectedColumns(alignment);
1532 setSelectionGroup(null);
1533 isColSelChanged(true);
1536 public void hideColumns(int start, int end)
1540 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1544 alignment.getHiddenColumns().hideColumns(start, end);
1546 isColSelChanged(true);
1549 public void showColumn(int col)
1551 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1552 isColSelChanged(true);
1555 public void showAllHiddenColumns()
1557 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1558 isColSelChanged(true);
1561 // common hide/show seq stuff
1562 public void showAllHiddenSeqs()
1564 int startSeq = ranges.getStartSeq();
1565 int endSeq = ranges.getEndSeq();
1567 if (alignment.getHiddenSequences().getSize() > 0)
1569 if (selectionGroup == null)
1571 selectionGroup = new SequenceGroup();
1572 selectionGroup.setEndRes(alignment.getWidth() - 1);
1574 List<SequenceI> tmp = alignment.getHiddenSequences()
1575 .showAll(hiddenRepSequences);
1576 for (SequenceI seq : tmp)
1578 selectionGroup.addSequence(seq, false);
1579 setSequenceAnnotationsVisible(seq, true);
1582 hiddenRepSequences = null;
1584 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1586 firePropertyChange("alignment", null, alignment.getSequences());
1587 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1593 public void showSequence(int index)
1595 int startSeq = ranges.getStartSeq();
1596 int endSeq = ranges.getEndSeq();
1598 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1599 hiddenRepSequences);
1602 if (selectionGroup == null)
1604 selectionGroup = new SequenceGroup();
1605 selectionGroup.setEndRes(alignment.getWidth() - 1);
1608 for (SequenceI seq : tmp)
1610 selectionGroup.addSequence(seq, false);
1611 setSequenceAnnotationsVisible(seq, true);
1614 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1616 firePropertyChange("alignment", null, alignment.getSequences());
1621 public void hideAllSelectedSeqs()
1623 if (selectionGroup == null || selectionGroup.getSize() < 1)
1628 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1632 setSelectionGroup(null);
1635 public void hideSequence(SequenceI[] seq)
1638 * cache offset to first visible sequence
1640 int startSeq = ranges.getStartSeq();
1644 for (int i = 0; i < seq.length; i++)
1646 alignment.getHiddenSequences().hideSequence(seq[i]);
1647 setSequenceAnnotationsVisible(seq[i], false);
1649 ranges.setStartSeq(startSeq);
1650 firePropertyChange("alignment", null, alignment.getSequences());
1655 * Hides the specified sequence, or the sequences it represents
1658 * the sequence to hide, or keep as representative
1659 * @param representGroup
1660 * if true, hide the current selection group except for the
1661 * representative sequence
1663 public void hideSequences(SequenceI sequence, boolean representGroup)
1665 if (selectionGroup == null || selectionGroup.getSize() < 1)
1667 hideSequence(new SequenceI[] { sequence });
1673 hideRepSequences(sequence, selectionGroup);
1674 setSelectionGroup(null);
1678 int gsize = selectionGroup.getSize();
1679 SequenceI[] hseqs = selectionGroup.getSequences()
1680 .toArray(new SequenceI[gsize]);
1682 hideSequence(hseqs);
1683 setSelectionGroup(null);
1688 * Set visibility for any annotations for the given sequence.
1692 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1695 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1698 for (AlignmentAnnotation ann : anns)
1700 if (ann.sequenceRef == sequenceI)
1702 ann.visible = visible;
1708 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1710 int sSize = sg.getSize();
1716 if (hiddenRepSequences == null)
1718 hiddenRepSequences = new Hashtable<>();
1721 hiddenRepSequences.put(repSequence, sg);
1723 // Hide all sequences except the repSequence
1724 SequenceI[] seqs = new SequenceI[sSize - 1];
1726 for (int i = 0; i < sSize; i++)
1728 if (sg.getSequenceAt(i) != repSequence)
1730 if (index == sSize - 1)
1735 seqs[index++] = sg.getSequenceAt(i);
1738 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1739 sg.setHidereps(true); // note: not done in 2.7applet
1746 * @return null or the current reference sequence
1748 public SequenceI getReferenceSeq()
1750 return alignment.getSeqrep();
1755 * @return true iff seq is the reference for the alignment
1757 public boolean isReferenceSeq(SequenceI seq)
1759 return alignment.getSeqrep() == seq;
1765 * @return true if there are sequences represented by this sequence that are
1768 public boolean isHiddenRepSequence(SequenceI seq)
1770 return (hiddenRepSequences != null
1771 && hiddenRepSequences.containsKey(seq));
1777 * @return null or a sequence group containing the sequences that seq
1780 public SequenceGroup getRepresentedSequences(SequenceI seq)
1782 return (SequenceGroup) (hiddenRepSequences == null ? null
1783 : hiddenRepSequences.get(seq));
1787 public int adjustForHiddenSeqs(int alignmentIndex)
1789 return alignment.getHiddenSequences()
1790 .adjustForHiddenSeqs(alignmentIndex);
1794 public void invertColumnSelection()
1796 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1800 public SequenceI[] getSelectionAsNewSequence()
1802 SequenceI[] sequences;
1803 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1804 // this was the only caller in the applet for this method
1805 // JBPNote: in applet, this method returned references to the alignment
1806 // sequences, and it did not honour the presence/absence of annotation
1807 // attached to the alignment (probably!)
1808 if (selectionGroup == null || selectionGroup.getSize() == 0)
1810 sequences = alignment.getSequencesArray();
1811 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1812 for (int i = 0; i < sequences.length; i++)
1814 // construct new sequence with subset of visible annotation
1815 sequences[i] = new Sequence(sequences[i], annots);
1820 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1827 public SequenceI[] getSequenceSelection()
1829 SequenceI[] sequences = null;
1830 if (selectionGroup != null)
1832 sequences = selectionGroup.getSequencesInOrder(alignment);
1834 if (sequences == null)
1836 sequences = alignment.getSequencesArray();
1842 public jalview.datamodel.AlignmentView getAlignmentView(
1843 boolean selectedOnly)
1845 return getAlignmentView(selectedOnly, false);
1849 public jalview.datamodel.AlignmentView getAlignmentView(
1850 boolean selectedOnly, boolean markGroups)
1852 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1854 alignment.getHiddenColumns() != null
1855 && alignment.getHiddenColumns().hasHiddenColumns(),
1856 selectedOnly, markGroups);
1860 public String[] getViewAsString(boolean selectedRegionOnly)
1862 return getViewAsString(selectedRegionOnly, true);
1866 public String[] getViewAsString(boolean selectedRegionOnly,
1867 boolean exportHiddenSeqs)
1869 String[] selection = null;
1870 SequenceI[] seqs = null;
1872 int start = 0, end = 0;
1873 if (selectedRegionOnly && selectionGroup != null)
1875 iSize = selectionGroup.getSize();
1876 seqs = selectionGroup.getSequencesInOrder(alignment);
1877 start = selectionGroup.getStartRes();
1878 end = selectionGroup.getEndRes() + 1;
1882 if (hasHiddenRows() && exportHiddenSeqs)
1884 AlignmentI fullAlignment = alignment.getHiddenSequences()
1885 .getFullAlignment();
1886 iSize = fullAlignment.getHeight();
1887 seqs = fullAlignment.getSequencesArray();
1888 end = fullAlignment.getWidth();
1892 iSize = alignment.getHeight();
1893 seqs = alignment.getSequencesArray();
1894 end = alignment.getWidth();
1898 selection = new String[iSize];
1899 if (alignment.getHiddenColumns() != null
1900 && alignment.getHiddenColumns().hasHiddenColumns())
1902 selection = alignment.getHiddenColumns()
1903 .getVisibleSequenceStrings(start, end, seqs);
1907 for (i = 0; i < iSize; i++)
1909 selection[i] = seqs[i].getSequenceAsString(start, end);
1917 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1919 ArrayList<int[]> regions = new ArrayList<>();
1925 HiddenColumns hidden = alignment.getHiddenColumns();
1926 if (hidden != null && hidden.hasHiddenColumns())
1930 start = hidden.adjustForHiddenColumns(start);
1933 end = hidden.getHiddenBoundaryRight(start);
1944 regions.add(new int[] { start, end });
1946 if (hidden != null && hidden.hasHiddenColumns())
1948 start = hidden.adjustForHiddenColumns(end);
1949 start = hidden.getHiddenBoundaryLeft(start) + 1;
1951 } while (end < max);
1953 int[][] startEnd = new int[regions.size()][2];
1959 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1960 boolean selectedOnly)
1962 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1963 AlignmentAnnotation[] aa;
1964 if ((aa = alignment.getAlignmentAnnotation()) != null)
1966 for (AlignmentAnnotation annot : aa)
1968 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1969 if (selectedOnly && selectionGroup != null)
1971 alignment.getHiddenColumns().makeVisibleAnnotation(
1972 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1977 alignment.getHiddenColumns().makeVisibleAnnotation(clone);
1986 public boolean isPadGaps()
1992 public void setPadGaps(boolean padGaps)
1994 this.padGaps = padGaps;
1998 * apply any post-edit constraints and trigger any calculations needed after
1999 * an edit has been performed on the alignment
2004 public void alignmentChanged(AlignmentViewPanel ap)
2008 alignment.padGaps();
2010 if (autoCalculateConsensus)
2012 updateConsensus(ap);
2014 if (hconsensus != null && autoCalculateConsensus)
2016 updateConservation(ap);
2018 if (autoCalculateStrucConsensus)
2020 updateStrucConsensus(ap);
2023 updateInformation(ap);
2025 List<SequenceI> hmmSequences;
2026 hmmSequences = alignment.getHMMConsensusSequences(false);
2028 for (SequenceI seq : hmmSequences)
2030 seq.updateHMMMapping();
2033 // Reset endRes of groups if beyond alignment width
2034 int alWidth = alignment.getWidth();
2035 List<SequenceGroup> groups = alignment.getGroups();
2038 for (SequenceGroup sg : groups)
2040 if (sg.getEndRes() > alWidth)
2042 sg.setEndRes(alWidth - 1);
2047 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
2049 selectionGroup.setEndRes(alWidth - 1);
2052 updateAllColourSchemes();
2053 calculator.restartWorkers();
2054 // alignment.adjustSequenceAnnotations();
2058 * reset scope and do calculations for all applied colourschemes on alignment
2060 void updateAllColourSchemes()
2062 ResidueShaderI rs = residueShading;
2065 rs.alignmentChanged(alignment, hiddenRepSequences);
2067 rs.setConsensus(hconsensus);
2068 if (rs.conservationApplied())
2070 rs.setConservation(Conservation.calculateConservation("All",
2071 alignment.getSequences(), 0, alignment.getWidth(), false,
2072 getConsPercGaps(), false));
2076 for (SequenceGroup sg : alignment.getGroups())
2080 sg.cs.alignmentChanged(sg, hiddenRepSequences);
2082 sg.recalcConservation();
2086 protected void initAutoAnnotation()
2088 // TODO: add menu option action that nulls or creates consensus object
2089 // depending on if the user wants to see the annotation or not in a
2090 // specific alignment
2092 if (hconsensus == null && !isDataset)
2094 if (!alignment.isNucleotide())
2103 consensus = new AlignmentAnnotation("Consensus",
2104 MessageManager.getString("label.consensus_descr"),
2105 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2106 initConsensus(consensus);
2110 initComplementConsensus();
2115 * If this is a protein alignment and there are mappings to cDNA, adds the
2116 * cDNA consensus annotation and returns true, else returns false.
2118 public boolean initComplementConsensus()
2120 if (!alignment.isNucleotide())
2122 final List<AlignedCodonFrame> codonMappings = alignment
2124 if (codonMappings != null && !codonMappings.isEmpty())
2126 boolean doConsensus = false;
2127 for (AlignedCodonFrame mapping : codonMappings)
2129 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2130 MapList[] mapLists = mapping.getdnaToProt();
2131 // mapLists can be empty if project load has not finished resolving
2133 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2141 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2143 .getString("label.complement_consensus_descr"),
2144 new Annotation[1], 0f, 100f,
2145 AlignmentAnnotation.BAR_GRAPH);
2146 initConsensus(complementConsensus);
2154 private void initConsensus(AlignmentAnnotation aa)
2157 aa.autoCalculated = true;
2161 alignment.addAnnotation(aa);
2166 public void initInformation()
2168 for (SequenceI seq : alignment.getHMMConsensusSequences(false))
2170 if (!seq.hasHMMAnnotation())
2172 AlignmentAnnotation information;
2173 information = new AlignmentAnnotation(seq.getName(),
2174 MessageManager.getString("label.information_description"),
2175 new Annotation[1], 0f, 6.52f,
2176 AlignmentAnnotation.BAR_GRAPH);
2177 information.hasText = true;
2178 information.autoCalculated = true;
2179 information.hasText = true;
2180 information.autoCalculated = false;
2181 information.sequenceRef = seq;
2182 information.setCalcId("HMM");
2183 this.information.add(information);
2184 hinformation.add(new Profiles(new ProfileI[1]));
2185 alignment.addAnnotation(information);
2186 seq.updateHMMMapping();
2187 seq.setHasInfo(true);
2188 seq.addAlignmentAnnotation(information);
2194 // these should be extracted from the view model - style and settings for
2195 // derived annotation
2196 private void initGapCounts()
2200 gapcounts = new AlignmentAnnotation("Occupancy",
2201 MessageManager.getString("label.occupancy_descr"),
2202 new Annotation[1], 0f, alignment.getHeight(),
2203 AlignmentAnnotation.BAR_GRAPH);
2204 gapcounts.hasText = true;
2205 gapcounts.autoCalculated = true;
2206 gapcounts.scaleColLabel = true;
2207 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2209 alignment.addAnnotation(gapcounts);
2213 private void initConservation()
2215 if (showConservation)
2217 if (conservation == null)
2219 conservation = new AlignmentAnnotation("Conservation",
2220 MessageManager.formatMessage("label.conservation_descr",
2222 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2223 conservation.hasText = true;
2224 conservation.autoCalculated = true;
2225 alignment.addAnnotation(conservation);
2230 private void initQuality()
2234 if (quality == null)
2236 quality = new AlignmentAnnotation("Quality",
2237 MessageManager.getString("label.quality_descr"),
2238 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2239 quality.hasText = true;
2240 quality.autoCalculated = true;
2241 alignment.addAnnotation(quality);
2246 private void initRNAStructure()
2248 if (alignment.hasRNAStructure() && strucConsensus == null)
2250 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2251 MessageManager.getString("label.strucconsensus_descr"),
2252 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2253 strucConsensus.hasText = true;
2254 strucConsensus.autoCalculated = true;
2258 alignment.addAnnotation(strucConsensus);
2266 * @see jalview.api.AlignViewportI#calcPanelHeight()
2269 public int calcPanelHeight()
2271 // setHeight of panels
2272 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2274 int charHeight = getCharHeight();
2277 BitSet graphgrp = new BitSet();
2278 for (AlignmentAnnotation aa : anns)
2282 System.err.println("Null annotation row: ignoring.");
2289 if (aa.graphGroup > -1)
2291 if (graphgrp.get(aa.graphGroup))
2297 graphgrp.set(aa.graphGroup);
2304 aa.height += charHeight;
2314 aa.height += aa.graphHeight;
2322 height += aa.height;
2334 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2335 boolean preserveNewGroupSettings)
2337 boolean updateCalcs = false;
2338 boolean conv = isShowGroupConservation();
2339 boolean cons = isShowGroupConsensus();
2340 boolean showprf = isShowSequenceLogo();
2341 boolean showConsHist = isShowConsensusHistogram();
2342 boolean normLogo = isNormaliseSequenceLogo();
2343 boolean showHMMPrf = isShowHMMSequenceLogo();
2344 boolean showInfoHist = isShowInformationHistogram();
2345 boolean normHMMLogo = isNormaliseHMMSequenceLogo();
2348 * TODO reorder the annotation rows according to group/sequence ordering on
2351 boolean sortg = true;
2353 // remove old automatic annotation
2354 // add any new annotation
2356 // intersect alignment annotation with alignment groups
2358 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2359 List<SequenceGroup> oldrfs = new ArrayList<>();
2362 for (int an = 0; an < aan.length; an++)
2364 if (aan[an].autoCalculated && aan[an].groupRef != null)
2366 oldrfs.add(aan[an].groupRef);
2367 alignment.deleteAnnotation(aan[an], false);
2371 if (alignment.getGroups() != null)
2373 for (SequenceGroup sg : alignment.getGroups())
2375 updateCalcs = false;
2376 if (applyGlobalSettings
2377 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2379 // set defaults for this group's conservation/consensus
2380 sg.setshowSequenceLogo(showprf);
2381 sg.setShowConsensusHistogram(showConsHist);
2382 sg.setNormaliseSequenceLogo(normLogo);
2383 sg.setshowHMMSequenceLogo(showHMMPrf);
2384 sg.setShowInformationHistogram(showInfoHist);
2385 sg.setNormaliseHMMSequenceLogo(normHMMLogo);
2390 alignment.addAnnotation(sg.getConservationRow(), 0);
2395 alignment.addAnnotation(sg.getConsensus(), 0);
2397 // refresh the annotation rows
2400 sg.recalcConservation();
2408 public boolean isDisplayReferenceSeq()
2410 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2414 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2416 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2420 public boolean isColourByReferenceSeq()
2422 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2426 public Color getSequenceColour(SequenceI seq)
2428 Color sqc = sequenceColours.get(seq);
2429 return (sqc == null ? Color.white : sqc);
2433 public void setSequenceColour(SequenceI seq, Color col)
2437 sequenceColours.remove(seq);
2441 sequenceColours.put(seq, col);
2446 public void updateSequenceIdColours()
2448 for (SequenceGroup sg : alignment.getGroups())
2450 if (sg.idColour != null)
2452 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2454 sequenceColours.put(s, sg.idColour);
2461 public void clearSequenceColours()
2463 sequenceColours.clear();
2467 public AlignViewportI getCodingComplement()
2469 return this.codingComplement;
2473 * Set this as the (cDna/protein) complement of the given viewport. Also
2474 * ensures the reverse relationship is set on the given viewport.
2477 public void setCodingComplement(AlignViewportI av)
2481 System.err.println("Ignoring recursive setCodingComplement request");
2485 this.codingComplement = av;
2486 // avoid infinite recursion!
2487 if (av.getCodingComplement() != this)
2489 av.setCodingComplement(this);
2495 public boolean isNucleotide()
2497 return getAlignment() == null ? false : getAlignment().isNucleotide();
2501 public FeaturesDisplayedI getFeaturesDisplayed()
2503 return featuresDisplayed;
2507 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2509 featuresDisplayed = featuresDisplayedI;
2513 public boolean areFeaturesDisplayed()
2515 return featuresDisplayed != null
2516 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2523 * features are displayed if true
2526 public void setShowSequenceFeatures(boolean b)
2528 viewStyle.setShowSequenceFeatures(b);
2532 public boolean isShowSequenceFeatures()
2534 return viewStyle.isShowSequenceFeatures();
2538 public void setShowSequenceFeaturesHeight(boolean selected)
2540 viewStyle.setShowSequenceFeaturesHeight(selected);
2544 public boolean isShowSequenceFeaturesHeight()
2546 return viewStyle.isShowSequenceFeaturesHeight();
2550 public void setShowAnnotation(boolean b)
2552 viewStyle.setShowAnnotation(b);
2556 public boolean isShowAnnotation()
2558 return viewStyle.isShowAnnotation();
2562 public boolean isRightAlignIds()
2564 return viewStyle.isRightAlignIds();
2568 public void setRightAlignIds(boolean rightAlignIds)
2570 viewStyle.setRightAlignIds(rightAlignIds);
2574 public boolean getConservationSelected()
2576 return viewStyle.getConservationSelected();
2580 public void setShowBoxes(boolean state)
2582 viewStyle.setShowBoxes(state);
2587 * @see jalview.api.ViewStyleI#getTextColour()
2590 public Color getTextColour()
2592 return viewStyle.getTextColour();
2597 * @see jalview.api.ViewStyleI#getTextColour2()
2600 public Color getTextColour2()
2602 return viewStyle.getTextColour2();
2607 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2610 public int getThresholdTextColour()
2612 return viewStyle.getThresholdTextColour();
2617 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2620 public boolean isConservationColourSelected()
2622 return viewStyle.isConservationColourSelected();
2627 * @see jalview.api.ViewStyleI#isRenderGaps()
2630 public boolean isRenderGaps()
2632 return viewStyle.isRenderGaps();
2637 * @see jalview.api.ViewStyleI#isShowColourText()
2640 public boolean isShowColourText()
2642 return viewStyle.isShowColourText();
2646 * @param conservationColourSelected
2647 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2650 public void setConservationColourSelected(
2651 boolean conservationColourSelected)
2653 viewStyle.setConservationColourSelected(conservationColourSelected);
2657 * @param showColourText
2658 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2661 public void setShowColourText(boolean showColourText)
2663 viewStyle.setShowColourText(showColourText);
2668 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2671 public void setTextColour(Color textColour)
2673 viewStyle.setTextColour(textColour);
2677 * @param thresholdTextColour
2678 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2681 public void setThresholdTextColour(int thresholdTextColour)
2683 viewStyle.setThresholdTextColour(thresholdTextColour);
2687 * @param textColour2
2688 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2691 public void setTextColour2(Color textColour2)
2693 viewStyle.setTextColour2(textColour2);
2697 public ViewStyleI getViewStyle()
2699 return new ViewStyle(viewStyle);
2703 public void setViewStyle(ViewStyleI settingsForView)
2705 viewStyle = new ViewStyle(settingsForView);
2706 if (residueShading != null)
2708 residueShading.setConservationApplied(
2709 settingsForView.isConservationColourSelected());
2714 public boolean sameStyle(ViewStyleI them)
2716 return viewStyle.sameStyle(them);
2721 * @see jalview.api.ViewStyleI#getIdWidth()
2724 public int getIdWidth()
2726 return viewStyle.getIdWidth();
2731 * @see jalview.api.ViewStyleI#setIdWidth(int)
2734 public void setIdWidth(int i)
2736 viewStyle.setIdWidth(i);
2741 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2744 public boolean isCentreColumnLabels()
2746 return viewStyle.isCentreColumnLabels();
2750 * @param centreColumnLabels
2751 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2754 public void setCentreColumnLabels(boolean centreColumnLabels)
2756 viewStyle.setCentreColumnLabels(centreColumnLabels);
2761 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2764 public void setShowDBRefs(boolean showdbrefs)
2766 viewStyle.setShowDBRefs(showdbrefs);
2771 * @see jalview.api.ViewStyleI#isShowDBRefs()
2774 public boolean isShowDBRefs()
2776 return viewStyle.isShowDBRefs();
2781 * @see jalview.api.ViewStyleI#isShowNPFeats()
2784 public boolean isShowNPFeats()
2786 return viewStyle.isShowNPFeats();
2790 * @param shownpfeats
2791 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2794 public void setShowNPFeats(boolean shownpfeats)
2796 viewStyle.setShowNPFeats(shownpfeats);
2799 public abstract StructureSelectionManager getStructureSelectionManager();
2802 * Add one command to the command history list.
2806 public void addToHistoryList(CommandI command)
2808 if (this.historyList != null)
2810 this.historyList.push(command);
2811 broadcastCommand(command, false);
2815 protected void broadcastCommand(CommandI command, boolean undo)
2817 getStructureSelectionManager().commandPerformed(command, undo,
2822 * Add one command to the command redo list.
2826 public void addToRedoList(CommandI command)
2828 if (this.redoList != null)
2830 this.redoList.push(command);
2832 broadcastCommand(command, true);
2836 * Clear the command redo list.
2838 public void clearRedoList()
2840 if (this.redoList != null)
2842 this.redoList.clear();
2846 public void setHistoryList(Deque<CommandI> list)
2848 this.historyList = list;
2851 public Deque<CommandI> getHistoryList()
2853 return this.historyList;
2856 public void setRedoList(Deque<CommandI> list)
2858 this.redoList = list;
2861 public Deque<CommandI> getRedoList()
2863 return this.redoList;
2867 public VamsasSource getVamsasSource()
2872 public SequenceAnnotationOrder getSortAnnotationsBy()
2874 return sortAnnotationsBy;
2877 public void setSortAnnotationsBy(
2878 SequenceAnnotationOrder sortAnnotationsBy)
2880 this.sortAnnotationsBy = sortAnnotationsBy;
2883 public boolean isShowAutocalculatedAbove()
2885 return showAutocalculatedAbove;
2888 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2890 this.showAutocalculatedAbove = showAutocalculatedAbove;
2894 public boolean isScaleProteinAsCdna()
2896 return viewStyle.isScaleProteinAsCdna();
2900 public void setScaleProteinAsCdna(boolean b)
2902 viewStyle.setScaleProteinAsCdna(b);
2906 public boolean isProteinFontAsCdna()
2908 return viewStyle.isProteinFontAsCdna();
2912 public void setProteinFontAsCdna(boolean b)
2914 viewStyle.setProteinFontAsCdna(b);
2918 * @return true if view should scroll to show the highlighted region of a
2923 public final boolean isFollowHighlight()
2925 return followHighlight;
2929 public final void setFollowHighlight(boolean b)
2931 this.followHighlight = b;
2935 public ViewportRanges getRanges()
2941 * Helper method to populate the SearchResults with the location in the
2942 * complementary alignment to scroll to, in order to match this one.
2945 * the SearchResults to add to
2946 * @return the offset (below top of visible region) of the matched sequence
2948 protected int findComplementScrollTarget(SearchResultsI sr)
2950 final AlignViewportI complement = getCodingComplement();
2951 if (complement == null || !complement.isFollowHighlight())
2955 boolean iAmProtein = !getAlignment().isNucleotide();
2956 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2957 : complement.getAlignment();
2958 if (proteinAlignment == null)
2962 final List<AlignedCodonFrame> mappings = proteinAlignment
2966 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2967 * residue in the middle column of the visible region. Scroll the
2968 * complementary alignment to line up the corresponding residue.
2971 SequenceI sequence = null;
2974 * locate 'middle' column (true middle if an odd number visible, left of
2975 * middle if an even number visible)
2977 int middleColumn = ranges.getStartRes()
2978 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2979 final HiddenSequences hiddenSequences = getAlignment()
2980 .getHiddenSequences();
2983 * searching to the bottom of the alignment gives smoother scrolling across
2984 * all gapped visible regions
2986 int lastSeq = alignment.getHeight() - 1;
2987 List<AlignedCodonFrame> seqMappings = null;
2988 for (int seqNo = ranges
2989 .getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2991 sequence = getAlignment().getSequenceAt(seqNo);
2992 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2996 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
3000 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
3002 getCodingComplement().getAlignment().getSequences());
3003 if (!seqMappings.isEmpty())
3009 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
3012 * No ungapped mapped sequence in middle column - do nothing
3016 MappingUtils.addSearchResults(sr, sequence,
3017 sequence.findPosition(middleColumn), seqMappings);
3022 * synthesize a column selection if none exists so it covers the given
3023 * selection group. if wholewidth is false, no column selection is made if the
3024 * selection group covers the whole alignment width.
3029 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
3032 if (sg != null && (sgs = sg.getStartRes()) >= 0
3033 && sg.getStartRes() <= (sge = sg.getEndRes())
3034 && !this.hasSelectedColumns())
3036 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
3043 colSel = new ColumnSelection();
3045 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
3047 colSel.addElement(cspos);
3053 * hold status of current selection group - defined on alignment or not.
3055 private boolean selectionIsDefinedGroup = false;
3058 public boolean isSelectionDefinedGroup()
3060 if (selectionGroup == null)
3064 if (isSelectionGroupChanged(true))
3066 selectionIsDefinedGroup = false;
3067 List<SequenceGroup> gps = alignment.getGroups();
3068 if (gps == null || gps.size() == 0)
3070 selectionIsDefinedGroup = false;
3074 selectionIsDefinedGroup = gps.contains(selectionGroup);
3077 return selectionGroup.isDefined() || selectionIsDefinedGroup;
3081 * null, or currently highlighted results on this view
3083 private SearchResultsI searchResults = null;
3085 protected TreeModel currentTree = null;
3088 public boolean hasSearchResults()
3090 return searchResults != null;
3094 public void setSearchResults(SearchResultsI results)
3096 searchResults = results;
3100 public SearchResultsI getSearchResults()
3102 return searchResults;
3106 * get the consensus sequence as displayed under the PID consensus annotation
3109 * @return consensus sequence as a new sequence object
3111 public SequenceI getConsensusSeq()
3113 if (consensus == null)
3115 updateConsensus(null);
3117 if (consensus == null)
3121 StringBuffer seqs = new StringBuffer();
3122 for (int i = 0; i < consensus.annotations.length; i++)
3124 Annotation annotation = consensus.annotations[i];
3125 if (annotation != null)
3127 String description = annotation.description;
3128 if (description != null && description.startsWith("["))
3130 // consensus is a tie - just pick the first one
3131 seqs.append(description.charAt(1));
3135 seqs.append(annotation.displayCharacter);
3140 SequenceI sq = new Sequence("Consensus", seqs.toString());
3141 sq.setDescription("Percentage Identity Consensus "
3142 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3146 public boolean hasReferenceAnnotation()
3148 AlignmentAnnotation[] annots = this.alignment.getAlignmentAnnotation();
3149 for (AlignmentAnnotation annot : annots)
3151 if ("RF".equals(annot.label) || annot.label.contains("Reference"))
3160 public void setCurrentTree(TreeModel tree)
3166 public TreeModel getCurrentTree()