2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.viewmodel;
23 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
24 import jalview.analysis.Conservation;
25 import jalview.analysis.TreeModel;
26 import jalview.api.AlignCalcManagerI2;
27 import jalview.api.AlignCalcWorkerI;
28 import jalview.api.AlignExportSettingsI;
29 import jalview.api.AlignViewportI;
30 import jalview.api.AlignmentViewPanel;
31 import jalview.api.FeaturesDisplayedI;
32 import jalview.api.ViewStyleI;
33 import jalview.commands.CommandI;
34 import jalview.datamodel.AlignedCodonFrame;
35 import jalview.datamodel.AlignmentAnnotation;
36 import jalview.datamodel.AlignmentExportData;
37 import jalview.datamodel.AlignmentI;
38 import jalview.datamodel.AlignmentView;
39 import jalview.datamodel.Annotation;
40 import jalview.datamodel.ColumnSelection;
41 import jalview.datamodel.HiddenColumns;
42 import jalview.datamodel.HiddenSequences;
43 import jalview.datamodel.ProfilesI;
44 import jalview.datamodel.SearchResultsI;
45 import jalview.datamodel.Sequence;
46 import jalview.datamodel.SequenceCollectionI;
47 import jalview.datamodel.SequenceGroup;
48 import jalview.datamodel.SequenceI;
49 import jalview.renderer.ResidueShader;
50 import jalview.renderer.ResidueShaderI;
51 import jalview.schemes.ColourSchemeI;
52 import jalview.structure.CommandListener;
53 import jalview.structure.StructureSelectionManager;
54 import jalview.structure.VamsasSource;
55 import jalview.util.Comparison;
56 import jalview.util.MapList;
57 import jalview.util.MappingUtils;
58 import jalview.util.MessageManager;
59 import jalview.viewmodel.styles.ViewStyle;
60 import jalview.workers.AlignCalcManager2;
61 import jalview.workers.ComplementConsensusThread;
62 import jalview.workers.ConsensusThread;
63 import jalview.workers.InformationThread;
64 import jalview.workers.StrucConsensusThread;
65 import jalview.ws2.PollingTaskExecutor;
67 import java.awt.Color;
68 import java.beans.PropertyChangeSupport;
69 import java.util.ArrayDeque;
70 import java.util.ArrayList;
71 import java.util.BitSet;
72 import java.util.Deque;
73 import java.util.HashMap;
74 import java.util.Hashtable;
75 import java.util.Iterator;
76 import java.util.List;
80 * base class holding visualization and analysis attributes and common logic for
81 * an active alignment view displayed in the GUI
86 public abstract class AlignmentViewport
87 implements AlignViewportI, CommandListener, VamsasSource
89 public static final String PROPERTY_ALIGNMENT = "alignment";
90 public static final String PROPERTY_SEQUENCE = "sequence";
91 protected ViewportRanges ranges;
93 protected ViewStyleI viewStyle = new ViewStyle();
96 * A viewport that hosts the cDna view of this (protein), or vice versa (if
99 AlignViewportI codingComplement = null;
101 FeaturesDisplayedI featuresDisplayed = null;
103 protected Deque<CommandI> historyList = new ArrayDeque<>();
105 protected Deque<CommandI> redoList = new ArrayDeque<>();
108 * alignment displayed in the viewport. Please use get/setter
110 protected AlignmentI alignment;
113 * probably unused indicator that view is of a dataset rather than an
117 protected boolean ignoreBelowBackGroundFrequencyCalculation = false;
119 protected boolean infoLetterHeight = false;
121 protected AlignmentAnnotation occupancy;
124 * results of alignment consensus analysis for visible portion of view
126 protected ProfilesI consensusProfiles;
129 * HMM profile for the alignment
131 protected ProfilesI hmmProfiles;
133 public AlignmentViewport(AlignmentI al)
136 ranges = new ViewportRanges(al);
141 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
144 public void setFontName(String name)
146 viewStyle.setFontName(name);
151 * @see jalview.api.ViewStyleI#setFontStyle(int)
154 public void setFontStyle(int style)
156 viewStyle.setFontStyle(style);
161 * @see jalview.api.ViewStyleI#setFontSize(int)
164 public void setFontSize(int size)
166 viewStyle.setFontSize(size);
171 * @see jalview.api.ViewStyleI#getFontStyle()
174 public int getFontStyle()
176 return viewStyle.getFontStyle();
181 * @see jalview.api.ViewStyleI#getFontName()
184 public String getFontName()
186 return viewStyle.getFontName();
191 * @see jalview.api.ViewStyleI#getFontSize()
194 public int getFontSize()
196 return viewStyle.getFontSize();
200 * @param upperCasebold
201 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
204 public void setUpperCasebold(boolean upperCasebold)
206 viewStyle.setUpperCasebold(upperCasebold);
211 * @see jalview.api.ViewStyleI#isUpperCasebold()
214 public boolean isUpperCasebold()
216 return viewStyle.isUpperCasebold();
221 * @see jalview.api.ViewStyleI#isSeqNameItalics()
224 public boolean isSeqNameItalics()
226 return viewStyle.isSeqNameItalics();
230 * @param colourByReferenceSeq
231 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
234 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
236 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
241 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
244 public void setColourAppliesToAllGroups(boolean b)
246 viewStyle.setColourAppliesToAllGroups(b);
251 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
254 public boolean getColourAppliesToAllGroups()
256 return viewStyle.getColourAppliesToAllGroups();
261 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
264 public boolean getAbovePIDThreshold()
266 return viewStyle.getAbovePIDThreshold();
271 * @see jalview.api.ViewStyleI#setIncrement(int)
274 public void setIncrement(int inc)
276 viewStyle.setIncrement(inc);
281 * @see jalview.api.ViewStyleI#getIncrement()
284 public int getIncrement()
286 return viewStyle.getIncrement();
291 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
294 public void setConservationSelected(boolean b)
296 viewStyle.setConservationSelected(b);
301 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
304 public void setShowHiddenMarkers(boolean show)
306 viewStyle.setShowHiddenMarkers(show);
311 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
314 public boolean getShowHiddenMarkers()
316 return viewStyle.getShowHiddenMarkers();
321 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
324 public void setScaleRightWrapped(boolean b)
326 viewStyle.setScaleRightWrapped(b);
331 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
334 public void setScaleLeftWrapped(boolean b)
336 viewStyle.setScaleLeftWrapped(b);
341 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
344 public void setScaleAboveWrapped(boolean b)
346 viewStyle.setScaleAboveWrapped(b);
351 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
354 public boolean getScaleLeftWrapped()
356 return viewStyle.getScaleLeftWrapped();
361 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
364 public boolean getScaleAboveWrapped()
366 return viewStyle.getScaleAboveWrapped();
371 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
374 public boolean getScaleRightWrapped()
376 return viewStyle.getScaleRightWrapped();
381 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
384 public void setAbovePIDThreshold(boolean b)
386 viewStyle.setAbovePIDThreshold(b);
391 * @see jalview.api.ViewStyleI#setThreshold(int)
394 public void setThreshold(int thresh)
396 viewStyle.setThreshold(thresh);
401 * @see jalview.api.ViewStyleI#getThreshold()
404 public int getThreshold()
406 return viewStyle.getThreshold();
411 * @see jalview.api.ViewStyleI#getShowJVSuffix()
414 public boolean getShowJVSuffix()
416 return viewStyle.getShowJVSuffix();
421 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
424 public void setShowJVSuffix(boolean b)
426 viewStyle.setShowJVSuffix(b);
431 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
434 public void setWrapAlignment(boolean state)
436 viewStyle.setWrapAlignment(state);
437 ranges.setWrappedMode(state);
442 * @see jalview.api.ViewStyleI#setShowText(boolean)
445 public void setShowText(boolean state)
447 viewStyle.setShowText(state);
452 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
455 public void setRenderGaps(boolean state)
457 viewStyle.setRenderGaps(state);
462 * @see jalview.api.ViewStyleI#getColourText()
465 public boolean getColourText()
467 return viewStyle.getColourText();
472 * @see jalview.api.ViewStyleI#setColourText(boolean)
475 public void setColourText(boolean state)
477 viewStyle.setColourText(state);
482 * @see jalview.api.ViewStyleI#getWrapAlignment()
485 public boolean getWrapAlignment()
487 return viewStyle.getWrapAlignment();
492 * @see jalview.api.ViewStyleI#getShowText()
495 public boolean getShowText()
497 return viewStyle.getShowText();
502 * @see jalview.api.ViewStyleI#getWrappedWidth()
505 public int getWrappedWidth()
507 return viewStyle.getWrappedWidth();
512 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
515 public void setWrappedWidth(int w)
517 viewStyle.setWrappedWidth(w);
522 * @see jalview.api.ViewStyleI#getCharHeight()
525 public int getCharHeight()
527 return viewStyle.getCharHeight();
532 * @see jalview.api.ViewStyleI#setCharHeight(int)
535 public void setCharHeight(int h)
537 viewStyle.setCharHeight(h);
542 * @see jalview.api.ViewStyleI#getCharWidth()
545 public int getCharWidth()
547 return viewStyle.getCharWidth();
552 * @see jalview.api.ViewStyleI#setCharWidth(int)
555 public void setCharWidth(int w)
557 viewStyle.setCharWidth(w);
562 * @see jalview.api.ViewStyleI#getShowBoxes()
565 public boolean getShowBoxes()
567 return viewStyle.getShowBoxes();
572 * @see jalview.api.ViewStyleI#getShowUnconserved()
575 public boolean getShowUnconserved()
577 return viewStyle.getShowUnconserved();
581 * @param showunconserved
582 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
585 public void setShowUnconserved(boolean showunconserved)
587 viewStyle.setShowUnconserved(showunconserved);
592 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
595 public void setSeqNameItalics(boolean default1)
597 viewStyle.setSeqNameItalics(default1);
601 public AlignmentI getAlignment()
607 public char getGapCharacter()
609 return alignment.getGapCharacter();
612 protected String sequenceSetID;
615 * probably unused indicator that view is of a dataset rather than an
618 protected boolean isDataset = false;
621 public void setDataset(boolean b)
626 public boolean isDataset()
631 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
633 protected ColumnSelection colSel = new ColumnSelection();
635 protected boolean autoCalculateConsensusAndConservation = true;
637 public boolean getAutoCalculateConsensusAndConservation()
639 return autoCalculateConsensusAndConservation;
642 public void setAutoCalculateConsensusAndConservation(boolean b)
644 autoCalculateConsensusAndConservation = b;
647 protected boolean autoCalculateStrucConsensus = true;
649 public boolean getAutoCalculateStrucConsensus()
651 return autoCalculateStrucConsensus;
654 public void setAutoCalculateStrucConsensus(boolean b)
656 autoCalculateStrucConsensus = b;
658 protected boolean ignoreGapsInConsensusCalculation = false;
660 protected ResidueShaderI residueShading = new ResidueShader();
664 public void setGlobalColourScheme(ColourSchemeI cs)
666 // TODO: logic refactored from AlignFrame changeColour -
667 // TODO: autorecalc stuff should be changed to rely on the worker system
668 // check to see if we should implement a changeColour(cs) method rather than
669 // put the logic in here
670 // - means that caller decides if they want to just modify state and defer
671 // calculation till later or to do all calculations in thread.
675 * only instantiate alignment colouring once, thereafter update it;
676 * this means that any conservation or PID threshold settings
677 * persist when the alignment colour scheme is changed
679 if (residueShading == null)
681 residueShading = new ResidueShader(viewStyle);
683 residueShading.setColourScheme(cs);
685 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
686 // ...problem: groups need these, but do not currently have a ViewStyle
690 if (getConservationSelected())
692 residueShading.setConservation(hconservation);
695 * reset conservation flag in case just set to false if
696 * Conservation was null (calculation still in progress)
698 residueShading.setConservationApplied(getConservationSelected());
699 residueShading.alignmentChanged(alignment, hiddenRepSequences);
703 * if 'apply colour to all groups' is selected... do so
704 * (but don't transfer any colour threshold settings to groups)
706 if (getColourAppliesToAllGroups())
708 for (SequenceGroup sg : getAlignment().getGroups())
711 * retain any colour thresholds per group while
712 * changing choice of colour scheme (JAL-2386)
715 cs == null ? null : cs.getInstance(this, sg));
718 sg.getGroupColourScheme().alignmentChanged(sg,
726 public ColourSchemeI getGlobalColourScheme()
728 return residueShading == null ? null : residueShading.getColourScheme();
732 public ResidueShaderI getResidueShading()
734 return residueShading;
738 protected AlignmentAnnotation consensus;
740 protected AlignmentAnnotation complementConsensus;
742 protected AlignmentAnnotation gapcounts;
744 protected AlignmentAnnotation strucConsensus;
746 protected AlignmentAnnotation conservation;
748 protected AlignmentAnnotation quality;
750 protected AlignmentAnnotation[] groupConsensus;
752 protected AlignmentAnnotation[] groupConservation;
755 * results of alignment consensus analysis for visible portion of view
757 protected ProfilesI hconsensus = null;
760 * results of cDNA complement consensus visible portion of view
762 protected Hashtable<String, Object>[] hcomplementConsensus = null;
765 * results of secondary structure base pair consensus for visible portion of
768 protected Hashtable<String, Object>[] hStrucConsensus = null;
770 protected Conservation hconservation = null;
774 public void setConservation(Conservation cons)
776 hconservation = cons;
780 * percentage gaps allowed in a column before all amino acid properties should
781 * be considered unconserved
783 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
786 public int getConsPercGaps()
792 public void setSequenceConsensusHash(ProfilesI hconsensus)
794 this.hconsensus = hconsensus;
798 public void setComplementConsensusHash(
799 Hashtable<String, Object>[] hconsensus)
801 this.hcomplementConsensus = hconsensus;
805 public ProfilesI getSequenceConsensusHash()
811 public void setHmmProfiles(ProfilesI info)
817 public ProfilesI getHmmProfiles()
823 public Hashtable<String, Object>[] getComplementConsensusHash()
825 return hcomplementConsensus;
829 public Hashtable<String, Object>[] getRnaStructureConsensusHash()
831 return hStrucConsensus;
835 public void setRnaStructureConsensusHash(
836 Hashtable<String, Object>[] hStrucConsensus)
838 this.hStrucConsensus = hStrucConsensus;
843 public AlignmentAnnotation getAlignmentQualityAnnot()
849 public AlignmentAnnotation getAlignmentConservationAnnotation()
855 public AlignmentAnnotation getAlignmentConsensusAnnotation()
861 public AlignmentAnnotation getAlignmentGapAnnotation()
867 public AlignmentAnnotation getComplementConsensusAnnotation()
869 return complementConsensus;
873 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
875 return strucConsensus;
878 protected AlignCalcManagerI2 calculator = new AlignCalcManager2();
881 * trigger update of conservation annotation
883 public void updateConservation(final AlignmentViewPanel ap)
885 // see note in mantis : issue number 8585
886 if (alignment.isNucleotide()
887 || (conservation == null && quality == null)
888 || !autoCalculateConsensusAndConservation)
892 if (calculator.getWorkersOfClass(
893 jalview.workers.ConservationThread.class).isEmpty())
895 calculator.registerWorker(
896 new jalview.workers.ConservationThread(this, ap));
901 * trigger update of consensus annotation
903 public void updateConsensus(final AlignmentViewPanel ap)
905 // see note in mantis : issue number 8585
906 if (consensus == null || !autoCalculateConsensusAndConservation)
910 if (calculator.getWorkersOfClass(ConsensusThread.class).isEmpty())
912 calculator.registerWorker(new ConsensusThread(this, ap));
916 * A separate thread to compute cDNA consensus for a protein alignment
917 * which has mapping to cDNA
919 final AlignmentI al = this.getAlignment();
920 if (!al.isNucleotide() && al.getCodonFrames() != null
921 && !al.getCodonFrames().isEmpty())
924 * fudge - check first for protein-to-nucleotide mappings
925 * (we don't want to do this for protein-to-protein)
927 boolean doConsensus = false;
928 for (AlignedCodonFrame mapping : al.getCodonFrames())
930 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
931 MapList[] mapLists = mapping.getdnaToProt();
932 // mapLists can be empty if project load has not finished resolving seqs
933 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
941 if (calculator.getWorkersOfClass(ComplementConsensusThread.class).isEmpty())
943 calculator.registerWorker(new ComplementConsensusThread(this, ap));
950 public void initInformationWorker(final AlignmentViewPanel ap)
952 if (calculator.getWorkersOfClass(InformationThread.class).isEmpty())
954 calculator.registerWorker(new InformationThread(this, ap));
957 // --------START Structure Conservation
958 public void updateStrucConsensus(final AlignmentViewPanel ap)
960 if (autoCalculateStrucConsensus && strucConsensus == null
961 && alignment.isNucleotide() && alignment.hasRNAStructure())
963 // secondary structure has been added - so init the consensus line
967 // see note in mantis : issue number 8585
968 if (strucConsensus == null || !autoCalculateStrucConsensus)
972 if (calculator.getWorkersOfClass(StrucConsensusThread.class).isEmpty())
974 calculator.registerWorker(new StrucConsensusThread(this, ap));
978 public boolean isCalcInProgress()
980 return calculator.isWorking();
984 public boolean isCalculationInProgress(
985 AlignmentAnnotation alignmentAnnotation)
987 if (!alignmentAnnotation.autoCalculated)
991 if (calculator.isWorkingWithAnnotation(alignmentAnnotation))
993 // System.err.println("grey out ("+alignmentAnnotation.label+")");
999 private PollingTaskExecutor wsExecutor = new PollingTaskExecutor();
1001 public PollingTaskExecutor getWSExecutor()
1006 public void setAlignment(AlignmentI align)
1008 this.alignment = align;
1012 * Clean up references when this viewport is closed
1015 public void dispose()
1018 * defensively null out references to large objects in case
1019 * this object is not garbage collected (as if!)
1022 complementConsensus = null;
1023 strucConsensus = null;
1024 conservation = null;
1026 consensusProfiles = null;
1027 groupConsensus = null;
1028 groupConservation = null;
1030 hconservation = null;
1031 hcomplementConsensus = null;
1033 calculator.shutdown();
1035 wsExecutor.shutdown();
1037 residueShading = null; // may hold a reference to Consensus
1038 changeSupport = null;
1041 selectionGroup = null;
1047 public boolean isClosed()
1049 // TODO: check that this isClosed is only true after panel is closed, not
1050 // before it is fully constructed.
1051 return alignment == null;
1055 public AlignCalcManagerI2 getCalcManager()
1061 * should conservation rows be shown for groups
1063 protected boolean showGroupConservation = false;
1066 * should consensus rows be shown for groups
1068 protected boolean showGroupConsensus = false;
1071 * should consensus profile be rendered by default
1073 protected boolean showSequenceLogo = false;
1076 * should consensus profile be rendered normalised to row height
1078 protected boolean normaliseSequenceLogo = false;
1081 * should consensus histograms be rendered by default
1083 protected boolean showConsensusHistogram = true;
1086 * should hmm profile be rendered by default
1088 protected boolean hmmShowSequenceLogo = false;
1091 * should hmm profile be rendered normalised to row height
1093 protected boolean hmmNormaliseSequenceLogo = false;
1096 * should information histograms be rendered by default
1098 protected boolean hmmShowHistogram = true;
1101 * @return the showConsensusProfile
1104 public boolean isShowSequenceLogo()
1106 return showSequenceLogo;
1110 * @return the showInformationProfile
1113 public boolean isShowHMMSequenceLogo()
1115 return hmmShowSequenceLogo;
1119 * @param showSequenceLogo
1122 public void setShowSequenceLogo(boolean showSequenceLogo)
1124 if (showSequenceLogo != this.showSequenceLogo)
1126 // TODO: decouple settings setting from calculation when refactoring
1127 // annotation update method from alignframe to viewport
1128 this.showSequenceLogo = showSequenceLogo;
1129 for (AlignCalcWorkerI worker : calculator.getWorkers())
1131 if (worker.getClass().equals(ConsensusThread.class) ||
1132 worker.getClass().equals(ComplementConsensusThread.class) ||
1133 worker.getClass().equals(StrucConsensusThread.class))
1135 worker.updateAnnotation();
1139 this.showSequenceLogo = showSequenceLogo;
1142 public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo)
1144 if (showHMMSequenceLogo != this.hmmShowSequenceLogo)
1146 this.hmmShowSequenceLogo = showHMMSequenceLogo;
1147 // TODO: updateAnnotation if description (tooltip) will show
1148 // profile in place of information content?
1149 // calculator.updateAnnotationFor(InformationThread.class);
1151 this.hmmShowSequenceLogo = showHMMSequenceLogo;
1154 * @param showConsensusHistogram
1155 * the showConsensusHistogram to set
1157 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1159 this.showConsensusHistogram = showConsensusHistogram;
1163 * @param showInformationHistogram
1165 public void setShowInformationHistogram(boolean showInformationHistogram)
1167 this.hmmShowHistogram = showInformationHistogram;
1171 * @return the showGroupConservation
1173 public boolean isShowGroupConservation()
1175 return showGroupConservation;
1179 * @param showGroupConservation
1180 * the showGroupConservation to set
1182 public void setShowGroupConservation(boolean showGroupConservation)
1184 this.showGroupConservation = showGroupConservation;
1188 * @return the showGroupConsensus
1190 public boolean isShowGroupConsensus()
1192 return showGroupConsensus;
1196 * @param showGroupConsensus
1197 * the showGroupConsensus to set
1199 public void setShowGroupConsensus(boolean showGroupConsensus)
1201 this.showGroupConsensus = showGroupConsensus;
1206 * @return flag to indicate if the consensus histogram should be rendered by
1210 public boolean isShowConsensusHistogram()
1212 return this.showConsensusHistogram;
1217 * @return flag to indicate if the information content histogram should be
1218 * rendered by default
1221 public boolean isShowInformationHistogram()
1223 return this.hmmShowHistogram;
1227 * when set, updateAlignment will always ensure sequences are of equal length
1229 private boolean padGaps = false;
1232 * when set, alignment should be reordered according to a newly opened tree
1234 public boolean sortByTree = false;
1239 * @return null or the currently selected sequence region
1242 public SequenceGroup getSelectionGroup()
1244 return selectionGroup;
1248 * Set the selection group for this window. Also sets the current alignment as
1249 * the context for the group, if it does not already have one.
1252 * - group holding references to sequences in this alignment view
1256 public void setSelectionGroup(SequenceGroup sg)
1258 selectionGroup = sg;
1259 if (sg != null && sg.getContext() == null)
1261 sg.setContext(alignment);
1265 public void setHiddenColumns(HiddenColumns hidden)
1267 this.alignment.setHiddenColumns(hidden);
1271 public ColumnSelection getColumnSelection()
1277 public void setColumnSelection(ColumnSelection colSel)
1279 this.colSel = colSel;
1282 updateHiddenColumns();
1284 isColSelChanged(true);
1292 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1294 return hiddenRepSequences;
1298 public void setHiddenRepSequences(
1299 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1301 this.hiddenRepSequences = hiddenRepSequences;
1305 public boolean hasSelectedColumns()
1307 ColumnSelection columnSelection = getColumnSelection();
1308 return columnSelection != null && columnSelection.hasSelectedColumns();
1312 public boolean hasHiddenColumns()
1314 return alignment.getHiddenColumns() != null
1315 && alignment.getHiddenColumns().hasHiddenColumns();
1318 public void updateHiddenColumns()
1320 // this method doesn't really do anything now. But - it could, since a
1321 // column Selection could be in the process of modification
1322 // hasHiddenColumns = colSel.hasHiddenColumns();
1326 public boolean hasHiddenRows()
1328 return alignment.getHiddenSequences().getSize() > 0;
1331 protected SequenceGroup selectionGroup;
1333 public void setSequenceSetId(String newid)
1335 if (sequenceSetID != null)
1338 "Warning - overwriting a sequenceSetId for a viewport!");
1340 sequenceSetID = new String(newid);
1344 public String getSequenceSetId()
1346 if (sequenceSetID == null)
1348 sequenceSetID = alignment.hashCode() + "";
1351 return sequenceSetID;
1355 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1358 protected String viewId = null;
1361 public String getViewId()
1365 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1370 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1372 ignoreGapsInConsensusCalculation = b;
1375 updateConsensus(ap);
1376 if (residueShading != null)
1378 residueShading.setThreshold(residueShading.getThreshold(),
1379 ignoreGapsInConsensusCalculation);
1384 public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap)
1386 ignoreBelowBackGroundFrequencyCalculation = b;
1389 public void setInfoLetterHeight(boolean b, AlignmentViewPanel ap)
1391 infoLetterHeight = b;
1394 private long sgrouphash = -1, colselhash = -1;
1397 * checks current SelectionGroup against record of last hash value, and
1401 * update the record of last hash value
1403 * @return true if SelectionGroup changed since last call (when b is true)
1405 public boolean isSelectionGroupChanged(boolean b)
1407 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1408 : selectionGroup.hashCode();
1409 if (hc != -1 && hc != sgrouphash)
1421 * checks current colsel against record of last hash value, and optionally
1425 * update the record of last hash value
1426 * @return true if colsel changed since last call (when b is true)
1428 public boolean isColSelChanged(boolean updateHash)
1430 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1431 if (hc != -1 && hc != colselhash)
1444 public boolean isIgnoreGapsConsensus()
1446 return ignoreGapsInConsensusCalculation;
1450 public boolean isIgnoreBelowBackground()
1452 return ignoreBelowBackGroundFrequencyCalculation;
1456 public boolean isInfoLetterHeight()
1458 return infoLetterHeight;
1460 // property change stuff
1461 // JBPNote Prolly only need this in the applet version.
1462 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1465 protected boolean showConservation = true;
1467 protected boolean showQuality = true;
1469 protected boolean showConsensus = true;
1471 protected boolean showOccupancy = true;
1473 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1475 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1477 protected boolean showAutocalculatedAbove;
1480 * when set, view will scroll to show the highlighted position
1482 private boolean followHighlight = true;
1485 * Property change listener for changes in alignment
1490 public void addPropertyChangeListener(
1491 java.beans.PropertyChangeListener listener)
1493 changeSupport.addPropertyChangeListener(listener);
1502 public void removePropertyChangeListener(
1503 java.beans.PropertyChangeListener listener)
1505 if (changeSupport != null)
1507 changeSupport.removePropertyChangeListener(listener);
1512 // common hide/show column stuff
1514 public void hideSelectedColumns()
1516 if (colSel.isEmpty())
1521 colSel.hideSelectedColumns(alignment);
1522 setSelectionGroup(null);
1523 isColSelChanged(true);
1526 public void hideColumns(int start, int end)
1530 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1534 alignment.getHiddenColumns().hideColumns(start, end);
1536 isColSelChanged(true);
1539 public void showColumn(int col)
1541 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1542 isColSelChanged(true);
1545 public void showAllHiddenColumns()
1547 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1548 isColSelChanged(true);
1551 // common hide/show seq stuff
1552 public void showAllHiddenSeqs()
1554 int startSeq = ranges.getStartSeq();
1555 int endSeq = ranges.getEndSeq();
1557 if (alignment.getHiddenSequences().getSize() > 0)
1559 if (selectionGroup == null)
1561 selectionGroup = new SequenceGroup();
1562 selectionGroup.setEndRes(alignment.getWidth() - 1);
1564 List<SequenceI> tmp = alignment.getHiddenSequences()
1565 .showAll(hiddenRepSequences);
1566 for (SequenceI seq : tmp)
1568 selectionGroup.addSequence(seq, false);
1569 setSequenceAnnotationsVisible(seq, true);
1572 hiddenRepSequences = null;
1574 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1576 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1583 public void showSequence(int index)
1585 int startSeq = ranges.getStartSeq();
1586 int endSeq = ranges.getEndSeq();
1588 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1589 hiddenRepSequences);
1592 if (selectionGroup == null)
1594 selectionGroup = new SequenceGroup();
1595 selectionGroup.setEndRes(alignment.getWidth() - 1);
1598 for (SequenceI seq : tmp)
1600 selectionGroup.addSequence(seq, false);
1601 setSequenceAnnotationsVisible(seq, true);
1604 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1611 public void hideAllSelectedSeqs()
1613 if (selectionGroup == null || selectionGroup.getSize() < 1)
1618 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1622 setSelectionGroup(null);
1625 public void hideSequence(SequenceI[] seq)
1628 * cache offset to first visible sequence
1630 int startSeq = ranges.getStartSeq();
1634 for (int i = 0; i < seq.length; i++)
1636 alignment.getHiddenSequences().hideSequence(seq[i]);
1637 setSequenceAnnotationsVisible(seq[i], false);
1639 ranges.setStartSeq(startSeq);
1645 * Hides the specified sequence, or the sequences it represents
1648 * the sequence to hide, or keep as representative
1649 * @param representGroup
1650 * if true, hide the current selection group except for the
1651 * representative sequence
1653 public void hideSequences(SequenceI sequence, boolean representGroup)
1655 if (selectionGroup == null || selectionGroup.getSize() < 1)
1657 hideSequence(new SequenceI[] { sequence });
1663 hideRepSequences(sequence, selectionGroup);
1664 setSelectionGroup(null);
1668 int gsize = selectionGroup.getSize();
1669 SequenceI[] hseqs = selectionGroup.getSequences()
1670 .toArray(new SequenceI[gsize]);
1672 hideSequence(hseqs);
1673 setSelectionGroup(null);
1678 * Set visibility for any annotations for the given sequence.
1682 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1685 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1688 for (AlignmentAnnotation ann : anns)
1690 if (ann.sequenceRef == sequenceI)
1692 ann.visible = visible;
1698 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1700 int sSize = sg.getSize();
1706 if (hiddenRepSequences == null)
1708 hiddenRepSequences = new Hashtable<>();
1711 hiddenRepSequences.put(repSequence, sg);
1713 // Hide all sequences except the repSequence
1714 SequenceI[] seqs = new SequenceI[sSize - 1];
1716 for (int i = 0; i < sSize; i++)
1718 if (sg.getSequenceAt(i) != repSequence)
1720 if (index == sSize - 1)
1725 seqs[index++] = sg.getSequenceAt(i);
1728 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1729 sg.setHidereps(true); // note: not done in 2.7applet
1736 * @return null or the current reference sequence
1738 public SequenceI getReferenceSeq()
1740 return alignment.getSeqrep();
1745 * @return true iff seq is the reference for the alignment
1747 public boolean isReferenceSeq(SequenceI seq)
1749 return alignment.getSeqrep() == seq;
1755 * @return true if there are sequences represented by this sequence that are
1758 public boolean isHiddenRepSequence(SequenceI seq)
1760 return (hiddenRepSequences != null
1761 && hiddenRepSequences.containsKey(seq));
1767 * @return null or a sequence group containing the sequences that seq
1770 public SequenceGroup getRepresentedSequences(SequenceI seq)
1772 return (SequenceGroup) (hiddenRepSequences == null ? null
1773 : hiddenRepSequences.get(seq));
1777 public int adjustForHiddenSeqs(int alignmentIndex)
1779 return alignment.getHiddenSequences()
1780 .adjustForHiddenSeqs(alignmentIndex);
1784 public void invertColumnSelection()
1786 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1787 isColSelChanged(true);
1791 public SequenceI[] getSelectionAsNewSequence()
1793 SequenceI[] sequences;
1794 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1795 // this was the only caller in the applet for this method
1796 // JBPNote: in applet, this method returned references to the alignment
1797 // sequences, and it did not honour the presence/absence of annotation
1798 // attached to the alignment (probably!)
1799 if (selectionGroup == null || selectionGroup.getSize() == 0)
1801 sequences = alignment.getSequencesArray();
1802 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1803 for (int i = 0; i < sequences.length; i++)
1805 // construct new sequence with subset of visible annotation
1806 sequences[i] = new Sequence(sequences[i], annots);
1811 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1818 public SequenceI[] getSequenceSelection()
1820 SequenceI[] sequences = null;
1821 if (selectionGroup != null)
1823 sequences = selectionGroup.getSequencesInOrder(alignment);
1825 if (sequences == null)
1827 sequences = alignment.getSequencesArray();
1833 public jalview.datamodel.AlignmentView getAlignmentView(
1834 boolean selectedOnly)
1836 return getAlignmentView(selectedOnly, false);
1840 public jalview.datamodel.AlignmentView getAlignmentView(
1841 boolean selectedOnly, boolean markGroups)
1843 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1845 alignment.getHiddenColumns() != null
1846 && alignment.getHiddenColumns().hasHiddenColumns(),
1847 selectedOnly, markGroups);
1851 public String[] getViewAsString(boolean selectedRegionOnly)
1853 return getViewAsString(selectedRegionOnly, true);
1857 public String[] getViewAsString(boolean selectedRegionOnly,
1858 boolean exportHiddenSeqs)
1860 String[] selection = null;
1861 SequenceI[] seqs = null;
1863 int start = 0, end = 0;
1864 if (selectedRegionOnly && selectionGroup != null)
1866 iSize = selectionGroup.getSize();
1867 seqs = selectionGroup.getSequencesInOrder(alignment);
1868 start = selectionGroup.getStartRes();
1869 end = selectionGroup.getEndRes() + 1;
1873 if (hasHiddenRows() && exportHiddenSeqs)
1875 AlignmentI fullAlignment = alignment.getHiddenSequences()
1876 .getFullAlignment();
1877 iSize = fullAlignment.getHeight();
1878 seqs = fullAlignment.getSequencesArray();
1879 end = fullAlignment.getWidth();
1883 iSize = alignment.getHeight();
1884 seqs = alignment.getSequencesArray();
1885 end = alignment.getWidth();
1889 selection = new String[iSize];
1890 if (alignment.getHiddenColumns() != null
1891 && alignment.getHiddenColumns().hasHiddenColumns())
1893 for (i = 0; i < iSize; i++)
1895 Iterator<int[]> blocks = alignment.getHiddenColumns()
1896 .getVisContigsIterator(start, end + 1, false);
1897 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1902 for (i = 0; i < iSize; i++)
1904 selection[i] = seqs[i].getSequenceAsString(start, end);
1912 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1914 ArrayList<int[]> regions = new ArrayList<>();
1920 HiddenColumns hidden = alignment.getHiddenColumns();
1921 if (hidden != null && hidden.hasHiddenColumns())
1925 start = hidden.visibleToAbsoluteColumn(start);
1928 end = hidden.getNextHiddenBoundary(false, start);
1939 regions.add(new int[] { start, end });
1941 if (hidden != null && hidden.hasHiddenColumns())
1943 start = hidden.visibleToAbsoluteColumn(end);
1944 start = hidden.getNextHiddenBoundary(true, start) + 1;
1946 } while (end < max);
1948 // int[][] startEnd = new int[regions.size()][2];
1954 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1955 boolean selectedOnly)
1957 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1958 AlignmentAnnotation[] aa;
1959 if ((aa = alignment.getAlignmentAnnotation()) != null)
1961 for (AlignmentAnnotation annot : aa)
1963 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1964 if (selectedOnly && selectionGroup != null)
1966 clone.makeVisibleAnnotation(
1967 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1968 alignment.getHiddenColumns());
1972 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1981 public boolean isPadGaps()
1987 public void setPadGaps(boolean padGaps)
1989 this.padGaps = padGaps;
1993 * apply any post-edit constraints and trigger any calculations needed after
1994 * an edit has been performed on the alignment
1999 public void alignmentChanged(AlignmentViewPanel ap)
2003 alignment.padGaps();
2005 if (autoCalculateConsensusAndConservation)
2007 updateConsensus(ap);
2009 if (hconsensus != null && autoCalculateConsensusAndConservation)
2011 updateConservation(ap);
2013 if (autoCalculateStrucConsensus)
2015 updateStrucConsensus(ap);
2018 // Reset endRes of groups if beyond alignment width
2019 int alWidth = alignment.getWidth();
2020 List<SequenceGroup> groups = alignment.getGroups();
2023 for (SequenceGroup sg : groups)
2025 if (sg.getEndRes() > alWidth)
2027 sg.setEndRes(alWidth - 1);
2032 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
2034 selectionGroup.setEndRes(alWidth - 1);
2037 updateAllColourSchemes();
2038 calculator.restartWorkers();
2042 * reset scope and do calculations for all applied colourschemes on alignment
2044 void updateAllColourSchemes()
2046 ResidueShaderI rs = residueShading;
2049 rs.alignmentChanged(alignment, hiddenRepSequences);
2051 rs.setConsensus(hconsensus);
2052 if (rs.conservationApplied())
2054 rs.setConservation(Conservation.calculateConservation("All",
2055 alignment.getSequences(), 0, alignment.getWidth(), false,
2056 getConsPercGaps(), false));
2060 for (SequenceGroup sg : alignment.getGroups())
2064 sg.cs.alignmentChanged(sg, hiddenRepSequences);
2066 sg.recalcConservation();
2070 protected void initAutoAnnotation()
2072 // TODO: add menu option action that nulls or creates consensus object
2073 // depending on if the user wants to see the annotation or not in a
2074 // specific alignment
2076 if (hconsensus == null && !isDataset)
2078 if (!alignment.isNucleotide())
2087 consensus = new AlignmentAnnotation("Consensus",
2088 MessageManager.getString("label.consensus_descr"),
2089 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2090 initConsensus(consensus);
2093 initComplementConsensus();
2098 * If this is a protein alignment and there are mappings to cDNA, adds the
2099 * cDNA consensus annotation and returns true, else returns false.
2101 public boolean initComplementConsensus()
2103 if (!alignment.isNucleotide())
2105 final List<AlignedCodonFrame> codonMappings = alignment
2107 if (codonMappings != null && !codonMappings.isEmpty())
2109 boolean doConsensus = false;
2110 for (AlignedCodonFrame mapping : codonMappings)
2112 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2113 MapList[] mapLists = mapping.getdnaToProt();
2114 // mapLists can be empty if project load has not finished resolving
2116 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2124 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2126 .getString("label.complement_consensus_descr"),
2127 new Annotation[1], 0f, 100f,
2128 AlignmentAnnotation.BAR_GRAPH);
2129 initConsensus(complementConsensus);
2137 private void initConsensus(AlignmentAnnotation aa)
2140 aa.autoCalculated = true;
2144 alignment.addAnnotation(aa);
2148 // these should be extracted from the view model - style and settings for
2149 // derived annotation
2150 private void initGapCounts()
2154 gapcounts = new AlignmentAnnotation("Occupancy",
2155 MessageManager.getString("label.occupancy_descr"),
2156 new Annotation[1], 0f, alignment.getHeight(),
2157 AlignmentAnnotation.BAR_GRAPH);
2158 gapcounts.hasText = true;
2159 gapcounts.autoCalculated = true;
2160 gapcounts.scaleColLabel = true;
2161 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2163 alignment.addAnnotation(gapcounts);
2167 private void initConservation()
2169 if (showConservation)
2171 if (conservation == null)
2173 conservation = new AlignmentAnnotation("Conservation",
2174 MessageManager.formatMessage("label.conservation_descr",
2176 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2177 conservation.hasText = true;
2178 conservation.autoCalculated = true;
2179 alignment.addAnnotation(conservation);
2184 private void initQuality()
2188 if (quality == null)
2190 quality = new AlignmentAnnotation("Quality",
2191 MessageManager.getString("label.quality_descr"),
2192 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2193 quality.hasText = true;
2194 quality.autoCalculated = true;
2195 alignment.addAnnotation(quality);
2200 private void initRNAStructure()
2202 if (alignment.hasRNAStructure() && strucConsensus == null)
2204 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2205 MessageManager.getString("label.strucconsensus_descr"),
2206 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2207 strucConsensus.hasText = true;
2208 strucConsensus.autoCalculated = true;
2212 alignment.addAnnotation(strucConsensus);
2220 * @see jalview.api.AlignViewportI#calcPanelHeight()
2223 public int calcPanelHeight()
2225 // setHeight of panels
2226 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2228 int charHeight = getCharHeight();
2231 BitSet graphgrp = new BitSet();
2232 for (AlignmentAnnotation aa : anns)
2236 System.err.println("Null annotation row: ignoring.");
2243 if (aa.graphGroup > -1)
2245 if (graphgrp.get(aa.graphGroup))
2251 graphgrp.set(aa.graphGroup);
2258 aa.height += charHeight;
2268 aa.height += aa.graphHeight;
2276 height += aa.height;
2288 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2289 boolean preserveNewGroupSettings)
2291 boolean updateCalcs = false;
2292 boolean conv = isShowGroupConservation();
2293 boolean cons = isShowGroupConsensus();
2294 boolean showprf = isShowSequenceLogo();
2295 boolean showConsHist = isShowConsensusHistogram();
2296 boolean normLogo = isNormaliseSequenceLogo();
2297 boolean showHMMPrf = isShowHMMSequenceLogo();
2298 boolean showInfoHist = isShowInformationHistogram();
2299 boolean normHMMLogo = isNormaliseHMMSequenceLogo();
2302 * TODO reorder the annotation rows according to group/sequence ordering on
2305 // boolean sortg = true;
2307 // remove old automatic annotation
2308 // add any new annotation
2310 // intersect alignment annotation with alignment groups
2312 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2313 List<SequenceGroup> oldrfs = new ArrayList<>();
2316 for (int an = 0; an < aan.length; an++)
2318 if (aan[an].autoCalculated && aan[an].groupRef != null)
2320 oldrfs.add(aan[an].groupRef);
2321 alignment.deleteAnnotation(aan[an], false);
2325 if (alignment.getGroups() != null)
2327 for (SequenceGroup sg : alignment.getGroups())
2329 updateCalcs = false;
2330 if (applyGlobalSettings
2331 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2333 // set defaults for this group's conservation/consensus
2334 sg.setshowSequenceLogo(showprf);
2335 sg.setShowConsensusHistogram(showConsHist);
2336 sg.setNormaliseSequenceLogo(normLogo);
2337 sg.setShowHMMSequenceLogo(showHMMPrf);
2338 sg.setShowInformationHistogram(showInfoHist);
2339 sg.setNormaliseHMMSequenceLogo(normHMMLogo);
2344 alignment.addAnnotation(sg.getConservationRow(), 0);
2349 alignment.addAnnotation(sg.getConsensus(), 0);
2351 // refresh the annotation rows
2354 sg.recalcConservation();
2362 public boolean isDisplayReferenceSeq()
2364 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2368 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2370 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2374 public boolean isColourByReferenceSeq()
2376 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2380 public Color getSequenceColour(SequenceI seq)
2382 Color sqc = sequenceColours.get(seq);
2383 return (sqc == null ? Color.white : sqc);
2387 public void setSequenceColour(SequenceI seq, Color col)
2391 sequenceColours.remove(seq);
2395 sequenceColours.put(seq, col);
2400 public void updateSequenceIdColours()
2402 for (SequenceGroup sg : alignment.getGroups())
2404 if (sg.idColour != null)
2406 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2408 sequenceColours.put(s, sg.idColour);
2415 public void clearSequenceColours()
2417 sequenceColours.clear();
2421 public AlignViewportI getCodingComplement()
2423 return this.codingComplement;
2427 * Set this as the (cDna/protein) complement of the given viewport. Also
2428 * ensures the reverse relationship is set on the given viewport.
2431 public void setCodingComplement(AlignViewportI av)
2435 System.err.println("Ignoring recursive setCodingComplement request");
2439 this.codingComplement = av;
2440 // avoid infinite recursion!
2441 if (av.getCodingComplement() != this)
2443 av.setCodingComplement(this);
2449 public boolean isNucleotide()
2451 return getAlignment() == null ? false : getAlignment().isNucleotide();
2455 public FeaturesDisplayedI getFeaturesDisplayed()
2457 return featuresDisplayed;
2461 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2463 featuresDisplayed = featuresDisplayedI;
2467 public boolean areFeaturesDisplayed()
2469 return featuresDisplayed != null
2470 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2477 * features are displayed if true
2480 public void setShowSequenceFeatures(boolean b)
2482 viewStyle.setShowSequenceFeatures(b);
2486 public boolean isShowSequenceFeatures()
2488 return viewStyle.isShowSequenceFeatures();
2492 public void setShowSequenceFeaturesHeight(boolean selected)
2494 viewStyle.setShowSequenceFeaturesHeight(selected);
2498 public boolean isShowSequenceFeaturesHeight()
2500 return viewStyle.isShowSequenceFeaturesHeight();
2504 public void setShowAnnotation(boolean b)
2506 viewStyle.setShowAnnotation(b);
2510 public boolean isShowAnnotation()
2512 return viewStyle.isShowAnnotation();
2516 public boolean isRightAlignIds()
2518 return viewStyle.isRightAlignIds();
2522 public void setRightAlignIds(boolean rightAlignIds)
2524 viewStyle.setRightAlignIds(rightAlignIds);
2528 public boolean getConservationSelected()
2530 return viewStyle.getConservationSelected();
2534 public void setShowBoxes(boolean state)
2536 viewStyle.setShowBoxes(state);
2541 * @see jalview.api.ViewStyleI#getTextColour()
2544 public Color getTextColour()
2546 return viewStyle.getTextColour();
2551 * @see jalview.api.ViewStyleI#getTextColour2()
2554 public Color getTextColour2()
2556 return viewStyle.getTextColour2();
2561 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2564 public int getThresholdTextColour()
2566 return viewStyle.getThresholdTextColour();
2571 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2574 public boolean isConservationColourSelected()
2576 return viewStyle.isConservationColourSelected();
2581 * @see jalview.api.ViewStyleI#isRenderGaps()
2584 public boolean isRenderGaps()
2586 return viewStyle.isRenderGaps();
2591 * @see jalview.api.ViewStyleI#isShowColourText()
2594 public boolean isShowColourText()
2596 return viewStyle.isShowColourText();
2600 * @param conservationColourSelected
2601 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2604 public void setConservationColourSelected(
2605 boolean conservationColourSelected)
2607 viewStyle.setConservationColourSelected(conservationColourSelected);
2611 * @param showColourText
2612 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2615 public void setShowColourText(boolean showColourText)
2617 viewStyle.setShowColourText(showColourText);
2622 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2625 public void setTextColour(Color textColour)
2627 viewStyle.setTextColour(textColour);
2631 * @param thresholdTextColour
2632 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2635 public void setThresholdTextColour(int thresholdTextColour)
2637 viewStyle.setThresholdTextColour(thresholdTextColour);
2641 * @param textColour2
2642 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2645 public void setTextColour2(Color textColour2)
2647 viewStyle.setTextColour2(textColour2);
2651 public ViewStyleI getViewStyle()
2653 return new ViewStyle(viewStyle);
2657 public void setViewStyle(ViewStyleI settingsForView)
2659 viewStyle = new ViewStyle(settingsForView);
2660 if (residueShading != null)
2662 residueShading.setConservationApplied(
2663 settingsForView.isConservationColourSelected());
2668 public boolean sameStyle(ViewStyleI them)
2670 return viewStyle.sameStyle(them);
2675 * @see jalview.api.ViewStyleI#getIdWidth()
2678 public int getIdWidth()
2680 return viewStyle.getIdWidth();
2685 * @see jalview.api.ViewStyleI#setIdWidth(int)
2688 public void setIdWidth(int i)
2690 viewStyle.setIdWidth(i);
2695 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2698 public boolean isCentreColumnLabels()
2700 return viewStyle.isCentreColumnLabels();
2704 * @param centreColumnLabels
2705 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2708 public void setCentreColumnLabels(boolean centreColumnLabels)
2710 viewStyle.setCentreColumnLabels(centreColumnLabels);
2715 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2718 public void setShowDBRefs(boolean showdbrefs)
2720 viewStyle.setShowDBRefs(showdbrefs);
2725 * @see jalview.api.ViewStyleI#isShowDBRefs()
2728 public boolean isShowDBRefs()
2730 return viewStyle.isShowDBRefs();
2735 * @see jalview.api.ViewStyleI#isShowNPFeats()
2738 public boolean isShowNPFeats()
2740 return viewStyle.isShowNPFeats();
2744 * @param shownpfeats
2745 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2748 public void setShowNPFeats(boolean shownpfeats)
2750 viewStyle.setShowNPFeats(shownpfeats);
2753 public abstract StructureSelectionManager getStructureSelectionManager();
2756 * Add one command to the command history list.
2760 public void addToHistoryList(CommandI command)
2762 if (this.historyList != null)
2764 this.historyList.push(command);
2765 broadcastCommand(command, false);
2769 protected void broadcastCommand(CommandI command, boolean undo)
2771 getStructureSelectionManager().commandPerformed(command, undo,
2776 * Add one command to the command redo list.
2780 public void addToRedoList(CommandI command)
2782 if (this.redoList != null)
2784 this.redoList.push(command);
2786 broadcastCommand(command, true);
2790 * Clear the command redo list.
2792 public void clearRedoList()
2794 if (this.redoList != null)
2796 this.redoList.clear();
2800 public void setHistoryList(Deque<CommandI> list)
2802 this.historyList = list;
2805 public Deque<CommandI> getHistoryList()
2807 return this.historyList;
2810 public void setRedoList(Deque<CommandI> list)
2812 this.redoList = list;
2815 public Deque<CommandI> getRedoList()
2817 return this.redoList;
2821 public VamsasSource getVamsasSource()
2826 public SequenceAnnotationOrder getSortAnnotationsBy()
2828 return sortAnnotationsBy;
2831 public void setSortAnnotationsBy(
2832 SequenceAnnotationOrder sortAnnotationsBy)
2834 this.sortAnnotationsBy = sortAnnotationsBy;
2837 public boolean isShowAutocalculatedAbove()
2839 return showAutocalculatedAbove;
2842 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2844 this.showAutocalculatedAbove = showAutocalculatedAbove;
2848 public boolean isScaleProteinAsCdna()
2850 return viewStyle.isScaleProteinAsCdna();
2854 public void setScaleProteinAsCdna(boolean b)
2856 viewStyle.setScaleProteinAsCdna(b);
2860 public boolean isProteinFontAsCdna()
2862 return viewStyle.isProteinFontAsCdna();
2866 public void setProteinFontAsCdna(boolean b)
2868 viewStyle.setProteinFontAsCdna(b);
2872 public void setShowComplementFeatures(boolean b)
2874 viewStyle.setShowComplementFeatures(b);
2878 public boolean isShowComplementFeatures()
2880 return viewStyle.isShowComplementFeatures();
2884 public void setShowComplementFeaturesOnTop(boolean b)
2886 viewStyle.setShowComplementFeaturesOnTop(b);
2890 public boolean isShowComplementFeaturesOnTop()
2892 return viewStyle.isShowComplementFeaturesOnTop();
2896 * @return true if view should scroll to show the highlighted region of a
2901 public final boolean isFollowHighlight()
2903 return followHighlight;
2907 public final void setFollowHighlight(boolean b)
2909 this.followHighlight = b;
2913 public ViewportRanges getRanges()
2919 * Helper method to populate the SearchResults with the location in the
2920 * complementary alignment to scroll to, in order to match this one.
2923 * the SearchResults to add to
2924 * @return the offset (below top of visible region) of the matched sequence
2926 protected int findComplementScrollTarget(SearchResultsI sr)
2928 final AlignViewportI complement = getCodingComplement();
2929 if (complement == null || !complement.isFollowHighlight())
2933 boolean iAmProtein = !getAlignment().isNucleotide();
2934 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2935 : complement.getAlignment();
2936 if (proteinAlignment == null)
2940 final List<AlignedCodonFrame> mappings = proteinAlignment
2944 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2945 * residue in the middle column of the visible region. Scroll the
2946 * complementary alignment to line up the corresponding residue.
2949 SequenceI sequence = null;
2952 * locate 'middle' column (true middle if an odd number visible, left of
2953 * middle if an even number visible)
2955 int middleColumn = ranges.getStartRes()
2956 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2957 final HiddenSequences hiddenSequences = getAlignment()
2958 .getHiddenSequences();
2961 * searching to the bottom of the alignment gives smoother scrolling across
2962 * all gapped visible regions
2964 int lastSeq = alignment.getHeight() - 1;
2965 List<AlignedCodonFrame> seqMappings = null;
2966 for (int seqNo = ranges
2967 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2969 sequence = getAlignment().getSequenceAt(seqNo);
2970 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2974 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2978 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2980 getCodingComplement().getAlignment().getSequences());
2981 if (!seqMappings.isEmpty())
2987 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2990 * No ungapped mapped sequence in middle column - do nothing
2994 MappingUtils.addSearchResults(sr, sequence,
2995 sequence.findPosition(middleColumn), seqMappings);
3000 * synthesize a column selection if none exists so it covers the given
3001 * selection group. if wholewidth is false, no column selection is made if the
3002 * selection group covers the whole alignment width.
3007 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
3010 if (sg != null && (sgs = sg.getStartRes()) >= 0
3011 && sg.getStartRes() <= (sge = sg.getEndRes())
3012 && !this.hasSelectedColumns())
3014 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
3021 colSel = new ColumnSelection();
3023 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
3025 colSel.addElement(cspos);
3031 * hold status of current selection group - defined on alignment or not.
3033 private boolean selectionIsDefinedGroup = false;
3036 public boolean isSelectionDefinedGroup()
3038 if (selectionGroup == null)
3042 if (isSelectionGroupChanged(true))
3044 selectionIsDefinedGroup = false;
3045 List<SequenceGroup> gps = alignment.getGroups();
3046 if (gps == null || gps.size() == 0)
3048 selectionIsDefinedGroup = false;
3052 selectionIsDefinedGroup = gps.contains(selectionGroup);
3055 return selectionGroup.isDefined() || selectionIsDefinedGroup;
3059 * null, or currently highlighted results on this view
3061 private SearchResultsI searchResults = null;
3063 protected TreeModel currentTree = null;
3066 public boolean hasSearchResults()
3068 return searchResults != null;
3072 public void setSearchResults(SearchResultsI results)
3074 searchResults = results;
3078 public SearchResultsI getSearchResults()
3080 return searchResults;
3084 * get the consensus sequence as displayed under the PID consensus annotation
3087 * @return consensus sequence as a new sequence object
3089 public SequenceI getConsensusSeq()
3091 if (consensus == null)
3093 updateConsensus(null);
3095 if (consensus == null)
3099 StringBuffer seqs = new StringBuffer();
3100 for (int i = 0; i < consensus.annotations.length; i++)
3102 Annotation annotation = consensus.annotations[i];
3103 if (annotation != null)
3105 String description = annotation.description;
3106 if (description != null && description.startsWith("["))
3108 // consensus is a tie - just pick the first one
3109 seqs.append(description.charAt(1));
3113 seqs.append(annotation.displayCharacter);
3118 SequenceI sq = new Sequence("Consensus", seqs.toString());
3119 sq.setDescription("Percentage Identity Consensus "
3120 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3124 public boolean hasReferenceAnnotation()
3126 AlignmentAnnotation[] annots = this.alignment.getAlignmentAnnotation();
3127 for (AlignmentAnnotation annot : annots)
3129 if ("RF".equals(annot.label) || annot.label.contains("Reference"))
3137 public void setCurrentTree(TreeModel tree)
3143 public TreeModel getCurrentTree()
3149 public AlignmentExportData getAlignExportData(AlignExportSettingsI options)
3151 AlignmentI alignmentToExport = null;
3152 String[] omitHidden = null;
3153 alignmentToExport = null;
3155 if (hasHiddenColumns() && !options.isExportHiddenColumns())
3157 omitHidden = getViewAsString(false,
3158 options.isExportHiddenSequences());
3161 int[] alignmentStartEnd = new int[2];
3162 if (hasHiddenRows() && options.isExportHiddenSequences())
3164 alignmentToExport = getAlignment().getHiddenSequences()
3165 .getFullAlignment();
3169 alignmentToExport = getAlignment();
3171 alignmentStartEnd = getAlignment().getHiddenColumns()
3172 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
3173 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
3174 omitHidden, alignmentStartEnd);
3179 public boolean isNormaliseSequenceLogo()
3181 return normaliseSequenceLogo;
3184 public void setNormaliseSequenceLogo(boolean state)
3186 normaliseSequenceLogo = state;
3190 public boolean isNormaliseHMMSequenceLogo()
3192 return hmmNormaliseSequenceLogo;
3195 public void setNormaliseHMMSequenceLogo(boolean state)
3197 hmmNormaliseSequenceLogo = state;
3200 * flag set to indicate if structure views might be out of sync with sequences
3204 private boolean needToUpdateStructureViews = false;
3207 public boolean isUpdateStructures()
3209 return needToUpdateStructureViews;
3213 public void setUpdateStructures(boolean update)
3215 needToUpdateStructureViews = update;
3219 public boolean needToUpdateStructureViews()
3221 boolean update = needToUpdateStructureViews;
3222 needToUpdateStructureViews = false;
3227 public void addSequenceGroup(SequenceGroup sequenceGroup)
3229 alignment.addGroup(sequenceGroup);
3231 Color col = sequenceGroup.idColour;
3234 col = col.brighter();
3236 for (SequenceI sq : sequenceGroup.getSequences())
3238 setSequenceColour(sq, col);
3242 if (codingComplement != null)
3244 SequenceGroup mappedGroup = MappingUtils
3245 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3246 if (mappedGroup.getSequences().size() > 0)
3248 codingComplement.getAlignment().addGroup(mappedGroup);
3252 for (SequenceI seq : mappedGroup.getSequences())
3254 codingComplement.setSequenceColour(seq, col);
3258 // propagate the structure view update flag according to our own setting
3259 codingComplement.setUpdateStructures(needToUpdateStructureViews);
3264 public Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly)
3268 if (selectedRegionOnly && selectionGroup != null)
3270 start = selectionGroup.getStartRes();
3271 end = selectionGroup.getEndRes() + 1;
3275 end = alignment.getWidth();
3277 return (alignment.getHiddenColumns().getVisContigsIterator(start, end,
3281 * Filters out sequences with an eValue higher than the specified value. The
3282 * filtered sequences are hidden or deleted. Sequences with no eValues are also
3288 public void filterByEvalue(double eValue)
3290 for (SequenceI seq : alignment.getSequencesArray())
3292 if ((seq.getAnnotation("Search Scores") == null
3293 || seq.getAnnotation("Search Scores")[0].getEValue() > eValue)
3294 && seq.getHMM() == null)
3296 hideSequence(new SequenceI[] { seq });
3302 * Filters out sequences with an score lower than the specified value. The
3303 * filtered sequences are hidden or deleted.
3308 public void filterByScore(double score)
3310 for (SequenceI seq : alignment.getSequencesArray())
3312 if ((seq.getAnnotation("Search Scores") == null
3313 || seq.getAnnotation("Search Scores")[0]
3314 .getBitScore() < score)
3315 && seq.getHMM() == null)
3317 hideSequence(new SequenceI[] { seq });
3323 * Notify TreePanel and AlignmentPanel of some sort of alignment change.
3325 public void notifyAlignment()
3327 changeSupport.firePropertyChange(PROPERTY_ALIGNMENT, null, alignment.getSequences());
3331 * Notify AlignmentPanel of a sequence column selection or visibility changes.
3333 public void notifySequence()
3335 changeSupport.firePropertyChange(PROPERTY_SEQUENCE, null, null);