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";
91 protected ViewportRanges ranges;
93 protected ViewStyleI viewStyle = new ViewStyle();
96 * A viewport that hosts the cDna view of this (protein), or vice versa (if
99 AlignViewportI codingComplement = null;
101 FeaturesDisplayedI featuresDisplayed = null;
103 protected Deque<CommandI> historyList = new ArrayDeque<>();
105 protected Deque<CommandI> redoList = new ArrayDeque<>();
108 * alignment displayed in the viewport. Please use get/setter
110 protected AlignmentI alignment;
113 * probably unused indicator that view is of a dataset rather than an
117 protected boolean ignoreBelowBackGroundFrequencyCalculation = false;
119 protected boolean infoLetterHeight = false;
121 protected AlignmentAnnotation occupancy;
124 * results of alignment consensus analysis for visible portion of view
126 protected ProfilesI consensusProfiles;
129 * HMM profile for the alignment
131 protected ProfilesI hmmProfiles;
133 public AlignmentViewport(AlignmentI al)
136 ranges = new ViewportRanges(al);
141 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
144 public void setFontName(String name)
146 viewStyle.setFontName(name);
151 * @see jalview.api.ViewStyleI#setFontStyle(int)
154 public void setFontStyle(int style)
156 viewStyle.setFontStyle(style);
161 * @see jalview.api.ViewStyleI#setFontSize(int)
164 public void setFontSize(int size)
166 viewStyle.setFontSize(size);
171 * @see jalview.api.ViewStyleI#getFontStyle()
174 public int getFontStyle()
176 return viewStyle.getFontStyle();
181 * @see jalview.api.ViewStyleI#getFontName()
184 public String getFontName()
186 return viewStyle.getFontName();
191 * @see jalview.api.ViewStyleI#getFontSize()
194 public int getFontSize()
196 return viewStyle.getFontSize();
200 * @param upperCasebold
201 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
204 public void setUpperCasebold(boolean upperCasebold)
206 viewStyle.setUpperCasebold(upperCasebold);
211 * @see jalview.api.ViewStyleI#isUpperCasebold()
214 public boolean isUpperCasebold()
216 return viewStyle.isUpperCasebold();
221 * @see jalview.api.ViewStyleI#isSeqNameItalics()
224 public boolean isSeqNameItalics()
226 return viewStyle.isSeqNameItalics();
230 * @param colourByReferenceSeq
231 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
234 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
236 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
241 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
244 public void setColourAppliesToAllGroups(boolean b)
246 viewStyle.setColourAppliesToAllGroups(b);
251 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
254 public boolean getColourAppliesToAllGroups()
256 return viewStyle.getColourAppliesToAllGroups();
261 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
264 public boolean getAbovePIDThreshold()
266 return viewStyle.getAbovePIDThreshold();
271 * @see jalview.api.ViewStyleI#setIncrement(int)
274 public void setIncrement(int inc)
276 viewStyle.setIncrement(inc);
281 * @see jalview.api.ViewStyleI#getIncrement()
284 public int getIncrement()
286 return viewStyle.getIncrement();
291 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
294 public void setConservationSelected(boolean b)
296 viewStyle.setConservationSelected(b);
301 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
304 public void setShowHiddenMarkers(boolean show)
306 viewStyle.setShowHiddenMarkers(show);
311 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
314 public boolean getShowHiddenMarkers()
316 return viewStyle.getShowHiddenMarkers();
321 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
324 public void setScaleRightWrapped(boolean b)
326 viewStyle.setScaleRightWrapped(b);
331 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
334 public void setScaleLeftWrapped(boolean b)
336 viewStyle.setScaleLeftWrapped(b);
341 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
344 public void setScaleAboveWrapped(boolean b)
346 viewStyle.setScaleAboveWrapped(b);
351 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
354 public boolean getScaleLeftWrapped()
356 return viewStyle.getScaleLeftWrapped();
361 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
364 public boolean getScaleAboveWrapped()
366 return viewStyle.getScaleAboveWrapped();
371 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
374 public boolean getScaleRightWrapped()
376 return viewStyle.getScaleRightWrapped();
381 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
384 public void setAbovePIDThreshold(boolean b)
386 viewStyle.setAbovePIDThreshold(b);
391 * @see jalview.api.ViewStyleI#setThreshold(int)
394 public void setThreshold(int thresh)
396 viewStyle.setThreshold(thresh);
401 * @see jalview.api.ViewStyleI#getThreshold()
404 public int getThreshold()
406 return viewStyle.getThreshold();
411 * @see jalview.api.ViewStyleI#getShowJVSuffix()
414 public boolean getShowJVSuffix()
416 return viewStyle.getShowJVSuffix();
421 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
424 public void setShowJVSuffix(boolean b)
426 viewStyle.setShowJVSuffix(b);
431 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
434 public void setWrapAlignment(boolean state)
436 viewStyle.setWrapAlignment(state);
437 ranges.setWrappedMode(state);
442 * @see jalview.api.ViewStyleI#setShowText(boolean)
445 public void setShowText(boolean state)
447 viewStyle.setShowText(state);
452 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
455 public void setRenderGaps(boolean state)
457 viewStyle.setRenderGaps(state);
462 * @see jalview.api.ViewStyleI#getColourText()
465 public boolean getColourText()
467 return viewStyle.getColourText();
472 * @see jalview.api.ViewStyleI#setColourText(boolean)
475 public void setColourText(boolean state)
477 viewStyle.setColourText(state);
482 * @see jalview.api.ViewStyleI#getWrapAlignment()
485 public boolean getWrapAlignment()
487 return viewStyle.getWrapAlignment();
492 * @see jalview.api.ViewStyleI#getShowText()
495 public boolean getShowText()
497 return viewStyle.getShowText();
502 * @see jalview.api.ViewStyleI#getWrappedWidth()
505 public int getWrappedWidth()
507 return viewStyle.getWrappedWidth();
512 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
515 public void setWrappedWidth(int w)
517 viewStyle.setWrappedWidth(w);
522 * @see jalview.api.ViewStyleI#getCharHeight()
525 public int getCharHeight()
527 return viewStyle.getCharHeight();
532 * @see jalview.api.ViewStyleI#setCharHeight(int)
535 public void setCharHeight(int h)
537 viewStyle.setCharHeight(h);
542 * @see jalview.api.ViewStyleI#getCharWidth()
545 public int getCharWidth()
547 return viewStyle.getCharWidth();
552 * @see jalview.api.ViewStyleI#setCharWidth(int)
555 public void setCharWidth(int w)
557 viewStyle.setCharWidth(w);
562 * @see jalview.api.ViewStyleI#getShowBoxes()
565 public boolean getShowBoxes()
567 return viewStyle.getShowBoxes();
572 * @see jalview.api.ViewStyleI#getShowUnconserved()
575 public boolean getShowUnconserved()
577 return viewStyle.getShowUnconserved();
581 * @param showunconserved
582 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
585 public void setShowUnconserved(boolean showunconserved)
587 viewStyle.setShowUnconserved(showunconserved);
592 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
595 public void setSeqNameItalics(boolean default1)
597 viewStyle.setSeqNameItalics(default1);
601 public AlignmentI getAlignment()
607 public char getGapCharacter()
609 return alignment.getGapCharacter();
612 protected String sequenceSetID;
615 * probably unused indicator that view is of a dataset rather than an
618 protected boolean isDataset = false;
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;
659 protected boolean ignoreGapsInConsensusCalculation = false;
661 protected ResidueShaderI residueShading = new ResidueShader();
664 public void setGlobalColourScheme(ColourSchemeI cs)
666 // TODO: logic refactored from AlignFrame changeColour -
667 // TODO: autorecalc stuff should be changed to rely on the worker system
668 // check to see if we should implement a changeColour(cs) method rather than
669 // put the logic in here
670 // - means that caller decides if they want to just modify state and defer
671 // calculation till later or to do all calculations in thread.
675 * only instantiate alignment colouring once, thereafter update it;
676 * this means that any conservation or PID threshold settings
677 * persist when the alignment colour scheme is changed
679 if (residueShading == null)
681 residueShading = new ResidueShader(viewStyle);
683 residueShading.setColourScheme(cs);
685 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
686 // ...problem: groups need these, but do not currently have a ViewStyle
690 if (getConservationSelected())
692 residueShading.setConservation(hconservation);
695 * reset conservation flag in case just set to false if
696 * Conservation was null (calculation still in progress)
698 residueShading.setConservationApplied(getConservationSelected());
699 residueShading.alignmentChanged(alignment, hiddenRepSequences);
703 * if 'apply colour to all groups' is selected... do so
704 * (but don't transfer any colour threshold settings to groups)
706 if (getColourAppliesToAllGroups())
708 for (SequenceGroup sg : getAlignment().getGroups())
711 * retain any colour thresholds per group while
712 * changing choice of colour scheme (JAL-2386)
715 cs == null ? null : cs.getInstance(this, sg));
718 sg.getGroupColourScheme().alignmentChanged(sg,
726 public ColourSchemeI getGlobalColourScheme()
728 return residueShading == null ? null : residueShading.getColourScheme();
732 public ResidueShaderI getResidueShading()
734 return residueShading;
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;
772 public void setConservation(Conservation cons)
774 hconservation = cons;
778 * percentage gaps allowed in a column before all amino acid properties should
779 * be considered unconserved
781 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
784 public int getConsPercGaps()
790 public void setSequenceConsensusHash(ProfilesI hconsensus)
792 this.hconsensus = hconsensus;
796 public void setComplementConsensusHash(
797 Hashtable<String, Object>[] hconsensus)
799 this.hcomplementConsensus = hconsensus;
803 public ProfilesI getSequenceConsensusHash()
809 public void setHmmProfiles(ProfilesI info)
815 public ProfilesI getHmmProfiles()
821 public Hashtable<String, Object>[] getComplementConsensusHash()
823 return hcomplementConsensus;
827 public Hashtable<String, Object>[] getRnaStructureConsensusHash()
829 return hStrucConsensus;
833 public void setRnaStructureConsensusHash(
834 Hashtable<String, Object>[] hStrucConsensus)
836 this.hStrucConsensus = hStrucConsensus;
841 public AlignmentAnnotation getAlignmentQualityAnnot()
847 public AlignmentAnnotation getAlignmentConservationAnnotation()
853 public AlignmentAnnotation getAlignmentConsensusAnnotation()
859 public AlignmentAnnotation getAlignmentGapAnnotation()
865 public AlignmentAnnotation getComplementConsensusAnnotation()
867 return complementConsensus;
871 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
873 return strucConsensus;
876 protected AlignCalcManagerI2 calculator = new AlignCalcManager2();
879 * trigger update of conservation annotation
881 public void updateConservation(final AlignmentViewPanel ap)
883 // see note in mantis : issue number 8585
884 if (alignment.isNucleotide()
885 || (conservation == null && quality == null)
886 || !autoCalculateConsensusAndConservation)
890 if (calculator.getWorkersOfClass(
891 jalview.workers.ConservationThread.class).isEmpty())
893 calculator.registerWorker(
894 new jalview.workers.ConservationThread(this, ap));
899 * trigger update of consensus annotation
901 public void updateConsensus(final AlignmentViewPanel ap)
903 // see note in mantis : issue number 8585
904 if (consensus == null || !autoCalculateConsensusAndConservation)
908 if (calculator.getWorkersOfClass(ConsensusThread.class).isEmpty())
910 calculator.registerWorker(new ConsensusThread(this, ap));
914 * A separate thread to compute cDNA consensus for a protein alignment
915 * which has mapping to cDNA
917 final AlignmentI al = this.getAlignment();
918 if (!al.isNucleotide() && al.getCodonFrames() != null
919 && !al.getCodonFrames().isEmpty())
922 * fudge - check first for protein-to-nucleotide mappings
923 * (we don't want to do this for protein-to-protein)
925 boolean doConsensus = false;
926 for (AlignedCodonFrame mapping : al.getCodonFrames())
928 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
929 MapList[] mapLists = mapping.getdnaToProt();
930 // mapLists can be empty if project load has not finished resolving seqs
931 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
939 if (calculator.getWorkersOfClass(ComplementConsensusThread.class).isEmpty())
941 calculator.registerWorker(new ComplementConsensusThread(this, ap));
948 public void initInformationWorker(final AlignmentViewPanel ap)
950 if (calculator.getWorkersOfClass(InformationThread.class).isEmpty())
952 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;
1144 * @param showConsensusHistogram
1145 * the showConsensusHistogram to set
1147 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1149 this.showConsensusHistogram = showConsensusHistogram;
1153 * @param showInformationHistogram
1155 public void setShowInformationHistogram(boolean showInformationHistogram)
1157 this.hmmShowHistogram = showInformationHistogram;
1161 * @return the showGroupConservation
1163 public boolean isShowGroupConservation()
1165 return showGroupConservation;
1169 * @param showGroupConservation
1170 * the showGroupConservation to set
1172 public void setShowGroupConservation(boolean showGroupConservation)
1174 this.showGroupConservation = showGroupConservation;
1178 * @return the showGroupConsensus
1180 public boolean isShowGroupConsensus()
1182 return showGroupConsensus;
1186 * @param showGroupConsensus
1187 * the showGroupConsensus to set
1189 public void setShowGroupConsensus(boolean showGroupConsensus)
1191 this.showGroupConsensus = showGroupConsensus;
1196 * @return flag to indicate if the consensus histogram should be rendered by
1200 public boolean isShowConsensusHistogram()
1202 return this.showConsensusHistogram;
1207 * @return flag to indicate if the information content histogram should be
1208 * rendered by default
1211 public boolean isShowInformationHistogram()
1213 return this.hmmShowHistogram;
1217 * when set, updateAlignment will always ensure sequences are of equal length
1219 private boolean padGaps = false;
1222 * when set, alignment should be reordered according to a newly opened tree
1224 public boolean sortByTree = false;
1229 * @return null or the currently selected sequence region
1232 public SequenceGroup getSelectionGroup()
1234 return selectionGroup;
1238 * Set the selection group for this window. Also sets the current alignment as
1239 * the context for the group, if it does not already have one.
1242 * - group holding references to sequences in this alignment view
1246 public void setSelectionGroup(SequenceGroup sg)
1248 selectionGroup = sg;
1249 if (sg != null && sg.getContext() == null)
1251 sg.setContext(alignment);
1255 public void setHiddenColumns(HiddenColumns hidden)
1257 this.alignment.setHiddenColumns(hidden);
1261 public ColumnSelection getColumnSelection()
1267 public void setColumnSelection(ColumnSelection colSel)
1269 this.colSel = colSel;
1272 updateHiddenColumns();
1274 isColSelChanged(true);
1282 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1284 return hiddenRepSequences;
1288 public void setHiddenRepSequences(
1289 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1291 this.hiddenRepSequences = hiddenRepSequences;
1295 public boolean hasSelectedColumns()
1297 ColumnSelection columnSelection = getColumnSelection();
1298 return columnSelection != null && columnSelection.hasSelectedColumns();
1302 public boolean hasHiddenColumns()
1304 return alignment.getHiddenColumns() != null
1305 && alignment.getHiddenColumns().hasHiddenColumns();
1308 public void updateHiddenColumns()
1310 // this method doesn't really do anything now. But - it could, since a
1311 // column Selection could be in the process of modification
1312 // hasHiddenColumns = colSel.hasHiddenColumns();
1316 public boolean hasHiddenRows()
1318 return alignment.getHiddenSequences().getSize() > 0;
1321 protected SequenceGroup selectionGroup;
1323 public void setSequenceSetId(String newid)
1325 if (sequenceSetID != null)
1328 "Warning - overwriting a sequenceSetId for a viewport!");
1330 sequenceSetID = new String(newid);
1334 public String getSequenceSetId()
1336 if (sequenceSetID == null)
1338 sequenceSetID = alignment.hashCode() + "";
1341 return sequenceSetID;
1345 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1348 protected String viewId = null;
1351 public String getViewId()
1355 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1360 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1362 ignoreGapsInConsensusCalculation = b;
1365 updateConsensus(ap);
1366 if (residueShading != null)
1368 residueShading.setThreshold(residueShading.getThreshold(),
1369 ignoreGapsInConsensusCalculation);
1374 public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap)
1376 ignoreBelowBackGroundFrequencyCalculation = b;
1379 public void setInfoLetterHeight(boolean b, AlignmentViewPanel ap)
1381 infoLetterHeight = b;
1384 private long sgrouphash = -1, colselhash = -1;
1387 * checks current SelectionGroup against record of last hash value, and
1391 * update the record of last hash value
1393 * @return true if SelectionGroup changed since last call (when b is true)
1395 public boolean isSelectionGroupChanged(boolean b)
1397 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1398 : selectionGroup.hashCode();
1399 if (hc != -1 && hc != sgrouphash)
1411 * checks current colsel against record of last hash value, and optionally
1415 * update the record of last hash value
1416 * @return true if colsel changed since last call (when b is true)
1418 public boolean isColSelChanged(boolean updateHash)
1420 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1421 if (hc != -1 && hc != colselhash)
1434 public boolean isIgnoreGapsConsensus()
1436 return ignoreGapsInConsensusCalculation;
1440 public boolean isIgnoreBelowBackground()
1442 return ignoreBelowBackGroundFrequencyCalculation;
1446 public boolean isInfoLetterHeight()
1448 return infoLetterHeight;
1451 // property change stuff
1452 // JBPNote Prolly only need this in the applet version.
1453 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1456 protected boolean showConservation = true;
1458 protected boolean showQuality = true;
1460 protected boolean showConsensus = true;
1462 protected boolean showOccupancy = true;
1464 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1466 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1468 protected boolean showAutocalculatedAbove;
1471 * when set, view will scroll to show the highlighted position
1473 private boolean followHighlight = true;
1476 * Property change listener for changes in alignment
1481 public void addPropertyChangeListener(
1482 java.beans.PropertyChangeListener listener)
1484 changeSupport.addPropertyChangeListener(listener);
1493 public void removePropertyChangeListener(
1494 java.beans.PropertyChangeListener listener)
1496 if (changeSupport != null)
1498 changeSupport.removePropertyChangeListener(listener);
1502 // common hide/show column stuff
1504 public void hideSelectedColumns()
1506 if (colSel.isEmpty())
1511 colSel.hideSelectedColumns(alignment);
1512 setSelectionGroup(null);
1513 isColSelChanged(true);
1516 public void hideColumns(int start, int end)
1520 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1524 alignment.getHiddenColumns().hideColumns(start, end);
1526 isColSelChanged(true);
1529 public void showColumn(int col)
1531 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1532 isColSelChanged(true);
1535 public void showAllHiddenColumns()
1537 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1538 isColSelChanged(true);
1541 // common hide/show seq stuff
1542 public void showAllHiddenSeqs()
1544 int startSeq = ranges.getStartSeq();
1545 int endSeq = ranges.getEndSeq();
1547 if (alignment.getHiddenSequences().getSize() > 0)
1549 if (selectionGroup == null)
1551 selectionGroup = new SequenceGroup();
1552 selectionGroup.setEndRes(alignment.getWidth() - 1);
1554 List<SequenceI> tmp = alignment.getHiddenSequences()
1555 .showAll(hiddenRepSequences);
1556 for (SequenceI seq : tmp)
1558 selectionGroup.addSequence(seq, false);
1559 setSequenceAnnotationsVisible(seq, true);
1562 hiddenRepSequences = null;
1564 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1566 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1574 public void showSequence(int index)
1576 int startSeq = ranges.getStartSeq();
1577 int endSeq = ranges.getEndSeq();
1579 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1580 hiddenRepSequences);
1583 if (selectionGroup == null)
1585 selectionGroup = new SequenceGroup();
1586 selectionGroup.setEndRes(alignment.getWidth() - 1);
1589 for (SequenceI seq : tmp)
1591 selectionGroup.addSequence(seq, false);
1592 setSequenceAnnotationsVisible(seq, true);
1595 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1601 public void hideAllSelectedSeqs()
1603 if (selectionGroup == null || selectionGroup.getSize() < 1)
1608 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1612 setSelectionGroup(null);
1615 public void hideSequence(SequenceI[] seq)
1618 * cache offset to first visible sequence
1620 int startSeq = ranges.getStartSeq();
1624 for (int i = 0; i < seq.length; i++)
1626 alignment.getHiddenSequences().hideSequence(seq[i]);
1627 setSequenceAnnotationsVisible(seq[i], false);
1629 ranges.setStartSeq(startSeq);
1635 * Hides the specified sequence, or the sequences it represents
1638 * the sequence to hide, or keep as representative
1639 * @param representGroup
1640 * if true, hide the current selection group except for the
1641 * representative sequence
1643 public void hideSequences(SequenceI sequence, boolean representGroup)
1645 if (selectionGroup == null || selectionGroup.getSize() < 1)
1647 hideSequence(new SequenceI[] { sequence });
1653 hideRepSequences(sequence, selectionGroup);
1654 setSelectionGroup(null);
1658 int gsize = selectionGroup.getSize();
1659 SequenceI[] hseqs = selectionGroup.getSequences()
1660 .toArray(new SequenceI[gsize]);
1662 hideSequence(hseqs);
1663 setSelectionGroup(null);
1668 * Set visibility for any annotations for the given sequence.
1672 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1675 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1678 for (AlignmentAnnotation ann : anns)
1680 if (ann.sequenceRef == sequenceI)
1682 ann.visible = visible;
1688 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1690 int sSize = sg.getSize();
1696 if (hiddenRepSequences == null)
1698 hiddenRepSequences = new Hashtable<>();
1701 hiddenRepSequences.put(repSequence, sg);
1703 // Hide all sequences except the repSequence
1704 SequenceI[] seqs = new SequenceI[sSize - 1];
1706 for (int i = 0; i < sSize; i++)
1708 if (sg.getSequenceAt(i) != repSequence)
1710 if (index == sSize - 1)
1715 seqs[index++] = sg.getSequenceAt(i);
1718 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1719 sg.setHidereps(true); // note: not done in 2.7applet
1726 * @return null or the current reference sequence
1728 public SequenceI getReferenceSeq()
1730 return alignment.getSeqrep();
1735 * @return true iff seq is the reference for the alignment
1737 public boolean isReferenceSeq(SequenceI seq)
1739 return alignment.getSeqrep() == seq;
1745 * @return true if there are sequences represented by this sequence that are
1748 public boolean isHiddenRepSequence(SequenceI seq)
1750 return (hiddenRepSequences != null
1751 && hiddenRepSequences.containsKey(seq));
1757 * @return null or a sequence group containing the sequences that seq
1760 public SequenceGroup getRepresentedSequences(SequenceI seq)
1762 return (SequenceGroup) (hiddenRepSequences == null ? null
1763 : hiddenRepSequences.get(seq));
1767 public int adjustForHiddenSeqs(int alignmentIndex)
1769 return alignment.getHiddenSequences()
1770 .adjustForHiddenSeqs(alignmentIndex);
1774 public void invertColumnSelection()
1776 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1777 isColSelChanged(true);
1781 public SequenceI[] getSelectionAsNewSequence()
1783 SequenceI[] sequences;
1784 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1785 // this was the only caller in the applet for this method
1786 // JBPNote: in applet, this method returned references to the alignment
1787 // sequences, and it did not honour the presence/absence of annotation
1788 // attached to the alignment (probably!)
1789 if (selectionGroup == null || selectionGroup.getSize() == 0)
1791 sequences = alignment.getSequencesArray();
1792 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1793 for (int i = 0; i < sequences.length; i++)
1795 // construct new sequence with subset of visible annotation
1796 sequences[i] = new Sequence(sequences[i], annots);
1801 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1808 public SequenceI[] getSequenceSelection()
1810 SequenceI[] sequences = null;
1811 if (selectionGroup != null)
1813 sequences = selectionGroup.getSequencesInOrder(alignment);
1815 if (sequences == null)
1817 sequences = alignment.getSequencesArray();
1823 public jalview.datamodel.AlignmentView getAlignmentView(
1824 boolean selectedOnly)
1826 return getAlignmentView(selectedOnly, false);
1830 public jalview.datamodel.AlignmentView getAlignmentView(
1831 boolean selectedOnly, boolean markGroups)
1833 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1835 alignment.getHiddenColumns() != null
1836 && alignment.getHiddenColumns().hasHiddenColumns(),
1837 selectedOnly, markGroups);
1841 public String[] getViewAsString(boolean selectedRegionOnly)
1843 return getViewAsString(selectedRegionOnly, true);
1847 public String[] getViewAsString(boolean selectedRegionOnly,
1848 boolean exportHiddenSeqs)
1850 String[] selection = null;
1851 SequenceI[] seqs = null;
1853 int start = 0, end = 0;
1854 if (selectedRegionOnly && selectionGroup != null)
1856 iSize = selectionGroup.getSize();
1857 seqs = selectionGroup.getSequencesInOrder(alignment);
1858 start = selectionGroup.getStartRes();
1859 end = selectionGroup.getEndRes() + 1;
1863 if (hasHiddenRows() && exportHiddenSeqs)
1865 AlignmentI fullAlignment = alignment.getHiddenSequences()
1866 .getFullAlignment();
1867 iSize = fullAlignment.getHeight();
1868 seqs = fullAlignment.getSequencesArray();
1869 end = fullAlignment.getWidth();
1873 iSize = alignment.getHeight();
1874 seqs = alignment.getSequencesArray();
1875 end = alignment.getWidth();
1879 selection = new String[iSize];
1880 if (alignment.getHiddenColumns() != null
1881 && alignment.getHiddenColumns().hasHiddenColumns())
1883 for (i = 0; i < iSize; i++)
1885 Iterator<int[]> blocks = alignment.getHiddenColumns()
1886 .getVisContigsIterator(start, end + 1, false);
1887 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1892 for (i = 0; i < iSize; i++)
1894 selection[i] = seqs[i].getSequenceAsString(start, end);
1902 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1904 ArrayList<int[]> regions = new ArrayList<>();
1910 HiddenColumns hidden = alignment.getHiddenColumns();
1911 if (hidden != null && hidden.hasHiddenColumns())
1915 start = hidden.visibleToAbsoluteColumn(start);
1918 end = hidden.getNextHiddenBoundary(false, start);
1929 regions.add(new int[] { start, end });
1931 if (hidden != null && hidden.hasHiddenColumns())
1933 start = hidden.visibleToAbsoluteColumn(end);
1934 start = hidden.getNextHiddenBoundary(true, start) + 1;
1936 } while (end < max);
1938 // int[][] startEnd = new int[regions.size()][2];
1944 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1945 boolean selectedOnly)
1947 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1948 AlignmentAnnotation[] aa;
1949 if ((aa = alignment.getAlignmentAnnotation()) != null)
1951 for (AlignmentAnnotation annot : aa)
1953 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1954 if (selectedOnly && selectionGroup != null)
1956 clone.makeVisibleAnnotation(
1957 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1958 alignment.getHiddenColumns());
1962 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1971 public boolean isPadGaps()
1977 public void setPadGaps(boolean padGaps)
1979 this.padGaps = padGaps;
1983 * apply any post-edit constraints and trigger any calculations needed after
1984 * an edit has been performed on the alignment
1989 public void alignmentChanged(AlignmentViewPanel ap)
1993 alignment.padGaps();
1995 if (autoCalculateConsensusAndConservation)
1997 updateConsensus(ap);
1999 if (hconsensus != null && autoCalculateConsensusAndConservation)
2001 updateConservation(ap);
2003 if (autoCalculateStrucConsensus)
2005 updateStrucConsensus(ap);
2008 // Reset endRes of groups if beyond alignment width
2009 int alWidth = alignment.getWidth();
2010 List<SequenceGroup> groups = alignment.getGroups();
2013 for (SequenceGroup sg : groups)
2015 if (sg.getEndRes() > alWidth)
2017 sg.setEndRes(alWidth - 1);
2022 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
2024 selectionGroup.setEndRes(alWidth - 1);
2027 updateAllColourSchemes();
2028 calculator.restartWorkers();
2032 * reset scope and do calculations for all applied colourschemes on alignment
2034 void updateAllColourSchemes()
2036 ResidueShaderI rs = residueShading;
2039 rs.alignmentChanged(alignment, hiddenRepSequences);
2041 rs.setConsensus(hconsensus);
2042 if (rs.conservationApplied())
2044 rs.setConservation(Conservation.calculateConservation("All",
2045 alignment.getSequences(), 0, alignment.getWidth(), false,
2046 getConsPercGaps(), false));
2050 for (SequenceGroup sg : alignment.getGroups())
2054 sg.cs.alignmentChanged(sg, hiddenRepSequences);
2056 sg.recalcConservation();
2060 protected void initAutoAnnotation()
2062 // TODO: add menu option action that nulls or creates consensus object
2063 // depending on if the user wants to see the annotation or not in a
2064 // specific alignment
2066 if (hconsensus == null && !isDataset)
2068 if (!alignment.isNucleotide())
2077 consensus = new AlignmentAnnotation("Consensus",
2078 MessageManager.getString("label.consensus_descr"),
2079 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2080 initConsensus(consensus);
2084 initComplementConsensus();
2089 * If this is a protein alignment and there are mappings to cDNA, adds the
2090 * cDNA consensus annotation and returns true, else returns false.
2092 public boolean initComplementConsensus()
2094 if (!alignment.isNucleotide())
2096 final List<AlignedCodonFrame> codonMappings = alignment
2098 if (codonMappings != null && !codonMappings.isEmpty())
2100 boolean doConsensus = false;
2101 for (AlignedCodonFrame mapping : codonMappings)
2103 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2104 MapList[] mapLists = mapping.getdnaToProt();
2105 // mapLists can be empty if project load has not finished resolving
2107 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2115 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2117 .getString("label.complement_consensus_descr"),
2118 new Annotation[1], 0f, 100f,
2119 AlignmentAnnotation.BAR_GRAPH);
2120 initConsensus(complementConsensus);
2128 private void initConsensus(AlignmentAnnotation aa)
2131 aa.autoCalculated = true;
2135 alignment.addAnnotation(aa);
2139 // these should be extracted from the view model - style and settings for
2140 // derived annotation
2141 private void initGapCounts()
2145 gapcounts = new AlignmentAnnotation("Occupancy",
2146 MessageManager.getString("label.occupancy_descr"),
2147 new Annotation[1], 0f, alignment.getHeight(),
2148 AlignmentAnnotation.BAR_GRAPH);
2149 gapcounts.hasText = true;
2150 gapcounts.autoCalculated = true;
2151 gapcounts.scaleColLabel = true;
2152 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2154 alignment.addAnnotation(gapcounts);
2158 private void initConservation()
2160 if (showConservation)
2162 if (conservation == null)
2164 conservation = new AlignmentAnnotation("Conservation",
2165 MessageManager.formatMessage("label.conservation_descr",
2167 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2168 conservation.hasText = true;
2169 conservation.autoCalculated = true;
2170 alignment.addAnnotation(conservation);
2175 private void initQuality()
2179 if (quality == null)
2181 quality = new AlignmentAnnotation("Quality",
2182 MessageManager.getString("label.quality_descr"),
2183 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2184 quality.hasText = true;
2185 quality.autoCalculated = true;
2186 alignment.addAnnotation(quality);
2191 private void initRNAStructure()
2193 if (alignment.hasRNAStructure() && strucConsensus == null)
2195 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2196 MessageManager.getString("label.strucconsensus_descr"),
2197 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2198 strucConsensus.hasText = true;
2199 strucConsensus.autoCalculated = true;
2203 alignment.addAnnotation(strucConsensus);
2211 * @see jalview.api.AlignViewportI#calcPanelHeight()
2214 public int calcPanelHeight()
2216 // setHeight of panels
2217 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2219 int charHeight = getCharHeight();
2222 BitSet graphgrp = new BitSet();
2223 for (AlignmentAnnotation aa : anns)
2227 System.err.println("Null annotation row: ignoring.");
2234 if (aa.graphGroup > -1)
2236 if (graphgrp.get(aa.graphGroup))
2242 graphgrp.set(aa.graphGroup);
2249 aa.height += charHeight;
2259 aa.height += aa.graphHeight;
2267 height += aa.height;
2279 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2280 boolean preserveNewGroupSettings)
2282 boolean updateCalcs = false;
2283 boolean conv = isShowGroupConservation();
2284 boolean cons = isShowGroupConsensus();
2285 boolean showprf = isShowSequenceLogo();
2286 boolean showConsHist = isShowConsensusHistogram();
2287 boolean normLogo = isNormaliseSequenceLogo();
2288 boolean showHMMPrf = isShowHMMSequenceLogo();
2289 boolean showInfoHist = isShowInformationHistogram();
2290 boolean normHMMLogo = isNormaliseHMMSequenceLogo();
2293 * TODO reorder the annotation rows according to group/sequence ordering on
2296 // boolean sortg = true;
2298 // remove old automatic annotation
2299 // add any new annotation
2301 // intersect alignment annotation with alignment groups
2303 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2304 List<SequenceGroup> oldrfs = new ArrayList<>();
2307 for (int an = 0; an < aan.length; an++)
2309 if (aan[an].autoCalculated && aan[an].groupRef != null)
2311 oldrfs.add(aan[an].groupRef);
2312 alignment.deleteAnnotation(aan[an], false);
2316 if (alignment.getGroups() != null)
2318 for (SequenceGroup sg : alignment.getGroups())
2320 updateCalcs = false;
2321 if (applyGlobalSettings
2322 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2324 // set defaults for this group's conservation/consensus
2325 sg.setshowSequenceLogo(showprf);
2326 sg.setShowConsensusHistogram(showConsHist);
2327 sg.setNormaliseSequenceLogo(normLogo);
2328 sg.setShowHMMSequenceLogo(showHMMPrf);
2329 sg.setShowInformationHistogram(showInfoHist);
2330 sg.setNormaliseHMMSequenceLogo(normHMMLogo);
2335 alignment.addAnnotation(sg.getConservationRow(), 0);
2340 alignment.addAnnotation(sg.getConsensus(), 0);
2342 // refresh the annotation rows
2345 sg.recalcConservation();
2353 public boolean isDisplayReferenceSeq()
2355 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2359 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2361 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2365 public boolean isColourByReferenceSeq()
2367 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2371 public Color getSequenceColour(SequenceI seq)
2373 Color sqc = sequenceColours.get(seq);
2374 return (sqc == null ? Color.white : sqc);
2378 public void setSequenceColour(SequenceI seq, Color col)
2382 sequenceColours.remove(seq);
2386 sequenceColours.put(seq, col);
2391 public void updateSequenceIdColours()
2393 for (SequenceGroup sg : alignment.getGroups())
2395 if (sg.idColour != null)
2397 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2399 sequenceColours.put(s, sg.idColour);
2406 public void clearSequenceColours()
2408 sequenceColours.clear();
2412 public AlignViewportI getCodingComplement()
2414 return this.codingComplement;
2418 * Set this as the (cDna/protein) complement of the given viewport. Also
2419 * ensures the reverse relationship is set on the given viewport.
2422 public void setCodingComplement(AlignViewportI av)
2426 System.err.println("Ignoring recursive setCodingComplement request");
2430 this.codingComplement = av;
2431 // avoid infinite recursion!
2432 if (av.getCodingComplement() != this)
2434 av.setCodingComplement(this);
2440 public boolean isNucleotide()
2442 return getAlignment() == null ? false : getAlignment().isNucleotide();
2446 public FeaturesDisplayedI getFeaturesDisplayed()
2448 return featuresDisplayed;
2452 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2454 featuresDisplayed = featuresDisplayedI;
2458 public boolean areFeaturesDisplayed()
2460 return featuresDisplayed != null
2461 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2468 * features are displayed if true
2471 public void setShowSequenceFeatures(boolean b)
2473 viewStyle.setShowSequenceFeatures(b);
2477 public boolean isShowSequenceFeatures()
2479 return viewStyle.isShowSequenceFeatures();
2483 public void setShowSequenceFeaturesHeight(boolean selected)
2485 viewStyle.setShowSequenceFeaturesHeight(selected);
2489 public boolean isShowSequenceFeaturesHeight()
2491 return viewStyle.isShowSequenceFeaturesHeight();
2495 public void setShowAnnotation(boolean b)
2497 viewStyle.setShowAnnotation(b);
2501 public boolean isShowAnnotation()
2503 return viewStyle.isShowAnnotation();
2507 public boolean isRightAlignIds()
2509 return viewStyle.isRightAlignIds();
2513 public void setRightAlignIds(boolean rightAlignIds)
2515 viewStyle.setRightAlignIds(rightAlignIds);
2519 public boolean getConservationSelected()
2521 return viewStyle.getConservationSelected();
2525 public void setShowBoxes(boolean state)
2527 viewStyle.setShowBoxes(state);
2532 * @see jalview.api.ViewStyleI#getTextColour()
2535 public Color getTextColour()
2537 return viewStyle.getTextColour();
2542 * @see jalview.api.ViewStyleI#getTextColour2()
2545 public Color getTextColour2()
2547 return viewStyle.getTextColour2();
2552 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2555 public int getThresholdTextColour()
2557 return viewStyle.getThresholdTextColour();
2562 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2565 public boolean isConservationColourSelected()
2567 return viewStyle.isConservationColourSelected();
2572 * @see jalview.api.ViewStyleI#isRenderGaps()
2575 public boolean isRenderGaps()
2577 return viewStyle.isRenderGaps();
2582 * @see jalview.api.ViewStyleI#isShowColourText()
2585 public boolean isShowColourText()
2587 return viewStyle.isShowColourText();
2591 * @param conservationColourSelected
2592 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2595 public void setConservationColourSelected(
2596 boolean conservationColourSelected)
2598 viewStyle.setConservationColourSelected(conservationColourSelected);
2602 * @param showColourText
2603 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2606 public void setShowColourText(boolean showColourText)
2608 viewStyle.setShowColourText(showColourText);
2613 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2616 public void setTextColour(Color textColour)
2618 viewStyle.setTextColour(textColour);
2622 * @param thresholdTextColour
2623 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2626 public void setThresholdTextColour(int thresholdTextColour)
2628 viewStyle.setThresholdTextColour(thresholdTextColour);
2632 * @param textColour2
2633 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2636 public void setTextColour2(Color textColour2)
2638 viewStyle.setTextColour2(textColour2);
2642 public ViewStyleI getViewStyle()
2644 return new ViewStyle(viewStyle);
2648 public void setViewStyle(ViewStyleI settingsForView)
2650 viewStyle = new ViewStyle(settingsForView);
2651 if (residueShading != null)
2653 residueShading.setConservationApplied(
2654 settingsForView.isConservationColourSelected());
2659 public boolean sameStyle(ViewStyleI them)
2661 return viewStyle.sameStyle(them);
2666 * @see jalview.api.ViewStyleI#getIdWidth()
2669 public int getIdWidth()
2671 return viewStyle.getIdWidth();
2676 * @see jalview.api.ViewStyleI#setIdWidth(int)
2679 public void setIdWidth(int i)
2681 viewStyle.setIdWidth(i);
2686 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2689 public boolean isCentreColumnLabels()
2691 return viewStyle.isCentreColumnLabels();
2695 * @param centreColumnLabels
2696 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2699 public void setCentreColumnLabels(boolean centreColumnLabels)
2701 viewStyle.setCentreColumnLabels(centreColumnLabels);
2706 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2709 public void setShowDBRefs(boolean showdbrefs)
2711 viewStyle.setShowDBRefs(showdbrefs);
2716 * @see jalview.api.ViewStyleI#isShowDBRefs()
2719 public boolean isShowDBRefs()
2721 return viewStyle.isShowDBRefs();
2726 * @see jalview.api.ViewStyleI#isShowNPFeats()
2729 public boolean isShowNPFeats()
2731 return viewStyle.isShowNPFeats();
2735 * @param shownpfeats
2736 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2739 public void setShowNPFeats(boolean shownpfeats)
2741 viewStyle.setShowNPFeats(shownpfeats);
2744 public abstract StructureSelectionManager getStructureSelectionManager();
2747 * Add one command to the command history list.
2751 public void addToHistoryList(CommandI command)
2753 if (this.historyList != null)
2755 this.historyList.push(command);
2756 broadcastCommand(command, false);
2760 protected void broadcastCommand(CommandI command, boolean undo)
2762 getStructureSelectionManager().commandPerformed(command, undo,
2767 * Add one command to the command redo list.
2771 public void addToRedoList(CommandI command)
2773 if (this.redoList != null)
2775 this.redoList.push(command);
2777 broadcastCommand(command, true);
2781 * Clear the command redo list.
2783 public void clearRedoList()
2785 if (this.redoList != null)
2787 this.redoList.clear();
2791 public void setHistoryList(Deque<CommandI> list)
2793 this.historyList = list;
2796 public Deque<CommandI> getHistoryList()
2798 return this.historyList;
2801 public void setRedoList(Deque<CommandI> list)
2803 this.redoList = list;
2806 public Deque<CommandI> getRedoList()
2808 return this.redoList;
2812 public VamsasSource getVamsasSource()
2817 public SequenceAnnotationOrder getSortAnnotationsBy()
2819 return sortAnnotationsBy;
2822 public void setSortAnnotationsBy(
2823 SequenceAnnotationOrder sortAnnotationsBy)
2825 this.sortAnnotationsBy = sortAnnotationsBy;
2828 public boolean isShowAutocalculatedAbove()
2830 return showAutocalculatedAbove;
2833 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2835 this.showAutocalculatedAbove = showAutocalculatedAbove;
2839 public boolean isScaleProteinAsCdna()
2841 return viewStyle.isScaleProteinAsCdna();
2845 public void setScaleProteinAsCdna(boolean b)
2847 viewStyle.setScaleProteinAsCdna(b);
2851 public boolean isProteinFontAsCdna()
2853 return viewStyle.isProteinFontAsCdna();
2857 public void setProteinFontAsCdna(boolean b)
2859 viewStyle.setProteinFontAsCdna(b);
2863 public void setShowComplementFeatures(boolean b)
2865 viewStyle.setShowComplementFeatures(b);
2869 public boolean isShowComplementFeatures()
2871 return viewStyle.isShowComplementFeatures();
2875 public void setShowComplementFeaturesOnTop(boolean b)
2877 viewStyle.setShowComplementFeaturesOnTop(b);
2881 public boolean isShowComplementFeaturesOnTop()
2883 return viewStyle.isShowComplementFeaturesOnTop();
2887 * @return true if view should scroll to show the highlighted region of a
2892 public final boolean isFollowHighlight()
2894 return followHighlight;
2898 public final void setFollowHighlight(boolean b)
2900 this.followHighlight = b;
2904 public ViewportRanges getRanges()
2910 * Helper method to populate the SearchResults with the location in the
2911 * complementary alignment to scroll to, in order to match this one.
2914 * the SearchResults to add to
2915 * @return the offset (below top of visible region) of the matched sequence
2917 protected int findComplementScrollTarget(SearchResultsI sr)
2919 final AlignViewportI complement = getCodingComplement();
2920 if (complement == null || !complement.isFollowHighlight())
2924 boolean iAmProtein = !getAlignment().isNucleotide();
2925 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2926 : complement.getAlignment();
2927 if (proteinAlignment == null)
2931 final List<AlignedCodonFrame> mappings = proteinAlignment
2935 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2936 * residue in the middle column of the visible region. Scroll the
2937 * complementary alignment to line up the corresponding residue.
2940 SequenceI sequence = null;
2943 * locate 'middle' column (true middle if an odd number visible, left of
2944 * middle if an even number visible)
2946 int middleColumn = ranges.getStartRes()
2947 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2948 final HiddenSequences hiddenSequences = getAlignment()
2949 .getHiddenSequences();
2952 * searching to the bottom of the alignment gives smoother scrolling across
2953 * all gapped visible regions
2955 int lastSeq = alignment.getHeight() - 1;
2956 List<AlignedCodonFrame> seqMappings = null;
2957 for (int seqNo = ranges
2958 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2960 sequence = getAlignment().getSequenceAt(seqNo);
2961 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2965 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2969 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2971 getCodingComplement().getAlignment().getSequences());
2972 if (!seqMappings.isEmpty())
2978 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2981 * No ungapped mapped sequence in middle column - do nothing
2985 MappingUtils.addSearchResults(sr, sequence,
2986 sequence.findPosition(middleColumn), seqMappings);
2991 * synthesize a column selection if none exists so it covers the given
2992 * selection group. if wholewidth is false, no column selection is made if the
2993 * selection group covers the whole alignment width.
2998 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
3001 if (sg != null && (sgs = sg.getStartRes()) >= 0
3002 && sg.getStartRes() <= (sge = sg.getEndRes())
3003 && !this.hasSelectedColumns())
3005 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
3012 colSel = new ColumnSelection();
3014 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
3016 colSel.addElement(cspos);
3022 * hold status of current selection group - defined on alignment or not.
3024 private boolean selectionIsDefinedGroup = false;
3027 public boolean isSelectionDefinedGroup()
3029 if (selectionGroup == null)
3033 if (isSelectionGroupChanged(true))
3035 selectionIsDefinedGroup = false;
3036 List<SequenceGroup> gps = alignment.getGroups();
3037 if (gps == null || gps.size() == 0)
3039 selectionIsDefinedGroup = false;
3043 selectionIsDefinedGroup = gps.contains(selectionGroup);
3046 return selectionGroup.isDefined() || selectionIsDefinedGroup;
3050 * null, or currently highlighted results on this view
3052 private SearchResultsI searchResults = null;
3054 protected TreeModel currentTree = null;
3057 public boolean hasSearchResults()
3059 return searchResults != null;
3063 public void setSearchResults(SearchResultsI results)
3065 searchResults = results;
3069 public SearchResultsI getSearchResults()
3071 return searchResults;
3075 * get the consensus sequence as displayed under the PID consensus annotation
3078 * @return consensus sequence as a new sequence object
3080 public SequenceI getConsensusSeq()
3082 if (consensus == null)
3084 updateConsensus(null);
3086 if (consensus == null)
3090 StringBuffer seqs = new StringBuffer();
3091 for (int i = 0; i < consensus.annotations.length; i++)
3093 Annotation annotation = consensus.annotations[i];
3094 if (annotation != null)
3096 String description = annotation.description;
3097 if (description != null && description.startsWith("["))
3099 // consensus is a tie - just pick the first one
3100 seqs.append(description.charAt(1));
3104 seqs.append(annotation.displayCharacter);
3109 SequenceI sq = new Sequence("Consensus", seqs.toString());
3110 sq.setDescription("Percentage Identity Consensus "
3111 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3115 public boolean hasReferenceAnnotation()
3117 AlignmentAnnotation[] annots = this.alignment.getAlignmentAnnotation();
3118 for (AlignmentAnnotation annot : annots)
3120 if ("RF".equals(annot.label) || annot.label.contains("Reference"))
3129 public void setCurrentTree(TreeModel tree)
3135 public TreeModel getCurrentTree()
3141 public AlignmentExportData getAlignExportData(AlignExportSettingsI options)
3143 AlignmentI alignmentToExport = null;
3144 String[] omitHidden = null;
3145 alignmentToExport = null;
3147 if (hasHiddenColumns() && !options.isExportHiddenColumns())
3149 omitHidden = getViewAsString(false,
3150 options.isExportHiddenSequences());
3153 int[] alignmentStartEnd = new int[2];
3154 if (hasHiddenRows() && options.isExportHiddenSequences())
3156 alignmentToExport = getAlignment().getHiddenSequences()
3157 .getFullAlignment();
3161 alignmentToExport = getAlignment();
3163 alignmentStartEnd = getAlignment().getHiddenColumns()
3164 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
3165 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
3166 omitHidden, alignmentStartEnd);
3171 public boolean isNormaliseSequenceLogo()
3173 return normaliseSequenceLogo;
3176 public void setNormaliseSequenceLogo(boolean state)
3178 normaliseSequenceLogo = state;
3182 public boolean isNormaliseHMMSequenceLogo()
3184 return hmmNormaliseSequenceLogo;
3187 public void setNormaliseHMMSequenceLogo(boolean state)
3189 hmmNormaliseSequenceLogo = state;
3192 * flag set to indicate if structure views might be out of sync with sequences
3196 private boolean needToUpdateStructureViews = false;
3199 public boolean isUpdateStructures()
3201 return needToUpdateStructureViews;
3205 public void setUpdateStructures(boolean update)
3207 needToUpdateStructureViews = update;
3211 public boolean needToUpdateStructureViews()
3213 boolean update = needToUpdateStructureViews;
3214 needToUpdateStructureViews = false;
3219 public void addSequenceGroup(SequenceGroup sequenceGroup)
3221 alignment.addGroup(sequenceGroup);
3223 Color col = sequenceGroup.idColour;
3226 col = col.brighter();
3228 for (SequenceI sq : sequenceGroup.getSequences())
3230 setSequenceColour(sq, col);
3234 if (codingComplement != null)
3236 SequenceGroup mappedGroup = MappingUtils
3237 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3238 if (mappedGroup.getSequences().size() > 0)
3240 codingComplement.getAlignment().addGroup(mappedGroup);
3244 for (SequenceI seq : mappedGroup.getSequences())
3246 codingComplement.setSequenceColour(seq, col);
3250 // propagate the structure view update flag according to our own setting
3251 codingComplement.setUpdateStructures(needToUpdateStructureViews);
3255 * Filters out sequences with an eValue higher than the specified value. The
3256 * filtered sequences are hidden or deleted. Sequences with no eValues are also
3262 public void filterByEvalue(double eValue)
3264 for (SequenceI seq : alignment.getSequencesArray())
3266 if ((seq.getAnnotation("Search Scores") == null
3267 || seq.getAnnotation("Search Scores")[0].getEValue() > eValue)
3268 && seq.getHMM() == null)
3270 hideSequence(new SequenceI[] { seq });
3276 * Filters out sequences with an score lower than the specified value. The
3277 * filtered sequences are hidden or deleted.
3282 public void filterByScore(double score)
3284 for (SequenceI seq : alignment.getSequencesArray())
3286 if ((seq.getAnnotation("Search Scores") == null
3287 || seq.getAnnotation("Search Scores")[0]
3288 .getBitScore() < score)
3289 && seq.getHMM() == null)
3291 hideSequence(new SequenceI[] { seq });
3297 * Notify TreePanel and AlignmentPanel of some sort of alignment change.
3299 public void notifyAlignment()
3301 changeSupport.firePropertyChange(PROPERTY_ALIGNMENT, null, alignment.getSequences());
3305 * Notify AlignmentPanel of a sequence column selection or visibility changes.
3307 public void notifySequence()
3309 changeSupport.firePropertyChange(PROPERTY_SEQUENCE, null, null);