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.api.AlignCalcManagerI;
26 import jalview.api.AlignViewportI;
27 import jalview.api.AlignmentViewPanel;
28 import jalview.api.FeaturesDisplayedI;
29 import jalview.api.ViewStyleI;
30 import jalview.commands.CommandI;
31 import jalview.datamodel.AlignedCodonFrame;
32 import jalview.datamodel.AlignmentAnnotation;
33 import jalview.datamodel.AlignmentI;
34 import jalview.datamodel.AlignmentView;
35 import jalview.datamodel.Annotation;
36 import jalview.datamodel.CigarArray;
37 import jalview.datamodel.ColumnSelection;
38 import jalview.datamodel.HiddenColumns;
39 import jalview.datamodel.HiddenSequences;
40 import jalview.datamodel.ProfilesI;
41 import jalview.datamodel.SearchResultsI;
42 import jalview.datamodel.Sequence;
43 import jalview.datamodel.SequenceCollectionI;
44 import jalview.datamodel.SequenceGroup;
45 import jalview.datamodel.SequenceI;
46 import jalview.renderer.ResidueShader;
47 import jalview.renderer.ResidueShaderI;
48 import jalview.schemes.ColourSchemeI;
49 import jalview.structure.CommandListener;
50 import jalview.structure.StructureSelectionManager;
51 import jalview.structure.VamsasSource;
52 import jalview.util.Comparison;
53 import jalview.util.MapList;
54 import jalview.util.MappingUtils;
55 import jalview.util.MessageManager;
56 import jalview.viewmodel.styles.ViewStyle;
57 import jalview.workers.AlignCalcManager;
58 import jalview.workers.ComplementConsensusThread;
59 import jalview.workers.ConsensusThread;
60 import jalview.workers.InformationThread;
61 import jalview.workers.StrucConsensusThread;
63 import java.awt.Color;
64 import java.beans.PropertyChangeSupport;
65 import java.util.ArrayDeque;
66 import java.util.ArrayList;
67 import java.util.BitSet;
68 import java.util.Deque;
69 import java.util.HashMap;
70 import java.util.Hashtable;
71 import java.util.List;
75 * base class holding visualization and analysis attributes and common logic for
76 * an active alignment view displayed in the GUI
81 public abstract class AlignmentViewport implements AlignViewportI,
82 CommandListener, VamsasSource
84 final protected ViewportRanges ranges;
86 protected ViewStyleI viewStyle = new ViewStyle();
89 * A viewport that hosts the cDna view of this (protein), or vice versa (if
92 AlignViewportI codingComplement = null;
94 FeaturesDisplayedI featuresDisplayed = null;
96 protected Deque<CommandI> historyList = new ArrayDeque<>();
98 protected Deque<CommandI> redoList = new ArrayDeque<>();
102 * alignment displayed in the viewport. Please use get/setter
104 protected AlignmentI alignment;
106 public AlignmentViewport(AlignmentI al)
109 ranges = new ViewportRanges(al);
114 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
117 public void setFontName(String name)
119 viewStyle.setFontName(name);
124 * @see jalview.api.ViewStyleI#setFontStyle(int)
127 public void setFontStyle(int style)
129 viewStyle.setFontStyle(style);
134 * @see jalview.api.ViewStyleI#setFontSize(int)
137 public void setFontSize(int size)
139 viewStyle.setFontSize(size);
144 * @see jalview.api.ViewStyleI#getFontStyle()
147 public int getFontStyle()
149 return viewStyle.getFontStyle();
154 * @see jalview.api.ViewStyleI#getFontName()
157 public String getFontName()
159 return viewStyle.getFontName();
164 * @see jalview.api.ViewStyleI#getFontSize()
167 public int getFontSize()
169 return viewStyle.getFontSize();
173 * @param upperCasebold
174 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
177 public void setUpperCasebold(boolean upperCasebold)
179 viewStyle.setUpperCasebold(upperCasebold);
184 * @see jalview.api.ViewStyleI#isUpperCasebold()
187 public boolean isUpperCasebold()
189 return viewStyle.isUpperCasebold();
194 * @see jalview.api.ViewStyleI#isSeqNameItalics()
197 public boolean isSeqNameItalics()
199 return viewStyle.isSeqNameItalics();
203 * @param colourByReferenceSeq
204 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
207 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
209 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
214 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
217 public void setColourAppliesToAllGroups(boolean b)
219 viewStyle.setColourAppliesToAllGroups(b);
224 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
227 public boolean getColourAppliesToAllGroups()
229 return viewStyle.getColourAppliesToAllGroups();
234 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
237 public boolean getAbovePIDThreshold()
239 return viewStyle.getAbovePIDThreshold();
244 * @see jalview.api.ViewStyleI#setIncrement(int)
247 public void setIncrement(int inc)
249 viewStyle.setIncrement(inc);
254 * @see jalview.api.ViewStyleI#getIncrement()
257 public int getIncrement()
259 return viewStyle.getIncrement();
264 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
267 public void setConservationSelected(boolean b)
269 viewStyle.setConservationSelected(b);
274 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
277 public void setShowHiddenMarkers(boolean show)
279 viewStyle.setShowHiddenMarkers(show);
284 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
287 public boolean getShowHiddenMarkers()
289 return viewStyle.getShowHiddenMarkers();
294 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
297 public void setScaleRightWrapped(boolean b)
299 viewStyle.setScaleRightWrapped(b);
304 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
307 public void setScaleLeftWrapped(boolean b)
309 viewStyle.setScaleLeftWrapped(b);
314 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
317 public void setScaleAboveWrapped(boolean b)
319 viewStyle.setScaleAboveWrapped(b);
324 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
327 public boolean getScaleLeftWrapped()
329 return viewStyle.getScaleLeftWrapped();
334 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
337 public boolean getScaleAboveWrapped()
339 return viewStyle.getScaleAboveWrapped();
344 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
347 public boolean getScaleRightWrapped()
349 return viewStyle.getScaleRightWrapped();
354 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
357 public void setAbovePIDThreshold(boolean b)
359 viewStyle.setAbovePIDThreshold(b);
364 * @see jalview.api.ViewStyleI#setThreshold(int)
367 public void setThreshold(int thresh)
369 viewStyle.setThreshold(thresh);
374 * @see jalview.api.ViewStyleI#getThreshold()
377 public int getThreshold()
379 return viewStyle.getThreshold();
384 * @see jalview.api.ViewStyleI#getShowJVSuffix()
387 public boolean getShowJVSuffix()
389 return viewStyle.getShowJVSuffix();
394 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
397 public void setShowJVSuffix(boolean b)
399 viewStyle.setShowJVSuffix(b);
404 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
407 public void setWrapAlignment(boolean state)
409 viewStyle.setWrapAlignment(state);
414 * @see jalview.api.ViewStyleI#setShowText(boolean)
417 public void setShowText(boolean state)
419 viewStyle.setShowText(state);
424 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
427 public void setRenderGaps(boolean state)
429 viewStyle.setRenderGaps(state);
434 * @see jalview.api.ViewStyleI#getColourText()
437 public boolean getColourText()
439 return viewStyle.getColourText();
444 * @see jalview.api.ViewStyleI#setColourText(boolean)
447 public void setColourText(boolean state)
449 viewStyle.setColourText(state);
454 * @see jalview.api.ViewStyleI#getWrapAlignment()
457 public boolean getWrapAlignment()
459 return viewStyle.getWrapAlignment();
464 * @see jalview.api.ViewStyleI#getShowText()
467 public boolean getShowText()
469 return viewStyle.getShowText();
474 * @see jalview.api.ViewStyleI#getWrappedWidth()
477 public int getWrappedWidth()
479 return viewStyle.getWrappedWidth();
484 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
487 public void setWrappedWidth(int w)
489 viewStyle.setWrappedWidth(w);
494 * @see jalview.api.ViewStyleI#getCharHeight()
497 public int getCharHeight()
499 return viewStyle.getCharHeight();
504 * @see jalview.api.ViewStyleI#setCharHeight(int)
507 public void setCharHeight(int h)
509 viewStyle.setCharHeight(h);
514 * @see jalview.api.ViewStyleI#getCharWidth()
517 public int getCharWidth()
519 return viewStyle.getCharWidth();
524 * @see jalview.api.ViewStyleI#setCharWidth(int)
527 public void setCharWidth(int w)
529 viewStyle.setCharWidth(w);
534 * @see jalview.api.ViewStyleI#getShowBoxes()
537 public boolean getShowBoxes()
539 return viewStyle.getShowBoxes();
544 * @see jalview.api.ViewStyleI#getShowUnconserved()
547 public boolean getShowUnconserved()
549 return viewStyle.getShowUnconserved();
553 * @param showunconserved
554 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
557 public void setShowUnconserved(boolean showunconserved)
559 viewStyle.setShowUnconserved(showunconserved);
564 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
567 public void setSeqNameItalics(boolean default1)
569 viewStyle.setSeqNameItalics(default1);
575 public AlignmentI getAlignment()
581 public char getGapCharacter()
583 return alignment.getGapCharacter();
586 protected String sequenceSetID;
589 * probably unused indicator that view is of a dataset rather than an
592 protected boolean isDataset = false;
594 public void setDataset(boolean b)
599 public boolean isDataset()
604 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
606 protected ColumnSelection colSel = new ColumnSelection();
608 public boolean autoCalculateConsensus = true;
610 public boolean autoCalculateInformation = true;
612 protected boolean autoCalculateStrucConsensus = true;
614 protected boolean ignoreGapsInConsensusCalculation = false;
616 protected boolean ignoreBelowBackGroundFrequencyCalculation = false;
618 protected ResidueShaderI residueShading = new ResidueShader();
621 public void setGlobalColourScheme(ColourSchemeI cs)
623 // TODO: logic refactored from AlignFrame changeColour -
624 // TODO: autorecalc stuff should be changed to rely on the worker system
625 // check to see if we should implement a changeColour(cs) method rather than
626 // put the logic in here
627 // - means that caller decides if they want to just modify state and defer
628 // calculation till later or to do all calculations in thread.
632 * only instantiate alignment colouring once, thereafter update it;
633 * this means that any conservation or PID threshold settings
634 * persist when the alignment colour scheme is changed
636 if (residueShading == null)
638 residueShading = new ResidueShader(viewStyle);
640 residueShading.setColourScheme(cs);
642 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
643 // ...problem: groups need these, but do not currently have a ViewStyle
647 if (getConservationSelected())
649 residueShading.setConservation(hconservation);
651 residueShading.alignmentChanged(alignment, hiddenRepSequences);
655 * if 'apply colour to all groups' is selected... do so
656 * (but don't transfer any colour threshold settings to groups)
658 if (getColourAppliesToAllGroups())
660 for (SequenceGroup sg : getAlignment().getGroups())
663 * retain any colour thresholds per group while
664 * changing choice of colour scheme (JAL-2386)
666 sg.setColourScheme(cs);
669 sg.getGroupColourScheme()
670 .alignmentChanged(sg, hiddenRepSequences);
677 public ColourSchemeI getGlobalColourScheme()
679 return residueShading == null ? null : residueShading
684 public ResidueShaderI getResidueShading()
686 return residueShading;
689 protected AlignmentAnnotation consensus;
691 protected AlignmentAnnotation complementConsensus;
693 protected AlignmentAnnotation gapcounts;
695 protected AlignmentAnnotation strucConsensus;
697 protected AlignmentAnnotation conservation;
699 protected AlignmentAnnotation quality;
701 protected AlignmentAnnotation[] groupConsensus;
703 protected AlignmentAnnotation[] groupConservation;
705 protected AlignmentAnnotation[] groupInformation;
707 protected AlignmentAnnotation information;
710 * results of alignment information analysis for visible portion of view
712 protected ProfilesI hinformation = null;
715 * results of alignment consensus analysis for visible portion of view
717 protected ProfilesI hconsensus = null;
720 * results of cDNA complement consensus visible portion of view
722 protected Hashtable[] hcomplementConsensus = null;
725 * results of secondary structure base pair consensus for visible portion of
728 protected Hashtable[] hStrucConsensus = null;
730 protected Conservation hconservation = null;
733 public void setConservation(Conservation cons)
735 hconservation = cons;
739 * percentage gaps allowed in a column before all amino acid properties should
740 * be considered unconserved
742 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
745 public int getConsPercGaps()
751 public void setSequenceConsensusHash(ProfilesI hconsensus)
753 this.hconsensus = hconsensus;
757 public void setComplementConsensusHash(Hashtable[] hconsensus)
759 this.hcomplementConsensus = hconsensus;
763 public ProfilesI getSequenceConsensusHash()
769 public ProfilesI setSequenceInformationHash()
775 public ProfilesI getSequenceInformationHash()
781 public Hashtable[] getComplementConsensusHash()
783 return hcomplementConsensus;
787 public Hashtable[] getRnaStructureConsensusHash()
789 return hStrucConsensus;
793 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
795 this.hStrucConsensus = hStrucConsensus;
800 public AlignmentAnnotation getAlignmentQualityAnnot()
806 public AlignmentAnnotation getAlignmentConservationAnnotation()
812 public AlignmentAnnotation getAlignmentConsensusAnnotation()
818 public AlignmentAnnotation getAlignmentInformationAnnotation()
824 public AlignmentAnnotation getAlignmentGapAnnotation()
830 public AlignmentAnnotation getComplementConsensusAnnotation()
832 return complementConsensus;
836 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
838 return strucConsensus;
841 protected AlignCalcManagerI calculator = new AlignCalcManager();
844 * trigger update of conservation annotation
846 public void updateConservation(final AlignmentViewPanel ap)
848 // see note in mantis : issue number 8585
849 if (alignment.isNucleotide()
850 || (conservation == null && quality == null)
851 || !autoCalculateConsensus)
856 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
858 calculator.registerWorker(new jalview.workers.ConservationThread(
864 * trigger update of consensus annotation
866 public void updateConsensus(final AlignmentViewPanel ap)
868 // see note in mantis : issue number 8585
869 if (consensus == null || !autoCalculateConsensus)
873 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
875 calculator.registerWorker(new ConsensusThread(this, ap));
879 * A separate thread to compute cDNA consensus for a protein alignment
880 * which has mapping to cDNA
882 final AlignmentI al = this.getAlignment();
883 if (!al.isNucleotide() && al.getCodonFrames() != null
884 && !al.getCodonFrames().isEmpty())
887 * fudge - check first for protein-to-nucleotide mappings
888 * (we don't want to do this for protein-to-protein)
890 boolean doConsensus = false;
891 for (AlignedCodonFrame mapping : al.getCodonFrames())
893 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
894 MapList[] mapLists = mapping.getdnaToProt();
895 // mapLists can be empty if project load has not finished resolving seqs
896 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
905 .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null)
908 .registerWorker(new ComplementConsensusThread(this, ap));
915 * trigger update of information annotation
917 public void updateInformation(final AlignmentViewPanel ap)
919 if (information == null)
924 .getRegisteredWorkersOfClass(InformationThread.class) == null)
926 calculator.registerWorker(new InformationThread(this, ap));
931 // --------START Structure Conservation
932 public void updateStrucConsensus(final AlignmentViewPanel ap)
934 if (autoCalculateStrucConsensus && strucConsensus == null
935 && alignment.isNucleotide() && alignment.hasRNAStructure())
937 // secondary structure has been added - so init the consensus line
941 // see note in mantis : issue number 8585
942 if (strucConsensus == null || !autoCalculateStrucConsensus)
946 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
948 calculator.registerWorker(new StrucConsensusThread(this, ap));
952 public boolean isCalcInProgress()
954 return calculator.isWorking();
958 public boolean isCalculationInProgress(
959 AlignmentAnnotation alignmentAnnotation)
961 if (!alignmentAnnotation.autoCalculated)
965 if (calculator.workingInvolvedWith(alignmentAnnotation))
967 // System.err.println("grey out ("+alignmentAnnotation.label+")");
973 public void setAlignment(AlignmentI align)
975 this.alignment = align;
979 * Clean up references when this viewport is closed
982 public void dispose()
985 * defensively null out references to large objects in case
986 * this object is not garbage collected (as if!)
990 complementConsensus = null;
991 strucConsensus = null;
994 groupConsensus = null;
995 groupConservation = null;
997 hcomplementConsensus = null;
998 // colour scheme may hold reference to consensus
999 residueShading = null;
1000 // TODO remove listeners from changeSupport?
1001 changeSupport = null;
1006 public boolean isClosed()
1008 // TODO: check that this isClosed is only true after panel is closed, not
1009 // before it is fully constructed.
1010 return alignment == null;
1014 public AlignCalcManagerI getCalcManager()
1020 * should conservation rows be shown for groups
1022 protected boolean showGroupConservation = false;
1025 * should consensus rows be shown for groups
1027 protected boolean showGroupConsensus = false;
1030 * should consensus profile be rendered by default
1032 protected boolean showSequenceLogo = false;
1035 * should consensus profile be rendered normalised to row height
1037 protected boolean normaliseSequenceLogo = false;
1040 * should consensus histograms be rendered by default
1042 protected boolean showConsensusHistogram = true;
1045 * should hmm profile be rendered by default
1047 protected boolean showHMMSequenceLogo = false;
1050 * should hmm profile be rendered normalised to row height
1052 protected boolean normaliseHMMSequenceLogo = false;
1055 * should information histograms be rendered by default
1057 protected boolean showInformationHistogram = true;
1060 * @return the showConsensusProfile
1063 public boolean isShowSequenceLogo()
1065 return showSequenceLogo;
1069 * @return the showInformationProfile
1072 public boolean isShowHMMSequenceLogo()
1074 return showHMMSequenceLogo;
1078 * @param showSequenceLogo
1081 public void setShowSequenceLogo(boolean showSequenceLogo)
1083 if (showSequenceLogo != this.showSequenceLogo)
1085 // TODO: decouple settings setting from calculation when refactoring
1086 // annotation update method from alignframe to viewport
1087 this.showSequenceLogo = showSequenceLogo;
1088 calculator.updateAnnotationFor(ConsensusThread.class);
1089 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1090 calculator.updateAnnotationFor(StrucConsensusThread.class);
1092 this.showSequenceLogo = showSequenceLogo;
1095 public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo)
1097 if (showHMMSequenceLogo != this.showHMMSequenceLogo)
1099 this.showHMMSequenceLogo = showHMMSequenceLogo;
1100 calculator.updateAnnotationFor(InformationThread.class);
1102 this.showHMMSequenceLogo = showHMMSequenceLogo;
1106 * @param showConsensusHistogram
1107 * the showConsensusHistogram to set
1109 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1111 this.showConsensusHistogram = showConsensusHistogram;
1115 * @param showInformationHistogram
1116 * the showInformationHistogram to set
1118 public void setShowInformationHistogram(boolean showInformationHistogram)
1120 this.showInformationHistogram = showInformationHistogram;
1124 * @return the showGroupConservation
1126 public boolean isShowGroupConservation()
1128 return showGroupConservation;
1132 * @param showGroupConservation
1133 * the showGroupConservation to set
1135 public void setShowGroupConservation(boolean showGroupConservation)
1137 this.showGroupConservation = showGroupConservation;
1141 * @return the showGroupConsensus
1143 public boolean isShowGroupConsensus()
1145 return showGroupConsensus;
1149 * @param showGroupConsensus
1150 * the showGroupConsensus to set
1152 public void setShowGroupConsensus(boolean showGroupConsensus)
1154 this.showGroupConsensus = showGroupConsensus;
1159 * @return flag to indicate if the consensus histogram should be rendered by
1163 public boolean isShowConsensusHistogram()
1165 return this.showConsensusHistogram;
1170 * @return flag to indicate if the information content histogram should be
1171 * rendered by default
1174 public boolean isShowInformationHistogram()
1176 return this.showInformationHistogram;
1180 * when set, updateAlignment will always ensure sequences are of equal length
1182 private boolean padGaps = false;
1185 * when set, alignment should be reordered according to a newly opened tree
1187 public boolean sortByTree = false;
1192 * @return null or the currently selected sequence region
1195 public SequenceGroup getSelectionGroup()
1197 return selectionGroup;
1201 * Set the selection group for this window. Also sets the current alignment as
1202 * the context for the group, if it does not already have one.
1205 * - group holding references to sequences in this alignment view
1209 public void setSelectionGroup(SequenceGroup sg)
1211 selectionGroup = sg;
1212 if (sg != null && sg.getContext() == null)
1214 sg.setContext(alignment);
1218 public void setHiddenColumns(HiddenColumns hidden)
1220 this.alignment.setHiddenColumns(hidden);
1224 public ColumnSelection getColumnSelection()
1230 public void setColumnSelection(ColumnSelection colSel)
1232 this.colSel = colSel;
1235 updateHiddenColumns();
1237 isColSelChanged(true);
1245 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1247 return hiddenRepSequences;
1251 public void setHiddenRepSequences(
1252 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1254 this.hiddenRepSequences = hiddenRepSequences;
1258 public boolean hasSelectedColumns()
1260 ColumnSelection columnSelection = getColumnSelection();
1261 return columnSelection != null && columnSelection.hasSelectedColumns();
1265 public boolean hasHiddenColumns()
1267 return colSel != null
1268 && alignment.getHiddenColumns().hasHiddenColumns();
1271 public void updateHiddenColumns()
1273 // this method doesn't really do anything now. But - it could, since a
1274 // column Selection could be in the process of modification
1275 // hasHiddenColumns = colSel.hasHiddenColumns();
1279 public boolean hasHiddenRows()
1281 return alignment.getHiddenSequences().getSize() > 0;
1284 protected SequenceGroup selectionGroup;
1286 public void setSequenceSetId(String newid)
1288 if (sequenceSetID != null)
1291 .println("Warning - overwriting a sequenceSetId for a viewport!");
1293 sequenceSetID = new String(newid);
1297 public String getSequenceSetId()
1299 if (sequenceSetID == null)
1301 sequenceSetID = alignment.hashCode() + "";
1304 return sequenceSetID;
1308 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1311 protected String viewId = null;
1314 public String getViewId()
1318 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1323 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1325 ignoreGapsInConsensusCalculation = b;
1328 updateConsensus(ap);
1329 if (residueShading != null)
1331 residueShading.setThreshold(residueShading.getThreshold(),
1332 ignoreGapsInConsensusCalculation);
1338 public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap)
1340 ignoreBelowBackGroundFrequencyCalculation = b;
1343 updateInformation(ap);
1348 private long sgrouphash = -1, colselhash = -1;
1351 * checks current SelectionGroup against record of last hash value, and
1355 * update the record of last hash value
1357 * @return true if SelectionGroup changed since last call (when b is true)
1359 public boolean isSelectionGroupChanged(boolean b)
1361 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1362 : selectionGroup.hashCode();
1363 if (hc != -1 && hc != sgrouphash)
1375 * checks current colsel against record of last hash value, and optionally
1379 * update the record of last hash value
1380 * @return true if colsel changed since last call (when b is true)
1382 public boolean isColSelChanged(boolean b)
1384 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1385 if (hc != -1 && hc != colselhash)
1397 public boolean isIgnoreGapsConsensus()
1399 return ignoreGapsInConsensusCalculation;
1403 public boolean isIgnoreBelowBackground()
1405 return ignoreBelowBackGroundFrequencyCalculation;
1408 // property change stuff
1409 // JBPNote Prolly only need this in the applet version.
1410 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1413 protected boolean showConservation = true;
1415 protected boolean showQuality = true;
1417 protected boolean showConsensus = true;
1419 protected boolean showOccupancy = true;
1421 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1423 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1425 protected boolean showAutocalculatedAbove;
1428 * when set, view will scroll to show the highlighted position
1430 private boolean followHighlight = true;
1433 * Property change listener for changes in alignment
1438 public void addPropertyChangeListener(
1439 java.beans.PropertyChangeListener listener)
1441 changeSupport.addPropertyChangeListener(listener);
1450 public void removePropertyChangeListener(
1451 java.beans.PropertyChangeListener listener)
1453 changeSupport.removePropertyChangeListener(listener);
1457 * Property change listener for changes in alignment
1466 public void firePropertyChange(String prop, Object oldvalue,
1469 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1472 // common hide/show column stuff
1474 public void hideSelectedColumns()
1476 if (colSel.isEmpty())
1481 colSel.hideSelectedColumns(alignment);
1482 setSelectionGroup(null);
1483 isColSelChanged(true);
1486 public void hideColumns(int start, int end)
1490 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1494 alignment.getHiddenColumns().hideColumns(start, end);
1496 isColSelChanged(true);
1499 public void showColumn(int col)
1501 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1502 isColSelChanged(true);
1505 public void showAllHiddenColumns()
1507 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1508 isColSelChanged(true);
1511 // common hide/show seq stuff
1512 public void showAllHiddenSeqs()
1514 if (alignment.getHiddenSequences().getSize() > 0)
1516 if (selectionGroup == null)
1518 selectionGroup = new SequenceGroup();
1519 selectionGroup.setEndRes(alignment.getWidth() - 1);
1521 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1522 hiddenRepSequences);
1523 for (SequenceI seq : tmp)
1525 selectionGroup.addSequence(seq, false);
1526 setSequenceAnnotationsVisible(seq, true);
1529 hiddenRepSequences = null;
1531 firePropertyChange("alignment", null, alignment.getSequences());
1532 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1538 public void showSequence(int index)
1540 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1541 index, hiddenRepSequences);
1544 if (selectionGroup == null)
1546 selectionGroup = new SequenceGroup();
1547 selectionGroup.setEndRes(alignment.getWidth() - 1);
1550 for (SequenceI seq : tmp)
1552 selectionGroup.addSequence(seq, false);
1553 setSequenceAnnotationsVisible(seq, true);
1555 firePropertyChange("alignment", null, alignment.getSequences());
1560 public void hideAllSelectedSeqs()
1562 if (selectionGroup == null || selectionGroup.getSize() < 1)
1567 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1571 setSelectionGroup(null);
1574 public void hideSequence(SequenceI[] seq)
1578 for (int i = 0; i < seq.length; i++)
1580 alignment.getHiddenSequences().hideSequence(seq[i]);
1581 setSequenceAnnotationsVisible(seq[i], false);
1583 firePropertyChange("alignment", null, alignment.getSequences());
1588 * Hides the specified sequence, or the sequences it represents
1591 * the sequence to hide, or keep as representative
1592 * @param representGroup
1593 * if true, hide the current selection group except for the
1594 * representative sequence
1596 public void hideSequences(SequenceI sequence, boolean representGroup)
1598 if (selectionGroup == null || selectionGroup.getSize() < 1)
1600 hideSequence(new SequenceI[] { sequence });
1606 hideRepSequences(sequence, selectionGroup);
1607 setSelectionGroup(null);
1611 int gsize = selectionGroup.getSize();
1612 SequenceI[] hseqs = selectionGroup.getSequences().toArray(
1613 new SequenceI[gsize]);
1615 hideSequence(hseqs);
1616 setSelectionGroup(null);
1621 * Set visibility for any annotations for the given sequence.
1625 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1628 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1631 for (AlignmentAnnotation ann : anns)
1633 if (ann.sequenceRef == sequenceI)
1635 ann.visible = visible;
1641 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1643 int sSize = sg.getSize();
1649 if (hiddenRepSequences == null)
1651 hiddenRepSequences = new Hashtable<>();
1654 hiddenRepSequences.put(repSequence, sg);
1656 // Hide all sequences except the repSequence
1657 SequenceI[] seqs = new SequenceI[sSize - 1];
1659 for (int i = 0; i < sSize; i++)
1661 if (sg.getSequenceAt(i) != repSequence)
1663 if (index == sSize - 1)
1668 seqs[index++] = sg.getSequenceAt(i);
1671 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1672 sg.setHidereps(true); // note: not done in 2.7applet
1679 * @return null or the current reference sequence
1681 public SequenceI getReferenceSeq()
1683 return alignment.getSeqrep();
1688 * @return true iff seq is the reference for the alignment
1690 public boolean isReferenceSeq(SequenceI seq)
1692 return alignment.getSeqrep() == seq;
1698 * @return true if there are sequences represented by this sequence that are
1701 public boolean isHiddenRepSequence(SequenceI seq)
1703 return (hiddenRepSequences != null && hiddenRepSequences
1710 * @return null or a sequence group containing the sequences that seq
1713 public SequenceGroup getRepresentedSequences(SequenceI seq)
1715 return (SequenceGroup) (hiddenRepSequences == null ? null
1716 : hiddenRepSequences.get(seq));
1720 public int adjustForHiddenSeqs(int alignmentIndex)
1722 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1727 public void invertColumnSelection()
1729 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1733 public SequenceI[] getSelectionAsNewSequence()
1735 SequenceI[] sequences;
1736 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1737 // this was the only caller in the applet for this method
1738 // JBPNote: in applet, this method returned references to the alignment
1739 // sequences, and it did not honour the presence/absence of annotation
1740 // attached to the alignment (probably!)
1741 if (selectionGroup == null || selectionGroup.getSize() == 0)
1743 sequences = alignment.getSequencesArray();
1744 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1745 for (int i = 0; i < sequences.length; i++)
1747 // construct new sequence with subset of visible annotation
1748 sequences[i] = new Sequence(sequences[i], annots);
1753 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1760 public SequenceI[] getSequenceSelection()
1762 SequenceI[] sequences = null;
1763 if (selectionGroup != null)
1765 sequences = selectionGroup.getSequencesInOrder(alignment);
1767 if (sequences == null)
1769 sequences = alignment.getSequencesArray();
1775 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1777 return new CigarArray(alignment, alignment.getHiddenColumns(),
1778 (selectedRegionOnly ? selectionGroup : null));
1782 public jalview.datamodel.AlignmentView getAlignmentView(
1783 boolean selectedOnly)
1785 return getAlignmentView(selectedOnly, false);
1789 public jalview.datamodel.AlignmentView getAlignmentView(
1790 boolean selectedOnly, boolean markGroups)
1792 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1793 selectionGroup, alignment.getHiddenColumns() != null
1794 && alignment.getHiddenColumns().hasHiddenColumns(),
1800 public String[] getViewAsString(boolean selectedRegionOnly)
1802 return getViewAsString(selectedRegionOnly, true);
1806 public String[] getViewAsString(boolean selectedRegionOnly,
1807 boolean exportHiddenSeqs)
1809 String[] selection = null;
1810 SequenceI[] seqs = null;
1812 int start = 0, end = 0;
1813 if (selectedRegionOnly && selectionGroup != null)
1815 iSize = selectionGroup.getSize();
1816 seqs = selectionGroup.getSequencesInOrder(alignment);
1817 start = selectionGroup.getStartRes();
1818 end = selectionGroup.getEndRes() + 1;
1822 if (hasHiddenRows() && exportHiddenSeqs)
1824 AlignmentI fullAlignment = alignment.getHiddenSequences()
1825 .getFullAlignment();
1826 iSize = fullAlignment.getHeight();
1827 seqs = fullAlignment.getSequencesArray();
1828 end = fullAlignment.getWidth();
1832 iSize = alignment.getHeight();
1833 seqs = alignment.getSequencesArray();
1834 end = alignment.getWidth();
1838 selection = new String[iSize];
1839 if (alignment.getHiddenColumns() != null
1840 && alignment.getHiddenColumns().hasHiddenColumns())
1842 selection = alignment.getHiddenColumns().getVisibleSequenceStrings(
1847 for (i = 0; i < iSize; i++)
1849 selection[i] = seqs[i].getSequenceAsString(start, end);
1857 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1859 ArrayList<int[]> regions = new ArrayList<>();
1865 HiddenColumns hidden = alignment.getHiddenColumns();
1866 if (hidden != null && hidden.hasHiddenColumns())
1870 start = hidden.adjustForHiddenColumns(start);
1873 end = hidden.getHiddenBoundaryRight(start);
1884 regions.add(new int[] { start, end });
1886 if (hidden != null && hidden.hasHiddenColumns())
1888 start = hidden.adjustForHiddenColumns(end);
1889 start = hidden.getHiddenBoundaryLeft(start) + 1;
1891 } while (end < max);
1893 int[][] startEnd = new int[regions.size()][2];
1899 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1900 boolean selectedOnly)
1902 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1903 AlignmentAnnotation[] aa;
1904 if ((aa = alignment.getAlignmentAnnotation()) != null)
1906 for (AlignmentAnnotation annot : aa)
1908 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1909 if (selectedOnly && selectionGroup != null)
1911 alignment.getHiddenColumns().makeVisibleAnnotation(
1912 selectionGroup.getStartRes(),
1913 selectionGroup.getEndRes(), clone);
1917 alignment.getHiddenColumns().makeVisibleAnnotation(clone);
1926 public boolean isPadGaps()
1932 public void setPadGaps(boolean padGaps)
1934 this.padGaps = padGaps;
1938 * apply any post-edit constraints and trigger any calculations needed after
1939 * an edit has been performed on the alignment
1944 public void alignmentChanged(AlignmentViewPanel ap)
1948 alignment.padGaps();
1950 if (autoCalculateConsensus)
1952 updateConsensus(ap);
1954 if (hconsensus != null && autoCalculateConsensus)
1956 updateConservation(ap);
1958 if (autoCalculateStrucConsensus)
1960 updateStrucConsensus(ap);
1962 if (information != null)
1964 updateInformation(ap);
1967 // Reset endRes of groups if beyond alignment width
1968 int alWidth = alignment.getWidth();
1969 List<SequenceGroup> groups = alignment.getGroups();
1972 for (SequenceGroup sg : groups)
1974 if (sg.getEndRes() > alWidth)
1976 sg.setEndRes(alWidth - 1);
1981 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1983 selectionGroup.setEndRes(alWidth - 1);
1986 updateAllColourSchemes();
1987 calculator.restartWorkers();
1988 // alignment.adjustSequenceAnnotations();
1992 * reset scope and do calculations for all applied colourschemes on alignment
1994 void updateAllColourSchemes()
1996 ResidueShaderI rs = residueShading;
1999 rs.alignmentChanged(alignment, hiddenRepSequences);
2001 rs.setConsensus(hconsensus);
2002 rs.setInformation(hinformation);
2003 if (rs.conservationApplied())
2005 rs.setConservation(Conservation.calculateConservation("All",
2006 alignment.getSequences(), 0, alignment.getWidth(), false,
2007 getConsPercGaps(), false));
2011 for (SequenceGroup sg : alignment.getGroups())
2015 sg.cs.alignmentChanged(sg, hiddenRepSequences);
2017 sg.recalcConservation();
2021 protected void initAutoAnnotation()
2023 // TODO: add menu option action that nulls or creates consensus object
2024 // depending on if the user wants to see the annotation or not in a
2025 // specific alignment
2027 if (hconsensus == null && !isDataset)
2029 if (!alignment.isNucleotide())
2038 consensus = new AlignmentAnnotation("Consensus",
2039 MessageManager.getString("label.consensus_descr"),
2040 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2041 initConsensus(consensus);
2045 initComplementConsensus();
2051 * If this is a protein alignment and there are mappings to cDNA, adds the
2052 * cDNA consensus annotation and returns true, else returns false.
2054 public boolean initComplementConsensus()
2056 if (!alignment.isNucleotide())
2058 final List<AlignedCodonFrame> codonMappings = alignment
2060 if (codonMappings != null && !codonMappings.isEmpty())
2062 boolean doConsensus = false;
2063 for (AlignedCodonFrame mapping : codonMappings)
2065 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2066 MapList[] mapLists = mapping.getdnaToProt();
2067 // mapLists can be empty if project load has not finished resolving
2069 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2077 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2079 .getString("label.complement_consensus_descr"),
2080 new Annotation[1], 0f, 100f,
2081 AlignmentAnnotation.BAR_GRAPH);
2082 initConsensus(complementConsensus);
2090 private void initConsensus(AlignmentAnnotation aa)
2093 aa.autoCalculated = true;
2097 alignment.addAnnotation(aa);
2101 public void initInformation(SequenceI hmmSequence)
2103 information = new AlignmentAnnotation("Information",
2104 MessageManager.getString("label.information_description"),
2105 new Annotation[1], 0f, 6.52f, AlignmentAnnotation.BAR_GRAPH);
2106 information.hasText = true;
2107 information.autoCalculated = true;
2108 information.hasText = true;
2109 information.autoCalculated = false;
2110 information.sequenceRef = hmmSequence;
2111 alignment.addAnnotation(information);
2114 // these should be extracted from the view model - style and settings for
2115 // derived annotation
2116 private void initGapCounts()
2120 gapcounts = new AlignmentAnnotation("Occupancy",
2121 MessageManager.getString("label.occupancy_descr"),
2122 new Annotation[1], 0f,
2123 alignment.getHeight(), AlignmentAnnotation.BAR_GRAPH);
2124 gapcounts.hasText = true;
2125 gapcounts.autoCalculated = true;
2126 gapcounts.scaleColLabel = true;
2127 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2129 alignment.addAnnotation(gapcounts);
2133 private void initConservation()
2135 if (showConservation)
2137 if (conservation == null)
2139 conservation = new AlignmentAnnotation("Conservation",
2140 MessageManager.formatMessage("label.conservation_descr",
2141 getConsPercGaps()), new Annotation[1],
2142 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2143 conservation.hasText = true;
2144 conservation.autoCalculated = true;
2145 alignment.addAnnotation(conservation);
2150 private void initQuality()
2154 if (quality == null)
2156 quality = new AlignmentAnnotation("Quality",
2157 MessageManager.getString("label.quality_descr"),
2158 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2159 quality.hasText = true;
2160 quality.autoCalculated = true;
2161 alignment.addAnnotation(quality);
2166 private void initRNAStructure()
2168 if (alignment.hasRNAStructure() && strucConsensus == null)
2170 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2171 MessageManager.getString("label.strucconsensus_descr"),
2172 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2173 strucConsensus.hasText = true;
2174 strucConsensus.autoCalculated = true;
2178 alignment.addAnnotation(strucConsensus);
2186 * @see jalview.api.AlignViewportI#calcPanelHeight()
2189 public int calcPanelHeight()
2191 // setHeight of panels
2192 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2194 int charHeight = getCharHeight();
2197 BitSet graphgrp = new BitSet();
2198 for (AlignmentAnnotation aa : anns)
2202 System.err.println("Null annotation row: ignoring.");
2209 if (aa.graphGroup > -1)
2211 if (graphgrp.get(aa.graphGroup))
2217 graphgrp.set(aa.graphGroup);
2224 aa.height += charHeight;
2234 aa.height += aa.graphHeight;
2242 height += aa.height;
2254 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2255 boolean preserveNewGroupSettings)
2257 boolean updateCalcs = false;
2258 boolean conv = isShowGroupConservation();
2259 boolean cons = isShowGroupConsensus();
2260 boolean showprf = isShowSequenceLogo();
2261 boolean showConsHist = isShowConsensusHistogram();
2262 boolean normLogo = isNormaliseSequenceLogo();
2263 boolean showHMMPrf = isShowHMMSequenceLogo();
2264 boolean showInfoHist = isShowInformationHistogram();
2265 boolean normHMMLogo = isNormaliseHMMSequenceLogo();
2268 * TODO reorder the annotation rows according to group/sequence ordering on
2271 boolean sortg = true;
2273 // remove old automatic annotation
2274 // add any new annotation
2276 // intersect alignment annotation with alignment groups
2278 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2279 List<SequenceGroup> oldrfs = new ArrayList<>();
2282 for (int an = 0; an < aan.length; an++)
2284 if (aan[an].autoCalculated && aan[an].groupRef != null)
2286 oldrfs.add(aan[an].groupRef);
2287 alignment.deleteAnnotation(aan[an], false);
2291 if (alignment.getGroups() != null)
2293 for (SequenceGroup sg : alignment.getGroups())
2295 updateCalcs = false;
2296 if (applyGlobalSettings
2297 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2299 // set defaults for this group's conservation/consensus
2300 sg.setshowSequenceLogo(showprf);
2301 sg.setShowConsensusHistogram(showConsHist);
2302 sg.setNormaliseSequenceLogo(normLogo);
2303 sg.setshowHMMSequenceLogo(showHMMPrf);
2304 sg.setShowInformationHistogram(showInfoHist);
2305 sg.setNormaliseHMMSequenceLogo(normHMMLogo);
2310 alignment.addAnnotation(sg.getConservationRow(), 0);
2315 alignment.addAnnotation(sg.getConsensus(), 0);
2317 // refresh the annotation rows
2320 sg.recalcConservation();
2328 public boolean isDisplayReferenceSeq()
2330 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2334 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2336 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2340 public boolean isColourByReferenceSeq()
2342 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2346 public Color getSequenceColour(SequenceI seq)
2348 Color sqc = sequenceColours.get(seq);
2349 return (sqc == null ? Color.white : sqc);
2353 public void setSequenceColour(SequenceI seq, Color col)
2357 sequenceColours.remove(seq);
2361 sequenceColours.put(seq, col);
2366 public void updateSequenceIdColours()
2368 for (SequenceGroup sg : alignment.getGroups())
2370 if (sg.idColour != null)
2372 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2374 sequenceColours.put(s, sg.idColour);
2381 public void clearSequenceColours()
2383 sequenceColours.clear();
2387 public AlignViewportI getCodingComplement()
2389 return this.codingComplement;
2393 * Set this as the (cDna/protein) complement of the given viewport. Also
2394 * ensures the reverse relationship is set on the given viewport.
2397 public void setCodingComplement(AlignViewportI av)
2401 System.err.println("Ignoring recursive setCodingComplement request");
2405 this.codingComplement = av;
2406 // avoid infinite recursion!
2407 if (av.getCodingComplement() != this)
2409 av.setCodingComplement(this);
2415 public boolean isNucleotide()
2417 return getAlignment() == null ? false : getAlignment().isNucleotide();
2421 public FeaturesDisplayedI getFeaturesDisplayed()
2423 return featuresDisplayed;
2427 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2429 featuresDisplayed = featuresDisplayedI;
2433 public boolean areFeaturesDisplayed()
2435 return featuresDisplayed != null
2436 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2443 * features are displayed if true
2446 public void setShowSequenceFeatures(boolean b)
2448 viewStyle.setShowSequenceFeatures(b);
2452 public boolean isShowSequenceFeatures()
2454 return viewStyle.isShowSequenceFeatures();
2458 public void setShowSequenceFeaturesHeight(boolean selected)
2460 viewStyle.setShowSequenceFeaturesHeight(selected);
2464 public boolean isShowSequenceFeaturesHeight()
2466 return viewStyle.isShowSequenceFeaturesHeight();
2470 public void setShowAnnotation(boolean b)
2472 viewStyle.setShowAnnotation(b);
2476 public boolean isShowAnnotation()
2478 return viewStyle.isShowAnnotation();
2482 public boolean isRightAlignIds()
2484 return viewStyle.isRightAlignIds();
2488 public void setRightAlignIds(boolean rightAlignIds)
2490 viewStyle.setRightAlignIds(rightAlignIds);
2494 public boolean getConservationSelected()
2496 return viewStyle.getConservationSelected();
2500 public void setShowBoxes(boolean state)
2502 viewStyle.setShowBoxes(state);
2507 * @see jalview.api.ViewStyleI#getTextColour()
2510 public Color getTextColour()
2512 return viewStyle.getTextColour();
2517 * @see jalview.api.ViewStyleI#getTextColour2()
2520 public Color getTextColour2()
2522 return viewStyle.getTextColour2();
2527 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2530 public int getThresholdTextColour()
2532 return viewStyle.getThresholdTextColour();
2537 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2540 public boolean isConservationColourSelected()
2542 return viewStyle.isConservationColourSelected();
2547 * @see jalview.api.ViewStyleI#isRenderGaps()
2550 public boolean isRenderGaps()
2552 return viewStyle.isRenderGaps();
2557 * @see jalview.api.ViewStyleI#isShowColourText()
2560 public boolean isShowColourText()
2562 return viewStyle.isShowColourText();
2566 * @param conservationColourSelected
2567 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2570 public void setConservationColourSelected(
2571 boolean conservationColourSelected)
2573 viewStyle.setConservationColourSelected(conservationColourSelected);
2577 * @param showColourText
2578 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2581 public void setShowColourText(boolean showColourText)
2583 viewStyle.setShowColourText(showColourText);
2588 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2591 public void setTextColour(Color textColour)
2593 viewStyle.setTextColour(textColour);
2597 * @param thresholdTextColour
2598 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2601 public void setThresholdTextColour(int thresholdTextColour)
2603 viewStyle.setThresholdTextColour(thresholdTextColour);
2607 * @param textColour2
2608 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2611 public void setTextColour2(Color textColour2)
2613 viewStyle.setTextColour2(textColour2);
2617 public ViewStyleI getViewStyle()
2619 return new ViewStyle(viewStyle);
2623 public void setViewStyle(ViewStyleI settingsForView)
2625 viewStyle = new ViewStyle(settingsForView);
2626 if (residueShading != null)
2628 residueShading.setConservationApplied(settingsForView
2629 .isConservationColourSelected());
2634 public boolean sameStyle(ViewStyleI them)
2636 return viewStyle.sameStyle(them);
2641 * @see jalview.api.ViewStyleI#getIdWidth()
2644 public int getIdWidth()
2646 return viewStyle.getIdWidth();
2651 * @see jalview.api.ViewStyleI#setIdWidth(int)
2654 public void setIdWidth(int i)
2656 viewStyle.setIdWidth(i);
2661 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2664 public boolean isCentreColumnLabels()
2666 return viewStyle.isCentreColumnLabels();
2670 * @param centreColumnLabels
2671 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2674 public void setCentreColumnLabels(boolean centreColumnLabels)
2676 viewStyle.setCentreColumnLabels(centreColumnLabels);
2681 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2684 public void setShowDBRefs(boolean showdbrefs)
2686 viewStyle.setShowDBRefs(showdbrefs);
2691 * @see jalview.api.ViewStyleI#isShowDBRefs()
2694 public boolean isShowDBRefs()
2696 return viewStyle.isShowDBRefs();
2701 * @see jalview.api.ViewStyleI#isShowNPFeats()
2704 public boolean isShowNPFeats()
2706 return viewStyle.isShowNPFeats();
2710 * @param shownpfeats
2711 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2714 public void setShowNPFeats(boolean shownpfeats)
2716 viewStyle.setShowNPFeats(shownpfeats);
2719 public abstract StructureSelectionManager getStructureSelectionManager();
2722 * Add one command to the command history list.
2726 public void addToHistoryList(CommandI command)
2728 if (this.historyList != null)
2730 this.historyList.push(command);
2731 broadcastCommand(command, false);
2735 protected void broadcastCommand(CommandI command, boolean undo)
2737 getStructureSelectionManager().commandPerformed(command, undo,
2742 * Add one command to the command redo list.
2746 public void addToRedoList(CommandI command)
2748 if (this.redoList != null)
2750 this.redoList.push(command);
2752 broadcastCommand(command, true);
2756 * Clear the command redo list.
2758 public void clearRedoList()
2760 if (this.redoList != null)
2762 this.redoList.clear();
2766 public void setHistoryList(Deque<CommandI> list)
2768 this.historyList = list;
2771 public Deque<CommandI> getHistoryList()
2773 return this.historyList;
2776 public void setRedoList(Deque<CommandI> list)
2778 this.redoList = list;
2781 public Deque<CommandI> getRedoList()
2783 return this.redoList;
2787 public VamsasSource getVamsasSource()
2792 public SequenceAnnotationOrder getSortAnnotationsBy()
2794 return sortAnnotationsBy;
2797 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2799 this.sortAnnotationsBy = sortAnnotationsBy;
2802 public boolean isShowAutocalculatedAbove()
2804 return showAutocalculatedAbove;
2807 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2809 this.showAutocalculatedAbove = showAutocalculatedAbove;
2813 public boolean isScaleProteinAsCdna()
2815 return viewStyle.isScaleProteinAsCdna();
2819 public void setScaleProteinAsCdna(boolean b)
2821 viewStyle.setScaleProteinAsCdna(b);
2825 public boolean isProteinFontAsCdna()
2827 return viewStyle.isProteinFontAsCdna();
2831 public void setProteinFontAsCdna(boolean b)
2833 viewStyle.setProteinFontAsCdna(b);
2837 * @return true if view should scroll to show the highlighted region of a
2842 public final boolean isFollowHighlight()
2844 return followHighlight;
2848 public final void setFollowHighlight(boolean b)
2850 this.followHighlight = b;
2854 public ViewportRanges getRanges()
2860 * Helper method to populate the SearchResults with the location in the
2861 * complementary alignment to scroll to, in order to match this one.
2864 * the SearchResults to add to
2865 * @return the offset (below top of visible region) of the matched sequence
2867 protected int findComplementScrollTarget(SearchResultsI sr)
2869 final AlignViewportI complement = getCodingComplement();
2870 if (complement == null || !complement.isFollowHighlight())
2874 boolean iAmProtein = !getAlignment().isNucleotide();
2875 AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement
2877 if (proteinAlignment == null)
2881 final List<AlignedCodonFrame> mappings = proteinAlignment
2885 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2886 * residue in the middle column of the visible region. Scroll the
2887 * complementary alignment to line up the corresponding residue.
2890 SequenceI sequence = null;
2893 * locate 'middle' column (true middle if an odd number visible, left of
2894 * middle if an even number visible)
2896 int middleColumn = ranges.getStartRes()
2897 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2898 final HiddenSequences hiddenSequences = getAlignment()
2899 .getHiddenSequences();
2902 * searching to the bottom of the alignment gives smoother scrolling across
2903 * all gapped visible regions
2905 int lastSeq = alignment.getHeight() - 1;
2906 List<AlignedCodonFrame> seqMappings = null;
2907 for (int seqNo = ranges.getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2909 sequence = getAlignment().getSequenceAt(seqNo);
2910 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2914 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2918 seqMappings = MappingUtils
2919 .findMappingsForSequenceAndOthers(sequence, mappings,
2920 getCodingComplement().getAlignment().getSequences());
2921 if (!seqMappings.isEmpty())
2927 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2930 * No ungapped mapped sequence in middle column - do nothing
2934 MappingUtils.addSearchResults(sr, sequence,
2935 sequence.findPosition(middleColumn), seqMappings);
2940 * synthesize a column selection if none exists so it covers the given
2941 * selection group. if wholewidth is false, no column selection is made if the
2942 * selection group covers the whole alignment width.
2947 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2950 if (sg != null && (sgs = sg.getStartRes()) >= 0
2951 && sg.getStartRes() <= (sge = sg.getEndRes())
2952 && !this.hasSelectedColumns())
2954 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2961 colSel = new ColumnSelection();
2963 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2965 colSel.addElement(cspos);
2971 * hold status of current selection group - defined on alignment or not.
2973 private boolean selectionIsDefinedGroup = false;
2976 public boolean isSelectionDefinedGroup()
2978 if (selectionGroup == null)
2982 if (isSelectionGroupChanged(true))
2984 selectionIsDefinedGroup = false;
2985 List<SequenceGroup> gps = alignment.getGroups();
2986 if (gps == null || gps.size() == 0)
2988 selectionIsDefinedGroup = false;
2992 selectionIsDefinedGroup = gps.contains(selectionGroup);
2995 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2999 * null, or currently highlighted results on this view
3001 private SearchResultsI searchResults = null;
3004 public boolean hasSearchResults()
3006 return searchResults != null;
3010 public void setSearchResults(SearchResultsI results)
3012 searchResults = results;
3016 public SearchResultsI getSearchResults()
3018 return searchResults;