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 getAlignmentGapAnnotation()
853 public AlignmentAnnotation getComplementConsensusAnnotation()
855 return complementConsensus;
859 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
861 return strucConsensus;
864 protected AlignCalcManagerI calculator = new AlignCalcManager();
867 * trigger update of conservation annotation
869 public void updateConservation(final AlignmentViewPanel ap)
871 // see note in mantis : issue number 8585
872 if (alignment.isNucleotide()
873 || (conservation == null && quality == null)
874 || !autoCalculateConsensus)
878 if (calculator.getRegisteredWorkersOfClass(
879 jalview.workers.ConservationThread.class) == null)
881 calculator.registerWorker(
882 new jalview.workers.ConservationThread(this, ap));
887 * trigger update of consensus annotation
889 public void updateConsensus(final AlignmentViewPanel ap)
891 // see note in mantis : issue number 8585
892 if (consensus == null || !autoCalculateConsensus)
897 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
899 calculator.registerWorker(new ConsensusThread(this, ap));
903 * A separate thread to compute cDNA consensus for a protein alignment
904 * which has mapping to cDNA
906 final AlignmentI al = this.getAlignment();
907 if (!al.isNucleotide() && al.getCodonFrames() != null
908 && !al.getCodonFrames().isEmpty())
911 * fudge - check first for protein-to-nucleotide mappings
912 * (we don't want to do this for protein-to-protein)
914 boolean doConsensus = false;
915 for (AlignedCodonFrame mapping : al.getCodonFrames())
917 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
918 MapList[] mapLists = mapping.getdnaToProt();
919 // mapLists can be empty if project load has not finished resolving seqs
920 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
928 if (calculator.getRegisteredWorkersOfClass(
929 ComplementConsensusThread.class) == null)
932 .registerWorker(new ComplementConsensusThread(this, ap));
939 * trigger update of information annotation
942 public void updateInformation(final AlignmentViewPanel ap)
945 .getRegisteredWorkersOfClass(InformationThread.class) == null)
947 calculator.registerWorker(new InformationThread(this, ap));
952 // --------START Structure Conservation
953 public void updateStrucConsensus(final AlignmentViewPanel ap)
955 if (autoCalculateStrucConsensus && strucConsensus == null
956 && alignment.isNucleotide() && alignment.hasRNAStructure())
958 // secondary structure has been added - so init the consensus line
962 // see note in mantis : issue number 8585
963 if (strucConsensus == null || !autoCalculateStrucConsensus)
967 if (calculator.getRegisteredWorkersOfClass(
968 StrucConsensusThread.class) == null)
970 calculator.registerWorker(new StrucConsensusThread(this, ap));
974 public boolean isCalcInProgress()
976 return calculator.isWorking();
980 public boolean isCalculationInProgress(
981 AlignmentAnnotation alignmentAnnotation)
983 if (!alignmentAnnotation.autoCalculated)
987 if (calculator.workingInvolvedWith(alignmentAnnotation))
989 // System.err.println("grey out ("+alignmentAnnotation.label+")");
995 public void setAlignment(AlignmentI align)
997 this.alignment = align;
1001 * Clean up references when this viewport is closed
1004 public void dispose()
1007 * defensively null out references to large objects in case
1008 * this object is not garbage collected (as if!)
1011 complementConsensus = null;
1012 strucConsensus = null;
1013 conservation = null;
1015 groupConsensus = null;
1016 groupConservation = null;
1018 hconservation = null;
1019 hcomplementConsensus = null;
1022 residueShading = null; // may hold a reference to Consensus
1023 changeSupport = null;
1026 selectionGroup = null;
1031 public boolean isClosed()
1033 // TODO: check that this isClosed is only true after panel is closed, not
1034 // before it is fully constructed.
1035 return alignment == null;
1039 public AlignCalcManagerI getCalcManager()
1045 * should conservation rows be shown for groups
1047 protected boolean showGroupConservation = false;
1050 * should consensus rows be shown for groups
1052 protected boolean showGroupConsensus = false;
1055 * should consensus profile be rendered by default
1057 protected boolean showSequenceLogo = false;
1060 * should consensus profile be rendered normalised to row height
1062 protected boolean normaliseSequenceLogo = false;
1065 * should consensus histograms be rendered by default
1067 protected boolean showConsensusHistogram = true;
1070 * should hmm profile be rendered by default
1072 protected boolean showHMMSequenceLogo = false;
1075 * should hmm profile be rendered normalised to row height
1077 protected boolean normaliseHMMSequenceLogo = false;
1080 * should information histograms be rendered by default
1082 protected boolean showInformationHistogram = true;
1085 * @return the showConsensusProfile
1088 public boolean isShowSequenceLogo()
1090 return showSequenceLogo;
1094 * @return the showInformationProfile
1097 public boolean isShowHMMSequenceLogo()
1099 return showHMMSequenceLogo;
1103 * @param showSequenceLogo
1106 public void setShowSequenceLogo(boolean showSequenceLogo)
1108 if (showSequenceLogo != this.showSequenceLogo)
1110 // TODO: decouple settings setting from calculation when refactoring
1111 // annotation update method from alignframe to viewport
1112 this.showSequenceLogo = showSequenceLogo;
1113 calculator.updateAnnotationFor(ConsensusThread.class);
1114 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1115 calculator.updateAnnotationFor(StrucConsensusThread.class);
1117 this.showSequenceLogo = showSequenceLogo;
1120 public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo)
1122 if (showHMMSequenceLogo != this.showHMMSequenceLogo)
1124 this.showHMMSequenceLogo = showHMMSequenceLogo;
1125 calculator.updateAnnotationFor(InformationThread.class);
1127 this.showHMMSequenceLogo = showHMMSequenceLogo;
1131 * @param showConsensusHistogram
1132 * the showConsensusHistogram to set
1134 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1136 this.showConsensusHistogram = showConsensusHistogram;
1140 * @param showInformationHistogram
1141 * the showInformationHistogram to set
1143 public void setShowInformationHistogram(boolean showInformationHistogram)
1145 this.showInformationHistogram = showInformationHistogram;
1149 * @return the showGroupConservation
1151 public boolean isShowGroupConservation()
1153 return showGroupConservation;
1157 * @param showGroupConservation
1158 * the showGroupConservation to set
1160 public void setShowGroupConservation(boolean showGroupConservation)
1162 this.showGroupConservation = showGroupConservation;
1166 * @return the showGroupConsensus
1168 public boolean isShowGroupConsensus()
1170 return showGroupConsensus;
1174 * @param showGroupConsensus
1175 * the showGroupConsensus to set
1177 public void setShowGroupConsensus(boolean showGroupConsensus)
1179 this.showGroupConsensus = showGroupConsensus;
1184 * @return flag to indicate if the consensus histogram should be rendered by
1188 public boolean isShowConsensusHistogram()
1190 return this.showConsensusHistogram;
1195 * @return flag to indicate if the information content histogram should be
1196 * rendered by default
1199 public boolean isShowInformationHistogram()
1201 return this.showInformationHistogram;
1205 * when set, updateAlignment will always ensure sequences are of equal length
1207 private boolean padGaps = false;
1210 * when set, alignment should be reordered according to a newly opened tree
1212 public boolean sortByTree = false;
1217 * @return null or the currently selected sequence region
1220 public SequenceGroup getSelectionGroup()
1222 return selectionGroup;
1226 * Set the selection group for this window. Also sets the current alignment as
1227 * the context for the group, if it does not already have one.
1230 * - group holding references to sequences in this alignment view
1234 public void setSelectionGroup(SequenceGroup sg)
1236 selectionGroup = sg;
1237 if (sg != null && sg.getContext() == null)
1239 sg.setContext(alignment);
1243 public void setHiddenColumns(HiddenColumns hidden)
1245 this.alignment.setHiddenColumns(hidden);
1249 public ColumnSelection getColumnSelection()
1255 public void setColumnSelection(ColumnSelection colSel)
1257 this.colSel = colSel;
1260 updateHiddenColumns();
1262 isColSelChanged(true);
1270 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1272 return hiddenRepSequences;
1276 public void setHiddenRepSequences(
1277 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1279 this.hiddenRepSequences = hiddenRepSequences;
1283 public boolean hasSelectedColumns()
1285 ColumnSelection columnSelection = getColumnSelection();
1286 return columnSelection != null && columnSelection.hasSelectedColumns();
1290 public boolean hasHiddenColumns()
1292 return alignment.getHiddenColumns() != null
1293 && alignment.getHiddenColumns().hasHiddenColumns();
1296 public void updateHiddenColumns()
1298 // this method doesn't really do anything now. But - it could, since a
1299 // column Selection could be in the process of modification
1300 // hasHiddenColumns = colSel.hasHiddenColumns();
1304 public boolean hasHiddenRows()
1306 return alignment.getHiddenSequences().getSize() > 0;
1309 protected SequenceGroup selectionGroup;
1311 public void setSequenceSetId(String newid)
1313 if (sequenceSetID != null)
1316 "Warning - overwriting a sequenceSetId for a viewport!");
1318 sequenceSetID = new String(newid);
1322 public String getSequenceSetId()
1324 if (sequenceSetID == null)
1326 sequenceSetID = alignment.hashCode() + "";
1329 return sequenceSetID;
1333 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1336 protected String viewId = null;
1339 public String getViewId()
1343 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1348 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1350 ignoreGapsInConsensusCalculation = b;
1353 updateConsensus(ap);
1354 if (residueShading != null)
1356 residueShading.setThreshold(residueShading.getThreshold(),
1357 ignoreGapsInConsensusCalculation);
1363 public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap)
1365 ignoreBelowBackGroundFrequencyCalculation = b;
1368 updateInformation(ap);
1373 public void setInfoLetterHeight(boolean b, AlignmentViewPanel ap)
1375 infoLetterHeight = b;
1378 updateInformation(ap);
1383 private long sgrouphash = -1, colselhash = -1;
1386 * checks current SelectionGroup against record of last hash value, and
1390 * update the record of last hash value
1392 * @return true if SelectionGroup changed since last call (when b is true)
1394 public boolean isSelectionGroupChanged(boolean b)
1396 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1397 : selectionGroup.hashCode();
1398 if (hc != -1 && hc != sgrouphash)
1410 * checks current colsel against record of last hash value, and optionally
1414 * update the record of last hash value
1415 * @return true if colsel changed since last call (when b is true)
1417 public boolean isColSelChanged(boolean b)
1419 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1420 if (hc != -1 && hc != colselhash)
1432 public boolean isIgnoreGapsConsensus()
1434 return ignoreGapsInConsensusCalculation;
1438 public boolean isIgnoreBelowBackground()
1440 return ignoreBelowBackGroundFrequencyCalculation;
1444 public boolean isInfoLetterHeight()
1446 return infoLetterHeight;
1449 // property change stuff
1450 // JBPNote Prolly only need this in the applet version.
1451 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1454 protected boolean showConservation = true;
1456 protected boolean showQuality = true;
1458 protected boolean showConsensus = true;
1460 protected boolean showOccupancy = true;
1462 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1464 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1466 protected boolean showAutocalculatedAbove;
1469 * when set, view will scroll to show the highlighted position
1471 private boolean followHighlight = true;
1474 * Property change listener for changes in alignment
1479 public void addPropertyChangeListener(
1480 java.beans.PropertyChangeListener listener)
1482 changeSupport.addPropertyChangeListener(listener);
1491 public void removePropertyChangeListener(
1492 java.beans.PropertyChangeListener listener)
1494 if (changeSupport != null)
1496 changeSupport.removePropertyChangeListener(listener);
1501 * Property change listener for changes in alignment
1510 public void firePropertyChange(String prop, Object oldvalue,
1513 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1516 // common hide/show column stuff
1518 public void hideSelectedColumns()
1520 if (colSel.isEmpty())
1525 colSel.hideSelectedColumns(alignment);
1526 setSelectionGroup(null);
1527 isColSelChanged(true);
1530 public void hideColumns(int start, int end)
1534 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1538 alignment.getHiddenColumns().hideColumns(start, end);
1540 isColSelChanged(true);
1543 public void showColumn(int col)
1545 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1546 isColSelChanged(true);
1549 public void showAllHiddenColumns()
1551 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1552 isColSelChanged(true);
1555 // common hide/show seq stuff
1556 public void showAllHiddenSeqs()
1558 int startSeq = ranges.getStartSeq();
1559 int endSeq = ranges.getEndSeq();
1561 if (alignment.getHiddenSequences().getSize() > 0)
1563 if (selectionGroup == null)
1565 selectionGroup = new SequenceGroup();
1566 selectionGroup.setEndRes(alignment.getWidth() - 1);
1568 List<SequenceI> tmp = alignment.getHiddenSequences()
1569 .showAll(hiddenRepSequences);
1570 for (SequenceI seq : tmp)
1572 selectionGroup.addSequence(seq, false);
1573 setSequenceAnnotationsVisible(seq, true);
1576 hiddenRepSequences = null;
1578 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1580 firePropertyChange("alignment", null, alignment.getSequences());
1581 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1587 public void showSequence(int index)
1589 int startSeq = ranges.getStartSeq();
1590 int endSeq = ranges.getEndSeq();
1592 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1593 hiddenRepSequences);
1596 if (selectionGroup == null)
1598 selectionGroup = new SequenceGroup();
1599 selectionGroup.setEndRes(alignment.getWidth() - 1);
1602 for (SequenceI seq : tmp)
1604 selectionGroup.addSequence(seq, false);
1605 setSequenceAnnotationsVisible(seq, true);
1608 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1610 firePropertyChange("alignment", null, alignment.getSequences());
1615 public void hideAllSelectedSeqs()
1617 if (selectionGroup == null || selectionGroup.getSize() < 1)
1622 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1626 setSelectionGroup(null);
1629 public void hideSequence(SequenceI[] seq)
1632 * cache offset to first visible sequence
1634 int startSeq = ranges.getStartSeq();
1638 for (int i = 0; i < seq.length; i++)
1640 alignment.getHiddenSequences().hideSequence(seq[i]);
1641 setSequenceAnnotationsVisible(seq[i], false);
1643 ranges.setStartSeq(startSeq);
1644 firePropertyChange("alignment", null, alignment.getSequences());
1649 * Hides the specified sequence, or the sequences it represents
1652 * the sequence to hide, or keep as representative
1653 * @param representGroup
1654 * if true, hide the current selection group except for the
1655 * representative sequence
1657 public void hideSequences(SequenceI sequence, boolean representGroup)
1659 if (selectionGroup == null || selectionGroup.getSize() < 1)
1661 hideSequence(new SequenceI[] { sequence });
1667 hideRepSequences(sequence, selectionGroup);
1668 setSelectionGroup(null);
1672 int gsize = selectionGroup.getSize();
1673 SequenceI[] hseqs = selectionGroup.getSequences()
1674 .toArray(new SequenceI[gsize]);
1676 hideSequence(hseqs);
1677 setSelectionGroup(null);
1682 * Set visibility for any annotations for the given sequence.
1686 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1689 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1692 for (AlignmentAnnotation ann : anns)
1694 if (ann.sequenceRef == sequenceI)
1696 ann.visible = visible;
1702 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1704 int sSize = sg.getSize();
1710 if (hiddenRepSequences == null)
1712 hiddenRepSequences = new Hashtable<>();
1715 hiddenRepSequences.put(repSequence, sg);
1717 // Hide all sequences except the repSequence
1718 SequenceI[] seqs = new SequenceI[sSize - 1];
1720 for (int i = 0; i < sSize; i++)
1722 if (sg.getSequenceAt(i) != repSequence)
1724 if (index == sSize - 1)
1729 seqs[index++] = sg.getSequenceAt(i);
1732 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1733 sg.setHidereps(true); // note: not done in 2.7applet
1740 * @return null or the current reference sequence
1742 public SequenceI getReferenceSeq()
1744 return alignment.getSeqrep();
1749 * @return true iff seq is the reference for the alignment
1751 public boolean isReferenceSeq(SequenceI seq)
1753 return alignment.getSeqrep() == seq;
1759 * @return true if there are sequences represented by this sequence that are
1762 public boolean isHiddenRepSequence(SequenceI seq)
1764 return (hiddenRepSequences != null
1765 && hiddenRepSequences.containsKey(seq));
1771 * @return null or a sequence group containing the sequences that seq
1774 public SequenceGroup getRepresentedSequences(SequenceI seq)
1776 return (SequenceGroup) (hiddenRepSequences == null ? null
1777 : hiddenRepSequences.get(seq));
1781 public int adjustForHiddenSeqs(int alignmentIndex)
1783 return alignment.getHiddenSequences()
1784 .adjustForHiddenSeqs(alignmentIndex);
1788 public void invertColumnSelection()
1790 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1794 public SequenceI[] getSelectionAsNewSequence()
1796 SequenceI[] sequences;
1797 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1798 // this was the only caller in the applet for this method
1799 // JBPNote: in applet, this method returned references to the alignment
1800 // sequences, and it did not honour the presence/absence of annotation
1801 // attached to the alignment (probably!)
1802 if (selectionGroup == null || selectionGroup.getSize() == 0)
1804 sequences = alignment.getSequencesArray();
1805 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1806 for (int i = 0; i < sequences.length; i++)
1808 // construct new sequence with subset of visible annotation
1809 sequences[i] = new Sequence(sequences[i], annots);
1814 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1821 public SequenceI[] getSequenceSelection()
1823 SequenceI[] sequences = null;
1824 if (selectionGroup != null)
1826 sequences = selectionGroup.getSequencesInOrder(alignment);
1828 if (sequences == null)
1830 sequences = alignment.getSequencesArray();
1836 public jalview.datamodel.AlignmentView getAlignmentView(
1837 boolean selectedOnly)
1839 return getAlignmentView(selectedOnly, false);
1843 public jalview.datamodel.AlignmentView getAlignmentView(
1844 boolean selectedOnly, boolean markGroups)
1846 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1848 alignment.getHiddenColumns() != null
1849 && alignment.getHiddenColumns().hasHiddenColumns(),
1850 selectedOnly, markGroups);
1854 public String[] getViewAsString(boolean selectedRegionOnly)
1856 return getViewAsString(selectedRegionOnly, true);
1860 public String[] getViewAsString(boolean selectedRegionOnly,
1861 boolean exportHiddenSeqs)
1863 String[] selection = null;
1864 SequenceI[] seqs = null;
1866 int start = 0, end = 0;
1867 if (selectedRegionOnly && selectionGroup != null)
1869 iSize = selectionGroup.getSize();
1870 seqs = selectionGroup.getSequencesInOrder(alignment);
1871 start = selectionGroup.getStartRes();
1872 end = selectionGroup.getEndRes() + 1;
1876 if (hasHiddenRows() && exportHiddenSeqs)
1878 AlignmentI fullAlignment = alignment.getHiddenSequences()
1879 .getFullAlignment();
1880 iSize = fullAlignment.getHeight();
1881 seqs = fullAlignment.getSequencesArray();
1882 end = fullAlignment.getWidth();
1886 iSize = alignment.getHeight();
1887 seqs = alignment.getSequencesArray();
1888 end = alignment.getWidth();
1892 selection = new String[iSize];
1893 if (alignment.getHiddenColumns() != null
1894 && alignment.getHiddenColumns().hasHiddenColumns())
1896 selection = alignment.getHiddenColumns()
1897 .getVisibleSequenceStrings(start, end, seqs);
1901 for (i = 0; i < iSize; i++)
1903 selection[i] = seqs[i].getSequenceAsString(start, end);
1911 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1913 ArrayList<int[]> regions = new ArrayList<>();
1919 HiddenColumns hidden = alignment.getHiddenColumns();
1920 if (hidden != null && hidden.hasHiddenColumns())
1924 start = hidden.adjustForHiddenColumns(start);
1927 end = hidden.getHiddenBoundaryRight(start);
1938 regions.add(new int[] { start, end });
1940 if (hidden != null && hidden.hasHiddenColumns())
1942 start = hidden.adjustForHiddenColumns(end);
1943 start = hidden.getHiddenBoundaryLeft(start) + 1;
1945 } while (end < max);
1947 int[][] startEnd = new int[regions.size()][2];
1953 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1954 boolean selectedOnly)
1956 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1957 AlignmentAnnotation[] aa;
1958 if ((aa = alignment.getAlignmentAnnotation()) != null)
1960 for (AlignmentAnnotation annot : aa)
1962 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1963 if (selectedOnly && selectionGroup != null)
1965 alignment.getHiddenColumns().makeVisibleAnnotation(
1966 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1971 alignment.getHiddenColumns().makeVisibleAnnotation(clone);
1980 public boolean isPadGaps()
1986 public void setPadGaps(boolean padGaps)
1988 this.padGaps = padGaps;
1992 * apply any post-edit constraints and trigger any calculations needed after
1993 * an edit has been performed on the alignment
1998 public void alignmentChanged(AlignmentViewPanel ap)
2002 alignment.padGaps();
2004 if (autoCalculateConsensus)
2006 updateConsensus(ap);
2008 if (hconsensus != null && autoCalculateConsensus)
2010 updateConservation(ap);
2012 if (autoCalculateStrucConsensus)
2014 updateStrucConsensus(ap);
2017 updateInformation(ap);
2019 List<SequenceI> hmmSequences;
2020 hmmSequences = alignment.getHMMConsensusSequences();
2022 for (SequenceI seq : hmmSequences)
2024 seq.updateHMMMapping();
2027 // Reset endRes of groups if beyond alignment width
2028 int alWidth = alignment.getWidth();
2029 List<SequenceGroup> groups = alignment.getGroups();
2032 for (SequenceGroup sg : groups)
2034 if (sg.getEndRes() > alWidth)
2036 sg.setEndRes(alWidth - 1);
2041 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
2043 selectionGroup.setEndRes(alWidth - 1);
2046 updateAllColourSchemes();
2047 calculator.restartWorkers();
2048 // alignment.adjustSequenceAnnotations();
2052 * reset scope and do calculations for all applied colourschemes on alignment
2054 void updateAllColourSchemes()
2056 ResidueShaderI rs = residueShading;
2059 rs.alignmentChanged(alignment, hiddenRepSequences);
2061 rs.setConsensus(hconsensus);
2062 if (rs.conservationApplied())
2064 rs.setConservation(Conservation.calculateConservation("All",
2065 alignment.getSequences(), 0, alignment.getWidth(), false,
2066 getConsPercGaps(), false));
2070 for (SequenceGroup sg : alignment.getGroups())
2074 sg.cs.alignmentChanged(sg, hiddenRepSequences);
2076 sg.recalcConservation();
2080 protected void initAutoAnnotation()
2082 // TODO: add menu option action that nulls or creates consensus object
2083 // depending on if the user wants to see the annotation or not in a
2084 // specific alignment
2086 if (hconsensus == null && !isDataset)
2088 if (!alignment.isNucleotide())
2097 consensus = new AlignmentAnnotation("Consensus",
2098 MessageManager.getString("label.consensus_descr"),
2099 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2100 initConsensus(consensus);
2104 initComplementConsensus();
2109 * If this is a protein alignment and there are mappings to cDNA, adds the
2110 * cDNA consensus annotation and returns true, else returns false.
2112 public boolean initComplementConsensus()
2114 if (!alignment.isNucleotide())
2116 final List<AlignedCodonFrame> codonMappings = alignment
2118 if (codonMappings != null && !codonMappings.isEmpty())
2120 boolean doConsensus = false;
2121 for (AlignedCodonFrame mapping : codonMappings)
2123 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2124 MapList[] mapLists = mapping.getdnaToProt();
2125 // mapLists can be empty if project load has not finished resolving
2127 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2135 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2137 .getString("label.complement_consensus_descr"),
2138 new Annotation[1], 0f, 100f,
2139 AlignmentAnnotation.BAR_GRAPH);
2140 initConsensus(complementConsensus);
2148 private void initConsensus(AlignmentAnnotation aa)
2151 aa.autoCalculated = true;
2155 alignment.addAnnotation(aa);
2160 public void initInformation()
2162 for (SequenceI seq : alignment.getHMMConsensusSequences())
2164 if (!seq.hasHMMAnnotation())
2166 AlignmentAnnotation info = new AlignmentAnnotation(seq.getName(),
2167 MessageManager.getString("label.information_description"),
2168 new Annotation[1], 0f, 6.52f,
2169 AlignmentAnnotation.BAR_GRAPH);
2170 info.hasText = true;
2171 info.autoCalculated = false;
2172 info.sequenceRef = seq;
2173 info.setCalcId(InformationThread.HMM_CALC_ID);
2174 this.information.add(info);
2175 hinformation.add(new Profiles(new ProfileI[1]));
2176 alignment.addAnnotation(info);
2177 seq.updateHMMMapping();
2178 seq.addAlignmentAnnotation(info);
2183 // these should be extracted from the view model - style and settings for
2184 // derived annotation
2185 private void initGapCounts()
2189 gapcounts = new AlignmentAnnotation("Occupancy",
2190 MessageManager.getString("label.occupancy_descr"),
2191 new Annotation[1], 0f, alignment.getHeight(),
2192 AlignmentAnnotation.BAR_GRAPH);
2193 gapcounts.hasText = true;
2194 gapcounts.autoCalculated = true;
2195 gapcounts.scaleColLabel = true;
2196 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2198 alignment.addAnnotation(gapcounts);
2202 private void initConservation()
2204 if (showConservation)
2206 if (conservation == null)
2208 conservation = new AlignmentAnnotation("Conservation",
2209 MessageManager.formatMessage("label.conservation_descr",
2211 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2212 conservation.hasText = true;
2213 conservation.autoCalculated = true;
2214 alignment.addAnnotation(conservation);
2219 private void initQuality()
2223 if (quality == null)
2225 quality = new AlignmentAnnotation("Quality",
2226 MessageManager.getString("label.quality_descr"),
2227 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2228 quality.hasText = true;
2229 quality.autoCalculated = true;
2230 alignment.addAnnotation(quality);
2235 private void initRNAStructure()
2237 if (alignment.hasRNAStructure() && strucConsensus == null)
2239 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2240 MessageManager.getString("label.strucconsensus_descr"),
2241 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2242 strucConsensus.hasText = true;
2243 strucConsensus.autoCalculated = true;
2247 alignment.addAnnotation(strucConsensus);
2255 * @see jalview.api.AlignViewportI#calcPanelHeight()
2258 public int calcPanelHeight()
2260 // setHeight of panels
2261 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2263 int charHeight = getCharHeight();
2266 BitSet graphgrp = new BitSet();
2267 for (AlignmentAnnotation aa : anns)
2271 System.err.println("Null annotation row: ignoring.");
2278 if (aa.graphGroup > -1)
2280 if (graphgrp.get(aa.graphGroup))
2286 graphgrp.set(aa.graphGroup);
2293 aa.height += charHeight;
2303 aa.height += aa.graphHeight;
2311 height += aa.height;
2323 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2324 boolean preserveNewGroupSettings)
2326 boolean updateCalcs = false;
2327 boolean conv = isShowGroupConservation();
2328 boolean cons = isShowGroupConsensus();
2329 boolean showprf = isShowSequenceLogo();
2330 boolean showConsHist = isShowConsensusHistogram();
2331 boolean normLogo = isNormaliseSequenceLogo();
2332 boolean showHMMPrf = isShowHMMSequenceLogo();
2333 boolean showInfoHist = isShowInformationHistogram();
2334 boolean normHMMLogo = isNormaliseHMMSequenceLogo();
2337 * TODO reorder the annotation rows according to group/sequence ordering on
2340 boolean sortg = true;
2342 // remove old automatic annotation
2343 // add any new annotation
2345 // intersect alignment annotation with alignment groups
2347 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2348 List<SequenceGroup> oldrfs = new ArrayList<>();
2351 for (int an = 0; an < aan.length; an++)
2353 if (aan[an].autoCalculated && aan[an].groupRef != null)
2355 oldrfs.add(aan[an].groupRef);
2356 alignment.deleteAnnotation(aan[an], false);
2360 if (alignment.getGroups() != null)
2362 for (SequenceGroup sg : alignment.getGroups())
2364 updateCalcs = false;
2365 if (applyGlobalSettings
2366 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2368 // set defaults for this group's conservation/consensus
2369 sg.setshowSequenceLogo(showprf);
2370 sg.setShowConsensusHistogram(showConsHist);
2371 sg.setNormaliseSequenceLogo(normLogo);
2372 sg.setshowHMMSequenceLogo(showHMMPrf);
2373 sg.setShowInformationHistogram(showInfoHist);
2374 sg.setNormaliseHMMSequenceLogo(normHMMLogo);
2379 alignment.addAnnotation(sg.getConservationRow(), 0);
2384 alignment.addAnnotation(sg.getConsensus(), 0);
2386 // refresh the annotation rows
2389 sg.recalcConservation();
2397 public boolean isDisplayReferenceSeq()
2399 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2403 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2405 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2409 public boolean isColourByReferenceSeq()
2411 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2415 public Color getSequenceColour(SequenceI seq)
2417 Color sqc = sequenceColours.get(seq);
2418 return (sqc == null ? Color.white : sqc);
2422 public void setSequenceColour(SequenceI seq, Color col)
2426 sequenceColours.remove(seq);
2430 sequenceColours.put(seq, col);
2435 public void updateSequenceIdColours()
2437 for (SequenceGroup sg : alignment.getGroups())
2439 if (sg.idColour != null)
2441 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2443 sequenceColours.put(s, sg.idColour);
2450 public void clearSequenceColours()
2452 sequenceColours.clear();
2456 public AlignViewportI getCodingComplement()
2458 return this.codingComplement;
2462 * Set this as the (cDna/protein) complement of the given viewport. Also
2463 * ensures the reverse relationship is set on the given viewport.
2466 public void setCodingComplement(AlignViewportI av)
2470 System.err.println("Ignoring recursive setCodingComplement request");
2474 this.codingComplement = av;
2475 // avoid infinite recursion!
2476 if (av.getCodingComplement() != this)
2478 av.setCodingComplement(this);
2484 public boolean isNucleotide()
2486 return getAlignment() == null ? false : getAlignment().isNucleotide();
2490 public FeaturesDisplayedI getFeaturesDisplayed()
2492 return featuresDisplayed;
2496 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2498 featuresDisplayed = featuresDisplayedI;
2502 public boolean areFeaturesDisplayed()
2504 return featuresDisplayed != null
2505 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2512 * features are displayed if true
2515 public void setShowSequenceFeatures(boolean b)
2517 viewStyle.setShowSequenceFeatures(b);
2521 public boolean isShowSequenceFeatures()
2523 return viewStyle.isShowSequenceFeatures();
2527 public void setShowSequenceFeaturesHeight(boolean selected)
2529 viewStyle.setShowSequenceFeaturesHeight(selected);
2533 public boolean isShowSequenceFeaturesHeight()
2535 return viewStyle.isShowSequenceFeaturesHeight();
2539 public void setShowAnnotation(boolean b)
2541 viewStyle.setShowAnnotation(b);
2545 public boolean isShowAnnotation()
2547 return viewStyle.isShowAnnotation();
2551 public boolean isRightAlignIds()
2553 return viewStyle.isRightAlignIds();
2557 public void setRightAlignIds(boolean rightAlignIds)
2559 viewStyle.setRightAlignIds(rightAlignIds);
2563 public boolean getConservationSelected()
2565 return viewStyle.getConservationSelected();
2569 public void setShowBoxes(boolean state)
2571 viewStyle.setShowBoxes(state);
2576 * @see jalview.api.ViewStyleI#getTextColour()
2579 public Color getTextColour()
2581 return viewStyle.getTextColour();
2586 * @see jalview.api.ViewStyleI#getTextColour2()
2589 public Color getTextColour2()
2591 return viewStyle.getTextColour2();
2596 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2599 public int getThresholdTextColour()
2601 return viewStyle.getThresholdTextColour();
2606 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2609 public boolean isConservationColourSelected()
2611 return viewStyle.isConservationColourSelected();
2616 * @see jalview.api.ViewStyleI#isRenderGaps()
2619 public boolean isRenderGaps()
2621 return viewStyle.isRenderGaps();
2626 * @see jalview.api.ViewStyleI#isShowColourText()
2629 public boolean isShowColourText()
2631 return viewStyle.isShowColourText();
2635 * @param conservationColourSelected
2636 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2639 public void setConservationColourSelected(
2640 boolean conservationColourSelected)
2642 viewStyle.setConservationColourSelected(conservationColourSelected);
2646 * @param showColourText
2647 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2650 public void setShowColourText(boolean showColourText)
2652 viewStyle.setShowColourText(showColourText);
2657 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2660 public void setTextColour(Color textColour)
2662 viewStyle.setTextColour(textColour);
2666 * @param thresholdTextColour
2667 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2670 public void setThresholdTextColour(int thresholdTextColour)
2672 viewStyle.setThresholdTextColour(thresholdTextColour);
2676 * @param textColour2
2677 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2680 public void setTextColour2(Color textColour2)
2682 viewStyle.setTextColour2(textColour2);
2686 public ViewStyleI getViewStyle()
2688 return new ViewStyle(viewStyle);
2692 public void setViewStyle(ViewStyleI settingsForView)
2694 viewStyle = new ViewStyle(settingsForView);
2695 if (residueShading != null)
2697 residueShading.setConservationApplied(
2698 settingsForView.isConservationColourSelected());
2703 public boolean sameStyle(ViewStyleI them)
2705 return viewStyle.sameStyle(them);
2710 * @see jalview.api.ViewStyleI#getIdWidth()
2713 public int getIdWidth()
2715 return viewStyle.getIdWidth();
2720 * @see jalview.api.ViewStyleI#setIdWidth(int)
2723 public void setIdWidth(int i)
2725 viewStyle.setIdWidth(i);
2730 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2733 public boolean isCentreColumnLabels()
2735 return viewStyle.isCentreColumnLabels();
2739 * @param centreColumnLabels
2740 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2743 public void setCentreColumnLabels(boolean centreColumnLabels)
2745 viewStyle.setCentreColumnLabels(centreColumnLabels);
2750 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2753 public void setShowDBRefs(boolean showdbrefs)
2755 viewStyle.setShowDBRefs(showdbrefs);
2760 * @see jalview.api.ViewStyleI#isShowDBRefs()
2763 public boolean isShowDBRefs()
2765 return viewStyle.isShowDBRefs();
2770 * @see jalview.api.ViewStyleI#isShowNPFeats()
2773 public boolean isShowNPFeats()
2775 return viewStyle.isShowNPFeats();
2779 * @param shownpfeats
2780 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2783 public void setShowNPFeats(boolean shownpfeats)
2785 viewStyle.setShowNPFeats(shownpfeats);
2788 public abstract StructureSelectionManager getStructureSelectionManager();
2791 * Add one command to the command history list.
2795 public void addToHistoryList(CommandI command)
2797 if (this.historyList != null)
2799 this.historyList.push(command);
2800 broadcastCommand(command, false);
2804 protected void broadcastCommand(CommandI command, boolean undo)
2806 getStructureSelectionManager().commandPerformed(command, undo,
2811 * Add one command to the command redo list.
2815 public void addToRedoList(CommandI command)
2817 if (this.redoList != null)
2819 this.redoList.push(command);
2821 broadcastCommand(command, true);
2825 * Clear the command redo list.
2827 public void clearRedoList()
2829 if (this.redoList != null)
2831 this.redoList.clear();
2835 public void setHistoryList(Deque<CommandI> list)
2837 this.historyList = list;
2840 public Deque<CommandI> getHistoryList()
2842 return this.historyList;
2845 public void setRedoList(Deque<CommandI> list)
2847 this.redoList = list;
2850 public Deque<CommandI> getRedoList()
2852 return this.redoList;
2856 public VamsasSource getVamsasSource()
2861 public SequenceAnnotationOrder getSortAnnotationsBy()
2863 return sortAnnotationsBy;
2866 public void setSortAnnotationsBy(
2867 SequenceAnnotationOrder sortAnnotationsBy)
2869 this.sortAnnotationsBy = sortAnnotationsBy;
2872 public boolean isShowAutocalculatedAbove()
2874 return showAutocalculatedAbove;
2877 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2879 this.showAutocalculatedAbove = showAutocalculatedAbove;
2883 public boolean isScaleProteinAsCdna()
2885 return viewStyle.isScaleProteinAsCdna();
2889 public void setScaleProteinAsCdna(boolean b)
2891 viewStyle.setScaleProteinAsCdna(b);
2895 public boolean isProteinFontAsCdna()
2897 return viewStyle.isProteinFontAsCdna();
2901 public void setProteinFontAsCdna(boolean b)
2903 viewStyle.setProteinFontAsCdna(b);
2907 * @return true if view should scroll to show the highlighted region of a
2912 public final boolean isFollowHighlight()
2914 return followHighlight;
2918 public final void setFollowHighlight(boolean b)
2920 this.followHighlight = b;
2924 public ViewportRanges getRanges()
2930 * Helper method to populate the SearchResults with the location in the
2931 * complementary alignment to scroll to, in order to match this one.
2934 * the SearchResults to add to
2935 * @return the offset (below top of visible region) of the matched sequence
2937 protected int findComplementScrollTarget(SearchResultsI sr)
2939 final AlignViewportI complement = getCodingComplement();
2940 if (complement == null || !complement.isFollowHighlight())
2944 boolean iAmProtein = !getAlignment().isNucleotide();
2945 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2946 : complement.getAlignment();
2947 if (proteinAlignment == null)
2951 final List<AlignedCodonFrame> mappings = proteinAlignment
2955 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2956 * residue in the middle column of the visible region. Scroll the
2957 * complementary alignment to line up the corresponding residue.
2960 SequenceI sequence = null;
2963 * locate 'middle' column (true middle if an odd number visible, left of
2964 * middle if an even number visible)
2966 int middleColumn = ranges.getStartRes()
2967 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2968 final HiddenSequences hiddenSequences = getAlignment()
2969 .getHiddenSequences();
2972 * searching to the bottom of the alignment gives smoother scrolling across
2973 * all gapped visible regions
2975 int lastSeq = alignment.getHeight() - 1;
2976 List<AlignedCodonFrame> seqMappings = null;
2977 for (int seqNo = ranges
2978 .getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2980 sequence = getAlignment().getSequenceAt(seqNo);
2981 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2985 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2989 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2991 getCodingComplement().getAlignment().getSequences());
2992 if (!seqMappings.isEmpty())
2998 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
3001 * No ungapped mapped sequence in middle column - do nothing
3005 MappingUtils.addSearchResults(sr, sequence,
3006 sequence.findPosition(middleColumn), seqMappings);
3011 * synthesize a column selection if none exists so it covers the given
3012 * selection group. if wholewidth is false, no column selection is made if the
3013 * selection group covers the whole alignment width.
3018 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
3021 if (sg != null && (sgs = sg.getStartRes()) >= 0
3022 && sg.getStartRes() <= (sge = sg.getEndRes())
3023 && !this.hasSelectedColumns())
3025 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
3032 colSel = new ColumnSelection();
3034 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
3036 colSel.addElement(cspos);
3042 * hold status of current selection group - defined on alignment or not.
3044 private boolean selectionIsDefinedGroup = false;
3047 public boolean isSelectionDefinedGroup()
3049 if (selectionGroup == null)
3053 if (isSelectionGroupChanged(true))
3055 selectionIsDefinedGroup = false;
3056 List<SequenceGroup> gps = alignment.getGroups();
3057 if (gps == null || gps.size() == 0)
3059 selectionIsDefinedGroup = false;
3063 selectionIsDefinedGroup = gps.contains(selectionGroup);
3066 return selectionGroup.isDefined() || selectionIsDefinedGroup;
3070 * null, or currently highlighted results on this view
3072 private SearchResultsI searchResults = null;
3074 protected TreeModel currentTree = null;
3077 public boolean hasSearchResults()
3079 return searchResults != null;
3083 public void setSearchResults(SearchResultsI results)
3085 searchResults = results;
3089 public SearchResultsI getSearchResults()
3091 return searchResults;
3095 * get the consensus sequence as displayed under the PID consensus annotation
3098 * @return consensus sequence as a new sequence object
3100 public SequenceI getConsensusSeq()
3102 if (consensus == null)
3104 updateConsensus(null);
3106 if (consensus == null)
3110 StringBuffer seqs = new StringBuffer();
3111 for (int i = 0; i < consensus.annotations.length; i++)
3113 Annotation annotation = consensus.annotations[i];
3114 if (annotation != null)
3116 String description = annotation.description;
3117 if (description != null && description.startsWith("["))
3119 // consensus is a tie - just pick the first one
3120 seqs.append(description.charAt(1));
3124 seqs.append(annotation.displayCharacter);
3129 SequenceI sq = new Sequence("Consensus", seqs.toString());
3130 sq.setDescription("Percentage Identity Consensus "
3131 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3135 public boolean hasReferenceAnnotation()
3137 AlignmentAnnotation[] annots = this.alignment.getAlignmentAnnotation();
3138 for (AlignmentAnnotation annot : annots)
3140 if ("RF".equals(annot.label) || annot.label.contains("Reference"))
3149 public void setCurrentTree(TreeModel tree)
3155 public TreeModel getCurrentTree()