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.ColumnSelection;
37 import jalview.datamodel.HiddenColumns;
38 import jalview.datamodel.HiddenSequences;
39 import jalview.datamodel.ProfilesI;
40 import jalview.datamodel.SearchResultsI;
41 import jalview.datamodel.Sequence;
42 import jalview.datamodel.SequenceCollectionI;
43 import jalview.datamodel.SequenceGroup;
44 import jalview.datamodel.SequenceI;
45 import jalview.renderer.ResidueShader;
46 import jalview.renderer.ResidueShaderI;
47 import jalview.schemes.ColourSchemeI;
48 import jalview.structure.CommandListener;
49 import jalview.structure.StructureSelectionManager;
50 import jalview.structure.VamsasSource;
51 import jalview.util.Comparison;
52 import jalview.util.MapList;
53 import jalview.util.MappingUtils;
54 import jalview.util.MessageManager;
55 import jalview.viewmodel.styles.ViewStyle;
56 import jalview.workers.AlignCalcManager;
57 import jalview.workers.ComplementConsensusThread;
58 import jalview.workers.ConsensusThread;
59 import jalview.workers.StrucConsensusThread;
61 import java.awt.Color;
62 import java.beans.PropertyChangeSupport;
63 import java.util.ArrayDeque;
64 import java.util.ArrayList;
65 import java.util.BitSet;
66 import java.util.Deque;
67 import java.util.HashMap;
68 import java.util.Hashtable;
69 import java.util.List;
73 * base class holding visualization and analysis attributes and common logic for
74 * an active alignment view displayed in the GUI
79 public abstract class AlignmentViewport
80 implements AlignViewportI, CommandListener, VamsasSource
82 final protected ViewportRanges ranges;
84 protected ViewStyleI viewStyle = new ViewStyle();
87 * A viewport that hosts the cDna view of this (protein), or vice versa (if
90 AlignViewportI codingComplement = null;
92 FeaturesDisplayedI featuresDisplayed = null;
94 protected Deque<CommandI> historyList = new ArrayDeque<>();
96 protected Deque<CommandI> redoList = new ArrayDeque<>();
99 * alignment displayed in the viewport. Please use get/setter
101 protected AlignmentI alignment;
103 public AlignmentViewport(AlignmentI al)
106 ranges = new ViewportRanges(al);
111 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
114 public void setFontName(String name)
116 viewStyle.setFontName(name);
121 * @see jalview.api.ViewStyleI#setFontStyle(int)
124 public void setFontStyle(int style)
126 viewStyle.setFontStyle(style);
131 * @see jalview.api.ViewStyleI#setFontSize(int)
134 public void setFontSize(int size)
136 viewStyle.setFontSize(size);
141 * @see jalview.api.ViewStyleI#getFontStyle()
144 public int getFontStyle()
146 return viewStyle.getFontStyle();
151 * @see jalview.api.ViewStyleI#getFontName()
154 public String getFontName()
156 return viewStyle.getFontName();
161 * @see jalview.api.ViewStyleI#getFontSize()
164 public int getFontSize()
166 return viewStyle.getFontSize();
170 * @param upperCasebold
171 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
174 public void setUpperCasebold(boolean upperCasebold)
176 viewStyle.setUpperCasebold(upperCasebold);
181 * @see jalview.api.ViewStyleI#isUpperCasebold()
184 public boolean isUpperCasebold()
186 return viewStyle.isUpperCasebold();
191 * @see jalview.api.ViewStyleI#isSeqNameItalics()
194 public boolean isSeqNameItalics()
196 return viewStyle.isSeqNameItalics();
200 * @param colourByReferenceSeq
201 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
204 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
206 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
211 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
214 public void setColourAppliesToAllGroups(boolean b)
216 viewStyle.setColourAppliesToAllGroups(b);
221 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
224 public boolean getColourAppliesToAllGroups()
226 return viewStyle.getColourAppliesToAllGroups();
231 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
234 public boolean getAbovePIDThreshold()
236 return viewStyle.getAbovePIDThreshold();
241 * @see jalview.api.ViewStyleI#setIncrement(int)
244 public void setIncrement(int inc)
246 viewStyle.setIncrement(inc);
251 * @see jalview.api.ViewStyleI#getIncrement()
254 public int getIncrement()
256 return viewStyle.getIncrement();
261 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
264 public void setConservationSelected(boolean b)
266 viewStyle.setConservationSelected(b);
271 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
274 public void setShowHiddenMarkers(boolean show)
276 viewStyle.setShowHiddenMarkers(show);
281 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
284 public boolean getShowHiddenMarkers()
286 return viewStyle.getShowHiddenMarkers();
291 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
294 public void setScaleRightWrapped(boolean b)
296 viewStyle.setScaleRightWrapped(b);
301 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
304 public void setScaleLeftWrapped(boolean b)
306 viewStyle.setScaleLeftWrapped(b);
311 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
314 public void setScaleAboveWrapped(boolean b)
316 viewStyle.setScaleAboveWrapped(b);
321 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
324 public boolean getScaleLeftWrapped()
326 return viewStyle.getScaleLeftWrapped();
331 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
334 public boolean getScaleAboveWrapped()
336 return viewStyle.getScaleAboveWrapped();
341 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
344 public boolean getScaleRightWrapped()
346 return viewStyle.getScaleRightWrapped();
351 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
354 public void setAbovePIDThreshold(boolean b)
356 viewStyle.setAbovePIDThreshold(b);
361 * @see jalview.api.ViewStyleI#setThreshold(int)
364 public void setThreshold(int thresh)
366 viewStyle.setThreshold(thresh);
371 * @see jalview.api.ViewStyleI#getThreshold()
374 public int getThreshold()
376 return viewStyle.getThreshold();
381 * @see jalview.api.ViewStyleI#getShowJVSuffix()
384 public boolean getShowJVSuffix()
386 return viewStyle.getShowJVSuffix();
391 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
394 public void setShowJVSuffix(boolean b)
396 viewStyle.setShowJVSuffix(b);
401 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
404 public void setWrapAlignment(boolean state)
406 viewStyle.setWrapAlignment(state);
407 ranges.setWrappedMode(state);
412 * @see jalview.api.ViewStyleI#setShowText(boolean)
415 public void setShowText(boolean state)
417 viewStyle.setShowText(state);
422 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
425 public void setRenderGaps(boolean state)
427 viewStyle.setRenderGaps(state);
432 * @see jalview.api.ViewStyleI#getColourText()
435 public boolean getColourText()
437 return viewStyle.getColourText();
442 * @see jalview.api.ViewStyleI#setColourText(boolean)
445 public void setColourText(boolean state)
447 viewStyle.setColourText(state);
452 * @see jalview.api.ViewStyleI#getWrapAlignment()
455 public boolean getWrapAlignment()
457 return viewStyle.getWrapAlignment();
462 * @see jalview.api.ViewStyleI#getShowText()
465 public boolean getShowText()
467 return viewStyle.getShowText();
472 * @see jalview.api.ViewStyleI#getWrappedWidth()
475 public int getWrappedWidth()
477 return viewStyle.getWrappedWidth();
482 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
485 public void setWrappedWidth(int w)
487 viewStyle.setWrappedWidth(w);
492 * @see jalview.api.ViewStyleI#getCharHeight()
495 public int getCharHeight()
497 return viewStyle.getCharHeight();
502 * @see jalview.api.ViewStyleI#setCharHeight(int)
505 public void setCharHeight(int h)
507 viewStyle.setCharHeight(h);
512 * @see jalview.api.ViewStyleI#getCharWidth()
515 public int getCharWidth()
517 return viewStyle.getCharWidth();
522 * @see jalview.api.ViewStyleI#setCharWidth(int)
525 public void setCharWidth(int w)
527 viewStyle.setCharWidth(w);
532 * @see jalview.api.ViewStyleI#getShowBoxes()
535 public boolean getShowBoxes()
537 return viewStyle.getShowBoxes();
542 * @see jalview.api.ViewStyleI#getShowUnconserved()
545 public boolean getShowUnconserved()
547 return viewStyle.getShowUnconserved();
551 * @param showunconserved
552 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
555 public void setShowUnconserved(boolean showunconserved)
557 viewStyle.setShowUnconserved(showunconserved);
562 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
565 public void setSeqNameItalics(boolean default1)
567 viewStyle.setSeqNameItalics(default1);
571 public AlignmentI getAlignment()
577 public char getGapCharacter()
579 return alignment.getGapCharacter();
582 protected String sequenceSetID;
585 * probably unused indicator that view is of a dataset rather than an
588 protected boolean isDataset = false;
590 public void setDataset(boolean b)
595 public boolean isDataset()
600 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
602 protected ColumnSelection colSel = new ColumnSelection();
604 public boolean autoCalculateConsensus = true;
606 protected boolean autoCalculateStrucConsensus = true;
608 protected boolean ignoreGapsInConsensusCalculation = false;
610 protected ResidueShaderI residueShading = new ResidueShader();
613 public void setGlobalColourScheme(ColourSchemeI cs)
615 // TODO: logic refactored from AlignFrame changeColour -
616 // TODO: autorecalc stuff should be changed to rely on the worker system
617 // check to see if we should implement a changeColour(cs) method rather than
618 // put the logic in here
619 // - means that caller decides if they want to just modify state and defer
620 // calculation till later or to do all calculations in thread.
624 * only instantiate alignment colouring once, thereafter update it;
625 * this means that any conservation or PID threshold settings
626 * persist when the alignment colour scheme is changed
628 if (residueShading == null)
630 residueShading = new ResidueShader(viewStyle);
632 residueShading.setColourScheme(cs);
634 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
635 // ...problem: groups need these, but do not currently have a ViewStyle
639 if (getConservationSelected())
641 residueShading.setConservation(hconservation);
644 * reset conservation flag in case just set to false if
645 * Conservation was null (calculation still in progress)
647 residueShading.setConservationApplied(getConservationSelected());
648 residueShading.alignmentChanged(alignment, hiddenRepSequences);
652 * if 'apply colour to all groups' is selected... do so
653 * (but don't transfer any colour threshold settings to groups)
655 if (getColourAppliesToAllGroups())
657 for (SequenceGroup sg : getAlignment().getGroups())
660 * retain any colour thresholds per group while
661 * changing choice of colour scheme (JAL-2386)
663 sg.setColourScheme(cs);
666 sg.getGroupColourScheme().alignmentChanged(sg,
674 public ColourSchemeI getGlobalColourScheme()
676 return residueShading == null ? null : residueShading.getColourScheme();
680 public ResidueShaderI getResidueShading()
682 return residueShading;
685 protected AlignmentAnnotation consensus;
687 protected AlignmentAnnotation complementConsensus;
689 protected AlignmentAnnotation gapcounts;
691 protected AlignmentAnnotation strucConsensus;
693 protected AlignmentAnnotation conservation;
695 protected AlignmentAnnotation quality;
697 protected AlignmentAnnotation[] groupConsensus;
699 protected AlignmentAnnotation[] groupConservation;
702 * results of alignment consensus analysis for visible portion of view
704 protected ProfilesI hconsensus = null;
707 * results of cDNA complement consensus visible portion of view
709 protected Hashtable[] hcomplementConsensus = null;
712 * results of secondary structure base pair consensus for visible portion of
715 protected Hashtable[] hStrucConsensus = null;
717 protected Conservation hconservation = null;
720 public void setConservation(Conservation cons)
722 hconservation = cons;
726 * percentage gaps allowed in a column before all amino acid properties should
727 * be considered unconserved
729 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
732 public int getConsPercGaps()
738 public void setSequenceConsensusHash(ProfilesI hconsensus)
740 this.hconsensus = hconsensus;
744 public void setComplementConsensusHash(Hashtable[] hconsensus)
746 this.hcomplementConsensus = hconsensus;
750 public ProfilesI getSequenceConsensusHash()
756 public Hashtable[] getComplementConsensusHash()
758 return hcomplementConsensus;
762 public Hashtable[] getRnaStructureConsensusHash()
764 return hStrucConsensus;
768 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
770 this.hStrucConsensus = hStrucConsensus;
775 public AlignmentAnnotation getAlignmentQualityAnnot()
781 public AlignmentAnnotation getAlignmentConservationAnnotation()
787 public AlignmentAnnotation getAlignmentConsensusAnnotation()
793 public AlignmentAnnotation getAlignmentGapAnnotation()
799 public AlignmentAnnotation getComplementConsensusAnnotation()
801 return complementConsensus;
805 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
807 return strucConsensus;
810 protected AlignCalcManagerI calculator = new AlignCalcManager();
813 * trigger update of conservation annotation
815 public void updateConservation(final AlignmentViewPanel ap)
817 // see note in mantis : issue number 8585
818 if (alignment.isNucleotide()
819 || (conservation == null && quality == null)
820 || !autoCalculateConsensus)
824 if (calculator.getRegisteredWorkersOfClass(
825 jalview.workers.ConservationThread.class) == null)
827 calculator.registerWorker(
828 new jalview.workers.ConservationThread(this, ap));
833 * trigger update of consensus annotation
835 public void updateConsensus(final AlignmentViewPanel ap)
837 // see note in mantis : issue number 8585
838 if (consensus == null || !autoCalculateConsensus)
843 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
845 calculator.registerWorker(new ConsensusThread(this, ap));
849 * A separate thread to compute cDNA consensus for a protein alignment
850 * which has mapping to cDNA
852 final AlignmentI al = this.getAlignment();
853 if (!al.isNucleotide() && al.getCodonFrames() != null
854 && !al.getCodonFrames().isEmpty())
857 * fudge - check first for protein-to-nucleotide mappings
858 * (we don't want to do this for protein-to-protein)
860 boolean doConsensus = false;
861 for (AlignedCodonFrame mapping : al.getCodonFrames())
863 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
864 MapList[] mapLists = mapping.getdnaToProt();
865 // mapLists can be empty if project load has not finished resolving seqs
866 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
874 if (calculator.getRegisteredWorkersOfClass(
875 ComplementConsensusThread.class) == null)
878 .registerWorker(new ComplementConsensusThread(this, ap));
884 // --------START Structure Conservation
885 public void updateStrucConsensus(final AlignmentViewPanel ap)
887 if (autoCalculateStrucConsensus && strucConsensus == null
888 && alignment.isNucleotide() && alignment.hasRNAStructure())
890 // secondary structure has been added - so init the consensus line
894 // see note in mantis : issue number 8585
895 if (strucConsensus == null || !autoCalculateStrucConsensus)
899 if (calculator.getRegisteredWorkersOfClass(
900 StrucConsensusThread.class) == null)
902 calculator.registerWorker(new StrucConsensusThread(this, ap));
906 public boolean isCalcInProgress()
908 return calculator.isWorking();
912 public boolean isCalculationInProgress(
913 AlignmentAnnotation alignmentAnnotation)
915 if (!alignmentAnnotation.autoCalculated)
919 if (calculator.workingInvolvedWith(alignmentAnnotation))
921 // System.err.println("grey out ("+alignmentAnnotation.label+")");
927 public void setAlignment(AlignmentI align)
929 this.alignment = align;
933 * Clean up references when this viewport is closed
936 public void dispose()
939 * defensively null out references to large objects in case
940 * this object is not garbage collected (as if!)
943 complementConsensus = null;
944 strucConsensus = null;
947 groupConsensus = null;
948 groupConservation = null;
950 hcomplementConsensus = null;
951 // colour scheme may hold reference to consensus
952 residueShading = null;
953 // TODO remove listeners from changeSupport?
954 changeSupport = null;
959 public boolean isClosed()
961 // TODO: check that this isClosed is only true after panel is closed, not
962 // before it is fully constructed.
963 return alignment == null;
967 public AlignCalcManagerI getCalcManager()
973 * should conservation rows be shown for groups
975 protected boolean showGroupConservation = false;
978 * should consensus rows be shown for groups
980 protected boolean showGroupConsensus = false;
983 * should consensus profile be rendered by default
985 protected boolean showSequenceLogo = false;
988 * should consensus profile be rendered normalised to row height
990 protected boolean normaliseSequenceLogo = false;
993 * should consensus histograms be rendered by default
995 protected boolean showConsensusHistogram = true;
998 * @return the showConsensusProfile
1001 public boolean isShowSequenceLogo()
1003 return showSequenceLogo;
1007 * @param showSequenceLogo
1010 public void setShowSequenceLogo(boolean showSequenceLogo)
1012 if (showSequenceLogo != this.showSequenceLogo)
1014 // TODO: decouple settings setting from calculation when refactoring
1015 // annotation update method from alignframe to viewport
1016 this.showSequenceLogo = showSequenceLogo;
1017 calculator.updateAnnotationFor(ConsensusThread.class);
1018 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1019 calculator.updateAnnotationFor(StrucConsensusThread.class);
1021 this.showSequenceLogo = showSequenceLogo;
1025 * @param showConsensusHistogram
1026 * the showConsensusHistogram to set
1028 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1030 this.showConsensusHistogram = showConsensusHistogram;
1034 * @return the showGroupConservation
1036 public boolean isShowGroupConservation()
1038 return showGroupConservation;
1042 * @param showGroupConservation
1043 * the showGroupConservation to set
1045 public void setShowGroupConservation(boolean showGroupConservation)
1047 this.showGroupConservation = showGroupConservation;
1051 * @return the showGroupConsensus
1053 public boolean isShowGroupConsensus()
1055 return showGroupConsensus;
1059 * @param showGroupConsensus
1060 * the showGroupConsensus to set
1062 public void setShowGroupConsensus(boolean showGroupConsensus)
1064 this.showGroupConsensus = showGroupConsensus;
1069 * @return flag to indicate if the consensus histogram should be rendered by
1073 public boolean isShowConsensusHistogram()
1075 return this.showConsensusHistogram;
1079 * when set, updateAlignment will always ensure sequences are of equal length
1081 private boolean padGaps = false;
1084 * when set, alignment should be reordered according to a newly opened tree
1086 public boolean sortByTree = false;
1091 * @return null or the currently selected sequence region
1094 public SequenceGroup getSelectionGroup()
1096 return selectionGroup;
1100 * Set the selection group for this window. Also sets the current alignment as
1101 * the context for the group, if it does not already have one.
1104 * - group holding references to sequences in this alignment view
1108 public void setSelectionGroup(SequenceGroup sg)
1110 selectionGroup = sg;
1111 if (sg != null && sg.getContext() == null)
1113 sg.setContext(alignment);
1117 public void setHiddenColumns(HiddenColumns hidden)
1119 this.alignment.setHiddenColumns(hidden);
1123 public ColumnSelection getColumnSelection()
1129 public void setColumnSelection(ColumnSelection colSel)
1131 this.colSel = colSel;
1134 updateHiddenColumns();
1136 isColSelChanged(true);
1144 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1146 return hiddenRepSequences;
1150 public void setHiddenRepSequences(
1151 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1153 this.hiddenRepSequences = hiddenRepSequences;
1157 public boolean hasSelectedColumns()
1159 ColumnSelection columnSelection = getColumnSelection();
1160 return columnSelection != null && columnSelection.hasSelectedColumns();
1164 public boolean hasHiddenColumns()
1166 return alignment.getHiddenColumns() != null
1167 && alignment.getHiddenColumns().hasHiddenColumns();
1170 public void updateHiddenColumns()
1172 // this method doesn't really do anything now. But - it could, since a
1173 // column Selection could be in the process of modification
1174 // hasHiddenColumns = colSel.hasHiddenColumns();
1178 public boolean hasHiddenRows()
1180 return alignment.getHiddenSequences().getSize() > 0;
1183 protected SequenceGroup selectionGroup;
1185 public void setSequenceSetId(String newid)
1187 if (sequenceSetID != null)
1190 "Warning - overwriting a sequenceSetId for a viewport!");
1192 sequenceSetID = new String(newid);
1196 public String getSequenceSetId()
1198 if (sequenceSetID == null)
1200 sequenceSetID = alignment.hashCode() + "";
1203 return sequenceSetID;
1207 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1210 protected String viewId = null;
1213 public String getViewId()
1217 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1222 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1224 ignoreGapsInConsensusCalculation = b;
1227 updateConsensus(ap);
1228 if (residueShading != null)
1230 residueShading.setThreshold(residueShading.getThreshold(),
1231 ignoreGapsInConsensusCalculation);
1237 private long sgrouphash = -1, colselhash = -1;
1240 * checks current SelectionGroup against record of last hash value, and
1244 * update the record of last hash value
1246 * @return true if SelectionGroup changed since last call (when b is true)
1248 public boolean isSelectionGroupChanged(boolean b)
1250 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1251 : selectionGroup.hashCode();
1252 if (hc != -1 && hc != sgrouphash)
1264 * checks current colsel against record of last hash value, and optionally
1268 * update the record of last hash value
1269 * @return true if colsel changed since last call (when b is true)
1271 public boolean isColSelChanged(boolean b)
1273 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1274 if (hc != -1 && hc != colselhash)
1286 public boolean isIgnoreGapsConsensus()
1288 return ignoreGapsInConsensusCalculation;
1291 // property change stuff
1292 // JBPNote Prolly only need this in the applet version.
1293 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1296 protected boolean showConservation = true;
1298 protected boolean showQuality = true;
1300 protected boolean showConsensus = true;
1302 protected boolean showOccupancy = true;
1304 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1306 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1308 protected boolean showAutocalculatedAbove;
1311 * when set, view will scroll to show the highlighted position
1313 private boolean followHighlight = true;
1316 * Property change listener for changes in alignment
1321 public void addPropertyChangeListener(
1322 java.beans.PropertyChangeListener listener)
1324 changeSupport.addPropertyChangeListener(listener);
1333 public void removePropertyChangeListener(
1334 java.beans.PropertyChangeListener listener)
1336 changeSupport.removePropertyChangeListener(listener);
1340 * Property change listener for changes in alignment
1349 public void firePropertyChange(String prop, Object oldvalue,
1352 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1355 // common hide/show column stuff
1357 public void hideSelectedColumns()
1359 if (colSel.isEmpty())
1364 colSel.hideSelectedColumns(alignment);
1365 setSelectionGroup(null);
1366 isColSelChanged(true);
1369 public void hideColumns(int start, int end)
1373 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1377 alignment.getHiddenColumns().hideColumns(start, end);
1379 isColSelChanged(true);
1382 public void showColumn(int col)
1384 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1385 isColSelChanged(true);
1388 public void showAllHiddenColumns()
1390 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1391 isColSelChanged(true);
1394 // common hide/show seq stuff
1395 public void showAllHiddenSeqs()
1397 int startSeq = ranges.getStartSeq();
1398 int endSeq = ranges.getEndSeq();
1400 if (alignment.getHiddenSequences().getSize() > 0)
1402 if (selectionGroup == null)
1404 selectionGroup = new SequenceGroup();
1405 selectionGroup.setEndRes(alignment.getWidth() - 1);
1407 List<SequenceI> tmp = alignment.getHiddenSequences()
1408 .showAll(hiddenRepSequences);
1409 for (SequenceI seq : tmp)
1411 selectionGroup.addSequence(seq, false);
1412 setSequenceAnnotationsVisible(seq, true);
1415 hiddenRepSequences = null;
1417 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1419 firePropertyChange("alignment", null, alignment.getSequences());
1420 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1426 public void showSequence(int index)
1428 int startSeq = ranges.getStartSeq();
1429 int endSeq = ranges.getEndSeq();
1431 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1432 hiddenRepSequences);
1435 if (selectionGroup == null)
1437 selectionGroup = new SequenceGroup();
1438 selectionGroup.setEndRes(alignment.getWidth() - 1);
1441 for (SequenceI seq : tmp)
1443 selectionGroup.addSequence(seq, false);
1444 setSequenceAnnotationsVisible(seq, true);
1447 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1449 firePropertyChange("alignment", null, alignment.getSequences());
1454 public void hideAllSelectedSeqs()
1456 if (selectionGroup == null || selectionGroup.getSize() < 1)
1461 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1465 setSelectionGroup(null);
1468 public void hideSequence(SequenceI[] seq)
1471 * cache offset to first visible sequence
1473 int startSeq = ranges.getStartSeq();
1477 for (int i = 0; i < seq.length; i++)
1479 alignment.getHiddenSequences().hideSequence(seq[i]);
1480 setSequenceAnnotationsVisible(seq[i], false);
1482 ranges.setStartSeq(startSeq);
1483 firePropertyChange("alignment", null, alignment.getSequences());
1488 * Hides the specified sequence, or the sequences it represents
1491 * the sequence to hide, or keep as representative
1492 * @param representGroup
1493 * if true, hide the current selection group except for the
1494 * representative sequence
1496 public void hideSequences(SequenceI sequence, boolean representGroup)
1498 if (selectionGroup == null || selectionGroup.getSize() < 1)
1500 hideSequence(new SequenceI[] { sequence });
1506 hideRepSequences(sequence, selectionGroup);
1507 setSelectionGroup(null);
1511 int gsize = selectionGroup.getSize();
1512 SequenceI[] hseqs = selectionGroup.getSequences()
1513 .toArray(new SequenceI[gsize]);
1515 hideSequence(hseqs);
1516 setSelectionGroup(null);
1521 * Set visibility for any annotations for the given sequence.
1525 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1528 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1531 for (AlignmentAnnotation ann : anns)
1533 if (ann.sequenceRef == sequenceI)
1535 ann.visible = visible;
1541 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1543 int sSize = sg.getSize();
1549 if (hiddenRepSequences == null)
1551 hiddenRepSequences = new Hashtable<>();
1554 hiddenRepSequences.put(repSequence, sg);
1556 // Hide all sequences except the repSequence
1557 SequenceI[] seqs = new SequenceI[sSize - 1];
1559 for (int i = 0; i < sSize; i++)
1561 if (sg.getSequenceAt(i) != repSequence)
1563 if (index == sSize - 1)
1568 seqs[index++] = sg.getSequenceAt(i);
1571 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1572 sg.setHidereps(true); // note: not done in 2.7applet
1579 * @return null or the current reference sequence
1581 public SequenceI getReferenceSeq()
1583 return alignment.getSeqrep();
1588 * @return true iff seq is the reference for the alignment
1590 public boolean isReferenceSeq(SequenceI seq)
1592 return alignment.getSeqrep() == seq;
1598 * @return true if there are sequences represented by this sequence that are
1601 public boolean isHiddenRepSequence(SequenceI seq)
1603 return (hiddenRepSequences != null
1604 && hiddenRepSequences.containsKey(seq));
1610 * @return null or a sequence group containing the sequences that seq
1613 public SequenceGroup getRepresentedSequences(SequenceI seq)
1615 return (SequenceGroup) (hiddenRepSequences == null ? null
1616 : hiddenRepSequences.get(seq));
1620 public int adjustForHiddenSeqs(int alignmentIndex)
1622 return alignment.getHiddenSequences()
1623 .adjustForHiddenSeqs(alignmentIndex);
1627 public void invertColumnSelection()
1629 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1633 public SequenceI[] getSelectionAsNewSequence()
1635 SequenceI[] sequences;
1636 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1637 // this was the only caller in the applet for this method
1638 // JBPNote: in applet, this method returned references to the alignment
1639 // sequences, and it did not honour the presence/absence of annotation
1640 // attached to the alignment (probably!)
1641 if (selectionGroup == null || selectionGroup.getSize() == 0)
1643 sequences = alignment.getSequencesArray();
1644 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1645 for (int i = 0; i < sequences.length; i++)
1647 // construct new sequence with subset of visible annotation
1648 sequences[i] = new Sequence(sequences[i], annots);
1653 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1660 public SequenceI[] getSequenceSelection()
1662 SequenceI[] sequences = null;
1663 if (selectionGroup != null)
1665 sequences = selectionGroup.getSequencesInOrder(alignment);
1667 if (sequences == null)
1669 sequences = alignment.getSequencesArray();
1675 public jalview.datamodel.AlignmentView getAlignmentView(
1676 boolean selectedOnly)
1678 return getAlignmentView(selectedOnly, false);
1682 public jalview.datamodel.AlignmentView getAlignmentView(
1683 boolean selectedOnly, boolean markGroups)
1685 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1687 alignment.getHiddenColumns() != null
1688 && alignment.getHiddenColumns().hasHiddenColumns(),
1689 selectedOnly, markGroups);
1693 public String[] getViewAsString(boolean selectedRegionOnly)
1695 return getViewAsString(selectedRegionOnly, true);
1699 public String[] getViewAsString(boolean selectedRegionOnly,
1700 boolean exportHiddenSeqs)
1702 String[] selection = null;
1703 SequenceI[] seqs = null;
1705 int start = 0, end = 0;
1706 if (selectedRegionOnly && selectionGroup != null)
1708 iSize = selectionGroup.getSize();
1709 seqs = selectionGroup.getSequencesInOrder(alignment);
1710 start = selectionGroup.getStartRes();
1711 end = selectionGroup.getEndRes() + 1;
1715 if (hasHiddenRows() && exportHiddenSeqs)
1717 AlignmentI fullAlignment = alignment.getHiddenSequences()
1718 .getFullAlignment();
1719 iSize = fullAlignment.getHeight();
1720 seqs = fullAlignment.getSequencesArray();
1721 end = fullAlignment.getWidth();
1725 iSize = alignment.getHeight();
1726 seqs = alignment.getSequencesArray();
1727 end = alignment.getWidth();
1731 selection = new String[iSize];
1732 if (alignment.getHiddenColumns() != null
1733 && alignment.getHiddenColumns().hasHiddenColumns())
1735 selection = alignment.getHiddenColumns()
1736 .getVisibleSequenceStrings(start, end, seqs);
1740 for (i = 0; i < iSize; i++)
1742 selection[i] = seqs[i].getSequenceAsString(start, end);
1750 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1752 ArrayList<int[]> regions = new ArrayList<>();
1758 HiddenColumns hidden = alignment.getHiddenColumns();
1759 if (hidden != null && hidden.hasHiddenColumns())
1763 start = hidden.adjustForHiddenColumns(start);
1766 end = hidden.getHiddenBoundaryRight(start);
1777 regions.add(new int[] { start, end });
1779 if (hidden != null && hidden.hasHiddenColumns())
1781 start = hidden.adjustForHiddenColumns(end);
1782 start = hidden.getHiddenBoundaryLeft(start) + 1;
1784 } while (end < max);
1786 int[][] startEnd = new int[regions.size()][2];
1792 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1793 boolean selectedOnly)
1795 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1796 AlignmentAnnotation[] aa;
1797 if ((aa = alignment.getAlignmentAnnotation()) != null)
1799 for (AlignmentAnnotation annot : aa)
1801 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1802 if (selectedOnly && selectionGroup != null)
1804 alignment.getHiddenColumns().makeVisibleAnnotation(
1805 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1810 alignment.getHiddenColumns().makeVisibleAnnotation(clone);
1819 public boolean isPadGaps()
1825 public void setPadGaps(boolean padGaps)
1827 this.padGaps = padGaps;
1831 * apply any post-edit constraints and trigger any calculations needed after
1832 * an edit has been performed on the alignment
1837 public void alignmentChanged(AlignmentViewPanel ap)
1841 alignment.padGaps();
1843 if (autoCalculateConsensus)
1845 updateConsensus(ap);
1847 if (hconsensus != null && autoCalculateConsensus)
1849 updateConservation(ap);
1851 if (autoCalculateStrucConsensus)
1853 updateStrucConsensus(ap);
1856 // Reset endRes of groups if beyond alignment width
1857 int alWidth = alignment.getWidth();
1858 List<SequenceGroup> groups = alignment.getGroups();
1861 for (SequenceGroup sg : groups)
1863 if (sg.getEndRes() > alWidth)
1865 sg.setEndRes(alWidth - 1);
1870 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1872 selectionGroup.setEndRes(alWidth - 1);
1875 updateAllColourSchemes();
1876 calculator.restartWorkers();
1877 // alignment.adjustSequenceAnnotations();
1881 * reset scope and do calculations for all applied colourschemes on alignment
1883 void updateAllColourSchemes()
1885 ResidueShaderI rs = residueShading;
1888 rs.alignmentChanged(alignment, hiddenRepSequences);
1890 rs.setConsensus(hconsensus);
1891 if (rs.conservationApplied())
1893 rs.setConservation(Conservation.calculateConservation("All",
1894 alignment.getSequences(), 0, alignment.getWidth(), false,
1895 getConsPercGaps(), false));
1899 for (SequenceGroup sg : alignment.getGroups())
1903 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1905 sg.recalcConservation();
1909 protected void initAutoAnnotation()
1911 // TODO: add menu option action that nulls or creates consensus object
1912 // depending on if the user wants to see the annotation or not in a
1913 // specific alignment
1915 if (hconsensus == null && !isDataset)
1917 if (!alignment.isNucleotide())
1926 consensus = new AlignmentAnnotation("Consensus",
1927 MessageManager.getString("label.consensus_descr"),
1928 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1929 initConsensus(consensus);
1932 initComplementConsensus();
1937 * If this is a protein alignment and there are mappings to cDNA, adds the
1938 * cDNA consensus annotation and returns true, else returns false.
1940 public boolean initComplementConsensus()
1942 if (!alignment.isNucleotide())
1944 final List<AlignedCodonFrame> codonMappings = alignment
1946 if (codonMappings != null && !codonMappings.isEmpty())
1948 boolean doConsensus = false;
1949 for (AlignedCodonFrame mapping : codonMappings)
1951 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1952 MapList[] mapLists = mapping.getdnaToProt();
1953 // mapLists can be empty if project load has not finished resolving
1955 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1963 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1965 .getString("label.complement_consensus_descr"),
1966 new Annotation[1], 0f, 100f,
1967 AlignmentAnnotation.BAR_GRAPH);
1968 initConsensus(complementConsensus);
1976 private void initConsensus(AlignmentAnnotation aa)
1979 aa.autoCalculated = true;
1983 alignment.addAnnotation(aa);
1987 // these should be extracted from the view model - style and settings for
1988 // derived annotation
1989 private void initGapCounts()
1993 gapcounts = new AlignmentAnnotation("Occupancy",
1994 MessageManager.getString("label.occupancy_descr"),
1995 new Annotation[1], 0f, alignment.getHeight(),
1996 AlignmentAnnotation.BAR_GRAPH);
1997 gapcounts.hasText = true;
1998 gapcounts.autoCalculated = true;
1999 gapcounts.scaleColLabel = true;
2000 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2002 alignment.addAnnotation(gapcounts);
2006 private void initConservation()
2008 if (showConservation)
2010 if (conservation == null)
2012 conservation = new AlignmentAnnotation("Conservation",
2013 MessageManager.formatMessage("label.conservation_descr",
2015 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2016 conservation.hasText = true;
2017 conservation.autoCalculated = true;
2018 alignment.addAnnotation(conservation);
2023 private void initQuality()
2027 if (quality == null)
2029 quality = new AlignmentAnnotation("Quality",
2030 MessageManager.getString("label.quality_descr"),
2031 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2032 quality.hasText = true;
2033 quality.autoCalculated = true;
2034 alignment.addAnnotation(quality);
2039 private void initRNAStructure()
2041 if (alignment.hasRNAStructure() && strucConsensus == null)
2043 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2044 MessageManager.getString("label.strucconsensus_descr"),
2045 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2046 strucConsensus.hasText = true;
2047 strucConsensus.autoCalculated = true;
2051 alignment.addAnnotation(strucConsensus);
2059 * @see jalview.api.AlignViewportI#calcPanelHeight()
2062 public int calcPanelHeight()
2064 // setHeight of panels
2065 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2067 int charHeight = getCharHeight();
2070 BitSet graphgrp = new BitSet();
2071 for (AlignmentAnnotation aa : anns)
2075 System.err.println("Null annotation row: ignoring.");
2082 if (aa.graphGroup > -1)
2084 if (graphgrp.get(aa.graphGroup))
2090 graphgrp.set(aa.graphGroup);
2097 aa.height += charHeight;
2107 aa.height += aa.graphHeight;
2115 height += aa.height;
2127 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2128 boolean preserveNewGroupSettings)
2130 boolean updateCalcs = false;
2131 boolean conv = isShowGroupConservation();
2132 boolean cons = isShowGroupConsensus();
2133 boolean showprf = isShowSequenceLogo();
2134 boolean showConsHist = isShowConsensusHistogram();
2135 boolean normLogo = isNormaliseSequenceLogo();
2138 * TODO reorder the annotation rows according to group/sequence ordering on
2141 boolean sortg = true;
2143 // remove old automatic annotation
2144 // add any new annotation
2146 // intersect alignment annotation with alignment groups
2148 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2149 List<SequenceGroup> oldrfs = new ArrayList<>();
2152 for (int an = 0; an < aan.length; an++)
2154 if (aan[an].autoCalculated && aan[an].groupRef != null)
2156 oldrfs.add(aan[an].groupRef);
2157 alignment.deleteAnnotation(aan[an], false);
2161 if (alignment.getGroups() != null)
2163 for (SequenceGroup sg : alignment.getGroups())
2165 updateCalcs = false;
2166 if (applyGlobalSettings
2167 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2169 // set defaults for this group's conservation/consensus
2170 sg.setshowSequenceLogo(showprf);
2171 sg.setShowConsensusHistogram(showConsHist);
2172 sg.setNormaliseSequenceLogo(normLogo);
2177 alignment.addAnnotation(sg.getConservationRow(), 0);
2182 alignment.addAnnotation(sg.getConsensus(), 0);
2184 // refresh the annotation rows
2187 sg.recalcConservation();
2195 public boolean isDisplayReferenceSeq()
2197 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2201 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2203 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2207 public boolean isColourByReferenceSeq()
2209 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2213 public Color getSequenceColour(SequenceI seq)
2215 Color sqc = sequenceColours.get(seq);
2216 return (sqc == null ? Color.white : sqc);
2220 public void setSequenceColour(SequenceI seq, Color col)
2224 sequenceColours.remove(seq);
2228 sequenceColours.put(seq, col);
2233 public void updateSequenceIdColours()
2235 for (SequenceGroup sg : alignment.getGroups())
2237 if (sg.idColour != null)
2239 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2241 sequenceColours.put(s, sg.idColour);
2248 public void clearSequenceColours()
2250 sequenceColours.clear();
2254 public AlignViewportI getCodingComplement()
2256 return this.codingComplement;
2260 * Set this as the (cDna/protein) complement of the given viewport. Also
2261 * ensures the reverse relationship is set on the given viewport.
2264 public void setCodingComplement(AlignViewportI av)
2268 System.err.println("Ignoring recursive setCodingComplement request");
2272 this.codingComplement = av;
2273 // avoid infinite recursion!
2274 if (av.getCodingComplement() != this)
2276 av.setCodingComplement(this);
2282 public boolean isNucleotide()
2284 return getAlignment() == null ? false : getAlignment().isNucleotide();
2288 public FeaturesDisplayedI getFeaturesDisplayed()
2290 return featuresDisplayed;
2294 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2296 featuresDisplayed = featuresDisplayedI;
2300 public boolean areFeaturesDisplayed()
2302 return featuresDisplayed != null
2303 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2310 * features are displayed if true
2313 public void setShowSequenceFeatures(boolean b)
2315 viewStyle.setShowSequenceFeatures(b);
2319 public boolean isShowSequenceFeatures()
2321 return viewStyle.isShowSequenceFeatures();
2325 public void setShowSequenceFeaturesHeight(boolean selected)
2327 viewStyle.setShowSequenceFeaturesHeight(selected);
2331 public boolean isShowSequenceFeaturesHeight()
2333 return viewStyle.isShowSequenceFeaturesHeight();
2337 public void setShowAnnotation(boolean b)
2339 viewStyle.setShowAnnotation(b);
2343 public boolean isShowAnnotation()
2345 return viewStyle.isShowAnnotation();
2349 public boolean isRightAlignIds()
2351 return viewStyle.isRightAlignIds();
2355 public void setRightAlignIds(boolean rightAlignIds)
2357 viewStyle.setRightAlignIds(rightAlignIds);
2361 public boolean getConservationSelected()
2363 return viewStyle.getConservationSelected();
2367 public void setShowBoxes(boolean state)
2369 viewStyle.setShowBoxes(state);
2374 * @see jalview.api.ViewStyleI#getTextColour()
2377 public Color getTextColour()
2379 return viewStyle.getTextColour();
2384 * @see jalview.api.ViewStyleI#getTextColour2()
2387 public Color getTextColour2()
2389 return viewStyle.getTextColour2();
2394 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2397 public int getThresholdTextColour()
2399 return viewStyle.getThresholdTextColour();
2404 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2407 public boolean isConservationColourSelected()
2409 return viewStyle.isConservationColourSelected();
2414 * @see jalview.api.ViewStyleI#isRenderGaps()
2417 public boolean isRenderGaps()
2419 return viewStyle.isRenderGaps();
2424 * @see jalview.api.ViewStyleI#isShowColourText()
2427 public boolean isShowColourText()
2429 return viewStyle.isShowColourText();
2433 * @param conservationColourSelected
2434 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2437 public void setConservationColourSelected(
2438 boolean conservationColourSelected)
2440 viewStyle.setConservationColourSelected(conservationColourSelected);
2444 * @param showColourText
2445 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2448 public void setShowColourText(boolean showColourText)
2450 viewStyle.setShowColourText(showColourText);
2455 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2458 public void setTextColour(Color textColour)
2460 viewStyle.setTextColour(textColour);
2464 * @param thresholdTextColour
2465 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2468 public void setThresholdTextColour(int thresholdTextColour)
2470 viewStyle.setThresholdTextColour(thresholdTextColour);
2474 * @param textColour2
2475 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2478 public void setTextColour2(Color textColour2)
2480 viewStyle.setTextColour2(textColour2);
2484 public ViewStyleI getViewStyle()
2486 return new ViewStyle(viewStyle);
2490 public void setViewStyle(ViewStyleI settingsForView)
2492 viewStyle = new ViewStyle(settingsForView);
2493 if (residueShading != null)
2495 residueShading.setConservationApplied(
2496 settingsForView.isConservationColourSelected());
2501 public boolean sameStyle(ViewStyleI them)
2503 return viewStyle.sameStyle(them);
2508 * @see jalview.api.ViewStyleI#getIdWidth()
2511 public int getIdWidth()
2513 return viewStyle.getIdWidth();
2518 * @see jalview.api.ViewStyleI#setIdWidth(int)
2521 public void setIdWidth(int i)
2523 viewStyle.setIdWidth(i);
2528 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2531 public boolean isCentreColumnLabels()
2533 return viewStyle.isCentreColumnLabels();
2537 * @param centreColumnLabels
2538 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2541 public void setCentreColumnLabels(boolean centreColumnLabels)
2543 viewStyle.setCentreColumnLabels(centreColumnLabels);
2548 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2551 public void setShowDBRefs(boolean showdbrefs)
2553 viewStyle.setShowDBRefs(showdbrefs);
2558 * @see jalview.api.ViewStyleI#isShowDBRefs()
2561 public boolean isShowDBRefs()
2563 return viewStyle.isShowDBRefs();
2568 * @see jalview.api.ViewStyleI#isShowNPFeats()
2571 public boolean isShowNPFeats()
2573 return viewStyle.isShowNPFeats();
2577 * @param shownpfeats
2578 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2581 public void setShowNPFeats(boolean shownpfeats)
2583 viewStyle.setShowNPFeats(shownpfeats);
2586 public abstract StructureSelectionManager getStructureSelectionManager();
2589 * Add one command to the command history list.
2593 public void addToHistoryList(CommandI command)
2595 if (this.historyList != null)
2597 this.historyList.push(command);
2598 broadcastCommand(command, false);
2602 protected void broadcastCommand(CommandI command, boolean undo)
2604 getStructureSelectionManager().commandPerformed(command, undo,
2609 * Add one command to the command redo list.
2613 public void addToRedoList(CommandI command)
2615 if (this.redoList != null)
2617 this.redoList.push(command);
2619 broadcastCommand(command, true);
2623 * Clear the command redo list.
2625 public void clearRedoList()
2627 if (this.redoList != null)
2629 this.redoList.clear();
2633 public void setHistoryList(Deque<CommandI> list)
2635 this.historyList = list;
2638 public Deque<CommandI> getHistoryList()
2640 return this.historyList;
2643 public void setRedoList(Deque<CommandI> list)
2645 this.redoList = list;
2648 public Deque<CommandI> getRedoList()
2650 return this.redoList;
2654 public VamsasSource getVamsasSource()
2659 public SequenceAnnotationOrder getSortAnnotationsBy()
2661 return sortAnnotationsBy;
2664 public void setSortAnnotationsBy(
2665 SequenceAnnotationOrder sortAnnotationsBy)
2667 this.sortAnnotationsBy = sortAnnotationsBy;
2670 public boolean isShowAutocalculatedAbove()
2672 return showAutocalculatedAbove;
2675 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2677 this.showAutocalculatedAbove = showAutocalculatedAbove;
2681 public boolean isScaleProteinAsCdna()
2683 return viewStyle.isScaleProteinAsCdna();
2687 public void setScaleProteinAsCdna(boolean b)
2689 viewStyle.setScaleProteinAsCdna(b);
2693 public boolean isProteinFontAsCdna()
2695 return viewStyle.isProteinFontAsCdna();
2699 public void setProteinFontAsCdna(boolean b)
2701 viewStyle.setProteinFontAsCdna(b);
2705 * @return true if view should scroll to show the highlighted region of a
2710 public final boolean isFollowHighlight()
2712 return followHighlight;
2716 public final void setFollowHighlight(boolean b)
2718 this.followHighlight = b;
2722 public ViewportRanges getRanges()
2728 * Helper method to populate the SearchResults with the location in the
2729 * complementary alignment to scroll to, in order to match this one.
2732 * the SearchResults to add to
2733 * @return the offset (below top of visible region) of the matched sequence
2735 protected int findComplementScrollTarget(SearchResultsI sr)
2737 final AlignViewportI complement = getCodingComplement();
2738 if (complement == null || !complement.isFollowHighlight())
2742 boolean iAmProtein = !getAlignment().isNucleotide();
2743 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2744 : complement.getAlignment();
2745 if (proteinAlignment == null)
2749 final List<AlignedCodonFrame> mappings = proteinAlignment
2753 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2754 * residue in the middle column of the visible region. Scroll the
2755 * complementary alignment to line up the corresponding residue.
2758 SequenceI sequence = null;
2761 * locate 'middle' column (true middle if an odd number visible, left of
2762 * middle if an even number visible)
2764 int middleColumn = ranges.getStartRes()
2765 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2766 final HiddenSequences hiddenSequences = getAlignment()
2767 .getHiddenSequences();
2770 * searching to the bottom of the alignment gives smoother scrolling across
2771 * all gapped visible regions
2773 int lastSeq = alignment.getHeight() - 1;
2774 List<AlignedCodonFrame> seqMappings = null;
2775 for (int seqNo = ranges
2776 .getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2778 sequence = getAlignment().getSequenceAt(seqNo);
2779 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2783 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2787 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2789 getCodingComplement().getAlignment().getSequences());
2790 if (!seqMappings.isEmpty())
2796 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2799 * No ungapped mapped sequence in middle column - do nothing
2803 MappingUtils.addSearchResults(sr, sequence,
2804 sequence.findPosition(middleColumn), seqMappings);
2809 * synthesize a column selection if none exists so it covers the given
2810 * selection group. if wholewidth is false, no column selection is made if the
2811 * selection group covers the whole alignment width.
2816 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2819 if (sg != null && (sgs = sg.getStartRes()) >= 0
2820 && sg.getStartRes() <= (sge = sg.getEndRes())
2821 && !this.hasSelectedColumns())
2823 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2830 colSel = new ColumnSelection();
2832 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2834 colSel.addElement(cspos);
2840 * hold status of current selection group - defined on alignment or not.
2842 private boolean selectionIsDefinedGroup = false;
2845 public boolean isSelectionDefinedGroup()
2847 if (selectionGroup == null)
2851 if (isSelectionGroupChanged(true))
2853 selectionIsDefinedGroup = false;
2854 List<SequenceGroup> gps = alignment.getGroups();
2855 if (gps == null || gps.size() == 0)
2857 selectionIsDefinedGroup = false;
2861 selectionIsDefinedGroup = gps.contains(selectionGroup);
2864 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2868 * null, or currently highlighted results on this view
2870 private SearchResultsI searchResults = null;
2873 public boolean hasSearchResults()
2875 return searchResults != null;
2879 public void setSearchResults(SearchResultsI results)
2881 searchResults = results;
2885 public SearchResultsI getSearchResults()
2887 return searchResults;
2891 * get the consensus sequence as displayed under the PID consensus annotation
2894 * @return consensus sequence as a new sequence object
2896 public SequenceI getConsensusSeq()
2898 if (consensus == null)
2900 updateConsensus(null);
2902 if (consensus == null)
2906 StringBuffer seqs = new StringBuffer();
2907 for (int i = 0; i < consensus.annotations.length; i++)
2909 Annotation annotation = consensus.annotations[i];
2910 if (annotation != null)
2912 String description = annotation.description;
2913 if (description != null && description.startsWith("["))
2915 // consensus is a tie - just pick the first one
2916 seqs.append(description.charAt(1));
2920 seqs.append(annotation.displayCharacter);
2925 SequenceI sq = new Sequence("Consensus", seqs.toString());
2926 sq.setDescription("Percentage Identity Consensus "
2927 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));