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.AlignCalcManagerI2;
27 import jalview.api.AlignCalcWorkerI;
28 import jalview.api.AlignExportSettingsI;
29 import jalview.api.AlignViewportI;
30 import jalview.api.AlignmentViewPanel;
31 import jalview.api.FeaturesDisplayedI;
32 import jalview.api.ViewStyleI;
33 import jalview.commands.CommandI;
34 import jalview.datamodel.AlignedCodonFrame;
35 import jalview.datamodel.AlignmentAnnotation;
36 import jalview.datamodel.AlignmentExportData;
37 import jalview.datamodel.AlignmentI;
38 import jalview.datamodel.AlignmentView;
39 import jalview.datamodel.Annotation;
40 import jalview.datamodel.ColumnSelection;
41 import jalview.datamodel.HiddenColumns;
42 import jalview.datamodel.HiddenSequences;
43 import jalview.datamodel.ProfilesI;
44 import jalview.datamodel.SearchResultsI;
45 import jalview.datamodel.Sequence;
46 import jalview.datamodel.SequenceCollectionI;
47 import jalview.datamodel.SequenceGroup;
48 import jalview.datamodel.SequenceI;
49 import jalview.renderer.ResidueShader;
50 import jalview.renderer.ResidueShaderI;
51 import jalview.schemes.ColourSchemeI;
52 import jalview.structure.CommandListener;
53 import jalview.structure.StructureSelectionManager;
54 import jalview.structure.VamsasSource;
55 import jalview.util.Comparison;
56 import jalview.util.MapList;
57 import jalview.util.MappingUtils;
58 import jalview.util.MessageManager;
59 import jalview.viewmodel.styles.ViewStyle;
60 import jalview.workers.AlignCalcManager2;
61 import jalview.workers.ComplementConsensusThread;
62 import jalview.workers.ConsensusThread;
63 import jalview.workers.InformationThread;
64 import jalview.workers.StrucConsensusThread;
65 import jalview.ws2.WebServiceExecutor;
67 import java.awt.Color;
68 import java.beans.PropertyChangeSupport;
69 import java.util.ArrayDeque;
70 import java.util.ArrayList;
71 import java.util.BitSet;
72 import java.util.Deque;
73 import java.util.HashMap;
74 import java.util.Hashtable;
75 import java.util.Iterator;
76 import java.util.List;
80 * base class holding visualization and analysis attributes and common logic for
81 * an active alignment view displayed in the GUI
86 public abstract class AlignmentViewport
87 implements AlignViewportI, CommandListener, VamsasSource
89 public static final String PROPERTY_ALIGNMENT = "alignment";
90 public static final String PROPERTY_SEQUENCE = "sequence";
92 protected ViewportRanges ranges;
94 protected ViewStyleI viewStyle = new ViewStyle();
97 * A viewport that hosts the cDna view of this (protein), or vice versa (if
100 AlignViewportI codingComplement = null;
102 FeaturesDisplayedI featuresDisplayed = null;
104 protected Deque<CommandI> historyList = new ArrayDeque<>();
106 protected Deque<CommandI> redoList = new ArrayDeque<>();
109 * alignment displayed in the viewport. Please use get/setter
111 protected AlignmentI alignment;
114 * probably unused indicator that view is of a dataset rather than an
118 protected boolean ignoreBelowBackGroundFrequencyCalculation = false;
120 protected boolean infoLetterHeight = false;
122 protected AlignmentAnnotation occupancy;
125 * results of alignment consensus analysis for visible portion of view
127 protected ProfilesI consensusProfiles;
130 * HMM profile for the alignment
132 protected ProfilesI hmmProfiles;
134 public AlignmentViewport(AlignmentI al)
137 ranges = new ViewportRanges(al);
142 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
145 public void setFontName(String name)
147 viewStyle.setFontName(name);
152 * @see jalview.api.ViewStyleI#setFontStyle(int)
155 public void setFontStyle(int style)
157 viewStyle.setFontStyle(style);
162 * @see jalview.api.ViewStyleI#setFontSize(int)
165 public void setFontSize(int size)
167 viewStyle.setFontSize(size);
172 * @see jalview.api.ViewStyleI#getFontStyle()
175 public int getFontStyle()
177 return viewStyle.getFontStyle();
182 * @see jalview.api.ViewStyleI#getFontName()
185 public String getFontName()
187 return viewStyle.getFontName();
192 * @see jalview.api.ViewStyleI#getFontSize()
195 public int getFontSize()
197 return viewStyle.getFontSize();
201 * @param upperCasebold
202 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
205 public void setUpperCasebold(boolean upperCasebold)
207 viewStyle.setUpperCasebold(upperCasebold);
212 * @see jalview.api.ViewStyleI#isUpperCasebold()
215 public boolean isUpperCasebold()
217 return viewStyle.isUpperCasebold();
222 * @see jalview.api.ViewStyleI#isSeqNameItalics()
225 public boolean isSeqNameItalics()
227 return viewStyle.isSeqNameItalics();
231 * @param colourByReferenceSeq
232 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
235 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
237 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
242 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
245 public void setColourAppliesToAllGroups(boolean b)
247 viewStyle.setColourAppliesToAllGroups(b);
252 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
255 public boolean getColourAppliesToAllGroups()
257 return viewStyle.getColourAppliesToAllGroups();
262 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
265 public boolean getAbovePIDThreshold()
267 return viewStyle.getAbovePIDThreshold();
272 * @see jalview.api.ViewStyleI#setIncrement(int)
275 public void setIncrement(int inc)
277 viewStyle.setIncrement(inc);
282 * @see jalview.api.ViewStyleI#getIncrement()
285 public int getIncrement()
287 return viewStyle.getIncrement();
292 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
295 public void setConservationSelected(boolean b)
297 viewStyle.setConservationSelected(b);
302 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
305 public void setShowHiddenMarkers(boolean show)
307 viewStyle.setShowHiddenMarkers(show);
312 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
315 public boolean getShowHiddenMarkers()
317 return viewStyle.getShowHiddenMarkers();
322 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
325 public void setScaleRightWrapped(boolean b)
327 viewStyle.setScaleRightWrapped(b);
332 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
335 public void setScaleLeftWrapped(boolean b)
337 viewStyle.setScaleLeftWrapped(b);
342 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
345 public void setScaleAboveWrapped(boolean b)
347 viewStyle.setScaleAboveWrapped(b);
352 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
355 public boolean getScaleLeftWrapped()
357 return viewStyle.getScaleLeftWrapped();
362 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
365 public boolean getScaleAboveWrapped()
367 return viewStyle.getScaleAboveWrapped();
372 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
375 public boolean getScaleRightWrapped()
377 return viewStyle.getScaleRightWrapped();
382 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
385 public void setAbovePIDThreshold(boolean b)
387 viewStyle.setAbovePIDThreshold(b);
392 * @see jalview.api.ViewStyleI#setThreshold(int)
395 public void setThreshold(int thresh)
397 viewStyle.setThreshold(thresh);
402 * @see jalview.api.ViewStyleI#getThreshold()
405 public int getThreshold()
407 return viewStyle.getThreshold();
412 * @see jalview.api.ViewStyleI#getShowJVSuffix()
415 public boolean getShowJVSuffix()
417 return viewStyle.getShowJVSuffix();
422 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
425 public void setShowJVSuffix(boolean b)
427 viewStyle.setShowJVSuffix(b);
432 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
435 public void setWrapAlignment(boolean state)
437 viewStyle.setWrapAlignment(state);
438 ranges.setWrappedMode(state);
443 * @see jalview.api.ViewStyleI#setShowText(boolean)
446 public void setShowText(boolean state)
448 viewStyle.setShowText(state);
453 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
456 public void setRenderGaps(boolean state)
458 viewStyle.setRenderGaps(state);
463 * @see jalview.api.ViewStyleI#getColourText()
466 public boolean getColourText()
468 return viewStyle.getColourText();
473 * @see jalview.api.ViewStyleI#setColourText(boolean)
476 public void setColourText(boolean state)
478 viewStyle.setColourText(state);
483 * @see jalview.api.ViewStyleI#getWrapAlignment()
486 public boolean getWrapAlignment()
488 return viewStyle.getWrapAlignment();
493 * @see jalview.api.ViewStyleI#getShowText()
496 public boolean getShowText()
498 return viewStyle.getShowText();
503 * @see jalview.api.ViewStyleI#getWrappedWidth()
506 public int getWrappedWidth()
508 return viewStyle.getWrappedWidth();
513 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
516 public void setWrappedWidth(int w)
518 viewStyle.setWrappedWidth(w);
523 * @see jalview.api.ViewStyleI#getCharHeight()
526 public int getCharHeight()
528 return viewStyle.getCharHeight();
533 * @see jalview.api.ViewStyleI#setCharHeight(int)
536 public void setCharHeight(int h)
538 viewStyle.setCharHeight(h);
543 * @see jalview.api.ViewStyleI#getCharWidth()
546 public int getCharWidth()
548 return viewStyle.getCharWidth();
553 * @see jalview.api.ViewStyleI#setCharWidth(int)
556 public void setCharWidth(int w)
558 viewStyle.setCharWidth(w);
563 * @see jalview.api.ViewStyleI#getShowBoxes()
566 public boolean getShowBoxes()
568 return viewStyle.getShowBoxes();
573 * @see jalview.api.ViewStyleI#getShowUnconserved()
576 public boolean getShowUnconserved()
578 return viewStyle.getShowUnconserved();
582 * @param showunconserved
583 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
586 public void setShowUnconserved(boolean showunconserved)
588 viewStyle.setShowUnconserved(showunconserved);
593 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
596 public void setSeqNameItalics(boolean default1)
598 viewStyle.setSeqNameItalics(default1);
602 public AlignmentI getAlignment()
608 public char getGapCharacter()
610 return alignment.getGapCharacter();
613 protected String sequenceSetID;
616 * probably unused indicator that view is of a dataset rather than an
619 protected boolean isDataset = false;
621 public void setDataset(boolean b)
626 public boolean isDataset()
631 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
633 protected ColumnSelection colSel = new ColumnSelection();
635 protected boolean autoCalculateConsensusAndConservation = true;
637 public boolean getAutoCalculateConsensusAndConservation()
639 return autoCalculateConsensusAndConservation;
642 public void setAutoCalculateConsensusAndConservation(boolean b)
644 autoCalculateConsensusAndConservation = b;
647 protected boolean autoCalculateStrucConsensus = true;
649 public boolean getAutoCalculateStrucConsensus()
651 return autoCalculateStrucConsensus;
654 public void setAutoCalculateStrucConsensus(boolean b)
656 autoCalculateStrucConsensus = b;
660 protected boolean ignoreGapsInConsensusCalculation = false;
662 protected ResidueShaderI residueShading = new ResidueShader();
665 public void setGlobalColourScheme(ColourSchemeI cs)
667 // TODO: logic refactored from AlignFrame changeColour -
668 // TODO: autorecalc stuff should be changed to rely on the worker system
669 // check to see if we should implement a changeColour(cs) method rather than
670 // put the logic in here
671 // - means that caller decides if they want to just modify state and defer
672 // calculation till later or to do all calculations in thread.
676 * only instantiate alignment colouring once, thereafter update it;
677 * this means that any conservation or PID threshold settings
678 * persist when the alignment colour scheme is changed
680 if (residueShading == null)
682 residueShading = new ResidueShader(viewStyle);
684 residueShading.setColourScheme(cs);
686 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
687 // ...problem: groups need these, but do not currently have a ViewStyle
691 if (getConservationSelected())
693 residueShading.setConservation(hconservation);
696 * reset conservation flag in case just set to false if
697 * Conservation was null (calculation still in progress)
699 residueShading.setConservationApplied(getConservationSelected());
700 residueShading.alignmentChanged(alignment, hiddenRepSequences);
704 * if 'apply colour to all groups' is selected... do so
705 * (but don't transfer any colour threshold settings to groups)
707 if (getColourAppliesToAllGroups())
709 for (SequenceGroup sg : getAlignment().getGroups())
712 * retain any colour thresholds per group while
713 * changing choice of colour scheme (JAL-2386)
716 cs == null ? null : cs.getInstance(this, sg));
719 sg.getGroupColourScheme().alignmentChanged(sg,
727 public ColourSchemeI getGlobalColourScheme()
729 return residueShading == null ? null : residueShading.getColourScheme();
733 public ResidueShaderI getResidueShading()
735 return residueShading;
738 protected AlignmentAnnotation consensus;
740 protected AlignmentAnnotation complementConsensus;
742 protected AlignmentAnnotation gapcounts;
744 protected AlignmentAnnotation strucConsensus;
746 protected AlignmentAnnotation conservation;
748 protected AlignmentAnnotation quality;
750 protected AlignmentAnnotation[] groupConsensus;
752 protected AlignmentAnnotation[] groupConservation;
755 * results of alignment consensus analysis for visible portion of view
757 protected ProfilesI hconsensus = null;
760 * results of cDNA complement consensus visible portion of view
762 protected Hashtable<String, Object>[] hcomplementConsensus = null;
765 * results of secondary structure base pair consensus for visible portion of
768 protected Hashtable<String, Object>[] hStrucConsensus = null;
770 protected Conservation hconservation = null;
773 public void setConservation(Conservation cons)
775 hconservation = cons;
779 * percentage gaps allowed in a column before all amino acid properties should
780 * be considered unconserved
782 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
785 public int getConsPercGaps()
791 public void setSequenceConsensusHash(ProfilesI hconsensus)
793 this.hconsensus = hconsensus;
797 public void setComplementConsensusHash(
798 Hashtable<String, Object>[] hconsensus)
800 this.hcomplementConsensus = hconsensus;
804 public ProfilesI getSequenceConsensusHash()
810 public void setHmmProfiles(ProfilesI info)
816 public ProfilesI getHmmProfiles()
822 public Hashtable<String, Object>[] getComplementConsensusHash()
824 return hcomplementConsensus;
828 public Hashtable<String, Object>[] getRnaStructureConsensusHash()
830 return hStrucConsensus;
834 public void setRnaStructureConsensusHash(
835 Hashtable<String, Object>[] hStrucConsensus)
837 this.hStrucConsensus = hStrucConsensus;
842 public AlignmentAnnotation getAlignmentQualityAnnot()
848 public AlignmentAnnotation getAlignmentConservationAnnotation()
854 public AlignmentAnnotation getAlignmentConsensusAnnotation()
860 public AlignmentAnnotation getAlignmentGapAnnotation()
866 public AlignmentAnnotation getComplementConsensusAnnotation()
868 return complementConsensus;
872 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
874 return strucConsensus;
877 protected AlignCalcManagerI2 calculator = new AlignCalcManager2();
880 * trigger update of conservation annotation
882 public void updateConservation(final AlignmentViewPanel ap)
884 // see note in mantis : issue number 8585
885 if (alignment.isNucleotide()
886 || (conservation == null && quality == null)
887 || !autoCalculateConsensusAndConservation)
891 if (calculator.getWorkersOfClass(
892 jalview.workers.ConservationThread.class).isEmpty())
894 calculator.registerWorker(
895 new jalview.workers.ConservationThread(this, ap));
900 * trigger update of consensus annotation
902 public void updateConsensus(final AlignmentViewPanel ap)
904 // see note in mantis : issue number 8585
905 if (consensus == null || !autoCalculateConsensusAndConservation)
909 if (calculator.getWorkersOfClass(ConsensusThread.class).isEmpty())
911 calculator.registerWorker(new ConsensusThread(this, ap));
915 * A separate thread to compute cDNA consensus for a protein alignment
916 * which has mapping to cDNA
918 final AlignmentI al = this.getAlignment();
919 if (!al.isNucleotide() && al.getCodonFrames() != null
920 && !al.getCodonFrames().isEmpty())
923 * fudge - check first for protein-to-nucleotide mappings
924 * (we don't want to do this for protein-to-protein)
926 boolean doConsensus = false;
927 for (AlignedCodonFrame mapping : al.getCodonFrames())
929 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
930 MapList[] mapLists = mapping.getdnaToProt();
931 // mapLists can be empty if project load has not finished resolving seqs
932 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
940 if (calculator.getWorkersOfClass(ComplementConsensusThread.class).isEmpty())
942 calculator.registerWorker(new ComplementConsensusThread(this, ap));
949 public void initInformationWorker(final AlignmentViewPanel ap)
951 if (calculator.getWorkersOfClass(InformationThread.class).isEmpty())
953 calculator.registerWorker(new InformationThread(this, ap));
957 // --------START Structure Conservation
958 public void updateStrucConsensus(final AlignmentViewPanel ap)
960 if (autoCalculateStrucConsensus && strucConsensus == null
961 && alignment.isNucleotide() && alignment.hasRNAStructure())
963 // secondary structure has been added - so init the consensus line
967 // see note in mantis : issue number 8585
968 if (strucConsensus == null || !autoCalculateStrucConsensus)
972 if (calculator.getWorkersOfClass(StrucConsensusThread.class).isEmpty())
974 calculator.registerWorker(new StrucConsensusThread(this, ap));
978 public boolean isCalcInProgress()
980 return calculator.isWorking();
984 public boolean isCalculationInProgress(
985 AlignmentAnnotation alignmentAnnotation)
987 if (!alignmentAnnotation.autoCalculated)
991 if (calculator.isWorkingWithAnnotation(alignmentAnnotation))
993 // System.err.println("grey out ("+alignmentAnnotation.label+")");
999 private WebServiceExecutor wsExecutor = new WebServiceExecutor();
1001 public WebServiceExecutor getWSExecutor()
1006 public void setAlignment(AlignmentI align)
1008 this.alignment = align;
1012 * Clean up references when this viewport is closed
1015 public void dispose()
1018 * defensively null out references to large objects in case
1019 * this object is not garbage collected (as if!)
1022 complementConsensus = null;
1023 strucConsensus = null;
1024 conservation = null;
1026 consensusProfiles = null;
1027 groupConsensus = null;
1028 groupConservation = null;
1030 hconservation = null;
1031 hcomplementConsensus = null;
1033 calculator.shutdown();
1035 wsExecutor.shutdown();
1037 residueShading = null; // may hold a reference to Consensus
1038 changeSupport = null;
1041 selectionGroup = null;
1046 public boolean isClosed()
1048 // TODO: check that this isClosed is only true after panel is closed, not
1049 // before it is fully constructed.
1050 return alignment == null;
1054 public AlignCalcManagerI2 getCalcManager()
1060 * should conservation rows be shown for groups
1062 protected boolean showGroupConservation = false;
1065 * should consensus rows be shown for groups
1067 protected boolean showGroupConsensus = false;
1070 * should consensus profile be rendered by default
1072 protected boolean showSequenceLogo = false;
1075 * should consensus profile be rendered normalised to row height
1077 protected boolean normaliseSequenceLogo = false;
1080 * should consensus histograms be rendered by default
1082 protected boolean showConsensusHistogram = true;
1085 * should hmm profile be rendered by default
1087 protected boolean hmmShowSequenceLogo = false;
1090 * should hmm profile be rendered normalised to row height
1092 protected boolean hmmNormaliseSequenceLogo = false;
1095 * should information histograms be rendered by default
1097 protected boolean hmmShowHistogram = true;
1100 * @return the showConsensusProfile
1103 public boolean isShowSequenceLogo()
1105 return showSequenceLogo;
1109 * @return the showInformationProfile
1112 public boolean isShowHMMSequenceLogo()
1114 return hmmShowSequenceLogo;
1118 * @param showSequenceLogo
1121 public void setShowSequenceLogo(boolean showSequenceLogo)
1123 if (showSequenceLogo != this.showSequenceLogo)
1125 // TODO: decouple settings setting from calculation when refactoring
1126 // annotation update method from alignframe to viewport
1127 this.showSequenceLogo = showSequenceLogo;
1128 for (AlignCalcWorkerI worker : calculator.getWorkers())
1130 if (worker.getClass().equals(ConsensusThread.class) ||
1131 worker.getClass().equals(ComplementConsensusThread.class) ||
1132 worker.getClass().equals(StrucConsensusThread.class))
1134 worker.updateAnnotation();
1138 this.showSequenceLogo = showSequenceLogo;
1141 public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo)
1143 if (showHMMSequenceLogo != this.hmmShowSequenceLogo)
1145 this.hmmShowSequenceLogo = showHMMSequenceLogo;
1146 // TODO: updateAnnotation if description (tooltip) will show
1147 // profile in place of information content?
1148 // calculator.updateAnnotationFor(InformationThread.class);
1150 this.hmmShowSequenceLogo = showHMMSequenceLogo;
1154 * @param showConsensusHistogram
1155 * the showConsensusHistogram to set
1157 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1159 this.showConsensusHistogram = showConsensusHistogram;
1163 * @param showInformationHistogram
1165 public void setShowInformationHistogram(boolean showInformationHistogram)
1167 this.hmmShowHistogram = showInformationHistogram;
1171 * @return the showGroupConservation
1173 public boolean isShowGroupConservation()
1175 return showGroupConservation;
1179 * @param showGroupConservation
1180 * the showGroupConservation to set
1182 public void setShowGroupConservation(boolean showGroupConservation)
1184 this.showGroupConservation = showGroupConservation;
1188 * @return the showGroupConsensus
1190 public boolean isShowGroupConsensus()
1192 return showGroupConsensus;
1196 * @param showGroupConsensus
1197 * the showGroupConsensus to set
1199 public void setShowGroupConsensus(boolean showGroupConsensus)
1201 this.showGroupConsensus = showGroupConsensus;
1206 * @return flag to indicate if the consensus histogram should be rendered by
1210 public boolean isShowConsensusHistogram()
1212 return this.showConsensusHistogram;
1217 * @return flag to indicate if the information content histogram should be
1218 * rendered by default
1221 public boolean isShowInformationHistogram()
1223 return this.hmmShowHistogram;
1227 * when set, updateAlignment will always ensure sequences are of equal length
1229 private boolean padGaps = false;
1232 * when set, alignment should be reordered according to a newly opened tree
1234 public boolean sortByTree = false;
1239 * @return null or the currently selected sequence region
1242 public SequenceGroup getSelectionGroup()
1244 return selectionGroup;
1248 * Set the selection group for this window. Also sets the current alignment as
1249 * the context for the group, if it does not already have one.
1252 * - group holding references to sequences in this alignment view
1256 public void setSelectionGroup(SequenceGroup sg)
1258 selectionGroup = sg;
1259 if (sg != null && sg.getContext() == null)
1261 sg.setContext(alignment);
1265 public void setHiddenColumns(HiddenColumns hidden)
1267 this.alignment.setHiddenColumns(hidden);
1271 public ColumnSelection getColumnSelection()
1277 public void setColumnSelection(ColumnSelection colSel)
1279 this.colSel = colSel;
1282 updateHiddenColumns();
1284 isColSelChanged(true);
1292 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1294 return hiddenRepSequences;
1298 public void setHiddenRepSequences(
1299 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1301 this.hiddenRepSequences = hiddenRepSequences;
1305 public boolean hasSelectedColumns()
1307 ColumnSelection columnSelection = getColumnSelection();
1308 return columnSelection != null && columnSelection.hasSelectedColumns();
1312 public boolean hasHiddenColumns()
1314 return alignment.getHiddenColumns() != null
1315 && alignment.getHiddenColumns().hasHiddenColumns();
1318 public void updateHiddenColumns()
1320 // this method doesn't really do anything now. But - it could, since a
1321 // column Selection could be in the process of modification
1322 // hasHiddenColumns = colSel.hasHiddenColumns();
1326 public boolean hasHiddenRows()
1328 return alignment.getHiddenSequences().getSize() > 0;
1331 protected SequenceGroup selectionGroup;
1333 public void setSequenceSetId(String newid)
1335 if (sequenceSetID != null)
1338 "Warning - overwriting a sequenceSetId for a viewport!");
1340 sequenceSetID = new String(newid);
1344 public String getSequenceSetId()
1346 if (sequenceSetID == null)
1348 sequenceSetID = alignment.hashCode() + "";
1351 return sequenceSetID;
1355 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1358 protected String viewId = null;
1361 public String getViewId()
1365 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1370 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1372 ignoreGapsInConsensusCalculation = b;
1375 updateConsensus(ap);
1376 if (residueShading != null)
1378 residueShading.setThreshold(residueShading.getThreshold(),
1379 ignoreGapsInConsensusCalculation);
1384 public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap)
1386 ignoreBelowBackGroundFrequencyCalculation = b;
1389 public void setInfoLetterHeight(boolean b, AlignmentViewPanel ap)
1391 infoLetterHeight = b;
1394 private long sgrouphash = -1, colselhash = -1;
1397 * checks current SelectionGroup against record of last hash value, and
1401 * update the record of last hash value
1403 * @return true if SelectionGroup changed since last call (when b is true)
1405 public boolean isSelectionGroupChanged(boolean b)
1407 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1408 : selectionGroup.hashCode();
1409 if (hc != -1 && hc != sgrouphash)
1421 * checks current colsel against record of last hash value, and optionally
1425 * update the record of last hash value
1426 * @return true if colsel changed since last call (when b is true)
1428 public boolean isColSelChanged(boolean updateHash)
1430 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1431 if (hc != -1 && hc != colselhash)
1444 public boolean isIgnoreGapsConsensus()
1446 return ignoreGapsInConsensusCalculation;
1450 public boolean isIgnoreBelowBackground()
1452 return ignoreBelowBackGroundFrequencyCalculation;
1456 public boolean isInfoLetterHeight()
1458 return infoLetterHeight;
1461 // property change stuff
1462 // JBPNote Prolly only need this in the applet version.
1463 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1466 protected boolean showConservation = true;
1468 protected boolean showQuality = true;
1470 protected boolean showConsensus = true;
1472 protected boolean showOccupancy = true;
1474 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1476 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1478 protected boolean showAutocalculatedAbove;
1481 * when set, view will scroll to show the highlighted position
1483 private boolean followHighlight = true;
1486 * Property change listener for changes in alignment
1491 public void addPropertyChangeListener(
1492 java.beans.PropertyChangeListener listener)
1494 changeSupport.addPropertyChangeListener(listener);
1503 public void removePropertyChangeListener(
1504 java.beans.PropertyChangeListener listener)
1506 if (changeSupport != null)
1508 changeSupport.removePropertyChangeListener(listener);
1512 // common hide/show column stuff
1514 public void hideSelectedColumns()
1516 if (colSel.isEmpty())
1521 colSel.hideSelectedColumns(alignment);
1522 setSelectionGroup(null);
1523 isColSelChanged(true);
1526 public void hideColumns(int start, int end)
1530 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1534 alignment.getHiddenColumns().hideColumns(start, end);
1536 isColSelChanged(true);
1539 public void showColumn(int col)
1541 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1542 isColSelChanged(true);
1545 public void showAllHiddenColumns()
1547 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1548 isColSelChanged(true);
1551 // common hide/show seq stuff
1552 public void showAllHiddenSeqs()
1554 int startSeq = ranges.getStartSeq();
1555 int endSeq = ranges.getEndSeq();
1557 if (alignment.getHiddenSequences().getSize() > 0)
1559 if (selectionGroup == null)
1561 selectionGroup = new SequenceGroup();
1562 selectionGroup.setEndRes(alignment.getWidth() - 1);
1564 List<SequenceI> tmp = alignment.getHiddenSequences()
1565 .showAll(hiddenRepSequences);
1566 for (SequenceI seq : tmp)
1568 selectionGroup.addSequence(seq, false);
1569 setSequenceAnnotationsVisible(seq, true);
1572 hiddenRepSequences = null;
1574 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1576 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1584 public void showSequence(int index)
1586 int startSeq = ranges.getStartSeq();
1587 int endSeq = ranges.getEndSeq();
1589 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1590 hiddenRepSequences);
1593 if (selectionGroup == null)
1595 selectionGroup = new SequenceGroup();
1596 selectionGroup.setEndRes(alignment.getWidth() - 1);
1599 for (SequenceI seq : tmp)
1601 selectionGroup.addSequence(seq, false);
1602 setSequenceAnnotationsVisible(seq, true);
1605 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1611 public void hideAllSelectedSeqs()
1613 if (selectionGroup == null || selectionGroup.getSize() < 1)
1618 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1622 setSelectionGroup(null);
1625 public void hideSequence(SequenceI[] seq)
1628 * cache offset to first visible sequence
1630 int startSeq = ranges.getStartSeq();
1634 for (int i = 0; i < seq.length; i++)
1636 alignment.getHiddenSequences().hideSequence(seq[i]);
1637 setSequenceAnnotationsVisible(seq[i], false);
1639 ranges.setStartSeq(startSeq);
1645 * Hides the specified sequence, or the sequences it represents
1648 * the sequence to hide, or keep as representative
1649 * @param representGroup
1650 * if true, hide the current selection group except for the
1651 * representative sequence
1653 public void hideSequences(SequenceI sequence, boolean representGroup)
1655 if (selectionGroup == null || selectionGroup.getSize() < 1)
1657 hideSequence(new SequenceI[] { sequence });
1663 hideRepSequences(sequence, selectionGroup);
1664 setSelectionGroup(null);
1668 int gsize = selectionGroup.getSize();
1669 SequenceI[] hseqs = selectionGroup.getSequences()
1670 .toArray(new SequenceI[gsize]);
1672 hideSequence(hseqs);
1673 setSelectionGroup(null);
1678 * Set visibility for any annotations for the given sequence.
1682 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1685 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1688 for (AlignmentAnnotation ann : anns)
1690 if (ann.sequenceRef == sequenceI)
1692 ann.visible = visible;
1698 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1700 int sSize = sg.getSize();
1706 if (hiddenRepSequences == null)
1708 hiddenRepSequences = new Hashtable<>();
1711 hiddenRepSequences.put(repSequence, sg);
1713 // Hide all sequences except the repSequence
1714 SequenceI[] seqs = new SequenceI[sSize - 1];
1716 for (int i = 0; i < sSize; i++)
1718 if (sg.getSequenceAt(i) != repSequence)
1720 if (index == sSize - 1)
1725 seqs[index++] = sg.getSequenceAt(i);
1728 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1729 sg.setHidereps(true); // note: not done in 2.7applet
1736 * @return null or the current reference sequence
1738 public SequenceI getReferenceSeq()
1740 return alignment.getSeqrep();
1745 * @return true iff seq is the reference for the alignment
1747 public boolean isReferenceSeq(SequenceI seq)
1749 return alignment.getSeqrep() == seq;
1755 * @return true if there are sequences represented by this sequence that are
1758 public boolean isHiddenRepSequence(SequenceI seq)
1760 return (hiddenRepSequences != null
1761 && hiddenRepSequences.containsKey(seq));
1767 * @return null or a sequence group containing the sequences that seq
1770 public SequenceGroup getRepresentedSequences(SequenceI seq)
1772 return (SequenceGroup) (hiddenRepSequences == null ? null
1773 : hiddenRepSequences.get(seq));
1777 public int adjustForHiddenSeqs(int alignmentIndex)
1779 return alignment.getHiddenSequences()
1780 .adjustForHiddenSeqs(alignmentIndex);
1784 public void invertColumnSelection()
1786 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1787 isColSelChanged(true);
1791 public SequenceI[] getSelectionAsNewSequence()
1793 SequenceI[] sequences;
1794 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1795 // this was the only caller in the applet for this method
1796 // JBPNote: in applet, this method returned references to the alignment
1797 // sequences, and it did not honour the presence/absence of annotation
1798 // attached to the alignment (probably!)
1799 if (selectionGroup == null || selectionGroup.getSize() == 0)
1801 sequences = alignment.getSequencesArray();
1802 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1803 for (int i = 0; i < sequences.length; i++)
1805 // construct new sequence with subset of visible annotation
1806 sequences[i] = new Sequence(sequences[i], annots);
1811 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1818 public SequenceI[] getSequenceSelection()
1820 SequenceI[] sequences = null;
1821 if (selectionGroup != null)
1823 sequences = selectionGroup.getSequencesInOrder(alignment);
1825 if (sequences == null)
1827 sequences = alignment.getSequencesArray();
1833 public jalview.datamodel.AlignmentView getAlignmentView(
1834 boolean selectedOnly)
1836 return getAlignmentView(selectedOnly, false);
1840 public jalview.datamodel.AlignmentView getAlignmentView(
1841 boolean selectedOnly, boolean markGroups)
1843 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1845 alignment.getHiddenColumns() != null
1846 && alignment.getHiddenColumns().hasHiddenColumns(),
1847 selectedOnly, markGroups);
1851 public String[] getViewAsString(boolean selectedRegionOnly)
1853 return getViewAsString(selectedRegionOnly, true);
1857 public String[] getViewAsString(boolean selectedRegionOnly,
1858 boolean exportHiddenSeqs)
1860 String[] selection = null;
1861 SequenceI[] seqs = null;
1863 int start = 0, end = 0;
1864 if (selectedRegionOnly && selectionGroup != null)
1866 iSize = selectionGroup.getSize();
1867 seqs = selectionGroup.getSequencesInOrder(alignment);
1868 start = selectionGroup.getStartRes();
1869 end = selectionGroup.getEndRes() + 1;
1873 if (hasHiddenRows() && exportHiddenSeqs)
1875 AlignmentI fullAlignment = alignment.getHiddenSequences()
1876 .getFullAlignment();
1877 iSize = fullAlignment.getHeight();
1878 seqs = fullAlignment.getSequencesArray();
1879 end = fullAlignment.getWidth();
1883 iSize = alignment.getHeight();
1884 seqs = alignment.getSequencesArray();
1885 end = alignment.getWidth();
1889 selection = new String[iSize];
1890 if (alignment.getHiddenColumns() != null
1891 && alignment.getHiddenColumns().hasHiddenColumns())
1893 for (i = 0; i < iSize; i++)
1895 Iterator<int[]> blocks = alignment.getHiddenColumns()
1896 .getVisContigsIterator(start, end + 1, false);
1897 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1902 for (i = 0; i < iSize; i++)
1904 selection[i] = seqs[i].getSequenceAsString(start, end);
1912 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1914 ArrayList<int[]> regions = new ArrayList<>();
1920 HiddenColumns hidden = alignment.getHiddenColumns();
1921 if (hidden != null && hidden.hasHiddenColumns())
1925 start = hidden.visibleToAbsoluteColumn(start);
1928 end = hidden.getNextHiddenBoundary(false, start);
1939 regions.add(new int[] { start, end });
1941 if (hidden != null && hidden.hasHiddenColumns())
1943 start = hidden.visibleToAbsoluteColumn(end);
1944 start = hidden.getNextHiddenBoundary(true, start) + 1;
1946 } while (end < max);
1948 // int[][] startEnd = new int[regions.size()][2];
1954 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1955 boolean selectedOnly)
1957 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1958 AlignmentAnnotation[] aa;
1959 if ((aa = alignment.getAlignmentAnnotation()) != null)
1961 for (AlignmentAnnotation annot : aa)
1963 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1964 if (selectedOnly && selectionGroup != null)
1966 clone.makeVisibleAnnotation(
1967 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1968 alignment.getHiddenColumns());
1972 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1981 public boolean isPadGaps()
1987 public void setPadGaps(boolean padGaps)
1989 this.padGaps = padGaps;
1993 * apply any post-edit constraints and trigger any calculations needed after
1994 * an edit has been performed on the alignment
1999 public void alignmentChanged(AlignmentViewPanel ap)
2003 alignment.padGaps();
2005 if (autoCalculateConsensusAndConservation)
2007 updateConsensus(ap);
2009 if (hconsensus != null && autoCalculateConsensusAndConservation)
2011 updateConservation(ap);
2013 if (autoCalculateStrucConsensus)
2015 updateStrucConsensus(ap);
2018 // Reset endRes of groups if beyond alignment width
2019 int alWidth = alignment.getWidth();
2020 List<SequenceGroup> groups = alignment.getGroups();
2023 for (SequenceGroup sg : groups)
2025 if (sg.getEndRes() > alWidth)
2027 sg.setEndRes(alWidth - 1);
2032 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
2034 selectionGroup.setEndRes(alWidth - 1);
2037 updateAllColourSchemes();
2038 calculator.restartWorkers();
2042 * reset scope and do calculations for all applied colourschemes on alignment
2044 void updateAllColourSchemes()
2046 ResidueShaderI rs = residueShading;
2049 rs.alignmentChanged(alignment, hiddenRepSequences);
2051 rs.setConsensus(hconsensus);
2052 if (rs.conservationApplied())
2054 rs.setConservation(Conservation.calculateConservation("All",
2055 alignment.getSequences(), 0, alignment.getWidth(), false,
2056 getConsPercGaps(), false));
2060 for (SequenceGroup sg : alignment.getGroups())
2064 sg.cs.alignmentChanged(sg, hiddenRepSequences);
2066 sg.recalcConservation();
2070 protected void initAutoAnnotation()
2072 // TODO: add menu option action that nulls or creates consensus object
2073 // depending on if the user wants to see the annotation or not in a
2074 // specific alignment
2076 if (hconsensus == null && !isDataset)
2078 if (!alignment.isNucleotide())
2087 consensus = new AlignmentAnnotation("Consensus",
2088 MessageManager.getString("label.consensus_descr"),
2089 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2090 initConsensus(consensus);
2094 initComplementConsensus();
2099 * If this is a protein alignment and there are mappings to cDNA, adds the
2100 * cDNA consensus annotation and returns true, else returns false.
2102 public boolean initComplementConsensus()
2104 if (!alignment.isNucleotide())
2106 final List<AlignedCodonFrame> codonMappings = alignment
2108 if (codonMappings != null && !codonMappings.isEmpty())
2110 boolean doConsensus = false;
2111 for (AlignedCodonFrame mapping : codonMappings)
2113 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2114 MapList[] mapLists = mapping.getdnaToProt();
2115 // mapLists can be empty if project load has not finished resolving
2117 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2125 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2127 .getString("label.complement_consensus_descr"),
2128 new Annotation[1], 0f, 100f,
2129 AlignmentAnnotation.BAR_GRAPH);
2130 initConsensus(complementConsensus);
2138 private void initConsensus(AlignmentAnnotation aa)
2141 aa.autoCalculated = true;
2145 alignment.addAnnotation(aa);
2149 // these should be extracted from the view model - style and settings for
2150 // derived annotation
2151 private void initGapCounts()
2155 gapcounts = new AlignmentAnnotation("Occupancy",
2156 MessageManager.getString("label.occupancy_descr"),
2157 new Annotation[1], 0f, alignment.getHeight(),
2158 AlignmentAnnotation.BAR_GRAPH);
2159 gapcounts.hasText = true;
2160 gapcounts.autoCalculated = true;
2161 gapcounts.scaleColLabel = true;
2162 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2164 alignment.addAnnotation(gapcounts);
2168 private void initConservation()
2170 if (showConservation)
2172 if (conservation == null)
2174 conservation = new AlignmentAnnotation("Conservation",
2175 MessageManager.formatMessage("label.conservation_descr",
2177 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2178 conservation.hasText = true;
2179 conservation.autoCalculated = true;
2180 alignment.addAnnotation(conservation);
2185 private void initQuality()
2189 if (quality == null)
2191 quality = new AlignmentAnnotation("Quality",
2192 MessageManager.getString("label.quality_descr"),
2193 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2194 quality.hasText = true;
2195 quality.autoCalculated = true;
2196 alignment.addAnnotation(quality);
2201 private void initRNAStructure()
2203 if (alignment.hasRNAStructure() && strucConsensus == null)
2205 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2206 MessageManager.getString("label.strucconsensus_descr"),
2207 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2208 strucConsensus.hasText = true;
2209 strucConsensus.autoCalculated = true;
2213 alignment.addAnnotation(strucConsensus);
2221 * @see jalview.api.AlignViewportI#calcPanelHeight()
2224 public int calcPanelHeight()
2226 // setHeight of panels
2227 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2229 int charHeight = getCharHeight();
2232 BitSet graphgrp = new BitSet();
2233 for (AlignmentAnnotation aa : anns)
2237 System.err.println("Null annotation row: ignoring.");
2244 if (aa.graphGroup > -1)
2246 if (graphgrp.get(aa.graphGroup))
2252 graphgrp.set(aa.graphGroup);
2259 aa.height += charHeight;
2269 aa.height += aa.graphHeight;
2277 height += aa.height;
2289 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2290 boolean preserveNewGroupSettings)
2292 boolean updateCalcs = false;
2293 boolean conv = isShowGroupConservation();
2294 boolean cons = isShowGroupConsensus();
2295 boolean showprf = isShowSequenceLogo();
2296 boolean showConsHist = isShowConsensusHistogram();
2297 boolean normLogo = isNormaliseSequenceLogo();
2298 boolean showHMMPrf = isShowHMMSequenceLogo();
2299 boolean showInfoHist = isShowInformationHistogram();
2300 boolean normHMMLogo = isNormaliseHMMSequenceLogo();
2303 * TODO reorder the annotation rows according to group/sequence ordering on
2306 // boolean sortg = true;
2308 // remove old automatic annotation
2309 // add any new annotation
2311 // intersect alignment annotation with alignment groups
2313 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2314 List<SequenceGroup> oldrfs = new ArrayList<>();
2317 for (int an = 0; an < aan.length; an++)
2319 if (aan[an].autoCalculated && aan[an].groupRef != null)
2321 oldrfs.add(aan[an].groupRef);
2322 alignment.deleteAnnotation(aan[an], false);
2326 if (alignment.getGroups() != null)
2328 for (SequenceGroup sg : alignment.getGroups())
2330 updateCalcs = false;
2331 if (applyGlobalSettings
2332 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2334 // set defaults for this group's conservation/consensus
2335 sg.setshowSequenceLogo(showprf);
2336 sg.setShowConsensusHistogram(showConsHist);
2337 sg.setNormaliseSequenceLogo(normLogo);
2338 sg.setShowHMMSequenceLogo(showHMMPrf);
2339 sg.setShowInformationHistogram(showInfoHist);
2340 sg.setNormaliseHMMSequenceLogo(normHMMLogo);
2345 alignment.addAnnotation(sg.getConservationRow(), 0);
2350 alignment.addAnnotation(sg.getConsensus(), 0);
2352 // refresh the annotation rows
2355 sg.recalcConservation();
2363 public boolean isDisplayReferenceSeq()
2365 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2369 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2371 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2375 public boolean isColourByReferenceSeq()
2377 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2381 public Color getSequenceColour(SequenceI seq)
2383 Color sqc = sequenceColours.get(seq);
2384 return (sqc == null ? Color.white : sqc);
2388 public void setSequenceColour(SequenceI seq, Color col)
2392 sequenceColours.remove(seq);
2396 sequenceColours.put(seq, col);
2401 public void updateSequenceIdColours()
2403 for (SequenceGroup sg : alignment.getGroups())
2405 if (sg.idColour != null)
2407 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2409 sequenceColours.put(s, sg.idColour);
2416 public void clearSequenceColours()
2418 sequenceColours.clear();
2422 public AlignViewportI getCodingComplement()
2424 return this.codingComplement;
2428 * Set this as the (cDna/protein) complement of the given viewport. Also
2429 * ensures the reverse relationship is set on the given viewport.
2432 public void setCodingComplement(AlignViewportI av)
2436 System.err.println("Ignoring recursive setCodingComplement request");
2440 this.codingComplement = av;
2441 // avoid infinite recursion!
2442 if (av.getCodingComplement() != this)
2444 av.setCodingComplement(this);
2450 public boolean isNucleotide()
2452 return getAlignment() == null ? false : getAlignment().isNucleotide();
2456 public FeaturesDisplayedI getFeaturesDisplayed()
2458 return featuresDisplayed;
2462 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2464 featuresDisplayed = featuresDisplayedI;
2468 public boolean areFeaturesDisplayed()
2470 return featuresDisplayed != null
2471 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2478 * features are displayed if true
2481 public void setShowSequenceFeatures(boolean b)
2483 viewStyle.setShowSequenceFeatures(b);
2487 public boolean isShowSequenceFeatures()
2489 return viewStyle.isShowSequenceFeatures();
2493 public void setShowSequenceFeaturesHeight(boolean selected)
2495 viewStyle.setShowSequenceFeaturesHeight(selected);
2499 public boolean isShowSequenceFeaturesHeight()
2501 return viewStyle.isShowSequenceFeaturesHeight();
2505 public void setShowAnnotation(boolean b)
2507 viewStyle.setShowAnnotation(b);
2511 public boolean isShowAnnotation()
2513 return viewStyle.isShowAnnotation();
2517 public boolean isRightAlignIds()
2519 return viewStyle.isRightAlignIds();
2523 public void setRightAlignIds(boolean rightAlignIds)
2525 viewStyle.setRightAlignIds(rightAlignIds);
2529 public boolean getConservationSelected()
2531 return viewStyle.getConservationSelected();
2535 public void setShowBoxes(boolean state)
2537 viewStyle.setShowBoxes(state);
2542 * @see jalview.api.ViewStyleI#getTextColour()
2545 public Color getTextColour()
2547 return viewStyle.getTextColour();
2552 * @see jalview.api.ViewStyleI#getTextColour2()
2555 public Color getTextColour2()
2557 return viewStyle.getTextColour2();
2562 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2565 public int getThresholdTextColour()
2567 return viewStyle.getThresholdTextColour();
2572 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2575 public boolean isConservationColourSelected()
2577 return viewStyle.isConservationColourSelected();
2582 * @see jalview.api.ViewStyleI#isRenderGaps()
2585 public boolean isRenderGaps()
2587 return viewStyle.isRenderGaps();
2592 * @see jalview.api.ViewStyleI#isShowColourText()
2595 public boolean isShowColourText()
2597 return viewStyle.isShowColourText();
2601 * @param conservationColourSelected
2602 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2605 public void setConservationColourSelected(
2606 boolean conservationColourSelected)
2608 viewStyle.setConservationColourSelected(conservationColourSelected);
2612 * @param showColourText
2613 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2616 public void setShowColourText(boolean showColourText)
2618 viewStyle.setShowColourText(showColourText);
2623 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2626 public void setTextColour(Color textColour)
2628 viewStyle.setTextColour(textColour);
2632 * @param thresholdTextColour
2633 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2636 public void setThresholdTextColour(int thresholdTextColour)
2638 viewStyle.setThresholdTextColour(thresholdTextColour);
2642 * @param textColour2
2643 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2646 public void setTextColour2(Color textColour2)
2648 viewStyle.setTextColour2(textColour2);
2652 public ViewStyleI getViewStyle()
2654 return new ViewStyle(viewStyle);
2658 public void setViewStyle(ViewStyleI settingsForView)
2660 viewStyle = new ViewStyle(settingsForView);
2661 if (residueShading != null)
2663 residueShading.setConservationApplied(
2664 settingsForView.isConservationColourSelected());
2669 public boolean sameStyle(ViewStyleI them)
2671 return viewStyle.sameStyle(them);
2676 * @see jalview.api.ViewStyleI#getIdWidth()
2679 public int getIdWidth()
2681 return viewStyle.getIdWidth();
2686 * @see jalview.api.ViewStyleI#setIdWidth(int)
2689 public void setIdWidth(int i)
2691 viewStyle.setIdWidth(i);
2696 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2699 public boolean isCentreColumnLabels()
2701 return viewStyle.isCentreColumnLabels();
2705 * @param centreColumnLabels
2706 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2709 public void setCentreColumnLabels(boolean centreColumnLabels)
2711 viewStyle.setCentreColumnLabels(centreColumnLabels);
2716 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2719 public void setShowDBRefs(boolean showdbrefs)
2721 viewStyle.setShowDBRefs(showdbrefs);
2726 * @see jalview.api.ViewStyleI#isShowDBRefs()
2729 public boolean isShowDBRefs()
2731 return viewStyle.isShowDBRefs();
2736 * @see jalview.api.ViewStyleI#isShowNPFeats()
2739 public boolean isShowNPFeats()
2741 return viewStyle.isShowNPFeats();
2745 * @param shownpfeats
2746 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2749 public void setShowNPFeats(boolean shownpfeats)
2751 viewStyle.setShowNPFeats(shownpfeats);
2754 public abstract StructureSelectionManager getStructureSelectionManager();
2757 * Add one command to the command history list.
2761 public void addToHistoryList(CommandI command)
2763 if (this.historyList != null)
2765 this.historyList.push(command);
2766 broadcastCommand(command, false);
2770 protected void broadcastCommand(CommandI command, boolean undo)
2772 getStructureSelectionManager().commandPerformed(command, undo,
2777 * Add one command to the command redo list.
2781 public void addToRedoList(CommandI command)
2783 if (this.redoList != null)
2785 this.redoList.push(command);
2787 broadcastCommand(command, true);
2791 * Clear the command redo list.
2793 public void clearRedoList()
2795 if (this.redoList != null)
2797 this.redoList.clear();
2801 public void setHistoryList(Deque<CommandI> list)
2803 this.historyList = list;
2806 public Deque<CommandI> getHistoryList()
2808 return this.historyList;
2811 public void setRedoList(Deque<CommandI> list)
2813 this.redoList = list;
2816 public Deque<CommandI> getRedoList()
2818 return this.redoList;
2822 public VamsasSource getVamsasSource()
2827 public SequenceAnnotationOrder getSortAnnotationsBy()
2829 return sortAnnotationsBy;
2832 public void setSortAnnotationsBy(
2833 SequenceAnnotationOrder sortAnnotationsBy)
2835 this.sortAnnotationsBy = sortAnnotationsBy;
2838 public boolean isShowAutocalculatedAbove()
2840 return showAutocalculatedAbove;
2843 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2845 this.showAutocalculatedAbove = showAutocalculatedAbove;
2849 public boolean isScaleProteinAsCdna()
2851 return viewStyle.isScaleProteinAsCdna();
2855 public void setScaleProteinAsCdna(boolean b)
2857 viewStyle.setScaleProteinAsCdna(b);
2861 public boolean isProteinFontAsCdna()
2863 return viewStyle.isProteinFontAsCdna();
2867 public void setProteinFontAsCdna(boolean b)
2869 viewStyle.setProteinFontAsCdna(b);
2873 public void setShowComplementFeatures(boolean b)
2875 viewStyle.setShowComplementFeatures(b);
2879 public boolean isShowComplementFeatures()
2881 return viewStyle.isShowComplementFeatures();
2885 public void setShowComplementFeaturesOnTop(boolean b)
2887 viewStyle.setShowComplementFeaturesOnTop(b);
2891 public boolean isShowComplementFeaturesOnTop()
2893 return viewStyle.isShowComplementFeaturesOnTop();
2897 * @return true if view should scroll to show the highlighted region of a
2902 public final boolean isFollowHighlight()
2904 return followHighlight;
2908 public final void setFollowHighlight(boolean b)
2910 this.followHighlight = b;
2914 public ViewportRanges getRanges()
2920 * Helper method to populate the SearchResults with the location in the
2921 * complementary alignment to scroll to, in order to match this one.
2924 * the SearchResults to add to
2925 * @return the offset (below top of visible region) of the matched sequence
2927 protected int findComplementScrollTarget(SearchResultsI sr)
2929 final AlignViewportI complement = getCodingComplement();
2930 if (complement == null || !complement.isFollowHighlight())
2934 boolean iAmProtein = !getAlignment().isNucleotide();
2935 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2936 : complement.getAlignment();
2937 if (proteinAlignment == null)
2941 final List<AlignedCodonFrame> mappings = proteinAlignment
2945 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2946 * residue in the middle column of the visible region. Scroll the
2947 * complementary alignment to line up the corresponding residue.
2950 SequenceI sequence = null;
2953 * locate 'middle' column (true middle if an odd number visible, left of
2954 * middle if an even number visible)
2956 int middleColumn = ranges.getStartRes()
2957 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2958 final HiddenSequences hiddenSequences = getAlignment()
2959 .getHiddenSequences();
2962 * searching to the bottom of the alignment gives smoother scrolling across
2963 * all gapped visible regions
2965 int lastSeq = alignment.getHeight() - 1;
2966 List<AlignedCodonFrame> seqMappings = null;
2967 for (int seqNo = ranges
2968 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2970 sequence = getAlignment().getSequenceAt(seqNo);
2971 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2975 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2979 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2981 getCodingComplement().getAlignment().getSequences());
2982 if (!seqMappings.isEmpty())
2988 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2991 * No ungapped mapped sequence in middle column - do nothing
2995 MappingUtils.addSearchResults(sr, sequence,
2996 sequence.findPosition(middleColumn), seqMappings);
3001 * synthesize a column selection if none exists so it covers the given
3002 * selection group. if wholewidth is false, no column selection is made if the
3003 * selection group covers the whole alignment width.
3008 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
3011 if (sg != null && (sgs = sg.getStartRes()) >= 0
3012 && sg.getStartRes() <= (sge = sg.getEndRes())
3013 && !this.hasSelectedColumns())
3015 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
3022 colSel = new ColumnSelection();
3024 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
3026 colSel.addElement(cspos);
3032 * hold status of current selection group - defined on alignment or not.
3034 private boolean selectionIsDefinedGroup = false;
3037 public boolean isSelectionDefinedGroup()
3039 if (selectionGroup == null)
3043 if (isSelectionGroupChanged(true))
3045 selectionIsDefinedGroup = false;
3046 List<SequenceGroup> gps = alignment.getGroups();
3047 if (gps == null || gps.size() == 0)
3049 selectionIsDefinedGroup = false;
3053 selectionIsDefinedGroup = gps.contains(selectionGroup);
3056 return selectionGroup.isDefined() || selectionIsDefinedGroup;
3060 * null, or currently highlighted results on this view
3062 private SearchResultsI searchResults = null;
3064 protected TreeModel currentTree = null;
3067 public boolean hasSearchResults()
3069 return searchResults != null;
3073 public void setSearchResults(SearchResultsI results)
3075 searchResults = results;
3079 public SearchResultsI getSearchResults()
3081 return searchResults;
3085 * get the consensus sequence as displayed under the PID consensus annotation
3088 * @return consensus sequence as a new sequence object
3090 public SequenceI getConsensusSeq()
3092 if (consensus == null)
3094 updateConsensus(null);
3096 if (consensus == null)
3100 StringBuffer seqs = new StringBuffer();
3101 for (int i = 0; i < consensus.annotations.length; i++)
3103 Annotation annotation = consensus.annotations[i];
3104 if (annotation != null)
3106 String description = annotation.description;
3107 if (description != null && description.startsWith("["))
3109 // consensus is a tie - just pick the first one
3110 seqs.append(description.charAt(1));
3114 seqs.append(annotation.displayCharacter);
3119 SequenceI sq = new Sequence("Consensus", seqs.toString());
3120 sq.setDescription("Percentage Identity Consensus "
3121 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3125 public boolean hasReferenceAnnotation()
3127 AlignmentAnnotation[] annots = this.alignment.getAlignmentAnnotation();
3128 for (AlignmentAnnotation annot : annots)
3130 if ("RF".equals(annot.label) || annot.label.contains("Reference"))
3139 public void setCurrentTree(TreeModel tree)
3145 public TreeModel getCurrentTree()
3151 public AlignmentExportData getAlignExportData(AlignExportSettingsI options)
3153 AlignmentI alignmentToExport = null;
3154 String[] omitHidden = null;
3155 alignmentToExport = null;
3157 if (hasHiddenColumns() && !options.isExportHiddenColumns())
3159 omitHidden = getViewAsString(false,
3160 options.isExportHiddenSequences());
3163 int[] alignmentStartEnd = new int[2];
3164 if (hasHiddenRows() && options.isExportHiddenSequences())
3166 alignmentToExport = getAlignment().getHiddenSequences()
3167 .getFullAlignment();
3171 alignmentToExport = getAlignment();
3173 alignmentStartEnd = getAlignment().getHiddenColumns()
3174 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
3175 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
3176 omitHidden, alignmentStartEnd);
3181 public boolean isNormaliseSequenceLogo()
3183 return normaliseSequenceLogo;
3186 public void setNormaliseSequenceLogo(boolean state)
3188 normaliseSequenceLogo = state;
3192 public boolean isNormaliseHMMSequenceLogo()
3194 return hmmNormaliseSequenceLogo;
3197 public void setNormaliseHMMSequenceLogo(boolean state)
3199 hmmNormaliseSequenceLogo = state;
3202 * flag set to indicate if structure views might be out of sync with sequences
3206 private boolean needToUpdateStructureViews = false;
3209 public boolean isUpdateStructures()
3211 return needToUpdateStructureViews;
3215 public void setUpdateStructures(boolean update)
3217 needToUpdateStructureViews = update;
3221 public boolean needToUpdateStructureViews()
3223 boolean update = needToUpdateStructureViews;
3224 needToUpdateStructureViews = false;
3229 public void addSequenceGroup(SequenceGroup sequenceGroup)
3231 alignment.addGroup(sequenceGroup);
3233 Color col = sequenceGroup.idColour;
3236 col = col.brighter();
3238 for (SequenceI sq : sequenceGroup.getSequences())
3240 setSequenceColour(sq, col);
3244 if (codingComplement != null)
3246 SequenceGroup mappedGroup = MappingUtils
3247 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3248 if (mappedGroup.getSequences().size() > 0)
3250 codingComplement.getAlignment().addGroup(mappedGroup);
3254 for (SequenceI seq : mappedGroup.getSequences())
3256 codingComplement.setSequenceColour(seq, col);
3260 // propagate the structure view update flag according to our own setting
3261 codingComplement.setUpdateStructures(needToUpdateStructureViews);
3265 * Filters out sequences with an eValue higher than the specified value. The
3266 * filtered sequences are hidden or deleted. Sequences with no eValues are also
3272 public void filterByEvalue(double eValue)
3274 for (SequenceI seq : alignment.getSequencesArray())
3276 if ((seq.getAnnotation("Search Scores") == null
3277 || seq.getAnnotation("Search Scores")[0].getEValue() > eValue)
3278 && seq.getHMM() == null)
3280 hideSequence(new SequenceI[] { seq });
3286 * Filters out sequences with an score lower than the specified value. The
3287 * filtered sequences are hidden or deleted.
3292 public void filterByScore(double score)
3294 for (SequenceI seq : alignment.getSequencesArray())
3296 if ((seq.getAnnotation("Search Scores") == null
3297 || seq.getAnnotation("Search Scores")[0]
3298 .getBitScore() < score)
3299 && seq.getHMM() == null)
3301 hideSequence(new SequenceI[] { seq });
3307 * Notify TreePanel and AlignmentPanel of some sort of alignment change.
3309 public void notifyAlignment()
3311 changeSupport.firePropertyChange(PROPERTY_ALIGNMENT, null, alignment.getSequences());
3315 * Notify AlignmentPanel of a sequence column selection or visibility changes.
3317 public void notifySequence()
3319 changeSupport.firePropertyChange(PROPERTY_SEQUENCE, null, null);