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";
94 protected ViewportRanges ranges;
96 protected ViewStyleI viewStyle = new ViewStyle();
99 * A viewport that hosts the cDna view of this (protein), or vice versa (if
102 AlignViewportI codingComplement = null;
104 FeaturesDisplayedI featuresDisplayed = null;
106 protected Deque<CommandI> historyList = new ArrayDeque<>();
108 protected Deque<CommandI> redoList = new ArrayDeque<>();
111 * alignment displayed in the viewport. Please use get/setter
113 protected AlignmentI alignment;
116 * probably unused indicator that view is of a dataset rather than an
120 protected boolean ignoreBelowBackGroundFrequencyCalculation = false;
122 protected boolean infoLetterHeight = false;
124 protected AlignmentAnnotation occupancy;
127 * results of alignment consensus analysis for visible portion of view
129 protected ProfilesI consensusProfiles;
132 * HMM profile for the alignment
134 protected ProfilesI hmmProfiles;
136 public AlignmentViewport(AlignmentI al)
139 ranges = new ViewportRanges(al);
144 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
147 public void setFontName(String name)
149 viewStyle.setFontName(name);
154 * @see jalview.api.ViewStyleI#setFontStyle(int)
157 public void setFontStyle(int style)
159 viewStyle.setFontStyle(style);
164 * @see jalview.api.ViewStyleI#setFontSize(int)
167 public void setFontSize(int size)
169 viewStyle.setFontSize(size);
174 * @see jalview.api.ViewStyleI#getFontStyle()
177 public int getFontStyle()
179 return viewStyle.getFontStyle();
184 * @see jalview.api.ViewStyleI#getFontName()
187 public String getFontName()
189 return viewStyle.getFontName();
194 * @see jalview.api.ViewStyleI#getFontSize()
197 public int getFontSize()
199 return viewStyle.getFontSize();
203 * @param upperCasebold
204 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
207 public void setUpperCasebold(boolean upperCasebold)
209 viewStyle.setUpperCasebold(upperCasebold);
214 * @see jalview.api.ViewStyleI#isUpperCasebold()
217 public boolean isUpperCasebold()
219 return viewStyle.isUpperCasebold();
224 * @see jalview.api.ViewStyleI#isSeqNameItalics()
227 public boolean isSeqNameItalics()
229 return viewStyle.isSeqNameItalics();
233 * @param colourByReferenceSeq
234 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
237 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
239 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
244 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
247 public void setColourAppliesToAllGroups(boolean b)
249 viewStyle.setColourAppliesToAllGroups(b);
254 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
257 public boolean getColourAppliesToAllGroups()
259 return viewStyle.getColourAppliesToAllGroups();
264 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
267 public boolean getAbovePIDThreshold()
269 return viewStyle.getAbovePIDThreshold();
274 * @see jalview.api.ViewStyleI#setIncrement(int)
277 public void setIncrement(int inc)
279 viewStyle.setIncrement(inc);
284 * @see jalview.api.ViewStyleI#getIncrement()
287 public int getIncrement()
289 return viewStyle.getIncrement();
294 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
297 public void setConservationSelected(boolean b)
299 viewStyle.setConservationSelected(b);
304 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
307 public void setShowHiddenMarkers(boolean show)
309 viewStyle.setShowHiddenMarkers(show);
314 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
317 public boolean getShowHiddenMarkers()
319 return viewStyle.getShowHiddenMarkers();
324 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
327 public void setScaleRightWrapped(boolean b)
329 viewStyle.setScaleRightWrapped(b);
334 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
337 public void setScaleLeftWrapped(boolean b)
339 viewStyle.setScaleLeftWrapped(b);
344 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
347 public void setScaleAboveWrapped(boolean b)
349 viewStyle.setScaleAboveWrapped(b);
354 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
357 public boolean getScaleLeftWrapped()
359 return viewStyle.getScaleLeftWrapped();
364 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
367 public boolean getScaleAboveWrapped()
369 return viewStyle.getScaleAboveWrapped();
374 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
377 public boolean getScaleRightWrapped()
379 return viewStyle.getScaleRightWrapped();
384 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
387 public void setAbovePIDThreshold(boolean b)
389 viewStyle.setAbovePIDThreshold(b);
394 * @see jalview.api.ViewStyleI#setThreshold(int)
397 public void setThreshold(int thresh)
399 viewStyle.setThreshold(thresh);
404 * @see jalview.api.ViewStyleI#getThreshold()
407 public int getThreshold()
409 return viewStyle.getThreshold();
414 * @see jalview.api.ViewStyleI#getShowJVSuffix()
417 public boolean getShowJVSuffix()
419 return viewStyle.getShowJVSuffix();
424 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
427 public void setShowJVSuffix(boolean b)
429 viewStyle.setShowJVSuffix(b);
434 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
437 public void setWrapAlignment(boolean state)
439 viewStyle.setWrapAlignment(state);
440 ranges.setWrappedMode(state);
445 * @see jalview.api.ViewStyleI#setShowText(boolean)
448 public void setShowText(boolean state)
450 viewStyle.setShowText(state);
455 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
458 public void setRenderGaps(boolean state)
460 viewStyle.setRenderGaps(state);
465 * @see jalview.api.ViewStyleI#getColourText()
468 public boolean getColourText()
470 return viewStyle.getColourText();
475 * @see jalview.api.ViewStyleI#setColourText(boolean)
478 public void setColourText(boolean state)
480 viewStyle.setColourText(state);
485 * @see jalview.api.ViewStyleI#getWrapAlignment()
488 public boolean getWrapAlignment()
490 return viewStyle.getWrapAlignment();
495 * @see jalview.api.ViewStyleI#getShowText()
498 public boolean getShowText()
500 return viewStyle.getShowText();
505 * @see jalview.api.ViewStyleI#getWrappedWidth()
508 public int getWrappedWidth()
510 return viewStyle.getWrappedWidth();
515 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
518 public void setWrappedWidth(int w)
520 viewStyle.setWrappedWidth(w);
525 * @see jalview.api.ViewStyleI#getCharHeight()
528 public int getCharHeight()
530 return viewStyle.getCharHeight();
535 * @see jalview.api.ViewStyleI#setCharHeight(int)
538 public void setCharHeight(int h)
540 viewStyle.setCharHeight(h);
545 * @see jalview.api.ViewStyleI#getCharWidth()
548 public int getCharWidth()
550 return viewStyle.getCharWidth();
555 * @see jalview.api.ViewStyleI#setCharWidth(int)
558 public void setCharWidth(int w)
560 viewStyle.setCharWidth(w);
565 * @see jalview.api.ViewStyleI#getShowBoxes()
568 public boolean getShowBoxes()
570 return viewStyle.getShowBoxes();
575 * @see jalview.api.ViewStyleI#getShowUnconserved()
578 public boolean getShowUnconserved()
580 return viewStyle.getShowUnconserved();
584 * @param showunconserved
585 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
588 public void setShowUnconserved(boolean showunconserved)
590 viewStyle.setShowUnconserved(showunconserved);
595 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
598 public void setSeqNameItalics(boolean default1)
600 viewStyle.setSeqNameItalics(default1);
604 public AlignmentI getAlignment()
610 public char getGapCharacter()
612 return alignment.getGapCharacter();
615 protected String sequenceSetID;
618 * probably unused indicator that view is of a dataset rather than an
621 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;
662 protected boolean ignoreGapsInConsensusCalculation = false;
664 protected ResidueShaderI residueShading = new ResidueShader();
667 public void setGlobalColourScheme(ColourSchemeI cs)
669 // TODO: logic refactored from AlignFrame changeColour -
670 // TODO: autorecalc stuff should be changed to rely on the worker system
671 // check to see if we should implement a changeColour(cs) method rather than
672 // put the logic in here
673 // - means that caller decides if they want to just modify state and defer
674 // calculation till later or to do all calculations in thread.
678 * only instantiate alignment colouring once, thereafter update it;
679 * this means that any conservation or PID threshold settings
680 * persist when the alignment colour scheme is changed
682 if (residueShading == null)
684 residueShading = new ResidueShader(viewStyle);
686 residueShading.setColourScheme(cs);
688 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
689 // ...problem: groups need these, but do not currently have a ViewStyle
693 if (getConservationSelected())
695 residueShading.setConservation(hconservation);
698 * reset conservation flag in case just set to false if
699 * Conservation was null (calculation still in progress)
701 residueShading.setConservationApplied(getConservationSelected());
702 residueShading.alignmentChanged(alignment, hiddenRepSequences);
706 * if 'apply colour to all groups' is selected... do so
707 * (but don't transfer any colour threshold settings to groups)
709 if (getColourAppliesToAllGroups())
711 for (SequenceGroup sg : getAlignment().getGroups())
714 * retain any colour thresholds per group while
715 * changing choice of colour scheme (JAL-2386)
718 cs == null ? null : cs.getInstance(this, sg));
721 sg.getGroupColourScheme().alignmentChanged(sg,
729 public ColourSchemeI getGlobalColourScheme()
731 return residueShading == null ? null : residueShading.getColourScheme();
735 public ResidueShaderI getResidueShading()
737 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;
775 public void setConservation(Conservation cons)
777 hconservation = cons;
781 * percentage gaps allowed in a column before all amino acid properties should
782 * be considered unconserved
784 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
787 public int getConsPercGaps()
793 public void setSequenceConsensusHash(ProfilesI hconsensus)
795 this.hconsensus = hconsensus;
799 public void setComplementConsensusHash(
800 Hashtable<String, Object>[] hconsensus)
802 this.hcomplementConsensus = hconsensus;
806 public ProfilesI getSequenceConsensusHash()
812 public void setHmmProfiles(ProfilesI info)
818 public ProfilesI getHmmProfiles()
824 public Hashtable<String, Object>[] getComplementConsensusHash()
826 return hcomplementConsensus;
830 public Hashtable<String, Object>[] getRnaStructureConsensusHash()
832 return hStrucConsensus;
836 public void setRnaStructureConsensusHash(
837 Hashtable<String, Object>[] hStrucConsensus)
839 this.hStrucConsensus = hStrucConsensus;
844 public AlignmentAnnotation getAlignmentQualityAnnot()
850 public AlignmentAnnotation getAlignmentConservationAnnotation()
856 public AlignmentAnnotation getAlignmentConsensusAnnotation()
862 public AlignmentAnnotation getAlignmentGapAnnotation()
868 public AlignmentAnnotation getComplementConsensusAnnotation()
870 return complementConsensus;
874 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
876 return strucConsensus;
879 protected AlignCalcManagerI2 calculator = new AlignCalcManager2();
882 * trigger update of conservation annotation
884 public void updateConservation(final AlignmentViewPanel ap)
886 // see note in mantis : issue number 8585
887 if (alignment.isNucleotide()
888 || (conservation == null && quality == null)
889 || !autoCalculateConsensusAndConservation)
893 if (calculator.getWorkersOfClass(
894 jalview.workers.ConservationThread.class).isEmpty())
896 calculator.registerWorker(
897 new jalview.workers.ConservationThread(this, ap));
902 * trigger update of consensus annotation
904 public void updateConsensus(final AlignmentViewPanel ap)
906 // see note in mantis : issue number 8585
907 if (consensus == null || !autoCalculateConsensusAndConservation)
911 if (calculator.getWorkersOfClass(ConsensusThread.class).isEmpty())
913 calculator.registerWorker(new ConsensusThread(this, ap));
917 * A separate thread to compute cDNA consensus for a protein alignment
918 * which has mapping to cDNA
920 final AlignmentI al = this.getAlignment();
921 if (!al.isNucleotide() && al.getCodonFrames() != null
922 && !al.getCodonFrames().isEmpty())
925 * fudge - check first for protein-to-nucleotide mappings
926 * (we don't want to do this for protein-to-protein)
928 boolean doConsensus = false;
929 for (AlignedCodonFrame mapping : al.getCodonFrames())
931 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
932 MapList[] mapLists = mapping.getdnaToProt();
933 // mapLists can be empty if project load has not finished resolving seqs
934 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
942 if (calculator.getWorkersOfClass(ComplementConsensusThread.class).isEmpty())
944 calculator.registerWorker(new ComplementConsensusThread(this, ap));
951 public void initInformationWorker(final AlignmentViewPanel ap)
953 if (calculator.getWorkersOfClass(InformationThread.class).isEmpty())
955 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;
1055 public boolean isClosed()
1057 // TODO: check that this isClosed is only true after panel is closed, not
1058 // before it is fully constructed.
1059 return alignment == null;
1063 public AlignCalcManagerI2 getCalcManager()
1069 * should conservation rows be shown for groups
1071 protected boolean showGroupConservation = false;
1074 * should consensus rows be shown for groups
1076 protected boolean showGroupConsensus = false;
1079 * should consensus profile be rendered by default
1081 protected boolean showSequenceLogo = false;
1084 * should consensus profile be rendered normalised to row height
1086 protected boolean normaliseSequenceLogo = false;
1089 * should consensus histograms be rendered by default
1091 protected boolean showConsensusHistogram = true;
1094 * should hmm profile be rendered by default
1096 protected boolean hmmShowSequenceLogo = false;
1099 * should hmm profile be rendered normalised to row height
1101 protected boolean hmmNormaliseSequenceLogo = false;
1104 * should information histograms be rendered by default
1106 protected boolean hmmShowHistogram = true;
1109 * @return the showConsensusProfile
1112 public boolean isShowSequenceLogo()
1114 return showSequenceLogo;
1118 * @return the showInformationProfile
1121 public boolean isShowHMMSequenceLogo()
1123 return hmmShowSequenceLogo;
1127 * @param showSequenceLogo
1130 public void setShowSequenceLogo(boolean showSequenceLogo)
1132 if (showSequenceLogo != this.showSequenceLogo)
1134 // TODO: decouple settings setting from calculation when refactoring
1135 // annotation update method from alignframe to viewport
1136 this.showSequenceLogo = showSequenceLogo;
1137 for (AlignCalcWorkerI worker : calculator.getWorkers())
1139 if (worker.getClass().equals(ConsensusThread.class) ||
1140 worker.getClass().equals(ComplementConsensusThread.class) ||
1141 worker.getClass().equals(StrucConsensusThread.class))
1143 worker.updateAnnotation();
1147 this.showSequenceLogo = showSequenceLogo;
1150 public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo)
1152 if (showHMMSequenceLogo != this.hmmShowSequenceLogo)
1154 this.hmmShowSequenceLogo = showHMMSequenceLogo;
1155 // TODO: updateAnnotation if description (tooltip) will show
1156 // profile in place of information content?
1157 // calculator.updateAnnotationFor(InformationThread.class);
1159 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;
1470 // property change stuff
1471 // JBPNote Prolly only need this in the applet version.
1472 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1475 protected boolean showConservation = true;
1477 protected boolean showQuality = true;
1479 protected boolean showConsensus = true;
1481 protected boolean showOccupancy = true;
1483 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1485 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1487 protected boolean showAutocalculatedAbove;
1490 * when set, view will scroll to show the highlighted position
1492 private boolean followHighlight = true;
1495 * Property change listener for changes in alignment
1500 public void addPropertyChangeListener(
1501 java.beans.PropertyChangeListener listener)
1503 changeSupport.addPropertyChangeListener(listener);
1512 public void removePropertyChangeListener(
1513 java.beans.PropertyChangeListener listener)
1515 if (changeSupport != null)
1517 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
1593 public void showSequence(int index)
1595 int startSeq = ranges.getStartSeq();
1596 int endSeq = ranges.getEndSeq();
1598 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1599 hiddenRepSequences);
1602 if (selectionGroup == null)
1604 selectionGroup = new SequenceGroup();
1605 selectionGroup.setEndRes(alignment.getWidth() - 1);
1608 for (SequenceI seq : tmp)
1610 selectionGroup.addSequence(seq, false);
1611 setSequenceAnnotationsVisible(seq, true);
1614 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);
2103 initComplementConsensus();
2108 * If this is a protein alignment and there are mappings to cDNA, adds the
2109 * cDNA consensus annotation and returns true, else returns false.
2111 public boolean initComplementConsensus()
2113 if (!alignment.isNucleotide())
2115 final List<AlignedCodonFrame> codonMappings = alignment
2117 if (codonMappings != null && !codonMappings.isEmpty())
2119 boolean doConsensus = false;
2120 for (AlignedCodonFrame mapping : codonMappings)
2122 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2123 MapList[] mapLists = mapping.getdnaToProt();
2124 // mapLists can be empty if project load has not finished resolving
2126 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2134 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2136 .getString("label.complement_consensus_descr"),
2137 new Annotation[1], 0f, 100f,
2138 AlignmentAnnotation.BAR_GRAPH);
2139 initConsensus(complementConsensus);
2147 private void initConsensus(AlignmentAnnotation aa)
2150 aa.autoCalculated = true;
2154 alignment.addAnnotation(aa);
2158 // these should be extracted from the view model - style and settings for
2159 // derived annotation
2160 private void initGapCounts()
2164 gapcounts = new AlignmentAnnotation("Occupancy",
2165 MessageManager.getString("label.occupancy_descr"),
2166 new Annotation[1], 0f, alignment.getHeight(),
2167 AlignmentAnnotation.BAR_GRAPH);
2168 gapcounts.hasText = true;
2169 gapcounts.autoCalculated = true;
2170 gapcounts.scaleColLabel = true;
2171 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2173 alignment.addAnnotation(gapcounts);
2177 private void initConservation()
2179 if (showConservation)
2181 if (conservation == null)
2183 conservation = new AlignmentAnnotation("Conservation",
2184 MessageManager.formatMessage("label.conservation_descr",
2186 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2187 conservation.hasText = true;
2188 conservation.autoCalculated = true;
2189 alignment.addAnnotation(conservation);
2194 private void initQuality()
2198 if (quality == null)
2200 quality = new AlignmentAnnotation("Quality",
2201 MessageManager.getString("label.quality_descr"),
2202 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2203 quality.hasText = true;
2204 quality.autoCalculated = true;
2205 alignment.addAnnotation(quality);
2210 private void initRNAStructure()
2212 if (alignment.hasRNAStructure() && strucConsensus == null)
2214 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2215 MessageManager.getString("label.strucconsensus_descr"),
2216 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2217 strucConsensus.hasText = true;
2218 strucConsensus.autoCalculated = true;
2222 alignment.addAnnotation(strucConsensus);
2230 * @see jalview.api.AlignViewportI#calcPanelHeight()
2233 public int calcPanelHeight()
2235 // setHeight of panels
2236 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2238 int charHeight = getCharHeight();
2241 BitSet graphgrp = new BitSet();
2242 for (AlignmentAnnotation aa : anns)
2246 System.err.println("Null annotation row: ignoring.");
2253 if (aa.graphGroup > -1)
2255 if (graphgrp.get(aa.graphGroup))
2261 graphgrp.set(aa.graphGroup);
2268 aa.height += charHeight;
2278 aa.height += aa.graphHeight;
2286 height += aa.height;
2298 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2299 boolean preserveNewGroupSettings)
2301 boolean updateCalcs = false;
2302 boolean conv = isShowGroupConservation();
2303 boolean cons = isShowGroupConsensus();
2304 boolean showprf = isShowSequenceLogo();
2305 boolean showConsHist = isShowConsensusHistogram();
2306 boolean normLogo = isNormaliseSequenceLogo();
2307 boolean showHMMPrf = isShowHMMSequenceLogo();
2308 boolean showInfoHist = isShowInformationHistogram();
2309 boolean normHMMLogo = isNormaliseHMMSequenceLogo();
2312 * TODO reorder the annotation rows according to group/sequence ordering on
2315 // boolean sortg = true;
2317 // remove old automatic annotation
2318 // add any new annotation
2320 // intersect alignment annotation with alignment groups
2322 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2323 List<SequenceGroup> oldrfs = new ArrayList<>();
2326 for (int an = 0; an < aan.length; an++)
2328 if (aan[an].autoCalculated && aan[an].groupRef != null)
2330 oldrfs.add(aan[an].groupRef);
2331 alignment.deleteAnnotation(aan[an], false);
2335 if (alignment.getGroups() != null)
2337 for (SequenceGroup sg : alignment.getGroups())
2339 updateCalcs = false;
2340 if (applyGlobalSettings
2341 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2343 // set defaults for this group's conservation/consensus
2344 sg.setshowSequenceLogo(showprf);
2345 sg.setShowConsensusHistogram(showConsHist);
2346 sg.setNormaliseSequenceLogo(normLogo);
2347 sg.setShowHMMSequenceLogo(showHMMPrf);
2348 sg.setShowInformationHistogram(showInfoHist);
2349 sg.setNormaliseHMMSequenceLogo(normHMMLogo);
2354 alignment.addAnnotation(sg.getConservationRow(), 0);
2359 alignment.addAnnotation(sg.getConsensus(), 0);
2361 // refresh the annotation rows
2364 sg.recalcConservation();
2372 public boolean isDisplayReferenceSeq()
2374 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2378 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2380 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2384 public boolean isColourByReferenceSeq()
2386 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2390 public Color getSequenceColour(SequenceI seq)
2392 Color sqc = sequenceColours.get(seq);
2393 return (sqc == null ? Color.white : sqc);
2397 public void setSequenceColour(SequenceI seq, Color col)
2401 sequenceColours.remove(seq);
2405 sequenceColours.put(seq, col);
2410 public void updateSequenceIdColours()
2412 for (SequenceGroup sg : alignment.getGroups())
2414 if (sg.idColour != null)
2416 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2418 sequenceColours.put(s, sg.idColour);
2425 public void clearSequenceColours()
2427 sequenceColours.clear();
2431 public AlignViewportI getCodingComplement()
2433 return this.codingComplement;
2437 * Set this as the (cDna/protein) complement of the given viewport. Also
2438 * ensures the reverse relationship is set on the given viewport.
2441 public void setCodingComplement(AlignViewportI av)
2445 System.err.println("Ignoring recursive setCodingComplement request");
2449 this.codingComplement = av;
2450 // avoid infinite recursion!
2451 if (av.getCodingComplement() != this)
2453 av.setCodingComplement(this);
2459 public boolean isNucleotide()
2461 return getAlignment() == null ? false : getAlignment().isNucleotide();
2465 public FeaturesDisplayedI getFeaturesDisplayed()
2467 return featuresDisplayed;
2471 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2473 featuresDisplayed = featuresDisplayedI;
2477 public boolean areFeaturesDisplayed()
2479 return featuresDisplayed != null
2480 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2487 * features are displayed if true
2490 public void setShowSequenceFeatures(boolean b)
2492 viewStyle.setShowSequenceFeatures(b);
2496 public boolean isShowSequenceFeatures()
2498 return viewStyle.isShowSequenceFeatures();
2502 public void setShowSequenceFeaturesHeight(boolean selected)
2504 viewStyle.setShowSequenceFeaturesHeight(selected);
2508 public boolean isShowSequenceFeaturesHeight()
2510 return viewStyle.isShowSequenceFeaturesHeight();
2514 public void setShowAnnotation(boolean b)
2516 viewStyle.setShowAnnotation(b);
2520 public boolean isShowAnnotation()
2522 return viewStyle.isShowAnnotation();
2526 public boolean isRightAlignIds()
2528 return viewStyle.isRightAlignIds();
2532 public void setRightAlignIds(boolean rightAlignIds)
2534 viewStyle.setRightAlignIds(rightAlignIds);
2538 public boolean getConservationSelected()
2540 return viewStyle.getConservationSelected();
2544 public void setShowBoxes(boolean state)
2546 viewStyle.setShowBoxes(state);
2551 * @see jalview.api.ViewStyleI#getTextColour()
2554 public Color getTextColour()
2556 return viewStyle.getTextColour();
2561 * @see jalview.api.ViewStyleI#getTextColour2()
2564 public Color getTextColour2()
2566 return viewStyle.getTextColour2();
2571 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2574 public int getThresholdTextColour()
2576 return viewStyle.getThresholdTextColour();
2581 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2584 public boolean isConservationColourSelected()
2586 return viewStyle.isConservationColourSelected();
2591 * @see jalview.api.ViewStyleI#isRenderGaps()
2594 public boolean isRenderGaps()
2596 return viewStyle.isRenderGaps();
2601 * @see jalview.api.ViewStyleI#isShowColourText()
2604 public boolean isShowColourText()
2606 return viewStyle.isShowColourText();
2610 * @param conservationColourSelected
2611 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2614 public void setConservationColourSelected(
2615 boolean conservationColourSelected)
2617 viewStyle.setConservationColourSelected(conservationColourSelected);
2621 * @param showColourText
2622 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2625 public void setShowColourText(boolean showColourText)
2627 viewStyle.setShowColourText(showColourText);
2632 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2635 public void setTextColour(Color textColour)
2637 viewStyle.setTextColour(textColour);
2641 * @param thresholdTextColour
2642 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2645 public void setThresholdTextColour(int thresholdTextColour)
2647 viewStyle.setThresholdTextColour(thresholdTextColour);
2651 * @param textColour2
2652 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2655 public void setTextColour2(Color textColour2)
2657 viewStyle.setTextColour2(textColour2);
2661 public ViewStyleI getViewStyle()
2663 return new ViewStyle(viewStyle);
2667 public void setViewStyle(ViewStyleI settingsForView)
2669 viewStyle = new ViewStyle(settingsForView);
2670 if (residueShading != null)
2672 residueShading.setConservationApplied(
2673 settingsForView.isConservationColourSelected());
2678 public boolean sameStyle(ViewStyleI them)
2680 return viewStyle.sameStyle(them);
2685 * @see jalview.api.ViewStyleI#getIdWidth()
2688 public int getIdWidth()
2690 return viewStyle.getIdWidth();
2695 * @see jalview.api.ViewStyleI#setIdWidth(int)
2698 public void setIdWidth(int i)
2700 viewStyle.setIdWidth(i);
2705 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2708 public boolean isCentreColumnLabels()
2710 return viewStyle.isCentreColumnLabels();
2714 * @param centreColumnLabels
2715 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2718 public void setCentreColumnLabels(boolean centreColumnLabels)
2720 viewStyle.setCentreColumnLabels(centreColumnLabels);
2725 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2728 public void setShowDBRefs(boolean showdbrefs)
2730 viewStyle.setShowDBRefs(showdbrefs);
2735 * @see jalview.api.ViewStyleI#isShowDBRefs()
2738 public boolean isShowDBRefs()
2740 return viewStyle.isShowDBRefs();
2745 * @see jalview.api.ViewStyleI#isShowNPFeats()
2748 public boolean isShowNPFeats()
2750 return viewStyle.isShowNPFeats();
2754 * @param shownpfeats
2755 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2758 public void setShowNPFeats(boolean shownpfeats)
2760 viewStyle.setShowNPFeats(shownpfeats);
2763 public abstract StructureSelectionManager getStructureSelectionManager();
2766 * Add one command to the command history list.
2770 public void addToHistoryList(CommandI command)
2772 if (this.historyList != null)
2774 this.historyList.push(command);
2775 broadcastCommand(command, false);
2779 protected void broadcastCommand(CommandI command, boolean undo)
2781 getStructureSelectionManager().commandPerformed(command, undo,
2786 * Add one command to the command redo list.
2790 public void addToRedoList(CommandI command)
2792 if (this.redoList != null)
2794 this.redoList.push(command);
2796 broadcastCommand(command, true);
2800 * Clear the command redo list.
2802 public void clearRedoList()
2804 if (this.redoList != null)
2806 this.redoList.clear();
2810 public void setHistoryList(Deque<CommandI> list)
2812 this.historyList = list;
2815 public Deque<CommandI> getHistoryList()
2817 return this.historyList;
2820 public void setRedoList(Deque<CommandI> list)
2822 this.redoList = list;
2825 public Deque<CommandI> getRedoList()
2827 return this.redoList;
2831 public VamsasSource getVamsasSource()
2836 public SequenceAnnotationOrder getSortAnnotationsBy()
2838 return sortAnnotationsBy;
2841 public void setSortAnnotationsBy(
2842 SequenceAnnotationOrder sortAnnotationsBy)
2844 this.sortAnnotationsBy = sortAnnotationsBy;
2847 public boolean isShowAutocalculatedAbove()
2849 return showAutocalculatedAbove;
2852 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2854 this.showAutocalculatedAbove = showAutocalculatedAbove;
2858 public boolean isScaleProteinAsCdna()
2860 return viewStyle.isScaleProteinAsCdna();
2864 public void setScaleProteinAsCdna(boolean b)
2866 viewStyle.setScaleProteinAsCdna(b);
2870 public boolean isProteinFontAsCdna()
2872 return viewStyle.isProteinFontAsCdna();
2876 public void setProteinFontAsCdna(boolean b)
2878 viewStyle.setProteinFontAsCdna(b);
2882 public void setShowComplementFeatures(boolean b)
2884 viewStyle.setShowComplementFeatures(b);
2888 public boolean isShowComplementFeatures()
2890 return viewStyle.isShowComplementFeatures();
2894 public void setShowComplementFeaturesOnTop(boolean b)
2896 viewStyle.setShowComplementFeaturesOnTop(b);
2900 public boolean isShowComplementFeaturesOnTop()
2902 return viewStyle.isShowComplementFeaturesOnTop();
2906 * @return true if view should scroll to show the highlighted region of a
2911 public final boolean isFollowHighlight()
2913 return followHighlight;
2917 public final void setFollowHighlight(boolean b)
2919 this.followHighlight = b;
2923 public ViewportRanges getRanges()
2929 * Helper method to populate the SearchResults with the location in the
2930 * complementary alignment to scroll to, in order to match this one.
2933 * the SearchResults to add to
2934 * @return the offset (below top of visible region) of the matched sequence
2936 protected int findComplementScrollTarget(SearchResultsI sr)
2938 final AlignViewportI complement = getCodingComplement();
2939 if (complement == null || !complement.isFollowHighlight())
2943 boolean iAmProtein = !getAlignment().isNucleotide();
2944 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2945 : complement.getAlignment();
2946 if (proteinAlignment == null)
2950 final List<AlignedCodonFrame> mappings = proteinAlignment
2954 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2955 * residue in the middle column of the visible region. Scroll the
2956 * complementary alignment to line up the corresponding residue.
2959 SequenceI sequence = null;
2962 * locate 'middle' column (true middle if an odd number visible, left of
2963 * middle if an even number visible)
2965 int middleColumn = ranges.getStartRes()
2966 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2967 final HiddenSequences hiddenSequences = getAlignment()
2968 .getHiddenSequences();
2971 * searching to the bottom of the alignment gives smoother scrolling across
2972 * all gapped visible regions
2974 int lastSeq = alignment.getHeight() - 1;
2975 List<AlignedCodonFrame> seqMappings = null;
2976 for (int seqNo = ranges
2977 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2979 sequence = getAlignment().getSequenceAt(seqNo);
2980 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2984 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2988 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2990 getCodingComplement().getAlignment().getSequences());
2991 if (!seqMappings.isEmpty())
2997 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
3000 * No ungapped mapped sequence in middle column - do nothing
3004 MappingUtils.addSearchResults(sr, sequence,
3005 sequence.findPosition(middleColumn), seqMappings);
3010 * synthesize a column selection if none exists so it covers the given
3011 * selection group. if wholewidth is false, no column selection is made if the
3012 * selection group covers the whole alignment width.
3017 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
3020 if (sg != null && (sgs = sg.getStartRes()) >= 0
3021 && sg.getStartRes() <= (sge = sg.getEndRes())
3022 && !this.hasSelectedColumns())
3024 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
3031 colSel = new ColumnSelection();
3033 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
3035 colSel.addElement(cspos);
3041 * hold status of current selection group - defined on alignment or not.
3043 private boolean selectionIsDefinedGroup = false;
3046 public boolean isSelectionDefinedGroup()
3048 if (selectionGroup == null)
3052 if (isSelectionGroupChanged(true))
3054 selectionIsDefinedGroup = false;
3055 List<SequenceGroup> gps = alignment.getGroups();
3056 if (gps == null || gps.size() == 0)
3058 selectionIsDefinedGroup = false;
3062 selectionIsDefinedGroup = gps.contains(selectionGroup);
3065 return selectionGroup.isDefined() || selectionIsDefinedGroup;
3069 * null, or currently highlighted results on this view
3071 private SearchResultsI searchResults = null;
3073 protected TreeModel currentTree = null;
3076 public boolean hasSearchResults()
3078 return searchResults != null;
3082 public void setSearchResults(SearchResultsI results)
3084 searchResults = results;
3088 public SearchResultsI getSearchResults()
3090 return searchResults;
3094 * get the consensus sequence as displayed under the PID consensus annotation
3097 * @return consensus sequence as a new sequence object
3099 public SequenceI getConsensusSeq()
3101 if (consensus == null)
3103 updateConsensus(null);
3105 if (consensus == null)
3109 StringBuffer seqs = new StringBuffer();
3110 for (int i = 0; i < consensus.annotations.length; i++)
3112 Annotation annotation = consensus.annotations[i];
3113 if (annotation != null)
3115 String description = annotation.description;
3116 if (description != null && description.startsWith("["))
3118 // consensus is a tie - just pick the first one
3119 seqs.append(description.charAt(1));
3123 seqs.append(annotation.displayCharacter);
3128 SequenceI sq = new Sequence("Consensus", seqs.toString());
3129 sq.setDescription("Percentage Identity Consensus "
3130 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3134 public boolean hasReferenceAnnotation()
3136 AlignmentAnnotation[] annots = this.alignment.getAlignmentAnnotation();
3137 for (AlignmentAnnotation annot : annots)
3139 if ("RF".equals(annot.label) || annot.label.contains("Reference"))
3148 public void setCurrentTree(TreeModel tree)
3154 public TreeModel getCurrentTree()
3160 public AlignmentExportData getAlignExportData(AlignExportSettingsI options)
3162 AlignmentI alignmentToExport = null;
3163 String[] omitHidden = null;
3164 alignmentToExport = null;
3166 if (hasHiddenColumns() && !options.isExportHiddenColumns())
3168 omitHidden = getViewAsString(false,
3169 options.isExportHiddenSequences());
3172 int[] alignmentStartEnd = new int[2];
3173 if (hasHiddenRows() && options.isExportHiddenSequences())
3175 alignmentToExport = getAlignment().getHiddenSequences()
3176 .getFullAlignment();
3180 alignmentToExport = getAlignment();
3182 alignmentStartEnd = getAlignment().getHiddenColumns()
3183 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
3184 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
3185 omitHidden, alignmentStartEnd);
3190 public boolean isNormaliseSequenceLogo()
3192 return normaliseSequenceLogo;
3195 public void setNormaliseSequenceLogo(boolean state)
3197 normaliseSequenceLogo = state;
3201 public boolean isNormaliseHMMSequenceLogo()
3203 return hmmNormaliseSequenceLogo;
3206 public void setNormaliseHMMSequenceLogo(boolean state)
3208 hmmNormaliseSequenceLogo = state;
3211 * flag set to indicate if structure views might be out of sync with sequences
3215 private boolean needToUpdateStructureViews = false;
3218 public boolean isUpdateStructures()
3220 return needToUpdateStructureViews;
3224 public void setUpdateStructures(boolean update)
3226 needToUpdateStructureViews = update;
3230 public boolean needToUpdateStructureViews()
3232 boolean update = needToUpdateStructureViews;
3233 needToUpdateStructureViews = false;
3238 public void addSequenceGroup(SequenceGroup sequenceGroup)
3240 alignment.addGroup(sequenceGroup);
3242 Color col = sequenceGroup.idColour;
3245 col = col.brighter();
3247 for (SequenceI sq : sequenceGroup.getSequences())
3249 setSequenceColour(sq, col);
3253 if (codingComplement != null)
3255 SequenceGroup mappedGroup = MappingUtils
3256 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3257 if (mappedGroup.getSequences().size() > 0)
3259 codingComplement.getAlignment().addGroup(mappedGroup);
3263 for (SequenceI seq : mappedGroup.getSequences())
3265 codingComplement.setSequenceColour(seq, col);
3269 // propagate the structure view update flag according to our own setting
3270 codingComplement.setUpdateStructures(needToUpdateStructureViews);
3274 * Filters out sequences with an eValue higher than the specified value. The
3275 * filtered sequences are hidden or deleted. Sequences with no eValues are also
3281 public void filterByEvalue(double eValue)
3283 for (SequenceI seq : alignment.getSequencesArray())
3285 if ((seq.getAnnotation("Search Scores") == null
3286 || seq.getAnnotation("Search Scores")[0].getEValue() > eValue)
3287 && seq.getHMM() == null)
3289 hideSequence(new SequenceI[] { seq });
3295 * Filters out sequences with an score lower than the specified value. The
3296 * filtered sequences are hidden or deleted.
3301 public void filterByScore(double score)
3303 for (SequenceI seq : alignment.getSequencesArray())
3305 if ((seq.getAnnotation("Search Scores") == null
3306 || seq.getAnnotation("Search Scores")[0]
3307 .getBitScore() < score)
3308 && seq.getHMM() == null)
3310 hideSequence(new SequenceI[] { seq });
3316 * Notify TreePanel and AlignmentPanel of some sort of alignment change.
3318 public void notifyAlignment()
3320 changeSupport.firePropertyChange(PROPERTY_ALIGNMENT, null, alignment.getSequences());
3324 * Notify AlignmentPanel of a sequence column selection or visibility changes.
3326 public void notifySequence()
3328 changeSupport.firePropertyChange(PROPERTY_SEQUENCE, null, null);