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);
412 ranges.setWrappedMode(state);
417 * @see jalview.api.ViewStyleI#setShowText(boolean)
420 public void setShowText(boolean state)
422 viewStyle.setShowText(state);
427 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
430 public void setRenderGaps(boolean state)
432 viewStyle.setRenderGaps(state);
437 * @see jalview.api.ViewStyleI#getColourText()
440 public boolean getColourText()
442 return viewStyle.getColourText();
447 * @see jalview.api.ViewStyleI#setColourText(boolean)
450 public void setColourText(boolean state)
452 viewStyle.setColourText(state);
457 * @see jalview.api.ViewStyleI#getWrapAlignment()
460 public boolean getWrapAlignment()
462 return viewStyle.getWrapAlignment();
467 * @see jalview.api.ViewStyleI#getShowText()
470 public boolean getShowText()
472 return viewStyle.getShowText();
477 * @see jalview.api.ViewStyleI#getWrappedWidth()
480 public int getWrappedWidth()
482 return viewStyle.getWrappedWidth();
487 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
490 public void setWrappedWidth(int w)
492 viewStyle.setWrappedWidth(w);
497 * @see jalview.api.ViewStyleI#getCharHeight()
500 public int getCharHeight()
502 return viewStyle.getCharHeight();
507 * @see jalview.api.ViewStyleI#setCharHeight(int)
510 public void setCharHeight(int h)
512 viewStyle.setCharHeight(h);
517 * @see jalview.api.ViewStyleI#getCharWidth()
520 public int getCharWidth()
522 return viewStyle.getCharWidth();
527 * @see jalview.api.ViewStyleI#setCharWidth(int)
530 public void setCharWidth(int w)
532 viewStyle.setCharWidth(w);
537 * @see jalview.api.ViewStyleI#getShowBoxes()
540 public boolean getShowBoxes()
542 return viewStyle.getShowBoxes();
547 * @see jalview.api.ViewStyleI#getShowUnconserved()
550 public boolean getShowUnconserved()
552 return viewStyle.getShowUnconserved();
556 * @param showunconserved
557 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
560 public void setShowUnconserved(boolean showunconserved)
562 viewStyle.setShowUnconserved(showunconserved);
567 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
570 public void setSeqNameItalics(boolean default1)
572 viewStyle.setSeqNameItalics(default1);
576 public AlignmentI getAlignment()
582 public char getGapCharacter()
584 return alignment.getGapCharacter();
587 protected String sequenceSetID;
590 * probably unused indicator that view is of a dataset rather than an
593 protected boolean isDataset = false;
595 public void setDataset(boolean b)
600 public boolean isDataset()
605 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
607 protected ColumnSelection colSel = new ColumnSelection();
609 public boolean autoCalculateConsensus = true;
611 public boolean autoCalculateInformation = true;
613 protected boolean autoCalculateStrucConsensus = true;
615 protected boolean ignoreGapsInConsensusCalculation = false;
617 protected boolean ignoreBelowBackGroundFrequencyCalculation = false;
619 protected ResidueShaderI residueShading = new ResidueShader();
622 public void setGlobalColourScheme(ColourSchemeI cs)
624 // TODO: logic refactored from AlignFrame changeColour -
625 // TODO: autorecalc stuff should be changed to rely on the worker system
626 // check to see if we should implement a changeColour(cs) method rather than
627 // put the logic in here
628 // - means that caller decides if they want to just modify state and defer
629 // calculation till later or to do all calculations in thread.
633 * only instantiate alignment colouring once, thereafter update it;
634 * this means that any conservation or PID threshold settings
635 * persist when the alignment colour scheme is changed
637 if (residueShading == null)
639 residueShading = new ResidueShader(viewStyle);
641 residueShading.setColourScheme(cs);
643 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
644 // ...problem: groups need these, but do not currently have a ViewStyle
648 if (getConservationSelected())
650 residueShading.setConservation(hconservation);
653 * reset conservation flag in case just set to false if
654 * Conservation was null (calculation still in progress)
656 residueShading.setConservationApplied(getConservationSelected());
657 residueShading.alignmentChanged(alignment, hiddenRepSequences);
661 * if 'apply colour to all groups' is selected... do so
662 * (but don't transfer any colour threshold settings to groups)
664 if (getColourAppliesToAllGroups())
666 for (SequenceGroup sg : getAlignment().getGroups())
669 * retain any colour thresholds per group while
670 * changing choice of colour scheme (JAL-2386)
672 sg.setColourScheme(cs);
675 sg.getGroupColourScheme().alignmentChanged(sg,
683 public ColourSchemeI getGlobalColourScheme()
685 return residueShading == null ? null : residueShading.getColourScheme();
689 public ResidueShaderI getResidueShading()
691 return residueShading;
694 protected AlignmentAnnotation consensus;
696 protected AlignmentAnnotation complementConsensus;
698 protected AlignmentAnnotation gapcounts;
700 protected AlignmentAnnotation strucConsensus;
702 protected AlignmentAnnotation conservation;
704 protected AlignmentAnnotation quality;
706 protected AlignmentAnnotation[] groupConsensus;
708 protected AlignmentAnnotation[] groupConservation;
710 protected List<AlignmentAnnotation> groupInformation = new ArrayList<>();
712 protected List<AlignmentAnnotation> information = new ArrayList<>();
715 * results of alignment consensus analysis for visible portion of view
717 protected ProfilesI hconsensus = null;
720 * results of information annotation analysis for the visible portion of view
722 protected List<ProfilesI> hinformation = new ArrayList<>();
725 * results of cDNA complement consensus visible portion of view
727 protected Hashtable[] hcomplementConsensus = null;
730 * results of secondary structure base pair consensus for visible portion of
733 protected Hashtable[] hStrucConsensus = null;
735 protected Conservation hconservation = null;
738 public void setConservation(Conservation cons)
740 hconservation = cons;
744 * percentage gaps allowed in a column before all amino acid properties should
745 * be considered unconserved
747 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
750 public int getConsPercGaps()
756 public void setSequenceConsensusHash(ProfilesI hconsensus)
758 this.hconsensus = hconsensus;
762 public void setComplementConsensusHash(Hashtable[] hconsensus)
764 this.hcomplementConsensus = hconsensus;
768 public ProfilesI getSequenceConsensusHash()
774 public void setSequenceInformationHashes(List<ProfilesI> info)
780 public void setSequenceInformationHash(ProfilesI info, int index)
782 if (hinformation.size() < index + 1)
786 hinformation.set(index, info);
790 public List<ProfilesI> getSequenceInformationHashes()
796 public ProfilesI getSequenceInformationHash(int index)
798 return hinformation.get(index);
802 public Hashtable[] getComplementConsensusHash()
804 return hcomplementConsensus;
808 public Hashtable[] getRnaStructureConsensusHash()
810 return hStrucConsensus;
814 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
816 this.hStrucConsensus = hStrucConsensus;
821 public AlignmentAnnotation getAlignmentQualityAnnot()
827 public AlignmentAnnotation getAlignmentConservationAnnotation()
833 public AlignmentAnnotation getAlignmentConsensusAnnotation()
839 public List<AlignmentAnnotation> getInformationAnnotations()
845 public AlignmentAnnotation getInformationAnnotation(int index)
847 return information.get(index);
851 public AlignmentAnnotation getAlignmentGapAnnotation()
857 public AlignmentAnnotation getComplementConsensusAnnotation()
859 return complementConsensus;
863 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
865 return strucConsensus;
868 protected AlignCalcManagerI calculator = new AlignCalcManager();
871 * trigger update of conservation annotation
873 public void updateConservation(final AlignmentViewPanel ap)
875 // see note in mantis : issue number 8585
876 if (alignment.isNucleotide()
877 || (conservation == null && quality == null)
878 || !autoCalculateConsensus)
882 if (calculator.getRegisteredWorkersOfClass(
883 jalview.workers.ConservationThread.class) == null)
885 calculator.registerWorker(
886 new jalview.workers.ConservationThread(this, ap));
891 * trigger update of consensus annotation
893 public void updateConsensus(final AlignmentViewPanel ap)
895 // see note in mantis : issue number 8585
896 if (consensus == null || !autoCalculateConsensus)
901 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
903 calculator.registerWorker(new ConsensusThread(this, ap));
907 * A separate thread to compute cDNA consensus for a protein alignment
908 * which has mapping to cDNA
910 final AlignmentI al = this.getAlignment();
911 if (!al.isNucleotide() && al.getCodonFrames() != null
912 && !al.getCodonFrames().isEmpty())
915 * fudge - check first for protein-to-nucleotide mappings
916 * (we don't want to do this for protein-to-protein)
918 boolean doConsensus = false;
919 for (AlignedCodonFrame mapping : al.getCodonFrames())
921 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
922 MapList[] mapLists = mapping.getdnaToProt();
923 // mapLists can be empty if project load has not finished resolving seqs
924 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
932 if (calculator.getRegisteredWorkersOfClass(
933 ComplementConsensusThread.class) == null)
936 .registerWorker(new ComplementConsensusThread(this, ap));
943 * trigger update of information annotation
946 public void updateInformation(final AlignmentViewPanel ap)
949 .getRegisteredWorkersOfClass(InformationThread.class) == null)
951 calculator.registerWorker(new InformationThread(this, ap));
956 // --------START Structure Conservation
957 public void updateStrucConsensus(final AlignmentViewPanel ap)
959 if (autoCalculateStrucConsensus && strucConsensus == null
960 && alignment.isNucleotide() && alignment.hasRNAStructure())
962 // secondary structure has been added - so init the consensus line
966 // see note in mantis : issue number 8585
967 if (strucConsensus == null || !autoCalculateStrucConsensus)
971 if (calculator.getRegisteredWorkersOfClass(
972 StrucConsensusThread.class) == null)
974 calculator.registerWorker(new StrucConsensusThread(this, ap));
978 public boolean isCalcInProgress()
980 return calculator.isWorking();
984 public boolean isCalculationInProgress(
985 AlignmentAnnotation alignmentAnnotation)
987 if (!alignmentAnnotation.autoCalculated)
991 if (calculator.workingInvolvedWith(alignmentAnnotation))
993 // System.err.println("grey out ("+alignmentAnnotation.label+")");
999 public void setAlignment(AlignmentI align)
1001 this.alignment = align;
1005 * Clean up references when this viewport is closed
1008 public void dispose()
1011 * defensively null out references to large objects in case
1012 * this object is not garbage collected (as if!)
1015 complementConsensus = null;
1016 strucConsensus = null;
1017 conservation = null;
1019 groupConsensus = null;
1020 groupConservation = null;
1022 hcomplementConsensus = null;
1023 // colour scheme may hold reference to consensus
1024 residueShading = null;
1025 // TODO remove listeners from changeSupport?
1026 changeSupport = null;
1031 public boolean isClosed()
1033 // TODO: check that this isClosed is only true after panel is closed, not
1034 // before it is fully constructed.
1035 return alignment == null;
1039 public AlignCalcManagerI getCalcManager()
1045 * should conservation rows be shown for groups
1047 protected boolean showGroupConservation = false;
1050 * should consensus rows be shown for groups
1052 protected boolean showGroupConsensus = false;
1055 * should consensus profile be rendered by default
1057 protected boolean showSequenceLogo = false;
1060 * should consensus profile be rendered normalised to row height
1062 protected boolean normaliseSequenceLogo = false;
1065 * should consensus histograms be rendered by default
1067 protected boolean showConsensusHistogram = true;
1070 * should hmm profile be rendered by default
1072 protected boolean showHMMSequenceLogo = false;
1075 * should hmm profile be rendered normalised to row height
1077 protected boolean normaliseHMMSequenceLogo = false;
1080 * should information histograms be rendered by default
1082 protected boolean showInformationHistogram = true;
1085 * @return the showConsensusProfile
1088 public boolean isShowSequenceLogo()
1090 return showSequenceLogo;
1094 * @return the showInformationProfile
1097 public boolean isShowHMMSequenceLogo()
1099 return showHMMSequenceLogo;
1103 * @param showSequenceLogo
1106 public void setShowSequenceLogo(boolean showSequenceLogo)
1108 if (showSequenceLogo != this.showSequenceLogo)
1110 // TODO: decouple settings setting from calculation when refactoring
1111 // annotation update method from alignframe to viewport
1112 this.showSequenceLogo = showSequenceLogo;
1113 calculator.updateAnnotationFor(ConsensusThread.class);
1114 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1115 calculator.updateAnnotationFor(StrucConsensusThread.class);
1117 this.showSequenceLogo = showSequenceLogo;
1120 public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo)
1122 if (showHMMSequenceLogo != this.showHMMSequenceLogo)
1124 this.showHMMSequenceLogo = showHMMSequenceLogo;
1125 calculator.updateAnnotationFor(InformationThread.class);
1127 this.showHMMSequenceLogo = showHMMSequenceLogo;
1131 * @param showConsensusHistogram
1132 * the showConsensusHistogram to set
1134 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1136 this.showConsensusHistogram = showConsensusHistogram;
1140 * @param showInformationHistogram
1141 * the showInformationHistogram to set
1143 public void setShowInformationHistogram(boolean showInformationHistogram)
1145 this.showInformationHistogram = showInformationHistogram;
1149 * @return the showGroupConservation
1151 public boolean isShowGroupConservation()
1153 return showGroupConservation;
1157 * @param showGroupConservation
1158 * the showGroupConservation to set
1160 public void setShowGroupConservation(boolean showGroupConservation)
1162 this.showGroupConservation = showGroupConservation;
1166 * @return the showGroupConsensus
1168 public boolean isShowGroupConsensus()
1170 return showGroupConsensus;
1174 * @param showGroupConsensus
1175 * the showGroupConsensus to set
1177 public void setShowGroupConsensus(boolean showGroupConsensus)
1179 this.showGroupConsensus = showGroupConsensus;
1184 * @return flag to indicate if the consensus histogram should be rendered by
1188 public boolean isShowConsensusHistogram()
1190 return this.showConsensusHistogram;
1195 * @return flag to indicate if the information content histogram should be
1196 * rendered by default
1199 public boolean isShowInformationHistogram()
1201 return this.showInformationHistogram;
1205 * when set, updateAlignment will always ensure sequences are of equal length
1207 private boolean padGaps = false;
1210 * when set, alignment should be reordered according to a newly opened tree
1212 public boolean sortByTree = false;
1217 * @return null or the currently selected sequence region
1220 public SequenceGroup getSelectionGroup()
1222 return selectionGroup;
1226 * Set the selection group for this window. Also sets the current alignment as
1227 * the context for the group, if it does not already have one.
1230 * - group holding references to sequences in this alignment view
1234 public void setSelectionGroup(SequenceGroup sg)
1236 selectionGroup = sg;
1237 if (sg != null && sg.getContext() == null)
1239 sg.setContext(alignment);
1243 public void setHiddenColumns(HiddenColumns hidden)
1245 this.alignment.setHiddenColumns(hidden);
1249 public ColumnSelection getColumnSelection()
1255 public void setColumnSelection(ColumnSelection colSel)
1257 this.colSel = colSel;
1260 updateHiddenColumns();
1262 isColSelChanged(true);
1270 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1272 return hiddenRepSequences;
1276 public void setHiddenRepSequences(
1277 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1279 this.hiddenRepSequences = hiddenRepSequences;
1283 public boolean hasSelectedColumns()
1285 ColumnSelection columnSelection = getColumnSelection();
1286 return columnSelection != null && columnSelection.hasSelectedColumns();
1290 public boolean hasHiddenColumns()
1292 return alignment.getHiddenColumns() != null
1293 && alignment.getHiddenColumns().hasHiddenColumns();
1296 public void updateHiddenColumns()
1298 // this method doesn't really do anything now. But - it could, since a
1299 // column Selection could be in the process of modification
1300 // hasHiddenColumns = colSel.hasHiddenColumns();
1304 public boolean hasHiddenRows()
1306 return alignment.getHiddenSequences().getSize() > 0;
1309 protected SequenceGroup selectionGroup;
1311 public void setSequenceSetId(String newid)
1313 if (sequenceSetID != null)
1316 "Warning - overwriting a sequenceSetId for a viewport!");
1318 sequenceSetID = new String(newid);
1322 public String getSequenceSetId()
1324 if (sequenceSetID == null)
1326 sequenceSetID = alignment.hashCode() + "";
1329 return sequenceSetID;
1333 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1336 protected String viewId = null;
1339 public String getViewId()
1343 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1348 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1350 ignoreGapsInConsensusCalculation = b;
1353 updateConsensus(ap);
1354 if (residueShading != null)
1356 residueShading.setThreshold(residueShading.getThreshold(),
1357 ignoreGapsInConsensusCalculation);
1363 public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap)
1365 ignoreBelowBackGroundFrequencyCalculation = b;
1368 updateInformation(ap);
1373 private long sgrouphash = -1, colselhash = -1;
1376 * checks current SelectionGroup against record of last hash value, and
1380 * update the record of last hash value
1382 * @return true if SelectionGroup changed since last call (when b is true)
1384 public boolean isSelectionGroupChanged(boolean b)
1386 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1387 : selectionGroup.hashCode();
1388 if (hc != -1 && hc != sgrouphash)
1400 * checks current colsel against record of last hash value, and optionally
1404 * update the record of last hash value
1405 * @return true if colsel changed since last call (when b is true)
1407 public boolean isColSelChanged(boolean b)
1409 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1410 if (hc != -1 && hc != colselhash)
1422 public boolean isIgnoreGapsConsensus()
1424 return ignoreGapsInConsensusCalculation;
1428 public boolean isIgnoreBelowBackground()
1430 return ignoreBelowBackGroundFrequencyCalculation;
1433 // property change stuff
1434 // JBPNote Prolly only need this in the applet version.
1435 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1438 protected boolean showConservation = true;
1440 protected boolean showQuality = true;
1442 protected boolean showConsensus = true;
1444 protected boolean showOccupancy = true;
1446 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1448 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1450 protected boolean showAutocalculatedAbove;
1453 * when set, view will scroll to show the highlighted position
1455 private boolean followHighlight = true;
1458 * Property change listener for changes in alignment
1463 public void addPropertyChangeListener(
1464 java.beans.PropertyChangeListener listener)
1466 changeSupport.addPropertyChangeListener(listener);
1475 public void removePropertyChangeListener(
1476 java.beans.PropertyChangeListener listener)
1478 changeSupport.removePropertyChangeListener(listener);
1482 * Property change listener for changes in alignment
1491 public void firePropertyChange(String prop, Object oldvalue,
1494 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1497 // common hide/show column stuff
1499 public void hideSelectedColumns()
1501 if (colSel.isEmpty())
1506 colSel.hideSelectedColumns(alignment);
1507 setSelectionGroup(null);
1508 isColSelChanged(true);
1511 public void hideColumns(int start, int end)
1515 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1519 alignment.getHiddenColumns().hideColumns(start, end);
1521 isColSelChanged(true);
1524 public void showColumn(int col)
1526 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1527 isColSelChanged(true);
1530 public void showAllHiddenColumns()
1532 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1533 isColSelChanged(true);
1536 // common hide/show seq stuff
1537 public void showAllHiddenSeqs()
1539 int startSeq = ranges.getStartSeq();
1540 int endSeq = ranges.getEndSeq();
1542 if (alignment.getHiddenSequences().getSize() > 0)
1544 if (selectionGroup == null)
1546 selectionGroup = new SequenceGroup();
1547 selectionGroup.setEndRes(alignment.getWidth() - 1);
1549 List<SequenceI> tmp = alignment.getHiddenSequences()
1550 .showAll(hiddenRepSequences);
1551 for (SequenceI seq : tmp)
1553 selectionGroup.addSequence(seq, false);
1554 setSequenceAnnotationsVisible(seq, true);
1557 hiddenRepSequences = null;
1559 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1561 firePropertyChange("alignment", null, alignment.getSequences());
1562 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1568 public void showSequence(int index)
1570 int startSeq = ranges.getStartSeq();
1571 int endSeq = ranges.getEndSeq();
1573 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1574 hiddenRepSequences);
1577 if (selectionGroup == null)
1579 selectionGroup = new SequenceGroup();
1580 selectionGroup.setEndRes(alignment.getWidth() - 1);
1583 for (SequenceI seq : tmp)
1585 selectionGroup.addSequence(seq, false);
1586 setSequenceAnnotationsVisible(seq, true);
1589 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1591 firePropertyChange("alignment", null, alignment.getSequences());
1596 public void hideAllSelectedSeqs()
1598 if (selectionGroup == null || selectionGroup.getSize() < 1)
1603 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1607 setSelectionGroup(null);
1610 public void hideSequence(SequenceI[] seq)
1613 * cache offset to first visible sequence
1615 int startSeq = ranges.getStartSeq();
1619 for (int i = 0; i < seq.length; i++)
1621 alignment.getHiddenSequences().hideSequence(seq[i]);
1622 setSequenceAnnotationsVisible(seq[i], false);
1624 ranges.setStartSeq(startSeq);
1625 firePropertyChange("alignment", null, alignment.getSequences());
1630 * Hides the specified sequence, or the sequences it represents
1633 * the sequence to hide, or keep as representative
1634 * @param representGroup
1635 * if true, hide the current selection group except for the
1636 * representative sequence
1638 public void hideSequences(SequenceI sequence, boolean representGroup)
1640 if (selectionGroup == null || selectionGroup.getSize() < 1)
1642 hideSequence(new SequenceI[] { sequence });
1648 hideRepSequences(sequence, selectionGroup);
1649 setSelectionGroup(null);
1653 int gsize = selectionGroup.getSize();
1654 SequenceI[] hseqs = selectionGroup.getSequences()
1655 .toArray(new SequenceI[gsize]);
1657 hideSequence(hseqs);
1658 setSelectionGroup(null);
1663 * Set visibility for any annotations for the given sequence.
1667 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1670 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1673 for (AlignmentAnnotation ann : anns)
1675 if (ann.sequenceRef == sequenceI)
1677 ann.visible = visible;
1683 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1685 int sSize = sg.getSize();
1691 if (hiddenRepSequences == null)
1693 hiddenRepSequences = new Hashtable<>();
1696 hiddenRepSequences.put(repSequence, sg);
1698 // Hide all sequences except the repSequence
1699 SequenceI[] seqs = new SequenceI[sSize - 1];
1701 for (int i = 0; i < sSize; i++)
1703 if (sg.getSequenceAt(i) != repSequence)
1705 if (index == sSize - 1)
1710 seqs[index++] = sg.getSequenceAt(i);
1713 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1714 sg.setHidereps(true); // note: not done in 2.7applet
1721 * @return null or the current reference sequence
1723 public SequenceI getReferenceSeq()
1725 return alignment.getSeqrep();
1730 * @return true iff seq is the reference for the alignment
1732 public boolean isReferenceSeq(SequenceI seq)
1734 return alignment.getSeqrep() == seq;
1740 * @return true if there are sequences represented by this sequence that are
1743 public boolean isHiddenRepSequence(SequenceI seq)
1745 return (hiddenRepSequences != null
1746 && hiddenRepSequences.containsKey(seq));
1752 * @return null or a sequence group containing the sequences that seq
1755 public SequenceGroup getRepresentedSequences(SequenceI seq)
1757 return (SequenceGroup) (hiddenRepSequences == null ? null
1758 : hiddenRepSequences.get(seq));
1762 public int adjustForHiddenSeqs(int alignmentIndex)
1764 return alignment.getHiddenSequences()
1765 .adjustForHiddenSeqs(alignmentIndex);
1769 public void invertColumnSelection()
1771 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1775 public SequenceI[] getSelectionAsNewSequence()
1777 SequenceI[] sequences;
1778 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1779 // this was the only caller in the applet for this method
1780 // JBPNote: in applet, this method returned references to the alignment
1781 // sequences, and it did not honour the presence/absence of annotation
1782 // attached to the alignment (probably!)
1783 if (selectionGroup == null || selectionGroup.getSize() == 0)
1785 sequences = alignment.getSequencesArray();
1786 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1787 for (int i = 0; i < sequences.length; i++)
1789 // construct new sequence with subset of visible annotation
1790 sequences[i] = new Sequence(sequences[i], annots);
1795 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1802 public SequenceI[] getSequenceSelection()
1804 SequenceI[] sequences = null;
1805 if (selectionGroup != null)
1807 sequences = selectionGroup.getSequencesInOrder(alignment);
1809 if (sequences == null)
1811 sequences = alignment.getSequencesArray();
1817 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1819 return new CigarArray(alignment, alignment.getHiddenColumns(),
1820 (selectedRegionOnly ? selectionGroup : null));
1824 public jalview.datamodel.AlignmentView getAlignmentView(
1825 boolean selectedOnly)
1827 return getAlignmentView(selectedOnly, false);
1831 public jalview.datamodel.AlignmentView getAlignmentView(
1832 boolean selectedOnly, boolean markGroups)
1834 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1836 alignment.getHiddenColumns() != null
1837 && alignment.getHiddenColumns().hasHiddenColumns(),
1838 selectedOnly, markGroups);
1842 public String[] getViewAsString(boolean selectedRegionOnly)
1844 return getViewAsString(selectedRegionOnly, true);
1848 public String[] getViewAsString(boolean selectedRegionOnly,
1849 boolean exportHiddenSeqs)
1851 String[] selection = null;
1852 SequenceI[] seqs = null;
1854 int start = 0, end = 0;
1855 if (selectedRegionOnly && selectionGroup != null)
1857 iSize = selectionGroup.getSize();
1858 seqs = selectionGroup.getSequencesInOrder(alignment);
1859 start = selectionGroup.getStartRes();
1860 end = selectionGroup.getEndRes() + 1;
1864 if (hasHiddenRows() && exportHiddenSeqs)
1866 AlignmentI fullAlignment = alignment.getHiddenSequences()
1867 .getFullAlignment();
1868 iSize = fullAlignment.getHeight();
1869 seqs = fullAlignment.getSequencesArray();
1870 end = fullAlignment.getWidth();
1874 iSize = alignment.getHeight();
1875 seqs = alignment.getSequencesArray();
1876 end = alignment.getWidth();
1880 selection = new String[iSize];
1881 if (alignment.getHiddenColumns() != null
1882 && alignment.getHiddenColumns().hasHiddenColumns())
1884 selection = alignment.getHiddenColumns()
1885 .getVisibleSequenceStrings(start, end, seqs);
1889 for (i = 0; i < iSize; i++)
1891 selection[i] = seqs[i].getSequenceAsString(start, end);
1899 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1901 ArrayList<int[]> regions = new ArrayList<>();
1907 HiddenColumns hidden = alignment.getHiddenColumns();
1908 if (hidden != null && hidden.hasHiddenColumns())
1912 start = hidden.adjustForHiddenColumns(start);
1915 end = hidden.getHiddenBoundaryRight(start);
1926 regions.add(new int[] { start, end });
1928 if (hidden != null && hidden.hasHiddenColumns())
1930 start = hidden.adjustForHiddenColumns(end);
1931 start = hidden.getHiddenBoundaryLeft(start) + 1;
1933 } while (end < max);
1935 int[][] startEnd = new int[regions.size()][2];
1941 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1942 boolean selectedOnly)
1944 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1945 AlignmentAnnotation[] aa;
1946 if ((aa = alignment.getAlignmentAnnotation()) != null)
1948 for (AlignmentAnnotation annot : aa)
1950 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1951 if (selectedOnly && selectionGroup != null)
1953 alignment.getHiddenColumns().makeVisibleAnnotation(
1954 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1959 alignment.getHiddenColumns().makeVisibleAnnotation(clone);
1968 public boolean isPadGaps()
1974 public void setPadGaps(boolean padGaps)
1976 this.padGaps = padGaps;
1980 * apply any post-edit constraints and trigger any calculations needed after
1981 * an edit has been performed on the alignment
1986 public void alignmentChanged(AlignmentViewPanel ap)
1990 alignment.padGaps();
1992 if (autoCalculateConsensus)
1994 updateConsensus(ap);
1996 if (hconsensus != null && autoCalculateConsensus)
1998 updateConservation(ap);
2000 if (autoCalculateStrucConsensus)
2002 updateStrucConsensus(ap);
2005 updateInformation(ap);
2007 List<SequenceI> hmmSequences;
2008 hmmSequences = alignment.getHMMConsensusSequences(false);
2010 for (SequenceI seq : hmmSequences)
2012 seq.updateHMMMapping();
2015 // Reset endRes of groups if beyond alignment width
2016 int alWidth = alignment.getWidth();
2017 List<SequenceGroup> groups = alignment.getGroups();
2020 for (SequenceGroup sg : groups)
2022 if (sg.getEndRes() > alWidth)
2024 sg.setEndRes(alWidth - 1);
2029 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
2031 selectionGroup.setEndRes(alWidth - 1);
2034 updateAllColourSchemes();
2035 calculator.restartWorkers();
2036 // alignment.adjustSequenceAnnotations();
2040 * reset scope and do calculations for all applied colourschemes on alignment
2042 void updateAllColourSchemes()
2044 ResidueShaderI rs = residueShading;
2047 rs.alignmentChanged(alignment, hiddenRepSequences);
2049 rs.setConsensus(hconsensus);
2050 if (rs.conservationApplied())
2052 rs.setConservation(Conservation.calculateConservation("All",
2053 alignment.getSequences(), 0, alignment.getWidth(), false,
2054 getConsPercGaps(), false));
2058 for (SequenceGroup sg : alignment.getGroups())
2062 sg.cs.alignmentChanged(sg, hiddenRepSequences);
2064 sg.recalcConservation();
2068 protected void initAutoAnnotation()
2070 // TODO: add menu option action that nulls or creates consensus object
2071 // depending on if the user wants to see the annotation or not in a
2072 // specific alignment
2074 if (hconsensus == null && !isDataset)
2076 if (!alignment.isNucleotide())
2085 consensus = new AlignmentAnnotation("Consensus",
2086 MessageManager.getString("label.consensus_descr"),
2087 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2088 initConsensus(consensus);
2092 initComplementConsensus();
2097 * If this is a protein alignment and there are mappings to cDNA, adds the
2098 * cDNA consensus annotation and returns true, else returns false.
2100 public boolean initComplementConsensus()
2102 if (!alignment.isNucleotide())
2104 final List<AlignedCodonFrame> codonMappings = alignment
2106 if (codonMappings != null && !codonMappings.isEmpty())
2108 boolean doConsensus = false;
2109 for (AlignedCodonFrame mapping : codonMappings)
2111 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2112 MapList[] mapLists = mapping.getdnaToProt();
2113 // mapLists can be empty if project load has not finished resolving
2115 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2123 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2125 .getString("label.complement_consensus_descr"),
2126 new Annotation[1], 0f, 100f,
2127 AlignmentAnnotation.BAR_GRAPH);
2128 initConsensus(complementConsensus);
2136 private void initConsensus(AlignmentAnnotation aa)
2139 aa.autoCalculated = true;
2143 alignment.addAnnotation(aa);
2148 public void initInformation()
2150 for (SequenceI seq : alignment.getHMMConsensusSequences(false))
2152 if (!seq.hasHMMAnnotation())
2154 AlignmentAnnotation information;
2155 information = new AlignmentAnnotation(seq.getName(),
2156 MessageManager.getString("label.information_description"),
2157 new Annotation[1], 0f, 6.52f,
2158 AlignmentAnnotation.BAR_GRAPH);
2159 information.hasText = true;
2160 information.autoCalculated = true;
2161 information.hasText = true;
2162 information.autoCalculated = false;
2163 information.sequenceRef = seq;
2164 information.setCalcId("HMM");
2165 this.information.add(information);
2166 hinformation.add(new Profiles(new ProfileI[1]));
2167 alignment.addAnnotation(information);
2168 seq.updateHMMMapping();
2169 seq.setHasInfo(true);
2170 seq.addAlignmentAnnotation(information);
2176 // these should be extracted from the view model - style and settings for
2177 // derived annotation
2178 private void initGapCounts()
2182 gapcounts = new AlignmentAnnotation("Occupancy",
2183 MessageManager.getString("label.occupancy_descr"),
2184 new Annotation[1], 0f, alignment.getHeight(),
2185 AlignmentAnnotation.BAR_GRAPH);
2186 gapcounts.hasText = true;
2187 gapcounts.autoCalculated = true;
2188 gapcounts.scaleColLabel = true;
2189 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2191 alignment.addAnnotation(gapcounts);
2195 private void initConservation()
2197 if (showConservation)
2199 if (conservation == null)
2201 conservation = new AlignmentAnnotation("Conservation",
2202 MessageManager.formatMessage("label.conservation_descr",
2204 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2205 conservation.hasText = true;
2206 conservation.autoCalculated = true;
2207 alignment.addAnnotation(conservation);
2212 private void initQuality()
2216 if (quality == null)
2218 quality = new AlignmentAnnotation("Quality",
2219 MessageManager.getString("label.quality_descr"),
2220 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2221 quality.hasText = true;
2222 quality.autoCalculated = true;
2223 alignment.addAnnotation(quality);
2228 private void initRNAStructure()
2230 if (alignment.hasRNAStructure() && strucConsensus == null)
2232 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2233 MessageManager.getString("label.strucconsensus_descr"),
2234 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2235 strucConsensus.hasText = true;
2236 strucConsensus.autoCalculated = true;
2240 alignment.addAnnotation(strucConsensus);
2248 * @see jalview.api.AlignViewportI#calcPanelHeight()
2251 public int calcPanelHeight()
2253 // setHeight of panels
2254 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2256 int charHeight = getCharHeight();
2259 BitSet graphgrp = new BitSet();
2260 for (AlignmentAnnotation aa : anns)
2264 System.err.println("Null annotation row: ignoring.");
2271 if (aa.graphGroup > -1)
2273 if (graphgrp.get(aa.graphGroup))
2279 graphgrp.set(aa.graphGroup);
2286 aa.height += charHeight;
2296 aa.height += aa.graphHeight;
2304 height += aa.height;
2316 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2317 boolean preserveNewGroupSettings)
2319 boolean updateCalcs = false;
2320 boolean conv = isShowGroupConservation();
2321 boolean cons = isShowGroupConsensus();
2322 boolean showprf = isShowSequenceLogo();
2323 boolean showConsHist = isShowConsensusHistogram();
2324 boolean normLogo = isNormaliseSequenceLogo();
2325 boolean showHMMPrf = isShowHMMSequenceLogo();
2326 boolean showInfoHist = isShowInformationHistogram();
2327 boolean normHMMLogo = isNormaliseHMMSequenceLogo();
2330 * TODO reorder the annotation rows according to group/sequence ordering on
2333 boolean sortg = true;
2335 // remove old automatic annotation
2336 // add any new annotation
2338 // intersect alignment annotation with alignment groups
2340 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2341 List<SequenceGroup> oldrfs = new ArrayList<>();
2344 for (int an = 0; an < aan.length; an++)
2346 if (aan[an].autoCalculated && aan[an].groupRef != null)
2348 oldrfs.add(aan[an].groupRef);
2349 alignment.deleteAnnotation(aan[an], false);
2353 if (alignment.getGroups() != null)
2355 for (SequenceGroup sg : alignment.getGroups())
2357 updateCalcs = false;
2358 if (applyGlobalSettings
2359 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2361 // set defaults for this group's conservation/consensus
2362 sg.setshowSequenceLogo(showprf);
2363 sg.setShowConsensusHistogram(showConsHist);
2364 sg.setNormaliseSequenceLogo(normLogo);
2365 sg.setshowHMMSequenceLogo(showHMMPrf);
2366 sg.setShowInformationHistogram(showInfoHist);
2367 sg.setNormaliseHMMSequenceLogo(normHMMLogo);
2372 alignment.addAnnotation(sg.getConservationRow(), 0);
2377 alignment.addAnnotation(sg.getConsensus(), 0);
2379 // refresh the annotation rows
2382 sg.recalcConservation();
2390 public boolean isDisplayReferenceSeq()
2392 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2396 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2398 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2402 public boolean isColourByReferenceSeq()
2404 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2408 public Color getSequenceColour(SequenceI seq)
2410 Color sqc = sequenceColours.get(seq);
2411 return (sqc == null ? Color.white : sqc);
2415 public void setSequenceColour(SequenceI seq, Color col)
2419 sequenceColours.remove(seq);
2423 sequenceColours.put(seq, col);
2428 public void updateSequenceIdColours()
2430 for (SequenceGroup sg : alignment.getGroups())
2432 if (sg.idColour != null)
2434 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2436 sequenceColours.put(s, sg.idColour);
2443 public void clearSequenceColours()
2445 sequenceColours.clear();
2449 public AlignViewportI getCodingComplement()
2451 return this.codingComplement;
2455 * Set this as the (cDna/protein) complement of the given viewport. Also
2456 * ensures the reverse relationship is set on the given viewport.
2459 public void setCodingComplement(AlignViewportI av)
2463 System.err.println("Ignoring recursive setCodingComplement request");
2467 this.codingComplement = av;
2468 // avoid infinite recursion!
2469 if (av.getCodingComplement() != this)
2471 av.setCodingComplement(this);
2477 public boolean isNucleotide()
2479 return getAlignment() == null ? false : getAlignment().isNucleotide();
2483 public FeaturesDisplayedI getFeaturesDisplayed()
2485 return featuresDisplayed;
2489 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2491 featuresDisplayed = featuresDisplayedI;
2495 public boolean areFeaturesDisplayed()
2497 return featuresDisplayed != null
2498 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2505 * features are displayed if true
2508 public void setShowSequenceFeatures(boolean b)
2510 viewStyle.setShowSequenceFeatures(b);
2514 public boolean isShowSequenceFeatures()
2516 return viewStyle.isShowSequenceFeatures();
2520 public void setShowSequenceFeaturesHeight(boolean selected)
2522 viewStyle.setShowSequenceFeaturesHeight(selected);
2526 public boolean isShowSequenceFeaturesHeight()
2528 return viewStyle.isShowSequenceFeaturesHeight();
2532 public void setShowAnnotation(boolean b)
2534 viewStyle.setShowAnnotation(b);
2538 public boolean isShowAnnotation()
2540 return viewStyle.isShowAnnotation();
2544 public boolean isRightAlignIds()
2546 return viewStyle.isRightAlignIds();
2550 public void setRightAlignIds(boolean rightAlignIds)
2552 viewStyle.setRightAlignIds(rightAlignIds);
2556 public boolean getConservationSelected()
2558 return viewStyle.getConservationSelected();
2562 public void setShowBoxes(boolean state)
2564 viewStyle.setShowBoxes(state);
2569 * @see jalview.api.ViewStyleI#getTextColour()
2572 public Color getTextColour()
2574 return viewStyle.getTextColour();
2579 * @see jalview.api.ViewStyleI#getTextColour2()
2582 public Color getTextColour2()
2584 return viewStyle.getTextColour2();
2589 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2592 public int getThresholdTextColour()
2594 return viewStyle.getThresholdTextColour();
2599 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2602 public boolean isConservationColourSelected()
2604 return viewStyle.isConservationColourSelected();
2609 * @see jalview.api.ViewStyleI#isRenderGaps()
2612 public boolean isRenderGaps()
2614 return viewStyle.isRenderGaps();
2619 * @see jalview.api.ViewStyleI#isShowColourText()
2622 public boolean isShowColourText()
2624 return viewStyle.isShowColourText();
2628 * @param conservationColourSelected
2629 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2632 public void setConservationColourSelected(
2633 boolean conservationColourSelected)
2635 viewStyle.setConservationColourSelected(conservationColourSelected);
2639 * @param showColourText
2640 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2643 public void setShowColourText(boolean showColourText)
2645 viewStyle.setShowColourText(showColourText);
2650 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2653 public void setTextColour(Color textColour)
2655 viewStyle.setTextColour(textColour);
2659 * @param thresholdTextColour
2660 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2663 public void setThresholdTextColour(int thresholdTextColour)
2665 viewStyle.setThresholdTextColour(thresholdTextColour);
2669 * @param textColour2
2670 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2673 public void setTextColour2(Color textColour2)
2675 viewStyle.setTextColour2(textColour2);
2679 public ViewStyleI getViewStyle()
2681 return new ViewStyle(viewStyle);
2685 public void setViewStyle(ViewStyleI settingsForView)
2687 viewStyle = new ViewStyle(settingsForView);
2688 if (residueShading != null)
2690 residueShading.setConservationApplied(
2691 settingsForView.isConservationColourSelected());
2696 public boolean sameStyle(ViewStyleI them)
2698 return viewStyle.sameStyle(them);
2703 * @see jalview.api.ViewStyleI#getIdWidth()
2706 public int getIdWidth()
2708 return viewStyle.getIdWidth();
2713 * @see jalview.api.ViewStyleI#setIdWidth(int)
2716 public void setIdWidth(int i)
2718 viewStyle.setIdWidth(i);
2723 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2726 public boolean isCentreColumnLabels()
2728 return viewStyle.isCentreColumnLabels();
2732 * @param centreColumnLabels
2733 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2736 public void setCentreColumnLabels(boolean centreColumnLabels)
2738 viewStyle.setCentreColumnLabels(centreColumnLabels);
2743 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2746 public void setShowDBRefs(boolean showdbrefs)
2748 viewStyle.setShowDBRefs(showdbrefs);
2753 * @see jalview.api.ViewStyleI#isShowDBRefs()
2756 public boolean isShowDBRefs()
2758 return viewStyle.isShowDBRefs();
2763 * @see jalview.api.ViewStyleI#isShowNPFeats()
2766 public boolean isShowNPFeats()
2768 return viewStyle.isShowNPFeats();
2772 * @param shownpfeats
2773 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2776 public void setShowNPFeats(boolean shownpfeats)
2778 viewStyle.setShowNPFeats(shownpfeats);
2781 public abstract StructureSelectionManager getStructureSelectionManager();
2784 * Add one command to the command history list.
2788 public void addToHistoryList(CommandI command)
2790 if (this.historyList != null)
2792 this.historyList.push(command);
2793 broadcastCommand(command, false);
2797 protected void broadcastCommand(CommandI command, boolean undo)
2799 getStructureSelectionManager().commandPerformed(command, undo,
2804 * Add one command to the command redo list.
2808 public void addToRedoList(CommandI command)
2810 if (this.redoList != null)
2812 this.redoList.push(command);
2814 broadcastCommand(command, true);
2818 * Clear the command redo list.
2820 public void clearRedoList()
2822 if (this.redoList != null)
2824 this.redoList.clear();
2828 public void setHistoryList(Deque<CommandI> list)
2830 this.historyList = list;
2833 public Deque<CommandI> getHistoryList()
2835 return this.historyList;
2838 public void setRedoList(Deque<CommandI> list)
2840 this.redoList = list;
2843 public Deque<CommandI> getRedoList()
2845 return this.redoList;
2849 public VamsasSource getVamsasSource()
2854 public SequenceAnnotationOrder getSortAnnotationsBy()
2856 return sortAnnotationsBy;
2859 public void setSortAnnotationsBy(
2860 SequenceAnnotationOrder sortAnnotationsBy)
2862 this.sortAnnotationsBy = sortAnnotationsBy;
2865 public boolean isShowAutocalculatedAbove()
2867 return showAutocalculatedAbove;
2870 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2872 this.showAutocalculatedAbove = showAutocalculatedAbove;
2876 public boolean isScaleProteinAsCdna()
2878 return viewStyle.isScaleProteinAsCdna();
2882 public void setScaleProteinAsCdna(boolean b)
2884 viewStyle.setScaleProteinAsCdna(b);
2888 public boolean isProteinFontAsCdna()
2890 return viewStyle.isProteinFontAsCdna();
2894 public void setProteinFontAsCdna(boolean b)
2896 viewStyle.setProteinFontAsCdna(b);
2900 * @return true if view should scroll to show the highlighted region of a
2905 public final boolean isFollowHighlight()
2907 return followHighlight;
2911 public final void setFollowHighlight(boolean b)
2913 this.followHighlight = b;
2917 public ViewportRanges getRanges()
2923 * Helper method to populate the SearchResults with the location in the
2924 * complementary alignment to scroll to, in order to match this one.
2927 * the SearchResults to add to
2928 * @return the offset (below top of visible region) of the matched sequence
2930 protected int findComplementScrollTarget(SearchResultsI sr)
2932 final AlignViewportI complement = getCodingComplement();
2933 if (complement == null || !complement.isFollowHighlight())
2937 boolean iAmProtein = !getAlignment().isNucleotide();
2938 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2939 : complement.getAlignment();
2940 if (proteinAlignment == null)
2944 final List<AlignedCodonFrame> mappings = proteinAlignment
2948 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2949 * residue in the middle column of the visible region. Scroll the
2950 * complementary alignment to line up the corresponding residue.
2953 SequenceI sequence = null;
2956 * locate 'middle' column (true middle if an odd number visible, left of
2957 * middle if an even number visible)
2959 int middleColumn = ranges.getStartRes()
2960 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2961 final HiddenSequences hiddenSequences = getAlignment()
2962 .getHiddenSequences();
2965 * searching to the bottom of the alignment gives smoother scrolling across
2966 * all gapped visible regions
2968 int lastSeq = alignment.getHeight() - 1;
2969 List<AlignedCodonFrame> seqMappings = null;
2970 for (int seqNo = ranges
2971 .getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2973 sequence = getAlignment().getSequenceAt(seqNo);
2974 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2978 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2982 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2984 getCodingComplement().getAlignment().getSequences());
2985 if (!seqMappings.isEmpty())
2991 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2994 * No ungapped mapped sequence in middle column - do nothing
2998 MappingUtils.addSearchResults(sr, sequence,
2999 sequence.findPosition(middleColumn), seqMappings);
3004 * synthesize a column selection if none exists so it covers the given
3005 * selection group. if wholewidth is false, no column selection is made if the
3006 * selection group covers the whole alignment width.
3011 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
3014 if (sg != null && (sgs = sg.getStartRes()) >= 0
3015 && sg.getStartRes() <= (sge = sg.getEndRes())
3016 && !this.hasSelectedColumns())
3018 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
3025 colSel = new ColumnSelection();
3027 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
3029 colSel.addElement(cspos);
3035 * hold status of current selection group - defined on alignment or not.
3037 private boolean selectionIsDefinedGroup = false;
3040 public boolean isSelectionDefinedGroup()
3042 if (selectionGroup == null)
3046 if (isSelectionGroupChanged(true))
3048 selectionIsDefinedGroup = false;
3049 List<SequenceGroup> gps = alignment.getGroups();
3050 if (gps == null || gps.size() == 0)
3052 selectionIsDefinedGroup = false;
3056 selectionIsDefinedGroup = gps.contains(selectionGroup);
3059 return selectionGroup.isDefined() || selectionIsDefinedGroup;
3063 * null, or currently highlighted results on this view
3065 private SearchResultsI searchResults = null;
3068 public boolean hasSearchResults()
3070 return searchResults != null;
3074 public void setSearchResults(SearchResultsI results)
3076 searchResults = results;
3080 public SearchResultsI getSearchResults()
3082 return searchResults;
3086 * get the consensus sequence as displayed under the PID consensus annotation
3089 * @return consensus sequence as a new sequence object
3091 public SequenceI getConsensusSeq()
3093 if (consensus == null)
3095 updateConsensus(null);
3097 if (consensus == null)
3101 StringBuffer seqs = new StringBuffer();
3102 for (int i = 0; i < consensus.annotations.length; i++)
3104 Annotation annotation = consensus.annotations[i];
3105 if (annotation != null)
3107 String description = annotation.description;
3108 if (description != null && description.startsWith("["))
3110 // consensus is a tie - just pick the first one
3111 seqs.append(description.charAt(1));
3115 seqs.append(annotation.displayCharacter);
3120 SequenceI sq = new Sequence("Consensus", seqs.toString());
3121 sq.setDescription("Percentage Identity Consensus "
3122 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));