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.AlignCalcManagerI;
27 import jalview.api.AlignCalcManagerI2;
28 import jalview.api.AlignCalcWorkerI;
29 import jalview.api.AlignExportSettingsI;
30 import jalview.api.AlignViewportI;
31 import jalview.api.AlignmentViewPanel;
32 import jalview.api.FeaturesDisplayedI;
33 import jalview.api.ViewStyleI;
34 import jalview.commands.CommandI;
35 import jalview.datamodel.AlignedCodonFrame;
36 import jalview.datamodel.AlignmentAnnotation;
37 import jalview.datamodel.AlignmentExportData;
38 import jalview.datamodel.AlignmentI;
39 import jalview.datamodel.AlignmentView;
40 import jalview.datamodel.Annotation;
41 import jalview.datamodel.ColumnSelection;
42 import jalview.datamodel.HiddenColumns;
43 import jalview.datamodel.HiddenSequences;
44 import jalview.datamodel.ProfilesI;
45 import jalview.datamodel.SearchResultsI;
46 import jalview.datamodel.Sequence;
47 import jalview.datamodel.SequenceCollectionI;
48 import jalview.datamodel.SequenceGroup;
49 import jalview.datamodel.SequenceI;
50 import jalview.renderer.ResidueShader;
51 import jalview.renderer.ResidueShaderI;
52 import jalview.schemes.ColourSchemeI;
53 import jalview.structure.CommandListener;
54 import jalview.structure.StructureSelectionManager;
55 import jalview.structure.VamsasSource;
56 import jalview.util.Comparison;
57 import jalview.util.MapList;
58 import jalview.util.MappingUtils;
59 import jalview.util.MessageManager;
60 import jalview.viewmodel.styles.ViewStyle;
61 import jalview.workers.AlignCalcManager;
62 import jalview.workers.AlignCalcManager2;
63 import jalview.workers.ComplementConsensusThread;
64 import jalview.workers.ConsensusThread;
65 import jalview.workers.InformationThread;
66 import jalview.workers.StrucConsensusThread;
68 import java.awt.Color;
69 import java.beans.PropertyChangeSupport;
70 import java.util.ArrayDeque;
71 import java.util.ArrayList;
72 import java.util.BitSet;
73 import java.util.Deque;
74 import java.util.HashMap;
75 import java.util.Hashtable;
76 import java.util.Iterator;
77 import java.util.List;
81 * base class holding visualization and analysis attributes and common logic for
82 * an active alignment view displayed in the GUI
87 public abstract class AlignmentViewport
88 implements AlignViewportI, CommandListener, VamsasSource
90 protected ViewportRanges ranges;
92 protected ViewStyleI viewStyle = new ViewStyle();
95 * A viewport that hosts the cDna view of this (protein), or vice versa (if
98 AlignViewportI codingComplement = null;
100 FeaturesDisplayedI featuresDisplayed = null;
102 protected Deque<CommandI> historyList = new ArrayDeque<>();
104 protected Deque<CommandI> redoList = new ArrayDeque<>();
107 * alignment displayed in the viewport. Please use get/setter
109 protected AlignmentI alignment;
112 * probably unused indicator that view is of a dataset rather than an
116 protected boolean ignoreBelowBackGroundFrequencyCalculation = false;
118 protected boolean infoLetterHeight = false;
120 protected AlignmentAnnotation occupancy;
123 * results of alignment consensus analysis for visible portion of view
125 protected ProfilesI consensusProfiles;
128 * HMM profile for the alignment
130 protected ProfilesI hmmProfiles;
132 public AlignmentViewport(AlignmentI al)
135 ranges = new ViewportRanges(al);
140 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
143 public void setFontName(String name)
145 viewStyle.setFontName(name);
150 * @see jalview.api.ViewStyleI#setFontStyle(int)
153 public void setFontStyle(int style)
155 viewStyle.setFontStyle(style);
160 * @see jalview.api.ViewStyleI#setFontSize(int)
163 public void setFontSize(int size)
165 viewStyle.setFontSize(size);
170 * @see jalview.api.ViewStyleI#getFontStyle()
173 public int getFontStyle()
175 return viewStyle.getFontStyle();
180 * @see jalview.api.ViewStyleI#getFontName()
183 public String getFontName()
185 return viewStyle.getFontName();
190 * @see jalview.api.ViewStyleI#getFontSize()
193 public int getFontSize()
195 return viewStyle.getFontSize();
199 * @param upperCasebold
200 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
203 public void setUpperCasebold(boolean upperCasebold)
205 viewStyle.setUpperCasebold(upperCasebold);
210 * @see jalview.api.ViewStyleI#isUpperCasebold()
213 public boolean isUpperCasebold()
215 return viewStyle.isUpperCasebold();
220 * @see jalview.api.ViewStyleI#isSeqNameItalics()
223 public boolean isSeqNameItalics()
225 return viewStyle.isSeqNameItalics();
229 * @param colourByReferenceSeq
230 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
233 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
235 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
240 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
243 public void setColourAppliesToAllGroups(boolean b)
245 viewStyle.setColourAppliesToAllGroups(b);
250 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
253 public boolean getColourAppliesToAllGroups()
255 return viewStyle.getColourAppliesToAllGroups();
260 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
263 public boolean getAbovePIDThreshold()
265 return viewStyle.getAbovePIDThreshold();
270 * @see jalview.api.ViewStyleI#setIncrement(int)
273 public void setIncrement(int inc)
275 viewStyle.setIncrement(inc);
280 * @see jalview.api.ViewStyleI#getIncrement()
283 public int getIncrement()
285 return viewStyle.getIncrement();
290 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
293 public void setConservationSelected(boolean b)
295 viewStyle.setConservationSelected(b);
300 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
303 public void setShowHiddenMarkers(boolean show)
305 viewStyle.setShowHiddenMarkers(show);
310 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
313 public boolean getShowHiddenMarkers()
315 return viewStyle.getShowHiddenMarkers();
320 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
323 public void setScaleRightWrapped(boolean b)
325 viewStyle.setScaleRightWrapped(b);
330 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
333 public void setScaleLeftWrapped(boolean b)
335 viewStyle.setScaleLeftWrapped(b);
340 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
343 public void setScaleAboveWrapped(boolean b)
345 viewStyle.setScaleAboveWrapped(b);
350 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
353 public boolean getScaleLeftWrapped()
355 return viewStyle.getScaleLeftWrapped();
360 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
363 public boolean getScaleAboveWrapped()
365 return viewStyle.getScaleAboveWrapped();
370 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
373 public boolean getScaleRightWrapped()
375 return viewStyle.getScaleRightWrapped();
380 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
383 public void setAbovePIDThreshold(boolean b)
385 viewStyle.setAbovePIDThreshold(b);
390 * @see jalview.api.ViewStyleI#setThreshold(int)
393 public void setThreshold(int thresh)
395 viewStyle.setThreshold(thresh);
400 * @see jalview.api.ViewStyleI#getThreshold()
403 public int getThreshold()
405 return viewStyle.getThreshold();
410 * @see jalview.api.ViewStyleI#getShowJVSuffix()
413 public boolean getShowJVSuffix()
415 return viewStyle.getShowJVSuffix();
420 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
423 public void setShowJVSuffix(boolean b)
425 viewStyle.setShowJVSuffix(b);
430 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
433 public void setWrapAlignment(boolean state)
435 viewStyle.setWrapAlignment(state);
436 ranges.setWrappedMode(state);
441 * @see jalview.api.ViewStyleI#setShowText(boolean)
444 public void setShowText(boolean state)
446 viewStyle.setShowText(state);
451 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
454 public void setRenderGaps(boolean state)
456 viewStyle.setRenderGaps(state);
461 * @see jalview.api.ViewStyleI#getColourText()
464 public boolean getColourText()
466 return viewStyle.getColourText();
471 * @see jalview.api.ViewStyleI#setColourText(boolean)
474 public void setColourText(boolean state)
476 viewStyle.setColourText(state);
481 * @see jalview.api.ViewStyleI#getWrapAlignment()
484 public boolean getWrapAlignment()
486 return viewStyle.getWrapAlignment();
491 * @see jalview.api.ViewStyleI#getShowText()
494 public boolean getShowText()
496 return viewStyle.getShowText();
501 * @see jalview.api.ViewStyleI#getWrappedWidth()
504 public int getWrappedWidth()
506 return viewStyle.getWrappedWidth();
511 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
514 public void setWrappedWidth(int w)
516 viewStyle.setWrappedWidth(w);
521 * @see jalview.api.ViewStyleI#getCharHeight()
524 public int getCharHeight()
526 return viewStyle.getCharHeight();
531 * @see jalview.api.ViewStyleI#setCharHeight(int)
534 public void setCharHeight(int h)
536 viewStyle.setCharHeight(h);
541 * @see jalview.api.ViewStyleI#getCharWidth()
544 public int getCharWidth()
546 return viewStyle.getCharWidth();
551 * @see jalview.api.ViewStyleI#setCharWidth(int)
554 public void setCharWidth(int w)
556 viewStyle.setCharWidth(w);
561 * @see jalview.api.ViewStyleI#getShowBoxes()
564 public boolean getShowBoxes()
566 return viewStyle.getShowBoxes();
571 * @see jalview.api.ViewStyleI#getShowUnconserved()
574 public boolean getShowUnconserved()
576 return viewStyle.getShowUnconserved();
580 * @param showunconserved
581 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
584 public void setShowUnconserved(boolean showunconserved)
586 viewStyle.setShowUnconserved(showunconserved);
591 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
594 public void setSeqNameItalics(boolean default1)
596 viewStyle.setSeqNameItalics(default1);
600 public AlignmentI getAlignment()
606 public char getGapCharacter()
608 return alignment.getGapCharacter();
611 protected String sequenceSetID;
614 * probably unused indicator that view is of a dataset rather than an
617 protected boolean isDataset = false;
619 public void setDataset(boolean b)
624 public boolean isDataset()
629 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
631 protected ColumnSelection colSel = new ColumnSelection();
633 public boolean autoCalculateConsensus = true;
635 protected boolean autoCalculateStrucConsensus = true;
637 protected boolean ignoreGapsInConsensusCalculation = false;
639 protected ResidueShaderI residueShading = new ResidueShader();
642 public void setGlobalColourScheme(ColourSchemeI cs)
644 // TODO: logic refactored from AlignFrame changeColour -
645 // TODO: autorecalc stuff should be changed to rely on the worker system
646 // check to see if we should implement a changeColour(cs) method rather than
647 // put the logic in here
648 // - means that caller decides if they want to just modify state and defer
649 // calculation till later or to do all calculations in thread.
653 * only instantiate alignment colouring once, thereafter update it;
654 * this means that any conservation or PID threshold settings
655 * persist when the alignment colour scheme is changed
657 if (residueShading == null)
659 residueShading = new ResidueShader(viewStyle);
661 residueShading.setColourScheme(cs);
663 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
664 // ...problem: groups need these, but do not currently have a ViewStyle
668 if (getConservationSelected())
670 residueShading.setConservation(hconservation);
673 * reset conservation flag in case just set to false if
674 * Conservation was null (calculation still in progress)
676 residueShading.setConservationApplied(getConservationSelected());
677 residueShading.alignmentChanged(alignment, hiddenRepSequences);
681 * if 'apply colour to all groups' is selected... do so
682 * (but don't transfer any colour threshold settings to groups)
684 if (getColourAppliesToAllGroups())
686 for (SequenceGroup sg : getAlignment().getGroups())
689 * retain any colour thresholds per group while
690 * changing choice of colour scheme (JAL-2386)
693 cs == null ? null : cs.getInstance(this, sg));
696 sg.getGroupColourScheme().alignmentChanged(sg,
704 public ColourSchemeI getGlobalColourScheme()
706 return residueShading == null ? null : residueShading.getColourScheme();
710 public ResidueShaderI getResidueShading()
712 return residueShading;
715 protected AlignmentAnnotation consensus;
717 protected AlignmentAnnotation complementConsensus;
719 protected AlignmentAnnotation gapcounts;
721 protected AlignmentAnnotation strucConsensus;
723 protected AlignmentAnnotation conservation;
725 protected AlignmentAnnotation quality;
727 protected AlignmentAnnotation[] groupConsensus;
729 protected AlignmentAnnotation[] groupConservation;
732 * results of alignment consensus analysis for visible portion of view
734 protected ProfilesI hconsensus = null;
737 * results of cDNA complement consensus visible portion of view
739 protected Hashtable<String, Object>[] hcomplementConsensus = null;
742 * results of secondary structure base pair consensus for visible portion of
745 protected Hashtable<String, Object>[] hStrucConsensus = null;
747 protected Conservation hconservation = null;
750 public void setConservation(Conservation cons)
752 hconservation = cons;
756 * percentage gaps allowed in a column before all amino acid properties should
757 * be considered unconserved
759 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
762 public int getConsPercGaps()
768 public void setSequenceConsensusHash(ProfilesI hconsensus)
770 this.hconsensus = hconsensus;
774 public void setComplementConsensusHash(
775 Hashtable<String, Object>[] hconsensus)
777 this.hcomplementConsensus = hconsensus;
781 public ProfilesI getSequenceConsensusHash()
787 public void setHmmProfiles(ProfilesI info)
793 public ProfilesI getHmmProfiles()
799 public Hashtable<String, Object>[] getComplementConsensusHash()
801 return hcomplementConsensus;
805 public Hashtable<String, Object>[] getRnaStructureConsensusHash()
807 return hStrucConsensus;
811 public void setRnaStructureConsensusHash(
812 Hashtable<String, Object>[] hStrucConsensus)
814 this.hStrucConsensus = hStrucConsensus;
819 public AlignmentAnnotation getAlignmentQualityAnnot()
825 public AlignmentAnnotation getAlignmentConservationAnnotation()
831 public AlignmentAnnotation getAlignmentConsensusAnnotation()
837 public AlignmentAnnotation getAlignmentGapAnnotation()
843 public AlignmentAnnotation getComplementConsensusAnnotation()
845 return complementConsensus;
849 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
851 return strucConsensus;
854 protected AlignCalcManagerI2 calculator = new AlignCalcManager2();
857 * trigger update of conservation annotation
859 public void updateConservation(final AlignmentViewPanel ap)
861 // see note in mantis : issue number 8585
862 if (alignment.isNucleotide()
863 || (conservation == null && quality == null)
864 || !autoCalculateConsensus)
868 if (calculator.getWorkersOfClass(
869 jalview.workers.ConservationThread.class).isEmpty())
871 calculator.registerWorker(
872 new jalview.workers.ConservationThread(this, ap));
877 * trigger update of consensus annotation
879 public void updateConsensus(final AlignmentViewPanel ap)
881 // see note in mantis : issue number 8585
882 if (consensus == null || !autoCalculateConsensus)
886 if (calculator.getWorkersOfClass(ConsensusThread.class).isEmpty())
888 calculator.registerWorker(new ConsensusThread(this, ap));
892 * A separate thread to compute cDNA consensus for a protein alignment
893 * which has mapping to cDNA
895 final AlignmentI al = this.getAlignment();
896 if (!al.isNucleotide() && al.getCodonFrames() != null
897 && !al.getCodonFrames().isEmpty())
900 * fudge - check first for protein-to-nucleotide mappings
901 * (we don't want to do this for protein-to-protein)
903 boolean doConsensus = false;
904 for (AlignedCodonFrame mapping : al.getCodonFrames())
906 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
907 MapList[] mapLists = mapping.getdnaToProt();
908 // mapLists can be empty if project load has not finished resolving seqs
909 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
917 if (calculator.getWorkersOfClass(ComplementConsensusThread.class).isEmpty())
919 calculator.registerWorker(new ComplementConsensusThread(this, ap));
926 public void initInformationWorker(final AlignmentViewPanel ap)
928 if (calculator.getWorkersOfClass(InformationThread.class).isEmpty())
930 calculator.registerWorker(new InformationThread(this, ap));
934 // --------START Structure Conservation
935 public void updateStrucConsensus(final AlignmentViewPanel ap)
937 if (autoCalculateStrucConsensus && strucConsensus == null
938 && alignment.isNucleotide() && alignment.hasRNAStructure())
940 // secondary structure has been added - so init the consensus line
944 // see note in mantis : issue number 8585
945 if (strucConsensus == null || !autoCalculateStrucConsensus)
949 if (calculator.getWorkersOfClass(StrucConsensusThread.class).isEmpty())
951 calculator.registerWorker(new StrucConsensusThread(this, ap));
955 public boolean isCalcInProgress()
957 return calculator.isWorking();
961 public boolean isCalculationInProgress(
962 AlignmentAnnotation alignmentAnnotation)
964 if (!alignmentAnnotation.autoCalculated)
968 if (calculator.isWorkingWithAnnotation(alignmentAnnotation))
970 // System.err.println("grey out ("+alignmentAnnotation.label+")");
976 public void setAlignment(AlignmentI align)
978 this.alignment = align;
982 * Clean up references when this viewport is closed
985 public void dispose()
988 * defensively null out references to large objects in case
989 * this object is not garbage collected (as if!)
992 complementConsensus = null;
993 strucConsensus = null;
996 consensusProfiles = null;
997 groupConsensus = null;
998 groupConservation = null;
1000 hconservation = null;
1001 hcomplementConsensus = null;
1003 calculator.shutdown();
1005 residueShading = null; // may hold a reference to Consensus
1006 changeSupport = null;
1009 selectionGroup = null;
1014 public boolean isClosed()
1016 // TODO: check that this isClosed is only true after panel is closed, not
1017 // before it is fully constructed.
1018 return alignment == null;
1022 public AlignCalcManagerI2 getCalcManager()
1028 * should conservation rows be shown for groups
1030 protected boolean showGroupConservation = false;
1033 * should consensus rows be shown for groups
1035 protected boolean showGroupConsensus = false;
1038 * should consensus profile be rendered by default
1040 protected boolean showSequenceLogo = false;
1043 * should consensus profile be rendered normalised to row height
1045 protected boolean normaliseSequenceLogo = false;
1048 * should consensus histograms be rendered by default
1050 protected boolean showConsensusHistogram = true;
1053 * should hmm profile be rendered by default
1055 protected boolean hmmShowSequenceLogo = false;
1058 * should hmm profile be rendered normalised to row height
1060 protected boolean hmmNormaliseSequenceLogo = false;
1063 * should information histograms be rendered by default
1065 protected boolean hmmShowHistogram = true;
1068 * @return the showConsensusProfile
1071 public boolean isShowSequenceLogo()
1073 return showSequenceLogo;
1077 * @return the showInformationProfile
1080 public boolean isShowHMMSequenceLogo()
1082 return hmmShowSequenceLogo;
1086 * @param showSequenceLogo
1089 public void setShowSequenceLogo(boolean showSequenceLogo)
1091 if (showSequenceLogo != this.showSequenceLogo)
1093 // TODO: decouple settings setting from calculation when refactoring
1094 // annotation update method from alignframe to viewport
1095 this.showSequenceLogo = showSequenceLogo;
1096 for (AlignCalcWorkerI worker : calculator.getWorkers())
1098 if (worker.getClass().equals(ConsensusThread.class) ||
1099 worker.getClass().equals(ComplementConsensusThread.class) ||
1100 worker.getClass().equals(StrucConsensusThread.class))
1102 worker.updateAnnotation();
1106 this.showSequenceLogo = showSequenceLogo;
1109 public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo)
1111 if (showHMMSequenceLogo != this.hmmShowSequenceLogo)
1113 this.hmmShowSequenceLogo = showHMMSequenceLogo;
1114 // TODO: updateAnnotation if description (tooltip) will show
1115 // profile in place of information content?
1116 // calculator.updateAnnotationFor(InformationThread.class);
1118 this.hmmShowSequenceLogo = showHMMSequenceLogo;
1122 * @param showConsensusHistogram
1123 * the showConsensusHistogram to set
1125 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1127 this.showConsensusHistogram = showConsensusHistogram;
1131 * @param showInformationHistogram
1133 public void setShowInformationHistogram(boolean showInformationHistogram)
1135 this.hmmShowHistogram = showInformationHistogram;
1139 * @return the showGroupConservation
1141 public boolean isShowGroupConservation()
1143 return showGroupConservation;
1147 * @param showGroupConservation
1148 * the showGroupConservation to set
1150 public void setShowGroupConservation(boolean showGroupConservation)
1152 this.showGroupConservation = showGroupConservation;
1156 * @return the showGroupConsensus
1158 public boolean isShowGroupConsensus()
1160 return showGroupConsensus;
1164 * @param showGroupConsensus
1165 * the showGroupConsensus to set
1167 public void setShowGroupConsensus(boolean showGroupConsensus)
1169 this.showGroupConsensus = showGroupConsensus;
1174 * @return flag to indicate if the consensus histogram should be rendered by
1178 public boolean isShowConsensusHistogram()
1180 return this.showConsensusHistogram;
1185 * @return flag to indicate if the information content histogram should be
1186 * rendered by default
1189 public boolean isShowInformationHistogram()
1191 return this.hmmShowHistogram;
1195 * when set, updateAlignment will always ensure sequences are of equal length
1197 private boolean padGaps = false;
1200 * when set, alignment should be reordered according to a newly opened tree
1202 public boolean sortByTree = false;
1207 * @return null or the currently selected sequence region
1210 public SequenceGroup getSelectionGroup()
1212 return selectionGroup;
1216 * Set the selection group for this window. Also sets the current alignment as
1217 * the context for the group, if it does not already have one.
1220 * - group holding references to sequences in this alignment view
1224 public void setSelectionGroup(SequenceGroup sg)
1226 selectionGroup = sg;
1227 if (sg != null && sg.getContext() == null)
1229 sg.setContext(alignment);
1233 public void setHiddenColumns(HiddenColumns hidden)
1235 this.alignment.setHiddenColumns(hidden);
1239 public ColumnSelection getColumnSelection()
1245 public void setColumnSelection(ColumnSelection colSel)
1247 this.colSel = colSel;
1250 updateHiddenColumns();
1252 isColSelChanged(true);
1260 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1262 return hiddenRepSequences;
1266 public void setHiddenRepSequences(
1267 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1269 this.hiddenRepSequences = hiddenRepSequences;
1273 public boolean hasSelectedColumns()
1275 ColumnSelection columnSelection = getColumnSelection();
1276 return columnSelection != null && columnSelection.hasSelectedColumns();
1280 public boolean hasHiddenColumns()
1282 return alignment.getHiddenColumns() != null
1283 && alignment.getHiddenColumns().hasHiddenColumns();
1286 public void updateHiddenColumns()
1288 // this method doesn't really do anything now. But - it could, since a
1289 // column Selection could be in the process of modification
1290 // hasHiddenColumns = colSel.hasHiddenColumns();
1294 public boolean hasHiddenRows()
1296 return alignment.getHiddenSequences().getSize() > 0;
1299 protected SequenceGroup selectionGroup;
1301 public void setSequenceSetId(String newid)
1303 if (sequenceSetID != null)
1306 "Warning - overwriting a sequenceSetId for a viewport!");
1308 sequenceSetID = new String(newid);
1312 public String getSequenceSetId()
1314 if (sequenceSetID == null)
1316 sequenceSetID = alignment.hashCode() + "";
1319 return sequenceSetID;
1323 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1326 protected String viewId = null;
1329 public String getViewId()
1333 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1338 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1340 ignoreGapsInConsensusCalculation = b;
1343 updateConsensus(ap);
1344 if (residueShading != null)
1346 residueShading.setThreshold(residueShading.getThreshold(),
1347 ignoreGapsInConsensusCalculation);
1352 public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap)
1354 ignoreBelowBackGroundFrequencyCalculation = b;
1357 public void setInfoLetterHeight(boolean b, AlignmentViewPanel ap)
1359 infoLetterHeight = b;
1362 private long sgrouphash = -1, colselhash = -1;
1365 * checks current SelectionGroup against record of last hash value, and
1369 * update the record of last hash value
1371 * @return true if SelectionGroup changed since last call (when b is true)
1373 public boolean isSelectionGroupChanged(boolean b)
1375 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1376 : selectionGroup.hashCode();
1377 if (hc != -1 && hc != sgrouphash)
1389 * checks current colsel against record of last hash value, and optionally
1393 * update the record of last hash value
1394 * @return true if colsel changed since last call (when b is true)
1396 public boolean isColSelChanged(boolean b)
1398 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1399 if (hc != -1 && hc != colselhash)
1411 public boolean isIgnoreGapsConsensus()
1413 return ignoreGapsInConsensusCalculation;
1417 public boolean isIgnoreBelowBackground()
1419 return ignoreBelowBackGroundFrequencyCalculation;
1423 public boolean isInfoLetterHeight()
1425 return infoLetterHeight;
1428 // property change stuff
1429 // JBPNote Prolly only need this in the applet version.
1430 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1433 protected boolean showConservation = true;
1435 protected boolean showQuality = true;
1437 protected boolean showConsensus = true;
1439 protected boolean showOccupancy = true;
1441 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1443 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1445 protected boolean showAutocalculatedAbove;
1448 * when set, view will scroll to show the highlighted position
1450 private boolean followHighlight = true;
1453 * Property change listener for changes in alignment
1458 public void addPropertyChangeListener(
1459 java.beans.PropertyChangeListener listener)
1461 changeSupport.addPropertyChangeListener(listener);
1470 public void removePropertyChangeListener(
1471 java.beans.PropertyChangeListener listener)
1473 if (changeSupport != null)
1475 changeSupport.removePropertyChangeListener(listener);
1480 * Property change listener for changes in alignment
1489 public void firePropertyChange(String prop, Object oldvalue,
1492 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1495 // common hide/show column stuff
1497 public void hideSelectedColumns()
1499 if (colSel.isEmpty())
1504 colSel.hideSelectedColumns(alignment);
1505 setSelectionGroup(null);
1506 isColSelChanged(true);
1509 public void hideColumns(int start, int end)
1513 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1517 alignment.getHiddenColumns().hideColumns(start, end);
1519 isColSelChanged(true);
1522 public void showColumn(int col)
1524 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1525 isColSelChanged(true);
1528 public void showAllHiddenColumns()
1530 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1531 isColSelChanged(true);
1534 // common hide/show seq stuff
1535 public void showAllHiddenSeqs()
1537 int startSeq = ranges.getStartSeq();
1538 int endSeq = ranges.getEndSeq();
1540 if (alignment.getHiddenSequences().getSize() > 0)
1542 if (selectionGroup == null)
1544 selectionGroup = new SequenceGroup();
1545 selectionGroup.setEndRes(alignment.getWidth() - 1);
1547 List<SequenceI> tmp = alignment.getHiddenSequences()
1548 .showAll(hiddenRepSequences);
1549 for (SequenceI seq : tmp)
1551 selectionGroup.addSequence(seq, false);
1552 setSequenceAnnotationsVisible(seq, true);
1555 hiddenRepSequences = null;
1557 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1559 firePropertyChange("alignment", null, alignment.getSequences());
1560 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1566 public void showSequence(int index)
1568 int startSeq = ranges.getStartSeq();
1569 int endSeq = ranges.getEndSeq();
1571 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1572 hiddenRepSequences);
1575 if (selectionGroup == null)
1577 selectionGroup = new SequenceGroup();
1578 selectionGroup.setEndRes(alignment.getWidth() - 1);
1581 for (SequenceI seq : tmp)
1583 selectionGroup.addSequence(seq, false);
1584 setSequenceAnnotationsVisible(seq, true);
1587 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1589 firePropertyChange("alignment", null, alignment.getSequences());
1594 public void hideAllSelectedSeqs()
1596 if (selectionGroup == null || selectionGroup.getSize() < 1)
1601 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1605 setSelectionGroup(null);
1608 public void hideSequence(SequenceI[] seq)
1611 * cache offset to first visible sequence
1613 int startSeq = ranges.getStartSeq();
1617 for (int i = 0; i < seq.length; i++)
1619 alignment.getHiddenSequences().hideSequence(seq[i]);
1620 setSequenceAnnotationsVisible(seq[i], false);
1622 ranges.setStartSeq(startSeq);
1623 firePropertyChange("alignment", null, alignment.getSequences());
1628 * Hides the specified sequence, or the sequences it represents
1631 * the sequence to hide, or keep as representative
1632 * @param representGroup
1633 * if true, hide the current selection group except for the
1634 * representative sequence
1636 public void hideSequences(SequenceI sequence, boolean representGroup)
1638 if (selectionGroup == null || selectionGroup.getSize() < 1)
1640 hideSequence(new SequenceI[] { sequence });
1646 hideRepSequences(sequence, selectionGroup);
1647 setSelectionGroup(null);
1651 int gsize = selectionGroup.getSize();
1652 SequenceI[] hseqs = selectionGroup.getSequences()
1653 .toArray(new SequenceI[gsize]);
1655 hideSequence(hseqs);
1656 setSelectionGroup(null);
1661 * Set visibility for any annotations for the given sequence.
1665 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1668 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1671 for (AlignmentAnnotation ann : anns)
1673 if (ann.sequenceRef == sequenceI)
1675 ann.visible = visible;
1681 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1683 int sSize = sg.getSize();
1689 if (hiddenRepSequences == null)
1691 hiddenRepSequences = new Hashtable<>();
1694 hiddenRepSequences.put(repSequence, sg);
1696 // Hide all sequences except the repSequence
1697 SequenceI[] seqs = new SequenceI[sSize - 1];
1699 for (int i = 0; i < sSize; i++)
1701 if (sg.getSequenceAt(i) != repSequence)
1703 if (index == sSize - 1)
1708 seqs[index++] = sg.getSequenceAt(i);
1711 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1712 sg.setHidereps(true); // note: not done in 2.7applet
1719 * @return null or the current reference sequence
1721 public SequenceI getReferenceSeq()
1723 return alignment.getSeqrep();
1728 * @return true iff seq is the reference for the alignment
1730 public boolean isReferenceSeq(SequenceI seq)
1732 return alignment.getSeqrep() == seq;
1738 * @return true if there are sequences represented by this sequence that are
1741 public boolean isHiddenRepSequence(SequenceI seq)
1743 return (hiddenRepSequences != null
1744 && hiddenRepSequences.containsKey(seq));
1750 * @return null or a sequence group containing the sequences that seq
1753 public SequenceGroup getRepresentedSequences(SequenceI seq)
1755 return (SequenceGroup) (hiddenRepSequences == null ? null
1756 : hiddenRepSequences.get(seq));
1760 public int adjustForHiddenSeqs(int alignmentIndex)
1762 return alignment.getHiddenSequences()
1763 .adjustForHiddenSeqs(alignmentIndex);
1767 public void invertColumnSelection()
1769 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1770 isColSelChanged(true);
1774 public SequenceI[] getSelectionAsNewSequence()
1776 SequenceI[] sequences;
1777 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1778 // this was the only caller in the applet for this method
1779 // JBPNote: in applet, this method returned references to the alignment
1780 // sequences, and it did not honour the presence/absence of annotation
1781 // attached to the alignment (probably!)
1782 if (selectionGroup == null || selectionGroup.getSize() == 0)
1784 sequences = alignment.getSequencesArray();
1785 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1786 for (int i = 0; i < sequences.length; i++)
1788 // construct new sequence with subset of visible annotation
1789 sequences[i] = new Sequence(sequences[i], annots);
1794 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1801 public SequenceI[] getSequenceSelection()
1803 SequenceI[] sequences = null;
1804 if (selectionGroup != null)
1806 sequences = selectionGroup.getSequencesInOrder(alignment);
1808 if (sequences == null)
1810 sequences = alignment.getSequencesArray();
1816 public jalview.datamodel.AlignmentView getAlignmentView(
1817 boolean selectedOnly)
1819 return getAlignmentView(selectedOnly, false);
1823 public jalview.datamodel.AlignmentView getAlignmentView(
1824 boolean selectedOnly, boolean markGroups)
1826 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1828 alignment.getHiddenColumns() != null
1829 && alignment.getHiddenColumns().hasHiddenColumns(),
1830 selectedOnly, markGroups);
1834 public String[] getViewAsString(boolean selectedRegionOnly)
1836 return getViewAsString(selectedRegionOnly, true);
1840 public String[] getViewAsString(boolean selectedRegionOnly,
1841 boolean exportHiddenSeqs)
1843 String[] selection = null;
1844 SequenceI[] seqs = null;
1846 int start = 0, end = 0;
1847 if (selectedRegionOnly && selectionGroup != null)
1849 iSize = selectionGroup.getSize();
1850 seqs = selectionGroup.getSequencesInOrder(alignment);
1851 start = selectionGroup.getStartRes();
1852 end = selectionGroup.getEndRes() + 1;
1856 if (hasHiddenRows() && exportHiddenSeqs)
1858 AlignmentI fullAlignment = alignment.getHiddenSequences()
1859 .getFullAlignment();
1860 iSize = fullAlignment.getHeight();
1861 seqs = fullAlignment.getSequencesArray();
1862 end = fullAlignment.getWidth();
1866 iSize = alignment.getHeight();
1867 seqs = alignment.getSequencesArray();
1868 end = alignment.getWidth();
1872 selection = new String[iSize];
1873 if (alignment.getHiddenColumns() != null
1874 && alignment.getHiddenColumns().hasHiddenColumns())
1876 for (i = 0; i < iSize; i++)
1878 Iterator<int[]> blocks = alignment.getHiddenColumns()
1879 .getVisContigsIterator(start, end + 1, false);
1880 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1885 for (i = 0; i < iSize; i++)
1887 selection[i] = seqs[i].getSequenceAsString(start, end);
1895 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1897 ArrayList<int[]> regions = new ArrayList<>();
1903 HiddenColumns hidden = alignment.getHiddenColumns();
1904 if (hidden != null && hidden.hasHiddenColumns())
1908 start = hidden.visibleToAbsoluteColumn(start);
1911 end = hidden.getNextHiddenBoundary(false, start);
1922 regions.add(new int[] { start, end });
1924 if (hidden != null && hidden.hasHiddenColumns())
1926 start = hidden.visibleToAbsoluteColumn(end);
1927 start = hidden.getNextHiddenBoundary(true, start) + 1;
1929 } while (end < max);
1931 // int[][] startEnd = new int[regions.size()][2];
1937 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1938 boolean selectedOnly)
1940 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1941 AlignmentAnnotation[] aa;
1942 if ((aa = alignment.getAlignmentAnnotation()) != null)
1944 for (AlignmentAnnotation annot : aa)
1946 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1947 if (selectedOnly && selectionGroup != null)
1949 clone.makeVisibleAnnotation(
1950 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1951 alignment.getHiddenColumns());
1955 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1964 public boolean isPadGaps()
1970 public void setPadGaps(boolean padGaps)
1972 this.padGaps = padGaps;
1976 * apply any post-edit constraints and trigger any calculations needed after
1977 * an edit has been performed on the alignment
1982 public void alignmentChanged(AlignmentViewPanel ap)
1986 alignment.padGaps();
1988 if (autoCalculateConsensus)
1990 updateConsensus(ap);
1992 if (hconsensus != null && autoCalculateConsensus)
1994 updateConservation(ap);
1996 if (autoCalculateStrucConsensus)
1998 updateStrucConsensus(ap);
2001 // Reset endRes of groups if beyond alignment width
2002 int alWidth = alignment.getWidth();
2003 List<SequenceGroup> groups = alignment.getGroups();
2006 for (SequenceGroup sg : groups)
2008 if (sg.getEndRes() > alWidth)
2010 sg.setEndRes(alWidth - 1);
2015 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
2017 selectionGroup.setEndRes(alWidth - 1);
2020 updateAllColourSchemes();
2021 calculator.restartWorkers();
2025 * reset scope and do calculations for all applied colourschemes on alignment
2027 void updateAllColourSchemes()
2029 ResidueShaderI rs = residueShading;
2032 rs.alignmentChanged(alignment, hiddenRepSequences);
2034 rs.setConsensus(hconsensus);
2035 if (rs.conservationApplied())
2037 rs.setConservation(Conservation.calculateConservation("All",
2038 alignment.getSequences(), 0, alignment.getWidth(), false,
2039 getConsPercGaps(), false));
2043 for (SequenceGroup sg : alignment.getGroups())
2047 sg.cs.alignmentChanged(sg, hiddenRepSequences);
2049 sg.recalcConservation();
2053 protected void initAutoAnnotation()
2055 // TODO: add menu option action that nulls or creates consensus object
2056 // depending on if the user wants to see the annotation or not in a
2057 // specific alignment
2059 if (hconsensus == null && !isDataset)
2061 if (!alignment.isNucleotide())
2070 consensus = new AlignmentAnnotation("Consensus",
2071 MessageManager.getString("label.consensus_descr"),
2072 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2073 initConsensus(consensus);
2077 initComplementConsensus();
2082 * If this is a protein alignment and there are mappings to cDNA, adds the
2083 * cDNA consensus annotation and returns true, else returns false.
2085 public boolean initComplementConsensus()
2087 if (!alignment.isNucleotide())
2089 final List<AlignedCodonFrame> codonMappings = alignment
2091 if (codonMappings != null && !codonMappings.isEmpty())
2093 boolean doConsensus = false;
2094 for (AlignedCodonFrame mapping : codonMappings)
2096 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2097 MapList[] mapLists = mapping.getdnaToProt();
2098 // mapLists can be empty if project load has not finished resolving
2100 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2108 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2110 .getString("label.complement_consensus_descr"),
2111 new Annotation[1], 0f, 100f,
2112 AlignmentAnnotation.BAR_GRAPH);
2113 initConsensus(complementConsensus);
2121 private void initConsensus(AlignmentAnnotation aa)
2124 aa.autoCalculated = true;
2128 alignment.addAnnotation(aa);
2132 // these should be extracted from the view model - style and settings for
2133 // derived annotation
2134 private void initGapCounts()
2138 gapcounts = new AlignmentAnnotation("Occupancy",
2139 MessageManager.getString("label.occupancy_descr"),
2140 new Annotation[1], 0f, alignment.getHeight(),
2141 AlignmentAnnotation.BAR_GRAPH);
2142 gapcounts.hasText = true;
2143 gapcounts.autoCalculated = true;
2144 gapcounts.scaleColLabel = true;
2145 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2147 alignment.addAnnotation(gapcounts);
2151 private void initConservation()
2153 if (showConservation)
2155 if (conservation == null)
2157 conservation = new AlignmentAnnotation("Conservation",
2158 MessageManager.formatMessage("label.conservation_descr",
2160 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2161 conservation.hasText = true;
2162 conservation.autoCalculated = true;
2163 alignment.addAnnotation(conservation);
2168 private void initQuality()
2172 if (quality == null)
2174 quality = new AlignmentAnnotation("Quality",
2175 MessageManager.getString("label.quality_descr"),
2176 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2177 quality.hasText = true;
2178 quality.autoCalculated = true;
2179 alignment.addAnnotation(quality);
2184 private void initRNAStructure()
2186 if (alignment.hasRNAStructure() && strucConsensus == null)
2188 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2189 MessageManager.getString("label.strucconsensus_descr"),
2190 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2191 strucConsensus.hasText = true;
2192 strucConsensus.autoCalculated = true;
2196 alignment.addAnnotation(strucConsensus);
2204 * @see jalview.api.AlignViewportI#calcPanelHeight()
2207 public int calcPanelHeight()
2209 // setHeight of panels
2210 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2212 int charHeight = getCharHeight();
2215 BitSet graphgrp = new BitSet();
2216 for (AlignmentAnnotation aa : anns)
2220 System.err.println("Null annotation row: ignoring.");
2227 if (aa.graphGroup > -1)
2229 if (graphgrp.get(aa.graphGroup))
2235 graphgrp.set(aa.graphGroup);
2242 aa.height += charHeight;
2252 aa.height += aa.graphHeight;
2260 height += aa.height;
2272 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2273 boolean preserveNewGroupSettings)
2275 boolean updateCalcs = false;
2276 boolean conv = isShowGroupConservation();
2277 boolean cons = isShowGroupConsensus();
2278 boolean showprf = isShowSequenceLogo();
2279 boolean showConsHist = isShowConsensusHistogram();
2280 boolean normLogo = isNormaliseSequenceLogo();
2281 boolean showHMMPrf = isShowHMMSequenceLogo();
2282 boolean showInfoHist = isShowInformationHistogram();
2283 boolean normHMMLogo = isNormaliseHMMSequenceLogo();
2286 * TODO reorder the annotation rows according to group/sequence ordering on
2289 // boolean sortg = true;
2291 // remove old automatic annotation
2292 // add any new annotation
2294 // intersect alignment annotation with alignment groups
2296 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2297 List<SequenceGroup> oldrfs = new ArrayList<>();
2300 for (int an = 0; an < aan.length; an++)
2302 if (aan[an].autoCalculated && aan[an].groupRef != null)
2304 oldrfs.add(aan[an].groupRef);
2305 alignment.deleteAnnotation(aan[an], false);
2309 if (alignment.getGroups() != null)
2311 for (SequenceGroup sg : alignment.getGroups())
2313 updateCalcs = false;
2314 if (applyGlobalSettings
2315 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2317 // set defaults for this group's conservation/consensus
2318 sg.setshowSequenceLogo(showprf);
2319 sg.setShowConsensusHistogram(showConsHist);
2320 sg.setNormaliseSequenceLogo(normLogo);
2321 sg.setShowHMMSequenceLogo(showHMMPrf);
2322 sg.setShowInformationHistogram(showInfoHist);
2323 sg.setNormaliseHMMSequenceLogo(normHMMLogo);
2328 alignment.addAnnotation(sg.getConservationRow(), 0);
2333 alignment.addAnnotation(sg.getConsensus(), 0);
2335 // refresh the annotation rows
2338 sg.recalcConservation();
2346 public boolean isDisplayReferenceSeq()
2348 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2352 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2354 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2358 public boolean isColourByReferenceSeq()
2360 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2364 public Color getSequenceColour(SequenceI seq)
2366 Color sqc = sequenceColours.get(seq);
2367 return (sqc == null ? Color.white : sqc);
2371 public void setSequenceColour(SequenceI seq, Color col)
2375 sequenceColours.remove(seq);
2379 sequenceColours.put(seq, col);
2384 public void updateSequenceIdColours()
2386 for (SequenceGroup sg : alignment.getGroups())
2388 if (sg.idColour != null)
2390 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2392 sequenceColours.put(s, sg.idColour);
2399 public void clearSequenceColours()
2401 sequenceColours.clear();
2405 public AlignViewportI getCodingComplement()
2407 return this.codingComplement;
2411 * Set this as the (cDna/protein) complement of the given viewport. Also
2412 * ensures the reverse relationship is set on the given viewport.
2415 public void setCodingComplement(AlignViewportI av)
2419 System.err.println("Ignoring recursive setCodingComplement request");
2423 this.codingComplement = av;
2424 // avoid infinite recursion!
2425 if (av.getCodingComplement() != this)
2427 av.setCodingComplement(this);
2433 public boolean isNucleotide()
2435 return getAlignment() == null ? false : getAlignment().isNucleotide();
2439 public FeaturesDisplayedI getFeaturesDisplayed()
2441 return featuresDisplayed;
2445 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2447 featuresDisplayed = featuresDisplayedI;
2451 public boolean areFeaturesDisplayed()
2453 return featuresDisplayed != null
2454 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2461 * features are displayed if true
2464 public void setShowSequenceFeatures(boolean b)
2466 viewStyle.setShowSequenceFeatures(b);
2470 public boolean isShowSequenceFeatures()
2472 return viewStyle.isShowSequenceFeatures();
2476 public void setShowSequenceFeaturesHeight(boolean selected)
2478 viewStyle.setShowSequenceFeaturesHeight(selected);
2482 public boolean isShowSequenceFeaturesHeight()
2484 return viewStyle.isShowSequenceFeaturesHeight();
2488 public void setShowAnnotation(boolean b)
2490 viewStyle.setShowAnnotation(b);
2494 public boolean isShowAnnotation()
2496 return viewStyle.isShowAnnotation();
2500 public boolean isRightAlignIds()
2502 return viewStyle.isRightAlignIds();
2506 public void setRightAlignIds(boolean rightAlignIds)
2508 viewStyle.setRightAlignIds(rightAlignIds);
2512 public boolean getConservationSelected()
2514 return viewStyle.getConservationSelected();
2518 public void setShowBoxes(boolean state)
2520 viewStyle.setShowBoxes(state);
2525 * @see jalview.api.ViewStyleI#getTextColour()
2528 public Color getTextColour()
2530 return viewStyle.getTextColour();
2535 * @see jalview.api.ViewStyleI#getTextColour2()
2538 public Color getTextColour2()
2540 return viewStyle.getTextColour2();
2545 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2548 public int getThresholdTextColour()
2550 return viewStyle.getThresholdTextColour();
2555 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2558 public boolean isConservationColourSelected()
2560 return viewStyle.isConservationColourSelected();
2565 * @see jalview.api.ViewStyleI#isRenderGaps()
2568 public boolean isRenderGaps()
2570 return viewStyle.isRenderGaps();
2575 * @see jalview.api.ViewStyleI#isShowColourText()
2578 public boolean isShowColourText()
2580 return viewStyle.isShowColourText();
2584 * @param conservationColourSelected
2585 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2588 public void setConservationColourSelected(
2589 boolean conservationColourSelected)
2591 viewStyle.setConservationColourSelected(conservationColourSelected);
2595 * @param showColourText
2596 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2599 public void setShowColourText(boolean showColourText)
2601 viewStyle.setShowColourText(showColourText);
2606 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2609 public void setTextColour(Color textColour)
2611 viewStyle.setTextColour(textColour);
2615 * @param thresholdTextColour
2616 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2619 public void setThresholdTextColour(int thresholdTextColour)
2621 viewStyle.setThresholdTextColour(thresholdTextColour);
2625 * @param textColour2
2626 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2629 public void setTextColour2(Color textColour2)
2631 viewStyle.setTextColour2(textColour2);
2635 public ViewStyleI getViewStyle()
2637 return new ViewStyle(viewStyle);
2641 public void setViewStyle(ViewStyleI settingsForView)
2643 viewStyle = new ViewStyle(settingsForView);
2644 if (residueShading != null)
2646 residueShading.setConservationApplied(
2647 settingsForView.isConservationColourSelected());
2652 public boolean sameStyle(ViewStyleI them)
2654 return viewStyle.sameStyle(them);
2659 * @see jalview.api.ViewStyleI#getIdWidth()
2662 public int getIdWidth()
2664 return viewStyle.getIdWidth();
2669 * @see jalview.api.ViewStyleI#setIdWidth(int)
2672 public void setIdWidth(int i)
2674 viewStyle.setIdWidth(i);
2679 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2682 public boolean isCentreColumnLabels()
2684 return viewStyle.isCentreColumnLabels();
2688 * @param centreColumnLabels
2689 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2692 public void setCentreColumnLabels(boolean centreColumnLabels)
2694 viewStyle.setCentreColumnLabels(centreColumnLabels);
2699 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2702 public void setShowDBRefs(boolean showdbrefs)
2704 viewStyle.setShowDBRefs(showdbrefs);
2709 * @see jalview.api.ViewStyleI#isShowDBRefs()
2712 public boolean isShowDBRefs()
2714 return viewStyle.isShowDBRefs();
2719 * @see jalview.api.ViewStyleI#isShowNPFeats()
2722 public boolean isShowNPFeats()
2724 return viewStyle.isShowNPFeats();
2728 * @param shownpfeats
2729 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2732 public void setShowNPFeats(boolean shownpfeats)
2734 viewStyle.setShowNPFeats(shownpfeats);
2737 public abstract StructureSelectionManager getStructureSelectionManager();
2740 * Add one command to the command history list.
2744 public void addToHistoryList(CommandI command)
2746 if (this.historyList != null)
2748 this.historyList.push(command);
2749 broadcastCommand(command, false);
2753 protected void broadcastCommand(CommandI command, boolean undo)
2755 getStructureSelectionManager().commandPerformed(command, undo,
2760 * Add one command to the command redo list.
2764 public void addToRedoList(CommandI command)
2766 if (this.redoList != null)
2768 this.redoList.push(command);
2770 broadcastCommand(command, true);
2774 * Clear the command redo list.
2776 public void clearRedoList()
2778 if (this.redoList != null)
2780 this.redoList.clear();
2784 public void setHistoryList(Deque<CommandI> list)
2786 this.historyList = list;
2789 public Deque<CommandI> getHistoryList()
2791 return this.historyList;
2794 public void setRedoList(Deque<CommandI> list)
2796 this.redoList = list;
2799 public Deque<CommandI> getRedoList()
2801 return this.redoList;
2805 public VamsasSource getVamsasSource()
2810 public SequenceAnnotationOrder getSortAnnotationsBy()
2812 return sortAnnotationsBy;
2815 public void setSortAnnotationsBy(
2816 SequenceAnnotationOrder sortAnnotationsBy)
2818 this.sortAnnotationsBy = sortAnnotationsBy;
2821 public boolean isShowAutocalculatedAbove()
2823 return showAutocalculatedAbove;
2826 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2828 this.showAutocalculatedAbove = showAutocalculatedAbove;
2832 public boolean isScaleProteinAsCdna()
2834 return viewStyle.isScaleProteinAsCdna();
2838 public void setScaleProteinAsCdna(boolean b)
2840 viewStyle.setScaleProteinAsCdna(b);
2844 public boolean isProteinFontAsCdna()
2846 return viewStyle.isProteinFontAsCdna();
2850 public void setProteinFontAsCdna(boolean b)
2852 viewStyle.setProteinFontAsCdna(b);
2856 public void setShowComplementFeatures(boolean b)
2858 viewStyle.setShowComplementFeatures(b);
2862 public boolean isShowComplementFeatures()
2864 return viewStyle.isShowComplementFeatures();
2868 public void setShowComplementFeaturesOnTop(boolean b)
2870 viewStyle.setShowComplementFeaturesOnTop(b);
2874 public boolean isShowComplementFeaturesOnTop()
2876 return viewStyle.isShowComplementFeaturesOnTop();
2880 * @return true if view should scroll to show the highlighted region of a
2885 public final boolean isFollowHighlight()
2887 return followHighlight;
2891 public final void setFollowHighlight(boolean b)
2893 this.followHighlight = b;
2897 public ViewportRanges getRanges()
2903 * Helper method to populate the SearchResults with the location in the
2904 * complementary alignment to scroll to, in order to match this one.
2907 * the SearchResults to add to
2908 * @return the offset (below top of visible region) of the matched sequence
2910 protected int findComplementScrollTarget(SearchResultsI sr)
2912 final AlignViewportI complement = getCodingComplement();
2913 if (complement == null || !complement.isFollowHighlight())
2917 boolean iAmProtein = !getAlignment().isNucleotide();
2918 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2919 : complement.getAlignment();
2920 if (proteinAlignment == null)
2924 final List<AlignedCodonFrame> mappings = proteinAlignment
2928 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2929 * residue in the middle column of the visible region. Scroll the
2930 * complementary alignment to line up the corresponding residue.
2933 SequenceI sequence = null;
2936 * locate 'middle' column (true middle if an odd number visible, left of
2937 * middle if an even number visible)
2939 int middleColumn = ranges.getStartRes()
2940 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2941 final HiddenSequences hiddenSequences = getAlignment()
2942 .getHiddenSequences();
2945 * searching to the bottom of the alignment gives smoother scrolling across
2946 * all gapped visible regions
2948 int lastSeq = alignment.getHeight() - 1;
2949 List<AlignedCodonFrame> seqMappings = null;
2950 for (int seqNo = ranges
2951 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2953 sequence = getAlignment().getSequenceAt(seqNo);
2954 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2958 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2962 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2964 getCodingComplement().getAlignment().getSequences());
2965 if (!seqMappings.isEmpty())
2971 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2974 * No ungapped mapped sequence in middle column - do nothing
2978 MappingUtils.addSearchResults(sr, sequence,
2979 sequence.findPosition(middleColumn), seqMappings);
2984 * synthesize a column selection if none exists so it covers the given
2985 * selection group. if wholewidth is false, no column selection is made if the
2986 * selection group covers the whole alignment width.
2991 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2994 if (sg != null && (sgs = sg.getStartRes()) >= 0
2995 && sg.getStartRes() <= (sge = sg.getEndRes())
2996 && !this.hasSelectedColumns())
2998 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
3005 colSel = new ColumnSelection();
3007 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
3009 colSel.addElement(cspos);
3015 * hold status of current selection group - defined on alignment or not.
3017 private boolean selectionIsDefinedGroup = false;
3020 public boolean isSelectionDefinedGroup()
3022 if (selectionGroup == null)
3026 if (isSelectionGroupChanged(true))
3028 selectionIsDefinedGroup = false;
3029 List<SequenceGroup> gps = alignment.getGroups();
3030 if (gps == null || gps.size() == 0)
3032 selectionIsDefinedGroup = false;
3036 selectionIsDefinedGroup = gps.contains(selectionGroup);
3039 return selectionGroup.isDefined() || selectionIsDefinedGroup;
3043 * null, or currently highlighted results on this view
3045 private SearchResultsI searchResults = null;
3047 protected TreeModel currentTree = null;
3050 public boolean hasSearchResults()
3052 return searchResults != null;
3056 public void setSearchResults(SearchResultsI results)
3058 searchResults = results;
3062 public SearchResultsI getSearchResults()
3064 return searchResults;
3068 * get the consensus sequence as displayed under the PID consensus annotation
3071 * @return consensus sequence as a new sequence object
3073 public SequenceI getConsensusSeq()
3075 if (consensus == null)
3077 updateConsensus(null);
3079 if (consensus == null)
3083 StringBuffer seqs = new StringBuffer();
3084 for (int i = 0; i < consensus.annotations.length; i++)
3086 Annotation annotation = consensus.annotations[i];
3087 if (annotation != null)
3089 String description = annotation.description;
3090 if (description != null && description.startsWith("["))
3092 // consensus is a tie - just pick the first one
3093 seqs.append(description.charAt(1));
3097 seqs.append(annotation.displayCharacter);
3102 SequenceI sq = new Sequence("Consensus", seqs.toString());
3103 sq.setDescription("Percentage Identity Consensus "
3104 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3108 public boolean hasReferenceAnnotation()
3110 AlignmentAnnotation[] annots = this.alignment.getAlignmentAnnotation();
3111 for (AlignmentAnnotation annot : annots)
3113 if ("RF".equals(annot.label) || annot.label.contains("Reference"))
3122 public void setCurrentTree(TreeModel tree)
3128 public TreeModel getCurrentTree()
3134 public AlignmentExportData getAlignExportData(AlignExportSettingsI options)
3136 AlignmentI alignmentToExport = null;
3137 String[] omitHidden = null;
3138 alignmentToExport = null;
3140 if (hasHiddenColumns() && !options.isExportHiddenColumns())
3142 omitHidden = getViewAsString(false,
3143 options.isExportHiddenSequences());
3146 int[] alignmentStartEnd = new int[2];
3147 if (hasHiddenRows() && options.isExportHiddenSequences())
3149 alignmentToExport = getAlignment().getHiddenSequences()
3150 .getFullAlignment();
3154 alignmentToExport = getAlignment();
3156 alignmentStartEnd = getAlignment().getHiddenColumns()
3157 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
3158 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
3159 omitHidden, alignmentStartEnd);
3164 public boolean isNormaliseSequenceLogo()
3166 return normaliseSequenceLogo;
3169 public void setNormaliseSequenceLogo(boolean state)
3171 normaliseSequenceLogo = state;
3175 public boolean isNormaliseHMMSequenceLogo()
3177 return hmmNormaliseSequenceLogo;
3180 public void setNormaliseHMMSequenceLogo(boolean state)
3182 hmmNormaliseSequenceLogo = state;
3185 * flag set to indicate if structure views might be out of sync with sequences
3189 private boolean needToUpdateStructureViews = false;
3192 public boolean isUpdateStructures()
3194 return needToUpdateStructureViews;
3198 public void setUpdateStructures(boolean update)
3200 needToUpdateStructureViews = update;
3204 public boolean needToUpdateStructureViews()
3206 boolean update = needToUpdateStructureViews;
3207 needToUpdateStructureViews = false;
3212 public void addSequenceGroup(SequenceGroup sequenceGroup)
3214 alignment.addGroup(sequenceGroup);
3216 Color col = sequenceGroup.idColour;
3219 col = col.brighter();
3221 for (SequenceI sq : sequenceGroup.getSequences())
3223 setSequenceColour(sq, col);
3227 if (codingComplement != null)
3229 SequenceGroup mappedGroup = MappingUtils
3230 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3231 if (mappedGroup.getSequences().size() > 0)
3233 codingComplement.getAlignment().addGroup(mappedGroup);
3237 for (SequenceI seq : mappedGroup.getSequences())
3239 codingComplement.setSequenceColour(seq, col);
3243 // propagate the structure view update flag according to our own setting
3244 codingComplement.setUpdateStructures(needToUpdateStructureViews);
3249 * Filters out sequences with an eValue higher than the specified value. The
3250 * filtered sequences are hidden or deleted. Sequences with no eValues are also
3256 public void filterByEvalue(double eValue)
3258 for (SequenceI seq : alignment.getSequencesArray())
3260 if ((seq.getAnnotation("Search Scores") == null
3261 || seq.getAnnotation("Search Scores")[0].getEValue() > eValue)
3262 && seq.getHMM() == null)
3264 hideSequence(new SequenceI[] { seq });
3270 * Filters out sequences with an score lower than the specified value. The
3271 * filtered sequences are hidden or deleted.
3276 public void filterByScore(double score)
3278 for (SequenceI seq : alignment.getSequencesArray())
3280 if ((seq.getAnnotation("Search Scores") == null
3281 || seq.getAnnotation("Search Scores")[0]
3282 .getBitScore() < score)
3283 && seq.getHMM() == null)
3285 hideSequence(new SequenceI[] { seq });