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 hinformation.set(index, info);
786 public List<ProfilesI> getSequenceInformationHashes()
792 public ProfilesI getSequenceInformationHash(int index)
794 return hinformation.get(index);
798 public Hashtable[] getComplementConsensusHash()
800 return hcomplementConsensus;
804 public Hashtable[] getRnaStructureConsensusHash()
806 return hStrucConsensus;
810 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
812 this.hStrucConsensus = hStrucConsensus;
817 public AlignmentAnnotation getAlignmentQualityAnnot()
823 public AlignmentAnnotation getAlignmentConservationAnnotation()
829 public AlignmentAnnotation getAlignmentConsensusAnnotation()
835 public List<AlignmentAnnotation> getInformationAnnotations()
841 public AlignmentAnnotation getInformationAnnotation(int index)
843 return information.get(index);
847 public AlignmentAnnotation getAlignmentGapAnnotation()
853 public AlignmentAnnotation getComplementConsensusAnnotation()
855 return complementConsensus;
859 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
861 return strucConsensus;
864 protected AlignCalcManagerI calculator = new AlignCalcManager();
867 * trigger update of conservation annotation
869 public void updateConservation(final AlignmentViewPanel ap)
871 // see note in mantis : issue number 8585
872 if (alignment.isNucleotide()
873 || (conservation == null && quality == null)
874 || !autoCalculateConsensus)
878 if (calculator.getRegisteredWorkersOfClass(
879 jalview.workers.ConservationThread.class) == null)
881 calculator.registerWorker(
882 new jalview.workers.ConservationThread(this, ap));
887 * trigger update of consensus annotation
889 public void updateConsensus(final AlignmentViewPanel ap)
891 // see note in mantis : issue number 8585
892 if (consensus == null || !autoCalculateConsensus)
897 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
899 calculator.registerWorker(new ConsensusThread(this, ap));
903 * A separate thread to compute cDNA consensus for a protein alignment
904 * which has mapping to cDNA
906 final AlignmentI al = this.getAlignment();
907 if (!al.isNucleotide() && al.getCodonFrames() != null
908 && !al.getCodonFrames().isEmpty())
911 * fudge - check first for protein-to-nucleotide mappings
912 * (we don't want to do this for protein-to-protein)
914 boolean doConsensus = false;
915 for (AlignedCodonFrame mapping : al.getCodonFrames())
917 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
918 MapList[] mapLists = mapping.getdnaToProt();
919 // mapLists can be empty if project load has not finished resolving seqs
920 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
928 if (calculator.getRegisteredWorkersOfClass(
929 ComplementConsensusThread.class) == null)
932 .registerWorker(new ComplementConsensusThread(this, ap));
939 * trigger update of information annotation
942 public void updateInformation(final AlignmentViewPanel ap)
945 .getRegisteredWorkersOfClass(InformationThread.class) == null)
947 calculator.registerWorker(new InformationThread(this, ap));
952 // --------START Structure Conservation
953 public void updateStrucConsensus(final AlignmentViewPanel ap)
955 if (autoCalculateStrucConsensus && strucConsensus == null
956 && alignment.isNucleotide() && alignment.hasRNAStructure())
958 // secondary structure has been added - so init the consensus line
962 // see note in mantis : issue number 8585
963 if (strucConsensus == null || !autoCalculateStrucConsensus)
967 if (calculator.getRegisteredWorkersOfClass(
968 StrucConsensusThread.class) == null)
970 calculator.registerWorker(new StrucConsensusThread(this, ap));
974 public boolean isCalcInProgress()
976 return calculator.isWorking();
980 public boolean isCalculationInProgress(
981 AlignmentAnnotation alignmentAnnotation)
983 if (!alignmentAnnotation.autoCalculated)
987 if (calculator.workingInvolvedWith(alignmentAnnotation))
989 // System.err.println("grey out ("+alignmentAnnotation.label+")");
995 public void setAlignment(AlignmentI align)
997 this.alignment = align;
1001 * Clean up references when this viewport is closed
1004 public void dispose()
1007 * defensively null out references to large objects in case
1008 * this object is not garbage collected (as if!)
1011 complementConsensus = null;
1012 strucConsensus = null;
1013 conservation = null;
1015 groupConsensus = null;
1016 groupConservation = null;
1018 hcomplementConsensus = null;
1019 // colour scheme may hold reference to consensus
1020 residueShading = null;
1021 // TODO remove listeners from changeSupport?
1022 changeSupport = null;
1027 public boolean isClosed()
1029 // TODO: check that this isClosed is only true after panel is closed, not
1030 // before it is fully constructed.
1031 return alignment == null;
1035 public AlignCalcManagerI getCalcManager()
1041 * should conservation rows be shown for groups
1043 protected boolean showGroupConservation = false;
1046 * should consensus rows be shown for groups
1048 protected boolean showGroupConsensus = false;
1051 * should consensus profile be rendered by default
1053 protected boolean showSequenceLogo = false;
1056 * should consensus profile be rendered normalised to row height
1058 protected boolean normaliseSequenceLogo = false;
1061 * should consensus histograms be rendered by default
1063 protected boolean showConsensusHistogram = true;
1066 * should hmm profile be rendered by default
1068 protected boolean showHMMSequenceLogo = false;
1071 * should hmm profile be rendered normalised to row height
1073 protected boolean normaliseHMMSequenceLogo = false;
1076 * should information histograms be rendered by default
1078 protected boolean showInformationHistogram = true;
1081 * @return the showConsensusProfile
1084 public boolean isShowSequenceLogo()
1086 return showSequenceLogo;
1090 * @return the showInformationProfile
1093 public boolean isShowHMMSequenceLogo()
1095 return showHMMSequenceLogo;
1099 * @param showSequenceLogo
1102 public void setShowSequenceLogo(boolean showSequenceLogo)
1104 if (showSequenceLogo != this.showSequenceLogo)
1106 // TODO: decouple settings setting from calculation when refactoring
1107 // annotation update method from alignframe to viewport
1108 this.showSequenceLogo = showSequenceLogo;
1109 calculator.updateAnnotationFor(ConsensusThread.class);
1110 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1111 calculator.updateAnnotationFor(StrucConsensusThread.class);
1113 this.showSequenceLogo = showSequenceLogo;
1116 public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo)
1118 if (showHMMSequenceLogo != this.showHMMSequenceLogo)
1120 this.showHMMSequenceLogo = showHMMSequenceLogo;
1121 calculator.updateAnnotationFor(InformationThread.class);
1123 this.showHMMSequenceLogo = showHMMSequenceLogo;
1127 * @param showConsensusHistogram
1128 * the showConsensusHistogram to set
1130 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1132 this.showConsensusHistogram = showConsensusHistogram;
1136 * @param showInformationHistogram
1137 * the showInformationHistogram to set
1139 public void setShowInformationHistogram(boolean showInformationHistogram)
1141 this.showInformationHistogram = showInformationHistogram;
1145 * @return the showGroupConservation
1147 public boolean isShowGroupConservation()
1149 return showGroupConservation;
1153 * @param showGroupConservation
1154 * the showGroupConservation to set
1156 public void setShowGroupConservation(boolean showGroupConservation)
1158 this.showGroupConservation = showGroupConservation;
1162 * @return the showGroupConsensus
1164 public boolean isShowGroupConsensus()
1166 return showGroupConsensus;
1170 * @param showGroupConsensus
1171 * the showGroupConsensus to set
1173 public void setShowGroupConsensus(boolean showGroupConsensus)
1175 this.showGroupConsensus = showGroupConsensus;
1180 * @return flag to indicate if the consensus histogram should be rendered by
1184 public boolean isShowConsensusHistogram()
1186 return this.showConsensusHistogram;
1191 * @return flag to indicate if the information content histogram should be
1192 * rendered by default
1195 public boolean isShowInformationHistogram()
1197 return this.showInformationHistogram;
1201 * when set, updateAlignment will always ensure sequences are of equal length
1203 private boolean padGaps = false;
1206 * when set, alignment should be reordered according to a newly opened tree
1208 public boolean sortByTree = false;
1213 * @return null or the currently selected sequence region
1216 public SequenceGroup getSelectionGroup()
1218 return selectionGroup;
1222 * Set the selection group for this window. Also sets the current alignment as
1223 * the context for the group, if it does not already have one.
1226 * - group holding references to sequences in this alignment view
1230 public void setSelectionGroup(SequenceGroup sg)
1232 selectionGroup = sg;
1233 if (sg != null && sg.getContext() == null)
1235 sg.setContext(alignment);
1239 public void setHiddenColumns(HiddenColumns hidden)
1241 this.alignment.setHiddenColumns(hidden);
1245 public ColumnSelection getColumnSelection()
1251 public void setColumnSelection(ColumnSelection colSel)
1253 this.colSel = colSel;
1256 updateHiddenColumns();
1258 isColSelChanged(true);
1266 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1268 return hiddenRepSequences;
1272 public void setHiddenRepSequences(
1273 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1275 this.hiddenRepSequences = hiddenRepSequences;
1279 public boolean hasSelectedColumns()
1281 ColumnSelection columnSelection = getColumnSelection();
1282 return columnSelection != null && columnSelection.hasSelectedColumns();
1286 public boolean hasHiddenColumns()
1288 return alignment.getHiddenColumns() != null
1289 && alignment.getHiddenColumns().hasHiddenColumns();
1292 public void updateHiddenColumns()
1294 // this method doesn't really do anything now. But - it could, since a
1295 // column Selection could be in the process of modification
1296 // hasHiddenColumns = colSel.hasHiddenColumns();
1300 public boolean hasHiddenRows()
1302 return alignment.getHiddenSequences().getSize() > 0;
1305 protected SequenceGroup selectionGroup;
1307 public void setSequenceSetId(String newid)
1309 if (sequenceSetID != null)
1312 "Warning - overwriting a sequenceSetId for a viewport!");
1314 sequenceSetID = new String(newid);
1318 public String getSequenceSetId()
1320 if (sequenceSetID == null)
1322 sequenceSetID = alignment.hashCode() + "";
1325 return sequenceSetID;
1329 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1332 protected String viewId = null;
1335 public String getViewId()
1339 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1344 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1346 ignoreGapsInConsensusCalculation = b;
1349 updateConsensus(ap);
1350 if (residueShading != null)
1352 residueShading.setThreshold(residueShading.getThreshold(),
1353 ignoreGapsInConsensusCalculation);
1359 public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap)
1361 ignoreBelowBackGroundFrequencyCalculation = b;
1364 updateInformation(ap);
1369 private long sgrouphash = -1, colselhash = -1;
1372 * checks current SelectionGroup against record of last hash value, and
1376 * update the record of last hash value
1378 * @return true if SelectionGroup changed since last call (when b is true)
1380 public boolean isSelectionGroupChanged(boolean b)
1382 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1383 : selectionGroup.hashCode();
1384 if (hc != -1 && hc != sgrouphash)
1396 * checks current colsel against record of last hash value, and optionally
1400 * update the record of last hash value
1401 * @return true if colsel changed since last call (when b is true)
1403 public boolean isColSelChanged(boolean b)
1405 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1406 if (hc != -1 && hc != colselhash)
1418 public boolean isIgnoreGapsConsensus()
1420 return ignoreGapsInConsensusCalculation;
1424 public boolean isIgnoreBelowBackground()
1426 return ignoreBelowBackGroundFrequencyCalculation;
1429 // property change stuff
1430 // JBPNote Prolly only need this in the applet version.
1431 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1434 protected boolean showConservation = true;
1436 protected boolean showQuality = true;
1438 protected boolean showConsensus = true;
1440 protected boolean showOccupancy = true;
1442 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1444 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1446 protected boolean showAutocalculatedAbove;
1449 * when set, view will scroll to show the highlighted position
1451 private boolean followHighlight = true;
1454 * Property change listener for changes in alignment
1459 public void addPropertyChangeListener(
1460 java.beans.PropertyChangeListener listener)
1462 changeSupport.addPropertyChangeListener(listener);
1471 public void removePropertyChangeListener(
1472 java.beans.PropertyChangeListener listener)
1474 changeSupport.removePropertyChangeListener(listener);
1478 * Property change listener for changes in alignment
1487 public void firePropertyChange(String prop, Object oldvalue,
1490 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1493 // common hide/show column stuff
1495 public void hideSelectedColumns()
1497 if (colSel.isEmpty())
1502 colSel.hideSelectedColumns(alignment);
1503 setSelectionGroup(null);
1504 isColSelChanged(true);
1507 public void hideColumns(int start, int end)
1511 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1515 alignment.getHiddenColumns().hideColumns(start, end);
1517 isColSelChanged(true);
1520 public void showColumn(int col)
1522 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1523 isColSelChanged(true);
1526 public void showAllHiddenColumns()
1528 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1529 isColSelChanged(true);
1532 // common hide/show seq stuff
1533 public void showAllHiddenSeqs()
1535 int startSeq = ranges.getStartSeq();
1536 int endSeq = ranges.getEndSeq();
1538 if (alignment.getHiddenSequences().getSize() > 0)
1540 if (selectionGroup == null)
1542 selectionGroup = new SequenceGroup();
1543 selectionGroup.setEndRes(alignment.getWidth() - 1);
1545 List<SequenceI> tmp = alignment.getHiddenSequences()
1546 .showAll(hiddenRepSequences);
1547 for (SequenceI seq : tmp)
1549 selectionGroup.addSequence(seq, false);
1550 setSequenceAnnotationsVisible(seq, true);
1553 hiddenRepSequences = null;
1555 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1557 firePropertyChange("alignment", null, alignment.getSequences());
1558 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1564 public void showSequence(int index)
1566 int startSeq = ranges.getStartSeq();
1567 int endSeq = ranges.getEndSeq();
1569 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1570 hiddenRepSequences);
1573 if (selectionGroup == null)
1575 selectionGroup = new SequenceGroup();
1576 selectionGroup.setEndRes(alignment.getWidth() - 1);
1579 for (SequenceI seq : tmp)
1581 selectionGroup.addSequence(seq, false);
1582 setSequenceAnnotationsVisible(seq, true);
1585 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1587 firePropertyChange("alignment", null, alignment.getSequences());
1592 public void hideAllSelectedSeqs()
1594 if (selectionGroup == null || selectionGroup.getSize() < 1)
1599 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1603 setSelectionGroup(null);
1606 public void hideSequence(SequenceI[] seq)
1609 * cache offset to first visible sequence
1611 int startSeq = ranges.getStartSeq();
1615 for (int i = 0; i < seq.length; i++)
1617 alignment.getHiddenSequences().hideSequence(seq[i]);
1618 setSequenceAnnotationsVisible(seq[i], false);
1620 ranges.setStartSeq(startSeq);
1621 firePropertyChange("alignment", null, alignment.getSequences());
1626 * Hides the specified sequence, or the sequences it represents
1629 * the sequence to hide, or keep as representative
1630 * @param representGroup
1631 * if true, hide the current selection group except for the
1632 * representative sequence
1634 public void hideSequences(SequenceI sequence, boolean representGroup)
1636 if (selectionGroup == null || selectionGroup.getSize() < 1)
1638 hideSequence(new SequenceI[] { sequence });
1644 hideRepSequences(sequence, selectionGroup);
1645 setSelectionGroup(null);
1649 int gsize = selectionGroup.getSize();
1650 SequenceI[] hseqs = selectionGroup.getSequences()
1651 .toArray(new SequenceI[gsize]);
1653 hideSequence(hseqs);
1654 setSelectionGroup(null);
1659 * Set visibility for any annotations for the given sequence.
1663 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1666 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1669 for (AlignmentAnnotation ann : anns)
1671 if (ann.sequenceRef == sequenceI)
1673 ann.visible = visible;
1679 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1681 int sSize = sg.getSize();
1687 if (hiddenRepSequences == null)
1689 hiddenRepSequences = new Hashtable<>();
1692 hiddenRepSequences.put(repSequence, sg);
1694 // Hide all sequences except the repSequence
1695 SequenceI[] seqs = new SequenceI[sSize - 1];
1697 for (int i = 0; i < sSize; i++)
1699 if (sg.getSequenceAt(i) != repSequence)
1701 if (index == sSize - 1)
1706 seqs[index++] = sg.getSequenceAt(i);
1709 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1710 sg.setHidereps(true); // note: not done in 2.7applet
1717 * @return null or the current reference sequence
1719 public SequenceI getReferenceSeq()
1721 return alignment.getSeqrep();
1726 * @return true iff seq is the reference for the alignment
1728 public boolean isReferenceSeq(SequenceI seq)
1730 return alignment.getSeqrep() == seq;
1736 * @return true if there are sequences represented by this sequence that are
1739 public boolean isHiddenRepSequence(SequenceI seq)
1741 return (hiddenRepSequences != null
1742 && hiddenRepSequences.containsKey(seq));
1748 * @return null or a sequence group containing the sequences that seq
1751 public SequenceGroup getRepresentedSequences(SequenceI seq)
1753 return (SequenceGroup) (hiddenRepSequences == null ? null
1754 : hiddenRepSequences.get(seq));
1758 public int adjustForHiddenSeqs(int alignmentIndex)
1760 return alignment.getHiddenSequences()
1761 .adjustForHiddenSeqs(alignmentIndex);
1765 public void invertColumnSelection()
1767 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1771 public SequenceI[] getSelectionAsNewSequence()
1773 SequenceI[] sequences;
1774 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1775 // this was the only caller in the applet for this method
1776 // JBPNote: in applet, this method returned references to the alignment
1777 // sequences, and it did not honour the presence/absence of annotation
1778 // attached to the alignment (probably!)
1779 if (selectionGroup == null || selectionGroup.getSize() == 0)
1781 sequences = alignment.getSequencesArray();
1782 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1783 for (int i = 0; i < sequences.length; i++)
1785 // construct new sequence with subset of visible annotation
1786 sequences[i] = new Sequence(sequences[i], annots);
1791 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1798 public SequenceI[] getSequenceSelection()
1800 SequenceI[] sequences = null;
1801 if (selectionGroup != null)
1803 sequences = selectionGroup.getSequencesInOrder(alignment);
1805 if (sequences == null)
1807 sequences = alignment.getSequencesArray();
1813 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1815 return new CigarArray(alignment, alignment.getHiddenColumns(),
1816 (selectedRegionOnly ? selectionGroup : null));
1820 public jalview.datamodel.AlignmentView getAlignmentView(
1821 boolean selectedOnly)
1823 return getAlignmentView(selectedOnly, false);
1827 public jalview.datamodel.AlignmentView getAlignmentView(
1828 boolean selectedOnly, boolean markGroups)
1830 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1832 alignment.getHiddenColumns() != null
1833 && alignment.getHiddenColumns().hasHiddenColumns(),
1834 selectedOnly, markGroups);
1838 public String[] getViewAsString(boolean selectedRegionOnly)
1840 return getViewAsString(selectedRegionOnly, true);
1844 public String[] getViewAsString(boolean selectedRegionOnly,
1845 boolean exportHiddenSeqs)
1847 String[] selection = null;
1848 SequenceI[] seqs = null;
1850 int start = 0, end = 0;
1851 if (selectedRegionOnly && selectionGroup != null)
1853 iSize = selectionGroup.getSize();
1854 seqs = selectionGroup.getSequencesInOrder(alignment);
1855 start = selectionGroup.getStartRes();
1856 end = selectionGroup.getEndRes() + 1;
1860 if (hasHiddenRows() && exportHiddenSeqs)
1862 AlignmentI fullAlignment = alignment.getHiddenSequences()
1863 .getFullAlignment();
1864 iSize = fullAlignment.getHeight();
1865 seqs = fullAlignment.getSequencesArray();
1866 end = fullAlignment.getWidth();
1870 iSize = alignment.getHeight();
1871 seqs = alignment.getSequencesArray();
1872 end = alignment.getWidth();
1876 selection = new String[iSize];
1877 if (alignment.getHiddenColumns() != null
1878 && alignment.getHiddenColumns().hasHiddenColumns())
1880 selection = alignment.getHiddenColumns()
1881 .getVisibleSequenceStrings(start, end, seqs);
1885 for (i = 0; i < iSize; i++)
1887 selection[i] = seqs[i].getSequenceAsString(start, end);
1895 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1897 ArrayList<int[]> regions = new ArrayList<>();
1903 HiddenColumns hidden = alignment.getHiddenColumns();
1904 if (hidden != null && hidden.hasHiddenColumns())
1908 start = hidden.adjustForHiddenColumns(start);
1911 end = hidden.getHiddenBoundaryRight(start);
1922 regions.add(new int[] { start, end });
1924 if (hidden != null && hidden.hasHiddenColumns())
1926 start = hidden.adjustForHiddenColumns(end);
1927 start = hidden.getHiddenBoundaryLeft(start) + 1;
1929 } while (end < max);
1931 int[][] startEnd = new int[regions.size()][2];
1937 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1938 boolean selectedOnly)
1940 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1941 AlignmentAnnotation[] aa;
1942 if ((aa = alignment.getAlignmentAnnotation()) != null)
1944 for (AlignmentAnnotation annot : aa)
1946 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1947 if (selectedOnly && selectionGroup != null)
1949 alignment.getHiddenColumns().makeVisibleAnnotation(
1950 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1955 alignment.getHiddenColumns().makeVisibleAnnotation(clone);
1964 public boolean isPadGaps()
1970 public void setPadGaps(boolean padGaps)
1972 this.padGaps = padGaps;
1976 * apply any post-edit constraints and trigger any calculations needed after
1977 * an edit has been performed on the alignment
1982 public void alignmentChanged(AlignmentViewPanel ap)
1986 alignment.padGaps();
1988 if (autoCalculateConsensus)
1990 updateConsensus(ap);
1992 if (hconsensus != null && autoCalculateConsensus)
1994 updateConservation(ap);
1996 if (autoCalculateStrucConsensus)
1998 updateStrucConsensus(ap);
2000 updateInformation(ap);
2002 List<SequenceI> hmmSequences;
2003 hmmSequences = alignment.getHMMConsensusSequences(false);
2005 for (SequenceI seq : hmmSequences)
2007 seq.updateHMMMapping();
2010 // Reset endRes of groups if beyond alignment width
2011 int alWidth = alignment.getWidth();
2012 List<SequenceGroup> groups = alignment.getGroups();
2015 for (SequenceGroup sg : groups)
2017 if (sg.getEndRes() > alWidth)
2019 sg.setEndRes(alWidth - 1);
2024 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
2026 selectionGroup.setEndRes(alWidth - 1);
2029 updateAllColourSchemes();
2030 calculator.restartWorkers();
2031 // alignment.adjustSequenceAnnotations();
2035 * reset scope and do calculations for all applied colourschemes on alignment
2037 void updateAllColourSchemes()
2039 ResidueShaderI rs = residueShading;
2042 rs.alignmentChanged(alignment, hiddenRepSequences);
2044 rs.setConsensus(hconsensus);
2045 if (rs.conservationApplied())
2047 rs.setConservation(Conservation.calculateConservation("All",
2048 alignment.getSequences(), 0, alignment.getWidth(), false,
2049 getConsPercGaps(), false));
2053 for (SequenceGroup sg : alignment.getGroups())
2057 sg.cs.alignmentChanged(sg, hiddenRepSequences);
2059 sg.recalcConservation();
2063 protected void initAutoAnnotation()
2065 // TODO: add menu option action that nulls or creates consensus object
2066 // depending on if the user wants to see the annotation or not in a
2067 // specific alignment
2069 if (hconsensus == null && !isDataset)
2071 if (!alignment.isNucleotide())
2080 consensus = new AlignmentAnnotation("Consensus",
2081 MessageManager.getString("label.consensus_descr"),
2082 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2083 initConsensus(consensus);
2087 initComplementConsensus();
2092 * If this is a protein alignment and there are mappings to cDNA, adds the
2093 * cDNA consensus annotation and returns true, else returns false.
2095 public boolean initComplementConsensus()
2097 if (!alignment.isNucleotide())
2099 final List<AlignedCodonFrame> codonMappings = alignment
2101 if (codonMappings != null && !codonMappings.isEmpty())
2103 boolean doConsensus = false;
2104 for (AlignedCodonFrame mapping : codonMappings)
2106 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2107 MapList[] mapLists = mapping.getdnaToProt();
2108 // mapLists can be empty if project load has not finished resolving
2110 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2118 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2120 .getString("label.complement_consensus_descr"),
2121 new Annotation[1], 0f, 100f,
2122 AlignmentAnnotation.BAR_GRAPH);
2123 initConsensus(complementConsensus);
2131 private void initConsensus(AlignmentAnnotation aa)
2134 aa.autoCalculated = true;
2138 alignment.addAnnotation(aa);
2143 public void initInformation()
2145 for (SequenceI seq : alignment.getHMMConsensusSequences(false))
2147 if (!seq.hasHMMAnnotation())
2149 AlignmentAnnotation information;
2150 information = new AlignmentAnnotation(seq.getName(),
2151 MessageManager.getString("label.information_description"),
2152 new Annotation[1], 0f, 6.52f,
2153 AlignmentAnnotation.BAR_GRAPH);
2154 information.hasText = true;
2155 information.autoCalculated = true;
2156 information.hasText = true;
2157 information.autoCalculated = false;
2158 information.sequenceRef = seq;
2159 information.setCalcId("HMM annotation");
2160 this.information.add(information);
2161 hinformation.add(new Profiles(new ProfileI[1]));
2162 alignment.addAnnotation(information);
2163 seq.updateHMMMapping();
2164 seq.setHasInfo(true);
2165 seq.addAlignmentAnnotation(information);
2171 // these should be extracted from the view model - style and settings for
2172 // derived annotation
2173 private void initGapCounts()
2177 gapcounts = new AlignmentAnnotation("Occupancy",
2178 MessageManager.getString("label.occupancy_descr"),
2179 new Annotation[1], 0f, alignment.getHeight(),
2180 AlignmentAnnotation.BAR_GRAPH);
2181 gapcounts.hasText = true;
2182 gapcounts.autoCalculated = true;
2183 gapcounts.scaleColLabel = true;
2184 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2186 alignment.addAnnotation(gapcounts);
2190 private void initConservation()
2192 if (showConservation)
2194 if (conservation == null)
2196 conservation = new AlignmentAnnotation("Conservation",
2197 MessageManager.formatMessage("label.conservation_descr",
2199 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2200 conservation.hasText = true;
2201 conservation.autoCalculated = true;
2202 alignment.addAnnotation(conservation);
2207 private void initQuality()
2211 if (quality == null)
2213 quality = new AlignmentAnnotation("Quality",
2214 MessageManager.getString("label.quality_descr"),
2215 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2216 quality.hasText = true;
2217 quality.autoCalculated = true;
2218 alignment.addAnnotation(quality);
2223 private void initRNAStructure()
2225 if (alignment.hasRNAStructure() && strucConsensus == null)
2227 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2228 MessageManager.getString("label.strucconsensus_descr"),
2229 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2230 strucConsensus.hasText = true;
2231 strucConsensus.autoCalculated = true;
2235 alignment.addAnnotation(strucConsensus);
2243 * @see jalview.api.AlignViewportI#calcPanelHeight()
2246 public int calcPanelHeight()
2248 // setHeight of panels
2249 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2251 int charHeight = getCharHeight();
2254 BitSet graphgrp = new BitSet();
2255 for (AlignmentAnnotation aa : anns)
2259 System.err.println("Null annotation row: ignoring.");
2266 if (aa.graphGroup > -1)
2268 if (graphgrp.get(aa.graphGroup))
2274 graphgrp.set(aa.graphGroup);
2281 aa.height += charHeight;
2291 aa.height += aa.graphHeight;
2299 height += aa.height;
2311 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2312 boolean preserveNewGroupSettings)
2314 boolean updateCalcs = false;
2315 boolean conv = isShowGroupConservation();
2316 boolean cons = isShowGroupConsensus();
2317 boolean showprf = isShowSequenceLogo();
2318 boolean showConsHist = isShowConsensusHistogram();
2319 boolean normLogo = isNormaliseSequenceLogo();
2320 boolean showHMMPrf = isShowHMMSequenceLogo();
2321 boolean showInfoHist = isShowInformationHistogram();
2322 boolean normHMMLogo = isNormaliseHMMSequenceLogo();
2325 * TODO reorder the annotation rows according to group/sequence ordering on
2328 boolean sortg = true;
2330 // remove old automatic annotation
2331 // add any new annotation
2333 // intersect alignment annotation with alignment groups
2335 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2336 List<SequenceGroup> oldrfs = new ArrayList<>();
2339 for (int an = 0; an < aan.length; an++)
2341 if (aan[an].autoCalculated && aan[an].groupRef != null)
2343 oldrfs.add(aan[an].groupRef);
2344 alignment.deleteAnnotation(aan[an], false);
2348 if (alignment.getGroups() != null)
2350 for (SequenceGroup sg : alignment.getGroups())
2352 updateCalcs = false;
2353 if (applyGlobalSettings
2354 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2356 // set defaults for this group's conservation/consensus
2357 sg.setshowSequenceLogo(showprf);
2358 sg.setShowConsensusHistogram(showConsHist);
2359 sg.setNormaliseSequenceLogo(normLogo);
2360 sg.setshowHMMSequenceLogo(showHMMPrf);
2361 sg.setShowInformationHistogram(showInfoHist);
2362 sg.setNormaliseHMMSequenceLogo(normHMMLogo);
2367 alignment.addAnnotation(sg.getConservationRow(), 0);
2372 alignment.addAnnotation(sg.getConsensus(), 0);
2374 // refresh the annotation rows
2377 sg.recalcConservation();
2385 public boolean isDisplayReferenceSeq()
2387 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2391 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2393 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2397 public boolean isColourByReferenceSeq()
2399 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2403 public Color getSequenceColour(SequenceI seq)
2405 Color sqc = sequenceColours.get(seq);
2406 return (sqc == null ? Color.white : sqc);
2410 public void setSequenceColour(SequenceI seq, Color col)
2414 sequenceColours.remove(seq);
2418 sequenceColours.put(seq, col);
2423 public void updateSequenceIdColours()
2425 for (SequenceGroup sg : alignment.getGroups())
2427 if (sg.idColour != null)
2429 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2431 sequenceColours.put(s, sg.idColour);
2438 public void clearSequenceColours()
2440 sequenceColours.clear();
2444 public AlignViewportI getCodingComplement()
2446 return this.codingComplement;
2450 * Set this as the (cDna/protein) complement of the given viewport. Also
2451 * ensures the reverse relationship is set on the given viewport.
2454 public void setCodingComplement(AlignViewportI av)
2458 System.err.println("Ignoring recursive setCodingComplement request");
2462 this.codingComplement = av;
2463 // avoid infinite recursion!
2464 if (av.getCodingComplement() != this)
2466 av.setCodingComplement(this);
2472 public boolean isNucleotide()
2474 return getAlignment() == null ? false : getAlignment().isNucleotide();
2478 public FeaturesDisplayedI getFeaturesDisplayed()
2480 return featuresDisplayed;
2484 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2486 featuresDisplayed = featuresDisplayedI;
2490 public boolean areFeaturesDisplayed()
2492 return featuresDisplayed != null
2493 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2500 * features are displayed if true
2503 public void setShowSequenceFeatures(boolean b)
2505 viewStyle.setShowSequenceFeatures(b);
2509 public boolean isShowSequenceFeatures()
2511 return viewStyle.isShowSequenceFeatures();
2515 public void setShowSequenceFeaturesHeight(boolean selected)
2517 viewStyle.setShowSequenceFeaturesHeight(selected);
2521 public boolean isShowSequenceFeaturesHeight()
2523 return viewStyle.isShowSequenceFeaturesHeight();
2527 public void setShowAnnotation(boolean b)
2529 viewStyle.setShowAnnotation(b);
2533 public boolean isShowAnnotation()
2535 return viewStyle.isShowAnnotation();
2539 public boolean isRightAlignIds()
2541 return viewStyle.isRightAlignIds();
2545 public void setRightAlignIds(boolean rightAlignIds)
2547 viewStyle.setRightAlignIds(rightAlignIds);
2551 public boolean getConservationSelected()
2553 return viewStyle.getConservationSelected();
2557 public void setShowBoxes(boolean state)
2559 viewStyle.setShowBoxes(state);
2564 * @see jalview.api.ViewStyleI#getTextColour()
2567 public Color getTextColour()
2569 return viewStyle.getTextColour();
2574 * @see jalview.api.ViewStyleI#getTextColour2()
2577 public Color getTextColour2()
2579 return viewStyle.getTextColour2();
2584 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2587 public int getThresholdTextColour()
2589 return viewStyle.getThresholdTextColour();
2594 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2597 public boolean isConservationColourSelected()
2599 return viewStyle.isConservationColourSelected();
2604 * @see jalview.api.ViewStyleI#isRenderGaps()
2607 public boolean isRenderGaps()
2609 return viewStyle.isRenderGaps();
2614 * @see jalview.api.ViewStyleI#isShowColourText()
2617 public boolean isShowColourText()
2619 return viewStyle.isShowColourText();
2623 * @param conservationColourSelected
2624 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2627 public void setConservationColourSelected(
2628 boolean conservationColourSelected)
2630 viewStyle.setConservationColourSelected(conservationColourSelected);
2634 * @param showColourText
2635 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2638 public void setShowColourText(boolean showColourText)
2640 viewStyle.setShowColourText(showColourText);
2645 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2648 public void setTextColour(Color textColour)
2650 viewStyle.setTextColour(textColour);
2654 * @param thresholdTextColour
2655 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2658 public void setThresholdTextColour(int thresholdTextColour)
2660 viewStyle.setThresholdTextColour(thresholdTextColour);
2664 * @param textColour2
2665 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2668 public void setTextColour2(Color textColour2)
2670 viewStyle.setTextColour2(textColour2);
2674 public ViewStyleI getViewStyle()
2676 return new ViewStyle(viewStyle);
2680 public void setViewStyle(ViewStyleI settingsForView)
2682 viewStyle = new ViewStyle(settingsForView);
2683 if (residueShading != null)
2685 residueShading.setConservationApplied(
2686 settingsForView.isConservationColourSelected());
2691 public boolean sameStyle(ViewStyleI them)
2693 return viewStyle.sameStyle(them);
2698 * @see jalview.api.ViewStyleI#getIdWidth()
2701 public int getIdWidth()
2703 return viewStyle.getIdWidth();
2708 * @see jalview.api.ViewStyleI#setIdWidth(int)
2711 public void setIdWidth(int i)
2713 viewStyle.setIdWidth(i);
2718 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2721 public boolean isCentreColumnLabels()
2723 return viewStyle.isCentreColumnLabels();
2727 * @param centreColumnLabels
2728 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2731 public void setCentreColumnLabels(boolean centreColumnLabels)
2733 viewStyle.setCentreColumnLabels(centreColumnLabels);
2738 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2741 public void setShowDBRefs(boolean showdbrefs)
2743 viewStyle.setShowDBRefs(showdbrefs);
2748 * @see jalview.api.ViewStyleI#isShowDBRefs()
2751 public boolean isShowDBRefs()
2753 return viewStyle.isShowDBRefs();
2758 * @see jalview.api.ViewStyleI#isShowNPFeats()
2761 public boolean isShowNPFeats()
2763 return viewStyle.isShowNPFeats();
2767 * @param shownpfeats
2768 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2771 public void setShowNPFeats(boolean shownpfeats)
2773 viewStyle.setShowNPFeats(shownpfeats);
2776 public abstract StructureSelectionManager getStructureSelectionManager();
2779 * Add one command to the command history list.
2783 public void addToHistoryList(CommandI command)
2785 if (this.historyList != null)
2787 this.historyList.push(command);
2788 broadcastCommand(command, false);
2792 protected void broadcastCommand(CommandI command, boolean undo)
2794 getStructureSelectionManager().commandPerformed(command, undo,
2799 * Add one command to the command redo list.
2803 public void addToRedoList(CommandI command)
2805 if (this.redoList != null)
2807 this.redoList.push(command);
2809 broadcastCommand(command, true);
2813 * Clear the command redo list.
2815 public void clearRedoList()
2817 if (this.redoList != null)
2819 this.redoList.clear();
2823 public void setHistoryList(Deque<CommandI> list)
2825 this.historyList = list;
2828 public Deque<CommandI> getHistoryList()
2830 return this.historyList;
2833 public void setRedoList(Deque<CommandI> list)
2835 this.redoList = list;
2838 public Deque<CommandI> getRedoList()
2840 return this.redoList;
2844 public VamsasSource getVamsasSource()
2849 public SequenceAnnotationOrder getSortAnnotationsBy()
2851 return sortAnnotationsBy;
2854 public void setSortAnnotationsBy(
2855 SequenceAnnotationOrder sortAnnotationsBy)
2857 this.sortAnnotationsBy = sortAnnotationsBy;
2860 public boolean isShowAutocalculatedAbove()
2862 return showAutocalculatedAbove;
2865 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2867 this.showAutocalculatedAbove = showAutocalculatedAbove;
2871 public boolean isScaleProteinAsCdna()
2873 return viewStyle.isScaleProteinAsCdna();
2877 public void setScaleProteinAsCdna(boolean b)
2879 viewStyle.setScaleProteinAsCdna(b);
2883 public boolean isProteinFontAsCdna()
2885 return viewStyle.isProteinFontAsCdna();
2889 public void setProteinFontAsCdna(boolean b)
2891 viewStyle.setProteinFontAsCdna(b);
2895 * @return true if view should scroll to show the highlighted region of a
2900 public final boolean isFollowHighlight()
2902 return followHighlight;
2906 public final void setFollowHighlight(boolean b)
2908 this.followHighlight = b;
2912 public ViewportRanges getRanges()
2918 * Helper method to populate the SearchResults with the location in the
2919 * complementary alignment to scroll to, in order to match this one.
2922 * the SearchResults to add to
2923 * @return the offset (below top of visible region) of the matched sequence
2925 protected int findComplementScrollTarget(SearchResultsI sr)
2927 final AlignViewportI complement = getCodingComplement();
2928 if (complement == null || !complement.isFollowHighlight())
2932 boolean iAmProtein = !getAlignment().isNucleotide();
2933 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2934 : complement.getAlignment();
2935 if (proteinAlignment == null)
2939 final List<AlignedCodonFrame> mappings = proteinAlignment
2943 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2944 * residue in the middle column of the visible region. Scroll the
2945 * complementary alignment to line up the corresponding residue.
2948 SequenceI sequence = null;
2951 * locate 'middle' column (true middle if an odd number visible, left of
2952 * middle if an even number visible)
2954 int middleColumn = ranges.getStartRes()
2955 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2956 final HiddenSequences hiddenSequences = getAlignment()
2957 .getHiddenSequences();
2960 * searching to the bottom of the alignment gives smoother scrolling across
2961 * all gapped visible regions
2963 int lastSeq = alignment.getHeight() - 1;
2964 List<AlignedCodonFrame> seqMappings = null;
2965 for (int seqNo = ranges
2966 .getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2968 sequence = getAlignment().getSequenceAt(seqNo);
2969 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2973 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2977 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2979 getCodingComplement().getAlignment().getSequences());
2980 if (!seqMappings.isEmpty())
2986 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2989 * No ungapped mapped sequence in middle column - do nothing
2993 MappingUtils.addSearchResults(sr, sequence,
2994 sequence.findPosition(middleColumn), seqMappings);
2999 * synthesize a column selection if none exists so it covers the given
3000 * selection group. if wholewidth is false, no column selection is made if the
3001 * selection group covers the whole alignment width.
3006 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
3009 if (sg != null && (sgs = sg.getStartRes()) >= 0
3010 && sg.getStartRes() <= (sge = sg.getEndRes())
3011 && !this.hasSelectedColumns())
3013 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
3020 colSel = new ColumnSelection();
3022 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
3024 colSel.addElement(cspos);
3030 * hold status of current selection group - defined on alignment or not.
3032 private boolean selectionIsDefinedGroup = false;
3035 public boolean isSelectionDefinedGroup()
3037 if (selectionGroup == null)
3041 if (isSelectionGroupChanged(true))
3043 selectionIsDefinedGroup = false;
3044 List<SequenceGroup> gps = alignment.getGroups();
3045 if (gps == null || gps.size() == 0)
3047 selectionIsDefinedGroup = false;
3051 selectionIsDefinedGroup = gps.contains(selectionGroup);
3054 return selectionGroup.isDefined() || selectionIsDefinedGroup;
3058 * null, or currently highlighted results on this view
3060 private SearchResultsI searchResults = null;
3063 public boolean hasSearchResults()
3065 return searchResults != null;
3069 public void setSearchResults(SearchResultsI results)
3071 searchResults = results;
3075 public SearchResultsI getSearchResults()
3077 return searchResults;
3081 * get the consensus sequence as displayed under the PID consensus annotation
3084 * @return consensus sequence as a new sequence object
3086 public SequenceI getConsensusSeq()
3088 if (consensus == null)
3090 updateConsensus(null);
3092 if (consensus == null)
3096 StringBuffer seqs = new StringBuffer();
3097 for (int i = 0; i < consensus.annotations.length; i++)
3099 Annotation annotation = consensus.annotations[i];
3100 if (annotation != null)
3102 String description = annotation.description;
3103 if (description != null && description.startsWith("["))
3105 // consensus is a tie - just pick the first one
3106 seqs.append(description.charAt(1));
3110 seqs.append(annotation.displayCharacter);
3115 SequenceI sq = new Sequence("Consensus", seqs.toString());
3116 sq.setDescription("Percentage Identity Consensus "
3117 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));