2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.viewmodel;
23 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
24 import jalview.analysis.Conservation;
25 import jalview.analysis.TreeModel;
26 import jalview.api.AlignCalcManagerI;
27 import jalview.api.AlignViewportI;
28 import jalview.api.AlignmentViewPanel;
29 import jalview.api.FeaturesDisplayedI;
30 import jalview.api.ViewStyleI;
31 import jalview.commands.CommandI;
32 import jalview.datamodel.AlignedCodonFrame;
33 import jalview.datamodel.AlignmentAnnotation;
34 import jalview.datamodel.AlignmentI;
35 import jalview.datamodel.AlignmentView;
36 import jalview.datamodel.Annotation;
37 import jalview.datamodel.ColumnSelection;
38 import jalview.datamodel.HiddenColumns;
39 import jalview.datamodel.HiddenSequences;
40 import jalview.datamodel.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.StrucConsensusThread;
62 import java.awt.Color;
63 import java.beans.PropertyChangeSupport;
64 import java.util.ArrayDeque;
65 import java.util.ArrayList;
66 import java.util.BitSet;
67 import java.util.Deque;
68 import java.util.HashMap;
69 import java.util.Hashtable;
70 import java.util.Iterator;
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
82 implements AlignViewportI, CommandListener, VamsasSource
84 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<>();
101 * alignment displayed in the viewport. Please use get/setter
103 protected AlignmentI alignment;
105 public AlignmentViewport(AlignmentI al)
108 ranges = new ViewportRanges(al);
113 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
116 public void setFontName(String name)
118 viewStyle.setFontName(name);
123 * @see jalview.api.ViewStyleI#setFontStyle(int)
126 public void setFontStyle(int style)
128 viewStyle.setFontStyle(style);
133 * @see jalview.api.ViewStyleI#setFontSize(int)
136 public void setFontSize(int size)
138 viewStyle.setFontSize(size);
143 * @see jalview.api.ViewStyleI#getFontStyle()
146 public int getFontStyle()
148 return viewStyle.getFontStyle();
153 * @see jalview.api.ViewStyleI#getFontName()
156 public String getFontName()
158 return viewStyle.getFontName();
163 * @see jalview.api.ViewStyleI#getFontSize()
166 public int getFontSize()
168 return viewStyle.getFontSize();
172 * @param upperCasebold
173 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
176 public void setUpperCasebold(boolean upperCasebold)
178 viewStyle.setUpperCasebold(upperCasebold);
183 * @see jalview.api.ViewStyleI#isUpperCasebold()
186 public boolean isUpperCasebold()
188 return viewStyle.isUpperCasebold();
193 * @see jalview.api.ViewStyleI#isSeqNameItalics()
196 public boolean isSeqNameItalics()
198 return viewStyle.isSeqNameItalics();
202 * @param colourByReferenceSeq
203 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
206 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
208 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
213 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
216 public void setColourAppliesToAllGroups(boolean b)
218 viewStyle.setColourAppliesToAllGroups(b);
223 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
226 public boolean getColourAppliesToAllGroups()
228 return viewStyle.getColourAppliesToAllGroups();
233 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
236 public boolean getAbovePIDThreshold()
238 return viewStyle.getAbovePIDThreshold();
243 * @see jalview.api.ViewStyleI#setIncrement(int)
246 public void setIncrement(int inc)
248 viewStyle.setIncrement(inc);
253 * @see jalview.api.ViewStyleI#getIncrement()
256 public int getIncrement()
258 return viewStyle.getIncrement();
263 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
266 public void setConservationSelected(boolean b)
268 viewStyle.setConservationSelected(b);
273 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
276 public void setShowHiddenMarkers(boolean show)
278 viewStyle.setShowHiddenMarkers(show);
283 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
286 public boolean getShowHiddenMarkers()
288 return viewStyle.getShowHiddenMarkers();
293 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
296 public void setScaleRightWrapped(boolean b)
298 viewStyle.setScaleRightWrapped(b);
303 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
306 public void setScaleLeftWrapped(boolean b)
308 viewStyle.setScaleLeftWrapped(b);
313 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
316 public void setScaleAboveWrapped(boolean b)
318 viewStyle.setScaleAboveWrapped(b);
323 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
326 public boolean getScaleLeftWrapped()
328 return viewStyle.getScaleLeftWrapped();
333 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
336 public boolean getScaleAboveWrapped()
338 return viewStyle.getScaleAboveWrapped();
343 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
346 public boolean getScaleRightWrapped()
348 return viewStyle.getScaleRightWrapped();
353 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
356 public void setAbovePIDThreshold(boolean b)
358 viewStyle.setAbovePIDThreshold(b);
363 * @see jalview.api.ViewStyleI#setThreshold(int)
366 public void setThreshold(int thresh)
368 viewStyle.setThreshold(thresh);
373 * @see jalview.api.ViewStyleI#getThreshold()
376 public int getThreshold()
378 return viewStyle.getThreshold();
383 * @see jalview.api.ViewStyleI#getShowJVSuffix()
386 public boolean getShowJVSuffix()
388 return viewStyle.getShowJVSuffix();
393 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
396 public void setShowJVSuffix(boolean b)
398 viewStyle.setShowJVSuffix(b);
403 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
406 public void setWrapAlignment(boolean state)
408 viewStyle.setWrapAlignment(state);
409 ranges.setWrappedMode(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#getColourGaps()
457 public boolean getColourGaps()
459 return viewStyle.getColourGaps();
464 * @see jalview.api.ViewStyleI#setColourGaps(boolean)
467 public void setColourGaps(boolean state)
469 viewStyle.setColourGaps(state);
474 * @see jalview.api.ViewStyleI#getWrapAlignment()
477 public boolean getWrapAlignment()
479 return viewStyle.getWrapAlignment();
484 * @see jalview.api.ViewStyleI#getShowText()
487 public boolean getShowText()
489 return viewStyle.getShowText();
494 * @see jalview.api.ViewStyleI#getWrappedWidth()
497 public int getWrappedWidth()
499 return viewStyle.getWrappedWidth();
504 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
507 public void setWrappedWidth(int w)
509 viewStyle.setWrappedWidth(w);
514 * @see jalview.api.ViewStyleI#getCharHeight()
517 public int getCharHeight()
519 return viewStyle.getCharHeight();
524 * @see jalview.api.ViewStyleI#setCharHeight(int)
527 public void setCharHeight(int h)
529 viewStyle.setCharHeight(h);
534 * @see jalview.api.ViewStyleI#getCharWidth()
537 public int getCharWidth()
539 return viewStyle.getCharWidth();
544 * @see jalview.api.ViewStyleI#setCharWidth(int)
547 public void setCharWidth(int w)
549 viewStyle.setCharWidth(w);
554 * @see jalview.api.ViewStyleI#getShowBoxes()
557 public boolean getShowBoxes()
559 return viewStyle.getShowBoxes();
564 * @see jalview.api.ViewStyleI#getShowUnconserved()
567 public boolean getShowUnconserved()
569 return viewStyle.getShowUnconserved();
573 * @param showunconserved
574 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
577 public void setShowUnconserved(boolean showunconserved)
579 viewStyle.setShowUnconserved(showunconserved);
584 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
587 public void setSeqNameItalics(boolean default1)
589 viewStyle.setSeqNameItalics(default1);
593 public AlignmentI getAlignment()
599 public char getGapCharacter()
601 return alignment.getGapCharacter();
604 protected String sequenceSetID;
607 * probably unused indicator that view is of a dataset rather than an
610 protected boolean isDataset = false;
612 public void setDataset(boolean b)
617 public boolean isDataset()
622 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
624 protected ColumnSelection colSel = new ColumnSelection();
626 public boolean autoCalculateConsensus = true;
628 protected boolean autoCalculateStrucConsensus = true;
630 protected boolean ignoreGapsInConsensusCalculation = false;
632 protected ResidueShaderI residueShading = new ResidueShader();
635 public void setGlobalColourScheme(ColourSchemeI cs)
637 // TODO: logic refactored from AlignFrame changeColour -
638 // TODO: autorecalc stuff should be changed to rely on the worker system
639 // check to see if we should implement a changeColour(cs) method rather than
640 // put the logic in here
641 // - means that caller decides if they want to just modify state and defer
642 // calculation till later or to do all calculations in thread.
646 * only instantiate alignment colouring once, thereafter update it;
647 * this means that any conservation or PID threshold settings
648 * persist when the alignment colour scheme is changed
650 if (residueShading == null)
652 residueShading = new ResidueShader(viewStyle);
654 residueShading.setColourScheme(cs);
656 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
657 // ...problem: groups need these, but do not currently have a ViewStyle
661 if (getConservationSelected())
663 residueShading.setConservation(hconservation);
666 * reset conservation flag in case just set to false if
667 * Conservation was null (calculation still in progress)
669 residueShading.setConservationApplied(getConservationSelected());
670 residueShading.alignmentChanged(alignment, hiddenRepSequences);
674 * if 'apply colour to all groups' is selected... do so
675 * (but don't transfer any colour threshold settings to groups)
677 if (getColourAppliesToAllGroups())
679 for (SequenceGroup sg : getAlignment().getGroups())
682 * retain any colour thresholds per group while
683 * changing choice of colour scheme (JAL-2386)
686 cs == null ? null : cs.getInstance(this, sg));
689 sg.getGroupColourScheme().alignmentChanged(sg,
697 public ColourSchemeI getGlobalColourScheme()
699 return residueShading == null ? null : residueShading.getColourScheme();
703 public ResidueShaderI getResidueShading()
705 return residueShading;
708 protected AlignmentAnnotation consensus;
710 protected AlignmentAnnotation complementConsensus;
712 protected AlignmentAnnotation gapcounts;
714 protected AlignmentAnnotation strucConsensus;
716 protected AlignmentAnnotation conservation;
718 protected AlignmentAnnotation quality;
720 protected AlignmentAnnotation[] groupConsensus;
722 protected AlignmentAnnotation[] groupConservation;
725 * results of alignment consensus analysis for visible portion of view
727 protected ProfilesI hconsensus = null;
730 * results of cDNA complement consensus visible portion of view
732 protected Hashtable[] hcomplementConsensus = null;
735 * results of secondary structure base pair consensus for visible portion of
738 protected Hashtable[] hStrucConsensus = null;
740 protected Conservation hconservation = null;
743 public void setConservation(Conservation cons)
745 hconservation = cons;
749 * percentage gaps allowed in a column before all amino acid properties should
750 * be considered unconserved
752 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
755 public int getConsPercGaps()
761 public void setSequenceConsensusHash(ProfilesI hconsensus)
763 this.hconsensus = hconsensus;
767 public void setComplementConsensusHash(Hashtable[] hconsensus)
769 this.hcomplementConsensus = hconsensus;
773 public ProfilesI getSequenceConsensusHash()
779 public Hashtable[] getComplementConsensusHash()
781 return hcomplementConsensus;
785 public Hashtable[] getRnaStructureConsensusHash()
787 return hStrucConsensus;
791 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
793 this.hStrucConsensus = hStrucConsensus;
798 public AlignmentAnnotation getAlignmentQualityAnnot()
804 public AlignmentAnnotation getAlignmentConservationAnnotation()
810 public AlignmentAnnotation getAlignmentConsensusAnnotation()
816 public AlignmentAnnotation getAlignmentGapAnnotation()
822 public AlignmentAnnotation getComplementConsensusAnnotation()
824 return complementConsensus;
828 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
830 return strucConsensus;
833 protected AlignCalcManagerI calculator = new AlignCalcManager();
836 * trigger update of conservation annotation
838 public void updateConservation(final AlignmentViewPanel ap)
840 // see note in mantis : issue number 8585
841 if (alignment.isNucleotide()
842 || (conservation == null && quality == null)
843 || !autoCalculateConsensus)
847 if (calculator.getRegisteredWorkersOfClass(
848 jalview.workers.ConservationThread.class) == null)
850 calculator.registerWorker(
851 new jalview.workers.ConservationThread(this, ap));
856 * trigger update of consensus annotation
858 public void updateConsensus(final AlignmentViewPanel ap)
860 // see note in mantis : issue number 8585
861 if (consensus == null || !autoCalculateConsensus)
866 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
868 calculator.registerWorker(new ConsensusThread(this, ap));
872 * A separate thread to compute cDNA consensus for a protein alignment
873 * which has mapping to cDNA
875 final AlignmentI al = this.getAlignment();
876 if (!al.isNucleotide() && al.getCodonFrames() != null
877 && !al.getCodonFrames().isEmpty())
880 * fudge - check first for protein-to-nucleotide mappings
881 * (we don't want to do this for protein-to-protein)
883 boolean doConsensus = false;
884 for (AlignedCodonFrame mapping : al.getCodonFrames())
886 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
887 MapList[] mapLists = mapping.getdnaToProt();
888 // mapLists can be empty if project load has not finished resolving seqs
889 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
897 if (calculator.getRegisteredWorkersOfClass(
898 ComplementConsensusThread.class) == null)
901 .registerWorker(new ComplementConsensusThread(this, ap));
907 // --------START Structure Conservation
908 public void updateStrucConsensus(final AlignmentViewPanel ap)
910 if (autoCalculateStrucConsensus && strucConsensus == null
911 && alignment.isNucleotide() && alignment.hasRNAStructure())
913 // secondary structure has been added - so init the consensus line
917 // see note in mantis : issue number 8585
918 if (strucConsensus == null || !autoCalculateStrucConsensus)
922 if (calculator.getRegisteredWorkersOfClass(
923 StrucConsensusThread.class) == null)
925 calculator.registerWorker(new StrucConsensusThread(this, ap));
929 public boolean isCalcInProgress()
931 return calculator.isWorking();
935 public boolean isCalculationInProgress(
936 AlignmentAnnotation alignmentAnnotation)
938 if (!alignmentAnnotation.autoCalculated)
942 if (calculator.workingInvolvedWith(alignmentAnnotation))
944 // System.err.println("grey out ("+alignmentAnnotation.label+")");
950 public void setAlignment(AlignmentI align)
952 this.alignment = align;
956 * Clean up references when this viewport is closed
959 public void dispose()
962 * defensively null out references to large objects in case
963 * this object is not garbage collected (as if!)
966 complementConsensus = null;
967 strucConsensus = null;
970 groupConsensus = null;
971 groupConservation = null;
973 hconservation = null;
974 hcomplementConsensus = null;
977 residueShading = null; // may hold a reference to Consensus
978 changeSupport = null;
981 selectionGroup = null;
987 public boolean isClosed()
989 // TODO: check that this isClosed is only true after panel is closed, not
990 // before it is fully constructed.
991 return alignment == null;
995 public AlignCalcManagerI getCalcManager()
1001 * should conservation rows be shown for groups
1003 protected boolean showGroupConservation = false;
1006 * should consensus rows be shown for groups
1008 protected boolean showGroupConsensus = false;
1011 * should consensus profile be rendered by default
1013 protected boolean showSequenceLogo = false;
1016 * should consensus profile be rendered normalised to row height
1018 protected boolean normaliseSequenceLogo = false;
1021 * should consensus histograms be rendered by default
1023 protected boolean showConsensusHistogram = true;
1026 * @return the showConsensusProfile
1029 public boolean isShowSequenceLogo()
1031 return showSequenceLogo;
1035 * @param showSequenceLogo
1038 public void setShowSequenceLogo(boolean showSequenceLogo)
1040 if (showSequenceLogo != this.showSequenceLogo)
1042 // TODO: decouple settings setting from calculation when refactoring
1043 // annotation update method from alignframe to viewport
1044 this.showSequenceLogo = showSequenceLogo;
1045 calculator.updateAnnotationFor(ConsensusThread.class);
1046 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1047 calculator.updateAnnotationFor(StrucConsensusThread.class);
1049 this.showSequenceLogo = showSequenceLogo;
1053 * @param showConsensusHistogram
1054 * the showConsensusHistogram to set
1056 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1058 this.showConsensusHistogram = showConsensusHistogram;
1062 * @return the showGroupConservation
1064 public boolean isShowGroupConservation()
1066 return showGroupConservation;
1070 * @param showGroupConservation
1071 * the showGroupConservation to set
1073 public void setShowGroupConservation(boolean showGroupConservation)
1075 this.showGroupConservation = showGroupConservation;
1079 * @return the showGroupConsensus
1081 public boolean isShowGroupConsensus()
1083 return showGroupConsensus;
1087 * @param showGroupConsensus
1088 * the showGroupConsensus to set
1090 public void setShowGroupConsensus(boolean showGroupConsensus)
1092 this.showGroupConsensus = showGroupConsensus;
1097 * @return flag to indicate if the consensus histogram should be rendered by
1101 public boolean isShowConsensusHistogram()
1103 return this.showConsensusHistogram;
1107 * when set, updateAlignment will always ensure sequences are of equal length
1109 private boolean padGaps = false;
1112 * when set, alignment should be reordered according to a newly opened tree
1114 public boolean sortByTree = false;
1119 * @return null or the currently selected sequence region
1122 public SequenceGroup getSelectionGroup()
1124 return selectionGroup;
1128 * Set the selection group for this window. Also sets the current alignment as
1129 * the context for the group, if it does not already have one.
1132 * - group holding references to sequences in this alignment view
1136 public void setSelectionGroup(SequenceGroup sg)
1138 selectionGroup = sg;
1139 if (sg != null && sg.getContext() == null)
1141 sg.setContext(alignment);
1145 public void setHiddenColumns(HiddenColumns hidden)
1147 this.alignment.setHiddenColumns(hidden);
1151 public ColumnSelection getColumnSelection()
1157 public void setColumnSelection(ColumnSelection colSel)
1159 this.colSel = colSel;
1162 updateHiddenColumns();
1164 isColSelChanged(true);
1172 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1174 return hiddenRepSequences;
1178 public void setHiddenRepSequences(
1179 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1181 this.hiddenRepSequences = hiddenRepSequences;
1185 public boolean hasSelectedColumns()
1187 ColumnSelection columnSelection = getColumnSelection();
1188 return columnSelection != null && columnSelection.hasSelectedColumns();
1192 public boolean hasHiddenColumns()
1194 return alignment.getHiddenColumns() != null
1195 && alignment.getHiddenColumns().hasHiddenColumns();
1198 public void updateHiddenColumns()
1200 // this method doesn't really do anything now. But - it could, since a
1201 // column Selection could be in the process of modification
1202 // hasHiddenColumns = colSel.hasHiddenColumns();
1206 public boolean hasHiddenRows()
1208 return alignment.getHiddenSequences().getSize() > 0;
1211 protected SequenceGroup selectionGroup;
1213 public void setSequenceSetId(String newid)
1215 if (sequenceSetID != null)
1218 "Warning - overwriting a sequenceSetId for a viewport!");
1220 sequenceSetID = new String(newid);
1224 public String getSequenceSetId()
1226 if (sequenceSetID == null)
1228 sequenceSetID = alignment.hashCode() + "";
1231 return sequenceSetID;
1235 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1238 protected String viewId = null;
1241 public String getViewId()
1245 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1250 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1252 ignoreGapsInConsensusCalculation = b;
1255 updateConsensus(ap);
1256 if (residueShading != null)
1258 residueShading.setThreshold(residueShading.getThreshold(),
1259 ignoreGapsInConsensusCalculation);
1265 private long sgrouphash = -1, colselhash = -1;
1268 * checks current SelectionGroup against record of last hash value, and
1272 * update the record of last hash value
1274 * @return true if SelectionGroup changed since last call (when b is true)
1276 public boolean isSelectionGroupChanged(boolean b)
1278 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1279 : selectionGroup.hashCode();
1280 if (hc != -1 && hc != sgrouphash)
1292 * checks current colsel against record of last hash value, and optionally
1296 * update the record of last hash value
1297 * @return true if colsel changed since last call (when b is true)
1299 public boolean isColSelChanged(boolean b)
1301 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1302 if (hc != -1 && hc != colselhash)
1314 public boolean isIgnoreGapsConsensus()
1316 return ignoreGapsInConsensusCalculation;
1319 // property change stuff
1320 // JBPNote Prolly only need this in the applet version.
1321 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1324 protected boolean showConservation = true;
1326 protected boolean showQuality = true;
1328 protected boolean showConsensus = true;
1330 protected boolean showOccupancy = true;
1332 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1334 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1336 protected boolean showAutocalculatedAbove;
1339 * when set, view will scroll to show the highlighted position
1341 private boolean followHighlight = true;
1344 * Property change listener for changes in alignment
1349 public void addPropertyChangeListener(
1350 java.beans.PropertyChangeListener listener)
1352 changeSupport.addPropertyChangeListener(listener);
1361 public void removePropertyChangeListener(
1362 java.beans.PropertyChangeListener listener)
1364 if (changeSupport != null)
1366 changeSupport.removePropertyChangeListener(listener);
1371 * Property change listener for changes in alignment
1380 public void firePropertyChange(String prop, Object oldvalue,
1383 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1386 // common hide/show column stuff
1388 public void hideSelectedColumns()
1390 if (colSel.isEmpty())
1395 colSel.hideSelectedColumns(alignment);
1396 setSelectionGroup(null);
1397 isColSelChanged(true);
1400 public void hideColumns(int start, int end)
1404 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1408 alignment.getHiddenColumns().hideColumns(start, end);
1410 isColSelChanged(true);
1413 public void showColumn(int col)
1415 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1416 isColSelChanged(true);
1419 public void showAllHiddenColumns()
1421 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1422 isColSelChanged(true);
1425 // common hide/show seq stuff
1426 public void showAllHiddenSeqs()
1428 int startSeq = ranges.getStartSeq();
1429 int endSeq = ranges.getEndSeq();
1431 if (alignment.getHiddenSequences().getSize() > 0)
1433 if (selectionGroup == null)
1435 selectionGroup = new SequenceGroup();
1436 selectionGroup.setEndRes(alignment.getWidth() - 1);
1438 List<SequenceI> tmp = alignment.getHiddenSequences()
1439 .showAll(hiddenRepSequences);
1440 for (SequenceI seq : tmp)
1442 selectionGroup.addSequence(seq, false);
1443 setSequenceAnnotationsVisible(seq, true);
1446 hiddenRepSequences = null;
1448 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1450 firePropertyChange("alignment", null, alignment.getSequences());
1451 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1457 public void showSequence(int index)
1459 int startSeq = ranges.getStartSeq();
1460 int endSeq = ranges.getEndSeq();
1462 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1463 hiddenRepSequences);
1466 if (selectionGroup == null)
1468 selectionGroup = new SequenceGroup();
1469 selectionGroup.setEndRes(alignment.getWidth() - 1);
1472 for (SequenceI seq : tmp)
1474 selectionGroup.addSequence(seq, false);
1475 setSequenceAnnotationsVisible(seq, true);
1478 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1480 firePropertyChange("alignment", null, alignment.getSequences());
1485 public void hideAllSelectedSeqs()
1487 if (selectionGroup == null || selectionGroup.getSize() < 1)
1492 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1496 setSelectionGroup(null);
1499 public void hideSequence(SequenceI[] seq)
1502 * cache offset to first visible sequence
1504 int startSeq = ranges.getStartSeq();
1508 for (int i = 0; i < seq.length; i++)
1510 alignment.getHiddenSequences().hideSequence(seq[i]);
1511 setSequenceAnnotationsVisible(seq[i], false);
1513 ranges.setStartSeq(startSeq);
1514 firePropertyChange("alignment", null, alignment.getSequences());
1519 * Hides the specified sequence, or the sequences it represents
1522 * the sequence to hide, or keep as representative
1523 * @param representGroup
1524 * if true, hide the current selection group except for the
1525 * representative sequence
1527 public void hideSequences(SequenceI sequence, boolean representGroup)
1529 if (selectionGroup == null || selectionGroup.getSize() < 1)
1531 hideSequence(new SequenceI[] { sequence });
1537 hideRepSequences(sequence, selectionGroup);
1538 setSelectionGroup(null);
1542 int gsize = selectionGroup.getSize();
1543 SequenceI[] hseqs = selectionGroup.getSequences()
1544 .toArray(new SequenceI[gsize]);
1546 hideSequence(hseqs);
1547 setSelectionGroup(null);
1552 * Set visibility for any annotations for the given sequence.
1556 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1559 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1562 for (AlignmentAnnotation ann : anns)
1564 if (ann.sequenceRef == sequenceI)
1566 ann.visible = visible;
1572 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1574 int sSize = sg.getSize();
1580 if (hiddenRepSequences == null)
1582 hiddenRepSequences = new Hashtable<>();
1585 hiddenRepSequences.put(repSequence, sg);
1587 // Hide all sequences except the repSequence
1588 SequenceI[] seqs = new SequenceI[sSize - 1];
1590 for (int i = 0; i < sSize; i++)
1592 if (sg.getSequenceAt(i) != repSequence)
1594 if (index == sSize - 1)
1599 seqs[index++] = sg.getSequenceAt(i);
1602 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1603 sg.setHidereps(true); // note: not done in 2.7applet
1610 * @return null or the current reference sequence
1612 public SequenceI getReferenceSeq()
1614 return alignment.getSeqrep();
1619 * @return true iff seq is the reference for the alignment
1621 public boolean isReferenceSeq(SequenceI seq)
1623 return alignment.getSeqrep() == seq;
1629 * @return true if there are sequences represented by this sequence that are
1632 public boolean isHiddenRepSequence(SequenceI seq)
1634 return (hiddenRepSequences != null
1635 && hiddenRepSequences.containsKey(seq));
1641 * @return null or a sequence group containing the sequences that seq
1644 public SequenceGroup getRepresentedSequences(SequenceI seq)
1646 return (SequenceGroup) (hiddenRepSequences == null ? null
1647 : hiddenRepSequences.get(seq));
1651 public int adjustForHiddenSeqs(int alignmentIndex)
1653 return alignment.getHiddenSequences()
1654 .adjustForHiddenSeqs(alignmentIndex);
1658 public void invertColumnSelection()
1660 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1661 isColSelChanged(true);
1665 public SequenceI[] getSelectionAsNewSequence()
1667 SequenceI[] sequences;
1668 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1669 // this was the only caller in the applet for this method
1670 // JBPNote: in applet, this method returned references to the alignment
1671 // sequences, and it did not honour the presence/absence of annotation
1672 // attached to the alignment (probably!)
1673 if (selectionGroup == null || selectionGroup.getSize() == 0)
1675 sequences = alignment.getSequencesArray();
1676 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1677 for (int i = 0; i < sequences.length; i++)
1679 // construct new sequence with subset of visible annotation
1680 sequences[i] = new Sequence(sequences[i], annots);
1685 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1692 public SequenceI[] getSequenceSelection()
1694 SequenceI[] sequences = null;
1695 if (selectionGroup != null)
1697 sequences = selectionGroup.getSequencesInOrder(alignment);
1699 if (sequences == null)
1701 sequences = alignment.getSequencesArray();
1707 public jalview.datamodel.AlignmentView getAlignmentView(
1708 boolean selectedOnly)
1710 return getAlignmentView(selectedOnly, false);
1714 public jalview.datamodel.AlignmentView getAlignmentView(
1715 boolean selectedOnly, boolean markGroups)
1717 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1719 alignment.getHiddenColumns() != null
1720 && alignment.getHiddenColumns().hasHiddenColumns(),
1721 selectedOnly, markGroups);
1725 public String[] getViewAsString(boolean selectedRegionOnly)
1727 return getViewAsString(selectedRegionOnly, true);
1731 public String[] getViewAsString(boolean selectedRegionOnly,
1732 boolean exportHiddenSeqs)
1734 String[] selection = null;
1735 SequenceI[] seqs = null;
1737 int start = 0, end = 0;
1738 if (selectedRegionOnly && selectionGroup != null)
1740 iSize = selectionGroup.getSize();
1741 seqs = selectionGroup.getSequencesInOrder(alignment);
1742 start = selectionGroup.getStartRes();
1743 end = selectionGroup.getEndRes() + 1;
1747 if (hasHiddenRows() && exportHiddenSeqs)
1749 AlignmentI fullAlignment = alignment.getHiddenSequences()
1750 .getFullAlignment();
1751 iSize = fullAlignment.getHeight();
1752 seqs = fullAlignment.getSequencesArray();
1753 end = fullAlignment.getWidth();
1757 iSize = alignment.getHeight();
1758 seqs = alignment.getSequencesArray();
1759 end = alignment.getWidth();
1763 selection = new String[iSize];
1764 if (alignment.getHiddenColumns() != null
1765 && alignment.getHiddenColumns().hasHiddenColumns())
1767 for (i = 0; i < iSize; i++)
1769 Iterator<int[]> blocks = alignment.getHiddenColumns()
1770 .getVisContigsIterator(start, end + 1, false);
1771 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1776 for (i = 0; i < iSize; i++)
1778 selection[i] = seqs[i].getSequenceAsString(start, end);
1786 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1788 ArrayList<int[]> regions = new ArrayList<>();
1794 HiddenColumns hidden = alignment.getHiddenColumns();
1795 if (hidden != null && hidden.hasHiddenColumns())
1799 start = hidden.visibleToAbsoluteColumn(start);
1802 end = hidden.getNextHiddenBoundary(false, start);
1813 regions.add(new int[] { start, end });
1815 if (hidden != null && hidden.hasHiddenColumns())
1817 start = hidden.visibleToAbsoluteColumn(end);
1818 start = hidden.getNextHiddenBoundary(true, start) + 1;
1820 } while (end < max);
1822 int[][] startEnd = new int[regions.size()][2];
1828 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1829 boolean selectedOnly)
1831 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1832 AlignmentAnnotation[] aa;
1833 if ((aa = alignment.getAlignmentAnnotation()) != null)
1835 for (AlignmentAnnotation annot : aa)
1837 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1838 if (selectedOnly && selectionGroup != null)
1840 clone.makeVisibleAnnotation(
1841 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1842 alignment.getHiddenColumns());
1846 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1855 public boolean isPadGaps()
1861 public void setPadGaps(boolean padGaps)
1863 this.padGaps = padGaps;
1867 * apply any post-edit constraints and trigger any calculations needed after
1868 * an edit has been performed on the alignment
1873 public void alignmentChanged(AlignmentViewPanel ap)
1877 alignment.padGaps();
1879 if (autoCalculateConsensus)
1881 updateConsensus(ap);
1883 if (hconsensus != null && autoCalculateConsensus)
1885 updateConservation(ap);
1887 if (autoCalculateStrucConsensus)
1889 updateStrucConsensus(ap);
1892 // Reset endRes of groups if beyond alignment width
1893 int alWidth = alignment.getWidth();
1894 List<SequenceGroup> groups = alignment.getGroups();
1897 for (SequenceGroup sg : groups)
1899 if (sg.getEndRes() > alWidth)
1901 sg.setEndRes(alWidth - 1);
1906 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1908 selectionGroup.setEndRes(alWidth - 1);
1911 updateAllColourSchemes();
1912 calculator.restartWorkers();
1913 // alignment.adjustSequenceAnnotations();
1917 * reset scope and do calculations for all applied colourschemes on alignment
1919 void updateAllColourSchemes()
1921 ResidueShaderI rs = residueShading;
1924 rs.alignmentChanged(alignment, hiddenRepSequences);
1926 rs.setConsensus(hconsensus);
1927 if (rs.conservationApplied())
1929 rs.setConservation(Conservation.calculateConservation("All",
1930 alignment.getSequences(), 0, alignment.getWidth(), false,
1931 getConsPercGaps(), false));
1935 for (SequenceGroup sg : alignment.getGroups())
1939 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1941 sg.recalcConservation();
1945 protected void initAutoAnnotation()
1947 // TODO: add menu option action that nulls or creates consensus object
1948 // depending on if the user wants to see the annotation or not in a
1949 // specific alignment
1951 if (hconsensus == null && !isDataset)
1953 if (!alignment.isNucleotide())
1962 consensus = new AlignmentAnnotation("Consensus",
1963 MessageManager.getString("label.consensus_descr"),
1964 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1965 initConsensus(consensus);
1968 initComplementConsensus();
1973 * If this is a protein alignment and there are mappings to cDNA, adds the
1974 * cDNA consensus annotation and returns true, else returns false.
1976 public boolean initComplementConsensus()
1978 if (!alignment.isNucleotide())
1980 final List<AlignedCodonFrame> codonMappings = alignment
1982 if (codonMappings != null && !codonMappings.isEmpty())
1984 boolean doConsensus = false;
1985 for (AlignedCodonFrame mapping : codonMappings)
1987 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1988 MapList[] mapLists = mapping.getdnaToProt();
1989 // mapLists can be empty if project load has not finished resolving
1991 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1999 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2001 .getString("label.complement_consensus_descr"),
2002 new Annotation[1], 0f, 100f,
2003 AlignmentAnnotation.BAR_GRAPH);
2004 initConsensus(complementConsensus);
2012 private void initConsensus(AlignmentAnnotation aa)
2015 aa.autoCalculated = true;
2019 alignment.addAnnotation(aa);
2023 // these should be extracted from the view model - style and settings for
2024 // derived annotation
2025 private void initGapCounts()
2029 gapcounts = new AlignmentAnnotation("Occupancy",
2030 MessageManager.getString("label.occupancy_descr"),
2031 new Annotation[1], 0f, alignment.getHeight(),
2032 AlignmentAnnotation.BAR_GRAPH);
2033 gapcounts.hasText = true;
2034 gapcounts.autoCalculated = true;
2035 gapcounts.scaleColLabel = true;
2036 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2038 alignment.addAnnotation(gapcounts);
2042 private void initConservation()
2044 if (showConservation)
2046 if (conservation == null)
2048 conservation = new AlignmentAnnotation("Conservation",
2049 MessageManager.formatMessage("label.conservation_descr",
2051 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2052 conservation.hasText = true;
2053 conservation.autoCalculated = true;
2054 alignment.addAnnotation(conservation);
2059 private void initQuality()
2063 if (quality == null)
2065 quality = new AlignmentAnnotation("Quality",
2066 MessageManager.getString("label.quality_descr"),
2067 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2068 quality.hasText = true;
2069 quality.autoCalculated = true;
2070 alignment.addAnnotation(quality);
2075 private void initRNAStructure()
2077 if (alignment.hasRNAStructure() && strucConsensus == null)
2079 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2080 MessageManager.getString("label.strucconsensus_descr"),
2081 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2082 strucConsensus.hasText = true;
2083 strucConsensus.autoCalculated = true;
2087 alignment.addAnnotation(strucConsensus);
2095 * @see jalview.api.AlignViewportI#calcPanelHeight()
2098 public int calcPanelHeight()
2100 // setHeight of panels
2101 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2103 int charHeight = getCharHeight();
2106 BitSet graphgrp = new BitSet();
2107 for (AlignmentAnnotation aa : anns)
2111 System.err.println("Null annotation row: ignoring.");
2118 if (aa.graphGroup > -1)
2120 if (graphgrp.get(aa.graphGroup))
2126 graphgrp.set(aa.graphGroup);
2133 aa.height += charHeight;
2143 aa.height += aa.graphHeight;
2151 height += aa.height;
2163 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2164 boolean preserveNewGroupSettings)
2166 boolean updateCalcs = false;
2167 boolean conv = isShowGroupConservation();
2168 boolean cons = isShowGroupConsensus();
2169 boolean showprf = isShowSequenceLogo();
2170 boolean showConsHist = isShowConsensusHistogram();
2171 boolean normLogo = isNormaliseSequenceLogo();
2174 * TODO reorder the annotation rows according to group/sequence ordering on
2177 boolean sortg = true;
2179 // remove old automatic annotation
2180 // add any new annotation
2182 // intersect alignment annotation with alignment groups
2184 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2185 List<SequenceGroup> oldrfs = new ArrayList<>();
2188 for (int an = 0; an < aan.length; an++)
2190 if (aan[an].autoCalculated && aan[an].groupRef != null)
2192 oldrfs.add(aan[an].groupRef);
2193 alignment.deleteAnnotation(aan[an], false);
2197 if (alignment.getGroups() != null)
2199 for (SequenceGroup sg : alignment.getGroups())
2201 updateCalcs = false;
2202 if (applyGlobalSettings
2203 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2205 // set defaults for this group's conservation/consensus
2206 sg.setshowSequenceLogo(showprf);
2207 sg.setShowConsensusHistogram(showConsHist);
2208 sg.setNormaliseSequenceLogo(normLogo);
2213 alignment.addAnnotation(sg.getConservationRow(), 0);
2218 alignment.addAnnotation(sg.getConsensus(), 0);
2220 // refresh the annotation rows
2223 sg.recalcConservation();
2231 public boolean isDisplayReferenceSeq()
2233 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2237 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2239 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2243 public boolean isColourByReferenceSeq()
2245 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2249 public Color getSequenceColour(SequenceI seq)
2251 Color sqc = sequenceColours.get(seq);
2252 return (sqc == null ? Color.white : sqc);
2256 public void setSequenceColour(SequenceI seq, Color col)
2260 sequenceColours.remove(seq);
2264 sequenceColours.put(seq, col);
2269 public void updateSequenceIdColours()
2271 for (SequenceGroup sg : alignment.getGroups())
2273 if (sg.idColour != null)
2275 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2277 sequenceColours.put(s, sg.idColour);
2284 public void clearSequenceColours()
2286 sequenceColours.clear();
2290 public AlignViewportI getCodingComplement()
2292 return this.codingComplement;
2296 * Set this as the (cDna/protein) complement of the given viewport. Also
2297 * ensures the reverse relationship is set on the given viewport.
2300 public void setCodingComplement(AlignViewportI av)
2304 System.err.println("Ignoring recursive setCodingComplement request");
2308 this.codingComplement = av;
2309 // avoid infinite recursion!
2310 if (av.getCodingComplement() != this)
2312 av.setCodingComplement(this);
2318 public boolean isNucleotide()
2320 return getAlignment() == null ? false : getAlignment().isNucleotide();
2324 public FeaturesDisplayedI getFeaturesDisplayed()
2326 return featuresDisplayed;
2330 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2332 featuresDisplayed = featuresDisplayedI;
2336 public boolean areFeaturesDisplayed()
2338 return featuresDisplayed != null
2339 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2346 * features are displayed if true
2349 public void setShowSequenceFeatures(boolean b)
2351 viewStyle.setShowSequenceFeatures(b);
2355 public boolean isShowSequenceFeatures()
2357 return viewStyle.isShowSequenceFeatures();
2361 public void setShowSequenceFeaturesHeight(boolean selected)
2363 viewStyle.setShowSequenceFeaturesHeight(selected);
2367 public boolean isShowSequenceFeaturesHeight()
2369 return viewStyle.isShowSequenceFeaturesHeight();
2373 public void setShowAnnotation(boolean b)
2375 viewStyle.setShowAnnotation(b);
2379 public boolean isShowAnnotation()
2381 return viewStyle.isShowAnnotation();
2385 public boolean isRightAlignIds()
2387 return viewStyle.isRightAlignIds();
2391 public void setRightAlignIds(boolean rightAlignIds)
2393 viewStyle.setRightAlignIds(rightAlignIds);
2397 public boolean getConservationSelected()
2399 return viewStyle.getConservationSelected();
2403 public void setShowBoxes(boolean state)
2405 viewStyle.setShowBoxes(state);
2410 * @see jalview.api.ViewStyleI#getTextColour()
2413 public Color getTextColour()
2415 return viewStyle.getTextColour();
2420 * @see jalview.api.ViewStyleI#getTextColour2()
2423 public Color getTextColour2()
2425 return viewStyle.getTextColour2();
2430 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2433 public int getThresholdTextColour()
2435 return viewStyle.getThresholdTextColour();
2440 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2443 public boolean isConservationColourSelected()
2445 return viewStyle.isConservationColourSelected();
2450 * @see jalview.api.ViewStyleI#isRenderGaps()
2453 public boolean isRenderGaps()
2455 return viewStyle.isRenderGaps();
2460 * @see jalview.api.ViewStyleI#isShowColourText()
2463 public boolean isShowColourText()
2465 return viewStyle.isShowColourText();
2469 * @param conservationColourSelected
2470 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2473 public void setConservationColourSelected(
2474 boolean conservationColourSelected)
2476 viewStyle.setConservationColourSelected(conservationColourSelected);
2480 * @param showColourText
2481 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2484 public void setShowColourText(boolean showColourText)
2486 viewStyle.setShowColourText(showColourText);
2491 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2494 public void setTextColour(Color textColour)
2496 viewStyle.setTextColour(textColour);
2500 * @param thresholdTextColour
2501 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2504 public void setThresholdTextColour(int thresholdTextColour)
2506 viewStyle.setThresholdTextColour(thresholdTextColour);
2510 * @param textColour2
2511 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2514 public void setTextColour2(Color textColour2)
2516 viewStyle.setTextColour2(textColour2);
2520 public ViewStyleI getViewStyle()
2522 return new ViewStyle(viewStyle);
2526 public void setViewStyle(ViewStyleI settingsForView)
2528 viewStyle = new ViewStyle(settingsForView);
2529 if (residueShading != null)
2531 residueShading.setConservationApplied(
2532 settingsForView.isConservationColourSelected());
2537 public boolean sameStyle(ViewStyleI them)
2539 return viewStyle.sameStyle(them);
2544 * @see jalview.api.ViewStyleI#getIdWidth()
2547 public int getIdWidth()
2549 return viewStyle.getIdWidth();
2554 * @see jalview.api.ViewStyleI#setIdWidth(int)
2557 public void setIdWidth(int i)
2559 viewStyle.setIdWidth(i);
2564 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2567 public boolean isCentreColumnLabels()
2569 return viewStyle.isCentreColumnLabels();
2573 * @param centreColumnLabels
2574 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2577 public void setCentreColumnLabels(boolean centreColumnLabels)
2579 viewStyle.setCentreColumnLabels(centreColumnLabels);
2584 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2587 public void setShowDBRefs(boolean showdbrefs)
2589 viewStyle.setShowDBRefs(showdbrefs);
2594 * @see jalview.api.ViewStyleI#isShowDBRefs()
2597 public boolean isShowDBRefs()
2599 return viewStyle.isShowDBRefs();
2604 * @see jalview.api.ViewStyleI#isShowNPFeats()
2607 public boolean isShowNPFeats()
2609 return viewStyle.isShowNPFeats();
2613 * @param shownpfeats
2614 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2617 public void setShowNPFeats(boolean shownpfeats)
2619 viewStyle.setShowNPFeats(shownpfeats);
2622 public abstract StructureSelectionManager getStructureSelectionManager();
2625 * Add one command to the command history list.
2629 public void addToHistoryList(CommandI command)
2631 if (this.historyList != null)
2633 this.historyList.push(command);
2634 broadcastCommand(command, false);
2638 protected void broadcastCommand(CommandI command, boolean undo)
2640 getStructureSelectionManager().commandPerformed(command, undo,
2645 * Add one command to the command redo list.
2649 public void addToRedoList(CommandI command)
2651 if (this.redoList != null)
2653 this.redoList.push(command);
2655 broadcastCommand(command, true);
2659 * Clear the command redo list.
2661 public void clearRedoList()
2663 if (this.redoList != null)
2665 this.redoList.clear();
2669 public void setHistoryList(Deque<CommandI> list)
2671 this.historyList = list;
2674 public Deque<CommandI> getHistoryList()
2676 return this.historyList;
2679 public void setRedoList(Deque<CommandI> list)
2681 this.redoList = list;
2684 public Deque<CommandI> getRedoList()
2686 return this.redoList;
2690 public VamsasSource getVamsasSource()
2695 public SequenceAnnotationOrder getSortAnnotationsBy()
2697 return sortAnnotationsBy;
2700 public void setSortAnnotationsBy(
2701 SequenceAnnotationOrder sortAnnotationsBy)
2703 this.sortAnnotationsBy = sortAnnotationsBy;
2706 public boolean isShowAutocalculatedAbove()
2708 return showAutocalculatedAbove;
2711 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2713 this.showAutocalculatedAbove = showAutocalculatedAbove;
2717 public boolean isScaleProteinAsCdna()
2719 return viewStyle.isScaleProteinAsCdna();
2723 public void setScaleProteinAsCdna(boolean b)
2725 viewStyle.setScaleProteinAsCdna(b);
2729 public boolean isProteinFontAsCdna()
2731 return viewStyle.isProteinFontAsCdna();
2735 public void setProteinFontAsCdna(boolean b)
2737 viewStyle.setProteinFontAsCdna(b);
2741 public void setShowComplementFeatures(boolean b)
2743 viewStyle.setShowComplementFeatures(b);
2747 public boolean isShowComplementFeatures()
2749 return viewStyle.isShowComplementFeatures();
2753 public void setShowComplementFeaturesOnTop(boolean b)
2755 viewStyle.setShowComplementFeaturesOnTop(b);
2759 public boolean isShowComplementFeaturesOnTop()
2761 return viewStyle.isShowComplementFeaturesOnTop();
2765 * @return true if view should scroll to show the highlighted region of a
2770 public final boolean isFollowHighlight()
2772 return followHighlight;
2776 public final void setFollowHighlight(boolean b)
2778 this.followHighlight = b;
2782 public ViewportRanges getRanges()
2788 * Helper method to populate the SearchResults with the location in the
2789 * complementary alignment to scroll to, in order to match this one.
2792 * the SearchResults to add to
2793 * @return the offset (below top of visible region) of the matched sequence
2795 protected int findComplementScrollTarget(SearchResultsI sr)
2797 final AlignViewportI complement = getCodingComplement();
2798 if (complement == null || !complement.isFollowHighlight())
2802 boolean iAmProtein = !getAlignment().isNucleotide();
2803 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2804 : complement.getAlignment();
2805 if (proteinAlignment == null)
2809 final List<AlignedCodonFrame> mappings = proteinAlignment
2813 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2814 * residue in the middle column of the visible region. Scroll the
2815 * complementary alignment to line up the corresponding residue.
2818 SequenceI sequence = null;
2821 * locate 'middle' column (true middle if an odd number visible, left of
2822 * middle if an even number visible)
2824 int middleColumn = ranges.getStartRes()
2825 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2826 final HiddenSequences hiddenSequences = getAlignment()
2827 .getHiddenSequences();
2830 * searching to the bottom of the alignment gives smoother scrolling across
2831 * all gapped visible regions
2833 int lastSeq = alignment.getHeight() - 1;
2834 List<AlignedCodonFrame> seqMappings = null;
2835 for (int seqNo = ranges
2836 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2838 sequence = getAlignment().getSequenceAt(seqNo);
2839 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2843 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2847 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2849 getCodingComplement().getAlignment().getSequences());
2850 if (!seqMappings.isEmpty())
2856 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2859 * No ungapped mapped sequence in middle column - do nothing
2863 MappingUtils.addSearchResults(sr, sequence,
2864 sequence.findPosition(middleColumn), seqMappings);
2869 * synthesize a column selection if none exists so it covers the given
2870 * selection group. if wholewidth is false, no column selection is made if the
2871 * selection group covers the whole alignment width.
2876 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2879 if (sg != null && (sgs = sg.getStartRes()) >= 0
2880 && sg.getStartRes() <= (sge = sg.getEndRes())
2881 && !this.hasSelectedColumns())
2883 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2890 colSel = new ColumnSelection();
2892 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2894 colSel.addElement(cspos);
2900 * hold status of current selection group - defined on alignment or not.
2902 private boolean selectionIsDefinedGroup = false;
2905 public boolean isSelectionDefinedGroup()
2907 if (selectionGroup == null)
2911 if (isSelectionGroupChanged(true))
2913 selectionIsDefinedGroup = false;
2914 List<SequenceGroup> gps = alignment.getGroups();
2915 if (gps == null || gps.size() == 0)
2917 selectionIsDefinedGroup = false;
2921 selectionIsDefinedGroup = gps.contains(selectionGroup);
2924 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2928 * null, or currently highlighted results on this view
2930 private SearchResultsI searchResults = null;
2932 protected TreeModel currentTree = null;
2935 public boolean hasSearchResults()
2937 return searchResults != null;
2941 public void setSearchResults(SearchResultsI results)
2943 searchResults = results;
2947 public SearchResultsI getSearchResults()
2949 return searchResults;
2953 * get the consensus sequence as displayed under the PID consensus annotation
2956 * @return consensus sequence as a new sequence object
2958 public SequenceI getConsensusSeq()
2960 if (consensus == null)
2962 updateConsensus(null);
2964 if (consensus == null)
2968 StringBuffer seqs = new StringBuffer();
2969 for (int i = 0; i < consensus.annotations.length; i++)
2971 Annotation annotation = consensus.annotations[i];
2972 if (annotation != null)
2974 String description = annotation.description;
2975 if (description != null && description.startsWith("["))
2977 // consensus is a tie - just pick the first one
2978 seqs.append(description.charAt(1));
2982 seqs.append(annotation.displayCharacter);
2987 SequenceI sq = new Sequence("Consensus", seqs.toString());
2988 sq.setDescription("Percentage Identity Consensus "
2989 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
2994 public void setCurrentTree(TreeModel tree)
3000 public TreeModel getCurrentTree()
3006 * flag set to indicate if structure views might be out of sync with sequences
3010 private boolean needToUpdateStructureViews = false;
3013 public boolean isUpdateStructures()
3015 return needToUpdateStructureViews;
3019 public void setUpdateStructures(boolean update)
3021 needToUpdateStructureViews = update;
3025 public boolean needToUpdateStructureViews()
3027 boolean update = needToUpdateStructureViews;
3028 needToUpdateStructureViews = false;
3033 public void addSequenceGroup(SequenceGroup sequenceGroup)
3035 alignment.addGroup(sequenceGroup);
3037 Color col = sequenceGroup.idColour;
3040 col = col.brighter();
3042 for (SequenceI sq : sequenceGroup.getSequences())
3044 setSequenceColour(sq, col);
3048 if (codingComplement != null)
3050 SequenceGroup mappedGroup = MappingUtils
3051 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3052 if (mappedGroup.getSequences().size() > 0)
3054 codingComplement.getAlignment().addGroup(mappedGroup);
3058 for (SequenceI seq : mappedGroup.getSequences())
3060 codingComplement.setSequenceColour(seq, col);
3064 // propagate the structure view update flag according to our own setting
3065 codingComplement.setUpdateStructures(needToUpdateStructureViews);
3070 public Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly)
3074 if (selectedRegionOnly && selectionGroup != null)
3076 start = selectionGroup.getStartRes();
3077 end = selectionGroup.getEndRes() + 1;
3081 end = alignment.getWidth();
3083 return (alignment.getHiddenColumns().getVisContigsIterator(start, end,