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<>();
103 * alignment displayed in the viewport. Please use get/setter
105 protected AlignmentI alignment;
107 public AlignmentViewport(AlignmentI al)
110 ranges = new ViewportRanges(al);
115 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
118 public void setFontName(String name)
120 viewStyle.setFontName(name);
125 * @see jalview.api.ViewStyleI#setFontStyle(int)
128 public void setFontStyle(int style)
130 viewStyle.setFontStyle(style);
135 * @see jalview.api.ViewStyleI#setFontSize(int)
138 public void setFontSize(int size)
140 viewStyle.setFontSize(size);
145 * @see jalview.api.ViewStyleI#getFontStyle()
148 public int getFontStyle()
150 return viewStyle.getFontStyle();
155 * @see jalview.api.ViewStyleI#getFontName()
158 public String getFontName()
160 return viewStyle.getFontName();
165 * @see jalview.api.ViewStyleI#getFontSize()
168 public int getFontSize()
170 return viewStyle.getFontSize();
174 * @param upperCasebold
175 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
178 public void setUpperCasebold(boolean upperCasebold)
180 viewStyle.setUpperCasebold(upperCasebold);
185 * @see jalview.api.ViewStyleI#isUpperCasebold()
188 public boolean isUpperCasebold()
190 return viewStyle.isUpperCasebold();
195 * @see jalview.api.ViewStyleI#isSeqNameItalics()
198 public boolean isSeqNameItalics()
200 return viewStyle.isSeqNameItalics();
204 * @param colourByReferenceSeq
205 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
208 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
210 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
215 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
218 public void setColourAppliesToAllGroups(boolean b)
220 viewStyle.setColourAppliesToAllGroups(b);
225 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
228 public boolean getColourAppliesToAllGroups()
230 return viewStyle.getColourAppliesToAllGroups();
235 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
238 public boolean getAbovePIDThreshold()
240 return viewStyle.getAbovePIDThreshold();
245 * @see jalview.api.ViewStyleI#setIncrement(int)
248 public void setIncrement(int inc)
250 viewStyle.setIncrement(inc);
255 * @see jalview.api.ViewStyleI#getIncrement()
258 public int getIncrement()
260 return viewStyle.getIncrement();
265 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
268 public void setConservationSelected(boolean b)
270 viewStyle.setConservationSelected(b);
275 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
278 public void setShowHiddenMarkers(boolean show)
280 viewStyle.setShowHiddenMarkers(show);
285 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
288 public boolean getShowHiddenMarkers()
290 return viewStyle.getShowHiddenMarkers();
295 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
298 public void setScaleRightWrapped(boolean b)
300 viewStyle.setScaleRightWrapped(b);
305 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
308 public void setScaleLeftWrapped(boolean b)
310 viewStyle.setScaleLeftWrapped(b);
315 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
318 public void setScaleAboveWrapped(boolean b)
320 viewStyle.setScaleAboveWrapped(b);
325 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
328 public boolean getScaleLeftWrapped()
330 return viewStyle.getScaleLeftWrapped();
335 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
338 public boolean getScaleAboveWrapped()
340 return viewStyle.getScaleAboveWrapped();
345 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
348 public boolean getScaleRightWrapped()
350 return viewStyle.getScaleRightWrapped();
355 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
358 public void setAbovePIDThreshold(boolean b)
360 viewStyle.setAbovePIDThreshold(b);
365 * @see jalview.api.ViewStyleI#setThreshold(int)
368 public void setThreshold(int thresh)
370 viewStyle.setThreshold(thresh);
375 * @see jalview.api.ViewStyleI#getThreshold()
378 public int getThreshold()
380 return viewStyle.getThreshold();
385 * @see jalview.api.ViewStyleI#getShowJVSuffix()
388 public boolean getShowJVSuffix()
390 return viewStyle.getShowJVSuffix();
395 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
398 public void setShowJVSuffix(boolean b)
400 viewStyle.setShowJVSuffix(b);
405 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
408 public void setWrapAlignment(boolean state)
410 viewStyle.setWrapAlignment(state);
415 * @see jalview.api.ViewStyleI#setShowText(boolean)
418 public void setShowText(boolean state)
420 viewStyle.setShowText(state);
425 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
428 public void setRenderGaps(boolean state)
430 viewStyle.setRenderGaps(state);
435 * @see jalview.api.ViewStyleI#getColourText()
438 public boolean getColourText()
440 return viewStyle.getColourText();
445 * @see jalview.api.ViewStyleI#setColourText(boolean)
448 public void setColourText(boolean state)
450 viewStyle.setColourText(state);
455 * @see jalview.api.ViewStyleI#getWrapAlignment()
458 public boolean getWrapAlignment()
460 return viewStyle.getWrapAlignment();
465 * @see jalview.api.ViewStyleI#getShowText()
468 public boolean getShowText()
470 return viewStyle.getShowText();
475 * @see jalview.api.ViewStyleI#getWrappedWidth()
478 public int getWrappedWidth()
480 return viewStyle.getWrappedWidth();
485 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
488 public void setWrappedWidth(int w)
490 viewStyle.setWrappedWidth(w);
495 * @see jalview.api.ViewStyleI#getCharHeight()
498 public int getCharHeight()
500 return viewStyle.getCharHeight();
505 * @see jalview.api.ViewStyleI#setCharHeight(int)
508 public void setCharHeight(int h)
510 viewStyle.setCharHeight(h);
515 * @see jalview.api.ViewStyleI#getCharWidth()
518 public int getCharWidth()
520 return viewStyle.getCharWidth();
525 * @see jalview.api.ViewStyleI#setCharWidth(int)
528 public void setCharWidth(int w)
530 viewStyle.setCharWidth(w);
535 * @see jalview.api.ViewStyleI#getShowBoxes()
538 public boolean getShowBoxes()
540 return viewStyle.getShowBoxes();
545 * @see jalview.api.ViewStyleI#getShowUnconserved()
548 public boolean getShowUnconserved()
550 return viewStyle.getShowUnconserved();
554 * @param showunconserved
555 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
558 public void setShowUnconserved(boolean showunconserved)
560 viewStyle.setShowUnconserved(showunconserved);
565 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
568 public void setSeqNameItalics(boolean default1)
570 viewStyle.setSeqNameItalics(default1);
574 public AlignmentI getAlignment()
580 public char getGapCharacter()
582 return alignment.getGapCharacter();
585 protected String sequenceSetID;
588 * probably unused indicator that view is of a dataset rather than an
591 protected boolean isDataset = false;
593 public void setDataset(boolean b)
598 public boolean isDataset()
603 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
605 protected ColumnSelection colSel = new ColumnSelection();
607 public boolean autoCalculateConsensus = true;
609 public boolean autoCalculateInformation = true;
611 protected boolean autoCalculateStrucConsensus = true;
613 protected boolean ignoreGapsInConsensusCalculation = false;
615 protected boolean ignoreBelowBackGroundFrequencyCalculation = false;
617 protected ResidueShaderI residueShading = new ResidueShader();
620 public void setGlobalColourScheme(ColourSchemeI cs)
622 // TODO: logic refactored from AlignFrame changeColour -
623 // TODO: autorecalc stuff should be changed to rely on the worker system
624 // check to see if we should implement a changeColour(cs) method rather than
625 // put the logic in here
626 // - means that caller decides if they want to just modify state and defer
627 // calculation till later or to do all calculations in thread.
631 * only instantiate alignment colouring once, thereafter update it;
632 * this means that any conservation or PID threshold settings
633 * persist when the alignment colour scheme is changed
635 if (residueShading == null)
637 residueShading = new ResidueShader(viewStyle);
639 residueShading.setColourScheme(cs);
641 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
642 // ...problem: groups need these, but do not currently have a ViewStyle
646 if (getConservationSelected())
648 residueShading.setConservation(hconservation);
650 residueShading.alignmentChanged(alignment, hiddenRepSequences);
654 * if 'apply colour to all groups' is selected... do so
655 * (but don't transfer any colour threshold settings to groups)
657 if (getColourAppliesToAllGroups())
659 for (SequenceGroup sg : getAlignment().getGroups())
662 * retain any colour thresholds per group while
663 * changing choice of colour scheme (JAL-2386)
665 sg.setColourScheme(cs);
668 sg.getGroupColourScheme().alignmentChanged(sg,
676 public ColourSchemeI getGlobalColourScheme()
678 return residueShading == null ? null : residueShading.getColourScheme();
682 public ResidueShaderI getResidueShading()
684 return residueShading;
687 protected AlignmentAnnotation consensus;
689 protected AlignmentAnnotation complementConsensus;
691 protected AlignmentAnnotation gapcounts;
693 protected AlignmentAnnotation strucConsensus;
695 protected AlignmentAnnotation conservation;
697 protected AlignmentAnnotation quality;
699 protected AlignmentAnnotation[] groupConsensus;
701 protected AlignmentAnnotation[] groupConservation;
703 protected List<AlignmentAnnotation> groupInformation = new ArrayList<>();
705 protected List<AlignmentAnnotation> information = new ArrayList<>();
708 * results of alignment consensus analysis for visible portion of view
710 protected ProfilesI hconsensus = null;
712 protected List<ProfilesI> hinformation = new ArrayList<>();
715 * results of cDNA complement consensus visible portion of view
717 protected Hashtable[] hcomplementConsensus = null;
720 * results of secondary structure base pair consensus for visible portion of
723 protected Hashtable[] hStrucConsensus = null;
725 protected Conservation hconservation = null;
728 public void setConservation(Conservation cons)
730 hconservation = cons;
734 * percentage gaps allowed in a column before all amino acid properties should
735 * be considered unconserved
737 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
740 public int getConsPercGaps()
746 public void setSequenceConsensusHash(ProfilesI hconsensus)
748 this.hconsensus = hconsensus;
752 public void setComplementConsensusHash(Hashtable[] hconsensus)
754 this.hcomplementConsensus = hconsensus;
758 public ProfilesI getSequenceConsensusHash()
764 public void setSequenceInformationHashes(List<ProfilesI> info)
770 public void setSequenceInformationHash(ProfilesI info, int index)
772 hinformation.set(index, info);
776 public List<ProfilesI> getSequenceInformationHashes()
782 public ProfilesI getSequenceInformationHash(int index)
784 return hinformation.get(index);
788 public Hashtable[] getComplementConsensusHash()
790 return hcomplementConsensus;
794 public Hashtable[] getRnaStructureConsensusHash()
796 return hStrucConsensus;
800 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
802 this.hStrucConsensus = hStrucConsensus;
807 public AlignmentAnnotation getAlignmentQualityAnnot()
813 public AlignmentAnnotation getAlignmentConservationAnnotation()
819 public AlignmentAnnotation getAlignmentConsensusAnnotation()
825 public List<AlignmentAnnotation> getInformationAnnotations()
831 public AlignmentAnnotation getInformationAnnotation(int index)
833 return information.get(index);
837 public AlignmentAnnotation getAlignmentGapAnnotation()
843 public AlignmentAnnotation getComplementConsensusAnnotation()
845 return complementConsensus;
849 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
851 return strucConsensus;
854 protected AlignCalcManagerI calculator = new AlignCalcManager();
857 * trigger update of conservation annotation
859 public void updateConservation(final AlignmentViewPanel ap)
861 // see note in mantis : issue number 8585
862 if (alignment.isNucleotide()
863 || (conservation == null && quality == null)
864 || !autoCalculateConsensus)
868 if (calculator.getRegisteredWorkersOfClass(
869 jalview.workers.ConservationThread.class) == null)
871 calculator.registerWorker(
872 new jalview.workers.ConservationThread(this, ap));
877 * trigger update of consensus annotation
879 public void updateConsensus(final AlignmentViewPanel ap)
881 // see note in mantis : issue number 8585
882 if (consensus == null || !autoCalculateConsensus)
887 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
889 calculator.registerWorker(new ConsensusThread(this, ap));
893 * A separate thread to compute cDNA consensus for a protein alignment
894 * which has mapping to cDNA
896 final AlignmentI al = this.getAlignment();
897 if (!al.isNucleotide() && al.getCodonFrames() != null
898 && !al.getCodonFrames().isEmpty())
901 * fudge - check first for protein-to-nucleotide mappings
902 * (we don't want to do this for protein-to-protein)
904 boolean doConsensus = false;
905 for (AlignedCodonFrame mapping : al.getCodonFrames())
907 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
908 MapList[] mapLists = mapping.getdnaToProt();
909 // mapLists can be empty if project load has not finished resolving seqs
910 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
918 if (calculator.getRegisteredWorkersOfClass(
919 ComplementConsensusThread.class) == null)
922 .registerWorker(new ComplementConsensusThread(this, ap));
929 * trigger update of information annotation
931 public void updateInformation(final AlignmentViewPanel ap)
934 .getRegisteredWorkersOfClass(InformationThread.class) == null)
936 calculator.registerWorker(new InformationThread(this, ap));
941 // --------START Structure Conservation
942 public void updateStrucConsensus(final AlignmentViewPanel ap)
944 if (autoCalculateStrucConsensus && strucConsensus == null
945 && alignment.isNucleotide() && alignment.hasRNAStructure())
947 // secondary structure has been added - so init the consensus line
951 // see note in mantis : issue number 8585
952 if (strucConsensus == null || !autoCalculateStrucConsensus)
956 if (calculator.getRegisteredWorkersOfClass(
957 StrucConsensusThread.class) == null)
959 calculator.registerWorker(new StrucConsensusThread(this, ap));
963 public boolean isCalcInProgress()
965 return calculator.isWorking();
969 public boolean isCalculationInProgress(
970 AlignmentAnnotation alignmentAnnotation)
972 if (!alignmentAnnotation.autoCalculated)
976 if (calculator.workingInvolvedWith(alignmentAnnotation))
978 // System.err.println("grey out ("+alignmentAnnotation.label+")");
984 public void setAlignment(AlignmentI align)
986 this.alignment = align;
990 * Clean up references when this viewport is closed
993 public void dispose()
996 * defensively null out references to large objects in case
997 * this object is not garbage collected (as if!)
1000 complementConsensus = null;
1001 strucConsensus = null;
1002 conservation = null;
1004 groupConsensus = null;
1005 groupConservation = null;
1007 hcomplementConsensus = null;
1008 // colour scheme may hold reference to consensus
1009 residueShading = null;
1010 // TODO remove listeners from changeSupport?
1011 changeSupport = null;
1016 public boolean isClosed()
1018 // TODO: check that this isClosed is only true after panel is closed, not
1019 // before it is fully constructed.
1020 return alignment == null;
1024 public AlignCalcManagerI getCalcManager()
1030 * should conservation rows be shown for groups
1032 protected boolean showGroupConservation = false;
1035 * should consensus rows be shown for groups
1037 protected boolean showGroupConsensus = false;
1040 * should consensus profile be rendered by default
1042 protected boolean showSequenceLogo = false;
1045 * should consensus profile be rendered normalised to row height
1047 protected boolean normaliseSequenceLogo = false;
1050 * should consensus histograms be rendered by default
1052 protected boolean showConsensusHistogram = true;
1055 * should hmm profile be rendered by default
1057 protected boolean showHMMSequenceLogo = false;
1060 * should hmm profile be rendered normalised to row height
1062 protected boolean normaliseHMMSequenceLogo = false;
1065 * should information histograms be rendered by default
1067 protected boolean showInformationHistogram = true;
1070 * @return the showConsensusProfile
1073 public boolean isShowSequenceLogo()
1075 return showSequenceLogo;
1079 * @return the showInformationProfile
1082 public boolean isShowHMMSequenceLogo()
1084 return showHMMSequenceLogo;
1088 * @param showSequenceLogo
1091 public void setShowSequenceLogo(boolean showSequenceLogo)
1093 if (showSequenceLogo != this.showSequenceLogo)
1095 // TODO: decouple settings setting from calculation when refactoring
1096 // annotation update method from alignframe to viewport
1097 this.showSequenceLogo = showSequenceLogo;
1098 calculator.updateAnnotationFor(ConsensusThread.class);
1099 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1100 calculator.updateAnnotationFor(StrucConsensusThread.class);
1102 this.showSequenceLogo = showSequenceLogo;
1105 public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo)
1107 if (showHMMSequenceLogo != this.showHMMSequenceLogo)
1109 this.showHMMSequenceLogo = showHMMSequenceLogo;
1110 calculator.updateAnnotationFor(InformationThread.class);
1112 this.showHMMSequenceLogo = showHMMSequenceLogo;
1116 * @param showConsensusHistogram
1117 * the showConsensusHistogram to set
1119 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1121 this.showConsensusHistogram = showConsensusHistogram;
1125 * @param showInformationHistogram
1126 * the showInformationHistogram to set
1128 public void setShowInformationHistogram(boolean showInformationHistogram)
1130 this.showInformationHistogram = showInformationHistogram;
1134 * @return the showGroupConservation
1136 public boolean isShowGroupConservation()
1138 return showGroupConservation;
1142 * @param showGroupConservation
1143 * the showGroupConservation to set
1145 public void setShowGroupConservation(boolean showGroupConservation)
1147 this.showGroupConservation = showGroupConservation;
1151 * @return the showGroupConsensus
1153 public boolean isShowGroupConsensus()
1155 return showGroupConsensus;
1159 * @param showGroupConsensus
1160 * the showGroupConsensus to set
1162 public void setShowGroupConsensus(boolean showGroupConsensus)
1164 this.showGroupConsensus = showGroupConsensus;
1169 * @return flag to indicate if the consensus histogram should be rendered by
1173 public boolean isShowConsensusHistogram()
1175 return this.showConsensusHistogram;
1180 * @return flag to indicate if the information content histogram should be
1181 * rendered by default
1184 public boolean isShowInformationHistogram()
1186 return this.showInformationHistogram;
1190 * when set, updateAlignment will always ensure sequences are of equal length
1192 private boolean padGaps = false;
1195 * when set, alignment should be reordered according to a newly opened tree
1197 public boolean sortByTree = false;
1202 * @return null or the currently selected sequence region
1205 public SequenceGroup getSelectionGroup()
1207 return selectionGroup;
1211 * Set the selection group for this window. Also sets the current alignment as
1212 * the context for the group, if it does not already have one.
1215 * - group holding references to sequences in this alignment view
1219 public void setSelectionGroup(SequenceGroup sg)
1221 selectionGroup = sg;
1222 if (sg != null && sg.getContext() == null)
1224 sg.setContext(alignment);
1228 public void setHiddenColumns(HiddenColumns hidden)
1230 this.alignment.setHiddenColumns(hidden);
1234 public ColumnSelection getColumnSelection()
1240 public void setColumnSelection(ColumnSelection colSel)
1242 this.colSel = colSel;
1245 updateHiddenColumns();
1247 isColSelChanged(true);
1255 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1257 return hiddenRepSequences;
1261 public void setHiddenRepSequences(
1262 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1264 this.hiddenRepSequences = hiddenRepSequences;
1268 public boolean hasSelectedColumns()
1270 ColumnSelection columnSelection = getColumnSelection();
1271 return columnSelection != null && columnSelection.hasSelectedColumns();
1275 public boolean hasHiddenColumns()
1277 return colSel != null
1278 && alignment.getHiddenColumns().hasHiddenColumns();
1281 public void updateHiddenColumns()
1283 // this method doesn't really do anything now. But - it could, since a
1284 // column Selection could be in the process of modification
1285 // hasHiddenColumns = colSel.hasHiddenColumns();
1289 public boolean hasHiddenRows()
1291 return alignment.getHiddenSequences().getSize() > 0;
1294 protected SequenceGroup selectionGroup;
1296 public void setSequenceSetId(String newid)
1298 if (sequenceSetID != null)
1301 "Warning - overwriting a sequenceSetId for a viewport!");
1303 sequenceSetID = new String(newid);
1307 public String getSequenceSetId()
1309 if (sequenceSetID == null)
1311 sequenceSetID = alignment.hashCode() + "";
1314 return sequenceSetID;
1318 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1321 protected String viewId = null;
1324 public String getViewId()
1328 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1333 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1335 ignoreGapsInConsensusCalculation = b;
1338 updateConsensus(ap);
1339 if (residueShading != null)
1341 residueShading.setThreshold(residueShading.getThreshold(),
1342 ignoreGapsInConsensusCalculation);
1348 public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap)
1350 ignoreBelowBackGroundFrequencyCalculation = b;
1353 updateInformation(ap);
1358 private long sgrouphash = -1, colselhash = -1;
1361 * checks current SelectionGroup against record of last hash value, and
1365 * update the record of last hash value
1367 * @return true if SelectionGroup changed since last call (when b is true)
1369 public boolean isSelectionGroupChanged(boolean b)
1371 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1372 : selectionGroup.hashCode();
1373 if (hc != -1 && hc != sgrouphash)
1385 * checks current colsel against record of last hash value, and optionally
1389 * update the record of last hash value
1390 * @return true if colsel changed since last call (when b is true)
1392 public boolean isColSelChanged(boolean b)
1394 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1395 if (hc != -1 && hc != colselhash)
1407 public boolean isIgnoreGapsConsensus()
1409 return ignoreGapsInConsensusCalculation;
1413 public boolean isIgnoreBelowBackground()
1415 return ignoreBelowBackGroundFrequencyCalculation;
1418 // property change stuff
1419 // JBPNote Prolly only need this in the applet version.
1420 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1423 protected boolean showConservation = true;
1425 protected boolean showQuality = true;
1427 protected boolean showConsensus = true;
1429 protected boolean showOccupancy = true;
1431 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1433 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1435 protected boolean showAutocalculatedAbove;
1438 * when set, view will scroll to show the highlighted position
1440 private boolean followHighlight = true;
1443 * Property change listener for changes in alignment
1448 public void addPropertyChangeListener(
1449 java.beans.PropertyChangeListener listener)
1451 changeSupport.addPropertyChangeListener(listener);
1460 public void removePropertyChangeListener(
1461 java.beans.PropertyChangeListener listener)
1463 changeSupport.removePropertyChangeListener(listener);
1467 * Property change listener for changes in alignment
1476 public void firePropertyChange(String prop, Object oldvalue,
1479 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1482 // common hide/show column stuff
1484 public void hideSelectedColumns()
1486 if (colSel.isEmpty())
1491 colSel.hideSelectedColumns(alignment);
1492 setSelectionGroup(null);
1493 isColSelChanged(true);
1496 public void hideColumns(int start, int end)
1500 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1504 alignment.getHiddenColumns().hideColumns(start, end);
1506 isColSelChanged(true);
1509 public void showColumn(int col)
1511 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1512 isColSelChanged(true);
1515 public void showAllHiddenColumns()
1517 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1518 isColSelChanged(true);
1521 // common hide/show seq stuff
1522 public void showAllHiddenSeqs()
1524 if (alignment.getHiddenSequences().getSize() > 0)
1526 if (selectionGroup == null)
1528 selectionGroup = new SequenceGroup();
1529 selectionGroup.setEndRes(alignment.getWidth() - 1);
1531 List<SequenceI> tmp = alignment.getHiddenSequences()
1532 .showAll(hiddenRepSequences);
1533 for (SequenceI seq : tmp)
1535 selectionGroup.addSequence(seq, false);
1536 setSequenceAnnotationsVisible(seq, true);
1539 hiddenRepSequences = null;
1541 firePropertyChange("alignment", null, alignment.getSequences());
1542 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1548 public void showSequence(int index)
1550 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1551 hiddenRepSequences);
1554 if (selectionGroup == null)
1556 selectionGroup = new SequenceGroup();
1557 selectionGroup.setEndRes(alignment.getWidth() - 1);
1560 for (SequenceI seq : tmp)
1562 selectionGroup.addSequence(seq, false);
1563 setSequenceAnnotationsVisible(seq, true);
1565 firePropertyChange("alignment", null, alignment.getSequences());
1570 public void hideAllSelectedSeqs()
1572 if (selectionGroup == null || selectionGroup.getSize() < 1)
1577 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1581 setSelectionGroup(null);
1584 public void hideSequence(SequenceI[] seq)
1588 for (int i = 0; i < seq.length; i++)
1590 alignment.getHiddenSequences().hideSequence(seq[i]);
1591 setSequenceAnnotationsVisible(seq[i], false);
1593 firePropertyChange("alignment", null, alignment.getSequences());
1598 * Hides the specified sequence, or the sequences it represents
1601 * the sequence to hide, or keep as representative
1602 * @param representGroup
1603 * if true, hide the current selection group except for the
1604 * representative sequence
1606 public void hideSequences(SequenceI sequence, boolean representGroup)
1608 if (selectionGroup == null || selectionGroup.getSize() < 1)
1610 hideSequence(new SequenceI[] { sequence });
1616 hideRepSequences(sequence, selectionGroup);
1617 setSelectionGroup(null);
1621 int gsize = selectionGroup.getSize();
1622 SequenceI[] hseqs = selectionGroup.getSequences()
1623 .toArray(new SequenceI[gsize]);
1625 hideSequence(hseqs);
1626 setSelectionGroup(null);
1631 * Set visibility for any annotations for the given sequence.
1635 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1638 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1641 for (AlignmentAnnotation ann : anns)
1643 if (ann.sequenceRef == sequenceI)
1645 ann.visible = visible;
1651 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1653 int sSize = sg.getSize();
1659 if (hiddenRepSequences == null)
1661 hiddenRepSequences = new Hashtable<>();
1664 hiddenRepSequences.put(repSequence, sg);
1666 // Hide all sequences except the repSequence
1667 SequenceI[] seqs = new SequenceI[sSize - 1];
1669 for (int i = 0; i < sSize; i++)
1671 if (sg.getSequenceAt(i) != repSequence)
1673 if (index == sSize - 1)
1678 seqs[index++] = sg.getSequenceAt(i);
1681 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1682 sg.setHidereps(true); // note: not done in 2.7applet
1689 * @return null or the current reference sequence
1691 public SequenceI getReferenceSeq()
1693 return alignment.getSeqrep();
1698 * @return true iff seq is the reference for the alignment
1700 public boolean isReferenceSeq(SequenceI seq)
1702 return alignment.getSeqrep() == seq;
1708 * @return true if there are sequences represented by this sequence that are
1711 public boolean isHiddenRepSequence(SequenceI seq)
1713 return (hiddenRepSequences != null
1714 && hiddenRepSequences.containsKey(seq));
1720 * @return null or a sequence group containing the sequences that seq
1723 public SequenceGroup getRepresentedSequences(SequenceI seq)
1725 return (SequenceGroup) (hiddenRepSequences == null ? null
1726 : hiddenRepSequences.get(seq));
1730 public int adjustForHiddenSeqs(int alignmentIndex)
1732 return alignment.getHiddenSequences()
1733 .adjustForHiddenSeqs(alignmentIndex);
1737 public void invertColumnSelection()
1739 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1743 public SequenceI[] getSelectionAsNewSequence()
1745 SequenceI[] sequences;
1746 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1747 // this was the only caller in the applet for this method
1748 // JBPNote: in applet, this method returned references to the alignment
1749 // sequences, and it did not honour the presence/absence of annotation
1750 // attached to the alignment (probably!)
1751 if (selectionGroup == null || selectionGroup.getSize() == 0)
1753 sequences = alignment.getSequencesArray();
1754 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1755 for (int i = 0; i < sequences.length; i++)
1757 // construct new sequence with subset of visible annotation
1758 sequences[i] = new Sequence(sequences[i], annots);
1763 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1770 public SequenceI[] getSequenceSelection()
1772 SequenceI[] sequences = null;
1773 if (selectionGroup != null)
1775 sequences = selectionGroup.getSequencesInOrder(alignment);
1777 if (sequences == null)
1779 sequences = alignment.getSequencesArray();
1785 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1787 return new CigarArray(alignment, alignment.getHiddenColumns(),
1788 (selectedRegionOnly ? selectionGroup : null));
1792 public jalview.datamodel.AlignmentView getAlignmentView(
1793 boolean selectedOnly)
1795 return getAlignmentView(selectedOnly, false);
1799 public jalview.datamodel.AlignmentView getAlignmentView(
1800 boolean selectedOnly, boolean markGroups)
1802 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1803 selectionGroup, alignment.getHiddenColumns() != null
1804 && alignment.getHiddenColumns().hasHiddenColumns(),
1805 selectedOnly, markGroups);
1809 public String[] getViewAsString(boolean selectedRegionOnly)
1811 return getViewAsString(selectedRegionOnly, true);
1815 public String[] getViewAsString(boolean selectedRegionOnly,
1816 boolean exportHiddenSeqs)
1818 String[] selection = null;
1819 SequenceI[] seqs = null;
1821 int start = 0, end = 0;
1822 if (selectedRegionOnly && selectionGroup != null)
1824 iSize = selectionGroup.getSize();
1825 seqs = selectionGroup.getSequencesInOrder(alignment);
1826 start = selectionGroup.getStartRes();
1827 end = selectionGroup.getEndRes() + 1;
1831 if (hasHiddenRows() && exportHiddenSeqs)
1833 AlignmentI fullAlignment = alignment.getHiddenSequences()
1834 .getFullAlignment();
1835 iSize = fullAlignment.getHeight();
1836 seqs = fullAlignment.getSequencesArray();
1837 end = fullAlignment.getWidth();
1841 iSize = alignment.getHeight();
1842 seqs = alignment.getSequencesArray();
1843 end = alignment.getWidth();
1847 selection = new String[iSize];
1848 if (alignment.getHiddenColumns() != null
1849 && alignment.getHiddenColumns().hasHiddenColumns())
1851 selection = alignment.getHiddenColumns()
1852 .getVisibleSequenceStrings(start, end, seqs);
1856 for (i = 0; i < iSize; i++)
1858 selection[i] = seqs[i].getSequenceAsString(start, end);
1866 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1868 ArrayList<int[]> regions = new ArrayList<>();
1874 HiddenColumns hidden = alignment.getHiddenColumns();
1875 if (hidden != null && hidden.hasHiddenColumns())
1879 start = hidden.adjustForHiddenColumns(start);
1882 end = hidden.getHiddenBoundaryRight(start);
1893 regions.add(new int[] { start, end });
1895 if (hidden != null && hidden.hasHiddenColumns())
1897 start = hidden.adjustForHiddenColumns(end);
1898 start = hidden.getHiddenBoundaryLeft(start) + 1;
1900 } while (end < max);
1902 int[][] startEnd = new int[regions.size()][2];
1908 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1909 boolean selectedOnly)
1911 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1912 AlignmentAnnotation[] aa;
1913 if ((aa = alignment.getAlignmentAnnotation()) != null)
1915 for (AlignmentAnnotation annot : aa)
1917 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1918 if (selectedOnly && selectionGroup != null)
1920 alignment.getHiddenColumns().makeVisibleAnnotation(
1921 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1926 alignment.getHiddenColumns().makeVisibleAnnotation(clone);
1935 public boolean isPadGaps()
1941 public void setPadGaps(boolean padGaps)
1943 this.padGaps = padGaps;
1947 * apply any post-edit constraints and trigger any calculations needed after
1948 * an edit has been performed on the alignment
1953 public void alignmentChanged(AlignmentViewPanel ap)
1957 alignment.padGaps();
1959 if (autoCalculateConsensus)
1961 updateConsensus(ap);
1963 if (hconsensus != null && autoCalculateConsensus)
1965 updateConservation(ap);
1967 if (autoCalculateStrucConsensus)
1969 updateStrucConsensus(ap);
1971 updateInformation(ap);
1973 Map<Integer, SequenceI> hmmSequences;
1974 hmmSequences = alignment.getHMMConsensusSequences(false);
1976 for (Map.Entry<Integer, SequenceI> entry : hmmSequences.entrySet())
1978 SequenceI seq = entry.getValue();
1979 seq.updateHMMMapping();
1982 // Reset endRes of groups if beyond alignment width
1983 int alWidth = alignment.getWidth();
1984 List<SequenceGroup> groups = alignment.getGroups();
1987 for (SequenceGroup sg : groups)
1989 if (sg.getEndRes() > alWidth)
1991 sg.setEndRes(alWidth - 1);
1996 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1998 selectionGroup.setEndRes(alWidth - 1);
2001 updateAllColourSchemes();
2002 calculator.restartWorkers();
2003 // alignment.adjustSequenceAnnotations();
2007 * reset scope and do calculations for all applied colourschemes on alignment
2009 void updateAllColourSchemes()
2011 ResidueShaderI rs = residueShading;
2014 rs.alignmentChanged(alignment, hiddenRepSequences);
2016 rs.setConsensus(hconsensus);
2017 if (rs.conservationApplied())
2019 rs.setConservation(Conservation.calculateConservation("All",
2020 alignment.getSequences(), 0, alignment.getWidth(), false,
2021 getConsPercGaps(), false));
2025 for (SequenceGroup sg : alignment.getGroups())
2029 sg.cs.alignmentChanged(sg, hiddenRepSequences);
2031 sg.recalcConservation();
2035 protected void initAutoAnnotation()
2037 // TODO: add menu option action that nulls or creates consensus object
2038 // depending on if the user wants to see the annotation or not in a
2039 // specific alignment
2041 if (hconsensus == null && !isDataset)
2043 if (!alignment.isNucleotide())
2052 consensus = new AlignmentAnnotation("Consensus",
2053 MessageManager.getString("label.consensus_descr"),
2054 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2055 initConsensus(consensus);
2059 initComplementConsensus();
2064 * If this is a protein alignment and there are mappings to cDNA, adds the
2065 * cDNA consensus annotation and returns true, else returns false.
2067 public boolean initComplementConsensus()
2069 if (!alignment.isNucleotide())
2071 final List<AlignedCodonFrame> codonMappings = alignment
2073 if (codonMappings != null && !codonMappings.isEmpty())
2075 boolean doConsensus = false;
2076 for (AlignedCodonFrame mapping : codonMappings)
2078 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2079 MapList[] mapLists = mapping.getdnaToProt();
2080 // mapLists can be empty if project load has not finished resolving
2082 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2090 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2092 .getString("label.complement_consensus_descr"),
2093 new Annotation[1], 0f, 100f,
2094 AlignmentAnnotation.BAR_GRAPH);
2095 initConsensus(complementConsensus);
2103 private void initConsensus(AlignmentAnnotation aa)
2106 aa.autoCalculated = true;
2110 alignment.addAnnotation(aa);
2114 public void initInformation()
2116 for (SequenceI seq : alignment.getHMMConsensusSequences())
2118 AlignmentAnnotation information;
2119 information = new AlignmentAnnotation(seq.getName(),
2120 MessageManager.getString("label.information_description"),
2121 new Annotation[1], 0f, 6.52f, AlignmentAnnotation.BAR_GRAPH);
2122 information.hasText = true;
2123 information.autoCalculated = true;
2124 information.hasText = true;
2125 information.autoCalculated = false;
2126 information.sequenceRef = seq;
2127 information.setCalcId("HMM annotation");
2128 this.information.add(information);
2129 hinformation.add(new Profiles(new ProfileI[1]));
2130 alignment.addAnnotation(information);
2131 seq.updateHMMMapping();
2136 // these should be extracted from the view model - style and settings for
2137 // derived annotation
2138 private void initGapCounts()
2142 gapcounts = new AlignmentAnnotation("Occupancy",
2143 MessageManager.getString("label.occupancy_descr"),
2144 new Annotation[1], 0f, alignment.getHeight(),
2145 AlignmentAnnotation.BAR_GRAPH);
2146 gapcounts.hasText = true;
2147 gapcounts.autoCalculated = true;
2148 gapcounts.scaleColLabel = true;
2149 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2151 alignment.addAnnotation(gapcounts);
2155 private void initConservation()
2157 if (showConservation)
2159 if (conservation == null)
2161 conservation = new AlignmentAnnotation("Conservation",
2162 MessageManager.formatMessage("label.conservation_descr",
2164 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2165 conservation.hasText = true;
2166 conservation.autoCalculated = true;
2167 alignment.addAnnotation(conservation);
2172 private void initQuality()
2176 if (quality == null)
2178 quality = new AlignmentAnnotation("Quality",
2179 MessageManager.getString("label.quality_descr"),
2180 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2181 quality.hasText = true;
2182 quality.autoCalculated = true;
2183 alignment.addAnnotation(quality);
2188 private void initRNAStructure()
2190 if (alignment.hasRNAStructure() && strucConsensus == null)
2192 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2193 MessageManager.getString("label.strucconsensus_descr"),
2194 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2195 strucConsensus.hasText = true;
2196 strucConsensus.autoCalculated = true;
2200 alignment.addAnnotation(strucConsensus);
2208 * @see jalview.api.AlignViewportI#calcPanelHeight()
2211 public int calcPanelHeight()
2213 // setHeight of panels
2214 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2216 int charHeight = getCharHeight();
2219 BitSet graphgrp = new BitSet();
2220 for (AlignmentAnnotation aa : anns)
2224 System.err.println("Null annotation row: ignoring.");
2231 if (aa.graphGroup > -1)
2233 if (graphgrp.get(aa.graphGroup))
2239 graphgrp.set(aa.graphGroup);
2246 aa.height += charHeight;
2256 aa.height += aa.graphHeight;
2264 height += aa.height;
2276 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2277 boolean preserveNewGroupSettings)
2279 boolean updateCalcs = false;
2280 boolean conv = isShowGroupConservation();
2281 boolean cons = isShowGroupConsensus();
2282 boolean showprf = isShowSequenceLogo();
2283 boolean showConsHist = isShowConsensusHistogram();
2284 boolean normLogo = isNormaliseSequenceLogo();
2285 boolean showHMMPrf = isShowHMMSequenceLogo();
2286 boolean showInfoHist = isShowInformationHistogram();
2287 boolean normHMMLogo = isNormaliseHMMSequenceLogo();
2290 * TODO reorder the annotation rows according to group/sequence ordering on
2293 boolean sortg = true;
2295 // remove old automatic annotation
2296 // add any new annotation
2298 // intersect alignment annotation with alignment groups
2300 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2301 List<SequenceGroup> oldrfs = new ArrayList<>();
2304 for (int an = 0; an < aan.length; an++)
2306 if (aan[an].autoCalculated && aan[an].groupRef != null)
2308 oldrfs.add(aan[an].groupRef);
2309 alignment.deleteAnnotation(aan[an], false);
2313 if (alignment.getGroups() != null)
2315 for (SequenceGroup sg : alignment.getGroups())
2317 updateCalcs = false;
2318 if (applyGlobalSettings
2319 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2321 // set defaults for this group's conservation/consensus
2322 sg.setshowSequenceLogo(showprf);
2323 sg.setShowConsensusHistogram(showConsHist);
2324 sg.setNormaliseSequenceLogo(normLogo);
2325 sg.setshowHMMSequenceLogo(showHMMPrf);
2326 sg.setShowInformationHistogram(showInfoHist);
2327 sg.setNormaliseHMMSequenceLogo(normHMMLogo);
2332 alignment.addAnnotation(sg.getConservationRow(), 0);
2337 alignment.addAnnotation(sg.getConsensus(), 0);
2339 // refresh the annotation rows
2342 sg.recalcConservation();
2350 public boolean isDisplayReferenceSeq()
2352 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2356 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2358 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2362 public boolean isColourByReferenceSeq()
2364 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2368 public Color getSequenceColour(SequenceI seq)
2370 Color sqc = sequenceColours.get(seq);
2371 return (sqc == null ? Color.white : sqc);
2375 public void setSequenceColour(SequenceI seq, Color col)
2379 sequenceColours.remove(seq);
2383 sequenceColours.put(seq, col);
2388 public void updateSequenceIdColours()
2390 for (SequenceGroup sg : alignment.getGroups())
2392 if (sg.idColour != null)
2394 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2396 sequenceColours.put(s, sg.idColour);
2403 public void clearSequenceColours()
2405 sequenceColours.clear();
2409 public AlignViewportI getCodingComplement()
2411 return this.codingComplement;
2415 * Set this as the (cDna/protein) complement of the given viewport. Also
2416 * ensures the reverse relationship is set on the given viewport.
2419 public void setCodingComplement(AlignViewportI av)
2423 System.err.println("Ignoring recursive setCodingComplement request");
2427 this.codingComplement = av;
2428 // avoid infinite recursion!
2429 if (av.getCodingComplement() != this)
2431 av.setCodingComplement(this);
2437 public boolean isNucleotide()
2439 return getAlignment() == null ? false : getAlignment().isNucleotide();
2443 public FeaturesDisplayedI getFeaturesDisplayed()
2445 return featuresDisplayed;
2449 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2451 featuresDisplayed = featuresDisplayedI;
2455 public boolean areFeaturesDisplayed()
2457 return featuresDisplayed != null
2458 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2465 * features are displayed if true
2468 public void setShowSequenceFeatures(boolean b)
2470 viewStyle.setShowSequenceFeatures(b);
2474 public boolean isShowSequenceFeatures()
2476 return viewStyle.isShowSequenceFeatures();
2480 public void setShowSequenceFeaturesHeight(boolean selected)
2482 viewStyle.setShowSequenceFeaturesHeight(selected);
2486 public boolean isShowSequenceFeaturesHeight()
2488 return viewStyle.isShowSequenceFeaturesHeight();
2492 public void setShowAnnotation(boolean b)
2494 viewStyle.setShowAnnotation(b);
2498 public boolean isShowAnnotation()
2500 return viewStyle.isShowAnnotation();
2504 public boolean isRightAlignIds()
2506 return viewStyle.isRightAlignIds();
2510 public void setRightAlignIds(boolean rightAlignIds)
2512 viewStyle.setRightAlignIds(rightAlignIds);
2516 public boolean getConservationSelected()
2518 return viewStyle.getConservationSelected();
2522 public void setShowBoxes(boolean state)
2524 viewStyle.setShowBoxes(state);
2529 * @see jalview.api.ViewStyleI#getTextColour()
2532 public Color getTextColour()
2534 return viewStyle.getTextColour();
2539 * @see jalview.api.ViewStyleI#getTextColour2()
2542 public Color getTextColour2()
2544 return viewStyle.getTextColour2();
2549 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2552 public int getThresholdTextColour()
2554 return viewStyle.getThresholdTextColour();
2559 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2562 public boolean isConservationColourSelected()
2564 return viewStyle.isConservationColourSelected();
2569 * @see jalview.api.ViewStyleI#isRenderGaps()
2572 public boolean isRenderGaps()
2574 return viewStyle.isRenderGaps();
2579 * @see jalview.api.ViewStyleI#isShowColourText()
2582 public boolean isShowColourText()
2584 return viewStyle.isShowColourText();
2588 * @param conservationColourSelected
2589 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2592 public void setConservationColourSelected(
2593 boolean conservationColourSelected)
2595 viewStyle.setConservationColourSelected(conservationColourSelected);
2599 * @param showColourText
2600 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2603 public void setShowColourText(boolean showColourText)
2605 viewStyle.setShowColourText(showColourText);
2610 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2613 public void setTextColour(Color textColour)
2615 viewStyle.setTextColour(textColour);
2619 * @param thresholdTextColour
2620 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2623 public void setThresholdTextColour(int thresholdTextColour)
2625 viewStyle.setThresholdTextColour(thresholdTextColour);
2629 * @param textColour2
2630 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2633 public void setTextColour2(Color textColour2)
2635 viewStyle.setTextColour2(textColour2);
2639 public ViewStyleI getViewStyle()
2641 return new ViewStyle(viewStyle);
2645 public void setViewStyle(ViewStyleI settingsForView)
2647 viewStyle = new ViewStyle(settingsForView);
2648 if (residueShading != null)
2650 residueShading.setConservationApplied(
2651 settingsForView.isConservationColourSelected());
2656 public boolean sameStyle(ViewStyleI them)
2658 return viewStyle.sameStyle(them);
2663 * @see jalview.api.ViewStyleI#getIdWidth()
2666 public int getIdWidth()
2668 return viewStyle.getIdWidth();
2673 * @see jalview.api.ViewStyleI#setIdWidth(int)
2676 public void setIdWidth(int i)
2678 viewStyle.setIdWidth(i);
2683 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2686 public boolean isCentreColumnLabels()
2688 return viewStyle.isCentreColumnLabels();
2692 * @param centreColumnLabels
2693 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2696 public void setCentreColumnLabels(boolean centreColumnLabels)
2698 viewStyle.setCentreColumnLabels(centreColumnLabels);
2703 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2706 public void setShowDBRefs(boolean showdbrefs)
2708 viewStyle.setShowDBRefs(showdbrefs);
2713 * @see jalview.api.ViewStyleI#isShowDBRefs()
2716 public boolean isShowDBRefs()
2718 return viewStyle.isShowDBRefs();
2723 * @see jalview.api.ViewStyleI#isShowNPFeats()
2726 public boolean isShowNPFeats()
2728 return viewStyle.isShowNPFeats();
2732 * @param shownpfeats
2733 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2736 public void setShowNPFeats(boolean shownpfeats)
2738 viewStyle.setShowNPFeats(shownpfeats);
2741 public abstract StructureSelectionManager getStructureSelectionManager();
2744 * Add one command to the command history list.
2748 public void addToHistoryList(CommandI command)
2750 if (this.historyList != null)
2752 this.historyList.push(command);
2753 broadcastCommand(command, false);
2757 protected void broadcastCommand(CommandI command, boolean undo)
2759 getStructureSelectionManager().commandPerformed(command, undo,
2764 * Add one command to the command redo list.
2768 public void addToRedoList(CommandI command)
2770 if (this.redoList != null)
2772 this.redoList.push(command);
2774 broadcastCommand(command, true);
2778 * Clear the command redo list.
2780 public void clearRedoList()
2782 if (this.redoList != null)
2784 this.redoList.clear();
2788 public void setHistoryList(Deque<CommandI> list)
2790 this.historyList = list;
2793 public Deque<CommandI> getHistoryList()
2795 return this.historyList;
2798 public void setRedoList(Deque<CommandI> list)
2800 this.redoList = list;
2803 public Deque<CommandI> getRedoList()
2805 return this.redoList;
2809 public VamsasSource getVamsasSource()
2814 public SequenceAnnotationOrder getSortAnnotationsBy()
2816 return sortAnnotationsBy;
2819 public void setSortAnnotationsBy(
2820 SequenceAnnotationOrder sortAnnotationsBy)
2822 this.sortAnnotationsBy = sortAnnotationsBy;
2825 public boolean isShowAutocalculatedAbove()
2827 return showAutocalculatedAbove;
2830 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2832 this.showAutocalculatedAbove = showAutocalculatedAbove;
2836 public boolean isScaleProteinAsCdna()
2838 return viewStyle.isScaleProteinAsCdna();
2842 public void setScaleProteinAsCdna(boolean b)
2844 viewStyle.setScaleProteinAsCdna(b);
2848 public boolean isProteinFontAsCdna()
2850 return viewStyle.isProteinFontAsCdna();
2854 public void setProteinFontAsCdna(boolean b)
2856 viewStyle.setProteinFontAsCdna(b);
2860 * @return true if view should scroll to show the highlighted region of a
2865 public final boolean isFollowHighlight()
2867 return followHighlight;
2871 public final void setFollowHighlight(boolean b)
2873 this.followHighlight = b;
2877 public ViewportRanges getRanges()
2883 * Helper method to populate the SearchResults with the location in the
2884 * complementary alignment to scroll to, in order to match this one.
2887 * the SearchResults to add to
2888 * @return the offset (below top of visible region) of the matched sequence
2890 protected int findComplementScrollTarget(SearchResultsI sr)
2892 final AlignViewportI complement = getCodingComplement();
2893 if (complement == null || !complement.isFollowHighlight())
2897 boolean iAmProtein = !getAlignment().isNucleotide();
2898 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2899 : complement.getAlignment();
2900 if (proteinAlignment == null)
2904 final List<AlignedCodonFrame> mappings = proteinAlignment
2908 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2909 * residue in the middle column of the visible region. Scroll the
2910 * complementary alignment to line up the corresponding residue.
2913 SequenceI sequence = null;
2916 * locate 'middle' column (true middle if an odd number visible, left of
2917 * middle if an even number visible)
2919 int middleColumn = ranges.getStartRes()
2920 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2921 final HiddenSequences hiddenSequences = getAlignment()
2922 .getHiddenSequences();
2925 * searching to the bottom of the alignment gives smoother scrolling across
2926 * all gapped visible regions
2928 int lastSeq = alignment.getHeight() - 1;
2929 List<AlignedCodonFrame> seqMappings = null;
2930 for (int seqNo = ranges
2931 .getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2933 sequence = getAlignment().getSequenceAt(seqNo);
2934 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2938 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2942 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2944 getCodingComplement().getAlignment().getSequences());
2945 if (!seqMappings.isEmpty())
2951 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2954 * No ungapped mapped sequence in middle column - do nothing
2958 MappingUtils.addSearchResults(sr, sequence,
2959 sequence.findPosition(middleColumn), seqMappings);
2964 * synthesize a column selection if none exists so it covers the given
2965 * selection group. if wholewidth is false, no column selection is made if the
2966 * selection group covers the whole alignment width.
2971 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2974 if (sg != null && (sgs = sg.getStartRes()) >= 0
2975 && sg.getStartRes() <= (sge = sg.getEndRes())
2976 && !this.hasSelectedColumns())
2978 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2985 colSel = new ColumnSelection();
2987 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2989 colSel.addElement(cspos);
2995 * hold status of current selection group - defined on alignment or not.
2997 private boolean selectionIsDefinedGroup = false;
3000 public boolean isSelectionDefinedGroup()
3002 if (selectionGroup == null)
3006 if (isSelectionGroupChanged(true))
3008 selectionIsDefinedGroup = false;
3009 List<SequenceGroup> gps = alignment.getGroups();
3010 if (gps == null || gps.size() == 0)
3012 selectionIsDefinedGroup = false;
3016 selectionIsDefinedGroup = gps.contains(selectionGroup);
3019 return selectionGroup.isDefined() || selectionIsDefinedGroup;
3023 * null, or currently highlighted results on this view
3025 private SearchResultsI searchResults = null;
3028 public boolean hasSearchResults()
3030 return searchResults != null;
3034 public void setSearchResults(SearchResultsI results)
3036 searchResults = results;
3040 public SearchResultsI getSearchResults()
3042 return searchResults;