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;
66 import java.awt.Color;
67 import java.beans.PropertyChangeSupport;
68 import java.util.ArrayDeque;
69 import java.util.ArrayList;
70 import java.util.BitSet;
71 import java.util.Deque;
72 import java.util.HashMap;
73 import java.util.Hashtable;
74 import java.util.Iterator;
75 import java.util.List;
77 import java.util.concurrent.Executors;
78 import java.util.concurrent.ScheduledExecutorService;
79 import java.util.concurrent.ScheduledThreadPoolExecutor;
82 * base class holding visualization and analysis attributes and common logic for
83 * an active alignment view displayed in the GUI
87 * @param <AlignmentPanelT>
88 * implementation of the AlignmentViewPanel used by the class
90 public abstract class AlignmentViewport<AlignmentPanelT extends AlignmentViewPanel>
91 implements AlignViewportI, CommandListener, VamsasSource
93 public static final String PROPERTY_ALIGNMENT = "alignment";
94 public static final String PROPERTY_SEQUENCE = "sequence";
95 protected ViewportRanges ranges;
97 protected ViewStyleI viewStyle = new ViewStyle();
100 * A viewport that hosts the cDna view of this (protein), or vice versa (if
103 AlignViewportI codingComplement = null;
105 FeaturesDisplayedI featuresDisplayed = null;
107 protected Deque<CommandI> historyList = new ArrayDeque<>();
109 protected Deque<CommandI> redoList = new ArrayDeque<>();
112 * alignment displayed in the viewport. Please use get/setter
114 protected AlignmentI alignment;
117 * probably unused indicator that view is of a dataset rather than an
121 protected boolean ignoreBelowBackGroundFrequencyCalculation = false;
123 protected boolean infoLetterHeight = false;
125 protected AlignmentAnnotation occupancy;
128 * results of alignment consensus analysis for visible portion of view
130 protected ProfilesI consensusProfiles;
133 * HMM profile for the alignment
135 protected ProfilesI hmmProfiles;
137 public AlignmentViewport(AlignmentI al)
140 ranges = new ViewportRanges(al);
143 protected AlignmentPanelT alignPanel = null;
145 public void setAlignPanel(AlignmentPanelT ap)
151 * return the AlignmentViewPanel containing the given viewport. Use this to
152 * get the components currently handling the given viewport.
155 * @return null or an alignPanel guaranteed to have non-null alignFrame
158 public AlignmentPanelT getAlignPanel()
165 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
168 public void setFontName(String name)
170 viewStyle.setFontName(name);
175 * @see jalview.api.ViewStyleI#setFontStyle(int)
178 public void setFontStyle(int style)
180 viewStyle.setFontStyle(style);
185 * @see jalview.api.ViewStyleI#setFontSize(int)
188 public void setFontSize(int size)
190 viewStyle.setFontSize(size);
195 * @see jalview.api.ViewStyleI#getFontStyle()
198 public int getFontStyle()
200 return viewStyle.getFontStyle();
205 * @see jalview.api.ViewStyleI#getFontName()
208 public String getFontName()
210 return viewStyle.getFontName();
215 * @see jalview.api.ViewStyleI#getFontSize()
218 public int getFontSize()
220 return viewStyle.getFontSize();
224 * @param upperCasebold
225 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
228 public void setUpperCasebold(boolean upperCasebold)
230 viewStyle.setUpperCasebold(upperCasebold);
235 * @see jalview.api.ViewStyleI#isUpperCasebold()
238 public boolean isUpperCasebold()
240 return viewStyle.isUpperCasebold();
245 * @see jalview.api.ViewStyleI#isSeqNameItalics()
248 public boolean isSeqNameItalics()
250 return viewStyle.isSeqNameItalics();
254 * @param colourByReferenceSeq
255 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
258 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
260 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
265 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
268 public void setColourAppliesToAllGroups(boolean b)
270 viewStyle.setColourAppliesToAllGroups(b);
275 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
278 public boolean getColourAppliesToAllGroups()
280 return viewStyle.getColourAppliesToAllGroups();
285 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
288 public boolean getAbovePIDThreshold()
290 return viewStyle.getAbovePIDThreshold();
295 * @see jalview.api.ViewStyleI#setIncrement(int)
298 public void setIncrement(int inc)
300 viewStyle.setIncrement(inc);
305 * @see jalview.api.ViewStyleI#getIncrement()
308 public int getIncrement()
310 return viewStyle.getIncrement();
315 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
318 public void setConservationSelected(boolean b)
320 viewStyle.setConservationSelected(b);
325 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
328 public void setShowHiddenMarkers(boolean show)
330 viewStyle.setShowHiddenMarkers(show);
335 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
338 public boolean getShowHiddenMarkers()
340 return viewStyle.getShowHiddenMarkers();
345 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
348 public void setScaleRightWrapped(boolean b)
350 viewStyle.setScaleRightWrapped(b);
355 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
358 public void setScaleLeftWrapped(boolean b)
360 viewStyle.setScaleLeftWrapped(b);
365 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
368 public void setScaleAboveWrapped(boolean b)
370 viewStyle.setScaleAboveWrapped(b);
375 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
378 public boolean getScaleLeftWrapped()
380 return viewStyle.getScaleLeftWrapped();
385 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
388 public boolean getScaleAboveWrapped()
390 return viewStyle.getScaleAboveWrapped();
395 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
398 public boolean getScaleRightWrapped()
400 return viewStyle.getScaleRightWrapped();
405 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
408 public void setAbovePIDThreshold(boolean b)
410 viewStyle.setAbovePIDThreshold(b);
415 * @see jalview.api.ViewStyleI#setThreshold(int)
418 public void setThreshold(int thresh)
420 viewStyle.setThreshold(thresh);
425 * @see jalview.api.ViewStyleI#getThreshold()
428 public int getThreshold()
430 return viewStyle.getThreshold();
435 * @see jalview.api.ViewStyleI#getShowJVSuffix()
438 public boolean getShowJVSuffix()
440 return viewStyle.getShowJVSuffix();
445 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
448 public void setShowJVSuffix(boolean b)
450 viewStyle.setShowJVSuffix(b);
455 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
458 public void setWrapAlignment(boolean state)
460 viewStyle.setWrapAlignment(state);
461 ranges.setWrappedMode(state);
466 * @see jalview.api.ViewStyleI#setShowText(boolean)
469 public void setShowText(boolean state)
471 viewStyle.setShowText(state);
476 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
479 public void setRenderGaps(boolean state)
481 viewStyle.setRenderGaps(state);
486 * @see jalview.api.ViewStyleI#getColourText()
489 public boolean getColourText()
491 return viewStyle.getColourText();
496 * @see jalview.api.ViewStyleI#setColourText(boolean)
499 public void setColourText(boolean state)
501 viewStyle.setColourText(state);
506 * @see jalview.api.ViewStyleI#getWrapAlignment()
509 public boolean getWrapAlignment()
511 return viewStyle.getWrapAlignment();
516 * @see jalview.api.ViewStyleI#getShowText()
519 public boolean getShowText()
521 return viewStyle.getShowText();
526 * @see jalview.api.ViewStyleI#getWrappedWidth()
529 public int getWrappedWidth()
531 return viewStyle.getWrappedWidth();
536 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
539 public void setWrappedWidth(int w)
541 viewStyle.setWrappedWidth(w);
546 * @see jalview.api.ViewStyleI#getCharHeight()
549 public int getCharHeight()
551 return viewStyle.getCharHeight();
556 * @see jalview.api.ViewStyleI#setCharHeight(int)
559 public void setCharHeight(int h)
561 viewStyle.setCharHeight(h);
566 * @see jalview.api.ViewStyleI#getCharWidth()
569 public int getCharWidth()
571 return viewStyle.getCharWidth();
576 * @see jalview.api.ViewStyleI#setCharWidth(int)
579 public void setCharWidth(int w)
581 viewStyle.setCharWidth(w);
586 * @see jalview.api.ViewStyleI#getShowBoxes()
589 public boolean getShowBoxes()
591 return viewStyle.getShowBoxes();
596 * @see jalview.api.ViewStyleI#getShowUnconserved()
599 public boolean getShowUnconserved()
601 return viewStyle.getShowUnconserved();
605 * @param showunconserved
606 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
609 public void setShowUnconserved(boolean showunconserved)
611 viewStyle.setShowUnconserved(showunconserved);
616 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
619 public void setSeqNameItalics(boolean default1)
621 viewStyle.setSeqNameItalics(default1);
625 public AlignmentI getAlignment()
631 public char getGapCharacter()
633 return alignment.getGapCharacter();
636 protected String sequenceSetID;
639 * probably unused indicator that view is of a dataset rather than an
642 protected boolean isDataset = false;
645 public void setDataset(boolean b)
650 public boolean isDataset()
655 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
657 protected ColumnSelection colSel = new ColumnSelection();
659 protected boolean autoCalculateConsensusAndConservation = true;
661 public boolean getAutoCalculateConsensusAndConservation()
663 return autoCalculateConsensusAndConservation;
666 public void setAutoCalculateConsensusAndConservation(boolean b)
668 autoCalculateConsensusAndConservation = b;
671 protected boolean autoCalculateStrucConsensus = true;
673 public boolean getAutoCalculateStrucConsensus()
675 return autoCalculateStrucConsensus;
678 public void setAutoCalculateStrucConsensus(boolean b)
680 autoCalculateStrucConsensus = b;
682 protected boolean ignoreGapsInConsensusCalculation = false;
684 protected ResidueShaderI residueShading = new ResidueShader();
688 public void setGlobalColourScheme(ColourSchemeI cs)
690 // TODO: logic refactored from AlignFrame changeColour -
691 // TODO: autorecalc stuff should be changed to rely on the worker system
692 // check to see if we should implement a changeColour(cs) method rather than
693 // put the logic in here
694 // - means that caller decides if they want to just modify state and defer
695 // calculation till later or to do all calculations in thread.
699 * only instantiate alignment colouring once, thereafter update it;
700 * this means that any conservation or PID threshold settings
701 * persist when the alignment colour scheme is changed
703 if (residueShading == null)
705 residueShading = new ResidueShader(viewStyle);
707 residueShading.setColourScheme(cs);
709 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
710 // ...problem: groups need these, but do not currently have a ViewStyle
714 if (getConservationSelected())
716 residueShading.setConservation(hconservation);
719 * reset conservation flag in case just set to false if
720 * Conservation was null (calculation still in progress)
722 residueShading.setConservationApplied(getConservationSelected());
723 residueShading.alignmentChanged(alignment, hiddenRepSequences);
727 * if 'apply colour to all groups' is selected... do so
728 * (but don't transfer any colour threshold settings to groups)
730 if (getColourAppliesToAllGroups())
732 for (SequenceGroup sg : getAlignment().getGroups())
735 * retain any colour thresholds per group while
736 * changing choice of colour scheme (JAL-2386)
739 cs == null ? null : cs.getInstance(this, sg));
742 sg.getGroupColourScheme().alignmentChanged(sg,
750 public ColourSchemeI getGlobalColourScheme()
752 return residueShading == null ? null : residueShading.getColourScheme();
756 public ResidueShaderI getResidueShading()
758 return residueShading;
762 protected AlignmentAnnotation consensus;
764 protected AlignmentAnnotation complementConsensus;
766 protected AlignmentAnnotation gapcounts;
768 protected AlignmentAnnotation strucConsensus;
770 protected AlignmentAnnotation conservation;
772 protected AlignmentAnnotation quality;
774 protected AlignmentAnnotation[] groupConsensus;
776 protected AlignmentAnnotation[] groupConservation;
779 * results of alignment consensus analysis for visible portion of view
781 protected ProfilesI hconsensus = null;
784 * results of cDNA complement consensus visible portion of view
786 protected Hashtable<String, Object>[] hcomplementConsensus = null;
789 * results of secondary structure base pair consensus for visible portion of
792 protected Hashtable<String, Object>[] hStrucConsensus = null;
794 protected Conservation hconservation = null;
798 public void setConservation(Conservation cons)
800 hconservation = cons;
804 * percentage gaps allowed in a column before all amino acid properties should
805 * be considered unconserved
807 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
810 public int getConsPercGaps()
816 public void setSequenceConsensusHash(ProfilesI hconsensus)
818 this.hconsensus = hconsensus;
822 public void setComplementConsensusHash(
823 Hashtable<String, Object>[] hconsensus)
825 this.hcomplementConsensus = hconsensus;
829 public ProfilesI getSequenceConsensusHash()
835 public void setHmmProfiles(ProfilesI info)
841 public ProfilesI getHmmProfiles()
847 public Hashtable<String, Object>[] getComplementConsensusHash()
849 return hcomplementConsensus;
853 public Hashtable<String, Object>[] getRnaStructureConsensusHash()
855 return hStrucConsensus;
859 public void setRnaStructureConsensusHash(
860 Hashtable<String, Object>[] hStrucConsensus)
862 this.hStrucConsensus = hStrucConsensus;
867 public AlignmentAnnotation getAlignmentQualityAnnot()
873 public AlignmentAnnotation getAlignmentConservationAnnotation()
879 public AlignmentAnnotation getAlignmentConsensusAnnotation()
885 public AlignmentAnnotation getAlignmentGapAnnotation()
891 public AlignmentAnnotation getComplementConsensusAnnotation()
893 return complementConsensus;
897 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
899 return strucConsensus;
902 protected AlignCalcManagerI2 calculator = new AlignCalcManager2();
905 * trigger update of conservation annotation
907 public void updateConservation(final AlignmentViewPanel ap)
909 // see note in mantis : issue number 8585
910 if (alignment.isNucleotide()
911 || (conservation == null && quality == null)
912 || !autoCalculateConsensusAndConservation)
916 if (calculator.getWorkersOfClass(
917 jalview.workers.ConservationThread.class).isEmpty())
919 calculator.registerWorker(
920 new jalview.workers.ConservationThread(this, ap));
925 * trigger update of consensus annotation
927 public void updateConsensus(final AlignmentViewPanel ap)
929 // see note in mantis : issue number 8585
930 if (consensus == null || !autoCalculateConsensusAndConservation)
934 if (calculator.getWorkersOfClass(ConsensusThread.class).isEmpty())
936 calculator.registerWorker(new ConsensusThread(this, ap));
940 * A separate thread to compute cDNA consensus for a protein alignment
941 * which has mapping to cDNA
943 final AlignmentI al = this.getAlignment();
944 if (!al.isNucleotide() && al.getCodonFrames() != null
945 && !al.getCodonFrames().isEmpty())
948 * fudge - check first for protein-to-nucleotide mappings
949 * (we don't want to do this for protein-to-protein)
951 boolean doConsensus = false;
952 for (AlignedCodonFrame mapping : al.getCodonFrames())
954 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
955 MapList[] mapLists = mapping.getdnaToProt();
956 // mapLists can be empty if project load has not finished resolving seqs
957 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
965 if (calculator.getWorkersOfClass(ComplementConsensusThread.class).isEmpty())
967 calculator.registerWorker(new ComplementConsensusThread(this, ap));
974 public void initInformationWorker(final AlignmentViewPanel ap)
976 if (calculator.getWorkersOfClass(InformationThread.class).isEmpty())
978 calculator.registerWorker(new InformationThread(this, ap));
981 // --------START Structure Conservation
982 public void updateStrucConsensus(final AlignmentViewPanel ap)
984 if (autoCalculateStrucConsensus && strucConsensus == null
985 && alignment.isNucleotide() && alignment.hasRNAStructure())
987 // secondary structure has been added - so init the consensus line
991 // see note in mantis : issue number 8585
992 if (strucConsensus == null || !autoCalculateStrucConsensus)
996 if (calculator.getWorkersOfClass(StrucConsensusThread.class).isEmpty())
998 calculator.registerWorker(new StrucConsensusThread(this, ap));
1002 public boolean isCalcInProgress()
1004 return calculator.isWorking();
1008 public boolean isCalculationInProgress(
1009 AlignmentAnnotation alignmentAnnotation)
1011 if (!alignmentAnnotation.autoCalculated)
1015 if (calculator.isWorkingWithAnnotation(alignmentAnnotation))
1017 // System.err.println("grey out ("+alignmentAnnotation.label+")");
1023 private ScheduledExecutorService serviceExecutor = Executors.newSingleThreadScheduledExecutor();
1026 * Get a default scheduled executor service which can be used by
1027 * services and calculators to run parallel jobs associated with this
1030 * @return default service executor of that viewport
1032 public ScheduledExecutorService getServiceExecutor()
1034 return serviceExecutor;
1037 public void setAlignment(AlignmentI align)
1039 this.alignment = align;
1043 * Clean up references when this viewport is closed
1046 public void dispose()
1049 * defensively null out references to large objects in case
1050 * this object is not garbage collected (as if!)
1054 complementConsensus = null;
1055 strucConsensus = null;
1056 conservation = null;
1058 consensusProfiles = null;
1059 groupConsensus = null;
1060 groupConservation = null;
1062 hconservation = null;
1063 hcomplementConsensus = null;
1065 calculator.shutdown();
1067 serviceExecutor.shutdown();
1068 serviceExecutor = null;
1069 residueShading = null; // may hold a reference to Consensus
1070 changeSupport = null;
1073 selectionGroup = null;
1079 public boolean isClosed()
1081 // TODO: check that this isClosed is only true after panel is closed, not
1082 // before it is fully constructed.
1083 return alignment == null;
1087 public AlignCalcManagerI2 getCalcManager()
1093 * should conservation rows be shown for groups
1095 protected boolean showGroupConservation = false;
1098 * should consensus rows be shown for groups
1100 protected boolean showGroupConsensus = false;
1103 * should consensus profile be rendered by default
1105 protected boolean showSequenceLogo = false;
1108 * should consensus profile be rendered normalised to row height
1110 protected boolean normaliseSequenceLogo = false;
1113 * should consensus histograms be rendered by default
1115 protected boolean showConsensusHistogram = true;
1118 * should hmm profile be rendered by default
1120 protected boolean hmmShowSequenceLogo = false;
1123 * should hmm profile be rendered normalised to row height
1125 protected boolean hmmNormaliseSequenceLogo = false;
1128 * should information histograms be rendered by default
1130 protected boolean hmmShowHistogram = true;
1133 * @return the showConsensusProfile
1136 public boolean isShowSequenceLogo()
1138 return showSequenceLogo;
1142 * @return the showInformationProfile
1145 public boolean isShowHMMSequenceLogo()
1147 return hmmShowSequenceLogo;
1151 * @param showSequenceLogo
1154 public void setShowSequenceLogo(boolean showSequenceLogo)
1156 if (showSequenceLogo != this.showSequenceLogo)
1158 // TODO: decouple settings setting from calculation when refactoring
1159 // annotation update method from alignframe to viewport
1160 this.showSequenceLogo = showSequenceLogo;
1161 for (AlignCalcWorkerI worker : calculator.getWorkers())
1163 if (worker.getClass().equals(ConsensusThread.class) ||
1164 worker.getClass().equals(ComplementConsensusThread.class) ||
1165 worker.getClass().equals(StrucConsensusThread.class))
1167 worker.updateAnnotation();
1171 this.showSequenceLogo = showSequenceLogo;
1174 public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo)
1176 if (showHMMSequenceLogo != this.hmmShowSequenceLogo)
1178 this.hmmShowSequenceLogo = showHMMSequenceLogo;
1179 // TODO: updateAnnotation if description (tooltip) will show
1180 // profile in place of information content?
1181 // calculator.updateAnnotationFor(InformationThread.class);
1183 this.hmmShowSequenceLogo = showHMMSequenceLogo;
1186 * @param showConsensusHistogram
1187 * the showConsensusHistogram to set
1189 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1191 this.showConsensusHistogram = showConsensusHistogram;
1195 * @param showInformationHistogram
1197 public void setShowInformationHistogram(boolean showInformationHistogram)
1199 this.hmmShowHistogram = showInformationHistogram;
1203 * @return the showGroupConservation
1205 public boolean isShowGroupConservation()
1207 return showGroupConservation;
1211 * @param showGroupConservation
1212 * the showGroupConservation to set
1214 public void setShowGroupConservation(boolean showGroupConservation)
1216 this.showGroupConservation = showGroupConservation;
1220 * @return the showGroupConsensus
1222 public boolean isShowGroupConsensus()
1224 return showGroupConsensus;
1228 * @param showGroupConsensus
1229 * the showGroupConsensus to set
1231 public void setShowGroupConsensus(boolean showGroupConsensus)
1233 this.showGroupConsensus = showGroupConsensus;
1238 * @return flag to indicate if the consensus histogram should be rendered by
1242 public boolean isShowConsensusHistogram()
1244 return this.showConsensusHistogram;
1249 * @return flag to indicate if the information content histogram should be
1250 * rendered by default
1253 public boolean isShowInformationHistogram()
1255 return this.hmmShowHistogram;
1259 * when set, updateAlignment will always ensure sequences are of equal length
1261 private boolean padGaps = false;
1264 * when set, alignment should be reordered according to a newly opened tree
1266 public boolean sortByTree = false;
1271 * @return null or the currently selected sequence region
1274 public SequenceGroup getSelectionGroup()
1276 return selectionGroup;
1280 * Set the selection group for this window. Also sets the current alignment as
1281 * the context for the group, if it does not already have one.
1284 * - group holding references to sequences in this alignment view
1288 public void setSelectionGroup(SequenceGroup sg)
1290 selectionGroup = sg;
1291 if (sg != null && sg.getContext() == null)
1293 sg.setContext(alignment);
1297 public void setHiddenColumns(HiddenColumns hidden)
1299 this.alignment.setHiddenColumns(hidden);
1303 public ColumnSelection getColumnSelection()
1309 public void setColumnSelection(ColumnSelection colSel)
1311 this.colSel = colSel;
1314 updateHiddenColumns();
1316 isColSelChanged(true);
1324 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1326 return hiddenRepSequences;
1330 public void setHiddenRepSequences(
1331 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1333 this.hiddenRepSequences = hiddenRepSequences;
1337 public boolean hasSelectedColumns()
1339 ColumnSelection columnSelection = getColumnSelection();
1340 return columnSelection != null && columnSelection.hasSelectedColumns();
1344 public boolean hasHiddenColumns()
1346 return alignment.getHiddenColumns() != null
1347 && alignment.getHiddenColumns().hasHiddenColumns();
1350 public void updateHiddenColumns()
1352 // this method doesn't really do anything now. But - it could, since a
1353 // column Selection could be in the process of modification
1354 // hasHiddenColumns = colSel.hasHiddenColumns();
1358 public boolean hasHiddenRows()
1360 return alignment.getHiddenSequences().getSize() > 0;
1363 protected SequenceGroup selectionGroup;
1365 public void setSequenceSetId(String newid)
1367 if (sequenceSetID != null)
1370 "Warning - overwriting a sequenceSetId for a viewport!");
1372 sequenceSetID = new String(newid);
1376 public String getSequenceSetId()
1378 if (sequenceSetID == null)
1380 sequenceSetID = alignment.hashCode() + "";
1383 return sequenceSetID;
1387 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1390 protected String viewId = null;
1393 public String getViewId()
1397 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1402 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1404 ignoreGapsInConsensusCalculation = b;
1407 updateConsensus(ap);
1408 if (residueShading != null)
1410 residueShading.setThreshold(residueShading.getThreshold(),
1411 ignoreGapsInConsensusCalculation);
1416 public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap)
1418 ignoreBelowBackGroundFrequencyCalculation = b;
1421 public void setInfoLetterHeight(boolean b, AlignmentViewPanel ap)
1423 infoLetterHeight = b;
1426 private long sgrouphash = -1, colselhash = -1;
1429 * checks current SelectionGroup against record of last hash value, and
1433 * update the record of last hash value
1435 * @return true if SelectionGroup changed since last call (when b is true)
1437 public boolean isSelectionGroupChanged(boolean b)
1439 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1440 : selectionGroup.hashCode();
1441 if (hc != -1 && hc != sgrouphash)
1453 * checks current colsel against record of last hash value, and optionally
1457 * update the record of last hash value
1458 * @return true if colsel changed since last call (when b is true)
1460 public boolean isColSelChanged(boolean updateHash)
1462 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1463 if (hc != -1 && hc != colselhash)
1476 public boolean isIgnoreGapsConsensus()
1478 return ignoreGapsInConsensusCalculation;
1482 public boolean isIgnoreBelowBackground()
1484 return ignoreBelowBackGroundFrequencyCalculation;
1488 public boolean isInfoLetterHeight()
1490 return infoLetterHeight;
1492 // property change stuff
1493 // JBPNote Prolly only need this in the applet version.
1494 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1497 protected boolean showConservation = true;
1499 protected boolean showQuality = true;
1501 protected boolean showConsensus = true;
1503 protected boolean showOccupancy = true;
1505 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1507 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1509 protected boolean showAutocalculatedAbove;
1512 * when set, view will scroll to show the highlighted position
1514 private boolean followHighlight = true;
1517 * Property change listener for changes in alignment
1522 public void addPropertyChangeListener(
1523 java.beans.PropertyChangeListener listener)
1525 changeSupport.addPropertyChangeListener(listener);
1534 public void removePropertyChangeListener(
1535 java.beans.PropertyChangeListener listener)
1537 if (changeSupport != null)
1539 changeSupport.removePropertyChangeListener(listener);
1544 // common hide/show column stuff
1546 public void hideSelectedColumns()
1548 if (colSel.isEmpty())
1553 colSel.hideSelectedColumns(alignment);
1554 setSelectionGroup(null);
1555 isColSelChanged(true);
1558 public void hideColumns(int start, int end)
1562 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1566 alignment.getHiddenColumns().hideColumns(start, end);
1568 isColSelChanged(true);
1571 public void showColumn(int col)
1573 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1574 isColSelChanged(true);
1577 public void showAllHiddenColumns()
1579 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1580 isColSelChanged(true);
1583 // common hide/show seq stuff
1584 public void showAllHiddenSeqs()
1586 int startSeq = ranges.getStartSeq();
1587 int endSeq = ranges.getEndSeq();
1589 if (alignment.getHiddenSequences().getSize() > 0)
1591 if (selectionGroup == null)
1593 selectionGroup = new SequenceGroup();
1594 selectionGroup.setEndRes(alignment.getWidth() - 1);
1596 List<SequenceI> tmp = alignment.getHiddenSequences()
1597 .showAll(hiddenRepSequences);
1598 for (SequenceI seq : tmp)
1600 selectionGroup.addSequence(seq, false);
1601 setSequenceAnnotationsVisible(seq, true);
1604 hiddenRepSequences = null;
1606 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1608 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1615 public void showSequence(int index)
1617 int startSeq = ranges.getStartSeq();
1618 int endSeq = ranges.getEndSeq();
1620 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1621 hiddenRepSequences);
1624 if (selectionGroup == null)
1626 selectionGroup = new SequenceGroup();
1627 selectionGroup.setEndRes(alignment.getWidth() - 1);
1630 for (SequenceI seq : tmp)
1632 selectionGroup.addSequence(seq, false);
1633 setSequenceAnnotationsVisible(seq, true);
1636 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1643 public void hideAllSelectedSeqs()
1645 if (selectionGroup == null || selectionGroup.getSize() < 1)
1650 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1654 setSelectionGroup(null);
1657 public void hideSequence(SequenceI[] seq)
1660 * cache offset to first visible sequence
1662 int startSeq = ranges.getStartSeq();
1666 for (int i = 0; i < seq.length; i++)
1668 alignment.getHiddenSequences().hideSequence(seq[i]);
1669 setSequenceAnnotationsVisible(seq[i], false);
1671 ranges.setStartSeq(startSeq);
1677 * Hides the specified sequence, or the sequences it represents
1680 * the sequence to hide, or keep as representative
1681 * @param representGroup
1682 * if true, hide the current selection group except for the
1683 * representative sequence
1685 public void hideSequences(SequenceI sequence, boolean representGroup)
1687 if (selectionGroup == null || selectionGroup.getSize() < 1)
1689 hideSequence(new SequenceI[] { sequence });
1695 hideRepSequences(sequence, selectionGroup);
1696 setSelectionGroup(null);
1700 int gsize = selectionGroup.getSize();
1701 SequenceI[] hseqs = selectionGroup.getSequences()
1702 .toArray(new SequenceI[gsize]);
1704 hideSequence(hseqs);
1705 setSelectionGroup(null);
1710 * Set visibility for any annotations for the given sequence.
1714 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1717 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1720 for (AlignmentAnnotation ann : anns)
1722 if (ann.sequenceRef == sequenceI)
1724 ann.visible = visible;
1730 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1732 int sSize = sg.getSize();
1738 if (hiddenRepSequences == null)
1740 hiddenRepSequences = new Hashtable<>();
1743 hiddenRepSequences.put(repSequence, sg);
1745 // Hide all sequences except the repSequence
1746 SequenceI[] seqs = new SequenceI[sSize - 1];
1748 for (int i = 0; i < sSize; i++)
1750 if (sg.getSequenceAt(i) != repSequence)
1752 if (index == sSize - 1)
1757 seqs[index++] = sg.getSequenceAt(i);
1760 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1761 sg.setHidereps(true); // note: not done in 2.7applet
1768 * @return null or the current reference sequence
1770 public SequenceI getReferenceSeq()
1772 return alignment.getSeqrep();
1777 * @return true iff seq is the reference for the alignment
1779 public boolean isReferenceSeq(SequenceI seq)
1781 return alignment.getSeqrep() == seq;
1787 * @return true if there are sequences represented by this sequence that are
1790 public boolean isHiddenRepSequence(SequenceI seq)
1792 return (hiddenRepSequences != null
1793 && hiddenRepSequences.containsKey(seq));
1799 * @return null or a sequence group containing the sequences that seq
1802 public SequenceGroup getRepresentedSequences(SequenceI seq)
1804 return (SequenceGroup) (hiddenRepSequences == null ? null
1805 : hiddenRepSequences.get(seq));
1809 public int adjustForHiddenSeqs(int alignmentIndex)
1811 return alignment.getHiddenSequences()
1812 .adjustForHiddenSeqs(alignmentIndex);
1816 public void invertColumnSelection()
1818 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1819 isColSelChanged(true);
1823 public SequenceI[] getSelectionAsNewSequence()
1825 SequenceI[] sequences;
1826 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1827 // this was the only caller in the applet for this method
1828 // JBPNote: in applet, this method returned references to the alignment
1829 // sequences, and it did not honour the presence/absence of annotation
1830 // attached to the alignment (probably!)
1831 if (selectionGroup == null || selectionGroup.getSize() == 0)
1833 sequences = alignment.getSequencesArray();
1834 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1835 for (int i = 0; i < sequences.length; i++)
1837 // construct new sequence with subset of visible annotation
1838 sequences[i] = new Sequence(sequences[i], annots);
1843 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1850 public SequenceI[] getSequenceSelection()
1852 SequenceI[] sequences = null;
1853 if (selectionGroup != null)
1855 sequences = selectionGroup.getSequencesInOrder(alignment);
1857 if (sequences == null)
1859 sequences = alignment.getSequencesArray();
1865 public jalview.datamodel.AlignmentView getAlignmentView(
1866 boolean selectedOnly)
1868 return getAlignmentView(selectedOnly, false);
1872 public jalview.datamodel.AlignmentView getAlignmentView(
1873 boolean selectedOnly, boolean markGroups)
1875 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1877 alignment.getHiddenColumns() != null
1878 && alignment.getHiddenColumns().hasHiddenColumns(),
1879 selectedOnly, markGroups);
1883 public String[] getViewAsString(boolean selectedRegionOnly)
1885 return getViewAsString(selectedRegionOnly, true);
1889 public String[] getViewAsString(boolean selectedRegionOnly,
1890 boolean exportHiddenSeqs)
1892 String[] selection = null;
1893 SequenceI[] seqs = null;
1895 int start = 0, end = 0;
1896 if (selectedRegionOnly && selectionGroup != null)
1898 iSize = selectionGroup.getSize();
1899 seqs = selectionGroup.getSequencesInOrder(alignment);
1900 start = selectionGroup.getStartRes();
1901 end = selectionGroup.getEndRes() + 1;
1905 if (hasHiddenRows() && exportHiddenSeqs)
1907 AlignmentI fullAlignment = alignment.getHiddenSequences()
1908 .getFullAlignment();
1909 iSize = fullAlignment.getHeight();
1910 seqs = fullAlignment.getSequencesArray();
1911 end = fullAlignment.getWidth();
1915 iSize = alignment.getHeight();
1916 seqs = alignment.getSequencesArray();
1917 end = alignment.getWidth();
1921 selection = new String[iSize];
1922 if (alignment.getHiddenColumns() != null
1923 && alignment.getHiddenColumns().hasHiddenColumns())
1925 for (i = 0; i < iSize; i++)
1927 Iterator<int[]> blocks = alignment.getHiddenColumns()
1928 .getVisContigsIterator(start, end + 1, false);
1929 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1934 for (i = 0; i < iSize; i++)
1936 selection[i] = seqs[i].getSequenceAsString(start, end);
1944 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1946 ArrayList<int[]> regions = new ArrayList<>();
1952 HiddenColumns hidden = alignment.getHiddenColumns();
1953 if (hidden != null && hidden.hasHiddenColumns())
1957 start = hidden.visibleToAbsoluteColumn(start);
1960 end = hidden.getNextHiddenBoundary(false, start);
1971 regions.add(new int[] { start, end });
1973 if (hidden != null && hidden.hasHiddenColumns())
1975 start = hidden.visibleToAbsoluteColumn(end);
1976 start = hidden.getNextHiddenBoundary(true, start) + 1;
1978 } while (end < max);
1980 // int[][] startEnd = new int[regions.size()][2];
1986 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1987 boolean selectedOnly)
1989 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1990 AlignmentAnnotation[] aa;
1991 if ((aa = alignment.getAlignmentAnnotation()) != null)
1993 for (AlignmentAnnotation annot : aa)
1995 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1996 if (selectedOnly && selectionGroup != null)
1998 clone.makeVisibleAnnotation(
1999 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
2000 alignment.getHiddenColumns());
2004 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
2013 public boolean isPadGaps()
2019 public void setPadGaps(boolean padGaps)
2021 this.padGaps = padGaps;
2025 * apply any post-edit constraints and trigger any calculations needed after
2026 * an edit has been performed on the alignment
2031 public void alignmentChanged(AlignmentViewPanel ap)
2035 alignment.padGaps();
2037 if (autoCalculateConsensusAndConservation)
2039 updateConsensus(ap);
2041 if (hconsensus != null && autoCalculateConsensusAndConservation)
2043 updateConservation(ap);
2045 if (autoCalculateStrucConsensus)
2047 updateStrucConsensus(ap);
2050 // Reset endRes of groups if beyond alignment width
2051 int alWidth = alignment.getWidth();
2052 List<SequenceGroup> groups = alignment.getGroups();
2055 for (SequenceGroup sg : groups)
2057 if (sg.getEndRes() > alWidth)
2059 sg.setEndRes(alWidth - 1);
2064 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
2066 selectionGroup.setEndRes(alWidth - 1);
2069 updateAllColourSchemes();
2070 calculator.restartWorkers();
2074 * reset scope and do calculations for all applied colourschemes on alignment
2076 void updateAllColourSchemes()
2078 ResidueShaderI rs = residueShading;
2081 rs.alignmentChanged(alignment, hiddenRepSequences);
2083 rs.setConsensus(hconsensus);
2084 if (rs.conservationApplied())
2086 rs.setConservation(Conservation.calculateConservation("All",
2087 alignment.getSequences(), 0, alignment.getWidth(), false,
2088 getConsPercGaps(), false));
2092 for (SequenceGroup sg : alignment.getGroups())
2096 sg.cs.alignmentChanged(sg, hiddenRepSequences);
2098 sg.recalcConservation();
2102 protected void initAutoAnnotation()
2104 // TODO: add menu option action that nulls or creates consensus object
2105 // depending on if the user wants to see the annotation or not in a
2106 // specific alignment
2108 if (hconsensus == null && !isDataset)
2110 if (!alignment.isNucleotide())
2119 consensus = new AlignmentAnnotation("Consensus",
2120 MessageManager.getString("label.consensus_descr"),
2121 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2122 initConsensus(consensus);
2125 initComplementConsensus();
2130 * If this is a protein alignment and there are mappings to cDNA, adds the
2131 * cDNA consensus annotation and returns true, else returns false.
2133 public boolean initComplementConsensus()
2135 if (!alignment.isNucleotide())
2137 final List<AlignedCodonFrame> codonMappings = alignment
2139 if (codonMappings != null && !codonMappings.isEmpty())
2141 boolean doConsensus = false;
2142 for (AlignedCodonFrame mapping : codonMappings)
2144 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2145 MapList[] mapLists = mapping.getdnaToProt();
2146 // mapLists can be empty if project load has not finished resolving
2148 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2156 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2158 .getString("label.complement_consensus_descr"),
2159 new Annotation[1], 0f, 100f,
2160 AlignmentAnnotation.BAR_GRAPH);
2161 initConsensus(complementConsensus);
2169 private void initConsensus(AlignmentAnnotation aa)
2172 aa.autoCalculated = true;
2176 alignment.addAnnotation(aa);
2180 // these should be extracted from the view model - style and settings for
2181 // derived annotation
2182 private void initGapCounts()
2186 gapcounts = new AlignmentAnnotation("Occupancy",
2187 MessageManager.getString("label.occupancy_descr"),
2188 new Annotation[1], 0f, alignment.getHeight(),
2189 AlignmentAnnotation.BAR_GRAPH);
2190 gapcounts.hasText = true;
2191 gapcounts.autoCalculated = true;
2192 gapcounts.scaleColLabel = true;
2193 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2195 alignment.addAnnotation(gapcounts);
2199 private void initConservation()
2201 if (showConservation)
2203 if (conservation == null)
2205 conservation = new AlignmentAnnotation("Conservation",
2206 MessageManager.formatMessage("label.conservation_descr",
2208 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2209 conservation.hasText = true;
2210 conservation.autoCalculated = true;
2211 alignment.addAnnotation(conservation);
2216 private void initQuality()
2220 if (quality == null)
2222 quality = new AlignmentAnnotation("Quality",
2223 MessageManager.getString("label.quality_descr"),
2224 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2225 quality.hasText = true;
2226 quality.autoCalculated = true;
2227 alignment.addAnnotation(quality);
2232 private void initRNAStructure()
2234 if (alignment.hasRNAStructure() && strucConsensus == null)
2236 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2237 MessageManager.getString("label.strucconsensus_descr"),
2238 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2239 strucConsensus.hasText = true;
2240 strucConsensus.autoCalculated = true;
2244 alignment.addAnnotation(strucConsensus);
2252 * @see jalview.api.AlignViewportI#calcPanelHeight()
2255 public int calcPanelHeight()
2257 // setHeight of panels
2258 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2260 int charHeight = getCharHeight();
2263 BitSet graphgrp = new BitSet();
2264 for (AlignmentAnnotation aa : anns)
2268 System.err.println("Null annotation row: ignoring.");
2275 if (aa.graphGroup > -1)
2277 if (graphgrp.get(aa.graphGroup))
2283 graphgrp.set(aa.graphGroup);
2290 aa.height += charHeight;
2300 aa.height += aa.graphHeight;
2308 height += aa.height;
2320 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2321 boolean preserveNewGroupSettings)
2323 boolean updateCalcs = false;
2324 boolean conv = isShowGroupConservation();
2325 boolean cons = isShowGroupConsensus();
2326 boolean showprf = isShowSequenceLogo();
2327 boolean showConsHist = isShowConsensusHistogram();
2328 boolean normLogo = isNormaliseSequenceLogo();
2329 boolean showHMMPrf = isShowHMMSequenceLogo();
2330 boolean showInfoHist = isShowInformationHistogram();
2331 boolean normHMMLogo = isNormaliseHMMSequenceLogo();
2334 * TODO reorder the annotation rows according to group/sequence ordering on
2337 // boolean sortg = true;
2339 // remove old automatic annotation
2340 // add any new annotation
2342 // intersect alignment annotation with alignment groups
2344 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2345 List<SequenceGroup> oldrfs = new ArrayList<>();
2348 for (int an = 0; an < aan.length; an++)
2350 if (aan[an].autoCalculated && aan[an].groupRef != null)
2352 oldrfs.add(aan[an].groupRef);
2353 alignment.deleteAnnotation(aan[an], false);
2357 if (alignment.getGroups() != null)
2359 for (SequenceGroup sg : alignment.getGroups())
2361 updateCalcs = false;
2362 if (applyGlobalSettings
2363 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2365 // set defaults for this group's conservation/consensus
2366 sg.setshowSequenceLogo(showprf);
2367 sg.setShowConsensusHistogram(showConsHist);
2368 sg.setNormaliseSequenceLogo(normLogo);
2369 sg.setShowHMMSequenceLogo(showHMMPrf);
2370 sg.setShowInformationHistogram(showInfoHist);
2371 sg.setNormaliseHMMSequenceLogo(normHMMLogo);
2376 alignment.addAnnotation(sg.getConservationRow(), 0);
2381 alignment.addAnnotation(sg.getConsensus(), 0);
2383 // refresh the annotation rows
2386 sg.recalcConservation();
2394 public boolean isDisplayReferenceSeq()
2396 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2400 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2402 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2406 public boolean isColourByReferenceSeq()
2408 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2412 public Color getSequenceColour(SequenceI seq)
2414 Color sqc = sequenceColours.get(seq);
2415 return (sqc == null ? Color.white : sqc);
2419 public void setSequenceColour(SequenceI seq, Color col)
2423 sequenceColours.remove(seq);
2427 sequenceColours.put(seq, col);
2432 public void updateSequenceIdColours()
2434 for (SequenceGroup sg : alignment.getGroups())
2436 if (sg.idColour != null)
2438 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2440 sequenceColours.put(s, sg.idColour);
2447 public void clearSequenceColours()
2449 sequenceColours.clear();
2453 public AlignViewportI getCodingComplement()
2455 return this.codingComplement;
2459 * Set this as the (cDna/protein) complement of the given viewport. Also
2460 * ensures the reverse relationship is set on the given viewport.
2463 public void setCodingComplement(AlignViewportI av)
2467 System.err.println("Ignoring recursive setCodingComplement request");
2471 this.codingComplement = av;
2472 // avoid infinite recursion!
2473 if (av.getCodingComplement() != this)
2475 av.setCodingComplement(this);
2481 public boolean isNucleotide()
2483 return getAlignment() == null ? false : getAlignment().isNucleotide();
2487 public FeaturesDisplayedI getFeaturesDisplayed()
2489 return featuresDisplayed;
2493 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2495 featuresDisplayed = featuresDisplayedI;
2499 public boolean areFeaturesDisplayed()
2501 return featuresDisplayed != null
2502 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2509 * features are displayed if true
2512 public void setShowSequenceFeatures(boolean b)
2514 viewStyle.setShowSequenceFeatures(b);
2518 public boolean isShowSequenceFeatures()
2520 return viewStyle.isShowSequenceFeatures();
2524 public void setShowSequenceFeaturesHeight(boolean selected)
2526 viewStyle.setShowSequenceFeaturesHeight(selected);
2530 public boolean isShowSequenceFeaturesHeight()
2532 return viewStyle.isShowSequenceFeaturesHeight();
2536 public void setShowAnnotation(boolean b)
2538 viewStyle.setShowAnnotation(b);
2542 public boolean isShowAnnotation()
2544 return viewStyle.isShowAnnotation();
2548 public boolean isRightAlignIds()
2550 return viewStyle.isRightAlignIds();
2554 public void setRightAlignIds(boolean rightAlignIds)
2556 viewStyle.setRightAlignIds(rightAlignIds);
2560 public boolean getConservationSelected()
2562 return viewStyle.getConservationSelected();
2566 public void setShowBoxes(boolean state)
2568 viewStyle.setShowBoxes(state);
2573 * @see jalview.api.ViewStyleI#getTextColour()
2576 public Color getTextColour()
2578 return viewStyle.getTextColour();
2583 * @see jalview.api.ViewStyleI#getTextColour2()
2586 public Color getTextColour2()
2588 return viewStyle.getTextColour2();
2593 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2596 public int getThresholdTextColour()
2598 return viewStyle.getThresholdTextColour();
2603 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2606 public boolean isConservationColourSelected()
2608 return viewStyle.isConservationColourSelected();
2613 * @see jalview.api.ViewStyleI#isRenderGaps()
2616 public boolean isRenderGaps()
2618 return viewStyle.isRenderGaps();
2623 * @see jalview.api.ViewStyleI#isShowColourText()
2626 public boolean isShowColourText()
2628 return viewStyle.isShowColourText();
2632 * @param conservationColourSelected
2633 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2636 public void setConservationColourSelected(
2637 boolean conservationColourSelected)
2639 viewStyle.setConservationColourSelected(conservationColourSelected);
2643 * @param showColourText
2644 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2647 public void setShowColourText(boolean showColourText)
2649 viewStyle.setShowColourText(showColourText);
2654 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2657 public void setTextColour(Color textColour)
2659 viewStyle.setTextColour(textColour);
2663 * @param thresholdTextColour
2664 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2667 public void setThresholdTextColour(int thresholdTextColour)
2669 viewStyle.setThresholdTextColour(thresholdTextColour);
2673 * @param textColour2
2674 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2677 public void setTextColour2(Color textColour2)
2679 viewStyle.setTextColour2(textColour2);
2683 public ViewStyleI getViewStyle()
2685 return new ViewStyle(viewStyle);
2689 public void setViewStyle(ViewStyleI settingsForView)
2691 viewStyle = new ViewStyle(settingsForView);
2692 if (residueShading != null)
2694 residueShading.setConservationApplied(
2695 settingsForView.isConservationColourSelected());
2700 public boolean sameStyle(ViewStyleI them)
2702 return viewStyle.sameStyle(them);
2707 * @see jalview.api.ViewStyleI#getIdWidth()
2710 public int getIdWidth()
2712 return viewStyle.getIdWidth();
2717 * @see jalview.api.ViewStyleI#setIdWidth(int)
2720 public void setIdWidth(int i)
2722 viewStyle.setIdWidth(i);
2727 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2730 public boolean isCentreColumnLabels()
2732 return viewStyle.isCentreColumnLabels();
2736 * @param centreColumnLabels
2737 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2740 public void setCentreColumnLabels(boolean centreColumnLabels)
2742 viewStyle.setCentreColumnLabels(centreColumnLabels);
2747 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2750 public void setShowDBRefs(boolean showdbrefs)
2752 viewStyle.setShowDBRefs(showdbrefs);
2757 * @see jalview.api.ViewStyleI#isShowDBRefs()
2760 public boolean isShowDBRefs()
2762 return viewStyle.isShowDBRefs();
2767 * @see jalview.api.ViewStyleI#isShowNPFeats()
2770 public boolean isShowNPFeats()
2772 return viewStyle.isShowNPFeats();
2776 * @param shownpfeats
2777 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2780 public void setShowNPFeats(boolean shownpfeats)
2782 viewStyle.setShowNPFeats(shownpfeats);
2785 public abstract StructureSelectionManager getStructureSelectionManager();
2788 * Add one command to the command history list.
2792 public void addToHistoryList(CommandI command)
2794 if (this.historyList != null)
2796 this.historyList.push(command);
2797 broadcastCommand(command, false);
2801 protected void broadcastCommand(CommandI command, boolean undo)
2803 getStructureSelectionManager().commandPerformed(command, undo,
2808 * Add one command to the command redo list.
2812 public void addToRedoList(CommandI command)
2814 if (this.redoList != null)
2816 this.redoList.push(command);
2818 broadcastCommand(command, true);
2822 * Clear the command redo list.
2824 public void clearRedoList()
2826 if (this.redoList != null)
2828 this.redoList.clear();
2832 public void setHistoryList(Deque<CommandI> list)
2834 this.historyList = list;
2837 public Deque<CommandI> getHistoryList()
2839 return this.historyList;
2842 public void setRedoList(Deque<CommandI> list)
2844 this.redoList = list;
2847 public Deque<CommandI> getRedoList()
2849 return this.redoList;
2853 public VamsasSource getVamsasSource()
2858 public SequenceAnnotationOrder getSortAnnotationsBy()
2860 return sortAnnotationsBy;
2863 public void setSortAnnotationsBy(
2864 SequenceAnnotationOrder sortAnnotationsBy)
2866 this.sortAnnotationsBy = sortAnnotationsBy;
2869 public boolean isShowAutocalculatedAbove()
2871 return showAutocalculatedAbove;
2874 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2876 this.showAutocalculatedAbove = showAutocalculatedAbove;
2880 public boolean isScaleProteinAsCdna()
2882 return viewStyle.isScaleProteinAsCdna();
2886 public void setScaleProteinAsCdna(boolean b)
2888 viewStyle.setScaleProteinAsCdna(b);
2892 public boolean isProteinFontAsCdna()
2894 return viewStyle.isProteinFontAsCdna();
2898 public void setProteinFontAsCdna(boolean b)
2900 viewStyle.setProteinFontAsCdna(b);
2904 public void setShowComplementFeatures(boolean b)
2906 viewStyle.setShowComplementFeatures(b);
2910 public boolean isShowComplementFeatures()
2912 return viewStyle.isShowComplementFeatures();
2916 public void setShowComplementFeaturesOnTop(boolean b)
2918 viewStyle.setShowComplementFeaturesOnTop(b);
2922 public boolean isShowComplementFeaturesOnTop()
2924 return viewStyle.isShowComplementFeaturesOnTop();
2928 * @return true if view should scroll to show the highlighted region of a
2933 public final boolean isFollowHighlight()
2935 return followHighlight;
2939 public final void setFollowHighlight(boolean b)
2941 this.followHighlight = b;
2945 public ViewportRanges getRanges()
2951 * Helper method to populate the SearchResults with the location in the
2952 * complementary alignment to scroll to, in order to match this one.
2955 * the SearchResults to add to
2956 * @return the offset (below top of visible region) of the matched sequence
2958 protected int findComplementScrollTarget(SearchResultsI sr)
2960 final AlignViewportI complement = getCodingComplement();
2961 if (complement == null || !complement.isFollowHighlight())
2965 boolean iAmProtein = !getAlignment().isNucleotide();
2966 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2967 : complement.getAlignment();
2968 if (proteinAlignment == null)
2972 final List<AlignedCodonFrame> mappings = proteinAlignment
2976 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2977 * residue in the middle column of the visible region. Scroll the
2978 * complementary alignment to line up the corresponding residue.
2981 SequenceI sequence = null;
2984 * locate 'middle' column (true middle if an odd number visible, left of
2985 * middle if an even number visible)
2987 int middleColumn = ranges.getStartRes()
2988 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2989 final HiddenSequences hiddenSequences = getAlignment()
2990 .getHiddenSequences();
2993 * searching to the bottom of the alignment gives smoother scrolling across
2994 * all gapped visible regions
2996 int lastSeq = alignment.getHeight() - 1;
2997 List<AlignedCodonFrame> seqMappings = null;
2998 for (int seqNo = ranges
2999 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
3001 sequence = getAlignment().getSequenceAt(seqNo);
3002 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
3006 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
3010 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
3012 getCodingComplement().getAlignment().getSequences());
3013 if (!seqMappings.isEmpty())
3019 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
3022 * No ungapped mapped sequence in middle column - do nothing
3026 MappingUtils.addSearchResults(sr, sequence,
3027 sequence.findPosition(middleColumn), seqMappings);
3032 * synthesize a column selection if none exists so it covers the given
3033 * selection group. if wholewidth is false, no column selection is made if the
3034 * selection group covers the whole alignment width.
3039 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
3042 if (sg != null && (sgs = sg.getStartRes()) >= 0
3043 && sg.getStartRes() <= (sge = sg.getEndRes())
3044 && !this.hasSelectedColumns())
3046 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
3053 colSel = new ColumnSelection();
3055 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
3057 colSel.addElement(cspos);
3063 * hold status of current selection group - defined on alignment or not.
3065 private boolean selectionIsDefinedGroup = false;
3068 public boolean isSelectionDefinedGroup()
3070 if (selectionGroup == null)
3074 if (isSelectionGroupChanged(true))
3076 selectionIsDefinedGroup = false;
3077 List<SequenceGroup> gps = alignment.getGroups();
3078 if (gps == null || gps.size() == 0)
3080 selectionIsDefinedGroup = false;
3084 selectionIsDefinedGroup = gps.contains(selectionGroup);
3087 return selectionGroup.isDefined() || selectionIsDefinedGroup;
3091 * null, or currently highlighted results on this view
3093 private SearchResultsI searchResults = null;
3095 protected TreeModel currentTree = null;
3098 public boolean hasSearchResults()
3100 return searchResults != null;
3104 public void setSearchResults(SearchResultsI results)
3106 searchResults = results;
3110 public SearchResultsI getSearchResults()
3112 return searchResults;
3116 * get the consensus sequence as displayed under the PID consensus annotation
3119 * @return consensus sequence as a new sequence object
3121 public SequenceI getConsensusSeq()
3123 if (consensus == null)
3125 updateConsensus(null);
3127 if (consensus == null)
3131 StringBuffer seqs = new StringBuffer();
3132 for (int i = 0; i < consensus.annotations.length; i++)
3134 Annotation annotation = consensus.annotations[i];
3135 if (annotation != null)
3137 String description = annotation.description;
3138 if (description != null && description.startsWith("["))
3140 // consensus is a tie - just pick the first one
3141 seqs.append(description.charAt(1));
3145 seqs.append(annotation.displayCharacter);
3150 SequenceI sq = new Sequence("Consensus", seqs.toString());
3151 sq.setDescription("Percentage Identity Consensus "
3152 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3156 public boolean hasReferenceAnnotation()
3158 AlignmentAnnotation[] annots = this.alignment.getAlignmentAnnotation();
3159 for (AlignmentAnnotation annot : annots)
3161 if ("RF".equals(annot.label) || annot.label.contains("Reference"))
3169 public void setCurrentTree(TreeModel tree)
3175 public TreeModel getCurrentTree()
3181 public AlignmentExportData getAlignExportData(AlignExportSettingsI options)
3183 AlignmentI alignmentToExport = null;
3184 String[] omitHidden = null;
3185 alignmentToExport = null;
3187 if (hasHiddenColumns() && !options.isExportHiddenColumns())
3189 omitHidden = getViewAsString(false,
3190 options.isExportHiddenSequences());
3193 int[] alignmentStartEnd = new int[2];
3194 if (hasHiddenRows() && options.isExportHiddenSequences())
3196 alignmentToExport = getAlignment().getHiddenSequences()
3197 .getFullAlignment();
3201 alignmentToExport = getAlignment();
3203 alignmentStartEnd = getAlignment().getHiddenColumns()
3204 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
3205 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
3206 omitHidden, alignmentStartEnd);
3211 public boolean isNormaliseSequenceLogo()
3213 return normaliseSequenceLogo;
3216 public void setNormaliseSequenceLogo(boolean state)
3218 normaliseSequenceLogo = state;
3222 public boolean isNormaliseHMMSequenceLogo()
3224 return hmmNormaliseSequenceLogo;
3227 public void setNormaliseHMMSequenceLogo(boolean state)
3229 hmmNormaliseSequenceLogo = state;
3232 * flag set to indicate if structure views might be out of sync with sequences
3236 private boolean needToUpdateStructureViews = false;
3239 public boolean isUpdateStructures()
3241 return needToUpdateStructureViews;
3245 public void setUpdateStructures(boolean update)
3247 needToUpdateStructureViews = update;
3251 public boolean needToUpdateStructureViews()
3253 boolean update = needToUpdateStructureViews;
3254 needToUpdateStructureViews = false;
3259 public void addSequenceGroup(SequenceGroup sequenceGroup)
3261 alignment.addGroup(sequenceGroup);
3263 Color col = sequenceGroup.idColour;
3266 col = col.brighter();
3268 for (SequenceI sq : sequenceGroup.getSequences())
3270 setSequenceColour(sq, col);
3274 if (codingComplement != null)
3276 SequenceGroup mappedGroup = MappingUtils
3277 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3278 if (mappedGroup.getSequences().size() > 0)
3280 codingComplement.getAlignment().addGroup(mappedGroup);
3284 for (SequenceI seq : mappedGroup.getSequences())
3286 codingComplement.setSequenceColour(seq, col);
3290 // propagate the structure view update flag according to our own setting
3291 codingComplement.setUpdateStructures(needToUpdateStructureViews);
3296 public Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly)
3300 if (selectedRegionOnly && selectionGroup != null)
3302 start = selectionGroup.getStartRes();
3303 end = selectionGroup.getEndRes() + 1;
3307 end = alignment.getWidth();
3309 return (alignment.getHiddenColumns().getVisContigsIterator(start, end,
3313 * Filters out sequences with an eValue higher than the specified value. The
3314 * filtered sequences are hidden or deleted. Sequences with no eValues are also
3320 public void filterByEvalue(double eValue)
3322 for (SequenceI seq : alignment.getSequencesArray())
3324 if ((seq.getAnnotation("Search Scores") == null
3325 || seq.getAnnotation("Search Scores")[0].getEValue() > eValue)
3326 && seq.getHMM() == null)
3328 hideSequence(new SequenceI[] { seq });
3334 * Filters out sequences with an score lower than the specified value. The
3335 * filtered sequences are hidden or deleted.
3340 public void filterByScore(double score)
3342 for (SequenceI seq : alignment.getSequencesArray())
3344 if ((seq.getAnnotation("Search Scores") == null
3345 || seq.getAnnotation("Search Scores")[0]
3346 .getBitScore() < score)
3347 && seq.getHMM() == null)
3349 hideSequence(new SequenceI[] { seq });
3355 * Notify TreePanel and AlignmentPanel of some sort of alignment change.
3357 public void notifyAlignment()
3359 changeSupport.firePropertyChange(PROPERTY_ALIGNMENT, null, alignment.getSequences());
3363 * Notify AlignmentPanel of a sequence column selection or visibility changes.
3365 public void notifySequence()
3367 changeSupport.firePropertyChange(PROPERTY_SEQUENCE, null, null);