2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.viewmodel;
23 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
24 import jalview.analysis.Conservation;
25 import jalview.analysis.TreeModel;
26 import jalview.api.AlignCalcManagerI;
27 import jalview.api.AlignViewportI;
28 import jalview.api.AlignmentViewPanel;
29 import jalview.api.FeaturesDisplayedI;
30 import jalview.api.ViewStyleI;
31 import jalview.commands.CommandI;
32 import jalview.datamodel.AlignedCodonFrame;
33 import jalview.datamodel.AlignmentAnnotation;
34 import jalview.datamodel.AlignmentI;
35 import jalview.datamodel.AlignmentView;
36 import jalview.datamodel.Annotation;
37 import jalview.datamodel.ColumnSelection;
38 import jalview.datamodel.HiddenColumns;
39 import jalview.datamodel.HiddenSequences;
40 import jalview.datamodel.ProfileI;
41 import jalview.datamodel.Profiles;
42 import jalview.datamodel.ProfilesI;
43 import jalview.datamodel.SearchResultsI;
44 import jalview.datamodel.Sequence;
45 import jalview.datamodel.SequenceCollectionI;
46 import jalview.datamodel.SequenceGroup;
47 import jalview.datamodel.SequenceI;
48 import jalview.renderer.ResidueShader;
49 import jalview.renderer.ResidueShaderI;
50 import jalview.schemes.ColourSchemeI;
51 import jalview.structure.CommandListener;
52 import jalview.structure.StructureSelectionManager;
53 import jalview.structure.VamsasSource;
54 import jalview.util.Comparison;
55 import jalview.util.MapList;
56 import jalview.util.MappingUtils;
57 import jalview.util.MessageManager;
58 import jalview.viewmodel.styles.ViewStyle;
59 import jalview.workers.AlignCalcManager;
60 import jalview.workers.ComplementConsensusThread;
61 import jalview.workers.ConsensusThread;
62 import jalview.workers.InformationThread;
63 import jalview.workers.StrucConsensusThread;
65 import java.awt.Color;
66 import java.beans.PropertyChangeSupport;
67 import java.util.ArrayDeque;
68 import java.util.ArrayList;
69 import java.util.BitSet;
70 import java.util.Deque;
71 import java.util.HashMap;
72 import java.util.Hashtable;
73 import java.util.List;
77 * base class holding visualization and analysis attributes and common logic for
78 * an active alignment view displayed in the GUI
83 public abstract class AlignmentViewport
84 implements AlignViewportI, CommandListener, VamsasSource
86 protected ViewportRanges ranges;
88 protected ViewStyleI viewStyle = new ViewStyle();
91 * A viewport that hosts the cDna view of this (protein), or vice versa (if
94 AlignViewportI codingComplement = null;
96 FeaturesDisplayedI featuresDisplayed = null;
98 protected Deque<CommandI> historyList = new ArrayDeque<>();
100 protected Deque<CommandI> redoList = new ArrayDeque<>();
102 protected String sequenceSetID;
105 * probably unused indicator that view is of a dataset rather than an
108 protected boolean isDataset = false;
110 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
112 protected ColumnSelection colSel = new ColumnSelection();
114 public boolean autoCalculateConsensus = true;
116 public boolean autoCalculateInformation = true;
118 protected boolean autoCalculateStrucConsensus = true;
120 protected boolean ignoreGapsInConsensusCalculation = false;
122 protected boolean ignoreBelowBackGroundFrequencyCalculation = false;
124 protected boolean infoLetterHeight = false;
126 protected ResidueShaderI residueShading = new ResidueShader();
128 protected AlignmentAnnotation consensus;
130 protected AlignmentAnnotation complementConsensus;
132 protected AlignmentAnnotation occupancy;
134 protected AlignmentAnnotation strucConsensus;
136 protected AlignmentAnnotation conservation;
138 protected AlignmentAnnotation quality;
140 protected List<AlignmentAnnotation> information = new ArrayList<>();
143 * alignment displayed in the viewport
145 private AlignmentI alignment;
148 * results of alignment consensus analysis for visible portion of view
150 protected ProfilesI hconsensus = null;
153 * results of information annotation analysis for the visible portion of view
155 protected List<ProfilesI> hinformation = new ArrayList<>();
158 * results of cDNA complement consensus visible portion of view
160 protected Hashtable[] hcomplementConsensus = null;
163 * results of secondary structure base pair consensus for visible portion of
166 protected Hashtable[] hStrucConsensus = null;
168 protected Conservation hconservation = null;
170 public AlignmentViewport(AlignmentI al)
173 ranges = new ViewportRanges(al);
178 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
181 public void setFontName(String name)
183 viewStyle.setFontName(name);
188 * @see jalview.api.ViewStyleI#setFontStyle(int)
191 public void setFontStyle(int style)
193 viewStyle.setFontStyle(style);
198 * @see jalview.api.ViewStyleI#setFontSize(int)
201 public void setFontSize(int size)
203 viewStyle.setFontSize(size);
208 * @see jalview.api.ViewStyleI#getFontStyle()
211 public int getFontStyle()
213 return viewStyle.getFontStyle();
218 * @see jalview.api.ViewStyleI#getFontName()
221 public String getFontName()
223 return viewStyle.getFontName();
228 * @see jalview.api.ViewStyleI#getFontSize()
231 public int getFontSize()
233 return viewStyle.getFontSize();
237 * @param upperCasebold
238 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
241 public void setUpperCasebold(boolean upperCasebold)
243 viewStyle.setUpperCasebold(upperCasebold);
248 * @see jalview.api.ViewStyleI#isUpperCasebold()
251 public boolean isUpperCasebold()
253 return viewStyle.isUpperCasebold();
258 * @see jalview.api.ViewStyleI#isSeqNameItalics()
261 public boolean isSeqNameItalics()
263 return viewStyle.isSeqNameItalics();
267 * @param colourByReferenceSeq
268 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
271 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
273 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
278 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
281 public void setColourAppliesToAllGroups(boolean b)
283 viewStyle.setColourAppliesToAllGroups(b);
288 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
291 public boolean getColourAppliesToAllGroups()
293 return viewStyle.getColourAppliesToAllGroups();
298 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
301 public boolean getAbovePIDThreshold()
303 return viewStyle.getAbovePIDThreshold();
308 * @see jalview.api.ViewStyleI#setIncrement(int)
311 public void setIncrement(int inc)
313 viewStyle.setIncrement(inc);
318 * @see jalview.api.ViewStyleI#getIncrement()
321 public int getIncrement()
323 return viewStyle.getIncrement();
328 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
331 public void setConservationSelected(boolean b)
333 viewStyle.setConservationSelected(b);
338 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
341 public void setShowHiddenMarkers(boolean show)
343 viewStyle.setShowHiddenMarkers(show);
348 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
351 public boolean getShowHiddenMarkers()
353 return viewStyle.getShowHiddenMarkers();
358 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
361 public void setScaleRightWrapped(boolean b)
363 viewStyle.setScaleRightWrapped(b);
368 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
371 public void setScaleLeftWrapped(boolean b)
373 viewStyle.setScaleLeftWrapped(b);
378 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
381 public void setScaleAboveWrapped(boolean b)
383 viewStyle.setScaleAboveWrapped(b);
388 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
391 public boolean getScaleLeftWrapped()
393 return viewStyle.getScaleLeftWrapped();
398 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
401 public boolean getScaleAboveWrapped()
403 return viewStyle.getScaleAboveWrapped();
408 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
411 public boolean getScaleRightWrapped()
413 return viewStyle.getScaleRightWrapped();
418 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
421 public void setAbovePIDThreshold(boolean b)
423 viewStyle.setAbovePIDThreshold(b);
428 * @see jalview.api.ViewStyleI#setThreshold(int)
431 public void setThreshold(int thresh)
433 viewStyle.setThreshold(thresh);
438 * @see jalview.api.ViewStyleI#getThreshold()
441 public int getThreshold()
443 return viewStyle.getThreshold();
448 * @see jalview.api.ViewStyleI#getShowJVSuffix()
451 public boolean getShowJVSuffix()
453 return viewStyle.getShowJVSuffix();
458 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
461 public void setShowJVSuffix(boolean b)
463 viewStyle.setShowJVSuffix(b);
468 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
471 public void setWrapAlignment(boolean state)
473 viewStyle.setWrapAlignment(state);
474 ranges.setWrappedMode(state);
479 * @see jalview.api.ViewStyleI#setShowText(boolean)
482 public void setShowText(boolean state)
484 viewStyle.setShowText(state);
489 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
492 public void setRenderGaps(boolean state)
494 viewStyle.setRenderGaps(state);
499 * @see jalview.api.ViewStyleI#getColourText()
502 public boolean getColourText()
504 return viewStyle.getColourText();
509 * @see jalview.api.ViewStyleI#setColourText(boolean)
512 public void setColourText(boolean state)
514 viewStyle.setColourText(state);
519 * @see jalview.api.ViewStyleI#getWrapAlignment()
522 public boolean getWrapAlignment()
524 return viewStyle.getWrapAlignment();
529 * @see jalview.api.ViewStyleI#getShowText()
532 public boolean getShowText()
534 return viewStyle.getShowText();
539 * @see jalview.api.ViewStyleI#getWrappedWidth()
542 public int getWrappedWidth()
544 return viewStyle.getWrappedWidth();
549 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
552 public void setWrappedWidth(int w)
554 viewStyle.setWrappedWidth(w);
559 * @see jalview.api.ViewStyleI#getCharHeight()
562 public int getCharHeight()
564 return viewStyle.getCharHeight();
569 * @see jalview.api.ViewStyleI#setCharHeight(int)
572 public void setCharHeight(int h)
574 viewStyle.setCharHeight(h);
579 * @see jalview.api.ViewStyleI#getCharWidth()
582 public int getCharWidth()
584 return viewStyle.getCharWidth();
589 * @see jalview.api.ViewStyleI#setCharWidth(int)
592 public void setCharWidth(int w)
594 viewStyle.setCharWidth(w);
599 * @see jalview.api.ViewStyleI#getShowBoxes()
602 public boolean getShowBoxes()
604 return viewStyle.getShowBoxes();
609 * @see jalview.api.ViewStyleI#getShowUnconserved()
612 public boolean getShowUnconserved()
614 return viewStyle.getShowUnconserved();
618 * @param showunconserved
619 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
622 public void setShowUnconserved(boolean showunconserved)
624 viewStyle.setShowUnconserved(showunconserved);
629 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
632 public void setSeqNameItalics(boolean default1)
634 viewStyle.setSeqNameItalics(default1);
638 public AlignmentI getAlignment()
644 public char getGapCharacter()
646 return alignment.getGapCharacter();
649 public void setDataset(boolean b)
654 public boolean isDataset()
660 public void setGlobalColourScheme(ColourSchemeI cs)
662 // TODO: logic refactored from AlignFrame changeColour -
663 // TODO: autorecalc stuff should be changed to rely on the worker system
664 // check to see if we should implement a changeColour(cs) method rather than
665 // put the logic in here
666 // - means that caller decides if they want to just modify state and defer
667 // calculation till later or to do all calculations in thread.
671 * only instantiate alignment colouring once, thereafter update it;
672 * this means that any conservation or PID threshold settings
673 * persist when the alignment colour scheme is changed
675 if (residueShading == null)
677 residueShading = new ResidueShader(viewStyle);
679 residueShading.setColourScheme(cs);
681 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
682 // ...problem: groups need these, but do not currently have a ViewStyle
686 if (getConservationSelected())
688 residueShading.setConservation(hconservation);
691 * reset conservation flag in case just set to false if
692 * Conservation was null (calculation still in progress)
694 residueShading.setConservationApplied(getConservationSelected());
695 residueShading.alignmentChanged(alignment, hiddenRepSequences);
699 * if 'apply colour to all groups' is selected... do so
700 * (but don't transfer any colour threshold settings to groups)
702 if (getColourAppliesToAllGroups())
704 for (SequenceGroup sg : getAlignment().getGroups())
707 * retain any colour thresholds per group while
708 * changing choice of colour scheme (JAL-2386)
710 sg.setColourScheme(cs);
713 sg.getGroupColourScheme().alignmentChanged(sg,
721 public ColourSchemeI getGlobalColourScheme()
723 return residueShading == null ? null : residueShading.getColourScheme();
727 public ResidueShaderI getResidueShading()
729 return residueShading;
732 public void setConservation(Conservation cons)
734 hconservation = cons;
738 * percentage gaps allowed in a column before all amino acid properties should
739 * be considered unconserved
741 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
744 public int getConsPercGaps()
750 public void setSequenceConsensusHash(ProfilesI hconsensus)
752 this.hconsensus = hconsensus;
756 public void setComplementConsensusHash(Hashtable[] hconsensus)
758 this.hcomplementConsensus = hconsensus;
762 public ProfilesI getSequenceConsensusHash()
768 public void setSequenceInformationHashes(List<ProfilesI> info)
774 public void setSequenceInformationHash(ProfilesI info, int index)
776 if (hinformation.size() < index + 1)
780 hinformation.set(index, info);
784 public List<ProfilesI> getSequenceInformationHashes()
790 public ProfilesI getSequenceInformationHash(int index)
792 return hinformation.get(index);
796 public Hashtable[] getComplementConsensusHash()
798 return hcomplementConsensus;
802 public Hashtable[] getRnaStructureConsensusHash()
804 return hStrucConsensus;
808 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
810 this.hStrucConsensus = hStrucConsensus;
815 public AlignmentAnnotation getAlignmentQualityAnnot()
821 public AlignmentAnnotation getAlignmentConservationAnnotation()
827 public AlignmentAnnotation getAlignmentConsensusAnnotation()
833 public List<AlignmentAnnotation> getInformationAnnotations()
839 public AlignmentAnnotation getAlignmentGapAnnotation()
845 public AlignmentAnnotation getComplementConsensusAnnotation()
847 return complementConsensus;
851 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
853 return strucConsensus;
856 protected AlignCalcManagerI calculator = new AlignCalcManager();
859 * trigger update of conservation annotation
861 public void updateConservation(final AlignmentViewPanel ap)
863 // see note in mantis : issue number 8585
864 if (alignment.isNucleotide()
865 || (conservation == null && quality == null)
866 || !autoCalculateConsensus)
870 if (calculator.getRegisteredWorkersOfClass(
871 jalview.workers.ConservationThread.class) == null)
873 calculator.registerWorker(
874 new jalview.workers.ConservationThread(this, ap));
879 * trigger update of consensus annotation
881 public void updateConsensus(final AlignmentViewPanel ap)
883 // see note in mantis : issue number 8585
884 if (consensus == null || !autoCalculateConsensus)
889 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
891 calculator.registerWorker(new ConsensusThread(this, ap));
895 * A separate thread to compute cDNA consensus for a protein alignment
896 * which has mapping to cDNA
898 final AlignmentI al = this.getAlignment();
899 if (!al.isNucleotide() && al.getCodonFrames() != null
900 && !al.getCodonFrames().isEmpty())
903 * fudge - check first for protein-to-nucleotide mappings
904 * (we don't want to do this for protein-to-protein)
906 boolean doConsensus = false;
907 for (AlignedCodonFrame mapping : al.getCodonFrames())
909 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
910 MapList[] mapLists = mapping.getdnaToProt();
911 // mapLists can be empty if project load has not finished resolving seqs
912 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
920 if (calculator.getRegisteredWorkersOfClass(
921 ComplementConsensusThread.class) == null)
924 .registerWorker(new ComplementConsensusThread(this, ap));
931 * trigger update of information annotation
934 public void updateInformation(final AlignmentViewPanel ap)
937 .getRegisteredWorkersOfClass(InformationThread.class) == null)
939 calculator.registerWorker(new InformationThread(this, ap));
944 // --------START Structure Conservation
945 public void updateStrucConsensus(final AlignmentViewPanel ap)
947 if (autoCalculateStrucConsensus && strucConsensus == null
948 && alignment.isNucleotide() && alignment.hasRNAStructure())
950 // secondary structure has been added - so init the consensus line
954 // see note in mantis : issue number 8585
955 if (strucConsensus == null || !autoCalculateStrucConsensus)
959 if (calculator.getRegisteredWorkersOfClass(
960 StrucConsensusThread.class) == null)
962 calculator.registerWorker(new StrucConsensusThread(this, ap));
966 public boolean isCalcInProgress()
968 return calculator.isWorking();
972 public boolean isCalculationInProgress(
973 AlignmentAnnotation alignmentAnnotation)
975 if (!alignmentAnnotation.autoCalculated)
979 if (calculator.workingInvolvedWith(alignmentAnnotation))
981 // System.err.println("grey out ("+alignmentAnnotation.label+")");
987 public void setAlignment(AlignmentI align)
989 this.alignment = align;
993 * Clean up references when this viewport is closed
996 public void dispose()
999 * defensively null out references to large objects in case
1000 * this object is not garbage collected (as if!)
1003 complementConsensus = null;
1004 strucConsensus = null;
1005 conservation = null;
1008 hconservation = null;
1009 hcomplementConsensus = null;
1012 residueShading = null; // may hold a reference to Consensus
1013 changeSupport = null;
1016 selectionGroup = null;
1021 public boolean isClosed()
1023 // TODO: check that this isClosed is only true after panel is closed, not
1024 // before it is fully constructed.
1025 return alignment == null;
1029 public AlignCalcManagerI getCalcManager()
1035 * should conservation rows be shown for groups
1037 protected boolean showGroupConservation = false;
1040 * should consensus rows be shown for groups
1042 protected boolean showGroupConsensus = false;
1045 * should consensus profile be rendered by default
1047 protected boolean showSequenceLogo = false;
1050 * should consensus profile be rendered normalised to row height
1052 protected boolean normaliseSequenceLogo = false;
1055 * should consensus histograms be rendered by default
1057 protected boolean showConsensusHistogram = true;
1060 * should hmm profile be rendered by default
1062 protected boolean showHMMSequenceLogo = false;
1065 * should hmm profile be rendered normalised to row height
1067 protected boolean normaliseHMMSequenceLogo = false;
1070 * should information histograms be rendered by default
1072 protected boolean showInformationHistogram = true;
1075 * @return the showConsensusProfile
1078 public boolean isShowSequenceLogo()
1080 return showSequenceLogo;
1084 * @return the showInformationProfile
1087 public boolean isShowHMMSequenceLogo()
1089 return showHMMSequenceLogo;
1093 * @param showSequenceLogo
1096 public void setShowSequenceLogo(boolean showSequenceLogo)
1098 if (showSequenceLogo != this.showSequenceLogo)
1100 // TODO: decouple settings setting from calculation when refactoring
1101 // annotation update method from alignframe to viewport
1102 this.showSequenceLogo = showSequenceLogo;
1103 calculator.updateAnnotationFor(ConsensusThread.class);
1104 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1105 calculator.updateAnnotationFor(StrucConsensusThread.class);
1107 this.showSequenceLogo = showSequenceLogo;
1110 public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo)
1112 if (showHMMSequenceLogo != this.showHMMSequenceLogo)
1114 this.showHMMSequenceLogo = showHMMSequenceLogo;
1115 calculator.updateAnnotationFor(InformationThread.class);
1117 this.showHMMSequenceLogo = showHMMSequenceLogo;
1121 * @param showConsensusHistogram
1122 * the showConsensusHistogram to set
1124 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1126 this.showConsensusHistogram = showConsensusHistogram;
1130 * @param showInformationHistogram
1131 * the showInformationHistogram to set
1133 public void setShowInformationHistogram(boolean showInformationHistogram)
1135 this.showInformationHistogram = showInformationHistogram;
1139 * @return the showGroupConservation
1141 public boolean isShowGroupConservation()
1143 return showGroupConservation;
1147 * @param showGroupConservation
1148 * the showGroupConservation to set
1150 public void setShowGroupConservation(boolean showGroupConservation)
1152 this.showGroupConservation = showGroupConservation;
1156 * @return the showGroupConsensus
1158 public boolean isShowGroupConsensus()
1160 return showGroupConsensus;
1164 * @param showGroupConsensus
1165 * the showGroupConsensus to set
1167 public void setShowGroupConsensus(boolean showGroupConsensus)
1169 this.showGroupConsensus = showGroupConsensus;
1174 * @return flag to indicate if the consensus histogram should be rendered by
1178 public boolean isShowConsensusHistogram()
1180 return this.showConsensusHistogram;
1185 * @return flag to indicate if the information content histogram should be
1186 * rendered by default
1189 public boolean isShowInformationHistogram()
1191 return this.showInformationHistogram;
1195 * when set, updateAlignment will always ensure sequences are of equal length
1197 private boolean padGaps = false;
1200 * when set, alignment should be reordered according to a newly opened tree
1202 public boolean sortByTree = false;
1207 * @return null or the currently selected sequence region
1210 public SequenceGroup getSelectionGroup()
1212 return selectionGroup;
1216 * Set the selection group for this window. Also sets the current alignment as
1217 * the context for the group, if it does not already have one.
1220 * - group holding references to sequences in this alignment view
1224 public void setSelectionGroup(SequenceGroup sg)
1226 selectionGroup = sg;
1227 if (sg != null && sg.getContext() == null)
1229 sg.setContext(alignment);
1233 public void setHiddenColumns(HiddenColumns hidden)
1235 this.alignment.setHiddenColumns(hidden);
1239 public ColumnSelection getColumnSelection()
1245 public void setColumnSelection(ColumnSelection colSel)
1247 this.colSel = colSel;
1250 updateHiddenColumns();
1252 isColSelChanged(true);
1260 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1262 return hiddenRepSequences;
1266 public void setHiddenRepSequences(
1267 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1269 this.hiddenRepSequences = hiddenRepSequences;
1273 public boolean hasSelectedColumns()
1275 ColumnSelection columnSelection = getColumnSelection();
1276 return columnSelection != null && columnSelection.hasSelectedColumns();
1280 public boolean hasHiddenColumns()
1282 return alignment.getHiddenColumns() != null
1283 && alignment.getHiddenColumns().hasHiddenColumns();
1286 public void updateHiddenColumns()
1288 // this method doesn't really do anything now. But - it could, since a
1289 // column Selection could be in the process of modification
1290 // hasHiddenColumns = colSel.hasHiddenColumns();
1294 public boolean hasHiddenRows()
1296 return alignment.getHiddenSequences().getSize() > 0;
1299 protected SequenceGroup selectionGroup;
1301 public void setSequenceSetId(String newid)
1303 if (sequenceSetID != null)
1306 "Warning - overwriting a sequenceSetId for a viewport!");
1308 sequenceSetID = new String(newid);
1312 public String getSequenceSetId()
1314 if (sequenceSetID == null)
1316 sequenceSetID = alignment.hashCode() + "";
1319 return sequenceSetID;
1323 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1326 protected String viewId = null;
1329 public String getViewId()
1333 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1338 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1340 ignoreGapsInConsensusCalculation = b;
1343 updateConsensus(ap);
1344 if (residueShading != null)
1346 residueShading.setThreshold(residueShading.getThreshold(),
1347 ignoreGapsInConsensusCalculation);
1353 public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap)
1355 ignoreBelowBackGroundFrequencyCalculation = b;
1358 updateInformation(ap);
1363 public void setInfoLetterHeight(boolean b, AlignmentViewPanel ap)
1365 infoLetterHeight = b;
1368 updateInformation(ap);
1373 private long sgrouphash = -1, colselhash = -1;
1376 * checks current SelectionGroup against record of last hash value, and
1380 * update the record of last hash value
1382 * @return true if SelectionGroup changed since last call (when b is true)
1384 public boolean isSelectionGroupChanged(boolean b)
1386 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1387 : selectionGroup.hashCode();
1388 if (hc != -1 && hc != sgrouphash)
1400 * checks current colsel against record of last hash value, and optionally
1404 * update the record of last hash value
1405 * @return true if colsel changed since last call (when b is true)
1407 public boolean isColSelChanged(boolean b)
1409 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1410 if (hc != -1 && hc != colselhash)
1422 public boolean isIgnoreGapsConsensus()
1424 return ignoreGapsInConsensusCalculation;
1428 public boolean isIgnoreBelowBackground()
1430 return ignoreBelowBackGroundFrequencyCalculation;
1434 public boolean isInfoLetterHeight()
1436 return infoLetterHeight;
1439 // property change stuff
1440 // JBPNote Prolly only need this in the applet version.
1441 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1444 protected boolean showConservation = true;
1446 protected boolean showQuality = true;
1448 protected boolean showConsensus = true;
1450 protected boolean showOccupancy = true;
1452 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1454 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1456 protected boolean showAutocalculatedAbove;
1459 * when set, view will scroll to show the highlighted position
1461 private boolean followHighlight = true;
1464 * Property change listener for changes in alignment
1469 public void addPropertyChangeListener(
1470 java.beans.PropertyChangeListener listener)
1472 changeSupport.addPropertyChangeListener(listener);
1481 public void removePropertyChangeListener(
1482 java.beans.PropertyChangeListener listener)
1484 if (changeSupport != null)
1486 changeSupport.removePropertyChangeListener(listener);
1491 * Property change listener for changes in alignment
1500 public void firePropertyChange(String prop, Object oldvalue,
1503 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1506 // common hide/show column stuff
1508 public void hideSelectedColumns()
1510 if (colSel.isEmpty())
1515 colSel.hideSelectedColumns(alignment);
1516 setSelectionGroup(null);
1517 isColSelChanged(true);
1520 public void hideColumns(int start, int end)
1524 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1528 alignment.getHiddenColumns().hideColumns(start, end);
1530 isColSelChanged(true);
1533 public void showColumn(int col)
1535 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1536 isColSelChanged(true);
1539 public void showAllHiddenColumns()
1541 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1542 isColSelChanged(true);
1545 // common hide/show seq stuff
1546 public void showAllHiddenSeqs()
1548 int startSeq = ranges.getStartSeq();
1549 int endSeq = ranges.getEndSeq();
1551 if (alignment.getHiddenSequences().getSize() > 0)
1553 if (selectionGroup == null)
1555 selectionGroup = new SequenceGroup();
1556 selectionGroup.setEndRes(alignment.getWidth() - 1);
1558 List<SequenceI> tmp = alignment.getHiddenSequences()
1559 .showAll(hiddenRepSequences);
1560 for (SequenceI seq : tmp)
1562 selectionGroup.addSequence(seq, false);
1563 setSequenceAnnotationsVisible(seq, true);
1566 hiddenRepSequences = null;
1568 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1570 firePropertyChange("alignment", null, alignment.getSequences());
1571 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1577 public void showSequence(int index)
1579 int startSeq = ranges.getStartSeq();
1580 int endSeq = ranges.getEndSeq();
1582 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1583 hiddenRepSequences);
1586 if (selectionGroup == null)
1588 selectionGroup = new SequenceGroup();
1589 selectionGroup.setEndRes(alignment.getWidth() - 1);
1592 for (SequenceI seq : tmp)
1594 selectionGroup.addSequence(seq, false);
1595 setSequenceAnnotationsVisible(seq, true);
1598 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1600 firePropertyChange("alignment", null, alignment.getSequences());
1605 public void hideAllSelectedSeqs()
1607 if (selectionGroup == null || selectionGroup.getSize() < 1)
1612 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1616 setSelectionGroup(null);
1619 public void hideSequence(SequenceI[] seq)
1622 * cache offset to first visible sequence
1624 int startSeq = ranges.getStartSeq();
1628 for (int i = 0; i < seq.length; i++)
1630 alignment.getHiddenSequences().hideSequence(seq[i]);
1631 setSequenceAnnotationsVisible(seq[i], false);
1633 ranges.setStartSeq(startSeq);
1634 firePropertyChange("alignment", null, alignment.getSequences());
1639 * Hides the specified sequence, or the sequences it represents
1642 * the sequence to hide, or keep as representative
1643 * @param representGroup
1644 * if true, hide the current selection group except for the
1645 * representative sequence
1647 public void hideSequences(SequenceI sequence, boolean representGroup)
1649 if (selectionGroup == null || selectionGroup.getSize() < 1)
1651 hideSequence(new SequenceI[] { sequence });
1657 hideRepSequences(sequence, selectionGroup);
1658 setSelectionGroup(null);
1662 int gsize = selectionGroup.getSize();
1663 SequenceI[] hseqs = selectionGroup.getSequences()
1664 .toArray(new SequenceI[gsize]);
1666 hideSequence(hseqs);
1667 setSelectionGroup(null);
1672 * Set visibility for any annotations for the given sequence.
1676 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1679 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1682 for (AlignmentAnnotation ann : anns)
1684 if (ann.sequenceRef == sequenceI)
1686 ann.visible = visible;
1692 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1694 int sSize = sg.getSize();
1700 if (hiddenRepSequences == null)
1702 hiddenRepSequences = new Hashtable<>();
1705 hiddenRepSequences.put(repSequence, sg);
1707 // Hide all sequences except the repSequence
1708 SequenceI[] seqs = new SequenceI[sSize - 1];
1710 for (int i = 0; i < sSize; i++)
1712 if (sg.getSequenceAt(i) != repSequence)
1714 if (index == sSize - 1)
1719 seqs[index++] = sg.getSequenceAt(i);
1722 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1723 sg.setHidereps(true); // note: not done in 2.7applet
1730 * @return null or the current reference sequence
1732 public SequenceI getReferenceSeq()
1734 return alignment.getSeqrep();
1739 * @return true iff seq is the reference for the alignment
1741 public boolean isReferenceSeq(SequenceI seq)
1743 return alignment.getSeqrep() == seq;
1749 * @return true if there are sequences represented by this sequence that are
1752 public boolean isHiddenRepSequence(SequenceI seq)
1754 return (hiddenRepSequences != null
1755 && hiddenRepSequences.containsKey(seq));
1761 * @return null or a sequence group containing the sequences that seq
1764 public SequenceGroup getRepresentedSequences(SequenceI seq)
1766 return (SequenceGroup) (hiddenRepSequences == null ? null
1767 : hiddenRepSequences.get(seq));
1771 public int adjustForHiddenSeqs(int alignmentIndex)
1773 return alignment.getHiddenSequences()
1774 .adjustForHiddenSeqs(alignmentIndex);
1778 public void invertColumnSelection()
1780 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1784 public SequenceI[] getSelectionAsNewSequence()
1786 SequenceI[] sequences;
1787 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1788 // this was the only caller in the applet for this method
1789 // JBPNote: in applet, this method returned references to the alignment
1790 // sequences, and it did not honour the presence/absence of annotation
1791 // attached to the alignment (probably!)
1792 if (selectionGroup == null || selectionGroup.getSize() == 0)
1794 sequences = alignment.getSequencesArray();
1795 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1796 for (int i = 0; i < sequences.length; i++)
1798 // construct new sequence with subset of visible annotation
1799 sequences[i] = new Sequence(sequences[i], annots);
1804 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1811 public SequenceI[] getSequenceSelection()
1813 SequenceI[] sequences = null;
1814 if (selectionGroup != null)
1816 sequences = selectionGroup.getSequencesInOrder(alignment);
1818 if (sequences == null)
1820 sequences = alignment.getSequencesArray();
1826 public jalview.datamodel.AlignmentView getAlignmentView(
1827 boolean selectedOnly)
1829 return getAlignmentView(selectedOnly, false);
1833 public jalview.datamodel.AlignmentView getAlignmentView(
1834 boolean selectedOnly, boolean markGroups)
1836 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1838 alignment.getHiddenColumns() != null
1839 && alignment.getHiddenColumns().hasHiddenColumns(),
1840 selectedOnly, markGroups);
1844 public String[] getViewAsString(boolean selectedRegionOnly)
1846 return getViewAsString(selectedRegionOnly, true);
1850 public String[] getViewAsString(boolean selectedRegionOnly,
1851 boolean exportHiddenSeqs)
1853 String[] selection = null;
1854 SequenceI[] seqs = null;
1856 int start = 0, end = 0;
1857 if (selectedRegionOnly && selectionGroup != null)
1859 iSize = selectionGroup.getSize();
1860 seqs = selectionGroup.getSequencesInOrder(alignment);
1861 start = selectionGroup.getStartRes();
1862 end = selectionGroup.getEndRes() + 1;
1866 if (hasHiddenRows() && exportHiddenSeqs)
1868 AlignmentI fullAlignment = alignment.getHiddenSequences()
1869 .getFullAlignment();
1870 iSize = fullAlignment.getHeight();
1871 seqs = fullAlignment.getSequencesArray();
1872 end = fullAlignment.getWidth();
1876 iSize = alignment.getHeight();
1877 seqs = alignment.getSequencesArray();
1878 end = alignment.getWidth();
1882 selection = new String[iSize];
1883 if (alignment.getHiddenColumns() != null
1884 && alignment.getHiddenColumns().hasHiddenColumns())
1886 selection = alignment.getHiddenColumns()
1887 .getVisibleSequenceStrings(start, end, seqs);
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.adjustForHiddenColumns(start);
1917 end = hidden.getHiddenBoundaryRight(start);
1928 regions.add(new int[] { start, end });
1930 if (hidden != null && hidden.hasHiddenColumns())
1932 start = hidden.adjustForHiddenColumns(end);
1933 start = hidden.getHiddenBoundaryLeft(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 alignment.getHiddenColumns().makeVisibleAnnotation(
1956 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1961 alignment.getHiddenColumns().makeVisibleAnnotation(clone);
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 (autoCalculateConsensus)
1996 updateConsensus(ap);
1998 if (hconsensus != null && autoCalculateConsensus)
2000 updateConservation(ap);
2002 if (autoCalculateStrucConsensus)
2004 updateStrucConsensus(ap);
2007 updateInformation(ap);
2009 List<SequenceI> hmmSequences;
2010 hmmSequences = alignment.getHMMConsensusSequences();
2012 for (SequenceI seq : hmmSequences)
2014 seq.updateHMMMapping();
2017 // Reset endRes of groups if beyond alignment width
2018 int alWidth = alignment.getWidth();
2019 List<SequenceGroup> groups = alignment.getGroups();
2022 for (SequenceGroup sg : groups)
2024 if (sg.getEndRes() > alWidth)
2026 sg.setEndRes(alWidth - 1);
2031 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
2033 selectionGroup.setEndRes(alWidth - 1);
2036 updateAllColourSchemes();
2037 calculator.restartWorkers();
2038 // alignment.adjustSequenceAnnotations();
2042 * reset scope and do calculations for all applied colourschemes on alignment
2044 void updateAllColourSchemes()
2046 ResidueShaderI rs = residueShading;
2049 rs.alignmentChanged(alignment, hiddenRepSequences);
2051 rs.setConsensus(hconsensus);
2052 if (rs.conservationApplied())
2054 rs.setConservation(Conservation.calculateConservation("All",
2055 alignment.getSequences(), 0, alignment.getWidth(), false,
2056 getConsPercGaps(), false));
2060 for (SequenceGroup sg : alignment.getGroups())
2064 sg.cs.alignmentChanged(sg, hiddenRepSequences);
2066 sg.recalcConservation();
2070 protected void initAutoAnnotation()
2072 // TODO: add menu option action that nulls or creates consensus object
2073 // depending on if the user wants to see the annotation or not in a
2074 // specific alignment
2076 if (hconsensus == null && !isDataset)
2078 if (!alignment.isNucleotide())
2087 consensus = new AlignmentAnnotation("Consensus",
2088 MessageManager.getString("label.consensus_descr"),
2089 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2090 initConsensus(consensus);
2094 initComplementConsensus();
2099 * If this is a protein alignment and there are mappings to cDNA, adds the
2100 * cDNA consensus annotation and returns true, else returns false.
2102 public boolean initComplementConsensus()
2104 if (!alignment.isNucleotide())
2106 final List<AlignedCodonFrame> codonMappings = alignment
2108 if (codonMappings != null && !codonMappings.isEmpty())
2110 boolean doConsensus = false;
2111 for (AlignedCodonFrame mapping : codonMappings)
2113 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2114 MapList[] mapLists = mapping.getdnaToProt();
2115 // mapLists can be empty if project load has not finished resolving
2117 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2125 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2127 .getString("label.complement_consensus_descr"),
2128 new Annotation[1], 0f, 100f,
2129 AlignmentAnnotation.BAR_GRAPH);
2130 initConsensus(complementConsensus);
2138 private void initConsensus(AlignmentAnnotation aa)
2141 aa.autoCalculated = true;
2145 alignment.addAnnotation(aa);
2150 public void initInformation()
2152 for (SequenceI seq : alignment.getHMMConsensusSequences())
2154 if (!seq.hasHMMAnnotation())
2156 AlignmentAnnotation info = new AlignmentAnnotation(seq.getName(),
2157 MessageManager.getString("label.information_description"),
2158 new Annotation[1], 0f, 6.52f,
2159 AlignmentAnnotation.BAR_GRAPH);
2160 info.hasText = true;
2161 info.autoCalculated = false;
2162 info.sequenceRef = seq;
2163 info.setCalcId(InformationThread.HMM_CALC_ID);
2164 this.information.add(info);
2165 hinformation.add(new Profiles(new ProfileI[1]));
2166 alignment.addAnnotation(info);
2167 seq.updateHMMMapping();
2168 seq.addAlignmentAnnotation(info);
2173 // these should be extracted from the view model - style and settings for
2174 // derived annotation
2175 private void initOccupancy()
2179 occupancy = new AlignmentAnnotation("Occupancy",
2180 MessageManager.getString("label.occupancy_descr"),
2181 new Annotation[1], 0f, alignment.getHeight(),
2182 AlignmentAnnotation.BAR_GRAPH);
2183 occupancy.hasText = true;
2184 occupancy.autoCalculated = true;
2185 occupancy.scaleColLabel = true;
2186 occupancy.graph = AlignmentAnnotation.BAR_GRAPH;
2188 alignment.addAnnotation(occupancy);
2192 private void initConservation()
2194 if (showConservation)
2196 if (conservation == null)
2198 conservation = new AlignmentAnnotation("Conservation",
2199 MessageManager.formatMessage("label.conservation_descr",
2201 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2202 conservation.hasText = true;
2203 conservation.autoCalculated = true;
2204 alignment.addAnnotation(conservation);
2209 private void initQuality()
2213 if (quality == null)
2215 quality = new AlignmentAnnotation("Quality",
2216 MessageManager.getString("label.quality_descr"),
2217 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2218 quality.hasText = true;
2219 quality.autoCalculated = true;
2220 alignment.addAnnotation(quality);
2225 private void initRNAStructure()
2227 if (alignment.hasRNAStructure() && strucConsensus == null)
2229 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2230 MessageManager.getString("label.strucconsensus_descr"),
2231 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2232 strucConsensus.hasText = true;
2233 strucConsensus.autoCalculated = true;
2237 alignment.addAnnotation(strucConsensus);
2245 * @see jalview.api.AlignViewportI#calcPanelHeight()
2248 public int calcPanelHeight()
2250 // setHeight of panels
2251 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2253 int charHeight = getCharHeight();
2256 BitSet graphgrp = new BitSet();
2257 for (AlignmentAnnotation aa : anns)
2261 System.err.println("Null annotation row: ignoring.");
2268 if (aa.graphGroup > -1)
2270 if (graphgrp.get(aa.graphGroup))
2276 graphgrp.set(aa.graphGroup);
2283 aa.height += charHeight;
2293 aa.height += aa.graphHeight;
2301 height += aa.height;
2313 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2314 boolean preserveNewGroupSettings)
2316 boolean updateCalcs = false;
2317 boolean conv = isShowGroupConservation();
2318 boolean cons = isShowGroupConsensus();
2319 boolean showprf = isShowSequenceLogo();
2320 boolean showConsHist = isShowConsensusHistogram();
2321 boolean normLogo = isNormaliseSequenceLogo();
2322 boolean showHMMPrf = isShowHMMSequenceLogo();
2323 boolean showInfoHist = isShowInformationHistogram();
2324 boolean normHMMLogo = isNormaliseHMMSequenceLogo();
2327 * TODO reorder the annotation rows according to group/sequence ordering on
2330 boolean sortg = true;
2332 // remove old automatic annotation
2333 // add any new annotation
2335 // intersect alignment annotation with alignment groups
2337 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2338 List<SequenceGroup> oldrfs = new ArrayList<>();
2341 for (int an = 0; an < aan.length; an++)
2343 if (aan[an].autoCalculated && aan[an].groupRef != null)
2345 oldrfs.add(aan[an].groupRef);
2346 alignment.deleteAnnotation(aan[an], false);
2350 if (alignment.getGroups() != null)
2352 for (SequenceGroup sg : alignment.getGroups())
2354 updateCalcs = false;
2355 if (applyGlobalSettings
2356 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2358 // set defaults for this group's conservation/consensus
2359 sg.setshowSequenceLogo(showprf);
2360 sg.setShowConsensusHistogram(showConsHist);
2361 sg.setNormaliseSequenceLogo(normLogo);
2362 sg.setshowHMMSequenceLogo(showHMMPrf);
2363 sg.setShowInformationHistogram(showInfoHist);
2364 sg.setNormaliseHMMSequenceLogo(normHMMLogo);
2369 alignment.addAnnotation(sg.getConservationRow(), 0);
2374 alignment.addAnnotation(sg.getConsensus(), 0);
2376 // refresh the annotation rows
2379 sg.recalcConservation();
2387 public boolean isDisplayReferenceSeq()
2389 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2393 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2395 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2399 public boolean isColourByReferenceSeq()
2401 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2405 public Color getSequenceColour(SequenceI seq)
2407 Color sqc = sequenceColours.get(seq);
2408 return (sqc == null ? Color.white : sqc);
2412 public void setSequenceColour(SequenceI seq, Color col)
2416 sequenceColours.remove(seq);
2420 sequenceColours.put(seq, col);
2425 public void updateSequenceIdColours()
2427 for (SequenceGroup sg : alignment.getGroups())
2429 if (sg.idColour != null)
2431 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2433 sequenceColours.put(s, sg.idColour);
2440 public void clearSequenceColours()
2442 sequenceColours.clear();
2446 public AlignViewportI getCodingComplement()
2448 return this.codingComplement;
2452 * Set this as the (cDna/protein) complement of the given viewport. Also
2453 * ensures the reverse relationship is set on the given viewport.
2456 public void setCodingComplement(AlignViewportI av)
2460 System.err.println("Ignoring recursive setCodingComplement request");
2464 this.codingComplement = av;
2465 // avoid infinite recursion!
2466 if (av.getCodingComplement() != this)
2468 av.setCodingComplement(this);
2474 public boolean isNucleotide()
2476 return getAlignment() == null ? false : getAlignment().isNucleotide();
2480 public FeaturesDisplayedI getFeaturesDisplayed()
2482 return featuresDisplayed;
2486 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2488 featuresDisplayed = featuresDisplayedI;
2492 public boolean areFeaturesDisplayed()
2494 return featuresDisplayed != null
2495 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2502 * features are displayed if true
2505 public void setShowSequenceFeatures(boolean b)
2507 viewStyle.setShowSequenceFeatures(b);
2511 public boolean isShowSequenceFeatures()
2513 return viewStyle.isShowSequenceFeatures();
2517 public void setShowSequenceFeaturesHeight(boolean selected)
2519 viewStyle.setShowSequenceFeaturesHeight(selected);
2523 public boolean isShowSequenceFeaturesHeight()
2525 return viewStyle.isShowSequenceFeaturesHeight();
2529 public void setShowAnnotation(boolean b)
2531 viewStyle.setShowAnnotation(b);
2535 public boolean isShowAnnotation()
2537 return viewStyle.isShowAnnotation();
2541 public boolean isRightAlignIds()
2543 return viewStyle.isRightAlignIds();
2547 public void setRightAlignIds(boolean rightAlignIds)
2549 viewStyle.setRightAlignIds(rightAlignIds);
2553 public boolean getConservationSelected()
2555 return viewStyle.getConservationSelected();
2559 public void setShowBoxes(boolean state)
2561 viewStyle.setShowBoxes(state);
2566 * @see jalview.api.ViewStyleI#getTextColour()
2569 public Color getTextColour()
2571 return viewStyle.getTextColour();
2576 * @see jalview.api.ViewStyleI#getTextColour2()
2579 public Color getTextColour2()
2581 return viewStyle.getTextColour2();
2586 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2589 public int getThresholdTextColour()
2591 return viewStyle.getThresholdTextColour();
2596 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2599 public boolean isConservationColourSelected()
2601 return viewStyle.isConservationColourSelected();
2606 * @see jalview.api.ViewStyleI#isRenderGaps()
2609 public boolean isRenderGaps()
2611 return viewStyle.isRenderGaps();
2616 * @see jalview.api.ViewStyleI#isShowColourText()
2619 public boolean isShowColourText()
2621 return viewStyle.isShowColourText();
2625 * @param conservationColourSelected
2626 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2629 public void setConservationColourSelected(
2630 boolean conservationColourSelected)
2632 viewStyle.setConservationColourSelected(conservationColourSelected);
2636 * @param showColourText
2637 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2640 public void setShowColourText(boolean showColourText)
2642 viewStyle.setShowColourText(showColourText);
2647 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2650 public void setTextColour(Color textColour)
2652 viewStyle.setTextColour(textColour);
2656 * @param thresholdTextColour
2657 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2660 public void setThresholdTextColour(int thresholdTextColour)
2662 viewStyle.setThresholdTextColour(thresholdTextColour);
2666 * @param textColour2
2667 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2670 public void setTextColour2(Color textColour2)
2672 viewStyle.setTextColour2(textColour2);
2676 public ViewStyleI getViewStyle()
2678 return new ViewStyle(viewStyle);
2682 public void setViewStyle(ViewStyleI settingsForView)
2684 viewStyle = new ViewStyle(settingsForView);
2685 if (residueShading != null)
2687 residueShading.setConservationApplied(
2688 settingsForView.isConservationColourSelected());
2693 public boolean sameStyle(ViewStyleI them)
2695 return viewStyle.sameStyle(them);
2700 * @see jalview.api.ViewStyleI#getIdWidth()
2703 public int getIdWidth()
2705 return viewStyle.getIdWidth();
2710 * @see jalview.api.ViewStyleI#setIdWidth(int)
2713 public void setIdWidth(int i)
2715 viewStyle.setIdWidth(i);
2720 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2723 public boolean isCentreColumnLabels()
2725 return viewStyle.isCentreColumnLabels();
2729 * @param centreColumnLabels
2730 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2733 public void setCentreColumnLabels(boolean centreColumnLabels)
2735 viewStyle.setCentreColumnLabels(centreColumnLabels);
2740 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2743 public void setShowDBRefs(boolean showdbrefs)
2745 viewStyle.setShowDBRefs(showdbrefs);
2750 * @see jalview.api.ViewStyleI#isShowDBRefs()
2753 public boolean isShowDBRefs()
2755 return viewStyle.isShowDBRefs();
2760 * @see jalview.api.ViewStyleI#isShowNPFeats()
2763 public boolean isShowNPFeats()
2765 return viewStyle.isShowNPFeats();
2769 * @param shownpfeats
2770 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2773 public void setShowNPFeats(boolean shownpfeats)
2775 viewStyle.setShowNPFeats(shownpfeats);
2778 public abstract StructureSelectionManager getStructureSelectionManager();
2781 * Add one command to the command history list.
2785 public void addToHistoryList(CommandI command)
2787 if (this.historyList != null)
2789 this.historyList.push(command);
2790 broadcastCommand(command, false);
2794 protected void broadcastCommand(CommandI command, boolean undo)
2796 getStructureSelectionManager().commandPerformed(command, undo,
2801 * Add one command to the command redo list.
2805 public void addToRedoList(CommandI command)
2807 if (this.redoList != null)
2809 this.redoList.push(command);
2811 broadcastCommand(command, true);
2815 * Clear the command redo list.
2817 public void clearRedoList()
2819 if (this.redoList != null)
2821 this.redoList.clear();
2825 public void setHistoryList(Deque<CommandI> list)
2827 this.historyList = list;
2830 public Deque<CommandI> getHistoryList()
2832 return this.historyList;
2835 public void setRedoList(Deque<CommandI> list)
2837 this.redoList = list;
2840 public Deque<CommandI> getRedoList()
2842 return this.redoList;
2846 public VamsasSource getVamsasSource()
2851 public SequenceAnnotationOrder getSortAnnotationsBy()
2853 return sortAnnotationsBy;
2856 public void setSortAnnotationsBy(
2857 SequenceAnnotationOrder sortAnnotationsBy)
2859 this.sortAnnotationsBy = sortAnnotationsBy;
2862 public boolean isShowAutocalculatedAbove()
2864 return showAutocalculatedAbove;
2867 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2869 this.showAutocalculatedAbove = showAutocalculatedAbove;
2873 public boolean isScaleProteinAsCdna()
2875 return viewStyle.isScaleProteinAsCdna();
2879 public void setScaleProteinAsCdna(boolean b)
2881 viewStyle.setScaleProteinAsCdna(b);
2885 public boolean isProteinFontAsCdna()
2887 return viewStyle.isProteinFontAsCdna();
2891 public void setProteinFontAsCdna(boolean b)
2893 viewStyle.setProteinFontAsCdna(b);
2897 * @return true if view should scroll to show the highlighted region of a
2902 public final boolean isFollowHighlight()
2904 return followHighlight;
2908 public final void setFollowHighlight(boolean b)
2910 this.followHighlight = b;
2914 public ViewportRanges getRanges()
2920 * Helper method to populate the SearchResults with the location in the
2921 * complementary alignment to scroll to, in order to match this one.
2924 * the SearchResults to add to
2925 * @return the offset (below top of visible region) of the matched sequence
2927 protected int findComplementScrollTarget(SearchResultsI sr)
2929 final AlignViewportI complement = getCodingComplement();
2930 if (complement == null || !complement.isFollowHighlight())
2934 boolean iAmProtein = !getAlignment().isNucleotide();
2935 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2936 : complement.getAlignment();
2937 if (proteinAlignment == null)
2941 final List<AlignedCodonFrame> mappings = proteinAlignment
2945 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2946 * residue in the middle column of the visible region. Scroll the
2947 * complementary alignment to line up the corresponding residue.
2950 SequenceI sequence = null;
2953 * locate 'middle' column (true middle if an odd number visible, left of
2954 * middle if an even number visible)
2956 int middleColumn = ranges.getStartRes()
2957 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2958 final HiddenSequences hiddenSequences = getAlignment()
2959 .getHiddenSequences();
2962 * searching to the bottom of the alignment gives smoother scrolling across
2963 * all gapped visible regions
2965 int lastSeq = alignment.getHeight() - 1;
2966 List<AlignedCodonFrame> seqMappings = null;
2967 for (int seqNo = ranges
2968 .getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2970 sequence = getAlignment().getSequenceAt(seqNo);
2971 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2975 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2979 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2981 getCodingComplement().getAlignment().getSequences());
2982 if (!seqMappings.isEmpty())
2988 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2991 * No ungapped mapped sequence in middle column - do nothing
2995 MappingUtils.addSearchResults(sr, sequence,
2996 sequence.findPosition(middleColumn), seqMappings);
3001 * synthesize a column selection if none exists so it covers the given
3002 * selection group. if wholewidth is false, no column selection is made if the
3003 * selection group covers the whole alignment width.
3008 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
3011 if (sg != null && (sgs = sg.getStartRes()) >= 0
3012 && sg.getStartRes() <= (sge = sg.getEndRes())
3013 && !this.hasSelectedColumns())
3015 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
3022 colSel = new ColumnSelection();
3024 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
3026 colSel.addElement(cspos);
3032 * hold status of current selection group - defined on alignment or not.
3034 private boolean selectionIsDefinedGroup = false;
3037 public boolean isSelectionDefinedGroup()
3039 if (selectionGroup == null)
3043 if (isSelectionGroupChanged(true))
3045 selectionIsDefinedGroup = false;
3046 List<SequenceGroup> gps = alignment.getGroups();
3047 if (gps == null || gps.size() == 0)
3049 selectionIsDefinedGroup = false;
3053 selectionIsDefinedGroup = gps.contains(selectionGroup);
3056 return selectionGroup.isDefined() || selectionIsDefinedGroup;
3060 * null, or currently highlighted results on this view
3062 private SearchResultsI searchResults = null;
3064 protected TreeModel currentTree = null;
3067 public boolean hasSearchResults()
3069 return searchResults != null;
3073 public void setSearchResults(SearchResultsI results)
3075 searchResults = results;
3079 public SearchResultsI getSearchResults()
3081 return searchResults;
3085 * get the consensus sequence as displayed under the PID consensus annotation
3088 * @return consensus sequence as a new sequence object
3090 public SequenceI getConsensusSeq()
3092 if (consensus == null)
3094 updateConsensus(null);
3096 if (consensus == null)
3100 StringBuffer seqs = new StringBuffer();
3101 for (int i = 0; i < consensus.annotations.length; i++)
3103 Annotation annotation = consensus.annotations[i];
3104 if (annotation != null)
3106 String description = annotation.description;
3107 if (description != null && description.startsWith("["))
3109 // consensus is a tie - just pick the first one
3110 seqs.append(description.charAt(1));
3114 seqs.append(annotation.displayCharacter);
3119 SequenceI sq = new Sequence("Consensus", seqs.toString());
3120 sq.setDescription("Percentage Identity Consensus "
3121 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3125 public boolean hasReferenceAnnotation()
3127 AlignmentAnnotation[] annots = this.alignment.getAlignmentAnnotation();
3128 for (AlignmentAnnotation annot : annots)
3130 if ("RF".equals(annot.label) || annot.label.contains("Reference"))
3139 public void setCurrentTree(TreeModel tree)
3145 public TreeModel getCurrentTree()