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;
79 * base class holding visualization and analysis attributes and common logic for
80 * an active alignment view displayed in the GUI
85 public abstract class AlignmentViewport
86 implements AlignViewportI, CommandListener, VamsasSource
88 public static final String PROPERTY_ALIGNMENT = "alignment";
89 public static final String PROPERTY_SEQUENCE = "sequence";
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;
620 public void setDataset(boolean b)
625 public boolean isDataset()
630 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
632 protected ColumnSelection colSel = new ColumnSelection();
634 protected boolean autoCalculateConsensusAndConservation = true;
636 public boolean getAutoCalculateConsensusAndConservation()
638 return autoCalculateConsensusAndConservation;
641 public void setAutoCalculateConsensusAndConservation(boolean b)
643 autoCalculateConsensusAndConservation = b;
646 protected boolean autoCalculateStrucConsensus = true;
648 public boolean getAutoCalculateStrucConsensus()
650 return autoCalculateStrucConsensus;
653 public void setAutoCalculateStrucConsensus(boolean b)
655 autoCalculateStrucConsensus = b;
657 protected boolean ignoreGapsInConsensusCalculation = false;
659 protected ResidueShaderI residueShading = new ResidueShader();
663 public void setGlobalColourScheme(ColourSchemeI cs)
665 // TODO: logic refactored from AlignFrame changeColour -
666 // TODO: autorecalc stuff should be changed to rely on the worker system
667 // check to see if we should implement a changeColour(cs) method rather than
668 // put the logic in here
669 // - means that caller decides if they want to just modify state and defer
670 // calculation till later or to do all calculations in thread.
674 * only instantiate alignment colouring once, thereafter update it;
675 * this means that any conservation or PID threshold settings
676 * persist when the alignment colour scheme is changed
678 if (residueShading == null)
680 residueShading = new ResidueShader(viewStyle);
682 residueShading.setColourScheme(cs);
684 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
685 // ...problem: groups need these, but do not currently have a ViewStyle
689 if (getConservationSelected())
691 residueShading.setConservation(hconservation);
694 * reset conservation flag in case just set to false if
695 * Conservation was null (calculation still in progress)
697 residueShading.setConservationApplied(getConservationSelected());
698 residueShading.alignmentChanged(alignment, hiddenRepSequences);
702 * if 'apply colour to all groups' is selected... do so
703 * (but don't transfer any colour threshold settings to groups)
705 if (getColourAppliesToAllGroups())
707 for (SequenceGroup sg : getAlignment().getGroups())
710 * retain any colour thresholds per group while
711 * changing choice of colour scheme (JAL-2386)
714 cs == null ? null : cs.getInstance(this, sg));
717 sg.getGroupColourScheme().alignmentChanged(sg,
725 public ColourSchemeI getGlobalColourScheme()
727 return residueShading == null ? null : residueShading.getColourScheme();
731 public ResidueShaderI getResidueShading()
733 return residueShading;
737 protected AlignmentAnnotation consensus;
739 protected AlignmentAnnotation complementConsensus;
741 protected AlignmentAnnotation gapcounts;
743 protected AlignmentAnnotation strucConsensus;
745 protected AlignmentAnnotation conservation;
747 protected AlignmentAnnotation quality;
749 protected AlignmentAnnotation[] groupConsensus;
751 protected AlignmentAnnotation[] groupConservation;
754 * results of alignment consensus analysis for visible portion of view
756 protected ProfilesI hconsensus = null;
759 * results of cDNA complement consensus visible portion of view
761 protected Hashtable<String, Object>[] hcomplementConsensus = null;
764 * results of secondary structure base pair consensus for visible portion of
767 protected Hashtable<String, Object>[] hStrucConsensus = null;
769 protected Conservation hconservation = null;
773 public void setConservation(Conservation cons)
775 hconservation = cons;
779 * percentage gaps allowed in a column before all amino acid properties should
780 * be considered unconserved
782 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
785 public int getConsPercGaps()
791 public void setSequenceConsensusHash(ProfilesI hconsensus)
793 this.hconsensus = hconsensus;
797 public void setComplementConsensusHash(
798 Hashtable<String, Object>[] hconsensus)
800 this.hcomplementConsensus = hconsensus;
804 public ProfilesI getSequenceConsensusHash()
810 public void setHmmProfiles(ProfilesI info)
816 public ProfilesI getHmmProfiles()
822 public Hashtable<String, Object>[] getComplementConsensusHash()
824 return hcomplementConsensus;
828 public Hashtable<String, Object>[] getRnaStructureConsensusHash()
830 return hStrucConsensus;
834 public void setRnaStructureConsensusHash(
835 Hashtable<String, Object>[] hStrucConsensus)
837 this.hStrucConsensus = hStrucConsensus;
842 public AlignmentAnnotation getAlignmentQualityAnnot()
848 public AlignmentAnnotation getAlignmentConservationAnnotation()
854 public AlignmentAnnotation getAlignmentConsensusAnnotation()
860 public AlignmentAnnotation getAlignmentGapAnnotation()
866 public AlignmentAnnotation getComplementConsensusAnnotation()
868 return complementConsensus;
872 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
874 return strucConsensus;
877 protected AlignCalcManagerI2 calculator = new AlignCalcManager2();
880 * trigger update of conservation annotation
882 public void updateConservation(final AlignmentViewPanel ap)
884 // see note in mantis : issue number 8585
885 if (alignment.isNucleotide()
886 || (conservation == null && quality == null)
887 || !autoCalculateConsensusAndConservation)
891 if (calculator.getWorkersOfClass(
892 jalview.workers.ConservationThread.class).isEmpty())
894 calculator.registerWorker(
895 new jalview.workers.ConservationThread(this, ap));
900 * trigger update of consensus annotation
902 public void updateConsensus(final AlignmentViewPanel ap)
904 // see note in mantis : issue number 8585
905 if (consensus == null || !autoCalculateConsensusAndConservation)
909 if (calculator.getWorkersOfClass(ConsensusThread.class).isEmpty())
911 calculator.registerWorker(new ConsensusThread(this, ap));
915 * A separate thread to compute cDNA consensus for a protein alignment
916 * which has mapping to cDNA
918 final AlignmentI al = this.getAlignment();
919 if (!al.isNucleotide() && al.getCodonFrames() != null
920 && !al.getCodonFrames().isEmpty())
923 * fudge - check first for protein-to-nucleotide mappings
924 * (we don't want to do this for protein-to-protein)
926 boolean doConsensus = false;
927 for (AlignedCodonFrame mapping : al.getCodonFrames())
929 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
930 MapList[] mapLists = mapping.getdnaToProt();
931 // mapLists can be empty if project load has not finished resolving seqs
932 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
940 if (calculator.getWorkersOfClass(ComplementConsensusThread.class).isEmpty())
942 calculator.registerWorker(new ComplementConsensusThread(this, ap));
949 public void initInformationWorker(final AlignmentViewPanel ap)
951 if (calculator.getWorkersOfClass(InformationThread.class).isEmpty())
953 calculator.registerWorker(new InformationThread(this, ap));
956 // --------START Structure Conservation
957 public void updateStrucConsensus(final AlignmentViewPanel ap)
959 if (autoCalculateStrucConsensus && strucConsensus == null
960 && alignment.isNucleotide() && alignment.hasRNAStructure())
962 // secondary structure has been added - so init the consensus line
966 // see note in mantis : issue number 8585
967 if (strucConsensus == null || !autoCalculateStrucConsensus)
971 if (calculator.getWorkersOfClass(StrucConsensusThread.class).isEmpty())
973 calculator.registerWorker(new StrucConsensusThread(this, ap));
977 public boolean isCalcInProgress()
979 return calculator.isWorking();
983 public boolean isCalculationInProgress(
984 AlignmentAnnotation alignmentAnnotation)
986 if (!alignmentAnnotation.autoCalculated)
990 if (calculator.isWorkingWithAnnotation(alignmentAnnotation))
992 // System.err.println("grey out ("+alignmentAnnotation.label+")");
998 public void setAlignment(AlignmentI align)
1000 this.alignment = align;
1004 * Clean up references when this viewport is closed
1007 public void dispose()
1010 * defensively null out references to large objects in case
1011 * this object is not garbage collected (as if!)
1014 complementConsensus = null;
1015 strucConsensus = null;
1016 conservation = null;
1018 consensusProfiles = null;
1019 groupConsensus = null;
1020 groupConservation = null;
1022 hconservation = null;
1023 hcomplementConsensus = null;
1025 calculator.shutdown();
1027 residueShading = null; // may hold a reference to Consensus
1028 changeSupport = null;
1031 selectionGroup = null;
1036 public boolean isClosed()
1038 // TODO: check that this isClosed is only true after panel is closed, not
1039 // before it is fully constructed.
1040 return alignment == null;
1044 public AlignCalcManagerI2 getCalcManager()
1050 * should conservation rows be shown for groups
1052 protected boolean showGroupConservation = false;
1055 * should consensus rows be shown for groups
1057 protected boolean showGroupConsensus = false;
1060 * should consensus profile be rendered by default
1062 protected boolean showSequenceLogo = false;
1065 * should consensus profile be rendered normalised to row height
1067 protected boolean normaliseSequenceLogo = false;
1070 * should consensus histograms be rendered by default
1072 protected boolean showConsensusHistogram = true;
1075 * should hmm profile be rendered by default
1077 protected boolean hmmShowSequenceLogo = false;
1080 * should hmm profile be rendered normalised to row height
1082 protected boolean hmmNormaliseSequenceLogo = false;
1085 * should information histograms be rendered by default
1087 protected boolean hmmShowHistogram = true;
1090 * @return the showConsensusProfile
1093 public boolean isShowSequenceLogo()
1095 return showSequenceLogo;
1099 * @return the showInformationProfile
1102 public boolean isShowHMMSequenceLogo()
1104 return hmmShowSequenceLogo;
1108 * @param showSequenceLogo
1111 public void setShowSequenceLogo(boolean showSequenceLogo)
1113 if (showSequenceLogo != this.showSequenceLogo)
1115 // TODO: decouple settings setting from calculation when refactoring
1116 // annotation update method from alignframe to viewport
1117 this.showSequenceLogo = showSequenceLogo;
1118 for (AlignCalcWorkerI worker : calculator.getWorkers())
1120 if (worker.getClass().equals(ConsensusThread.class) ||
1121 worker.getClass().equals(ComplementConsensusThread.class) ||
1122 worker.getClass().equals(StrucConsensusThread.class))
1124 worker.updateAnnotation();
1128 this.showSequenceLogo = showSequenceLogo;
1131 public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo)
1133 if (showHMMSequenceLogo != this.hmmShowSequenceLogo)
1135 this.hmmShowSequenceLogo = showHMMSequenceLogo;
1136 // TODO: updateAnnotation if description (tooltip) will show
1137 // profile in place of information content?
1138 // calculator.updateAnnotationFor(InformationThread.class);
1140 this.hmmShowSequenceLogo = showHMMSequenceLogo;
1143 * @param showConsensusHistogram
1144 * the showConsensusHistogram to set
1146 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1148 this.showConsensusHistogram = showConsensusHistogram;
1152 * @param showInformationHistogram
1154 public void setShowInformationHistogram(boolean showInformationHistogram)
1156 this.hmmShowHistogram = showInformationHistogram;
1160 * @return the showGroupConservation
1162 public boolean isShowGroupConservation()
1164 return showGroupConservation;
1168 * @param showGroupConservation
1169 * the showGroupConservation to set
1171 public void setShowGroupConservation(boolean showGroupConservation)
1173 this.showGroupConservation = showGroupConservation;
1177 * @return the showGroupConsensus
1179 public boolean isShowGroupConsensus()
1181 return showGroupConsensus;
1185 * @param showGroupConsensus
1186 * the showGroupConsensus to set
1188 public void setShowGroupConsensus(boolean showGroupConsensus)
1190 this.showGroupConsensus = showGroupConsensus;
1195 * @return flag to indicate if the consensus histogram should be rendered by
1199 public boolean isShowConsensusHistogram()
1201 return this.showConsensusHistogram;
1206 * @return flag to indicate if the information content histogram should be
1207 * rendered by default
1210 public boolean isShowInformationHistogram()
1212 return this.hmmShowHistogram;
1216 * when set, updateAlignment will always ensure sequences are of equal length
1218 private boolean padGaps = false;
1221 * when set, alignment should be reordered according to a newly opened tree
1223 public boolean sortByTree = false;
1228 * @return null or the currently selected sequence region
1231 public SequenceGroup getSelectionGroup()
1233 return selectionGroup;
1237 * Set the selection group for this window. Also sets the current alignment as
1238 * the context for the group, if it does not already have one.
1241 * - group holding references to sequences in this alignment view
1245 public void setSelectionGroup(SequenceGroup sg)
1247 selectionGroup = sg;
1248 if (sg != null && sg.getContext() == null)
1250 sg.setContext(alignment);
1254 public void setHiddenColumns(HiddenColumns hidden)
1256 this.alignment.setHiddenColumns(hidden);
1260 public ColumnSelection getColumnSelection()
1266 public void setColumnSelection(ColumnSelection colSel)
1268 this.colSel = colSel;
1271 updateHiddenColumns();
1273 isColSelChanged(true);
1281 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1283 return hiddenRepSequences;
1287 public void setHiddenRepSequences(
1288 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1290 this.hiddenRepSequences = hiddenRepSequences;
1294 public boolean hasSelectedColumns()
1296 ColumnSelection columnSelection = getColumnSelection();
1297 return columnSelection != null && columnSelection.hasSelectedColumns();
1301 public boolean hasHiddenColumns()
1303 return alignment.getHiddenColumns() != null
1304 && alignment.getHiddenColumns().hasHiddenColumns();
1307 public void updateHiddenColumns()
1309 // this method doesn't really do anything now. But - it could, since a
1310 // column Selection could be in the process of modification
1311 // hasHiddenColumns = colSel.hasHiddenColumns();
1315 public boolean hasHiddenRows()
1317 return alignment.getHiddenSequences().getSize() > 0;
1320 protected SequenceGroup selectionGroup;
1322 public void setSequenceSetId(String newid)
1324 if (sequenceSetID != null)
1327 "Warning - overwriting a sequenceSetId for a viewport!");
1329 sequenceSetID = new String(newid);
1333 public String getSequenceSetId()
1335 if (sequenceSetID == null)
1337 sequenceSetID = alignment.hashCode() + "";
1340 return sequenceSetID;
1344 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1347 protected String viewId = null;
1350 public String getViewId()
1354 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1359 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1361 ignoreGapsInConsensusCalculation = b;
1364 updateConsensus(ap);
1365 if (residueShading != null)
1367 residueShading.setThreshold(residueShading.getThreshold(),
1368 ignoreGapsInConsensusCalculation);
1373 public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap)
1375 ignoreBelowBackGroundFrequencyCalculation = b;
1378 public void setInfoLetterHeight(boolean b, AlignmentViewPanel ap)
1380 infoLetterHeight = b;
1383 private long sgrouphash = -1, colselhash = -1;
1386 * checks current SelectionGroup against record of last hash value, and
1390 * update the record of last hash value
1392 * @return true if SelectionGroup changed since last call (when b is true)
1394 public boolean isSelectionGroupChanged(boolean b)
1396 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1397 : selectionGroup.hashCode();
1398 if (hc != -1 && hc != sgrouphash)
1410 * checks current colsel against record of last hash value, and optionally
1414 * update the record of last hash value
1415 * @return true if colsel changed since last call (when b is true)
1417 public boolean isColSelChanged(boolean updateHash)
1419 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1420 if (hc != -1 && hc != colselhash)
1433 public boolean isIgnoreGapsConsensus()
1435 return ignoreGapsInConsensusCalculation;
1439 public boolean isIgnoreBelowBackground()
1441 return ignoreBelowBackGroundFrequencyCalculation;
1445 public boolean isInfoLetterHeight()
1447 return infoLetterHeight;
1449 // property change stuff
1450 // JBPNote Prolly only need this in the applet version.
1451 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1454 protected boolean showConservation = true;
1456 protected boolean showQuality = true;
1458 protected boolean showConsensus = true;
1460 protected boolean showOccupancy = true;
1462 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1464 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1466 protected boolean showAutocalculatedAbove;
1469 * when set, view will scroll to show the highlighted position
1471 private boolean followHighlight = true;
1474 * Property change listener for changes in alignment
1479 public void addPropertyChangeListener(
1480 java.beans.PropertyChangeListener listener)
1482 changeSupport.addPropertyChangeListener(listener);
1491 public void removePropertyChangeListener(
1492 java.beans.PropertyChangeListener listener)
1494 if (changeSupport != null)
1496 changeSupport.removePropertyChangeListener(listener);
1501 // common hide/show column stuff
1503 public void hideSelectedColumns()
1505 if (colSel.isEmpty())
1510 colSel.hideSelectedColumns(alignment);
1511 setSelectionGroup(null);
1512 isColSelChanged(true);
1515 public void hideColumns(int start, int end)
1519 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1523 alignment.getHiddenColumns().hideColumns(start, end);
1525 isColSelChanged(true);
1528 public void showColumn(int col)
1530 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1531 isColSelChanged(true);
1534 public void showAllHiddenColumns()
1536 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1537 isColSelChanged(true);
1540 // common hide/show seq stuff
1541 public void showAllHiddenSeqs()
1543 int startSeq = ranges.getStartSeq();
1544 int endSeq = ranges.getEndSeq();
1546 if (alignment.getHiddenSequences().getSize() > 0)
1548 if (selectionGroup == null)
1550 selectionGroup = new SequenceGroup();
1551 selectionGroup.setEndRes(alignment.getWidth() - 1);
1553 List<SequenceI> tmp = alignment.getHiddenSequences()
1554 .showAll(hiddenRepSequences);
1555 for (SequenceI seq : tmp)
1557 selectionGroup.addSequence(seq, false);
1558 setSequenceAnnotationsVisible(seq, true);
1561 hiddenRepSequences = null;
1563 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1565 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1572 public void showSequence(int index)
1574 int startSeq = ranges.getStartSeq();
1575 int endSeq = ranges.getEndSeq();
1577 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1578 hiddenRepSequences);
1581 if (selectionGroup == null)
1583 selectionGroup = new SequenceGroup();
1584 selectionGroup.setEndRes(alignment.getWidth() - 1);
1587 for (SequenceI seq : tmp)
1589 selectionGroup.addSequence(seq, false);
1590 setSequenceAnnotationsVisible(seq, true);
1593 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1600 public void hideAllSelectedSeqs()
1602 if (selectionGroup == null || selectionGroup.getSize() < 1)
1607 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1611 setSelectionGroup(null);
1614 public void hideSequence(SequenceI[] seq)
1617 * cache offset to first visible sequence
1619 int startSeq = ranges.getStartSeq();
1623 for (int i = 0; i < seq.length; i++)
1625 alignment.getHiddenSequences().hideSequence(seq[i]);
1626 setSequenceAnnotationsVisible(seq[i], false);
1628 ranges.setStartSeq(startSeq);
1634 * Hides the specified sequence, or the sequences it represents
1637 * the sequence to hide, or keep as representative
1638 * @param representGroup
1639 * if true, hide the current selection group except for the
1640 * representative sequence
1642 public void hideSequences(SequenceI sequence, boolean representGroup)
1644 if (selectionGroup == null || selectionGroup.getSize() < 1)
1646 hideSequence(new SequenceI[] { sequence });
1652 hideRepSequences(sequence, selectionGroup);
1653 setSelectionGroup(null);
1657 int gsize = selectionGroup.getSize();
1658 SequenceI[] hseqs = selectionGroup.getSequences()
1659 .toArray(new SequenceI[gsize]);
1661 hideSequence(hseqs);
1662 setSelectionGroup(null);
1667 * Set visibility for any annotations for the given sequence.
1671 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1674 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1677 for (AlignmentAnnotation ann : anns)
1679 if (ann.sequenceRef == sequenceI)
1681 ann.visible = visible;
1687 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1689 int sSize = sg.getSize();
1695 if (hiddenRepSequences == null)
1697 hiddenRepSequences = new Hashtable<>();
1700 hiddenRepSequences.put(repSequence, sg);
1702 // Hide all sequences except the repSequence
1703 SequenceI[] seqs = new SequenceI[sSize - 1];
1705 for (int i = 0; i < sSize; i++)
1707 if (sg.getSequenceAt(i) != repSequence)
1709 if (index == sSize - 1)
1714 seqs[index++] = sg.getSequenceAt(i);
1717 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1718 sg.setHidereps(true); // note: not done in 2.7applet
1725 * @return null or the current reference sequence
1727 public SequenceI getReferenceSeq()
1729 return alignment.getSeqrep();
1734 * @return true iff seq is the reference for the alignment
1736 public boolean isReferenceSeq(SequenceI seq)
1738 return alignment.getSeqrep() == seq;
1744 * @return true if there are sequences represented by this sequence that are
1747 public boolean isHiddenRepSequence(SequenceI seq)
1749 return (hiddenRepSequences != null
1750 && hiddenRepSequences.containsKey(seq));
1756 * @return null or a sequence group containing the sequences that seq
1759 public SequenceGroup getRepresentedSequences(SequenceI seq)
1761 return (SequenceGroup) (hiddenRepSequences == null ? null
1762 : hiddenRepSequences.get(seq));
1766 public int adjustForHiddenSeqs(int alignmentIndex)
1768 return alignment.getHiddenSequences()
1769 .adjustForHiddenSeqs(alignmentIndex);
1773 public void invertColumnSelection()
1775 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1776 isColSelChanged(true);
1780 public SequenceI[] getSelectionAsNewSequence()
1782 SequenceI[] sequences;
1783 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1784 // this was the only caller in the applet for this method
1785 // JBPNote: in applet, this method returned references to the alignment
1786 // sequences, and it did not honour the presence/absence of annotation
1787 // attached to the alignment (probably!)
1788 if (selectionGroup == null || selectionGroup.getSize() == 0)
1790 sequences = alignment.getSequencesArray();
1791 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1792 for (int i = 0; i < sequences.length; i++)
1794 // construct new sequence with subset of visible annotation
1795 sequences[i] = new Sequence(sequences[i], annots);
1800 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1807 public SequenceI[] getSequenceSelection()
1809 SequenceI[] sequences = null;
1810 if (selectionGroup != null)
1812 sequences = selectionGroup.getSequencesInOrder(alignment);
1814 if (sequences == null)
1816 sequences = alignment.getSequencesArray();
1822 public jalview.datamodel.AlignmentView getAlignmentView(
1823 boolean selectedOnly)
1825 return getAlignmentView(selectedOnly, false);
1829 public jalview.datamodel.AlignmentView getAlignmentView(
1830 boolean selectedOnly, boolean markGroups)
1832 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1834 alignment.getHiddenColumns() != null
1835 && alignment.getHiddenColumns().hasHiddenColumns(),
1836 selectedOnly, markGroups);
1840 public String[] getViewAsString(boolean selectedRegionOnly)
1842 return getViewAsString(selectedRegionOnly, true);
1846 public String[] getViewAsString(boolean selectedRegionOnly,
1847 boolean exportHiddenSeqs)
1849 String[] selection = null;
1850 SequenceI[] seqs = null;
1852 int start = 0, end = 0;
1853 if (selectedRegionOnly && selectionGroup != null)
1855 iSize = selectionGroup.getSize();
1856 seqs = selectionGroup.getSequencesInOrder(alignment);
1857 start = selectionGroup.getStartRes();
1858 end = selectionGroup.getEndRes() + 1;
1862 if (hasHiddenRows() && exportHiddenSeqs)
1864 AlignmentI fullAlignment = alignment.getHiddenSequences()
1865 .getFullAlignment();
1866 iSize = fullAlignment.getHeight();
1867 seqs = fullAlignment.getSequencesArray();
1868 end = fullAlignment.getWidth();
1872 iSize = alignment.getHeight();
1873 seqs = alignment.getSequencesArray();
1874 end = alignment.getWidth();
1878 selection = new String[iSize];
1879 if (alignment.getHiddenColumns() != null
1880 && alignment.getHiddenColumns().hasHiddenColumns())
1882 for (i = 0; i < iSize; i++)
1884 Iterator<int[]> blocks = alignment.getHiddenColumns()
1885 .getVisContigsIterator(start, end + 1, false);
1886 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1891 for (i = 0; i < iSize; i++)
1893 selection[i] = seqs[i].getSequenceAsString(start, end);
1901 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1903 ArrayList<int[]> regions = new ArrayList<>();
1909 HiddenColumns hidden = alignment.getHiddenColumns();
1910 if (hidden != null && hidden.hasHiddenColumns())
1914 start = hidden.visibleToAbsoluteColumn(start);
1917 end = hidden.getNextHiddenBoundary(false, start);
1928 regions.add(new int[] { start, end });
1930 if (hidden != null && hidden.hasHiddenColumns())
1932 start = hidden.visibleToAbsoluteColumn(end);
1933 start = hidden.getNextHiddenBoundary(true, start) + 1;
1935 } while (end < max);
1937 // int[][] startEnd = new int[regions.size()][2];
1943 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1944 boolean selectedOnly)
1946 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1947 AlignmentAnnotation[] aa;
1948 if ((aa = alignment.getAlignmentAnnotation()) != null)
1950 for (AlignmentAnnotation annot : aa)
1952 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1953 if (selectedOnly && selectionGroup != null)
1955 clone.makeVisibleAnnotation(
1956 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1957 alignment.getHiddenColumns());
1961 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1970 public boolean isPadGaps()
1976 public void setPadGaps(boolean padGaps)
1978 this.padGaps = padGaps;
1982 * apply any post-edit constraints and trigger any calculations needed after
1983 * an edit has been performed on the alignment
1988 public void alignmentChanged(AlignmentViewPanel ap)
1992 alignment.padGaps();
1994 if (autoCalculateConsensusAndConservation)
1996 updateConsensus(ap);
1998 if (hconsensus != null && autoCalculateConsensusAndConservation)
2000 updateConservation(ap);
2002 if (autoCalculateStrucConsensus)
2004 updateStrucConsensus(ap);
2007 // Reset endRes of groups if beyond alignment width
2008 int alWidth = alignment.getWidth();
2009 List<SequenceGroup> groups = alignment.getGroups();
2012 for (SequenceGroup sg : groups)
2014 if (sg.getEndRes() > alWidth)
2016 sg.setEndRes(alWidth - 1);
2021 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
2023 selectionGroup.setEndRes(alWidth - 1);
2026 updateAllColourSchemes();
2027 calculator.restartWorkers();
2031 * reset scope and do calculations for all applied colourschemes on alignment
2033 void updateAllColourSchemes()
2035 ResidueShaderI rs = residueShading;
2038 rs.alignmentChanged(alignment, hiddenRepSequences);
2040 rs.setConsensus(hconsensus);
2041 if (rs.conservationApplied())
2043 rs.setConservation(Conservation.calculateConservation("All",
2044 alignment.getSequences(), 0, alignment.getWidth(), false,
2045 getConsPercGaps(), false));
2049 for (SequenceGroup sg : alignment.getGroups())
2053 sg.cs.alignmentChanged(sg, hiddenRepSequences);
2055 sg.recalcConservation();
2059 protected void initAutoAnnotation()
2061 // TODO: add menu option action that nulls or creates consensus object
2062 // depending on if the user wants to see the annotation or not in a
2063 // specific alignment
2065 if (hconsensus == null && !isDataset)
2067 if (!alignment.isNucleotide())
2076 consensus = new AlignmentAnnotation("Consensus",
2077 MessageManager.getString("label.consensus_descr"),
2078 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2079 initConsensus(consensus);
2082 initComplementConsensus();
2087 * If this is a protein alignment and there are mappings to cDNA, adds the
2088 * cDNA consensus annotation and returns true, else returns false.
2090 public boolean initComplementConsensus()
2092 if (!alignment.isNucleotide())
2094 final List<AlignedCodonFrame> codonMappings = alignment
2096 if (codonMappings != null && !codonMappings.isEmpty())
2098 boolean doConsensus = false;
2099 for (AlignedCodonFrame mapping : codonMappings)
2101 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2102 MapList[] mapLists = mapping.getdnaToProt();
2103 // mapLists can be empty if project load has not finished resolving
2105 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2113 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2115 .getString("label.complement_consensus_descr"),
2116 new Annotation[1], 0f, 100f,
2117 AlignmentAnnotation.BAR_GRAPH);
2118 initConsensus(complementConsensus);
2126 private void initConsensus(AlignmentAnnotation aa)
2129 aa.autoCalculated = true;
2133 alignment.addAnnotation(aa);
2137 // these should be extracted from the view model - style and settings for
2138 // derived annotation
2139 private void initGapCounts()
2143 gapcounts = new AlignmentAnnotation("Occupancy",
2144 MessageManager.getString("label.occupancy_descr"),
2145 new Annotation[1], 0f, alignment.getHeight(),
2146 AlignmentAnnotation.BAR_GRAPH);
2147 gapcounts.hasText = true;
2148 gapcounts.autoCalculated = true;
2149 gapcounts.scaleColLabel = true;
2150 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2152 alignment.addAnnotation(gapcounts);
2156 private void initConservation()
2158 if (showConservation)
2160 if (conservation == null)
2162 conservation = new AlignmentAnnotation("Conservation",
2163 MessageManager.formatMessage("label.conservation_descr",
2165 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2166 conservation.hasText = true;
2167 conservation.autoCalculated = true;
2168 alignment.addAnnotation(conservation);
2173 private void initQuality()
2177 if (quality == null)
2179 quality = new AlignmentAnnotation("Quality",
2180 MessageManager.getString("label.quality_descr"),
2181 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2182 quality.hasText = true;
2183 quality.autoCalculated = true;
2184 alignment.addAnnotation(quality);
2189 private void initRNAStructure()
2191 if (alignment.hasRNAStructure() && strucConsensus == null)
2193 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2194 MessageManager.getString("label.strucconsensus_descr"),
2195 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2196 strucConsensus.hasText = true;
2197 strucConsensus.autoCalculated = true;
2201 alignment.addAnnotation(strucConsensus);
2209 * @see jalview.api.AlignViewportI#calcPanelHeight()
2212 public int calcPanelHeight()
2214 // setHeight of panels
2215 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2217 int charHeight = getCharHeight();
2220 BitSet graphgrp = new BitSet();
2221 for (AlignmentAnnotation aa : anns)
2225 System.err.println("Null annotation row: ignoring.");
2232 if (aa.graphGroup > -1)
2234 if (graphgrp.get(aa.graphGroup))
2240 graphgrp.set(aa.graphGroup);
2247 aa.height += charHeight;
2257 aa.height += aa.graphHeight;
2265 height += aa.height;
2277 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2278 boolean preserveNewGroupSettings)
2280 boolean updateCalcs = false;
2281 boolean conv = isShowGroupConservation();
2282 boolean cons = isShowGroupConsensus();
2283 boolean showprf = isShowSequenceLogo();
2284 boolean showConsHist = isShowConsensusHistogram();
2285 boolean normLogo = isNormaliseSequenceLogo();
2286 boolean showHMMPrf = isShowHMMSequenceLogo();
2287 boolean showInfoHist = isShowInformationHistogram();
2288 boolean normHMMLogo = isNormaliseHMMSequenceLogo();
2291 * TODO reorder the annotation rows according to group/sequence ordering on
2294 // boolean sortg = true;
2296 // remove old automatic annotation
2297 // add any new annotation
2299 // intersect alignment annotation with alignment groups
2301 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2302 List<SequenceGroup> oldrfs = new ArrayList<>();
2305 for (int an = 0; an < aan.length; an++)
2307 if (aan[an].autoCalculated && aan[an].groupRef != null)
2309 oldrfs.add(aan[an].groupRef);
2310 alignment.deleteAnnotation(aan[an], false);
2314 if (alignment.getGroups() != null)
2316 for (SequenceGroup sg : alignment.getGroups())
2318 updateCalcs = false;
2319 if (applyGlobalSettings
2320 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2322 // set defaults for this group's conservation/consensus
2323 sg.setshowSequenceLogo(showprf);
2324 sg.setShowConsensusHistogram(showConsHist);
2325 sg.setNormaliseSequenceLogo(normLogo);
2326 sg.setShowHMMSequenceLogo(showHMMPrf);
2327 sg.setShowInformationHistogram(showInfoHist);
2328 sg.setNormaliseHMMSequenceLogo(normHMMLogo);
2333 alignment.addAnnotation(sg.getConservationRow(), 0);
2338 alignment.addAnnotation(sg.getConsensus(), 0);
2340 // refresh the annotation rows
2343 sg.recalcConservation();
2351 public boolean isDisplayReferenceSeq()
2353 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2357 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2359 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2363 public boolean isColourByReferenceSeq()
2365 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2369 public Color getSequenceColour(SequenceI seq)
2371 Color sqc = sequenceColours.get(seq);
2372 return (sqc == null ? Color.white : sqc);
2376 public void setSequenceColour(SequenceI seq, Color col)
2380 sequenceColours.remove(seq);
2384 sequenceColours.put(seq, col);
2389 public void updateSequenceIdColours()
2391 for (SequenceGroup sg : alignment.getGroups())
2393 if (sg.idColour != null)
2395 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2397 sequenceColours.put(s, sg.idColour);
2404 public void clearSequenceColours()
2406 sequenceColours.clear();
2410 public AlignViewportI getCodingComplement()
2412 return this.codingComplement;
2416 * Set this as the (cDna/protein) complement of the given viewport. Also
2417 * ensures the reverse relationship is set on the given viewport.
2420 public void setCodingComplement(AlignViewportI av)
2424 System.err.println("Ignoring recursive setCodingComplement request");
2428 this.codingComplement = av;
2429 // avoid infinite recursion!
2430 if (av.getCodingComplement() != this)
2432 av.setCodingComplement(this);
2438 public boolean isNucleotide()
2440 return getAlignment() == null ? false : getAlignment().isNucleotide();
2444 public FeaturesDisplayedI getFeaturesDisplayed()
2446 return featuresDisplayed;
2450 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2452 featuresDisplayed = featuresDisplayedI;
2456 public boolean areFeaturesDisplayed()
2458 return featuresDisplayed != null
2459 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2466 * features are displayed if true
2469 public void setShowSequenceFeatures(boolean b)
2471 viewStyle.setShowSequenceFeatures(b);
2475 public boolean isShowSequenceFeatures()
2477 return viewStyle.isShowSequenceFeatures();
2481 public void setShowSequenceFeaturesHeight(boolean selected)
2483 viewStyle.setShowSequenceFeaturesHeight(selected);
2487 public boolean isShowSequenceFeaturesHeight()
2489 return viewStyle.isShowSequenceFeaturesHeight();
2493 public void setShowAnnotation(boolean b)
2495 viewStyle.setShowAnnotation(b);
2499 public boolean isShowAnnotation()
2501 return viewStyle.isShowAnnotation();
2505 public boolean isRightAlignIds()
2507 return viewStyle.isRightAlignIds();
2511 public void setRightAlignIds(boolean rightAlignIds)
2513 viewStyle.setRightAlignIds(rightAlignIds);
2517 public boolean getConservationSelected()
2519 return viewStyle.getConservationSelected();
2523 public void setShowBoxes(boolean state)
2525 viewStyle.setShowBoxes(state);
2530 * @see jalview.api.ViewStyleI#getTextColour()
2533 public Color getTextColour()
2535 return viewStyle.getTextColour();
2540 * @see jalview.api.ViewStyleI#getTextColour2()
2543 public Color getTextColour2()
2545 return viewStyle.getTextColour2();
2550 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2553 public int getThresholdTextColour()
2555 return viewStyle.getThresholdTextColour();
2560 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2563 public boolean isConservationColourSelected()
2565 return viewStyle.isConservationColourSelected();
2570 * @see jalview.api.ViewStyleI#isRenderGaps()
2573 public boolean isRenderGaps()
2575 return viewStyle.isRenderGaps();
2580 * @see jalview.api.ViewStyleI#isShowColourText()
2583 public boolean isShowColourText()
2585 return viewStyle.isShowColourText();
2589 * @param conservationColourSelected
2590 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2593 public void setConservationColourSelected(
2594 boolean conservationColourSelected)
2596 viewStyle.setConservationColourSelected(conservationColourSelected);
2600 * @param showColourText
2601 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2604 public void setShowColourText(boolean showColourText)
2606 viewStyle.setShowColourText(showColourText);
2611 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2614 public void setTextColour(Color textColour)
2616 viewStyle.setTextColour(textColour);
2620 * @param thresholdTextColour
2621 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2624 public void setThresholdTextColour(int thresholdTextColour)
2626 viewStyle.setThresholdTextColour(thresholdTextColour);
2630 * @param textColour2
2631 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2634 public void setTextColour2(Color textColour2)
2636 viewStyle.setTextColour2(textColour2);
2640 public ViewStyleI getViewStyle()
2642 return new ViewStyle(viewStyle);
2646 public void setViewStyle(ViewStyleI settingsForView)
2648 viewStyle = new ViewStyle(settingsForView);
2649 if (residueShading != null)
2651 residueShading.setConservationApplied(
2652 settingsForView.isConservationColourSelected());
2657 public boolean sameStyle(ViewStyleI them)
2659 return viewStyle.sameStyle(them);
2664 * @see jalview.api.ViewStyleI#getIdWidth()
2667 public int getIdWidth()
2669 return viewStyle.getIdWidth();
2674 * @see jalview.api.ViewStyleI#setIdWidth(int)
2677 public void setIdWidth(int i)
2679 viewStyle.setIdWidth(i);
2684 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2687 public boolean isCentreColumnLabels()
2689 return viewStyle.isCentreColumnLabels();
2693 * @param centreColumnLabels
2694 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2697 public void setCentreColumnLabels(boolean centreColumnLabels)
2699 viewStyle.setCentreColumnLabels(centreColumnLabels);
2704 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2707 public void setShowDBRefs(boolean showdbrefs)
2709 viewStyle.setShowDBRefs(showdbrefs);
2714 * @see jalview.api.ViewStyleI#isShowDBRefs()
2717 public boolean isShowDBRefs()
2719 return viewStyle.isShowDBRefs();
2724 * @see jalview.api.ViewStyleI#isShowNPFeats()
2727 public boolean isShowNPFeats()
2729 return viewStyle.isShowNPFeats();
2733 * @param shownpfeats
2734 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2737 public void setShowNPFeats(boolean shownpfeats)
2739 viewStyle.setShowNPFeats(shownpfeats);
2742 public abstract StructureSelectionManager getStructureSelectionManager();
2745 * Add one command to the command history list.
2749 public void addToHistoryList(CommandI command)
2751 if (this.historyList != null)
2753 this.historyList.push(command);
2754 broadcastCommand(command, false);
2758 protected void broadcastCommand(CommandI command, boolean undo)
2760 getStructureSelectionManager().commandPerformed(command, undo,
2765 * Add one command to the command redo list.
2769 public void addToRedoList(CommandI command)
2771 if (this.redoList != null)
2773 this.redoList.push(command);
2775 broadcastCommand(command, true);
2779 * Clear the command redo list.
2781 public void clearRedoList()
2783 if (this.redoList != null)
2785 this.redoList.clear();
2789 public void setHistoryList(Deque<CommandI> list)
2791 this.historyList = list;
2794 public Deque<CommandI> getHistoryList()
2796 return this.historyList;
2799 public void setRedoList(Deque<CommandI> list)
2801 this.redoList = list;
2804 public Deque<CommandI> getRedoList()
2806 return this.redoList;
2810 public VamsasSource getVamsasSource()
2815 public SequenceAnnotationOrder getSortAnnotationsBy()
2817 return sortAnnotationsBy;
2820 public void setSortAnnotationsBy(
2821 SequenceAnnotationOrder sortAnnotationsBy)
2823 this.sortAnnotationsBy = sortAnnotationsBy;
2826 public boolean isShowAutocalculatedAbove()
2828 return showAutocalculatedAbove;
2831 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2833 this.showAutocalculatedAbove = showAutocalculatedAbove;
2837 public boolean isScaleProteinAsCdna()
2839 return viewStyle.isScaleProteinAsCdna();
2843 public void setScaleProteinAsCdna(boolean b)
2845 viewStyle.setScaleProteinAsCdna(b);
2849 public boolean isProteinFontAsCdna()
2851 return viewStyle.isProteinFontAsCdna();
2855 public void setProteinFontAsCdna(boolean b)
2857 viewStyle.setProteinFontAsCdna(b);
2861 public void setShowComplementFeatures(boolean b)
2863 viewStyle.setShowComplementFeatures(b);
2867 public boolean isShowComplementFeatures()
2869 return viewStyle.isShowComplementFeatures();
2873 public void setShowComplementFeaturesOnTop(boolean b)
2875 viewStyle.setShowComplementFeaturesOnTop(b);
2879 public boolean isShowComplementFeaturesOnTop()
2881 return viewStyle.isShowComplementFeaturesOnTop();
2885 * @return true if view should scroll to show the highlighted region of a
2890 public final boolean isFollowHighlight()
2892 return followHighlight;
2896 public final void setFollowHighlight(boolean b)
2898 this.followHighlight = b;
2902 public ViewportRanges getRanges()
2908 * Helper method to populate the SearchResults with the location in the
2909 * complementary alignment to scroll to, in order to match this one.
2912 * the SearchResults to add to
2913 * @return the offset (below top of visible region) of the matched sequence
2915 protected int findComplementScrollTarget(SearchResultsI sr)
2917 final AlignViewportI complement = getCodingComplement();
2918 if (complement == null || !complement.isFollowHighlight())
2922 boolean iAmProtein = !getAlignment().isNucleotide();
2923 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2924 : complement.getAlignment();
2925 if (proteinAlignment == null)
2929 final List<AlignedCodonFrame> mappings = proteinAlignment
2933 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2934 * residue in the middle column of the visible region. Scroll the
2935 * complementary alignment to line up the corresponding residue.
2938 SequenceI sequence = null;
2941 * locate 'middle' column (true middle if an odd number visible, left of
2942 * middle if an even number visible)
2944 int middleColumn = ranges.getStartRes()
2945 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2946 final HiddenSequences hiddenSequences = getAlignment()
2947 .getHiddenSequences();
2950 * searching to the bottom of the alignment gives smoother scrolling across
2951 * all gapped visible regions
2953 int lastSeq = alignment.getHeight() - 1;
2954 List<AlignedCodonFrame> seqMappings = null;
2955 for (int seqNo = ranges
2956 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2958 sequence = getAlignment().getSequenceAt(seqNo);
2959 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2963 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2967 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2969 getCodingComplement().getAlignment().getSequences());
2970 if (!seqMappings.isEmpty())
2976 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2979 * No ungapped mapped sequence in middle column - do nothing
2983 MappingUtils.addSearchResults(sr, sequence,
2984 sequence.findPosition(middleColumn), seqMappings);
2989 * synthesize a column selection if none exists so it covers the given
2990 * selection group. if wholewidth is false, no column selection is made if the
2991 * selection group covers the whole alignment width.
2996 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2999 if (sg != null && (sgs = sg.getStartRes()) >= 0
3000 && sg.getStartRes() <= (sge = sg.getEndRes())
3001 && !this.hasSelectedColumns())
3003 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
3010 colSel = new ColumnSelection();
3012 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
3014 colSel.addElement(cspos);
3020 * hold status of current selection group - defined on alignment or not.
3022 private boolean selectionIsDefinedGroup = false;
3025 public boolean isSelectionDefinedGroup()
3027 if (selectionGroup == null)
3031 if (isSelectionGroupChanged(true))
3033 selectionIsDefinedGroup = false;
3034 List<SequenceGroup> gps = alignment.getGroups();
3035 if (gps == null || gps.size() == 0)
3037 selectionIsDefinedGroup = false;
3041 selectionIsDefinedGroup = gps.contains(selectionGroup);
3044 return selectionGroup.isDefined() || selectionIsDefinedGroup;
3048 * null, or currently highlighted results on this view
3050 private SearchResultsI searchResults = null;
3052 protected TreeModel currentTree = null;
3055 public boolean hasSearchResults()
3057 return searchResults != null;
3061 public void setSearchResults(SearchResultsI results)
3063 searchResults = results;
3067 public SearchResultsI getSearchResults()
3069 return searchResults;
3073 * get the consensus sequence as displayed under the PID consensus annotation
3076 * @return consensus sequence as a new sequence object
3078 public SequenceI getConsensusSeq()
3080 if (consensus == null)
3082 updateConsensus(null);
3084 if (consensus == null)
3088 StringBuffer seqs = new StringBuffer();
3089 for (int i = 0; i < consensus.annotations.length; i++)
3091 Annotation annotation = consensus.annotations[i];
3092 if (annotation != null)
3094 String description = annotation.description;
3095 if (description != null && description.startsWith("["))
3097 // consensus is a tie - just pick the first one
3098 seqs.append(description.charAt(1));
3102 seqs.append(annotation.displayCharacter);
3107 SequenceI sq = new Sequence("Consensus", seqs.toString());
3108 sq.setDescription("Percentage Identity Consensus "
3109 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3113 public boolean hasReferenceAnnotation()
3115 AlignmentAnnotation[] annots = this.alignment.getAlignmentAnnotation();
3116 for (AlignmentAnnotation annot : annots)
3118 if ("RF".equals(annot.label) || annot.label.contains("Reference"))
3126 public void setCurrentTree(TreeModel tree)
3132 public TreeModel getCurrentTree()
3138 public AlignmentExportData getAlignExportData(AlignExportSettingsI options)
3140 AlignmentI alignmentToExport = null;
3141 String[] omitHidden = null;
3142 alignmentToExport = null;
3144 if (hasHiddenColumns() && !options.isExportHiddenColumns())
3146 omitHidden = getViewAsString(false,
3147 options.isExportHiddenSequences());
3150 int[] alignmentStartEnd = new int[2];
3151 if (hasHiddenRows() && options.isExportHiddenSequences())
3153 alignmentToExport = getAlignment().getHiddenSequences()
3154 .getFullAlignment();
3158 alignmentToExport = getAlignment();
3160 alignmentStartEnd = getAlignment().getHiddenColumns()
3161 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
3162 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
3163 omitHidden, alignmentStartEnd);
3168 public boolean isNormaliseSequenceLogo()
3170 return normaliseSequenceLogo;
3173 public void setNormaliseSequenceLogo(boolean state)
3175 normaliseSequenceLogo = state;
3179 public boolean isNormaliseHMMSequenceLogo()
3181 return hmmNormaliseSequenceLogo;
3184 public void setNormaliseHMMSequenceLogo(boolean state)
3186 hmmNormaliseSequenceLogo = state;
3189 * flag set to indicate if structure views might be out of sync with sequences
3193 private boolean needToUpdateStructureViews = false;
3196 public boolean isUpdateStructures()
3198 return needToUpdateStructureViews;
3202 public void setUpdateStructures(boolean update)
3204 needToUpdateStructureViews = update;
3208 public boolean needToUpdateStructureViews()
3210 boolean update = needToUpdateStructureViews;
3211 needToUpdateStructureViews = false;
3216 public void addSequenceGroup(SequenceGroup sequenceGroup)
3218 alignment.addGroup(sequenceGroup);
3220 Color col = sequenceGroup.idColour;
3223 col = col.brighter();
3225 for (SequenceI sq : sequenceGroup.getSequences())
3227 setSequenceColour(sq, col);
3231 if (codingComplement != null)
3233 SequenceGroup mappedGroup = MappingUtils
3234 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3235 if (mappedGroup.getSequences().size() > 0)
3237 codingComplement.getAlignment().addGroup(mappedGroup);
3241 for (SequenceI seq : mappedGroup.getSequences())
3243 codingComplement.setSequenceColour(seq, col);
3247 // propagate the structure view update flag according to our own setting
3248 codingComplement.setUpdateStructures(needToUpdateStructureViews);
3253 public Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly)
3257 if (selectedRegionOnly && selectionGroup != null)
3259 start = selectionGroup.getStartRes();
3260 end = selectionGroup.getEndRes() + 1;
3264 end = alignment.getWidth();
3266 return (alignment.getHiddenColumns().getVisContigsIterator(start, end,
3270 * Filters out sequences with an eValue higher than the specified value. The
3271 * filtered sequences are hidden or deleted. Sequences with no eValues are also
3277 public void filterByEvalue(double eValue)
3279 for (SequenceI seq : alignment.getSequencesArray())
3281 if ((seq.getAnnotation("Search Scores") == null
3282 || seq.getAnnotation("Search Scores")[0].getEValue() > eValue)
3283 && seq.getHMM() == null)
3285 hideSequence(new SequenceI[] { seq });
3291 * Filters out sequences with an score lower than the specified value. The
3292 * filtered sequences are hidden or deleted.
3297 public void filterByScore(double score)
3299 for (SequenceI seq : alignment.getSequencesArray())
3301 if ((seq.getAnnotation("Search Scores") == null
3302 || seq.getAnnotation("Search Scores")[0]
3303 .getBitScore() < score)
3304 && seq.getHMM() == null)
3306 hideSequence(new SequenceI[] { seq });
3312 * Notify TreePanel and AlignmentPanel of some sort of alignment change.
3314 public void notifyAlignment()
3316 changeSupport.firePropertyChange(PROPERTY_ALIGNMENT, null, alignment.getSequences());
3320 * Notify AlignmentPanel of a sequence column selection or visibility changes.
3322 public void notifySequence()
3324 changeSupport.firePropertyChange(PROPERTY_SEQUENCE, null, null);