2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.viewmodel;
23 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
24 import jalview.analysis.Conservation;
25 import jalview.api.AlignCalcManagerI;
26 import jalview.api.AlignViewportI;
27 import jalview.api.AlignmentViewPanel;
28 import jalview.api.FeaturesDisplayedI;
29 import jalview.api.ViewStyleI;
30 import jalview.commands.CommandI;
31 import jalview.datamodel.AlignedCodonFrame;
32 import jalview.datamodel.AlignmentAnnotation;
33 import jalview.datamodel.AlignmentI;
34 import jalview.datamodel.AlignmentView;
35 import jalview.datamodel.Annotation;
36 import jalview.datamodel.CigarArray;
37 import jalview.datamodel.ColumnSelection;
38 import jalview.datamodel.HiddenColumns;
39 import jalview.datamodel.HiddenSequences;
40 import jalview.datamodel.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 final 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);
416 * @see jalview.api.ViewStyleI#setShowText(boolean)
419 public void setShowText(boolean state)
421 viewStyle.setShowText(state);
426 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
429 public void setRenderGaps(boolean state)
431 viewStyle.setRenderGaps(state);
436 * @see jalview.api.ViewStyleI#getColourText()
439 public boolean getColourText()
441 return viewStyle.getColourText();
446 * @see jalview.api.ViewStyleI#setColourText(boolean)
449 public void setColourText(boolean state)
451 viewStyle.setColourText(state);
456 * @see jalview.api.ViewStyleI#getWrapAlignment()
459 public boolean getWrapAlignment()
461 return viewStyle.getWrapAlignment();
466 * @see jalview.api.ViewStyleI#getShowText()
469 public boolean getShowText()
471 return viewStyle.getShowText();
476 * @see jalview.api.ViewStyleI#getWrappedWidth()
479 public int getWrappedWidth()
481 return viewStyle.getWrappedWidth();
486 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
489 public void setWrappedWidth(int w)
491 viewStyle.setWrappedWidth(w);
496 * @see jalview.api.ViewStyleI#getCharHeight()
499 public int getCharHeight()
501 return viewStyle.getCharHeight();
506 * @see jalview.api.ViewStyleI#setCharHeight(int)
509 public void setCharHeight(int h)
511 viewStyle.setCharHeight(h);
516 * @see jalview.api.ViewStyleI#getCharWidth()
519 public int getCharWidth()
521 return viewStyle.getCharWidth();
526 * @see jalview.api.ViewStyleI#setCharWidth(int)
529 public void setCharWidth(int w)
531 viewStyle.setCharWidth(w);
536 * @see jalview.api.ViewStyleI#getShowBoxes()
539 public boolean getShowBoxes()
541 return viewStyle.getShowBoxes();
546 * @see jalview.api.ViewStyleI#getShowUnconserved()
549 public boolean getShowUnconserved()
551 return viewStyle.getShowUnconserved();
555 * @param showunconserved
556 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
559 public void setShowUnconserved(boolean showunconserved)
561 viewStyle.setShowUnconserved(showunconserved);
566 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
569 public void setSeqNameItalics(boolean default1)
571 viewStyle.setSeqNameItalics(default1);
575 public AlignmentI getAlignment()
581 public char getGapCharacter()
583 return alignment.getGapCharacter();
586 protected String sequenceSetID;
589 * probably unused indicator that view is of a dataset rather than an
592 protected boolean isDataset = false;
594 public void setDataset(boolean b)
599 public boolean isDataset()
604 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
606 protected ColumnSelection colSel = new ColumnSelection();
608 public boolean autoCalculateConsensus = true;
610 public boolean autoCalculateInformation = true;
612 protected boolean autoCalculateStrucConsensus = true;
614 protected boolean ignoreGapsInConsensusCalculation = false;
616 protected boolean ignoreBelowBackGroundFrequencyCalculation = false;
618 protected ResidueShaderI residueShading = new ResidueShader();
621 public void setGlobalColourScheme(ColourSchemeI cs)
623 // TODO: logic refactored from AlignFrame changeColour -
624 // TODO: autorecalc stuff should be changed to rely on the worker system
625 // check to see if we should implement a changeColour(cs) method rather than
626 // put the logic in here
627 // - means that caller decides if they want to just modify state and defer
628 // calculation till later or to do all calculations in thread.
632 * only instantiate alignment colouring once, thereafter update it;
633 * this means that any conservation or PID threshold settings
634 * persist when the alignment colour scheme is changed
636 if (residueShading == null)
638 residueShading = new ResidueShader(viewStyle);
640 residueShading.setColourScheme(cs);
642 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
643 // ...problem: groups need these, but do not currently have a ViewStyle
647 if (getConservationSelected())
649 residueShading.setConservation(hconservation);
651 residueShading.alignmentChanged(alignment, hiddenRepSequences);
655 * if 'apply colour to all groups' is selected... do so
656 * (but don't transfer any colour threshold settings to groups)
658 if (getColourAppliesToAllGroups())
660 for (SequenceGroup sg : getAlignment().getGroups())
663 * retain any colour thresholds per group while
664 * changing choice of colour scheme (JAL-2386)
666 sg.setColourScheme(cs);
669 sg.getGroupColourScheme().alignmentChanged(sg,
677 public ColourSchemeI getGlobalColourScheme()
679 return residueShading == null ? null : residueShading.getColourScheme();
683 public ResidueShaderI getResidueShading()
685 return residueShading;
688 protected AlignmentAnnotation consensus;
690 protected AlignmentAnnotation complementConsensus;
692 protected AlignmentAnnotation gapcounts;
694 protected AlignmentAnnotation strucConsensus;
696 protected AlignmentAnnotation conservation;
698 protected AlignmentAnnotation quality;
700 protected AlignmentAnnotation[] groupConsensus;
702 protected AlignmentAnnotation[] groupConservation;
704 protected List<AlignmentAnnotation> groupInformation = new ArrayList<>();
706 protected List<AlignmentAnnotation> information = new ArrayList<>();
709 * results of alignment consensus analysis for visible portion of view
711 protected ProfilesI hconsensus = null;
714 * results of information annotation analysis for the visible portion of view
716 protected List<ProfilesI> hinformation = new ArrayList<>();
719 * results of cDNA complement consensus visible portion of view
721 protected Hashtable[] hcomplementConsensus = null;
724 * results of secondary structure base pair consensus for visible portion of
727 protected Hashtable[] hStrucConsensus = null;
729 protected Conservation hconservation = null;
732 public void setConservation(Conservation cons)
734 hconservation = cons;
738 * percentage gaps allowed in a column before all amino acid properties should
739 * be considered unconserved
741 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
744 public int getConsPercGaps()
750 public void setSequenceConsensusHash(ProfilesI hconsensus)
752 this.hconsensus = hconsensus;
756 public void setComplementConsensusHash(Hashtable[] hconsensus)
758 this.hcomplementConsensus = hconsensus;
762 public ProfilesI getSequenceConsensusHash()
768 public void setSequenceInformationHashes(List<ProfilesI> info)
774 public void setSequenceInformationHash(ProfilesI info, int index)
776 hinformation.set(index, info);
780 public List<ProfilesI> getSequenceInformationHashes()
786 public ProfilesI getSequenceInformationHash(int index)
788 return hinformation.get(index);
792 public Hashtable[] getComplementConsensusHash()
794 return hcomplementConsensus;
798 public Hashtable[] getRnaStructureConsensusHash()
800 return hStrucConsensus;
804 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
806 this.hStrucConsensus = hStrucConsensus;
811 public AlignmentAnnotation getAlignmentQualityAnnot()
817 public AlignmentAnnotation getAlignmentConservationAnnotation()
823 public AlignmentAnnotation getAlignmentConsensusAnnotation()
829 public List<AlignmentAnnotation> getInformationAnnotations()
835 public AlignmentAnnotation getInformationAnnotation(int index)
837 return information.get(index);
841 public AlignmentAnnotation getAlignmentGapAnnotation()
847 public AlignmentAnnotation getComplementConsensusAnnotation()
849 return complementConsensus;
853 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
855 return strucConsensus;
858 protected AlignCalcManagerI calculator = new AlignCalcManager();
861 * trigger update of conservation annotation
863 public void updateConservation(final AlignmentViewPanel ap)
865 // see note in mantis : issue number 8585
866 if (alignment.isNucleotide()
867 || (conservation == null && quality == null)
868 || !autoCalculateConsensus)
872 if (calculator.getRegisteredWorkersOfClass(
873 jalview.workers.ConservationThread.class) == null)
875 calculator.registerWorker(
876 new jalview.workers.ConservationThread(this, ap));
881 * trigger update of consensus annotation
883 public void updateConsensus(final AlignmentViewPanel ap)
885 // see note in mantis : issue number 8585
886 if (consensus == null || !autoCalculateConsensus)
891 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
893 calculator.registerWorker(new ConsensusThread(this, ap));
897 * A separate thread to compute cDNA consensus for a protein alignment
898 * which has mapping to cDNA
900 final AlignmentI al = this.getAlignment();
901 if (!al.isNucleotide() && al.getCodonFrames() != null
902 && !al.getCodonFrames().isEmpty())
905 * fudge - check first for protein-to-nucleotide mappings
906 * (we don't want to do this for protein-to-protein)
908 boolean doConsensus = false;
909 for (AlignedCodonFrame mapping : al.getCodonFrames())
911 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
912 MapList[] mapLists = mapping.getdnaToProt();
913 // mapLists can be empty if project load has not finished resolving seqs
914 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
922 if (calculator.getRegisteredWorkersOfClass(
923 ComplementConsensusThread.class) == null)
926 .registerWorker(new ComplementConsensusThread(this, ap));
933 * trigger update of information annotation
936 public void updateInformation(final AlignmentViewPanel ap)
939 .getRegisteredWorkersOfClass(InformationThread.class) == null)
941 calculator.registerWorker(new InformationThread(this, ap));
946 // --------START Structure Conservation
947 public void updateStrucConsensus(final AlignmentViewPanel ap)
949 if (autoCalculateStrucConsensus && strucConsensus == null
950 && alignment.isNucleotide() && alignment.hasRNAStructure())
952 // secondary structure has been added - so init the consensus line
956 // see note in mantis : issue number 8585
957 if (strucConsensus == null || !autoCalculateStrucConsensus)
961 if (calculator.getRegisteredWorkersOfClass(
962 StrucConsensusThread.class) == null)
964 calculator.registerWorker(new StrucConsensusThread(this, ap));
968 public boolean isCalcInProgress()
970 return calculator.isWorking();
974 public boolean isCalculationInProgress(
975 AlignmentAnnotation alignmentAnnotation)
977 if (!alignmentAnnotation.autoCalculated)
981 if (calculator.workingInvolvedWith(alignmentAnnotation))
983 // System.err.println("grey out ("+alignmentAnnotation.label+")");
989 public void setAlignment(AlignmentI align)
991 this.alignment = align;
995 * Clean up references when this viewport is closed
998 public void dispose()
1001 * defensively null out references to large objects in case
1002 * this object is not garbage collected (as if!)
1005 complementConsensus = null;
1006 strucConsensus = null;
1007 conservation = null;
1009 groupConsensus = null;
1010 groupConservation = null;
1012 hcomplementConsensus = null;
1013 // colour scheme may hold reference to consensus
1014 residueShading = null;
1015 // TODO remove listeners from changeSupport?
1016 changeSupport = null;
1021 public boolean isClosed()
1023 // TODO: check that this isClosed is only true after panel is closed, not
1024 // before it is fully constructed.
1025 return alignment == null;
1029 public AlignCalcManagerI getCalcManager()
1035 * should conservation rows be shown for groups
1037 protected boolean showGroupConservation = false;
1040 * should consensus rows be shown for groups
1042 protected boolean showGroupConsensus = false;
1045 * should consensus profile be rendered by default
1047 protected boolean showSequenceLogo = false;
1050 * should consensus profile be rendered normalised to row height
1052 protected boolean normaliseSequenceLogo = false;
1055 * should consensus histograms be rendered by default
1057 protected boolean showConsensusHistogram = true;
1060 * should hmm profile be rendered by default
1062 protected boolean showHMMSequenceLogo = false;
1065 * should hmm profile be rendered normalised to row height
1067 protected boolean normaliseHMMSequenceLogo = false;
1070 * should information histograms be rendered by default
1072 protected boolean showInformationHistogram = true;
1075 * @return the showConsensusProfile
1078 public boolean isShowSequenceLogo()
1080 return showSequenceLogo;
1084 * @return the showInformationProfile
1087 public boolean isShowHMMSequenceLogo()
1089 return showHMMSequenceLogo;
1093 * @param showSequenceLogo
1096 public void setShowSequenceLogo(boolean showSequenceLogo)
1098 if (showSequenceLogo != this.showSequenceLogo)
1100 // TODO: decouple settings setting from calculation when refactoring
1101 // annotation update method from alignframe to viewport
1102 this.showSequenceLogo = showSequenceLogo;
1103 calculator.updateAnnotationFor(ConsensusThread.class);
1104 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1105 calculator.updateAnnotationFor(StrucConsensusThread.class);
1107 this.showSequenceLogo = showSequenceLogo;
1110 public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo)
1112 if (showHMMSequenceLogo != this.showHMMSequenceLogo)
1114 this.showHMMSequenceLogo = showHMMSequenceLogo;
1115 calculator.updateAnnotationFor(InformationThread.class);
1117 this.showHMMSequenceLogo = showHMMSequenceLogo;
1121 * @param showConsensusHistogram
1122 * the showConsensusHistogram to set
1124 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1126 this.showConsensusHistogram = showConsensusHistogram;
1130 * @param showInformationHistogram
1131 * the showInformationHistogram to set
1133 public void setShowInformationHistogram(boolean showInformationHistogram)
1135 this.showInformationHistogram = showInformationHistogram;
1139 * @return the showGroupConservation
1141 public boolean isShowGroupConservation()
1143 return showGroupConservation;
1147 * @param showGroupConservation
1148 * the showGroupConservation to set
1150 public void setShowGroupConservation(boolean showGroupConservation)
1152 this.showGroupConservation = showGroupConservation;
1156 * @return the showGroupConsensus
1158 public boolean isShowGroupConsensus()
1160 return showGroupConsensus;
1164 * @param showGroupConsensus
1165 * the showGroupConsensus to set
1167 public void setShowGroupConsensus(boolean showGroupConsensus)
1169 this.showGroupConsensus = showGroupConsensus;
1174 * @return flag to indicate if the consensus histogram should be rendered by
1178 public boolean isShowConsensusHistogram()
1180 return this.showConsensusHistogram;
1185 * @return flag to indicate if the information content histogram should be
1186 * rendered by default
1189 public boolean isShowInformationHistogram()
1191 return this.showInformationHistogram;
1195 * when set, updateAlignment will always ensure sequences are of equal length
1197 private boolean padGaps = false;
1200 * when set, alignment should be reordered according to a newly opened tree
1202 public boolean sortByTree = false;
1207 * @return null or the currently selected sequence region
1210 public SequenceGroup getSelectionGroup()
1212 return selectionGroup;
1216 * Set the selection group for this window. Also sets the current alignment as
1217 * the context for the group, if it does not already have one.
1220 * - group holding references to sequences in this alignment view
1224 public void setSelectionGroup(SequenceGroup sg)
1226 selectionGroup = sg;
1227 if (sg != null && sg.getContext() == null)
1229 sg.setContext(alignment);
1233 public void setHiddenColumns(HiddenColumns hidden)
1235 this.alignment.setHiddenColumns(hidden);
1239 public ColumnSelection getColumnSelection()
1245 public void setColumnSelection(ColumnSelection colSel)
1247 this.colSel = colSel;
1250 updateHiddenColumns();
1252 isColSelChanged(true);
1260 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1262 return hiddenRepSequences;
1266 public void setHiddenRepSequences(
1267 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1269 this.hiddenRepSequences = hiddenRepSequences;
1273 public boolean hasSelectedColumns()
1275 ColumnSelection columnSelection = getColumnSelection();
1276 return columnSelection != null && columnSelection.hasSelectedColumns();
1280 public boolean hasHiddenColumns()
1282 return colSel != null
1283 && alignment.getHiddenColumns().hasHiddenColumns();
1286 public void updateHiddenColumns()
1288 // this method doesn't really do anything now. But - it could, since a
1289 // column Selection could be in the process of modification
1290 // hasHiddenColumns = colSel.hasHiddenColumns();
1294 public boolean hasHiddenRows()
1296 return alignment.getHiddenSequences().getSize() > 0;
1299 protected SequenceGroup selectionGroup;
1301 public void setSequenceSetId(String newid)
1303 if (sequenceSetID != null)
1306 "Warning - overwriting a sequenceSetId for a viewport!");
1308 sequenceSetID = new String(newid);
1312 public String getSequenceSetId()
1314 if (sequenceSetID == null)
1316 sequenceSetID = alignment.hashCode() + "";
1319 return sequenceSetID;
1323 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1326 protected String viewId = null;
1329 public String getViewId()
1333 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1338 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1340 ignoreGapsInConsensusCalculation = b;
1343 updateConsensus(ap);
1344 if (residueShading != null)
1346 residueShading.setThreshold(residueShading.getThreshold(),
1347 ignoreGapsInConsensusCalculation);
1353 public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap)
1355 ignoreBelowBackGroundFrequencyCalculation = b;
1358 updateInformation(ap);
1363 private long sgrouphash = -1, colselhash = -1;
1366 * checks current SelectionGroup against record of last hash value, and
1370 * update the record of last hash value
1372 * @return true if SelectionGroup changed since last call (when b is true)
1374 public boolean isSelectionGroupChanged(boolean b)
1376 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1377 : selectionGroup.hashCode();
1378 if (hc != -1 && hc != sgrouphash)
1390 * checks current colsel against record of last hash value, and optionally
1394 * update the record of last hash value
1395 * @return true if colsel changed since last call (when b is true)
1397 public boolean isColSelChanged(boolean b)
1399 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1400 if (hc != -1 && hc != colselhash)
1412 public boolean isIgnoreGapsConsensus()
1414 return ignoreGapsInConsensusCalculation;
1418 public boolean isIgnoreBelowBackground()
1420 return ignoreBelowBackGroundFrequencyCalculation;
1423 // property change stuff
1424 // JBPNote Prolly only need this in the applet version.
1425 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1428 protected boolean showConservation = true;
1430 protected boolean showQuality = true;
1432 protected boolean showConsensus = true;
1434 protected boolean showOccupancy = true;
1436 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1438 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1440 protected boolean showAutocalculatedAbove;
1443 * when set, view will scroll to show the highlighted position
1445 private boolean followHighlight = true;
1448 * Property change listener for changes in alignment
1453 public void addPropertyChangeListener(
1454 java.beans.PropertyChangeListener listener)
1456 changeSupport.addPropertyChangeListener(listener);
1465 public void removePropertyChangeListener(
1466 java.beans.PropertyChangeListener listener)
1468 changeSupport.removePropertyChangeListener(listener);
1472 * Property change listener for changes in alignment
1481 public void firePropertyChange(String prop, Object oldvalue,
1484 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1487 // common hide/show column stuff
1489 public void hideSelectedColumns()
1491 if (colSel.isEmpty())
1496 colSel.hideSelectedColumns(alignment);
1497 setSelectionGroup(null);
1498 isColSelChanged(true);
1501 public void hideColumns(int start, int end)
1505 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1509 alignment.getHiddenColumns().hideColumns(start, end);
1511 isColSelChanged(true);
1514 public void showColumn(int col)
1516 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1517 isColSelChanged(true);
1520 public void showAllHiddenColumns()
1522 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1523 isColSelChanged(true);
1526 // common hide/show seq stuff
1527 public void showAllHiddenSeqs()
1529 if (alignment.getHiddenSequences().getSize() > 0)
1531 if (selectionGroup == null)
1533 selectionGroup = new SequenceGroup();
1534 selectionGroup.setEndRes(alignment.getWidth() - 1);
1536 List<SequenceI> tmp = alignment.getHiddenSequences()
1537 .showAll(hiddenRepSequences);
1538 for (SequenceI seq : tmp)
1540 selectionGroup.addSequence(seq, false);
1541 setSequenceAnnotationsVisible(seq, true);
1544 hiddenRepSequences = null;
1546 firePropertyChange("alignment", null, alignment.getSequences());
1547 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1553 public void showSequence(int index)
1555 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1556 hiddenRepSequences);
1559 if (selectionGroup == null)
1561 selectionGroup = new SequenceGroup();
1562 selectionGroup.setEndRes(alignment.getWidth() - 1);
1565 for (SequenceI seq : tmp)
1567 selectionGroup.addSequence(seq, false);
1568 setSequenceAnnotationsVisible(seq, true);
1570 firePropertyChange("alignment", null, alignment.getSequences());
1575 public void hideAllSelectedSeqs()
1577 if (selectionGroup == null || selectionGroup.getSize() < 1)
1582 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1586 setSelectionGroup(null);
1589 public void hideSequence(SequenceI[] seq)
1593 for (int i = 0; i < seq.length; i++)
1595 alignment.getHiddenSequences().hideSequence(seq[i]);
1596 setSequenceAnnotationsVisible(seq[i], false);
1598 firePropertyChange("alignment", null, alignment.getSequences());
1603 * Hides the specified sequence, or the sequences it represents
1606 * the sequence to hide, or keep as representative
1607 * @param representGroup
1608 * if true, hide the current selection group except for the
1609 * representative sequence
1611 public void hideSequences(SequenceI sequence, boolean representGroup)
1613 if (selectionGroup == null || selectionGroup.getSize() < 1)
1615 hideSequence(new SequenceI[] { sequence });
1621 hideRepSequences(sequence, selectionGroup);
1622 setSelectionGroup(null);
1626 int gsize = selectionGroup.getSize();
1627 SequenceI[] hseqs = selectionGroup.getSequences()
1628 .toArray(new SequenceI[gsize]);
1630 hideSequence(hseqs);
1631 setSelectionGroup(null);
1636 * Set visibility for any annotations for the given sequence.
1640 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1643 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1646 for (AlignmentAnnotation ann : anns)
1648 if (ann.sequenceRef == sequenceI)
1650 ann.visible = visible;
1656 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1658 int sSize = sg.getSize();
1664 if (hiddenRepSequences == null)
1666 hiddenRepSequences = new Hashtable<>();
1669 hiddenRepSequences.put(repSequence, sg);
1671 // Hide all sequences except the repSequence
1672 SequenceI[] seqs = new SequenceI[sSize - 1];
1674 for (int i = 0; i < sSize; i++)
1676 if (sg.getSequenceAt(i) != repSequence)
1678 if (index == sSize - 1)
1683 seqs[index++] = sg.getSequenceAt(i);
1686 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1687 sg.setHidereps(true); // note: not done in 2.7applet
1694 * @return null or the current reference sequence
1696 public SequenceI getReferenceSeq()
1698 return alignment.getSeqrep();
1703 * @return true iff seq is the reference for the alignment
1705 public boolean isReferenceSeq(SequenceI seq)
1707 return alignment.getSeqrep() == seq;
1713 * @return true if there are sequences represented by this sequence that are
1716 public boolean isHiddenRepSequence(SequenceI seq)
1718 return (hiddenRepSequences != null
1719 && hiddenRepSequences.containsKey(seq));
1725 * @return null or a sequence group containing the sequences that seq
1728 public SequenceGroup getRepresentedSequences(SequenceI seq)
1730 return (SequenceGroup) (hiddenRepSequences == null ? null
1731 : hiddenRepSequences.get(seq));
1735 public int adjustForHiddenSeqs(int alignmentIndex)
1737 return alignment.getHiddenSequences()
1738 .adjustForHiddenSeqs(alignmentIndex);
1742 public void invertColumnSelection()
1744 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1748 public SequenceI[] getSelectionAsNewSequence()
1750 SequenceI[] sequences;
1751 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1752 // this was the only caller in the applet for this method
1753 // JBPNote: in applet, this method returned references to the alignment
1754 // sequences, and it did not honour the presence/absence of annotation
1755 // attached to the alignment (probably!)
1756 if (selectionGroup == null || selectionGroup.getSize() == 0)
1758 sequences = alignment.getSequencesArray();
1759 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1760 for (int i = 0; i < sequences.length; i++)
1762 // construct new sequence with subset of visible annotation
1763 sequences[i] = new Sequence(sequences[i], annots);
1768 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1775 public SequenceI[] getSequenceSelection()
1777 SequenceI[] sequences = null;
1778 if (selectionGroup != null)
1780 sequences = selectionGroup.getSequencesInOrder(alignment);
1782 if (sequences == null)
1784 sequences = alignment.getSequencesArray();
1790 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1792 return new CigarArray(alignment, alignment.getHiddenColumns(),
1793 (selectedRegionOnly ? selectionGroup : null));
1797 public jalview.datamodel.AlignmentView getAlignmentView(
1798 boolean selectedOnly)
1800 return getAlignmentView(selectedOnly, false);
1804 public jalview.datamodel.AlignmentView getAlignmentView(
1805 boolean selectedOnly, boolean markGroups)
1807 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1808 selectionGroup, alignment.getHiddenColumns() != null
1809 && alignment.getHiddenColumns().hasHiddenColumns(),
1810 selectedOnly, markGroups);
1814 public String[] getViewAsString(boolean selectedRegionOnly)
1816 return getViewAsString(selectedRegionOnly, true);
1820 public String[] getViewAsString(boolean selectedRegionOnly,
1821 boolean exportHiddenSeqs)
1823 String[] selection = null;
1824 SequenceI[] seqs = null;
1826 int start = 0, end = 0;
1827 if (selectedRegionOnly && selectionGroup != null)
1829 iSize = selectionGroup.getSize();
1830 seqs = selectionGroup.getSequencesInOrder(alignment);
1831 start = selectionGroup.getStartRes();
1832 end = selectionGroup.getEndRes() + 1;
1836 if (hasHiddenRows() && exportHiddenSeqs)
1838 AlignmentI fullAlignment = alignment.getHiddenSequences()
1839 .getFullAlignment();
1840 iSize = fullAlignment.getHeight();
1841 seqs = fullAlignment.getSequencesArray();
1842 end = fullAlignment.getWidth();
1846 iSize = alignment.getHeight();
1847 seqs = alignment.getSequencesArray();
1848 end = alignment.getWidth();
1852 selection = new String[iSize];
1853 if (alignment.getHiddenColumns() != null
1854 && alignment.getHiddenColumns().hasHiddenColumns())
1856 selection = alignment.getHiddenColumns()
1857 .getVisibleSequenceStrings(start, end, seqs);
1861 for (i = 0; i < iSize; i++)
1863 selection[i] = seqs[i].getSequenceAsString(start, end);
1871 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1873 ArrayList<int[]> regions = new ArrayList<>();
1879 HiddenColumns hidden = alignment.getHiddenColumns();
1880 if (hidden != null && hidden.hasHiddenColumns())
1884 start = hidden.adjustForHiddenColumns(start);
1887 end = hidden.getHiddenBoundaryRight(start);
1898 regions.add(new int[] { start, end });
1900 if (hidden != null && hidden.hasHiddenColumns())
1902 start = hidden.adjustForHiddenColumns(end);
1903 start = hidden.getHiddenBoundaryLeft(start) + 1;
1905 } while (end < max);
1907 int[][] startEnd = new int[regions.size()][2];
1913 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1914 boolean selectedOnly)
1916 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1917 AlignmentAnnotation[] aa;
1918 if ((aa = alignment.getAlignmentAnnotation()) != null)
1920 for (AlignmentAnnotation annot : aa)
1922 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1923 if (selectedOnly && selectionGroup != null)
1925 alignment.getHiddenColumns().makeVisibleAnnotation(
1926 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1931 alignment.getHiddenColumns().makeVisibleAnnotation(clone);
1940 public boolean isPadGaps()
1946 public void setPadGaps(boolean padGaps)
1948 this.padGaps = padGaps;
1952 * apply any post-edit constraints and trigger any calculations needed after
1953 * an edit has been performed on the alignment
1958 public void alignmentChanged(AlignmentViewPanel ap)
1962 alignment.padGaps();
1964 if (autoCalculateConsensus)
1966 updateConsensus(ap);
1968 if (hconsensus != null && autoCalculateConsensus)
1970 updateConservation(ap);
1972 if (autoCalculateStrucConsensus)
1974 updateStrucConsensus(ap);
1976 updateInformation(ap);
1978 List<SequenceI> hmmSequences;
1979 hmmSequences = alignment.getHMMConsensusSequences(false);
1981 for (SequenceI seq : hmmSequences)
1983 seq.updateHMMMapping();
1986 // Reset endRes of groups if beyond alignment width
1987 int alWidth = alignment.getWidth();
1988 List<SequenceGroup> groups = alignment.getGroups();
1991 for (SequenceGroup sg : groups)
1993 if (sg.getEndRes() > alWidth)
1995 sg.setEndRes(alWidth - 1);
2000 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
2002 selectionGroup.setEndRes(alWidth - 1);
2005 updateAllColourSchemes();
2006 calculator.restartWorkers();
2007 // alignment.adjustSequenceAnnotations();
2011 * reset scope and do calculations for all applied colourschemes on alignment
2013 void updateAllColourSchemes()
2015 ResidueShaderI rs = residueShading;
2018 rs.alignmentChanged(alignment, hiddenRepSequences);
2020 rs.setConsensus(hconsensus);
2021 if (rs.conservationApplied())
2023 rs.setConservation(Conservation.calculateConservation("All",
2024 alignment.getSequences(), 0, alignment.getWidth(), false,
2025 getConsPercGaps(), false));
2029 for (SequenceGroup sg : alignment.getGroups())
2033 sg.cs.alignmentChanged(sg, hiddenRepSequences);
2035 sg.recalcConservation();
2039 protected void initAutoAnnotation()
2041 // TODO: add menu option action that nulls or creates consensus object
2042 // depending on if the user wants to see the annotation or not in a
2043 // specific alignment
2045 if (hconsensus == null && !isDataset)
2047 if (!alignment.isNucleotide())
2056 consensus = new AlignmentAnnotation("Consensus",
2057 MessageManager.getString("label.consensus_descr"),
2058 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2059 initConsensus(consensus);
2063 initComplementConsensus();
2068 * If this is a protein alignment and there are mappings to cDNA, adds the
2069 * cDNA consensus annotation and returns true, else returns false.
2071 public boolean initComplementConsensus()
2073 if (!alignment.isNucleotide())
2075 final List<AlignedCodonFrame> codonMappings = alignment
2077 if (codonMappings != null && !codonMappings.isEmpty())
2079 boolean doConsensus = false;
2080 for (AlignedCodonFrame mapping : codonMappings)
2082 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2083 MapList[] mapLists = mapping.getdnaToProt();
2084 // mapLists can be empty if project load has not finished resolving
2086 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2094 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2096 .getString("label.complement_consensus_descr"),
2097 new Annotation[1], 0f, 100f,
2098 AlignmentAnnotation.BAR_GRAPH);
2099 initConsensus(complementConsensus);
2107 private void initConsensus(AlignmentAnnotation aa)
2110 aa.autoCalculated = true;
2114 alignment.addAnnotation(aa);
2119 public void initInformation()
2121 for (SequenceI seq : alignment.getHMMConsensusSequences(false))
2123 if (!seq.hasHMMAnnotation())
2125 AlignmentAnnotation information;
2126 information = new AlignmentAnnotation(seq.getName(),
2127 MessageManager.getString("label.information_description"),
2128 new Annotation[1], 0f, 6.52f,
2129 AlignmentAnnotation.BAR_GRAPH);
2130 information.hasText = true;
2131 information.autoCalculated = true;
2132 information.hasText = true;
2133 information.autoCalculated = false;
2134 information.sequenceRef = seq;
2135 information.setCalcId("HMM annotation");
2136 this.information.add(information);
2137 hinformation.add(new Profiles(new ProfileI[1]));
2138 alignment.addAnnotation(information);
2139 seq.updateHMMMapping();
2140 seq.setHasInfo(true);
2141 seq.addAlignmentAnnotation(information);
2147 // these should be extracted from the view model - style and settings for
2148 // derived annotation
2149 private void initGapCounts()
2153 gapcounts = new AlignmentAnnotation("Occupancy",
2154 MessageManager.getString("label.occupancy_descr"),
2155 new Annotation[1], 0f, alignment.getHeight(),
2156 AlignmentAnnotation.BAR_GRAPH);
2157 gapcounts.hasText = true;
2158 gapcounts.autoCalculated = true;
2159 gapcounts.scaleColLabel = true;
2160 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2162 alignment.addAnnotation(gapcounts);
2166 private void initConservation()
2168 if (showConservation)
2170 if (conservation == null)
2172 conservation = new AlignmentAnnotation("Conservation",
2173 MessageManager.formatMessage("label.conservation_descr",
2175 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2176 conservation.hasText = true;
2177 conservation.autoCalculated = true;
2178 alignment.addAnnotation(conservation);
2183 private void initQuality()
2187 if (quality == null)
2189 quality = new AlignmentAnnotation("Quality",
2190 MessageManager.getString("label.quality_descr"),
2191 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2192 quality.hasText = true;
2193 quality.autoCalculated = true;
2194 alignment.addAnnotation(quality);
2199 private void initRNAStructure()
2201 if (alignment.hasRNAStructure() && strucConsensus == null)
2203 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2204 MessageManager.getString("label.strucconsensus_descr"),
2205 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2206 strucConsensus.hasText = true;
2207 strucConsensus.autoCalculated = true;
2211 alignment.addAnnotation(strucConsensus);
2219 * @see jalview.api.AlignViewportI#calcPanelHeight()
2222 public int calcPanelHeight()
2224 // setHeight of panels
2225 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2227 int charHeight = getCharHeight();
2230 BitSet graphgrp = new BitSet();
2231 for (AlignmentAnnotation aa : anns)
2235 System.err.println("Null annotation row: ignoring.");
2242 if (aa.graphGroup > -1)
2244 if (graphgrp.get(aa.graphGroup))
2250 graphgrp.set(aa.graphGroup);
2257 aa.height += charHeight;
2267 aa.height += aa.graphHeight;
2275 height += aa.height;
2287 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2288 boolean preserveNewGroupSettings)
2290 boolean updateCalcs = false;
2291 boolean conv = isShowGroupConservation();
2292 boolean cons = isShowGroupConsensus();
2293 boolean showprf = isShowSequenceLogo();
2294 boolean showConsHist = isShowConsensusHistogram();
2295 boolean normLogo = isNormaliseSequenceLogo();
2296 boolean showHMMPrf = isShowHMMSequenceLogo();
2297 boolean showInfoHist = isShowInformationHistogram();
2298 boolean normHMMLogo = isNormaliseHMMSequenceLogo();
2301 * TODO reorder the annotation rows according to group/sequence ordering on
2304 boolean sortg = true;
2306 // remove old automatic annotation
2307 // add any new annotation
2309 // intersect alignment annotation with alignment groups
2311 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2312 List<SequenceGroup> oldrfs = new ArrayList<>();
2315 for (int an = 0; an < aan.length; an++)
2317 if (aan[an].autoCalculated && aan[an].groupRef != null)
2319 oldrfs.add(aan[an].groupRef);
2320 alignment.deleteAnnotation(aan[an], false);
2324 if (alignment.getGroups() != null)
2326 for (SequenceGroup sg : alignment.getGroups())
2328 updateCalcs = false;
2329 if (applyGlobalSettings
2330 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2332 // set defaults for this group's conservation/consensus
2333 sg.setshowSequenceLogo(showprf);
2334 sg.setShowConsensusHistogram(showConsHist);
2335 sg.setNormaliseSequenceLogo(normLogo);
2336 sg.setshowHMMSequenceLogo(showHMMPrf);
2337 sg.setShowInformationHistogram(showInfoHist);
2338 sg.setNormaliseHMMSequenceLogo(normHMMLogo);
2343 alignment.addAnnotation(sg.getConservationRow(), 0);
2348 alignment.addAnnotation(sg.getConsensus(), 0);
2350 // refresh the annotation rows
2353 sg.recalcConservation();
2361 public boolean isDisplayReferenceSeq()
2363 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2367 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2369 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2373 public boolean isColourByReferenceSeq()
2375 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2379 public Color getSequenceColour(SequenceI seq)
2381 Color sqc = sequenceColours.get(seq);
2382 return (sqc == null ? Color.white : sqc);
2386 public void setSequenceColour(SequenceI seq, Color col)
2390 sequenceColours.remove(seq);
2394 sequenceColours.put(seq, col);
2399 public void updateSequenceIdColours()
2401 for (SequenceGroup sg : alignment.getGroups())
2403 if (sg.idColour != null)
2405 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2407 sequenceColours.put(s, sg.idColour);
2414 public void clearSequenceColours()
2416 sequenceColours.clear();
2420 public AlignViewportI getCodingComplement()
2422 return this.codingComplement;
2426 * Set this as the (cDna/protein) complement of the given viewport. Also
2427 * ensures the reverse relationship is set on the given viewport.
2430 public void setCodingComplement(AlignViewportI av)
2434 System.err.println("Ignoring recursive setCodingComplement request");
2438 this.codingComplement = av;
2439 // avoid infinite recursion!
2440 if (av.getCodingComplement() != this)
2442 av.setCodingComplement(this);
2448 public boolean isNucleotide()
2450 return getAlignment() == null ? false : getAlignment().isNucleotide();
2454 public FeaturesDisplayedI getFeaturesDisplayed()
2456 return featuresDisplayed;
2460 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2462 featuresDisplayed = featuresDisplayedI;
2466 public boolean areFeaturesDisplayed()
2468 return featuresDisplayed != null
2469 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2476 * features are displayed if true
2479 public void setShowSequenceFeatures(boolean b)
2481 viewStyle.setShowSequenceFeatures(b);
2485 public boolean isShowSequenceFeatures()
2487 return viewStyle.isShowSequenceFeatures();
2491 public void setShowSequenceFeaturesHeight(boolean selected)
2493 viewStyle.setShowSequenceFeaturesHeight(selected);
2497 public boolean isShowSequenceFeaturesHeight()
2499 return viewStyle.isShowSequenceFeaturesHeight();
2503 public void setShowAnnotation(boolean b)
2505 viewStyle.setShowAnnotation(b);
2509 public boolean isShowAnnotation()
2511 return viewStyle.isShowAnnotation();
2515 public boolean isRightAlignIds()
2517 return viewStyle.isRightAlignIds();
2521 public void setRightAlignIds(boolean rightAlignIds)
2523 viewStyle.setRightAlignIds(rightAlignIds);
2527 public boolean getConservationSelected()
2529 return viewStyle.getConservationSelected();
2533 public void setShowBoxes(boolean state)
2535 viewStyle.setShowBoxes(state);
2540 * @see jalview.api.ViewStyleI#getTextColour()
2543 public Color getTextColour()
2545 return viewStyle.getTextColour();
2550 * @see jalview.api.ViewStyleI#getTextColour2()
2553 public Color getTextColour2()
2555 return viewStyle.getTextColour2();
2560 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2563 public int getThresholdTextColour()
2565 return viewStyle.getThresholdTextColour();
2570 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2573 public boolean isConservationColourSelected()
2575 return viewStyle.isConservationColourSelected();
2580 * @see jalview.api.ViewStyleI#isRenderGaps()
2583 public boolean isRenderGaps()
2585 return viewStyle.isRenderGaps();
2590 * @see jalview.api.ViewStyleI#isShowColourText()
2593 public boolean isShowColourText()
2595 return viewStyle.isShowColourText();
2599 * @param conservationColourSelected
2600 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2603 public void setConservationColourSelected(
2604 boolean conservationColourSelected)
2606 viewStyle.setConservationColourSelected(conservationColourSelected);
2610 * @param showColourText
2611 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2614 public void setShowColourText(boolean showColourText)
2616 viewStyle.setShowColourText(showColourText);
2621 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2624 public void setTextColour(Color textColour)
2626 viewStyle.setTextColour(textColour);
2630 * @param thresholdTextColour
2631 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2634 public void setThresholdTextColour(int thresholdTextColour)
2636 viewStyle.setThresholdTextColour(thresholdTextColour);
2640 * @param textColour2
2641 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2644 public void setTextColour2(Color textColour2)
2646 viewStyle.setTextColour2(textColour2);
2650 public ViewStyleI getViewStyle()
2652 return new ViewStyle(viewStyle);
2656 public void setViewStyle(ViewStyleI settingsForView)
2658 viewStyle = new ViewStyle(settingsForView);
2659 if (residueShading != null)
2661 residueShading.setConservationApplied(
2662 settingsForView.isConservationColourSelected());
2667 public boolean sameStyle(ViewStyleI them)
2669 return viewStyle.sameStyle(them);
2674 * @see jalview.api.ViewStyleI#getIdWidth()
2677 public int getIdWidth()
2679 return viewStyle.getIdWidth();
2684 * @see jalview.api.ViewStyleI#setIdWidth(int)
2687 public void setIdWidth(int i)
2689 viewStyle.setIdWidth(i);
2694 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2697 public boolean isCentreColumnLabels()
2699 return viewStyle.isCentreColumnLabels();
2703 * @param centreColumnLabels
2704 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2707 public void setCentreColumnLabels(boolean centreColumnLabels)
2709 viewStyle.setCentreColumnLabels(centreColumnLabels);
2714 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2717 public void setShowDBRefs(boolean showdbrefs)
2719 viewStyle.setShowDBRefs(showdbrefs);
2724 * @see jalview.api.ViewStyleI#isShowDBRefs()
2727 public boolean isShowDBRefs()
2729 return viewStyle.isShowDBRefs();
2734 * @see jalview.api.ViewStyleI#isShowNPFeats()
2737 public boolean isShowNPFeats()
2739 return viewStyle.isShowNPFeats();
2743 * @param shownpfeats
2744 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2747 public void setShowNPFeats(boolean shownpfeats)
2749 viewStyle.setShowNPFeats(shownpfeats);
2752 public abstract StructureSelectionManager getStructureSelectionManager();
2755 * Add one command to the command history list.
2759 public void addToHistoryList(CommandI command)
2761 if (this.historyList != null)
2763 this.historyList.push(command);
2764 broadcastCommand(command, false);
2768 protected void broadcastCommand(CommandI command, boolean undo)
2770 getStructureSelectionManager().commandPerformed(command, undo,
2775 * Add one command to the command redo list.
2779 public void addToRedoList(CommandI command)
2781 if (this.redoList != null)
2783 this.redoList.push(command);
2785 broadcastCommand(command, true);
2789 * Clear the command redo list.
2791 public void clearRedoList()
2793 if (this.redoList != null)
2795 this.redoList.clear();
2799 public void setHistoryList(Deque<CommandI> list)
2801 this.historyList = list;
2804 public Deque<CommandI> getHistoryList()
2806 return this.historyList;
2809 public void setRedoList(Deque<CommandI> list)
2811 this.redoList = list;
2814 public Deque<CommandI> getRedoList()
2816 return this.redoList;
2820 public VamsasSource getVamsasSource()
2825 public SequenceAnnotationOrder getSortAnnotationsBy()
2827 return sortAnnotationsBy;
2830 public void setSortAnnotationsBy(
2831 SequenceAnnotationOrder sortAnnotationsBy)
2833 this.sortAnnotationsBy = sortAnnotationsBy;
2836 public boolean isShowAutocalculatedAbove()
2838 return showAutocalculatedAbove;
2841 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2843 this.showAutocalculatedAbove = showAutocalculatedAbove;
2847 public boolean isScaleProteinAsCdna()
2849 return viewStyle.isScaleProteinAsCdna();
2853 public void setScaleProteinAsCdna(boolean b)
2855 viewStyle.setScaleProteinAsCdna(b);
2859 public boolean isProteinFontAsCdna()
2861 return viewStyle.isProteinFontAsCdna();
2865 public void setProteinFontAsCdna(boolean b)
2867 viewStyle.setProteinFontAsCdna(b);
2871 * @return true if view should scroll to show the highlighted region of a
2876 public final boolean isFollowHighlight()
2878 return followHighlight;
2882 public final void setFollowHighlight(boolean b)
2884 this.followHighlight = b;
2888 public ViewportRanges getRanges()
2894 * Helper method to populate the SearchResults with the location in the
2895 * complementary alignment to scroll to, in order to match this one.
2898 * the SearchResults to add to
2899 * @return the offset (below top of visible region) of the matched sequence
2901 protected int findComplementScrollTarget(SearchResultsI sr)
2903 final AlignViewportI complement = getCodingComplement();
2904 if (complement == null || !complement.isFollowHighlight())
2908 boolean iAmProtein = !getAlignment().isNucleotide();
2909 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2910 : complement.getAlignment();
2911 if (proteinAlignment == null)
2915 final List<AlignedCodonFrame> mappings = proteinAlignment
2919 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2920 * residue in the middle column of the visible region. Scroll the
2921 * complementary alignment to line up the corresponding residue.
2924 SequenceI sequence = null;
2927 * locate 'middle' column (true middle if an odd number visible, left of
2928 * middle if an even number visible)
2930 int middleColumn = ranges.getStartRes()
2931 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2932 final HiddenSequences hiddenSequences = getAlignment()
2933 .getHiddenSequences();
2936 * searching to the bottom of the alignment gives smoother scrolling across
2937 * all gapped visible regions
2939 int lastSeq = alignment.getHeight() - 1;
2940 List<AlignedCodonFrame> seqMappings = null;
2941 for (int seqNo = ranges
2942 .getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2944 sequence = getAlignment().getSequenceAt(seqNo);
2945 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2949 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2953 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2955 getCodingComplement().getAlignment().getSequences());
2956 if (!seqMappings.isEmpty())
2962 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2965 * No ungapped mapped sequence in middle column - do nothing
2969 MappingUtils.addSearchResults(sr, sequence,
2970 sequence.findPosition(middleColumn), seqMappings);
2975 * synthesize a column selection if none exists so it covers the given
2976 * selection group. if wholewidth is false, no column selection is made if the
2977 * selection group covers the whole alignment width.
2982 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2985 if (sg != null && (sgs = sg.getStartRes()) >= 0
2986 && sg.getStartRes() <= (sge = sg.getEndRes())
2987 && !this.hasSelectedColumns())
2989 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2996 colSel = new ColumnSelection();
2998 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
3000 colSel.addElement(cspos);
3006 * hold status of current selection group - defined on alignment or not.
3008 private boolean selectionIsDefinedGroup = false;
3011 public boolean isSelectionDefinedGroup()
3013 if (selectionGroup == null)
3017 if (isSelectionGroupChanged(true))
3019 selectionIsDefinedGroup = false;
3020 List<SequenceGroup> gps = alignment.getGroups();
3021 if (gps == null || gps.size() == 0)
3023 selectionIsDefinedGroup = false;
3027 selectionIsDefinedGroup = gps.contains(selectionGroup);
3030 return selectionGroup.isDefined() || selectionIsDefinedGroup;
3034 * null, or currently highlighted results on this view
3036 private SearchResultsI searchResults = null;
3039 public boolean hasSearchResults()
3041 return searchResults != null;
3045 public void setSearchResults(SearchResultsI results)
3047 searchResults = results;
3051 public SearchResultsI getSearchResults()
3053 return searchResults;