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.analysis.TreeModel;
26 import jalview.api.AlignCalcManagerI;
27 import jalview.api.AlignExportSettingsI;
28 import jalview.api.AlignViewportI;
29 import jalview.api.AlignmentViewPanel;
30 import jalview.api.FeaturesDisplayedI;
31 import jalview.api.ViewStyleI;
32 import jalview.commands.CommandI;
33 import jalview.datamodel.AlignedCodonFrame;
34 import jalview.datamodel.AlignmentAnnotation;
35 import jalview.datamodel.AlignmentExportData;
36 import jalview.datamodel.AlignmentI;
37 import jalview.datamodel.AlignmentView;
38 import jalview.datamodel.Annotation;
39 import jalview.datamodel.ColumnSelection;
40 import jalview.datamodel.HiddenColumns;
41 import jalview.datamodel.HiddenSequences;
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.Iterator;
74 import java.util.List;
78 * base class holding visualization and analysis attributes and common logic for
79 * an active alignment view displayed in the GUI
84 public abstract class AlignmentViewport
85 implements AlignViewportI, CommandListener, VamsasSource
87 protected ViewportRanges ranges;
89 protected ViewStyleI viewStyle = new ViewStyle();
92 * A viewport that hosts the cDna view of this (protein), or vice versa (if
95 AlignViewportI codingComplement = null;
97 FeaturesDisplayedI featuresDisplayed = null;
99 protected Deque<CommandI> historyList = new ArrayDeque<>();
101 protected Deque<CommandI> redoList = new ArrayDeque<>();
104 * alignment displayed in the viewport. Please use get/setter
106 protected AlignmentI alignment;
109 * probably unused indicator that view is of a dataset rather than an
113 protected boolean ignoreBelowBackGroundFrequencyCalculation = false;
115 protected boolean infoLetterHeight = false;
117 protected AlignmentAnnotation occupancy;
120 * results of alignment consensus analysis for visible portion of view
122 protected ProfilesI consensusProfiles;
125 * HMM profile for the alignment
127 protected ProfilesI hmmProfiles;
129 public AlignmentViewport(AlignmentI al)
132 ranges = new ViewportRanges(al);
137 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
140 public void setFontName(String name)
142 viewStyle.setFontName(name);
147 * @see jalview.api.ViewStyleI#setFontStyle(int)
150 public void setFontStyle(int style)
152 viewStyle.setFontStyle(style);
157 * @see jalview.api.ViewStyleI#setFontSize(int)
160 public void setFontSize(int size)
162 viewStyle.setFontSize(size);
167 * @see jalview.api.ViewStyleI#getFontStyle()
170 public int getFontStyle()
172 return viewStyle.getFontStyle();
177 * @see jalview.api.ViewStyleI#getFontName()
180 public String getFontName()
182 return viewStyle.getFontName();
187 * @see jalview.api.ViewStyleI#getFontSize()
190 public int getFontSize()
192 return viewStyle.getFontSize();
196 * @param upperCasebold
197 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
200 public void setUpperCasebold(boolean upperCasebold)
202 viewStyle.setUpperCasebold(upperCasebold);
207 * @see jalview.api.ViewStyleI#isUpperCasebold()
210 public boolean isUpperCasebold()
212 return viewStyle.isUpperCasebold();
217 * @see jalview.api.ViewStyleI#isSeqNameItalics()
220 public boolean isSeqNameItalics()
222 return viewStyle.isSeqNameItalics();
226 * @param colourByReferenceSeq
227 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
230 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
232 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
237 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
240 public void setColourAppliesToAllGroups(boolean b)
242 viewStyle.setColourAppliesToAllGroups(b);
247 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
250 public boolean getColourAppliesToAllGroups()
252 return viewStyle.getColourAppliesToAllGroups();
257 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
260 public boolean getAbovePIDThreshold()
262 return viewStyle.getAbovePIDThreshold();
267 * @see jalview.api.ViewStyleI#setIncrement(int)
270 public void setIncrement(int inc)
272 viewStyle.setIncrement(inc);
277 * @see jalview.api.ViewStyleI#getIncrement()
280 public int getIncrement()
282 return viewStyle.getIncrement();
287 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
290 public void setConservationSelected(boolean b)
292 viewStyle.setConservationSelected(b);
297 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
300 public void setShowHiddenMarkers(boolean show)
302 viewStyle.setShowHiddenMarkers(show);
307 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
310 public boolean getShowHiddenMarkers()
312 return viewStyle.getShowHiddenMarkers();
317 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
320 public void setScaleRightWrapped(boolean b)
322 viewStyle.setScaleRightWrapped(b);
327 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
330 public void setScaleLeftWrapped(boolean b)
332 viewStyle.setScaleLeftWrapped(b);
337 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
340 public void setScaleAboveWrapped(boolean b)
342 viewStyle.setScaleAboveWrapped(b);
347 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
350 public boolean getScaleLeftWrapped()
352 return viewStyle.getScaleLeftWrapped();
357 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
360 public boolean getScaleAboveWrapped()
362 return viewStyle.getScaleAboveWrapped();
367 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
370 public boolean getScaleRightWrapped()
372 return viewStyle.getScaleRightWrapped();
377 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
380 public void setAbovePIDThreshold(boolean b)
382 viewStyle.setAbovePIDThreshold(b);
387 * @see jalview.api.ViewStyleI#setThreshold(int)
390 public void setThreshold(int thresh)
392 viewStyle.setThreshold(thresh);
397 * @see jalview.api.ViewStyleI#getThreshold()
400 public int getThreshold()
402 return viewStyle.getThreshold();
407 * @see jalview.api.ViewStyleI#getShowJVSuffix()
410 public boolean getShowJVSuffix()
412 return viewStyle.getShowJVSuffix();
417 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
420 public void setShowJVSuffix(boolean b)
422 viewStyle.setShowJVSuffix(b);
427 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
430 public void setWrapAlignment(boolean state)
432 viewStyle.setWrapAlignment(state);
433 ranges.setWrappedMode(state);
438 * @see jalview.api.ViewStyleI#setShowText(boolean)
441 public void setShowText(boolean state)
443 viewStyle.setShowText(state);
448 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
451 public void setRenderGaps(boolean state)
453 viewStyle.setRenderGaps(state);
458 * @see jalview.api.ViewStyleI#getColourText()
461 public boolean getColourText()
463 return viewStyle.getColourText();
468 * @see jalview.api.ViewStyleI#setColourText(boolean)
471 public void setColourText(boolean state)
473 viewStyle.setColourText(state);
478 * @see jalview.api.ViewStyleI#getWrapAlignment()
481 public boolean getWrapAlignment()
483 return viewStyle.getWrapAlignment();
488 * @see jalview.api.ViewStyleI#getShowText()
491 public boolean getShowText()
493 return viewStyle.getShowText();
498 * @see jalview.api.ViewStyleI#getWrappedWidth()
501 public int getWrappedWidth()
503 return viewStyle.getWrappedWidth();
508 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
511 public void setWrappedWidth(int w)
513 viewStyle.setWrappedWidth(w);
518 * @see jalview.api.ViewStyleI#getCharHeight()
521 public int getCharHeight()
523 return viewStyle.getCharHeight();
528 * @see jalview.api.ViewStyleI#setCharHeight(int)
531 public void setCharHeight(int h)
533 viewStyle.setCharHeight(h);
538 * @see jalview.api.ViewStyleI#getCharWidth()
541 public int getCharWidth()
543 return viewStyle.getCharWidth();
548 * @see jalview.api.ViewStyleI#setCharWidth(int)
551 public void setCharWidth(int w)
553 viewStyle.setCharWidth(w);
558 * @see jalview.api.ViewStyleI#getShowBoxes()
561 public boolean getShowBoxes()
563 return viewStyle.getShowBoxes();
568 * @see jalview.api.ViewStyleI#getShowUnconserved()
571 public boolean getShowUnconserved()
573 return viewStyle.getShowUnconserved();
577 * @param showunconserved
578 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
581 public void setShowUnconserved(boolean showunconserved)
583 viewStyle.setShowUnconserved(showunconserved);
588 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
591 public void setSeqNameItalics(boolean default1)
593 viewStyle.setSeqNameItalics(default1);
597 public AlignmentI getAlignment()
603 public char getGapCharacter()
605 return alignment.getGapCharacter();
608 protected String sequenceSetID;
611 * probably unused indicator that view is of a dataset rather than an
614 protected boolean isDataset = false;
616 public void setDataset(boolean b)
621 public boolean isDataset()
626 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
628 protected ColumnSelection colSel = new ColumnSelection();
630 public boolean autoCalculateConsensus = true;
632 protected boolean autoCalculateStrucConsensus = true;
634 protected boolean ignoreGapsInConsensusCalculation = false;
636 protected ResidueShaderI residueShading = new ResidueShader();
639 public void setGlobalColourScheme(ColourSchemeI cs)
641 // TODO: logic refactored from AlignFrame changeColour -
642 // TODO: autorecalc stuff should be changed to rely on the worker system
643 // check to see if we should implement a changeColour(cs) method rather than
644 // put the logic in here
645 // - means that caller decides if they want to just modify state and defer
646 // calculation till later or to do all calculations in thread.
650 * only instantiate alignment colouring once, thereafter update it;
651 * this means that any conservation or PID threshold settings
652 * persist when the alignment colour scheme is changed
654 if (residueShading == null)
656 residueShading = new ResidueShader(viewStyle);
658 residueShading.setColourScheme(cs);
660 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
661 // ...problem: groups need these, but do not currently have a ViewStyle
665 if (getConservationSelected())
667 residueShading.setConservation(hconservation);
670 * reset conservation flag in case just set to false if
671 * Conservation was null (calculation still in progress)
673 residueShading.setConservationApplied(getConservationSelected());
674 residueShading.alignmentChanged(alignment, hiddenRepSequences);
678 * if 'apply colour to all groups' is selected... do so
679 * (but don't transfer any colour threshold settings to groups)
681 if (getColourAppliesToAllGroups())
683 for (SequenceGroup sg : getAlignment().getGroups())
686 * retain any colour thresholds per group while
687 * changing choice of colour scheme (JAL-2386)
690 cs == null ? null : cs.getInstance(this, sg));
693 sg.getGroupColourScheme().alignmentChanged(sg,
701 public ColourSchemeI getGlobalColourScheme()
703 return residueShading == null ? null : residueShading.getColourScheme();
707 public ResidueShaderI getResidueShading()
709 return residueShading;
712 protected AlignmentAnnotation consensus;
714 protected AlignmentAnnotation complementConsensus;
716 protected AlignmentAnnotation gapcounts;
718 protected AlignmentAnnotation strucConsensus;
720 protected AlignmentAnnotation conservation;
722 protected AlignmentAnnotation quality;
724 protected AlignmentAnnotation[] groupConsensus;
726 protected AlignmentAnnotation[] groupConservation;
729 * results of alignment consensus analysis for visible portion of view
731 protected ProfilesI hconsensus = null;
734 * results of cDNA complement consensus visible portion of view
736 protected Hashtable<String, Object>[] hcomplementConsensus = null;
739 * results of secondary structure base pair consensus for visible portion of
742 protected Hashtable<String, Object>[] hStrucConsensus = null;
744 protected Conservation hconservation = null;
747 public void setConservation(Conservation cons)
749 hconservation = cons;
753 * percentage gaps allowed in a column before all amino acid properties should
754 * be considered unconserved
756 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
759 public int getConsPercGaps()
765 public void setSequenceConsensusHash(ProfilesI hconsensus)
767 this.hconsensus = hconsensus;
771 public void setComplementConsensusHash(
772 Hashtable<String, Object>[] hconsensus)
774 this.hcomplementConsensus = hconsensus;
778 public ProfilesI getSequenceConsensusHash()
784 public void setHmmProfiles(ProfilesI info)
790 public ProfilesI getHmmProfiles()
796 public Hashtable<String, Object>[] getComplementConsensusHash()
798 return hcomplementConsensus;
802 public Hashtable<String, Object>[] getRnaStructureConsensusHash()
804 return hStrucConsensus;
808 public void setRnaStructureConsensusHash(
809 Hashtable<String, Object>[] hStrucConsensus)
811 this.hStrucConsensus = hStrucConsensus;
816 public AlignmentAnnotation getAlignmentQualityAnnot()
822 public AlignmentAnnotation getAlignmentConservationAnnotation()
828 public AlignmentAnnotation getAlignmentConsensusAnnotation()
834 public AlignmentAnnotation getAlignmentGapAnnotation()
840 public AlignmentAnnotation getComplementConsensusAnnotation()
842 return complementConsensus;
846 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
848 return strucConsensus;
851 protected AlignCalcManagerI calculator = new AlignCalcManager();
854 * trigger update of conservation annotation
856 public void updateConservation(final AlignmentViewPanel ap)
858 // see note in mantis : issue number 8585
859 if (alignment.isNucleotide()
860 || (conservation == null && quality == null)
861 || !autoCalculateConsensus)
865 if (calculator.getRegisteredWorkersOfClass(
866 jalview.workers.ConservationThread.class) == null)
868 calculator.registerWorker(
869 new jalview.workers.ConservationThread(this, ap));
874 * trigger update of consensus annotation
876 public void updateConsensus(final AlignmentViewPanel ap)
878 // see note in mantis : issue number 8585
879 if (consensus == null || !autoCalculateConsensus)
884 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
886 calculator.registerWorker(new ConsensusThread(this, ap));
890 * A separate thread to compute cDNA consensus for a protein alignment
891 * which has mapping to cDNA
893 final AlignmentI al = this.getAlignment();
894 if (!al.isNucleotide() && al.getCodonFrames() != null
895 && !al.getCodonFrames().isEmpty())
898 * fudge - check first for protein-to-nucleotide mappings
899 * (we don't want to do this for protein-to-protein)
901 boolean doConsensus = false;
902 for (AlignedCodonFrame mapping : al.getCodonFrames())
904 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
905 MapList[] mapLists = mapping.getdnaToProt();
906 // mapLists can be empty if project load has not finished resolving seqs
907 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
915 if (calculator.getRegisteredWorkersOfClass(
916 ComplementConsensusThread.class) == null)
919 .registerWorker(new ComplementConsensusThread(this, ap));
926 public void initInformationWorker(final AlignmentViewPanel ap)
929 .getRegisteredWorkersOfClass(InformationThread.class) == null)
931 calculator.registerWorker(new InformationThread(this, ap));
935 // --------START Structure Conservation
936 public void updateStrucConsensus(final AlignmentViewPanel ap)
938 if (autoCalculateStrucConsensus && strucConsensus == null
939 && alignment.isNucleotide() && alignment.hasRNAStructure())
941 // secondary structure has been added - so init the consensus line
945 // see note in mantis : issue number 8585
946 if (strucConsensus == null || !autoCalculateStrucConsensus)
950 if (calculator.getRegisteredWorkersOfClass(
951 StrucConsensusThread.class) == null)
953 calculator.registerWorker(new StrucConsensusThread(this, ap));
957 public boolean isCalcInProgress()
959 return calculator.isWorking();
963 public boolean isCalculationInProgress(
964 AlignmentAnnotation alignmentAnnotation)
966 if (!alignmentAnnotation.autoCalculated)
970 if (calculator.workingInvolvedWith(alignmentAnnotation))
972 // System.err.println("grey out ("+alignmentAnnotation.label+")");
978 public void setAlignment(AlignmentI align)
980 this.alignment = align;
984 * Clean up references when this viewport is closed
987 public void dispose()
990 * defensively null out references to large objects in case
991 * this object is not garbage collected (as if!)
994 complementConsensus = null;
995 strucConsensus = null;
998 consensusProfiles = null;
999 groupConsensus = null;
1000 groupConservation = null;
1002 hconservation = null;
1003 hcomplementConsensus = null;
1006 residueShading = null; // may hold a reference to Consensus
1007 changeSupport = null;
1010 selectionGroup = null;
1015 public boolean isClosed()
1017 // TODO: check that this isClosed is only true after panel is closed, not
1018 // before it is fully constructed.
1019 return alignment == null;
1023 public AlignCalcManagerI getCalcManager()
1029 * should conservation rows be shown for groups
1031 protected boolean showGroupConservation = false;
1034 * should consensus rows be shown for groups
1036 protected boolean showGroupConsensus = false;
1039 * should consensus profile be rendered by default
1041 protected boolean showSequenceLogo = false;
1044 * should consensus profile be rendered normalised to row height
1046 protected boolean normaliseSequenceLogo = false;
1049 * should consensus histograms be rendered by default
1051 protected boolean showConsensusHistogram = true;
1054 * should hmm profile be rendered by default
1056 protected boolean hmmShowSequenceLogo = false;
1059 * should hmm profile be rendered normalised to row height
1061 protected boolean hmmNormaliseSequenceLogo = false;
1064 * should information histograms be rendered by default
1066 protected boolean hmmShowHistogram = true;
1069 * @return the showConsensusProfile
1072 public boolean isShowSequenceLogo()
1074 return showSequenceLogo;
1078 * @return the showInformationProfile
1081 public boolean isShowHMMSequenceLogo()
1083 return hmmShowSequenceLogo;
1087 * @param showSequenceLogo
1090 public void setShowSequenceLogo(boolean showSequenceLogo)
1092 if (showSequenceLogo != this.showSequenceLogo)
1094 // TODO: decouple settings setting from calculation when refactoring
1095 // annotation update method from alignframe to viewport
1096 this.showSequenceLogo = showSequenceLogo;
1097 calculator.updateAnnotationFor(ConsensusThread.class);
1098 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1099 calculator.updateAnnotationFor(StrucConsensusThread.class);
1101 this.showSequenceLogo = showSequenceLogo;
1104 public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo)
1106 if (showHMMSequenceLogo != this.hmmShowSequenceLogo)
1108 this.hmmShowSequenceLogo = showHMMSequenceLogo;
1109 // TODO: updateAnnotation if description (tooltip) will show
1110 // profile in place of information content?
1111 // calculator.updateAnnotationFor(InformationThread.class);
1113 this.hmmShowSequenceLogo = showHMMSequenceLogo;
1117 * @param showConsensusHistogram
1118 * the showConsensusHistogram to set
1120 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1122 this.showConsensusHistogram = showConsensusHistogram;
1126 * @param showInformationHistogram
1128 public void setShowInformationHistogram(boolean showInformationHistogram)
1130 this.hmmShowHistogram = 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.hmmShowHistogram;
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 alignment.getHiddenColumns() != 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);
1347 public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap)
1349 ignoreBelowBackGroundFrequencyCalculation = b;
1352 public void setInfoLetterHeight(boolean b, AlignmentViewPanel ap)
1354 infoLetterHeight = b;
1357 private long sgrouphash = -1, colselhash = -1;
1360 * checks current SelectionGroup against record of last hash value, and
1364 * update the record of last hash value
1366 * @return true if SelectionGroup changed since last call (when b is true)
1368 public boolean isSelectionGroupChanged(boolean b)
1370 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1371 : selectionGroup.hashCode();
1372 if (hc != -1 && hc != sgrouphash)
1384 * checks current colsel against record of last hash value, and optionally
1388 * update the record of last hash value
1389 * @return true if colsel changed since last call (when b is true)
1391 public boolean isColSelChanged(boolean b)
1393 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1394 if (hc != -1 && hc != colselhash)
1406 public boolean isIgnoreGapsConsensus()
1408 return ignoreGapsInConsensusCalculation;
1412 public boolean isIgnoreBelowBackground()
1414 return ignoreBelowBackGroundFrequencyCalculation;
1418 public boolean isInfoLetterHeight()
1420 return infoLetterHeight;
1423 // property change stuff
1424 // JBPNote Prolly only need this in the applet version.
1425 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1428 protected boolean showConservation = true;
1430 protected boolean showQuality = true;
1432 protected boolean showConsensus = true;
1434 protected boolean showOccupancy = true;
1436 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1438 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1440 protected boolean showAutocalculatedAbove;
1443 * when set, view will scroll to show the highlighted position
1445 private boolean followHighlight = true;
1448 * Property change listener for changes in alignment
1453 public void addPropertyChangeListener(
1454 java.beans.PropertyChangeListener listener)
1456 changeSupport.addPropertyChangeListener(listener);
1465 public void removePropertyChangeListener(
1466 java.beans.PropertyChangeListener listener)
1468 if (changeSupport != null)
1470 changeSupport.removePropertyChangeListener(listener);
1475 * Property change listener for changes in alignment
1484 public void firePropertyChange(String prop, Object oldvalue,
1487 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1490 // common hide/show column stuff
1492 public void hideSelectedColumns()
1494 if (colSel.isEmpty())
1499 colSel.hideSelectedColumns(alignment);
1500 setSelectionGroup(null);
1501 isColSelChanged(true);
1504 public void hideColumns(int start, int end)
1508 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1512 alignment.getHiddenColumns().hideColumns(start, end);
1514 isColSelChanged(true);
1517 public void showColumn(int col)
1519 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1520 isColSelChanged(true);
1523 public void showAllHiddenColumns()
1525 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1526 isColSelChanged(true);
1529 // common hide/show seq stuff
1530 public void showAllHiddenSeqs()
1532 int startSeq = ranges.getStartSeq();
1533 int endSeq = ranges.getEndSeq();
1535 if (alignment.getHiddenSequences().getSize() > 0)
1537 if (selectionGroup == null)
1539 selectionGroup = new SequenceGroup();
1540 selectionGroup.setEndRes(alignment.getWidth() - 1);
1542 List<SequenceI> tmp = alignment.getHiddenSequences()
1543 .showAll(hiddenRepSequences);
1544 for (SequenceI seq : tmp)
1546 selectionGroup.addSequence(seq, false);
1547 setSequenceAnnotationsVisible(seq, true);
1550 hiddenRepSequences = null;
1552 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1554 firePropertyChange("alignment", null, alignment.getSequences());
1555 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1561 public void showSequence(int index)
1563 int startSeq = ranges.getStartSeq();
1564 int endSeq = ranges.getEndSeq();
1566 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1567 hiddenRepSequences);
1570 if (selectionGroup == null)
1572 selectionGroup = new SequenceGroup();
1573 selectionGroup.setEndRes(alignment.getWidth() - 1);
1576 for (SequenceI seq : tmp)
1578 selectionGroup.addSequence(seq, false);
1579 setSequenceAnnotationsVisible(seq, true);
1582 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1584 firePropertyChange("alignment", null, alignment.getSequences());
1589 public void hideAllSelectedSeqs()
1591 if (selectionGroup == null || selectionGroup.getSize() < 1)
1596 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1600 setSelectionGroup(null);
1603 public void hideSequence(SequenceI[] seq)
1606 * cache offset to first visible sequence
1608 int startSeq = ranges.getStartSeq();
1612 for (int i = 0; i < seq.length; i++)
1614 alignment.getHiddenSequences().hideSequence(seq[i]);
1615 setSequenceAnnotationsVisible(seq[i], false);
1617 ranges.setStartSeq(startSeq);
1618 firePropertyChange("alignment", null, alignment.getSequences());
1623 * Hides the specified sequence, or the sequences it represents
1626 * the sequence to hide, or keep as representative
1627 * @param representGroup
1628 * if true, hide the current selection group except for the
1629 * representative sequence
1631 public void hideSequences(SequenceI sequence, boolean representGroup)
1633 if (selectionGroup == null || selectionGroup.getSize() < 1)
1635 hideSequence(new SequenceI[] { sequence });
1641 hideRepSequences(sequence, selectionGroup);
1642 setSelectionGroup(null);
1646 int gsize = selectionGroup.getSize();
1647 SequenceI[] hseqs = selectionGroup.getSequences()
1648 .toArray(new SequenceI[gsize]);
1650 hideSequence(hseqs);
1651 setSelectionGroup(null);
1656 * Set visibility for any annotations for the given sequence.
1660 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1663 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1666 for (AlignmentAnnotation ann : anns)
1668 if (ann.sequenceRef == sequenceI)
1670 ann.visible = visible;
1676 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1678 int sSize = sg.getSize();
1684 if (hiddenRepSequences == null)
1686 hiddenRepSequences = new Hashtable<>();
1689 hiddenRepSequences.put(repSequence, sg);
1691 // Hide all sequences except the repSequence
1692 SequenceI[] seqs = new SequenceI[sSize - 1];
1694 for (int i = 0; i < sSize; i++)
1696 if (sg.getSequenceAt(i) != repSequence)
1698 if (index == sSize - 1)
1703 seqs[index++] = sg.getSequenceAt(i);
1706 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1707 sg.setHidereps(true); // note: not done in 2.7applet
1714 * @return null or the current reference sequence
1716 public SequenceI getReferenceSeq()
1718 return alignment.getSeqrep();
1723 * @return true iff seq is the reference for the alignment
1725 public boolean isReferenceSeq(SequenceI seq)
1727 return alignment.getSeqrep() == seq;
1733 * @return true if there are sequences represented by this sequence that are
1736 public boolean isHiddenRepSequence(SequenceI seq)
1738 return (hiddenRepSequences != null
1739 && hiddenRepSequences.containsKey(seq));
1745 * @return null or a sequence group containing the sequences that seq
1748 public SequenceGroup getRepresentedSequences(SequenceI seq)
1750 return (SequenceGroup) (hiddenRepSequences == null ? null
1751 : hiddenRepSequences.get(seq));
1755 public int adjustForHiddenSeqs(int alignmentIndex)
1757 return alignment.getHiddenSequences()
1758 .adjustForHiddenSeqs(alignmentIndex);
1762 public void invertColumnSelection()
1764 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1765 isColSelChanged(true);
1769 public SequenceI[] getSelectionAsNewSequence()
1771 SequenceI[] sequences;
1772 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1773 // this was the only caller in the applet for this method
1774 // JBPNote: in applet, this method returned references to the alignment
1775 // sequences, and it did not honour the presence/absence of annotation
1776 // attached to the alignment (probably!)
1777 if (selectionGroup == null || selectionGroup.getSize() == 0)
1779 sequences = alignment.getSequencesArray();
1780 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1781 for (int i = 0; i < sequences.length; i++)
1783 // construct new sequence with subset of visible annotation
1784 sequences[i] = new Sequence(sequences[i], annots);
1789 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1796 public SequenceI[] getSequenceSelection()
1798 SequenceI[] sequences = null;
1799 if (selectionGroup != null)
1801 sequences = selectionGroup.getSequencesInOrder(alignment);
1803 if (sequences == null)
1805 sequences = alignment.getSequencesArray();
1811 public jalview.datamodel.AlignmentView getAlignmentView(
1812 boolean selectedOnly)
1814 return getAlignmentView(selectedOnly, false);
1818 public jalview.datamodel.AlignmentView getAlignmentView(
1819 boolean selectedOnly, boolean markGroups)
1821 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1823 alignment.getHiddenColumns() != null
1824 && alignment.getHiddenColumns().hasHiddenColumns(),
1825 selectedOnly, markGroups);
1829 public String[] getViewAsString(boolean selectedRegionOnly)
1831 return getViewAsString(selectedRegionOnly, true);
1835 public String[] getViewAsString(boolean selectedRegionOnly,
1836 boolean exportHiddenSeqs)
1838 String[] selection = null;
1839 SequenceI[] seqs = null;
1841 int start = 0, end = 0;
1842 if (selectedRegionOnly && selectionGroup != null)
1844 iSize = selectionGroup.getSize();
1845 seqs = selectionGroup.getSequencesInOrder(alignment);
1846 start = selectionGroup.getStartRes();
1847 end = selectionGroup.getEndRes() + 1;
1851 if (hasHiddenRows() && exportHiddenSeqs)
1853 AlignmentI fullAlignment = alignment.getHiddenSequences()
1854 .getFullAlignment();
1855 iSize = fullAlignment.getHeight();
1856 seqs = fullAlignment.getSequencesArray();
1857 end = fullAlignment.getWidth();
1861 iSize = alignment.getHeight();
1862 seqs = alignment.getSequencesArray();
1863 end = alignment.getWidth();
1867 selection = new String[iSize];
1868 if (alignment.getHiddenColumns() != null
1869 && alignment.getHiddenColumns().hasHiddenColumns())
1871 for (i = 0; i < iSize; i++)
1873 Iterator<int[]> blocks = alignment.getHiddenColumns()
1874 .getVisContigsIterator(start, end + 1, false);
1875 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1880 for (i = 0; i < iSize; i++)
1882 selection[i] = seqs[i].getSequenceAsString(start, end);
1890 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1892 ArrayList<int[]> regions = new ArrayList<>();
1898 HiddenColumns hidden = alignment.getHiddenColumns();
1899 if (hidden != null && hidden.hasHiddenColumns())
1903 start = hidden.visibleToAbsoluteColumn(start);
1906 end = hidden.getNextHiddenBoundary(false, start);
1917 regions.add(new int[] { start, end });
1919 if (hidden != null && hidden.hasHiddenColumns())
1921 start = hidden.visibleToAbsoluteColumn(end);
1922 start = hidden.getNextHiddenBoundary(true, start) + 1;
1924 } while (end < max);
1926 // int[][] startEnd = new int[regions.size()][2];
1932 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1933 boolean selectedOnly)
1935 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1936 AlignmentAnnotation[] aa;
1937 if ((aa = alignment.getAlignmentAnnotation()) != null)
1939 for (AlignmentAnnotation annot : aa)
1941 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1942 if (selectedOnly && selectionGroup != null)
1944 clone.makeVisibleAnnotation(
1945 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1946 alignment.getHiddenColumns());
1950 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1959 public boolean isPadGaps()
1965 public void setPadGaps(boolean padGaps)
1967 this.padGaps = padGaps;
1971 * apply any post-edit constraints and trigger any calculations needed after
1972 * an edit has been performed on the alignment
1977 public void alignmentChanged(AlignmentViewPanel ap)
1981 alignment.padGaps();
1983 if (autoCalculateConsensus)
1985 updateConsensus(ap);
1987 if (hconsensus != null && autoCalculateConsensus)
1989 updateConservation(ap);
1991 if (autoCalculateStrucConsensus)
1993 updateStrucConsensus(ap);
1996 // Reset endRes of groups if beyond alignment width
1997 int alWidth = alignment.getWidth();
1998 List<SequenceGroup> groups = alignment.getGroups();
2001 for (SequenceGroup sg : groups)
2003 if (sg.getEndRes() > alWidth)
2005 sg.setEndRes(alWidth - 1);
2010 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
2012 selectionGroup.setEndRes(alWidth - 1);
2015 updateAllColourSchemes();
2016 calculator.restartWorkers();
2020 * reset scope and do calculations for all applied colourschemes on alignment
2022 void updateAllColourSchemes()
2024 ResidueShaderI rs = residueShading;
2027 rs.alignmentChanged(alignment, hiddenRepSequences);
2029 rs.setConsensus(hconsensus);
2030 if (rs.conservationApplied())
2032 rs.setConservation(Conservation.calculateConservation("All",
2033 alignment.getSequences(), 0, alignment.getWidth(), false,
2034 getConsPercGaps(), false));
2038 for (SequenceGroup sg : alignment.getGroups())
2042 sg.cs.alignmentChanged(sg, hiddenRepSequences);
2044 sg.recalcConservation();
2048 protected void initAutoAnnotation()
2050 // TODO: add menu option action that nulls or creates consensus object
2051 // depending on if the user wants to see the annotation or not in a
2052 // specific alignment
2054 if (hconsensus == null && !isDataset)
2056 if (!alignment.isNucleotide())
2065 consensus = new AlignmentAnnotation("Consensus",
2066 MessageManager.getString("label.consensus_descr"),
2067 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2068 initConsensus(consensus);
2072 initComplementConsensus();
2077 * If this is a protein alignment and there are mappings to cDNA, adds the
2078 * cDNA consensus annotation and returns true, else returns false.
2080 public boolean initComplementConsensus()
2082 if (!alignment.isNucleotide())
2084 final List<AlignedCodonFrame> codonMappings = alignment
2086 if (codonMappings != null && !codonMappings.isEmpty())
2088 boolean doConsensus = false;
2089 for (AlignedCodonFrame mapping : codonMappings)
2091 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2092 MapList[] mapLists = mapping.getdnaToProt();
2093 // mapLists can be empty if project load has not finished resolving
2095 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2103 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2105 .getString("label.complement_consensus_descr"),
2106 new Annotation[1], 0f, 100f,
2107 AlignmentAnnotation.BAR_GRAPH);
2108 initConsensus(complementConsensus);
2116 private void initConsensus(AlignmentAnnotation aa)
2119 aa.autoCalculated = true;
2123 alignment.addAnnotation(aa);
2127 // these should be extracted from the view model - style and settings for
2128 // derived annotation
2129 private void initGapCounts()
2133 gapcounts = new AlignmentAnnotation("Occupancy",
2134 MessageManager.getString("label.occupancy_descr"),
2135 new Annotation[1], 0f, alignment.getHeight(),
2136 AlignmentAnnotation.BAR_GRAPH);
2137 gapcounts.hasText = true;
2138 gapcounts.autoCalculated = true;
2139 gapcounts.scaleColLabel = true;
2140 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2142 alignment.addAnnotation(gapcounts);
2146 private void initConservation()
2148 if (showConservation)
2150 if (conservation == null)
2152 conservation = new AlignmentAnnotation("Conservation",
2153 MessageManager.formatMessage("label.conservation_descr",
2155 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2156 conservation.hasText = true;
2157 conservation.autoCalculated = true;
2158 alignment.addAnnotation(conservation);
2163 private void initQuality()
2167 if (quality == null)
2169 quality = new AlignmentAnnotation("Quality",
2170 MessageManager.getString("label.quality_descr"),
2171 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2172 quality.hasText = true;
2173 quality.autoCalculated = true;
2174 alignment.addAnnotation(quality);
2179 private void initRNAStructure()
2181 if (alignment.hasRNAStructure() && strucConsensus == null)
2183 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2184 MessageManager.getString("label.strucconsensus_descr"),
2185 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2186 strucConsensus.hasText = true;
2187 strucConsensus.autoCalculated = true;
2191 alignment.addAnnotation(strucConsensus);
2199 * @see jalview.api.AlignViewportI#calcPanelHeight()
2202 public int calcPanelHeight()
2204 // setHeight of panels
2205 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2207 int charHeight = getCharHeight();
2210 BitSet graphgrp = new BitSet();
2211 for (AlignmentAnnotation aa : anns)
2215 System.err.println("Null annotation row: ignoring.");
2222 if (aa.graphGroup > -1)
2224 if (graphgrp.get(aa.graphGroup))
2230 graphgrp.set(aa.graphGroup);
2237 aa.height += charHeight;
2247 aa.height += aa.graphHeight;
2255 height += aa.height;
2267 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2268 boolean preserveNewGroupSettings)
2270 boolean updateCalcs = false;
2271 boolean conv = isShowGroupConservation();
2272 boolean cons = isShowGroupConsensus();
2273 boolean showprf = isShowSequenceLogo();
2274 boolean showConsHist = isShowConsensusHistogram();
2275 boolean normLogo = isNormaliseSequenceLogo();
2276 boolean showHMMPrf = isShowHMMSequenceLogo();
2277 boolean showInfoHist = isShowInformationHistogram();
2278 boolean normHMMLogo = isNormaliseHMMSequenceLogo();
2281 * TODO reorder the annotation rows according to group/sequence ordering on
2284 // boolean sortg = true;
2286 // remove old automatic annotation
2287 // add any new annotation
2289 // intersect alignment annotation with alignment groups
2291 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2292 List<SequenceGroup> oldrfs = new ArrayList<>();
2295 for (int an = 0; an < aan.length; an++)
2297 if (aan[an].autoCalculated && aan[an].groupRef != null)
2299 oldrfs.add(aan[an].groupRef);
2300 alignment.deleteAnnotation(aan[an], false);
2304 if (alignment.getGroups() != null)
2306 for (SequenceGroup sg : alignment.getGroups())
2308 updateCalcs = false;
2309 if (applyGlobalSettings
2310 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2312 // set defaults for this group's conservation/consensus
2313 sg.setshowSequenceLogo(showprf);
2314 sg.setShowConsensusHistogram(showConsHist);
2315 sg.setNormaliseSequenceLogo(normLogo);
2316 sg.setShowHMMSequenceLogo(showHMMPrf);
2317 sg.setShowInformationHistogram(showInfoHist);
2318 sg.setNormaliseHMMSequenceLogo(normHMMLogo);
2323 alignment.addAnnotation(sg.getConservationRow(), 0);
2328 alignment.addAnnotation(sg.getConsensus(), 0);
2330 // refresh the annotation rows
2333 sg.recalcConservation();
2341 public boolean isDisplayReferenceSeq()
2343 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2347 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2349 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2353 public boolean isColourByReferenceSeq()
2355 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2359 public Color getSequenceColour(SequenceI seq)
2361 Color sqc = sequenceColours.get(seq);
2362 return (sqc == null ? Color.white : sqc);
2366 public void setSequenceColour(SequenceI seq, Color col)
2370 sequenceColours.remove(seq);
2374 sequenceColours.put(seq, col);
2379 public void updateSequenceIdColours()
2381 for (SequenceGroup sg : alignment.getGroups())
2383 if (sg.idColour != null)
2385 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2387 sequenceColours.put(s, sg.idColour);
2394 public void clearSequenceColours()
2396 sequenceColours.clear();
2400 public AlignViewportI getCodingComplement()
2402 return this.codingComplement;
2406 * Set this as the (cDna/protein) complement of the given viewport. Also
2407 * ensures the reverse relationship is set on the given viewport.
2410 public void setCodingComplement(AlignViewportI av)
2414 System.err.println("Ignoring recursive setCodingComplement request");
2418 this.codingComplement = av;
2419 // avoid infinite recursion!
2420 if (av.getCodingComplement() != this)
2422 av.setCodingComplement(this);
2428 public boolean isNucleotide()
2430 return getAlignment() == null ? false : getAlignment().isNucleotide();
2434 public FeaturesDisplayedI getFeaturesDisplayed()
2436 return featuresDisplayed;
2440 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2442 featuresDisplayed = featuresDisplayedI;
2446 public boolean areFeaturesDisplayed()
2448 return featuresDisplayed != null
2449 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2456 * features are displayed if true
2459 public void setShowSequenceFeatures(boolean b)
2461 viewStyle.setShowSequenceFeatures(b);
2465 public boolean isShowSequenceFeatures()
2467 return viewStyle.isShowSequenceFeatures();
2471 public void setShowSequenceFeaturesHeight(boolean selected)
2473 viewStyle.setShowSequenceFeaturesHeight(selected);
2477 public boolean isShowSequenceFeaturesHeight()
2479 return viewStyle.isShowSequenceFeaturesHeight();
2483 public void setShowAnnotation(boolean b)
2485 viewStyle.setShowAnnotation(b);
2489 public boolean isShowAnnotation()
2491 return viewStyle.isShowAnnotation();
2495 public boolean isRightAlignIds()
2497 return viewStyle.isRightAlignIds();
2501 public void setRightAlignIds(boolean rightAlignIds)
2503 viewStyle.setRightAlignIds(rightAlignIds);
2507 public boolean getConservationSelected()
2509 return viewStyle.getConservationSelected();
2513 public void setShowBoxes(boolean state)
2515 viewStyle.setShowBoxes(state);
2520 * @see jalview.api.ViewStyleI#getTextColour()
2523 public Color getTextColour()
2525 return viewStyle.getTextColour();
2530 * @see jalview.api.ViewStyleI#getTextColour2()
2533 public Color getTextColour2()
2535 return viewStyle.getTextColour2();
2540 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2543 public int getThresholdTextColour()
2545 return viewStyle.getThresholdTextColour();
2550 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2553 public boolean isConservationColourSelected()
2555 return viewStyle.isConservationColourSelected();
2560 * @see jalview.api.ViewStyleI#isRenderGaps()
2563 public boolean isRenderGaps()
2565 return viewStyle.isRenderGaps();
2570 * @see jalview.api.ViewStyleI#isShowColourText()
2573 public boolean isShowColourText()
2575 return viewStyle.isShowColourText();
2579 * @param conservationColourSelected
2580 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2583 public void setConservationColourSelected(
2584 boolean conservationColourSelected)
2586 viewStyle.setConservationColourSelected(conservationColourSelected);
2590 * @param showColourText
2591 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2594 public void setShowColourText(boolean showColourText)
2596 viewStyle.setShowColourText(showColourText);
2601 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2604 public void setTextColour(Color textColour)
2606 viewStyle.setTextColour(textColour);
2610 * @param thresholdTextColour
2611 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2614 public void setThresholdTextColour(int thresholdTextColour)
2616 viewStyle.setThresholdTextColour(thresholdTextColour);
2620 * @param textColour2
2621 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2624 public void setTextColour2(Color textColour2)
2626 viewStyle.setTextColour2(textColour2);
2630 public ViewStyleI getViewStyle()
2632 return new ViewStyle(viewStyle);
2636 public void setViewStyle(ViewStyleI settingsForView)
2638 viewStyle = new ViewStyle(settingsForView);
2639 if (residueShading != null)
2641 residueShading.setConservationApplied(
2642 settingsForView.isConservationColourSelected());
2647 public boolean sameStyle(ViewStyleI them)
2649 return viewStyle.sameStyle(them);
2654 * @see jalview.api.ViewStyleI#getIdWidth()
2657 public int getIdWidth()
2659 return viewStyle.getIdWidth();
2664 * @see jalview.api.ViewStyleI#setIdWidth(int)
2667 public void setIdWidth(int i)
2669 viewStyle.setIdWidth(i);
2674 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2677 public boolean isCentreColumnLabels()
2679 return viewStyle.isCentreColumnLabels();
2683 * @param centreColumnLabels
2684 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2687 public void setCentreColumnLabels(boolean centreColumnLabels)
2689 viewStyle.setCentreColumnLabels(centreColumnLabels);
2694 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2697 public void setShowDBRefs(boolean showdbrefs)
2699 viewStyle.setShowDBRefs(showdbrefs);
2704 * @see jalview.api.ViewStyleI#isShowDBRefs()
2707 public boolean isShowDBRefs()
2709 return viewStyle.isShowDBRefs();
2714 * @see jalview.api.ViewStyleI#isShowNPFeats()
2717 public boolean isShowNPFeats()
2719 return viewStyle.isShowNPFeats();
2723 * @param shownpfeats
2724 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2727 public void setShowNPFeats(boolean shownpfeats)
2729 viewStyle.setShowNPFeats(shownpfeats);
2732 public abstract StructureSelectionManager getStructureSelectionManager();
2735 * Add one command to the command history list.
2739 public void addToHistoryList(CommandI command)
2741 if (this.historyList != null)
2743 this.historyList.push(command);
2744 broadcastCommand(command, false);
2748 protected void broadcastCommand(CommandI command, boolean undo)
2750 getStructureSelectionManager().commandPerformed(command, undo,
2755 * Add one command to the command redo list.
2759 public void addToRedoList(CommandI command)
2761 if (this.redoList != null)
2763 this.redoList.push(command);
2765 broadcastCommand(command, true);
2769 * Clear the command redo list.
2771 public void clearRedoList()
2773 if (this.redoList != null)
2775 this.redoList.clear();
2779 public void setHistoryList(Deque<CommandI> list)
2781 this.historyList = list;
2784 public Deque<CommandI> getHistoryList()
2786 return this.historyList;
2789 public void setRedoList(Deque<CommandI> list)
2791 this.redoList = list;
2794 public Deque<CommandI> getRedoList()
2796 return this.redoList;
2800 public VamsasSource getVamsasSource()
2805 public SequenceAnnotationOrder getSortAnnotationsBy()
2807 return sortAnnotationsBy;
2810 public void setSortAnnotationsBy(
2811 SequenceAnnotationOrder sortAnnotationsBy)
2813 this.sortAnnotationsBy = sortAnnotationsBy;
2816 public boolean isShowAutocalculatedAbove()
2818 return showAutocalculatedAbove;
2821 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2823 this.showAutocalculatedAbove = showAutocalculatedAbove;
2827 public boolean isScaleProteinAsCdna()
2829 return viewStyle.isScaleProteinAsCdna();
2833 public void setScaleProteinAsCdna(boolean b)
2835 viewStyle.setScaleProteinAsCdna(b);
2839 public boolean isProteinFontAsCdna()
2841 return viewStyle.isProteinFontAsCdna();
2845 public void setProteinFontAsCdna(boolean b)
2847 viewStyle.setProteinFontAsCdna(b);
2851 public void setShowComplementFeatures(boolean b)
2853 viewStyle.setShowComplementFeatures(b);
2857 public boolean isShowComplementFeatures()
2859 return viewStyle.isShowComplementFeatures();
2863 public void setShowComplementFeaturesOnTop(boolean b)
2865 viewStyle.setShowComplementFeaturesOnTop(b);
2869 public boolean isShowComplementFeaturesOnTop()
2871 return viewStyle.isShowComplementFeaturesOnTop();
2875 * @return true if view should scroll to show the highlighted region of a
2880 public final boolean isFollowHighlight()
2882 return followHighlight;
2886 public final void setFollowHighlight(boolean b)
2888 this.followHighlight = b;
2892 public ViewportRanges getRanges()
2898 * Helper method to populate the SearchResults with the location in the
2899 * complementary alignment to scroll to, in order to match this one.
2902 * the SearchResults to add to
2903 * @return the offset (below top of visible region) of the matched sequence
2905 protected int findComplementScrollTarget(SearchResultsI sr)
2907 final AlignViewportI complement = getCodingComplement();
2908 if (complement == null || !complement.isFollowHighlight())
2912 boolean iAmProtein = !getAlignment().isNucleotide();
2913 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2914 : complement.getAlignment();
2915 if (proteinAlignment == null)
2919 final List<AlignedCodonFrame> mappings = proteinAlignment
2923 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2924 * residue in the middle column of the visible region. Scroll the
2925 * complementary alignment to line up the corresponding residue.
2928 SequenceI sequence = null;
2931 * locate 'middle' column (true middle if an odd number visible, left of
2932 * middle if an even number visible)
2934 int middleColumn = ranges.getStartRes()
2935 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2936 final HiddenSequences hiddenSequences = getAlignment()
2937 .getHiddenSequences();
2940 * searching to the bottom of the alignment gives smoother scrolling across
2941 * all gapped visible regions
2943 int lastSeq = alignment.getHeight() - 1;
2944 List<AlignedCodonFrame> seqMappings = null;
2945 for (int seqNo = ranges
2946 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2948 sequence = getAlignment().getSequenceAt(seqNo);
2949 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2953 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2957 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2959 getCodingComplement().getAlignment().getSequences());
2960 if (!seqMappings.isEmpty())
2966 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2969 * No ungapped mapped sequence in middle column - do nothing
2973 MappingUtils.addSearchResults(sr, sequence,
2974 sequence.findPosition(middleColumn), seqMappings);
2979 * synthesize a column selection if none exists so it covers the given
2980 * selection group. if wholewidth is false, no column selection is made if the
2981 * selection group covers the whole alignment width.
2986 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2989 if (sg != null && (sgs = sg.getStartRes()) >= 0
2990 && sg.getStartRes() <= (sge = sg.getEndRes())
2991 && !this.hasSelectedColumns())
2993 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
3000 colSel = new ColumnSelection();
3002 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
3004 colSel.addElement(cspos);
3010 * hold status of current selection group - defined on alignment or not.
3012 private boolean selectionIsDefinedGroup = false;
3015 public boolean isSelectionDefinedGroup()
3017 if (selectionGroup == null)
3021 if (isSelectionGroupChanged(true))
3023 selectionIsDefinedGroup = false;
3024 List<SequenceGroup> gps = alignment.getGroups();
3025 if (gps == null || gps.size() == 0)
3027 selectionIsDefinedGroup = false;
3031 selectionIsDefinedGroup = gps.contains(selectionGroup);
3034 return selectionGroup.isDefined() || selectionIsDefinedGroup;
3038 * null, or currently highlighted results on this view
3040 private SearchResultsI searchResults = null;
3042 protected TreeModel currentTree = null;
3045 public boolean hasSearchResults()
3047 return searchResults != null;
3051 public void setSearchResults(SearchResultsI results)
3053 searchResults = results;
3057 public SearchResultsI getSearchResults()
3059 return searchResults;
3063 * get the consensus sequence as displayed under the PID consensus annotation
3066 * @return consensus sequence as a new sequence object
3068 public SequenceI getConsensusSeq()
3070 if (consensus == null)
3072 updateConsensus(null);
3074 if (consensus == null)
3078 StringBuffer seqs = new StringBuffer();
3079 for (int i = 0; i < consensus.annotations.length; i++)
3081 Annotation annotation = consensus.annotations[i];
3082 if (annotation != null)
3084 String description = annotation.description;
3085 if (description != null && description.startsWith("["))
3087 // consensus is a tie - just pick the first one
3088 seqs.append(description.charAt(1));
3092 seqs.append(annotation.displayCharacter);
3097 SequenceI sq = new Sequence("Consensus", seqs.toString());
3098 sq.setDescription("Percentage Identity Consensus "
3099 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3103 public boolean hasReferenceAnnotation()
3105 AlignmentAnnotation[] annots = this.alignment.getAlignmentAnnotation();
3106 for (AlignmentAnnotation annot : annots)
3108 if ("RF".equals(annot.label) || annot.label.contains("Reference"))
3117 public void setCurrentTree(TreeModel tree)
3123 public TreeModel getCurrentTree()
3129 public AlignmentExportData getAlignExportData(AlignExportSettingsI options)
3131 AlignmentI alignmentToExport = null;
3132 String[] omitHidden = null;
3133 alignmentToExport = null;
3135 if (hasHiddenColumns() && !options.isExportHiddenColumns())
3137 omitHidden = getViewAsString(false,
3138 options.isExportHiddenSequences());
3141 int[] alignmentStartEnd = new int[2];
3142 if (hasHiddenRows() && options.isExportHiddenSequences())
3144 alignmentToExport = getAlignment().getHiddenSequences()
3145 .getFullAlignment();
3149 alignmentToExport = getAlignment();
3151 alignmentStartEnd = getAlignment().getHiddenColumns()
3152 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
3153 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
3154 omitHidden, alignmentStartEnd);
3159 public boolean isNormaliseSequenceLogo()
3161 return normaliseSequenceLogo;
3164 public void setNormaliseSequenceLogo(boolean state)
3166 normaliseSequenceLogo = state;
3170 public boolean isNormaliseHMMSequenceLogo()
3172 return hmmNormaliseSequenceLogo;
3175 public void setNormaliseHMMSequenceLogo(boolean state)
3177 hmmNormaliseSequenceLogo = state;
3180 * flag set to indicate if structure views might be out of sync with sequences
3184 private boolean needToUpdateStructureViews = false;
3187 public boolean isUpdateStructures()
3189 return needToUpdateStructureViews;
3193 public void setUpdateStructures(boolean update)
3195 needToUpdateStructureViews = update;
3199 public boolean needToUpdateStructureViews()
3201 boolean update = needToUpdateStructureViews;
3202 needToUpdateStructureViews = false;
3207 public void addSequenceGroup(SequenceGroup sequenceGroup)
3209 alignment.addGroup(sequenceGroup);
3211 Color col = sequenceGroup.idColour;
3214 col = col.brighter();
3216 for (SequenceI sq : sequenceGroup.getSequences())
3218 setSequenceColour(sq, col);
3222 if (codingComplement != null)
3224 SequenceGroup mappedGroup = MappingUtils
3225 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3226 if (mappedGroup.getSequences().size() > 0)
3228 codingComplement.getAlignment().addGroup(mappedGroup);
3232 for (SequenceI seq : mappedGroup.getSequences())
3234 codingComplement.setSequenceColour(seq, col);
3238 // propagate the structure view update flag according to our own setting
3239 codingComplement.setUpdateStructures(needToUpdateStructureViews);
3244 * Filters out sequences with an eValue higher than the specified value. The
3245 * filtered sequences are hidden or deleted. Sequences with no eValues are also
3251 public void filterByEvalue(double eValue)
3253 for (SequenceI seq : alignment.getSequencesArray())
3255 if ((seq.getAnnotation("Search Scores") == null
3256 || seq.getAnnotation("Search Scores")[0].getEValue() > eValue)
3257 && seq.getHMM() == null)
3259 hideSequence(new SequenceI[] { seq });
3265 * Filters out sequences with an score lower than the specified value. The
3266 * filtered sequences are hidden or deleted.
3271 public void filterByScore(double score)
3273 for (SequenceI seq : alignment.getSequencesArray())
3275 if ((seq.getAnnotation("Search Scores") == null
3276 || seq.getAnnotation("Search Scores")[0]
3277 .getBitScore() < score)
3278 && seq.getHMM() == null)
3280 hideSequence(new SequenceI[] { seq });