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 implements AlignViewportI,
84 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);
577 public AlignmentI getAlignment()
583 public char getGapCharacter()
585 return alignment.getGapCharacter();
588 protected String sequenceSetID;
591 * probably unused indicator that view is of a dataset rather than an
594 protected boolean isDataset = false;
596 public void setDataset(boolean b)
601 public boolean isDataset()
606 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
608 protected ColumnSelection colSel = new ColumnSelection();
610 public boolean autoCalculateConsensus = true;
612 public boolean autoCalculateInformation = true;
614 protected boolean autoCalculateStrucConsensus = true;
616 protected boolean ignoreGapsInConsensusCalculation = false;
618 protected boolean ignoreBelowBackGroundFrequencyCalculation = false;
620 protected ResidueShaderI residueShading = new ResidueShader();
623 public void setGlobalColourScheme(ColourSchemeI cs)
625 // TODO: logic refactored from AlignFrame changeColour -
626 // TODO: autorecalc stuff should be changed to rely on the worker system
627 // check to see if we should implement a changeColour(cs) method rather than
628 // put the logic in here
629 // - means that caller decides if they want to just modify state and defer
630 // calculation till later or to do all calculations in thread.
634 * only instantiate alignment colouring once, thereafter update it;
635 * this means that any conservation or PID threshold settings
636 * persist when the alignment colour scheme is changed
638 if (residueShading == null)
640 residueShading = new ResidueShader(viewStyle);
642 residueShading.setColourScheme(cs);
644 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
645 // ...problem: groups need these, but do not currently have a ViewStyle
649 if (getConservationSelected())
651 residueShading.setConservation(hconservation);
653 residueShading.alignmentChanged(alignment, hiddenRepSequences);
657 * if 'apply colour to all groups' is selected... do so
658 * (but don't transfer any colour threshold settings to groups)
660 if (getColourAppliesToAllGroups())
662 for (SequenceGroup sg : getAlignment().getGroups())
665 * retain any colour thresholds per group while
666 * changing choice of colour scheme (JAL-2386)
668 sg.setColourScheme(cs);
671 sg.getGroupColourScheme()
672 .alignmentChanged(sg, hiddenRepSequences);
679 public ColourSchemeI getGlobalColourScheme()
681 return residueShading == null ? null : residueShading
686 public ResidueShaderI getResidueShading()
688 return residueShading;
691 protected AlignmentAnnotation consensus;
693 protected AlignmentAnnotation complementConsensus;
695 protected AlignmentAnnotation gapcounts;
697 protected AlignmentAnnotation strucConsensus;
699 protected AlignmentAnnotation conservation;
701 protected AlignmentAnnotation quality;
703 protected AlignmentAnnotation[] groupConsensus;
705 protected AlignmentAnnotation[] groupConservation;
707 protected List<AlignmentAnnotation> groupInformation = new ArrayList<>();
709 protected List<AlignmentAnnotation> information = new ArrayList<>();
712 * results of alignment consensus analysis for visible portion of view
714 protected ProfilesI hconsensus = null;
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);
842 public AlignmentAnnotation getAlignmentGapAnnotation()
848 public AlignmentAnnotation getComplementConsensusAnnotation()
850 return complementConsensus;
854 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
856 return strucConsensus;
859 protected AlignCalcManagerI calculator = new AlignCalcManager();
862 * trigger update of conservation annotation
864 public void updateConservation(final AlignmentViewPanel ap)
866 // see note in mantis : issue number 8585
867 if (alignment.isNucleotide()
868 || (conservation == null && quality == null)
869 || !autoCalculateConsensus)
874 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
876 calculator.registerWorker(new jalview.workers.ConservationThread(
882 * trigger update of consensus annotation
884 public void updateConsensus(final AlignmentViewPanel ap)
886 // see note in mantis : issue number 8585
887 if (consensus == null || !autoCalculateConsensus)
891 if (calculator.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)
923 .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null)
926 .registerWorker(new ComplementConsensusThread(this, ap));
933 * trigger update of information annotation
935 public void updateInformation(final AlignmentViewPanel ap)
938 .getRegisteredWorkersOfClass(InformationThread.class) == null)
940 calculator.registerWorker(new InformationThread(this, ap));
945 // --------START Structure Conservation
946 public void updateStrucConsensus(final AlignmentViewPanel ap)
948 if (autoCalculateStrucConsensus && strucConsensus == null
949 && alignment.isNucleotide() && alignment.hasRNAStructure())
951 // secondary structure has been added - so init the consensus line
955 // see note in mantis : issue number 8585
956 if (strucConsensus == null || !autoCalculateStrucConsensus)
960 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
962 calculator.registerWorker(new StrucConsensusThread(this, ap));
966 public boolean isCalcInProgress()
968 return calculator.isWorking();
972 public boolean isCalculationInProgress(
973 AlignmentAnnotation alignmentAnnotation)
975 if (!alignmentAnnotation.autoCalculated)
979 if (calculator.workingInvolvedWith(alignmentAnnotation))
981 // System.err.println("grey out ("+alignmentAnnotation.label+")");
987 public void setAlignment(AlignmentI align)
989 this.alignment = align;
993 * Clean up references when this viewport is closed
996 public void dispose()
999 * defensively null out references to large objects in case
1000 * this object is not garbage collected (as if!)
1003 complementConsensus = null;
1004 strucConsensus = null;
1005 conservation = null;
1007 groupConsensus = null;
1008 groupConservation = null;
1010 hcomplementConsensus = null;
1011 // colour scheme may hold reference to consensus
1012 residueShading = null;
1013 // TODO remove listeners from changeSupport?
1014 changeSupport = null;
1019 public boolean isClosed()
1021 // TODO: check that this isClosed is only true after panel is closed, not
1022 // before it is fully constructed.
1023 return alignment == null;
1027 public AlignCalcManagerI getCalcManager()
1033 * should conservation rows be shown for groups
1035 protected boolean showGroupConservation = false;
1038 * should consensus rows be shown for groups
1040 protected boolean showGroupConsensus = false;
1043 * should consensus profile be rendered by default
1045 protected boolean showSequenceLogo = false;
1048 * should consensus profile be rendered normalised to row height
1050 protected boolean normaliseSequenceLogo = false;
1053 * should consensus histograms be rendered by default
1055 protected boolean showConsensusHistogram = true;
1058 * should hmm profile be rendered by default
1060 protected boolean showHMMSequenceLogo = false;
1063 * should hmm profile be rendered normalised to row height
1065 protected boolean normaliseHMMSequenceLogo = false;
1068 * should information histograms be rendered by default
1070 protected boolean showInformationHistogram = true;
1073 * @return the showConsensusProfile
1076 public boolean isShowSequenceLogo()
1078 return showSequenceLogo;
1082 * @return the showInformationProfile
1085 public boolean isShowHMMSequenceLogo()
1087 return showHMMSequenceLogo;
1091 * @param showSequenceLogo
1094 public void setShowSequenceLogo(boolean showSequenceLogo)
1096 if (showSequenceLogo != this.showSequenceLogo)
1098 // TODO: decouple settings setting from calculation when refactoring
1099 // annotation update method from alignframe to viewport
1100 this.showSequenceLogo = showSequenceLogo;
1101 calculator.updateAnnotationFor(ConsensusThread.class);
1102 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1103 calculator.updateAnnotationFor(StrucConsensusThread.class);
1105 this.showSequenceLogo = showSequenceLogo;
1108 public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo)
1110 if (showHMMSequenceLogo != this.showHMMSequenceLogo)
1112 this.showHMMSequenceLogo = showHMMSequenceLogo;
1113 calculator.updateAnnotationFor(InformationThread.class);
1115 this.showHMMSequenceLogo = showHMMSequenceLogo;
1119 * @param showConsensusHistogram
1120 * the showConsensusHistogram to set
1122 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1124 this.showConsensusHistogram = showConsensusHistogram;
1128 * @param showInformationHistogram
1129 * the showInformationHistogram to set
1131 public void setShowInformationHistogram(boolean showInformationHistogram)
1133 this.showInformationHistogram = showInformationHistogram;
1137 * @return the showGroupConservation
1139 public boolean isShowGroupConservation()
1141 return showGroupConservation;
1145 * @param showGroupConservation
1146 * the showGroupConservation to set
1148 public void setShowGroupConservation(boolean showGroupConservation)
1150 this.showGroupConservation = showGroupConservation;
1154 * @return the showGroupConsensus
1156 public boolean isShowGroupConsensus()
1158 return showGroupConsensus;
1162 * @param showGroupConsensus
1163 * the showGroupConsensus to set
1165 public void setShowGroupConsensus(boolean showGroupConsensus)
1167 this.showGroupConsensus = showGroupConsensus;
1172 * @return flag to indicate if the consensus histogram should be rendered by
1176 public boolean isShowConsensusHistogram()
1178 return this.showConsensusHistogram;
1183 * @return flag to indicate if the information content histogram should be
1184 * rendered by default
1187 public boolean isShowInformationHistogram()
1189 return this.showInformationHistogram;
1193 * when set, updateAlignment will always ensure sequences are of equal length
1195 private boolean padGaps = false;
1198 * when set, alignment should be reordered according to a newly opened tree
1200 public boolean sortByTree = false;
1205 * @return null or the currently selected sequence region
1208 public SequenceGroup getSelectionGroup()
1210 return selectionGroup;
1214 * Set the selection group for this window. Also sets the current alignment as
1215 * the context for the group, if it does not already have one.
1218 * - group holding references to sequences in this alignment view
1222 public void setSelectionGroup(SequenceGroup sg)
1224 selectionGroup = sg;
1225 if (sg != null && sg.getContext() == null)
1227 sg.setContext(alignment);
1231 public void setHiddenColumns(HiddenColumns hidden)
1233 this.alignment.setHiddenColumns(hidden);
1237 public ColumnSelection getColumnSelection()
1243 public void setColumnSelection(ColumnSelection colSel)
1245 this.colSel = colSel;
1248 updateHiddenColumns();
1250 isColSelChanged(true);
1258 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1260 return hiddenRepSequences;
1264 public void setHiddenRepSequences(
1265 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1267 this.hiddenRepSequences = hiddenRepSequences;
1271 public boolean hasSelectedColumns()
1273 ColumnSelection columnSelection = getColumnSelection();
1274 return columnSelection != null && columnSelection.hasSelectedColumns();
1278 public boolean hasHiddenColumns()
1280 return colSel != null
1281 && alignment.getHiddenColumns().hasHiddenColumns();
1284 public void updateHiddenColumns()
1286 // this method doesn't really do anything now. But - it could, since a
1287 // column Selection could be in the process of modification
1288 // hasHiddenColumns = colSel.hasHiddenColumns();
1292 public boolean hasHiddenRows()
1294 return alignment.getHiddenSequences().getSize() > 0;
1297 protected SequenceGroup selectionGroup;
1299 public void setSequenceSetId(String newid)
1301 if (sequenceSetID != null)
1304 .println("Warning - overwriting a sequenceSetId for a viewport!");
1306 sequenceSetID = new String(newid);
1310 public String getSequenceSetId()
1312 if (sequenceSetID == null)
1314 sequenceSetID = alignment.hashCode() + "";
1317 return sequenceSetID;
1321 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1324 protected String viewId = null;
1327 public String getViewId()
1331 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1336 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1338 ignoreGapsInConsensusCalculation = b;
1341 updateConsensus(ap);
1342 if (residueShading != null)
1344 residueShading.setThreshold(residueShading.getThreshold(),
1345 ignoreGapsInConsensusCalculation);
1351 public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap)
1353 ignoreBelowBackGroundFrequencyCalculation = b;
1356 updateInformation(ap);
1361 private long sgrouphash = -1, colselhash = -1;
1364 * checks current SelectionGroup against record of last hash value, and
1368 * update the record of last hash value
1370 * @return true if SelectionGroup changed since last call (when b is true)
1372 public boolean isSelectionGroupChanged(boolean b)
1374 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1375 : selectionGroup.hashCode();
1376 if (hc != -1 && hc != sgrouphash)
1388 * checks current colsel against record of last hash value, and optionally
1392 * update the record of last hash value
1393 * @return true if colsel changed since last call (when b is true)
1395 public boolean isColSelChanged(boolean b)
1397 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1398 if (hc != -1 && hc != colselhash)
1410 public boolean isIgnoreGapsConsensus()
1412 return ignoreGapsInConsensusCalculation;
1416 public boolean isIgnoreBelowBackground()
1418 return ignoreBelowBackGroundFrequencyCalculation;
1421 // property change stuff
1422 // JBPNote Prolly only need this in the applet version.
1423 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1426 protected boolean showConservation = true;
1428 protected boolean showQuality = true;
1430 protected boolean showConsensus = true;
1432 protected boolean showOccupancy = true;
1434 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1436 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1438 protected boolean showAutocalculatedAbove;
1441 * when set, view will scroll to show the highlighted position
1443 private boolean followHighlight = true;
1446 * Property change listener for changes in alignment
1451 public void addPropertyChangeListener(
1452 java.beans.PropertyChangeListener listener)
1454 changeSupport.addPropertyChangeListener(listener);
1463 public void removePropertyChangeListener(
1464 java.beans.PropertyChangeListener listener)
1466 changeSupport.removePropertyChangeListener(listener);
1470 * Property change listener for changes in alignment
1479 public void firePropertyChange(String prop, Object oldvalue,
1482 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1485 // common hide/show column stuff
1487 public void hideSelectedColumns()
1489 if (colSel.isEmpty())
1494 colSel.hideSelectedColumns(alignment);
1495 setSelectionGroup(null);
1496 isColSelChanged(true);
1499 public void hideColumns(int start, int end)
1503 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1507 alignment.getHiddenColumns().hideColumns(start, end);
1509 isColSelChanged(true);
1512 public void showColumn(int col)
1514 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1515 isColSelChanged(true);
1518 public void showAllHiddenColumns()
1520 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1521 isColSelChanged(true);
1524 // common hide/show seq stuff
1525 public void showAllHiddenSeqs()
1527 if (alignment.getHiddenSequences().getSize() > 0)
1529 if (selectionGroup == null)
1531 selectionGroup = new SequenceGroup();
1532 selectionGroup.setEndRes(alignment.getWidth() - 1);
1534 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1535 hiddenRepSequences);
1536 for (SequenceI seq : tmp)
1538 selectionGroup.addSequence(seq, false);
1539 setSequenceAnnotationsVisible(seq, true);
1542 hiddenRepSequences = null;
1544 firePropertyChange("alignment", null, alignment.getSequences());
1545 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1551 public void showSequence(int index)
1553 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1554 index, hiddenRepSequences);
1557 if (selectionGroup == null)
1559 selectionGroup = new SequenceGroup();
1560 selectionGroup.setEndRes(alignment.getWidth() - 1);
1563 for (SequenceI seq : tmp)
1565 selectionGroup.addSequence(seq, false);
1566 setSequenceAnnotationsVisible(seq, true);
1568 firePropertyChange("alignment", null, alignment.getSequences());
1573 public void hideAllSelectedSeqs()
1575 if (selectionGroup == null || selectionGroup.getSize() < 1)
1580 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1584 setSelectionGroup(null);
1587 public void hideSequence(SequenceI[] seq)
1591 for (int i = 0; i < seq.length; i++)
1593 alignment.getHiddenSequences().hideSequence(seq[i]);
1594 setSequenceAnnotationsVisible(seq[i], false);
1596 firePropertyChange("alignment", null, alignment.getSequences());
1601 * Hides the specified sequence, or the sequences it represents
1604 * the sequence to hide, or keep as representative
1605 * @param representGroup
1606 * if true, hide the current selection group except for the
1607 * representative sequence
1609 public void hideSequences(SequenceI sequence, boolean representGroup)
1611 if (selectionGroup == null || selectionGroup.getSize() < 1)
1613 hideSequence(new SequenceI[] { sequence });
1619 hideRepSequences(sequence, selectionGroup);
1620 setSelectionGroup(null);
1624 int gsize = selectionGroup.getSize();
1625 SequenceI[] hseqs = selectionGroup.getSequences().toArray(
1626 new SequenceI[gsize]);
1628 hideSequence(hseqs);
1629 setSelectionGroup(null);
1634 * Set visibility for any annotations for the given sequence.
1638 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1641 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1644 for (AlignmentAnnotation ann : anns)
1646 if (ann.sequenceRef == sequenceI)
1648 ann.visible = visible;
1654 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1656 int sSize = sg.getSize();
1662 if (hiddenRepSequences == null)
1664 hiddenRepSequences = new Hashtable<>();
1667 hiddenRepSequences.put(repSequence, sg);
1669 // Hide all sequences except the repSequence
1670 SequenceI[] seqs = new SequenceI[sSize - 1];
1672 for (int i = 0; i < sSize; i++)
1674 if (sg.getSequenceAt(i) != repSequence)
1676 if (index == sSize - 1)
1681 seqs[index++] = sg.getSequenceAt(i);
1684 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1685 sg.setHidereps(true); // note: not done in 2.7applet
1692 * @return null or the current reference sequence
1694 public SequenceI getReferenceSeq()
1696 return alignment.getSeqrep();
1701 * @return true iff seq is the reference for the alignment
1703 public boolean isReferenceSeq(SequenceI seq)
1705 return alignment.getSeqrep() == seq;
1711 * @return true if there are sequences represented by this sequence that are
1714 public boolean isHiddenRepSequence(SequenceI seq)
1716 return (hiddenRepSequences != null && hiddenRepSequences
1723 * @return null or a sequence group containing the sequences that seq
1726 public SequenceGroup getRepresentedSequences(SequenceI seq)
1728 return (SequenceGroup) (hiddenRepSequences == null ? null
1729 : hiddenRepSequences.get(seq));
1733 public int adjustForHiddenSeqs(int alignmentIndex)
1735 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1740 public void invertColumnSelection()
1742 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1746 public SequenceI[] getSelectionAsNewSequence()
1748 SequenceI[] sequences;
1749 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1750 // this was the only caller in the applet for this method
1751 // JBPNote: in applet, this method returned references to the alignment
1752 // sequences, and it did not honour the presence/absence of annotation
1753 // attached to the alignment (probably!)
1754 if (selectionGroup == null || selectionGroup.getSize() == 0)
1756 sequences = alignment.getSequencesArray();
1757 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1758 for (int i = 0; i < sequences.length; i++)
1760 // construct new sequence with subset of visible annotation
1761 sequences[i] = new Sequence(sequences[i], annots);
1766 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1773 public SequenceI[] getSequenceSelection()
1775 SequenceI[] sequences = null;
1776 if (selectionGroup != null)
1778 sequences = selectionGroup.getSequencesInOrder(alignment);
1780 if (sequences == null)
1782 sequences = alignment.getSequencesArray();
1788 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1790 return new CigarArray(alignment, alignment.getHiddenColumns(),
1791 (selectedRegionOnly ? selectionGroup : null));
1795 public jalview.datamodel.AlignmentView getAlignmentView(
1796 boolean selectedOnly)
1798 return getAlignmentView(selectedOnly, false);
1802 public jalview.datamodel.AlignmentView getAlignmentView(
1803 boolean selectedOnly, boolean markGroups)
1805 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1806 selectionGroup, alignment.getHiddenColumns() != null
1807 && alignment.getHiddenColumns().hasHiddenColumns(),
1813 public String[] getViewAsString(boolean selectedRegionOnly)
1815 return getViewAsString(selectedRegionOnly, true);
1819 public String[] getViewAsString(boolean selectedRegionOnly,
1820 boolean exportHiddenSeqs)
1822 String[] selection = null;
1823 SequenceI[] seqs = null;
1825 int start = 0, end = 0;
1826 if (selectedRegionOnly && selectionGroup != null)
1828 iSize = selectionGroup.getSize();
1829 seqs = selectionGroup.getSequencesInOrder(alignment);
1830 start = selectionGroup.getStartRes();
1831 end = selectionGroup.getEndRes() + 1;
1835 if (hasHiddenRows() && exportHiddenSeqs)
1837 AlignmentI fullAlignment = alignment.getHiddenSequences()
1838 .getFullAlignment();
1839 iSize = fullAlignment.getHeight();
1840 seqs = fullAlignment.getSequencesArray();
1841 end = fullAlignment.getWidth();
1845 iSize = alignment.getHeight();
1846 seqs = alignment.getSequencesArray();
1847 end = alignment.getWidth();
1851 selection = new String[iSize];
1852 if (alignment.getHiddenColumns() != null
1853 && alignment.getHiddenColumns().hasHiddenColumns())
1855 selection = alignment.getHiddenColumns().getVisibleSequenceStrings(
1860 for (i = 0; i < iSize; i++)
1862 selection[i] = seqs[i].getSequenceAsString(start, end);
1870 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1872 ArrayList<int[]> regions = new ArrayList<>();
1878 HiddenColumns hidden = alignment.getHiddenColumns();
1879 if (hidden != null && hidden.hasHiddenColumns())
1883 start = hidden.adjustForHiddenColumns(start);
1886 end = hidden.getHiddenBoundaryRight(start);
1897 regions.add(new int[] { start, end });
1899 if (hidden != null && hidden.hasHiddenColumns())
1901 start = hidden.adjustForHiddenColumns(end);
1902 start = hidden.getHiddenBoundaryLeft(start) + 1;
1904 } while (end < max);
1906 int[][] startEnd = new int[regions.size()][2];
1912 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1913 boolean selectedOnly)
1915 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1916 AlignmentAnnotation[] aa;
1917 if ((aa = alignment.getAlignmentAnnotation()) != null)
1919 for (AlignmentAnnotation annot : aa)
1921 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1922 if (selectedOnly && selectionGroup != null)
1924 alignment.getHiddenColumns().makeVisibleAnnotation(
1925 selectionGroup.getStartRes(),
1926 selectionGroup.getEndRes(), clone);
1930 alignment.getHiddenColumns().makeVisibleAnnotation(clone);
1939 public boolean isPadGaps()
1945 public void setPadGaps(boolean padGaps)
1947 this.padGaps = padGaps;
1951 * apply any post-edit constraints and trigger any calculations needed after
1952 * an edit has been performed on the alignment
1957 public void alignmentChanged(AlignmentViewPanel ap)
1961 alignment.padGaps();
1963 if (autoCalculateConsensus)
1965 updateConsensus(ap);
1967 if (hconsensus != null && autoCalculateConsensus)
1969 updateConservation(ap);
1971 if (autoCalculateStrucConsensus)
1973 updateStrucConsensus(ap);
1975 updateInformation(ap);
1977 Map<Integer, SequenceI> hmmSequences;
1978 hmmSequences = alignment.getHMMConsensusSequences(false);
1980 for (Map.Entry<Integer, SequenceI> entry : hmmSequences.entrySet())
1982 SequenceI seq = entry.getValue();
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();
2069 * If this is a protein alignment and there are mappings to cDNA, adds the
2070 * cDNA consensus annotation and returns true, else returns false.
2072 public boolean initComplementConsensus()
2074 if (!alignment.isNucleotide())
2076 final List<AlignedCodonFrame> codonMappings = alignment
2078 if (codonMappings != null && !codonMappings.isEmpty())
2080 boolean doConsensus = false;
2081 for (AlignedCodonFrame mapping : codonMappings)
2083 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2084 MapList[] mapLists = mapping.getdnaToProt();
2085 // mapLists can be empty if project load has not finished resolving
2087 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2095 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2097 .getString("label.complement_consensus_descr"),
2098 new Annotation[1], 0f, 100f,
2099 AlignmentAnnotation.BAR_GRAPH);
2100 initConsensus(complementConsensus);
2108 private void initConsensus(AlignmentAnnotation aa)
2111 aa.autoCalculated = true;
2115 alignment.addAnnotation(aa);
2119 public void initInformation(SequenceI hmmSequence)
2121 AlignmentAnnotation information;
2122 information = new AlignmentAnnotation(hmmSequence.getName(),
2123 MessageManager.getString("label.information_description"),
2124 new Annotation[1], 0f, 6.52f, AlignmentAnnotation.BAR_GRAPH);
2125 information.hasText = true;
2126 information.autoCalculated = true;
2127 information.hasText = true;
2128 information.autoCalculated = false;
2129 information.sequenceRef = hmmSequence;
2130 this.information.add(information);
2131 hinformation.add(new Profiles(new ProfileI[1]));
2132 alignment.addAnnotation(information);
2135 // these should be extracted from the view model - style and settings for
2136 // derived annotation
2137 private void initGapCounts()
2141 gapcounts = new AlignmentAnnotation("Occupancy",
2142 MessageManager.getString("label.occupancy_descr"),
2143 new Annotation[1], 0f,
2144 alignment.getHeight(), AlignmentAnnotation.BAR_GRAPH);
2145 gapcounts.hasText = true;
2146 gapcounts.autoCalculated = true;
2147 gapcounts.scaleColLabel = true;
2148 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2150 alignment.addAnnotation(gapcounts);
2154 private void initConservation()
2156 if (showConservation)
2158 if (conservation == null)
2160 conservation = new AlignmentAnnotation("Conservation",
2161 MessageManager.formatMessage("label.conservation_descr",
2162 getConsPercGaps()), new Annotation[1],
2163 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2164 conservation.hasText = true;
2165 conservation.autoCalculated = true;
2166 alignment.addAnnotation(conservation);
2171 private void initQuality()
2175 if (quality == null)
2177 quality = new AlignmentAnnotation("Quality",
2178 MessageManager.getString("label.quality_descr"),
2179 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2180 quality.hasText = true;
2181 quality.autoCalculated = true;
2182 alignment.addAnnotation(quality);
2187 private void initRNAStructure()
2189 if (alignment.hasRNAStructure() && strucConsensus == null)
2191 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2192 MessageManager.getString("label.strucconsensus_descr"),
2193 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2194 strucConsensus.hasText = true;
2195 strucConsensus.autoCalculated = true;
2199 alignment.addAnnotation(strucConsensus);
2207 * @see jalview.api.AlignViewportI#calcPanelHeight()
2210 public int calcPanelHeight()
2212 // setHeight of panels
2213 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2215 int charHeight = getCharHeight();
2218 BitSet graphgrp = new BitSet();
2219 for (AlignmentAnnotation aa : anns)
2223 System.err.println("Null annotation row: ignoring.");
2230 if (aa.graphGroup > -1)
2232 if (graphgrp.get(aa.graphGroup))
2238 graphgrp.set(aa.graphGroup);
2245 aa.height += charHeight;
2255 aa.height += aa.graphHeight;
2263 height += aa.height;
2275 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2276 boolean preserveNewGroupSettings)
2278 boolean updateCalcs = false;
2279 boolean conv = isShowGroupConservation();
2280 boolean cons = isShowGroupConsensus();
2281 boolean showprf = isShowSequenceLogo();
2282 boolean showConsHist = isShowConsensusHistogram();
2283 boolean normLogo = isNormaliseSequenceLogo();
2284 boolean showHMMPrf = isShowHMMSequenceLogo();
2285 boolean showInfoHist = isShowInformationHistogram();
2286 boolean normHMMLogo = isNormaliseHMMSequenceLogo();
2289 * TODO reorder the annotation rows according to group/sequence ordering on
2292 boolean sortg = true;
2294 // remove old automatic annotation
2295 // add any new annotation
2297 // intersect alignment annotation with alignment groups
2299 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2300 List<SequenceGroup> oldrfs = new ArrayList<>();
2303 for (int an = 0; an < aan.length; an++)
2305 if (aan[an].autoCalculated && aan[an].groupRef != null)
2307 oldrfs.add(aan[an].groupRef);
2308 alignment.deleteAnnotation(aan[an], false);
2312 if (alignment.getGroups() != null)
2314 for (SequenceGroup sg : alignment.getGroups())
2316 updateCalcs = false;
2317 if (applyGlobalSettings
2318 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2320 // set defaults for this group's conservation/consensus
2321 sg.setshowSequenceLogo(showprf);
2322 sg.setShowConsensusHistogram(showConsHist);
2323 sg.setNormaliseSequenceLogo(normLogo);
2324 sg.setshowHMMSequenceLogo(showHMMPrf);
2325 sg.setShowInformationHistogram(showInfoHist);
2326 sg.setNormaliseHMMSequenceLogo(normHMMLogo);
2331 alignment.addAnnotation(sg.getConservationRow(), 0);
2336 alignment.addAnnotation(sg.getConsensus(), 0);
2338 // refresh the annotation rows
2341 sg.recalcConservation();
2349 public boolean isDisplayReferenceSeq()
2351 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2355 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2357 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2361 public boolean isColourByReferenceSeq()
2363 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2367 public Color getSequenceColour(SequenceI seq)
2369 Color sqc = sequenceColours.get(seq);
2370 return (sqc == null ? Color.white : sqc);
2374 public void setSequenceColour(SequenceI seq, Color col)
2378 sequenceColours.remove(seq);
2382 sequenceColours.put(seq, col);
2387 public void updateSequenceIdColours()
2389 for (SequenceGroup sg : alignment.getGroups())
2391 if (sg.idColour != null)
2393 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2395 sequenceColours.put(s, sg.idColour);
2402 public void clearSequenceColours()
2404 sequenceColours.clear();
2408 public AlignViewportI getCodingComplement()
2410 return this.codingComplement;
2414 * Set this as the (cDna/protein) complement of the given viewport. Also
2415 * ensures the reverse relationship is set on the given viewport.
2418 public void setCodingComplement(AlignViewportI av)
2422 System.err.println("Ignoring recursive setCodingComplement request");
2426 this.codingComplement = av;
2427 // avoid infinite recursion!
2428 if (av.getCodingComplement() != this)
2430 av.setCodingComplement(this);
2436 public boolean isNucleotide()
2438 return getAlignment() == null ? false : getAlignment().isNucleotide();
2442 public FeaturesDisplayedI getFeaturesDisplayed()
2444 return featuresDisplayed;
2448 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2450 featuresDisplayed = featuresDisplayedI;
2454 public boolean areFeaturesDisplayed()
2456 return featuresDisplayed != null
2457 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2464 * features are displayed if true
2467 public void setShowSequenceFeatures(boolean b)
2469 viewStyle.setShowSequenceFeatures(b);
2473 public boolean isShowSequenceFeatures()
2475 return viewStyle.isShowSequenceFeatures();
2479 public void setShowSequenceFeaturesHeight(boolean selected)
2481 viewStyle.setShowSequenceFeaturesHeight(selected);
2485 public boolean isShowSequenceFeaturesHeight()
2487 return viewStyle.isShowSequenceFeaturesHeight();
2491 public void setShowAnnotation(boolean b)
2493 viewStyle.setShowAnnotation(b);
2497 public boolean isShowAnnotation()
2499 return viewStyle.isShowAnnotation();
2503 public boolean isRightAlignIds()
2505 return viewStyle.isRightAlignIds();
2509 public void setRightAlignIds(boolean rightAlignIds)
2511 viewStyle.setRightAlignIds(rightAlignIds);
2515 public boolean getConservationSelected()
2517 return viewStyle.getConservationSelected();
2521 public void setShowBoxes(boolean state)
2523 viewStyle.setShowBoxes(state);
2528 * @see jalview.api.ViewStyleI#getTextColour()
2531 public Color getTextColour()
2533 return viewStyle.getTextColour();
2538 * @see jalview.api.ViewStyleI#getTextColour2()
2541 public Color getTextColour2()
2543 return viewStyle.getTextColour2();
2548 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2551 public int getThresholdTextColour()
2553 return viewStyle.getThresholdTextColour();
2558 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2561 public boolean isConservationColourSelected()
2563 return viewStyle.isConservationColourSelected();
2568 * @see jalview.api.ViewStyleI#isRenderGaps()
2571 public boolean isRenderGaps()
2573 return viewStyle.isRenderGaps();
2578 * @see jalview.api.ViewStyleI#isShowColourText()
2581 public boolean isShowColourText()
2583 return viewStyle.isShowColourText();
2587 * @param conservationColourSelected
2588 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2591 public void setConservationColourSelected(
2592 boolean conservationColourSelected)
2594 viewStyle.setConservationColourSelected(conservationColourSelected);
2598 * @param showColourText
2599 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2602 public void setShowColourText(boolean showColourText)
2604 viewStyle.setShowColourText(showColourText);
2609 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2612 public void setTextColour(Color textColour)
2614 viewStyle.setTextColour(textColour);
2618 * @param thresholdTextColour
2619 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2622 public void setThresholdTextColour(int thresholdTextColour)
2624 viewStyle.setThresholdTextColour(thresholdTextColour);
2628 * @param textColour2
2629 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2632 public void setTextColour2(Color textColour2)
2634 viewStyle.setTextColour2(textColour2);
2638 public ViewStyleI getViewStyle()
2640 return new ViewStyle(viewStyle);
2644 public void setViewStyle(ViewStyleI settingsForView)
2646 viewStyle = new ViewStyle(settingsForView);
2647 if (residueShading != null)
2649 residueShading.setConservationApplied(settingsForView
2650 .isConservationColourSelected());
2655 public boolean sameStyle(ViewStyleI them)
2657 return viewStyle.sameStyle(them);
2662 * @see jalview.api.ViewStyleI#getIdWidth()
2665 public int getIdWidth()
2667 return viewStyle.getIdWidth();
2672 * @see jalview.api.ViewStyleI#setIdWidth(int)
2675 public void setIdWidth(int i)
2677 viewStyle.setIdWidth(i);
2682 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2685 public boolean isCentreColumnLabels()
2687 return viewStyle.isCentreColumnLabels();
2691 * @param centreColumnLabels
2692 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2695 public void setCentreColumnLabels(boolean centreColumnLabels)
2697 viewStyle.setCentreColumnLabels(centreColumnLabels);
2702 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2705 public void setShowDBRefs(boolean showdbrefs)
2707 viewStyle.setShowDBRefs(showdbrefs);
2712 * @see jalview.api.ViewStyleI#isShowDBRefs()
2715 public boolean isShowDBRefs()
2717 return viewStyle.isShowDBRefs();
2722 * @see jalview.api.ViewStyleI#isShowNPFeats()
2725 public boolean isShowNPFeats()
2727 return viewStyle.isShowNPFeats();
2731 * @param shownpfeats
2732 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2735 public void setShowNPFeats(boolean shownpfeats)
2737 viewStyle.setShowNPFeats(shownpfeats);
2740 public abstract StructureSelectionManager getStructureSelectionManager();
2743 * Add one command to the command history list.
2747 public void addToHistoryList(CommandI command)
2749 if (this.historyList != null)
2751 this.historyList.push(command);
2752 broadcastCommand(command, false);
2756 protected void broadcastCommand(CommandI command, boolean undo)
2758 getStructureSelectionManager().commandPerformed(command, undo,
2763 * Add one command to the command redo list.
2767 public void addToRedoList(CommandI command)
2769 if (this.redoList != null)
2771 this.redoList.push(command);
2773 broadcastCommand(command, true);
2777 * Clear the command redo list.
2779 public void clearRedoList()
2781 if (this.redoList != null)
2783 this.redoList.clear();
2787 public void setHistoryList(Deque<CommandI> list)
2789 this.historyList = list;
2792 public Deque<CommandI> getHistoryList()
2794 return this.historyList;
2797 public void setRedoList(Deque<CommandI> list)
2799 this.redoList = list;
2802 public Deque<CommandI> getRedoList()
2804 return this.redoList;
2808 public VamsasSource getVamsasSource()
2813 public SequenceAnnotationOrder getSortAnnotationsBy()
2815 return sortAnnotationsBy;
2818 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2820 this.sortAnnotationsBy = sortAnnotationsBy;
2823 public boolean isShowAutocalculatedAbove()
2825 return showAutocalculatedAbove;
2828 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2830 this.showAutocalculatedAbove = showAutocalculatedAbove;
2834 public boolean isScaleProteinAsCdna()
2836 return viewStyle.isScaleProteinAsCdna();
2840 public void setScaleProteinAsCdna(boolean b)
2842 viewStyle.setScaleProteinAsCdna(b);
2846 public boolean isProteinFontAsCdna()
2848 return viewStyle.isProteinFontAsCdna();
2852 public void setProteinFontAsCdna(boolean b)
2854 viewStyle.setProteinFontAsCdna(b);
2858 * @return true if view should scroll to show the highlighted region of a
2863 public final boolean isFollowHighlight()
2865 return followHighlight;
2869 public final void setFollowHighlight(boolean b)
2871 this.followHighlight = b;
2875 public ViewportRanges getRanges()
2881 * Helper method to populate the SearchResults with the location in the
2882 * complementary alignment to scroll to, in order to match this one.
2885 * the SearchResults to add to
2886 * @return the offset (below top of visible region) of the matched sequence
2888 protected int findComplementScrollTarget(SearchResultsI sr)
2890 final AlignViewportI complement = getCodingComplement();
2891 if (complement == null || !complement.isFollowHighlight())
2895 boolean iAmProtein = !getAlignment().isNucleotide();
2896 AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement
2898 if (proteinAlignment == null)
2902 final List<AlignedCodonFrame> mappings = proteinAlignment
2906 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2907 * residue in the middle column of the visible region. Scroll the
2908 * complementary alignment to line up the corresponding residue.
2911 SequenceI sequence = null;
2914 * locate 'middle' column (true middle if an odd number visible, left of
2915 * middle if an even number visible)
2917 int middleColumn = ranges.getStartRes()
2918 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2919 final HiddenSequences hiddenSequences = getAlignment()
2920 .getHiddenSequences();
2923 * searching to the bottom of the alignment gives smoother scrolling across
2924 * all gapped visible regions
2926 int lastSeq = alignment.getHeight() - 1;
2927 List<AlignedCodonFrame> seqMappings = null;
2928 for (int seqNo = ranges.getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2930 sequence = getAlignment().getSequenceAt(seqNo);
2931 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2935 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2939 seqMappings = MappingUtils
2940 .findMappingsForSequenceAndOthers(sequence, mappings,
2941 getCodingComplement().getAlignment().getSequences());
2942 if (!seqMappings.isEmpty())
2948 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2951 * No ungapped mapped sequence in middle column - do nothing
2955 MappingUtils.addSearchResults(sr, sequence,
2956 sequence.findPosition(middleColumn), seqMappings);
2961 * synthesize a column selection if none exists so it covers the given
2962 * selection group. if wholewidth is false, no column selection is made if the
2963 * selection group covers the whole alignment width.
2968 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2971 if (sg != null && (sgs = sg.getStartRes()) >= 0
2972 && sg.getStartRes() <= (sge = sg.getEndRes())
2973 && !this.hasSelectedColumns())
2975 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2982 colSel = new ColumnSelection();
2984 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2986 colSel.addElement(cspos);
2992 * hold status of current selection group - defined on alignment or not.
2994 private boolean selectionIsDefinedGroup = false;
2997 public boolean isSelectionDefinedGroup()
2999 if (selectionGroup == null)
3003 if (isSelectionGroupChanged(true))
3005 selectionIsDefinedGroup = false;
3006 List<SequenceGroup> gps = alignment.getGroups();
3007 if (gps == null || gps.size() == 0)
3009 selectionIsDefinedGroup = false;
3013 selectionIsDefinedGroup = gps.contains(selectionGroup);
3016 return selectionGroup.isDefined() || selectionIsDefinedGroup;
3020 * null, or currently highlighted results on this view
3022 private SearchResultsI searchResults = null;
3025 public boolean hasSearchResults()
3027 return searchResults != null;
3031 public void setSearchResults(SearchResultsI results)
3033 searchResults = results;
3037 public SearchResultsI getSearchResults()
3039 return searchResults;