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
88 public abstract class AlignmentViewport
89 implements AlignViewportI, CommandListener, VamsasSource
91 public static final String PROPERTY_ALIGNMENT = "alignment";
92 public static final String PROPERTY_SEQUENCE = "sequence";
93 protected ViewportRanges ranges;
95 protected ViewStyleI viewStyle = new ViewStyle();
98 * A viewport that hosts the cDna view of this (protein), or vice versa (if
101 AlignViewportI codingComplement = null;
103 FeaturesDisplayedI featuresDisplayed = null;
105 protected Deque<CommandI> historyList = new ArrayDeque<>();
107 protected Deque<CommandI> redoList = new ArrayDeque<>();
110 * alignment displayed in the viewport. Please use get/setter
112 protected AlignmentI alignment;
115 * probably unused indicator that view is of a dataset rather than an
119 protected boolean ignoreBelowBackGroundFrequencyCalculation = false;
121 protected boolean infoLetterHeight = false;
123 protected AlignmentAnnotation occupancy;
126 * results of alignment consensus analysis for visible portion of view
128 protected ProfilesI consensusProfiles;
131 * HMM profile for the alignment
133 protected ProfilesI hmmProfiles;
135 public AlignmentViewport(AlignmentI al)
138 ranges = new ViewportRanges(al);
143 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
146 public void setFontName(String name)
148 viewStyle.setFontName(name);
153 * @see jalview.api.ViewStyleI#setFontStyle(int)
156 public void setFontStyle(int style)
158 viewStyle.setFontStyle(style);
163 * @see jalview.api.ViewStyleI#setFontSize(int)
166 public void setFontSize(int size)
168 viewStyle.setFontSize(size);
173 * @see jalview.api.ViewStyleI#getFontStyle()
176 public int getFontStyle()
178 return viewStyle.getFontStyle();
183 * @see jalview.api.ViewStyleI#getFontName()
186 public String getFontName()
188 return viewStyle.getFontName();
193 * @see jalview.api.ViewStyleI#getFontSize()
196 public int getFontSize()
198 return viewStyle.getFontSize();
202 * @param upperCasebold
203 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
206 public void setUpperCasebold(boolean upperCasebold)
208 viewStyle.setUpperCasebold(upperCasebold);
213 * @see jalview.api.ViewStyleI#isUpperCasebold()
216 public boolean isUpperCasebold()
218 return viewStyle.isUpperCasebold();
223 * @see jalview.api.ViewStyleI#isSeqNameItalics()
226 public boolean isSeqNameItalics()
228 return viewStyle.isSeqNameItalics();
232 * @param colourByReferenceSeq
233 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
236 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
238 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
243 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
246 public void setColourAppliesToAllGroups(boolean b)
248 viewStyle.setColourAppliesToAllGroups(b);
253 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
256 public boolean getColourAppliesToAllGroups()
258 return viewStyle.getColourAppliesToAllGroups();
263 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
266 public boolean getAbovePIDThreshold()
268 return viewStyle.getAbovePIDThreshold();
273 * @see jalview.api.ViewStyleI#setIncrement(int)
276 public void setIncrement(int inc)
278 viewStyle.setIncrement(inc);
283 * @see jalview.api.ViewStyleI#getIncrement()
286 public int getIncrement()
288 return viewStyle.getIncrement();
293 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
296 public void setConservationSelected(boolean b)
298 viewStyle.setConservationSelected(b);
303 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
306 public void setShowHiddenMarkers(boolean show)
308 viewStyle.setShowHiddenMarkers(show);
313 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
316 public boolean getShowHiddenMarkers()
318 return viewStyle.getShowHiddenMarkers();
323 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
326 public void setScaleRightWrapped(boolean b)
328 viewStyle.setScaleRightWrapped(b);
333 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
336 public void setScaleLeftWrapped(boolean b)
338 viewStyle.setScaleLeftWrapped(b);
343 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
346 public void setScaleAboveWrapped(boolean b)
348 viewStyle.setScaleAboveWrapped(b);
353 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
356 public boolean getScaleLeftWrapped()
358 return viewStyle.getScaleLeftWrapped();
363 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
366 public boolean getScaleAboveWrapped()
368 return viewStyle.getScaleAboveWrapped();
373 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
376 public boolean getScaleRightWrapped()
378 return viewStyle.getScaleRightWrapped();
383 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
386 public void setAbovePIDThreshold(boolean b)
388 viewStyle.setAbovePIDThreshold(b);
393 * @see jalview.api.ViewStyleI#setThreshold(int)
396 public void setThreshold(int thresh)
398 viewStyle.setThreshold(thresh);
403 * @see jalview.api.ViewStyleI#getThreshold()
406 public int getThreshold()
408 return viewStyle.getThreshold();
413 * @see jalview.api.ViewStyleI#getShowJVSuffix()
416 public boolean getShowJVSuffix()
418 return viewStyle.getShowJVSuffix();
423 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
426 public void setShowJVSuffix(boolean b)
428 viewStyle.setShowJVSuffix(b);
433 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
436 public void setWrapAlignment(boolean state)
438 viewStyle.setWrapAlignment(state);
439 ranges.setWrappedMode(state);
444 * @see jalview.api.ViewStyleI#setShowText(boolean)
447 public void setShowText(boolean state)
449 viewStyle.setShowText(state);
454 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
457 public void setRenderGaps(boolean state)
459 viewStyle.setRenderGaps(state);
464 * @see jalview.api.ViewStyleI#getColourText()
467 public boolean getColourText()
469 return viewStyle.getColourText();
474 * @see jalview.api.ViewStyleI#setColourText(boolean)
477 public void setColourText(boolean state)
479 viewStyle.setColourText(state);
484 * @see jalview.api.ViewStyleI#getWrapAlignment()
487 public boolean getWrapAlignment()
489 return viewStyle.getWrapAlignment();
494 * @see jalview.api.ViewStyleI#getShowText()
497 public boolean getShowText()
499 return viewStyle.getShowText();
504 * @see jalview.api.ViewStyleI#getWrappedWidth()
507 public int getWrappedWidth()
509 return viewStyle.getWrappedWidth();
514 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
517 public void setWrappedWidth(int w)
519 viewStyle.setWrappedWidth(w);
524 * @see jalview.api.ViewStyleI#getCharHeight()
527 public int getCharHeight()
529 return viewStyle.getCharHeight();
534 * @see jalview.api.ViewStyleI#setCharHeight(int)
537 public void setCharHeight(int h)
539 viewStyle.setCharHeight(h);
544 * @see jalview.api.ViewStyleI#getCharWidth()
547 public int getCharWidth()
549 return viewStyle.getCharWidth();
554 * @see jalview.api.ViewStyleI#setCharWidth(int)
557 public void setCharWidth(int w)
559 viewStyle.setCharWidth(w);
564 * @see jalview.api.ViewStyleI#getShowBoxes()
567 public boolean getShowBoxes()
569 return viewStyle.getShowBoxes();
574 * @see jalview.api.ViewStyleI#getShowUnconserved()
577 public boolean getShowUnconserved()
579 return viewStyle.getShowUnconserved();
583 * @param showunconserved
584 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
587 public void setShowUnconserved(boolean showunconserved)
589 viewStyle.setShowUnconserved(showunconserved);
594 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
597 public void setSeqNameItalics(boolean default1)
599 viewStyle.setSeqNameItalics(default1);
603 public AlignmentI getAlignment()
609 public char getGapCharacter()
611 return alignment.getGapCharacter();
614 protected String sequenceSetID;
617 * probably unused indicator that view is of a dataset rather than an
620 protected boolean isDataset = false;
623 public void setDataset(boolean b)
628 public boolean isDataset()
633 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
635 protected ColumnSelection colSel = new ColumnSelection();
637 protected boolean autoCalculateConsensusAndConservation = true;
639 public boolean getAutoCalculateConsensusAndConservation()
641 return autoCalculateConsensusAndConservation;
644 public void setAutoCalculateConsensusAndConservation(boolean b)
646 autoCalculateConsensusAndConservation = b;
649 protected boolean autoCalculateStrucConsensus = true;
651 public boolean getAutoCalculateStrucConsensus()
653 return autoCalculateStrucConsensus;
656 public void setAutoCalculateStrucConsensus(boolean b)
658 autoCalculateStrucConsensus = b;
660 protected boolean ignoreGapsInConsensusCalculation = false;
662 protected ResidueShaderI residueShading = new ResidueShader();
666 public void setGlobalColourScheme(ColourSchemeI cs)
668 // TODO: logic refactored from AlignFrame changeColour -
669 // TODO: autorecalc stuff should be changed to rely on the worker system
670 // check to see if we should implement a changeColour(cs) method rather than
671 // put the logic in here
672 // - means that caller decides if they want to just modify state and defer
673 // calculation till later or to do all calculations in thread.
677 * only instantiate alignment colouring once, thereafter update it;
678 * this means that any conservation or PID threshold settings
679 * persist when the alignment colour scheme is changed
681 if (residueShading == null)
683 residueShading = new ResidueShader(viewStyle);
685 residueShading.setColourScheme(cs);
687 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
688 // ...problem: groups need these, but do not currently have a ViewStyle
692 if (getConservationSelected())
694 residueShading.setConservation(hconservation);
697 * reset conservation flag in case just set to false if
698 * Conservation was null (calculation still in progress)
700 residueShading.setConservationApplied(getConservationSelected());
701 residueShading.alignmentChanged(alignment, hiddenRepSequences);
705 * if 'apply colour to all groups' is selected... do so
706 * (but don't transfer any colour threshold settings to groups)
708 if (getColourAppliesToAllGroups())
710 for (SequenceGroup sg : getAlignment().getGroups())
713 * retain any colour thresholds per group while
714 * changing choice of colour scheme (JAL-2386)
717 cs == null ? null : cs.getInstance(this, sg));
720 sg.getGroupColourScheme().alignmentChanged(sg,
728 public ColourSchemeI getGlobalColourScheme()
730 return residueShading == null ? null : residueShading.getColourScheme();
734 public ResidueShaderI getResidueShading()
736 return residueShading;
740 protected AlignmentAnnotation consensus;
742 protected AlignmentAnnotation complementConsensus;
744 protected AlignmentAnnotation gapcounts;
746 protected AlignmentAnnotation strucConsensus;
748 protected AlignmentAnnotation conservation;
750 protected AlignmentAnnotation quality;
752 protected AlignmentAnnotation[] groupConsensus;
754 protected AlignmentAnnotation[] groupConservation;
757 * results of alignment consensus analysis for visible portion of view
759 protected ProfilesI hconsensus = null;
762 * results of cDNA complement consensus visible portion of view
764 protected Hashtable<String, Object>[] hcomplementConsensus = null;
767 * results of secondary structure base pair consensus for visible portion of
770 protected Hashtable<String, Object>[] hStrucConsensus = null;
772 protected Conservation hconservation = null;
776 public void setConservation(Conservation cons)
778 hconservation = cons;
782 * percentage gaps allowed in a column before all amino acid properties should
783 * be considered unconserved
785 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
788 public int getConsPercGaps()
794 public void setSequenceConsensusHash(ProfilesI hconsensus)
796 this.hconsensus = hconsensus;
800 public void setComplementConsensusHash(
801 Hashtable<String, Object>[] hconsensus)
803 this.hcomplementConsensus = hconsensus;
807 public ProfilesI getSequenceConsensusHash()
813 public void setHmmProfiles(ProfilesI info)
819 public ProfilesI getHmmProfiles()
825 public Hashtable<String, Object>[] getComplementConsensusHash()
827 return hcomplementConsensus;
831 public Hashtable<String, Object>[] getRnaStructureConsensusHash()
833 return hStrucConsensus;
837 public void setRnaStructureConsensusHash(
838 Hashtable<String, Object>[] hStrucConsensus)
840 this.hStrucConsensus = hStrucConsensus;
845 public AlignmentAnnotation getAlignmentQualityAnnot()
851 public AlignmentAnnotation getAlignmentConservationAnnotation()
857 public AlignmentAnnotation getAlignmentConsensusAnnotation()
863 public AlignmentAnnotation getAlignmentGapAnnotation()
869 public AlignmentAnnotation getComplementConsensusAnnotation()
871 return complementConsensus;
875 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
877 return strucConsensus;
880 protected AlignCalcManagerI2 calculator = new AlignCalcManager2();
883 * trigger update of conservation annotation
885 public void updateConservation(final AlignmentViewPanel ap)
887 // see note in mantis : issue number 8585
888 if (alignment.isNucleotide()
889 || (conservation == null && quality == null)
890 || !autoCalculateConsensusAndConservation)
894 if (calculator.getWorkersOfClass(
895 jalview.workers.ConservationThread.class).isEmpty())
897 calculator.registerWorker(
898 new jalview.workers.ConservationThread(this, ap));
903 * trigger update of consensus annotation
905 public void updateConsensus(final AlignmentViewPanel ap)
907 // see note in mantis : issue number 8585
908 if (consensus == null || !autoCalculateConsensusAndConservation)
912 if (calculator.getWorkersOfClass(ConsensusThread.class).isEmpty())
914 calculator.registerWorker(new ConsensusThread(this, ap));
918 * A separate thread to compute cDNA consensus for a protein alignment
919 * which has mapping to cDNA
921 final AlignmentI al = this.getAlignment();
922 if (!al.isNucleotide() && al.getCodonFrames() != null
923 && !al.getCodonFrames().isEmpty())
926 * fudge - check first for protein-to-nucleotide mappings
927 * (we don't want to do this for protein-to-protein)
929 boolean doConsensus = false;
930 for (AlignedCodonFrame mapping : al.getCodonFrames())
932 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
933 MapList[] mapLists = mapping.getdnaToProt();
934 // mapLists can be empty if project load has not finished resolving seqs
935 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
943 if (calculator.getWorkersOfClass(ComplementConsensusThread.class).isEmpty())
945 calculator.registerWorker(new ComplementConsensusThread(this, ap));
952 public void initInformationWorker(final AlignmentViewPanel ap)
954 if (calculator.getWorkersOfClass(InformationThread.class).isEmpty())
956 calculator.registerWorker(new InformationThread(this, ap));
959 // --------START Structure Conservation
960 public void updateStrucConsensus(final AlignmentViewPanel ap)
962 if (autoCalculateStrucConsensus && strucConsensus == null
963 && alignment.isNucleotide() && alignment.hasRNAStructure())
965 // secondary structure has been added - so init the consensus line
969 // see note in mantis : issue number 8585
970 if (strucConsensus == null || !autoCalculateStrucConsensus)
974 if (calculator.getWorkersOfClass(StrucConsensusThread.class).isEmpty())
976 calculator.registerWorker(new StrucConsensusThread(this, ap));
980 public boolean isCalcInProgress()
982 return calculator.isWorking();
986 public boolean isCalculationInProgress(
987 AlignmentAnnotation alignmentAnnotation)
989 if (!alignmentAnnotation.autoCalculated)
993 if (calculator.isWorkingWithAnnotation(alignmentAnnotation))
995 // System.err.println("grey out ("+alignmentAnnotation.label+")");
1001 private ScheduledExecutorService serviceExecutor = Executors.newSingleThreadScheduledExecutor();
1004 * Get a default scheduled executor service which can be used by
1005 * services and calculators to run parallel jobs associated with this
1008 * @return default service executor of that viewport
1010 public ScheduledExecutorService getServiceExecutor()
1012 return serviceExecutor;
1015 public void setAlignment(AlignmentI align)
1017 this.alignment = align;
1021 * Clean up references when this viewport is closed
1024 public void dispose()
1027 * defensively null out references to large objects in case
1028 * this object is not garbage collected (as if!)
1031 complementConsensus = null;
1032 strucConsensus = null;
1033 conservation = null;
1035 consensusProfiles = null;
1036 groupConsensus = null;
1037 groupConservation = null;
1039 hconservation = null;
1040 hcomplementConsensus = null;
1042 calculator.shutdown();
1044 serviceExecutor.shutdown();
1045 serviceExecutor = null;
1046 residueShading = null; // may hold a reference to Consensus
1047 changeSupport = null;
1050 selectionGroup = null;
1056 public boolean isClosed()
1058 // TODO: check that this isClosed is only true after panel is closed, not
1059 // before it is fully constructed.
1060 return alignment == null;
1064 public AlignCalcManagerI2 getCalcManager()
1070 * should conservation rows be shown for groups
1072 protected boolean showGroupConservation = false;
1075 * should consensus rows be shown for groups
1077 protected boolean showGroupConsensus = false;
1080 * should consensus profile be rendered by default
1082 protected boolean showSequenceLogo = false;
1085 * should consensus profile be rendered normalised to row height
1087 protected boolean normaliseSequenceLogo = false;
1090 * should consensus histograms be rendered by default
1092 protected boolean showConsensusHistogram = true;
1095 * should hmm profile be rendered by default
1097 protected boolean hmmShowSequenceLogo = false;
1100 * should hmm profile be rendered normalised to row height
1102 protected boolean hmmNormaliseSequenceLogo = false;
1105 * should information histograms be rendered by default
1107 protected boolean hmmShowHistogram = true;
1110 * @return the showConsensusProfile
1113 public boolean isShowSequenceLogo()
1115 return showSequenceLogo;
1119 * @return the showInformationProfile
1122 public boolean isShowHMMSequenceLogo()
1124 return hmmShowSequenceLogo;
1128 * @param showSequenceLogo
1131 public void setShowSequenceLogo(boolean showSequenceLogo)
1133 if (showSequenceLogo != this.showSequenceLogo)
1135 // TODO: decouple settings setting from calculation when refactoring
1136 // annotation update method from alignframe to viewport
1137 this.showSequenceLogo = showSequenceLogo;
1138 for (AlignCalcWorkerI worker : calculator.getWorkers())
1140 if (worker.getClass().equals(ConsensusThread.class) ||
1141 worker.getClass().equals(ComplementConsensusThread.class) ||
1142 worker.getClass().equals(StrucConsensusThread.class))
1144 worker.updateAnnotation();
1148 this.showSequenceLogo = showSequenceLogo;
1151 public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo)
1153 if (showHMMSequenceLogo != this.hmmShowSequenceLogo)
1155 this.hmmShowSequenceLogo = showHMMSequenceLogo;
1156 // TODO: updateAnnotation if description (tooltip) will show
1157 // profile in place of information content?
1158 // calculator.updateAnnotationFor(InformationThread.class);
1160 this.hmmShowSequenceLogo = showHMMSequenceLogo;
1163 * @param showConsensusHistogram
1164 * the showConsensusHistogram to set
1166 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1168 this.showConsensusHistogram = showConsensusHistogram;
1172 * @param showInformationHistogram
1174 public void setShowInformationHistogram(boolean showInformationHistogram)
1176 this.hmmShowHistogram = showInformationHistogram;
1180 * @return the showGroupConservation
1182 public boolean isShowGroupConservation()
1184 return showGroupConservation;
1188 * @param showGroupConservation
1189 * the showGroupConservation to set
1191 public void setShowGroupConservation(boolean showGroupConservation)
1193 this.showGroupConservation = showGroupConservation;
1197 * @return the showGroupConsensus
1199 public boolean isShowGroupConsensus()
1201 return showGroupConsensus;
1205 * @param showGroupConsensus
1206 * the showGroupConsensus to set
1208 public void setShowGroupConsensus(boolean showGroupConsensus)
1210 this.showGroupConsensus = showGroupConsensus;
1215 * @return flag to indicate if the consensus histogram should be rendered by
1219 public boolean isShowConsensusHistogram()
1221 return this.showConsensusHistogram;
1226 * @return flag to indicate if the information content histogram should be
1227 * rendered by default
1230 public boolean isShowInformationHistogram()
1232 return this.hmmShowHistogram;
1236 * when set, updateAlignment will always ensure sequences are of equal length
1238 private boolean padGaps = false;
1241 * when set, alignment should be reordered according to a newly opened tree
1243 public boolean sortByTree = false;
1248 * @return null or the currently selected sequence region
1251 public SequenceGroup getSelectionGroup()
1253 return selectionGroup;
1257 * Set the selection group for this window. Also sets the current alignment as
1258 * the context for the group, if it does not already have one.
1261 * - group holding references to sequences in this alignment view
1265 public void setSelectionGroup(SequenceGroup sg)
1267 selectionGroup = sg;
1268 if (sg != null && sg.getContext() == null)
1270 sg.setContext(alignment);
1274 public void setHiddenColumns(HiddenColumns hidden)
1276 this.alignment.setHiddenColumns(hidden);
1280 public ColumnSelection getColumnSelection()
1286 public void setColumnSelection(ColumnSelection colSel)
1288 this.colSel = colSel;
1291 updateHiddenColumns();
1293 isColSelChanged(true);
1301 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1303 return hiddenRepSequences;
1307 public void setHiddenRepSequences(
1308 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1310 this.hiddenRepSequences = hiddenRepSequences;
1314 public boolean hasSelectedColumns()
1316 ColumnSelection columnSelection = getColumnSelection();
1317 return columnSelection != null && columnSelection.hasSelectedColumns();
1321 public boolean hasHiddenColumns()
1323 return alignment.getHiddenColumns() != null
1324 && alignment.getHiddenColumns().hasHiddenColumns();
1327 public void updateHiddenColumns()
1329 // this method doesn't really do anything now. But - it could, since a
1330 // column Selection could be in the process of modification
1331 // hasHiddenColumns = colSel.hasHiddenColumns();
1335 public boolean hasHiddenRows()
1337 return alignment.getHiddenSequences().getSize() > 0;
1340 protected SequenceGroup selectionGroup;
1342 public void setSequenceSetId(String newid)
1344 if (sequenceSetID != null)
1347 "Warning - overwriting a sequenceSetId for a viewport!");
1349 sequenceSetID = new String(newid);
1353 public String getSequenceSetId()
1355 if (sequenceSetID == null)
1357 sequenceSetID = alignment.hashCode() + "";
1360 return sequenceSetID;
1364 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1367 protected String viewId = null;
1370 public String getViewId()
1374 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1379 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1381 ignoreGapsInConsensusCalculation = b;
1384 updateConsensus(ap);
1385 if (residueShading != null)
1387 residueShading.setThreshold(residueShading.getThreshold(),
1388 ignoreGapsInConsensusCalculation);
1393 public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap)
1395 ignoreBelowBackGroundFrequencyCalculation = b;
1398 public void setInfoLetterHeight(boolean b, AlignmentViewPanel ap)
1400 infoLetterHeight = b;
1403 private long sgrouphash = -1, colselhash = -1;
1406 * checks current SelectionGroup against record of last hash value, and
1410 * update the record of last hash value
1412 * @return true if SelectionGroup changed since last call (when b is true)
1414 public boolean isSelectionGroupChanged(boolean b)
1416 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1417 : selectionGroup.hashCode();
1418 if (hc != -1 && hc != sgrouphash)
1430 * checks current colsel against record of last hash value, and optionally
1434 * update the record of last hash value
1435 * @return true if colsel changed since last call (when b is true)
1437 public boolean isColSelChanged(boolean updateHash)
1439 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1440 if (hc != -1 && hc != colselhash)
1453 public boolean isIgnoreGapsConsensus()
1455 return ignoreGapsInConsensusCalculation;
1459 public boolean isIgnoreBelowBackground()
1461 return ignoreBelowBackGroundFrequencyCalculation;
1465 public boolean isInfoLetterHeight()
1467 return infoLetterHeight;
1469 // property change stuff
1470 // JBPNote Prolly only need this in the applet version.
1471 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1474 protected boolean showConservation = true;
1476 protected boolean showQuality = true;
1478 protected boolean showConsensus = true;
1480 protected boolean showOccupancy = true;
1482 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1484 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1486 protected boolean showAutocalculatedAbove;
1489 * when set, view will scroll to show the highlighted position
1491 private boolean followHighlight = true;
1494 * Property change listener for changes in alignment
1499 public void addPropertyChangeListener(
1500 java.beans.PropertyChangeListener listener)
1502 changeSupport.addPropertyChangeListener(listener);
1511 public void removePropertyChangeListener(
1512 java.beans.PropertyChangeListener listener)
1514 if (changeSupport != null)
1516 changeSupport.removePropertyChangeListener(listener);
1521 // common hide/show column stuff
1523 public void hideSelectedColumns()
1525 if (colSel.isEmpty())
1530 colSel.hideSelectedColumns(alignment);
1531 setSelectionGroup(null);
1532 isColSelChanged(true);
1535 public void hideColumns(int start, int end)
1539 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1543 alignment.getHiddenColumns().hideColumns(start, end);
1545 isColSelChanged(true);
1548 public void showColumn(int col)
1550 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1551 isColSelChanged(true);
1554 public void showAllHiddenColumns()
1556 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1557 isColSelChanged(true);
1560 // common hide/show seq stuff
1561 public void showAllHiddenSeqs()
1563 int startSeq = ranges.getStartSeq();
1564 int endSeq = ranges.getEndSeq();
1566 if (alignment.getHiddenSequences().getSize() > 0)
1568 if (selectionGroup == null)
1570 selectionGroup = new SequenceGroup();
1571 selectionGroup.setEndRes(alignment.getWidth() - 1);
1573 List<SequenceI> tmp = alignment.getHiddenSequences()
1574 .showAll(hiddenRepSequences);
1575 for (SequenceI seq : tmp)
1577 selectionGroup.addSequence(seq, false);
1578 setSequenceAnnotationsVisible(seq, true);
1581 hiddenRepSequences = null;
1583 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1585 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1592 public void showSequence(int index)
1594 int startSeq = ranges.getStartSeq();
1595 int endSeq = ranges.getEndSeq();
1597 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1598 hiddenRepSequences);
1601 if (selectionGroup == null)
1603 selectionGroup = new SequenceGroup();
1604 selectionGroup.setEndRes(alignment.getWidth() - 1);
1607 for (SequenceI seq : tmp)
1609 selectionGroup.addSequence(seq, false);
1610 setSequenceAnnotationsVisible(seq, true);
1613 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1620 public void hideAllSelectedSeqs()
1622 if (selectionGroup == null || selectionGroup.getSize() < 1)
1627 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1631 setSelectionGroup(null);
1634 public void hideSequence(SequenceI[] seq)
1637 * cache offset to first visible sequence
1639 int startSeq = ranges.getStartSeq();
1643 for (int i = 0; i < seq.length; i++)
1645 alignment.getHiddenSequences().hideSequence(seq[i]);
1646 setSequenceAnnotationsVisible(seq[i], false);
1648 ranges.setStartSeq(startSeq);
1654 * Hides the specified sequence, or the sequences it represents
1657 * the sequence to hide, or keep as representative
1658 * @param representGroup
1659 * if true, hide the current selection group except for the
1660 * representative sequence
1662 public void hideSequences(SequenceI sequence, boolean representGroup)
1664 if (selectionGroup == null || selectionGroup.getSize() < 1)
1666 hideSequence(new SequenceI[] { sequence });
1672 hideRepSequences(sequence, selectionGroup);
1673 setSelectionGroup(null);
1677 int gsize = selectionGroup.getSize();
1678 SequenceI[] hseqs = selectionGroup.getSequences()
1679 .toArray(new SequenceI[gsize]);
1681 hideSequence(hseqs);
1682 setSelectionGroup(null);
1687 * Set visibility for any annotations for the given sequence.
1691 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1694 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1697 for (AlignmentAnnotation ann : anns)
1699 if (ann.sequenceRef == sequenceI)
1701 ann.visible = visible;
1707 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1709 int sSize = sg.getSize();
1715 if (hiddenRepSequences == null)
1717 hiddenRepSequences = new Hashtable<>();
1720 hiddenRepSequences.put(repSequence, sg);
1722 // Hide all sequences except the repSequence
1723 SequenceI[] seqs = new SequenceI[sSize - 1];
1725 for (int i = 0; i < sSize; i++)
1727 if (sg.getSequenceAt(i) != repSequence)
1729 if (index == sSize - 1)
1734 seqs[index++] = sg.getSequenceAt(i);
1737 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1738 sg.setHidereps(true); // note: not done in 2.7applet
1745 * @return null or the current reference sequence
1747 public SequenceI getReferenceSeq()
1749 return alignment.getSeqrep();
1754 * @return true iff seq is the reference for the alignment
1756 public boolean isReferenceSeq(SequenceI seq)
1758 return alignment.getSeqrep() == seq;
1764 * @return true if there are sequences represented by this sequence that are
1767 public boolean isHiddenRepSequence(SequenceI seq)
1769 return (hiddenRepSequences != null
1770 && hiddenRepSequences.containsKey(seq));
1776 * @return null or a sequence group containing the sequences that seq
1779 public SequenceGroup getRepresentedSequences(SequenceI seq)
1781 return (SequenceGroup) (hiddenRepSequences == null ? null
1782 : hiddenRepSequences.get(seq));
1786 public int adjustForHiddenSeqs(int alignmentIndex)
1788 return alignment.getHiddenSequences()
1789 .adjustForHiddenSeqs(alignmentIndex);
1793 public void invertColumnSelection()
1795 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1796 isColSelChanged(true);
1800 public SequenceI[] getSelectionAsNewSequence()
1802 SequenceI[] sequences;
1803 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1804 // this was the only caller in the applet for this method
1805 // JBPNote: in applet, this method returned references to the alignment
1806 // sequences, and it did not honour the presence/absence of annotation
1807 // attached to the alignment (probably!)
1808 if (selectionGroup == null || selectionGroup.getSize() == 0)
1810 sequences = alignment.getSequencesArray();
1811 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1812 for (int i = 0; i < sequences.length; i++)
1814 // construct new sequence with subset of visible annotation
1815 sequences[i] = new Sequence(sequences[i], annots);
1820 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1827 public SequenceI[] getSequenceSelection()
1829 SequenceI[] sequences = null;
1830 if (selectionGroup != null)
1832 sequences = selectionGroup.getSequencesInOrder(alignment);
1834 if (sequences == null)
1836 sequences = alignment.getSequencesArray();
1842 public jalview.datamodel.AlignmentView getAlignmentView(
1843 boolean selectedOnly)
1845 return getAlignmentView(selectedOnly, false);
1849 public jalview.datamodel.AlignmentView getAlignmentView(
1850 boolean selectedOnly, boolean markGroups)
1852 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1854 alignment.getHiddenColumns() != null
1855 && alignment.getHiddenColumns().hasHiddenColumns(),
1856 selectedOnly, markGroups);
1860 public String[] getViewAsString(boolean selectedRegionOnly)
1862 return getViewAsString(selectedRegionOnly, true);
1866 public String[] getViewAsString(boolean selectedRegionOnly,
1867 boolean exportHiddenSeqs)
1869 String[] selection = null;
1870 SequenceI[] seqs = null;
1872 int start = 0, end = 0;
1873 if (selectedRegionOnly && selectionGroup != null)
1875 iSize = selectionGroup.getSize();
1876 seqs = selectionGroup.getSequencesInOrder(alignment);
1877 start = selectionGroup.getStartRes();
1878 end = selectionGroup.getEndRes() + 1;
1882 if (hasHiddenRows() && exportHiddenSeqs)
1884 AlignmentI fullAlignment = alignment.getHiddenSequences()
1885 .getFullAlignment();
1886 iSize = fullAlignment.getHeight();
1887 seqs = fullAlignment.getSequencesArray();
1888 end = fullAlignment.getWidth();
1892 iSize = alignment.getHeight();
1893 seqs = alignment.getSequencesArray();
1894 end = alignment.getWidth();
1898 selection = new String[iSize];
1899 if (alignment.getHiddenColumns() != null
1900 && alignment.getHiddenColumns().hasHiddenColumns())
1902 for (i = 0; i < iSize; i++)
1904 Iterator<int[]> blocks = alignment.getHiddenColumns()
1905 .getVisContigsIterator(start, end + 1, false);
1906 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1911 for (i = 0; i < iSize; i++)
1913 selection[i] = seqs[i].getSequenceAsString(start, end);
1921 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1923 ArrayList<int[]> regions = new ArrayList<>();
1929 HiddenColumns hidden = alignment.getHiddenColumns();
1930 if (hidden != null && hidden.hasHiddenColumns())
1934 start = hidden.visibleToAbsoluteColumn(start);
1937 end = hidden.getNextHiddenBoundary(false, start);
1948 regions.add(new int[] { start, end });
1950 if (hidden != null && hidden.hasHiddenColumns())
1952 start = hidden.visibleToAbsoluteColumn(end);
1953 start = hidden.getNextHiddenBoundary(true, start) + 1;
1955 } while (end < max);
1957 // int[][] startEnd = new int[regions.size()][2];
1963 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1964 boolean selectedOnly)
1966 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1967 AlignmentAnnotation[] aa;
1968 if ((aa = alignment.getAlignmentAnnotation()) != null)
1970 for (AlignmentAnnotation annot : aa)
1972 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1973 if (selectedOnly && selectionGroup != null)
1975 clone.makeVisibleAnnotation(
1976 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1977 alignment.getHiddenColumns());
1981 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1990 public boolean isPadGaps()
1996 public void setPadGaps(boolean padGaps)
1998 this.padGaps = padGaps;
2002 * apply any post-edit constraints and trigger any calculations needed after
2003 * an edit has been performed on the alignment
2008 public void alignmentChanged(AlignmentViewPanel ap)
2012 alignment.padGaps();
2014 if (autoCalculateConsensusAndConservation)
2016 updateConsensus(ap);
2018 if (hconsensus != null && autoCalculateConsensusAndConservation)
2020 updateConservation(ap);
2022 if (autoCalculateStrucConsensus)
2024 updateStrucConsensus(ap);
2027 // Reset endRes of groups if beyond alignment width
2028 int alWidth = alignment.getWidth();
2029 List<SequenceGroup> groups = alignment.getGroups();
2032 for (SequenceGroup sg : groups)
2034 if (sg.getEndRes() > alWidth)
2036 sg.setEndRes(alWidth - 1);
2041 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
2043 selectionGroup.setEndRes(alWidth - 1);
2046 updateAllColourSchemes();
2047 calculator.restartWorkers();
2051 * reset scope and do calculations for all applied colourschemes on alignment
2053 void updateAllColourSchemes()
2055 ResidueShaderI rs = residueShading;
2058 rs.alignmentChanged(alignment, hiddenRepSequences);
2060 rs.setConsensus(hconsensus);
2061 if (rs.conservationApplied())
2063 rs.setConservation(Conservation.calculateConservation("All",
2064 alignment.getSequences(), 0, alignment.getWidth(), false,
2065 getConsPercGaps(), false));
2069 for (SequenceGroup sg : alignment.getGroups())
2073 sg.cs.alignmentChanged(sg, hiddenRepSequences);
2075 sg.recalcConservation();
2079 protected void initAutoAnnotation()
2081 // TODO: add menu option action that nulls or creates consensus object
2082 // depending on if the user wants to see the annotation or not in a
2083 // specific alignment
2085 if (hconsensus == null && !isDataset)
2087 if (!alignment.isNucleotide())
2096 consensus = new AlignmentAnnotation("Consensus",
2097 MessageManager.getString("label.consensus_descr"),
2098 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2099 initConsensus(consensus);
2102 initComplementConsensus();
2107 * If this is a protein alignment and there are mappings to cDNA, adds the
2108 * cDNA consensus annotation and returns true, else returns false.
2110 public boolean initComplementConsensus()
2112 if (!alignment.isNucleotide())
2114 final List<AlignedCodonFrame> codonMappings = alignment
2116 if (codonMappings != null && !codonMappings.isEmpty())
2118 boolean doConsensus = false;
2119 for (AlignedCodonFrame mapping : codonMappings)
2121 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2122 MapList[] mapLists = mapping.getdnaToProt();
2123 // mapLists can be empty if project load has not finished resolving
2125 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2133 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2135 .getString("label.complement_consensus_descr"),
2136 new Annotation[1], 0f, 100f,
2137 AlignmentAnnotation.BAR_GRAPH);
2138 initConsensus(complementConsensus);
2146 private void initConsensus(AlignmentAnnotation aa)
2149 aa.autoCalculated = true;
2153 alignment.addAnnotation(aa);
2157 // these should be extracted from the view model - style and settings for
2158 // derived annotation
2159 private void initGapCounts()
2163 gapcounts = new AlignmentAnnotation("Occupancy",
2164 MessageManager.getString("label.occupancy_descr"),
2165 new Annotation[1], 0f, alignment.getHeight(),
2166 AlignmentAnnotation.BAR_GRAPH);
2167 gapcounts.hasText = true;
2168 gapcounts.autoCalculated = true;
2169 gapcounts.scaleColLabel = true;
2170 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2172 alignment.addAnnotation(gapcounts);
2176 private void initConservation()
2178 if (showConservation)
2180 if (conservation == null)
2182 conservation = new AlignmentAnnotation("Conservation",
2183 MessageManager.formatMessage("label.conservation_descr",
2185 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2186 conservation.hasText = true;
2187 conservation.autoCalculated = true;
2188 alignment.addAnnotation(conservation);
2193 private void initQuality()
2197 if (quality == null)
2199 quality = new AlignmentAnnotation("Quality",
2200 MessageManager.getString("label.quality_descr"),
2201 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2202 quality.hasText = true;
2203 quality.autoCalculated = true;
2204 alignment.addAnnotation(quality);
2209 private void initRNAStructure()
2211 if (alignment.hasRNAStructure() && strucConsensus == null)
2213 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2214 MessageManager.getString("label.strucconsensus_descr"),
2215 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2216 strucConsensus.hasText = true;
2217 strucConsensus.autoCalculated = true;
2221 alignment.addAnnotation(strucConsensus);
2229 * @see jalview.api.AlignViewportI#calcPanelHeight()
2232 public int calcPanelHeight()
2234 // setHeight of panels
2235 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2237 int charHeight = getCharHeight();
2240 BitSet graphgrp = new BitSet();
2241 for (AlignmentAnnotation aa : anns)
2245 System.err.println("Null annotation row: ignoring.");
2252 if (aa.graphGroup > -1)
2254 if (graphgrp.get(aa.graphGroup))
2260 graphgrp.set(aa.graphGroup);
2267 aa.height += charHeight;
2277 aa.height += aa.graphHeight;
2285 height += aa.height;
2297 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2298 boolean preserveNewGroupSettings)
2300 boolean updateCalcs = false;
2301 boolean conv = isShowGroupConservation();
2302 boolean cons = isShowGroupConsensus();
2303 boolean showprf = isShowSequenceLogo();
2304 boolean showConsHist = isShowConsensusHistogram();
2305 boolean normLogo = isNormaliseSequenceLogo();
2306 boolean showHMMPrf = isShowHMMSequenceLogo();
2307 boolean showInfoHist = isShowInformationHistogram();
2308 boolean normHMMLogo = isNormaliseHMMSequenceLogo();
2311 * TODO reorder the annotation rows according to group/sequence ordering on
2314 // boolean sortg = true;
2316 // remove old automatic annotation
2317 // add any new annotation
2319 // intersect alignment annotation with alignment groups
2321 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2322 List<SequenceGroup> oldrfs = new ArrayList<>();
2325 for (int an = 0; an < aan.length; an++)
2327 if (aan[an].autoCalculated && aan[an].groupRef != null)
2329 oldrfs.add(aan[an].groupRef);
2330 alignment.deleteAnnotation(aan[an], false);
2334 if (alignment.getGroups() != null)
2336 for (SequenceGroup sg : alignment.getGroups())
2338 updateCalcs = false;
2339 if (applyGlobalSettings
2340 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2342 // set defaults for this group's conservation/consensus
2343 sg.setshowSequenceLogo(showprf);
2344 sg.setShowConsensusHistogram(showConsHist);
2345 sg.setNormaliseSequenceLogo(normLogo);
2346 sg.setShowHMMSequenceLogo(showHMMPrf);
2347 sg.setShowInformationHistogram(showInfoHist);
2348 sg.setNormaliseHMMSequenceLogo(normHMMLogo);
2353 alignment.addAnnotation(sg.getConservationRow(), 0);
2358 alignment.addAnnotation(sg.getConsensus(), 0);
2360 // refresh the annotation rows
2363 sg.recalcConservation();
2371 public boolean isDisplayReferenceSeq()
2373 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2377 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2379 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2383 public boolean isColourByReferenceSeq()
2385 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2389 public Color getSequenceColour(SequenceI seq)
2391 Color sqc = sequenceColours.get(seq);
2392 return (sqc == null ? Color.white : sqc);
2396 public void setSequenceColour(SequenceI seq, Color col)
2400 sequenceColours.remove(seq);
2404 sequenceColours.put(seq, col);
2409 public void updateSequenceIdColours()
2411 for (SequenceGroup sg : alignment.getGroups())
2413 if (sg.idColour != null)
2415 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2417 sequenceColours.put(s, sg.idColour);
2424 public void clearSequenceColours()
2426 sequenceColours.clear();
2430 public AlignViewportI getCodingComplement()
2432 return this.codingComplement;
2436 * Set this as the (cDna/protein) complement of the given viewport. Also
2437 * ensures the reverse relationship is set on the given viewport.
2440 public void setCodingComplement(AlignViewportI av)
2444 System.err.println("Ignoring recursive setCodingComplement request");
2448 this.codingComplement = av;
2449 // avoid infinite recursion!
2450 if (av.getCodingComplement() != this)
2452 av.setCodingComplement(this);
2458 public boolean isNucleotide()
2460 return getAlignment() == null ? false : getAlignment().isNucleotide();
2464 public FeaturesDisplayedI getFeaturesDisplayed()
2466 return featuresDisplayed;
2470 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2472 featuresDisplayed = featuresDisplayedI;
2476 public boolean areFeaturesDisplayed()
2478 return featuresDisplayed != null
2479 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2486 * features are displayed if true
2489 public void setShowSequenceFeatures(boolean b)
2491 viewStyle.setShowSequenceFeatures(b);
2495 public boolean isShowSequenceFeatures()
2497 return viewStyle.isShowSequenceFeatures();
2501 public void setShowSequenceFeaturesHeight(boolean selected)
2503 viewStyle.setShowSequenceFeaturesHeight(selected);
2507 public boolean isShowSequenceFeaturesHeight()
2509 return viewStyle.isShowSequenceFeaturesHeight();
2513 public void setShowAnnotation(boolean b)
2515 viewStyle.setShowAnnotation(b);
2519 public boolean isShowAnnotation()
2521 return viewStyle.isShowAnnotation();
2525 public boolean isRightAlignIds()
2527 return viewStyle.isRightAlignIds();
2531 public void setRightAlignIds(boolean rightAlignIds)
2533 viewStyle.setRightAlignIds(rightAlignIds);
2537 public boolean getConservationSelected()
2539 return viewStyle.getConservationSelected();
2543 public void setShowBoxes(boolean state)
2545 viewStyle.setShowBoxes(state);
2550 * @see jalview.api.ViewStyleI#getTextColour()
2553 public Color getTextColour()
2555 return viewStyle.getTextColour();
2560 * @see jalview.api.ViewStyleI#getTextColour2()
2563 public Color getTextColour2()
2565 return viewStyle.getTextColour2();
2570 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2573 public int getThresholdTextColour()
2575 return viewStyle.getThresholdTextColour();
2580 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2583 public boolean isConservationColourSelected()
2585 return viewStyle.isConservationColourSelected();
2590 * @see jalview.api.ViewStyleI#isRenderGaps()
2593 public boolean isRenderGaps()
2595 return viewStyle.isRenderGaps();
2600 * @see jalview.api.ViewStyleI#isShowColourText()
2603 public boolean isShowColourText()
2605 return viewStyle.isShowColourText();
2609 * @param conservationColourSelected
2610 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2613 public void setConservationColourSelected(
2614 boolean conservationColourSelected)
2616 viewStyle.setConservationColourSelected(conservationColourSelected);
2620 * @param showColourText
2621 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2624 public void setShowColourText(boolean showColourText)
2626 viewStyle.setShowColourText(showColourText);
2631 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2634 public void setTextColour(Color textColour)
2636 viewStyle.setTextColour(textColour);
2640 * @param thresholdTextColour
2641 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2644 public void setThresholdTextColour(int thresholdTextColour)
2646 viewStyle.setThresholdTextColour(thresholdTextColour);
2650 * @param textColour2
2651 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2654 public void setTextColour2(Color textColour2)
2656 viewStyle.setTextColour2(textColour2);
2660 public ViewStyleI getViewStyle()
2662 return new ViewStyle(viewStyle);
2666 public void setViewStyle(ViewStyleI settingsForView)
2668 viewStyle = new ViewStyle(settingsForView);
2669 if (residueShading != null)
2671 residueShading.setConservationApplied(
2672 settingsForView.isConservationColourSelected());
2677 public boolean sameStyle(ViewStyleI them)
2679 return viewStyle.sameStyle(them);
2684 * @see jalview.api.ViewStyleI#getIdWidth()
2687 public int getIdWidth()
2689 return viewStyle.getIdWidth();
2694 * @see jalview.api.ViewStyleI#setIdWidth(int)
2697 public void setIdWidth(int i)
2699 viewStyle.setIdWidth(i);
2704 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2707 public boolean isCentreColumnLabels()
2709 return viewStyle.isCentreColumnLabels();
2713 * @param centreColumnLabels
2714 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2717 public void setCentreColumnLabels(boolean centreColumnLabels)
2719 viewStyle.setCentreColumnLabels(centreColumnLabels);
2724 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2727 public void setShowDBRefs(boolean showdbrefs)
2729 viewStyle.setShowDBRefs(showdbrefs);
2734 * @see jalview.api.ViewStyleI#isShowDBRefs()
2737 public boolean isShowDBRefs()
2739 return viewStyle.isShowDBRefs();
2744 * @see jalview.api.ViewStyleI#isShowNPFeats()
2747 public boolean isShowNPFeats()
2749 return viewStyle.isShowNPFeats();
2753 * @param shownpfeats
2754 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2757 public void setShowNPFeats(boolean shownpfeats)
2759 viewStyle.setShowNPFeats(shownpfeats);
2762 public abstract StructureSelectionManager getStructureSelectionManager();
2765 * Add one command to the command history list.
2769 public void addToHistoryList(CommandI command)
2771 if (this.historyList != null)
2773 this.historyList.push(command);
2774 broadcastCommand(command, false);
2778 protected void broadcastCommand(CommandI command, boolean undo)
2780 getStructureSelectionManager().commandPerformed(command, undo,
2785 * Add one command to the command redo list.
2789 public void addToRedoList(CommandI command)
2791 if (this.redoList != null)
2793 this.redoList.push(command);
2795 broadcastCommand(command, true);
2799 * Clear the command redo list.
2801 public void clearRedoList()
2803 if (this.redoList != null)
2805 this.redoList.clear();
2809 public void setHistoryList(Deque<CommandI> list)
2811 this.historyList = list;
2814 public Deque<CommandI> getHistoryList()
2816 return this.historyList;
2819 public void setRedoList(Deque<CommandI> list)
2821 this.redoList = list;
2824 public Deque<CommandI> getRedoList()
2826 return this.redoList;
2830 public VamsasSource getVamsasSource()
2835 public SequenceAnnotationOrder getSortAnnotationsBy()
2837 return sortAnnotationsBy;
2840 public void setSortAnnotationsBy(
2841 SequenceAnnotationOrder sortAnnotationsBy)
2843 this.sortAnnotationsBy = sortAnnotationsBy;
2846 public boolean isShowAutocalculatedAbove()
2848 return showAutocalculatedAbove;
2851 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2853 this.showAutocalculatedAbove = showAutocalculatedAbove;
2857 public boolean isScaleProteinAsCdna()
2859 return viewStyle.isScaleProteinAsCdna();
2863 public void setScaleProteinAsCdna(boolean b)
2865 viewStyle.setScaleProteinAsCdna(b);
2869 public boolean isProteinFontAsCdna()
2871 return viewStyle.isProteinFontAsCdna();
2875 public void setProteinFontAsCdna(boolean b)
2877 viewStyle.setProteinFontAsCdna(b);
2881 public void setShowComplementFeatures(boolean b)
2883 viewStyle.setShowComplementFeatures(b);
2887 public boolean isShowComplementFeatures()
2889 return viewStyle.isShowComplementFeatures();
2893 public void setShowComplementFeaturesOnTop(boolean b)
2895 viewStyle.setShowComplementFeaturesOnTop(b);
2899 public boolean isShowComplementFeaturesOnTop()
2901 return viewStyle.isShowComplementFeaturesOnTop();
2905 * @return true if view should scroll to show the highlighted region of a
2910 public final boolean isFollowHighlight()
2912 return followHighlight;
2916 public final void setFollowHighlight(boolean b)
2918 this.followHighlight = b;
2922 public ViewportRanges getRanges()
2928 * Helper method to populate the SearchResults with the location in the
2929 * complementary alignment to scroll to, in order to match this one.
2932 * the SearchResults to add to
2933 * @return the offset (below top of visible region) of the matched sequence
2935 protected int findComplementScrollTarget(SearchResultsI sr)
2937 final AlignViewportI complement = getCodingComplement();
2938 if (complement == null || !complement.isFollowHighlight())
2942 boolean iAmProtein = !getAlignment().isNucleotide();
2943 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2944 : complement.getAlignment();
2945 if (proteinAlignment == null)
2949 final List<AlignedCodonFrame> mappings = proteinAlignment
2953 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2954 * residue in the middle column of the visible region. Scroll the
2955 * complementary alignment to line up the corresponding residue.
2958 SequenceI sequence = null;
2961 * locate 'middle' column (true middle if an odd number visible, left of
2962 * middle if an even number visible)
2964 int middleColumn = ranges.getStartRes()
2965 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2966 final HiddenSequences hiddenSequences = getAlignment()
2967 .getHiddenSequences();
2970 * searching to the bottom of the alignment gives smoother scrolling across
2971 * all gapped visible regions
2973 int lastSeq = alignment.getHeight() - 1;
2974 List<AlignedCodonFrame> seqMappings = null;
2975 for (int seqNo = ranges
2976 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2978 sequence = getAlignment().getSequenceAt(seqNo);
2979 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2983 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2987 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2989 getCodingComplement().getAlignment().getSequences());
2990 if (!seqMappings.isEmpty())
2996 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2999 * No ungapped mapped sequence in middle column - do nothing
3003 MappingUtils.addSearchResults(sr, sequence,
3004 sequence.findPosition(middleColumn), seqMappings);
3009 * synthesize a column selection if none exists so it covers the given
3010 * selection group. if wholewidth is false, no column selection is made if the
3011 * selection group covers the whole alignment width.
3016 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
3019 if (sg != null && (sgs = sg.getStartRes()) >= 0
3020 && sg.getStartRes() <= (sge = sg.getEndRes())
3021 && !this.hasSelectedColumns())
3023 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
3030 colSel = new ColumnSelection();
3032 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
3034 colSel.addElement(cspos);
3040 * hold status of current selection group - defined on alignment or not.
3042 private boolean selectionIsDefinedGroup = false;
3045 public boolean isSelectionDefinedGroup()
3047 if (selectionGroup == null)
3051 if (isSelectionGroupChanged(true))
3053 selectionIsDefinedGroup = false;
3054 List<SequenceGroup> gps = alignment.getGroups();
3055 if (gps == null || gps.size() == 0)
3057 selectionIsDefinedGroup = false;
3061 selectionIsDefinedGroup = gps.contains(selectionGroup);
3064 return selectionGroup.isDefined() || selectionIsDefinedGroup;
3068 * null, or currently highlighted results on this view
3070 private SearchResultsI searchResults = null;
3072 protected TreeModel currentTree = null;
3075 public boolean hasSearchResults()
3077 return searchResults != null;
3081 public void setSearchResults(SearchResultsI results)
3083 searchResults = results;
3087 public SearchResultsI getSearchResults()
3089 return searchResults;
3093 * get the consensus sequence as displayed under the PID consensus annotation
3096 * @return consensus sequence as a new sequence object
3098 public SequenceI getConsensusSeq()
3100 if (consensus == null)
3102 updateConsensus(null);
3104 if (consensus == null)
3108 StringBuffer seqs = new StringBuffer();
3109 for (int i = 0; i < consensus.annotations.length; i++)
3111 Annotation annotation = consensus.annotations[i];
3112 if (annotation != null)
3114 String description = annotation.description;
3115 if (description != null && description.startsWith("["))
3117 // consensus is a tie - just pick the first one
3118 seqs.append(description.charAt(1));
3122 seqs.append(annotation.displayCharacter);
3127 SequenceI sq = new Sequence("Consensus", seqs.toString());
3128 sq.setDescription("Percentage Identity Consensus "
3129 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3133 public boolean hasReferenceAnnotation()
3135 AlignmentAnnotation[] annots = this.alignment.getAlignmentAnnotation();
3136 for (AlignmentAnnotation annot : annots)
3138 if ("RF".equals(annot.label) || annot.label.contains("Reference"))
3146 public void setCurrentTree(TreeModel tree)
3152 public TreeModel getCurrentTree()
3158 public AlignmentExportData getAlignExportData(AlignExportSettingsI options)
3160 AlignmentI alignmentToExport = null;
3161 String[] omitHidden = null;
3162 alignmentToExport = null;
3164 if (hasHiddenColumns() && !options.isExportHiddenColumns())
3166 omitHidden = getViewAsString(false,
3167 options.isExportHiddenSequences());
3170 int[] alignmentStartEnd = new int[2];
3171 if (hasHiddenRows() && options.isExportHiddenSequences())
3173 alignmentToExport = getAlignment().getHiddenSequences()
3174 .getFullAlignment();
3178 alignmentToExport = getAlignment();
3180 alignmentStartEnd = getAlignment().getHiddenColumns()
3181 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
3182 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
3183 omitHidden, alignmentStartEnd);
3188 public boolean isNormaliseSequenceLogo()
3190 return normaliseSequenceLogo;
3193 public void setNormaliseSequenceLogo(boolean state)
3195 normaliseSequenceLogo = state;
3199 public boolean isNormaliseHMMSequenceLogo()
3201 return hmmNormaliseSequenceLogo;
3204 public void setNormaliseHMMSequenceLogo(boolean state)
3206 hmmNormaliseSequenceLogo = state;
3209 * flag set to indicate if structure views might be out of sync with sequences
3213 private boolean needToUpdateStructureViews = false;
3216 public boolean isUpdateStructures()
3218 return needToUpdateStructureViews;
3222 public void setUpdateStructures(boolean update)
3224 needToUpdateStructureViews = update;
3228 public boolean needToUpdateStructureViews()
3230 boolean update = needToUpdateStructureViews;
3231 needToUpdateStructureViews = false;
3236 public void addSequenceGroup(SequenceGroup sequenceGroup)
3238 alignment.addGroup(sequenceGroup);
3240 Color col = sequenceGroup.idColour;
3243 col = col.brighter();
3245 for (SequenceI sq : sequenceGroup.getSequences())
3247 setSequenceColour(sq, col);
3251 if (codingComplement != null)
3253 SequenceGroup mappedGroup = MappingUtils
3254 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3255 if (mappedGroup.getSequences().size() > 0)
3257 codingComplement.getAlignment().addGroup(mappedGroup);
3261 for (SequenceI seq : mappedGroup.getSequences())
3263 codingComplement.setSequenceColour(seq, col);
3267 // propagate the structure view update flag according to our own setting
3268 codingComplement.setUpdateStructures(needToUpdateStructureViews);
3273 public Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly)
3277 if (selectedRegionOnly && selectionGroup != null)
3279 start = selectionGroup.getStartRes();
3280 end = selectionGroup.getEndRes() + 1;
3284 end = alignment.getWidth();
3286 return (alignment.getHiddenColumns().getVisContigsIterator(start, end,
3290 * Filters out sequences with an eValue higher than the specified value. The
3291 * filtered sequences are hidden or deleted. Sequences with no eValues are also
3297 public void filterByEvalue(double eValue)
3299 for (SequenceI seq : alignment.getSequencesArray())
3301 if ((seq.getAnnotation("Search Scores") == null
3302 || seq.getAnnotation("Search Scores")[0].getEValue() > eValue)
3303 && seq.getHMM() == null)
3305 hideSequence(new SequenceI[] { seq });
3311 * Filters out sequences with an score lower than the specified value. The
3312 * filtered sequences are hidden or deleted.
3317 public void filterByScore(double score)
3319 for (SequenceI seq : alignment.getSequencesArray())
3321 if ((seq.getAnnotation("Search Scores") == null
3322 || seq.getAnnotation("Search Scores")[0]
3323 .getBitScore() < score)
3324 && seq.getHMM() == null)
3326 hideSequence(new SequenceI[] { seq });
3332 * Notify TreePanel and AlignmentPanel of some sort of alignment change.
3334 public void notifyAlignment()
3336 changeSupport.firePropertyChange(PROPERTY_ALIGNMENT, null, alignment.getSequences());
3340 * Notify AlignmentPanel of a sequence column selection or visibility changes.
3342 public void notifySequence()
3344 changeSupport.firePropertyChange(PROPERTY_SEQUENCE, null, null);