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.AlignExportSettingsI;
28 import jalview.api.AlignViewportI;
29 import jalview.api.AlignmentViewPanel;
30 import jalview.api.FeaturesDisplayedI;
31 import jalview.api.ViewStyleI;
32 import jalview.commands.CommandI;
33 import jalview.datamodel.AlignedCodonFrame;
34 import jalview.datamodel.AlignmentAnnotation;
35 import jalview.datamodel.AlignmentExportData;
36 import jalview.datamodel.AlignmentI;
37 import jalview.datamodel.AlignmentView;
38 import jalview.datamodel.Annotation;
39 import jalview.datamodel.ColumnSelection;
40 import jalview.datamodel.HiddenColumns;
41 import jalview.datamodel.HiddenSequences;
42 import jalview.datamodel.ProfilesI;
43 import jalview.datamodel.SearchResultsI;
44 import jalview.datamodel.Sequence;
45 import jalview.datamodel.SequenceCollectionI;
46 import jalview.datamodel.SequenceGroup;
47 import jalview.datamodel.SequenceI;
48 import jalview.ext.treeviewer.TreeI;
49 import jalview.renderer.ResidueShader;
50 import jalview.renderer.ResidueShaderI;
51 import jalview.schemes.ColourSchemeI;
52 import jalview.structure.CommandListener;
53 import jalview.structure.StructureSelectionManager;
54 import jalview.structure.VamsasSource;
55 import jalview.util.Comparison;
56 import jalview.util.MapList;
57 import jalview.util.MappingUtils;
58 import jalview.util.MessageManager;
59 import jalview.viewmodel.styles.ViewStyle;
60 import jalview.workers.AlignCalcManager;
61 import jalview.workers.ComplementConsensusThread;
62 import jalview.workers.ConsensusThread;
63 import jalview.workers.StrucConsensusThread;
65 import java.awt.Color;
66 import java.beans.PropertyChangeSupport;
67 import java.util.ArrayDeque;
68 import java.util.ArrayList;
69 import java.util.BitSet;
70 import java.util.Deque;
71 import java.util.HashMap;
72 import java.util.Hashtable;
73 import java.util.Iterator;
74 import java.util.List;
78 * base class holding visualization and analysis attributes and common logic for
79 * an active alignment view displayed in the GUI
84 public abstract class AlignmentViewport
85 implements AlignViewportI, CommandListener, VamsasSource
87 protected ViewportRanges ranges;
89 protected ViewStyleI viewStyle = new ViewStyle();
92 * A viewport that hosts the cDna view of this (protein), or vice versa (if
95 AlignViewportI codingComplement = null;
97 FeaturesDisplayedI featuresDisplayed = null;
99 protected Deque<CommandI> historyList = new ArrayDeque<>();
101 protected Deque<CommandI> redoList = new ArrayDeque<>();
104 * alignment displayed in the viewport. Please use get/setter
106 protected AlignmentI alignment;
108 public AlignmentViewport(AlignmentI al)
111 ranges = new ViewportRanges(al);
116 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
119 public void setFontName(String name)
121 viewStyle.setFontName(name);
126 * @see jalview.api.ViewStyleI#setFontStyle(int)
129 public void setFontStyle(int style)
131 viewStyle.setFontStyle(style);
136 * @see jalview.api.ViewStyleI#setFontSize(int)
139 public void setFontSize(int size)
141 viewStyle.setFontSize(size);
146 * @see jalview.api.ViewStyleI#getFontStyle()
149 public int getFontStyle()
151 return viewStyle.getFontStyle();
156 * @see jalview.api.ViewStyleI#getFontName()
159 public String getFontName()
161 return viewStyle.getFontName();
166 * @see jalview.api.ViewStyleI#getFontSize()
169 public int getFontSize()
171 return viewStyle.getFontSize();
175 * @param upperCasebold
176 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
179 public void setUpperCasebold(boolean upperCasebold)
181 viewStyle.setUpperCasebold(upperCasebold);
186 * @see jalview.api.ViewStyleI#isUpperCasebold()
189 public boolean isUpperCasebold()
191 return viewStyle.isUpperCasebold();
196 * @see jalview.api.ViewStyleI#isSeqNameItalics()
199 public boolean isSeqNameItalics()
201 return viewStyle.isSeqNameItalics();
205 * @param colourByReferenceSeq
206 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
209 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
211 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
216 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
219 public void setColourAppliesToAllGroups(boolean b)
221 viewStyle.setColourAppliesToAllGroups(b);
226 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
229 public boolean getColourAppliesToAllGroups()
231 return viewStyle.getColourAppliesToAllGroups();
236 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
239 public boolean getAbovePIDThreshold()
241 return viewStyle.getAbovePIDThreshold();
246 * @see jalview.api.ViewStyleI#setIncrement(int)
249 public void setIncrement(int inc)
251 viewStyle.setIncrement(inc);
256 * @see jalview.api.ViewStyleI#getIncrement()
259 public int getIncrement()
261 return viewStyle.getIncrement();
266 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
269 public void setConservationSelected(boolean b)
271 viewStyle.setConservationSelected(b);
276 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
279 public void setShowHiddenMarkers(boolean show)
281 viewStyle.setShowHiddenMarkers(show);
286 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
289 public boolean getShowHiddenMarkers()
291 return viewStyle.getShowHiddenMarkers();
296 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
299 public void setScaleRightWrapped(boolean b)
301 viewStyle.setScaleRightWrapped(b);
306 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
309 public void setScaleLeftWrapped(boolean b)
311 viewStyle.setScaleLeftWrapped(b);
316 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
319 public void setScaleAboveWrapped(boolean b)
321 viewStyle.setScaleAboveWrapped(b);
326 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
329 public boolean getScaleLeftWrapped()
331 return viewStyle.getScaleLeftWrapped();
336 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
339 public boolean getScaleAboveWrapped()
341 return viewStyle.getScaleAboveWrapped();
346 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
349 public boolean getScaleRightWrapped()
351 return viewStyle.getScaleRightWrapped();
356 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
359 public void setAbovePIDThreshold(boolean b)
361 viewStyle.setAbovePIDThreshold(b);
366 * @see jalview.api.ViewStyleI#setThreshold(int)
369 public void setThreshold(int thresh)
371 viewStyle.setThreshold(thresh);
376 * @see jalview.api.ViewStyleI#getThreshold()
379 public int getThreshold()
381 return viewStyle.getThreshold();
386 * @see jalview.api.ViewStyleI#getShowJVSuffix()
389 public boolean getShowJVSuffix()
391 return viewStyle.getShowJVSuffix();
396 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
399 public void setShowJVSuffix(boolean b)
401 viewStyle.setShowJVSuffix(b);
406 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
409 public void setWrapAlignment(boolean state)
411 viewStyle.setWrapAlignment(state);
412 ranges.setWrappedMode(state);
417 * @see jalview.api.ViewStyleI#setShowText(boolean)
420 public void setShowText(boolean state)
422 viewStyle.setShowText(state);
427 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
430 public void setRenderGaps(boolean state)
432 viewStyle.setRenderGaps(state);
437 * @see jalview.api.ViewStyleI#getColourText()
440 public boolean getColourText()
442 return viewStyle.getColourText();
447 * @see jalview.api.ViewStyleI#setColourText(boolean)
450 public void setColourText(boolean state)
452 viewStyle.setColourText(state);
457 * @see jalview.api.ViewStyleI#getWrapAlignment()
460 public boolean getWrapAlignment()
462 return viewStyle.getWrapAlignment();
467 * @see jalview.api.ViewStyleI#getShowText()
470 public boolean getShowText()
472 return viewStyle.getShowText();
477 * @see jalview.api.ViewStyleI#getWrappedWidth()
480 public int getWrappedWidth()
482 return viewStyle.getWrappedWidth();
487 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
490 public void setWrappedWidth(int w)
492 viewStyle.setWrappedWidth(w);
497 * @see jalview.api.ViewStyleI#getCharHeight()
500 public int getCharHeight()
502 return viewStyle.getCharHeight();
507 * @see jalview.api.ViewStyleI#setCharHeight(int)
510 public void setCharHeight(int h)
512 viewStyle.setCharHeight(h);
517 * @see jalview.api.ViewStyleI#getCharWidth()
520 public int getCharWidth()
522 return viewStyle.getCharWidth();
527 * @see jalview.api.ViewStyleI#setCharWidth(int)
530 public void setCharWidth(int w)
532 viewStyle.setCharWidth(w);
537 * @see jalview.api.ViewStyleI#getShowBoxes()
540 public boolean getShowBoxes()
542 return viewStyle.getShowBoxes();
547 * @see jalview.api.ViewStyleI#getShowUnconserved()
550 public boolean getShowUnconserved()
552 return viewStyle.getShowUnconserved();
556 * @param showunconserved
557 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
560 public void setShowUnconserved(boolean showunconserved)
562 viewStyle.setShowUnconserved(showunconserved);
567 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
570 public void setSeqNameItalics(boolean default1)
572 viewStyle.setSeqNameItalics(default1);
576 public AlignmentI getAlignment()
582 public char getGapCharacter()
584 return alignment.getGapCharacter();
587 protected String sequenceSetID;
590 * probably unused indicator that view is of a dataset rather than an
593 protected boolean isDataset = false;
595 public void setDataset(boolean b)
600 public boolean isDataset()
605 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
607 protected ColumnSelection colSel = new ColumnSelection();
609 public boolean autoCalculateConsensus = true;
611 protected boolean autoCalculateStrucConsensus = true;
613 protected boolean ignoreGapsInConsensusCalculation = false;
615 protected ResidueShaderI residueShading = new ResidueShader();
618 public void setGlobalColourScheme(ColourSchemeI cs)
620 // TODO: logic refactored from AlignFrame changeColour -
621 // TODO: autorecalc stuff should be changed to rely on the worker system
622 // check to see if we should implement a changeColour(cs) method rather than
623 // put the logic in here
624 // - means that caller decides if they want to just modify state and defer
625 // calculation till later or to do all calculations in thread.
629 * only instantiate alignment colouring once, thereafter update it;
630 * this means that any conservation or PID threshold settings
631 * persist when the alignment colour scheme is changed
633 if (residueShading == null)
635 residueShading = new ResidueShader(viewStyle);
637 residueShading.setColourScheme(cs);
639 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
640 // ...problem: groups need these, but do not currently have a ViewStyle
644 if (getConservationSelected())
646 residueShading.setConservation(hconservation);
649 * reset conservation flag in case just set to false if
650 * Conservation was null (calculation still in progress)
652 residueShading.setConservationApplied(getConservationSelected());
653 residueShading.alignmentChanged(alignment, hiddenRepSequences);
657 * if 'apply colour to all groups' is selected... do so
658 * (but don't transfer any colour threshold settings to groups)
660 if (getColourAppliesToAllGroups())
662 for (SequenceGroup sg : getAlignment().getGroups())
665 * retain any colour thresholds per group while
666 * changing choice of colour scheme (JAL-2386)
668 sg.setColourScheme(cs == null ? null : cs.getInstance(this, sg));
671 sg.getGroupColourScheme().alignmentChanged(sg,
679 public ColourSchemeI getGlobalColourScheme()
681 return residueShading == null ? null : residueShading.getColourScheme();
685 public ResidueShaderI getResidueShading()
687 return residueShading;
690 protected AlignmentAnnotation consensus;
692 protected AlignmentAnnotation complementConsensus;
694 protected AlignmentAnnotation gapcounts;
696 protected AlignmentAnnotation strucConsensus;
698 protected AlignmentAnnotation conservation;
700 protected AlignmentAnnotation quality;
702 protected AlignmentAnnotation[] groupConsensus;
704 protected AlignmentAnnotation[] groupConservation;
707 * results of alignment consensus analysis for visible portion of view
709 protected ProfilesI hconsensus = null;
712 * results of cDNA complement consensus visible portion of view
714 protected Hashtable<String, Object>[] hcomplementConsensus = null;
717 * results of secondary structure base pair consensus for visible portion of
720 protected Hashtable<String, Object>[] hStrucConsensus = null;
722 protected Conservation hconservation = null;
725 public void setConservation(Conservation cons)
727 hconservation = cons;
731 * percentage gaps allowed in a column before all amino acid properties should
732 * be considered unconserved
734 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
737 public int getConsPercGaps()
743 public void setSequenceConsensusHash(ProfilesI hconsensus)
745 this.hconsensus = hconsensus;
749 public void setComplementConsensusHash(
750 Hashtable<String, Object>[] hconsensus)
752 this.hcomplementConsensus = hconsensus;
756 public ProfilesI getSequenceConsensusHash()
762 public Hashtable<String, Object>[] getComplementConsensusHash()
764 return hcomplementConsensus;
768 public Hashtable<String, Object>[] getRnaStructureConsensusHash()
770 return hStrucConsensus;
774 public void setRnaStructureConsensusHash(
775 Hashtable<String, Object>[] hStrucConsensus)
777 this.hStrucConsensus = hStrucConsensus;
782 public AlignmentAnnotation getAlignmentQualityAnnot()
788 public AlignmentAnnotation getAlignmentConservationAnnotation()
794 public AlignmentAnnotation getAlignmentConsensusAnnotation()
800 public AlignmentAnnotation getAlignmentGapAnnotation()
806 public AlignmentAnnotation getComplementConsensusAnnotation()
808 return complementConsensus;
812 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
814 return strucConsensus;
817 protected AlignCalcManagerI calculator = new AlignCalcManager();
820 * trigger update of conservation annotation
822 public void updateConservation(final AlignmentViewPanel ap)
824 // see note in mantis : issue number 8585
825 if (alignment.isNucleotide()
826 || (conservation == null && quality == null)
827 || !autoCalculateConsensus)
831 if (calculator.getRegisteredWorkersOfClass(
832 jalview.workers.ConservationThread.class) == null)
834 calculator.registerWorker(
835 new jalview.workers.ConservationThread(this, ap));
840 * trigger update of consensus annotation
842 public void updateConsensus(final AlignmentViewPanel ap)
844 // see note in mantis : issue number 8585
845 if (consensus == null || !autoCalculateConsensus)
850 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
852 calculator.registerWorker(new ConsensusThread(this, ap));
856 * A separate thread to compute cDNA consensus for a protein alignment
857 * which has mapping to cDNA
859 final AlignmentI al = this.getAlignment();
860 if (!al.isNucleotide() && al.getCodonFrames() != null
861 && !al.getCodonFrames().isEmpty())
864 * fudge - check first for protein-to-nucleotide mappings
865 * (we don't want to do this for protein-to-protein)
867 boolean doConsensus = false;
868 for (AlignedCodonFrame mapping : al.getCodonFrames())
870 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
871 MapList[] mapLists = mapping.getdnaToProt();
872 // mapLists can be empty if project load has not finished resolving seqs
873 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
881 if (calculator.getRegisteredWorkersOfClass(
882 ComplementConsensusThread.class) == null)
885 .registerWorker(new ComplementConsensusThread(this, ap));
891 // --------START Structure Conservation
892 public void updateStrucConsensus(final AlignmentViewPanel ap)
894 if (autoCalculateStrucConsensus && strucConsensus == null
895 && alignment.isNucleotide() && alignment.hasRNAStructure())
897 // secondary structure has been added - so init the consensus line
901 // see note in mantis : issue number 8585
902 if (strucConsensus == null || !autoCalculateStrucConsensus)
906 if (calculator.getRegisteredWorkersOfClass(
907 StrucConsensusThread.class) == null)
909 calculator.registerWorker(new StrucConsensusThread(this, ap));
913 public boolean isCalcInProgress()
915 return calculator.isWorking();
919 public boolean isCalculationInProgress(
920 AlignmentAnnotation alignmentAnnotation)
922 if (!alignmentAnnotation.autoCalculated)
926 if (calculator.workingInvolvedWith(alignmentAnnotation))
928 // System.err.println("grey out ("+alignmentAnnotation.label+")");
934 public void setAlignment(AlignmentI align)
936 this.alignment = align;
940 * Clean up references when this viewport is closed
943 public void dispose()
946 * defensively null out references to large objects in case
947 * this object is not garbage collected (as if!)
950 complementConsensus = null;
951 strucConsensus = null;
954 groupConsensus = null;
955 groupConservation = null;
957 hconservation = null;
958 hcomplementConsensus = null;
961 residueShading = null; // may hold a reference to Consensus
962 changeSupport = null;
965 currentExtTree = null;
966 selectionGroup = null;
972 public boolean isClosed()
974 // TODO: check that this isClosed is only true after panel is closed, not
975 // before it is fully constructed.
976 return alignment == null;
980 public AlignCalcManagerI getCalcManager()
986 * should conservation rows be shown for groups
988 protected boolean showGroupConservation = false;
991 * should consensus rows be shown for groups
993 protected boolean showGroupConsensus = false;
996 * should consensus profile be rendered by default
998 protected boolean showSequenceLogo = false;
1001 * should consensus profile be rendered normalised to row height
1003 protected boolean normaliseSequenceLogo = false;
1006 * should consensus histograms be rendered by default
1008 protected boolean showConsensusHistogram = true;
1011 * @return the showConsensusProfile
1014 public boolean isShowSequenceLogo()
1016 return showSequenceLogo;
1020 * @param showSequenceLogo
1023 public void setShowSequenceLogo(boolean showSequenceLogo)
1025 if (showSequenceLogo != this.showSequenceLogo)
1027 // TODO: decouple settings setting from calculation when refactoring
1028 // annotation update method from alignframe to viewport
1029 this.showSequenceLogo = showSequenceLogo;
1030 calculator.updateAnnotationFor(ConsensusThread.class);
1031 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1032 calculator.updateAnnotationFor(StrucConsensusThread.class);
1034 this.showSequenceLogo = showSequenceLogo;
1038 * @param showConsensusHistogram
1039 * the showConsensusHistogram to set
1041 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1043 this.showConsensusHistogram = showConsensusHistogram;
1047 * @return the showGroupConservation
1049 public boolean isShowGroupConservation()
1051 return showGroupConservation;
1055 * @param showGroupConservation
1056 * the showGroupConservation to set
1058 public void setShowGroupConservation(boolean showGroupConservation)
1060 this.showGroupConservation = showGroupConservation;
1064 * @return the showGroupConsensus
1066 public boolean isShowGroupConsensus()
1068 return showGroupConsensus;
1072 * @param showGroupConsensus
1073 * the showGroupConsensus to set
1075 public void setShowGroupConsensus(boolean showGroupConsensus)
1077 this.showGroupConsensus = showGroupConsensus;
1082 * @return flag to indicate if the consensus histogram should be rendered by
1086 public boolean isShowConsensusHistogram()
1088 return this.showConsensusHistogram;
1092 * when set, updateAlignment will always ensure sequences are of equal length
1094 private boolean padGaps = false;
1097 * when set, alignment should be reordered according to a newly opened tree
1099 public boolean sortByTree = false;
1104 * @return null or the currently selected sequence region
1107 public SequenceGroup getSelectionGroup()
1109 return selectionGroup;
1113 * Set the selection group for this window. Also sets the current alignment as
1114 * the context for the group, if it does not already have one.
1117 * - group holding references to sequences in this alignment view
1121 public void setSelectionGroup(SequenceGroup sg)
1123 selectionGroup = sg;
1124 if (sg != null && sg.getContext() == null)
1126 sg.setContext(alignment);
1130 public void setHiddenColumns(HiddenColumns hidden)
1132 this.alignment.setHiddenColumns(hidden);
1136 public ColumnSelection getColumnSelection()
1142 public void setColumnSelection(ColumnSelection colSel)
1144 this.colSel = colSel;
1147 updateHiddenColumns();
1149 isColSelChanged(true);
1157 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1159 return hiddenRepSequences;
1163 public void setHiddenRepSequences(
1164 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1166 this.hiddenRepSequences = hiddenRepSequences;
1170 public boolean hasSelectedColumns()
1172 ColumnSelection columnSelection = getColumnSelection();
1173 return columnSelection != null && columnSelection.hasSelectedColumns();
1177 public boolean hasHiddenColumns()
1179 return alignment.getHiddenColumns() != null
1180 && alignment.getHiddenColumns().hasHiddenColumns();
1183 public void updateHiddenColumns()
1185 // this method doesn't really do anything now. But - it could, since a
1186 // column Selection could be in the process of modification
1187 // hasHiddenColumns = colSel.hasHiddenColumns();
1191 public boolean hasHiddenRows()
1193 return alignment.getHiddenSequences().getSize() > 0;
1196 protected SequenceGroup selectionGroup;
1198 public void setSequenceSetId(String newid)
1200 if (sequenceSetID != null)
1203 "Warning - overwriting a sequenceSetId for a viewport!");
1205 sequenceSetID = new String(newid);
1209 public String getSequenceSetId()
1211 if (sequenceSetID == null)
1213 sequenceSetID = alignment.hashCode() + "";
1216 return sequenceSetID;
1220 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1223 protected String viewId = null;
1226 public String getViewId()
1230 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1235 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1237 ignoreGapsInConsensusCalculation = b;
1240 updateConsensus(ap);
1241 if (residueShading != null)
1243 residueShading.setThreshold(residueShading.getThreshold(),
1244 ignoreGapsInConsensusCalculation);
1250 private long sgrouphash = -1, colselhash = -1;
1253 * checks current SelectionGroup against record of last hash value, and
1257 * update the record of last hash value
1259 * @return true if SelectionGroup changed since last call (when b is true)
1261 public boolean isSelectionGroupChanged(boolean b)
1263 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1264 : selectionGroup.hashCode();
1265 if (hc != -1 && hc != sgrouphash)
1277 * checks current colsel against record of last hash value, and optionally
1281 * update the record of last hash value
1282 * @return true if colsel changed since last call (when b is true)
1284 public boolean isColSelChanged(boolean b)
1286 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1287 if (hc != -1 && hc != colselhash)
1299 public boolean isIgnoreGapsConsensus()
1301 return ignoreGapsInConsensusCalculation;
1304 // property change stuff
1305 // JBPNote Prolly only need this in the applet version.
1306 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1309 protected boolean showConservation = true;
1311 protected boolean showQuality = true;
1313 protected boolean showConsensus = true;
1315 protected boolean showOccupancy = true;
1317 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1319 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1321 protected boolean showAutocalculatedAbove;
1324 * when set, view will scroll to show the highlighted position
1326 private boolean followHighlight = true;
1329 * Property change listener for changes in alignment
1334 public void addPropertyChangeListener(
1335 java.beans.PropertyChangeListener listener)
1337 changeSupport.addPropertyChangeListener(listener);
1346 public void removePropertyChangeListener(
1347 java.beans.PropertyChangeListener listener)
1349 if (changeSupport != null)
1351 changeSupport.removePropertyChangeListener(listener);
1356 * Property change listener for changes in alignment
1365 public void firePropertyChange(String prop, Object oldvalue,
1368 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1371 // common hide/show column stuff
1373 public void hideSelectedColumns()
1375 if (colSel.isEmpty())
1380 colSel.hideSelectedColumns(alignment);
1381 setSelectionGroup(null);
1382 isColSelChanged(true);
1385 public void hideColumns(int start, int end)
1389 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1393 alignment.getHiddenColumns().hideColumns(start, end);
1395 isColSelChanged(true);
1398 public void showColumn(int col)
1400 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1401 isColSelChanged(true);
1404 public void showAllHiddenColumns()
1406 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1407 isColSelChanged(true);
1410 // common hide/show seq stuff
1411 public void showAllHiddenSeqs()
1413 int startSeq = ranges.getStartSeq();
1414 int endSeq = ranges.getEndSeq();
1416 if (alignment.getHiddenSequences().getSize() > 0)
1418 if (selectionGroup == null)
1420 selectionGroup = new SequenceGroup();
1421 selectionGroup.setEndRes(alignment.getWidth() - 1);
1423 List<SequenceI> tmp = alignment.getHiddenSequences()
1424 .showAll(hiddenRepSequences);
1425 for (SequenceI seq : tmp)
1427 selectionGroup.addSequence(seq, false);
1428 setSequenceAnnotationsVisible(seq, true);
1431 hiddenRepSequences = null;
1433 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1435 firePropertyChange("alignment", null, alignment.getSequences());
1436 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1442 public void showSequence(int index)
1444 int startSeq = ranges.getStartSeq();
1445 int endSeq = ranges.getEndSeq();
1447 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1448 hiddenRepSequences);
1451 if (selectionGroup == null)
1453 selectionGroup = new SequenceGroup();
1454 selectionGroup.setEndRes(alignment.getWidth() - 1);
1457 for (SequenceI seq : tmp)
1459 selectionGroup.addSequence(seq, false);
1460 setSequenceAnnotationsVisible(seq, true);
1463 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1465 firePropertyChange("alignment", null, alignment.getSequences());
1470 public void hideAllSelectedSeqs()
1472 if (selectionGroup == null || selectionGroup.getSize() < 1)
1477 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1481 setSelectionGroup(null);
1484 public void hideSequence(SequenceI[] seq)
1487 * cache offset to first visible sequence
1489 int startSeq = ranges.getStartSeq();
1493 for (int i = 0; i < seq.length; i++)
1495 alignment.getHiddenSequences().hideSequence(seq[i]);
1496 setSequenceAnnotationsVisible(seq[i], false);
1498 ranges.setStartSeq(startSeq);
1499 firePropertyChange("alignment", null, alignment.getSequences());
1504 * Hides the specified sequence, or the sequences it represents
1507 * the sequence to hide, or keep as representative
1508 * @param representGroup
1509 * if true, hide the current selection group except for the
1510 * representative sequence
1512 public void hideSequences(SequenceI sequence, boolean representGroup)
1514 if (selectionGroup == null || selectionGroup.getSize() < 1)
1516 hideSequence(new SequenceI[] { sequence });
1522 hideRepSequences(sequence, selectionGroup);
1523 setSelectionGroup(null);
1527 int gsize = selectionGroup.getSize();
1528 SequenceI[] hseqs = selectionGroup.getSequences()
1529 .toArray(new SequenceI[gsize]);
1531 hideSequence(hseqs);
1532 setSelectionGroup(null);
1537 * Set visibility for any annotations for the given sequence.
1541 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1544 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1547 for (AlignmentAnnotation ann : anns)
1549 if (ann.sequenceRef == sequenceI)
1551 ann.visible = visible;
1557 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1559 int sSize = sg.getSize();
1565 if (hiddenRepSequences == null)
1567 hiddenRepSequences = new Hashtable<>();
1570 hiddenRepSequences.put(repSequence, sg);
1572 // Hide all sequences except the repSequence
1573 SequenceI[] seqs = new SequenceI[sSize - 1];
1575 for (int i = 0; i < sSize; i++)
1577 if (sg.getSequenceAt(i) != repSequence)
1579 if (index == sSize - 1)
1584 seqs[index++] = sg.getSequenceAt(i);
1587 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1588 sg.setHidereps(true); // note: not done in 2.7applet
1595 * @return null or the current reference sequence
1597 public SequenceI getReferenceSeq()
1599 return alignment.getSeqrep();
1604 * @return true iff seq is the reference for the alignment
1606 public boolean isReferenceSeq(SequenceI seq)
1608 return alignment.getSeqrep() == seq;
1614 * @return true if there are sequences represented by this sequence that are
1617 public boolean isHiddenRepSequence(SequenceI seq)
1619 return (hiddenRepSequences != null
1620 && hiddenRepSequences.containsKey(seq));
1626 * @return null or a sequence group containing the sequences that seq
1629 public SequenceGroup getRepresentedSequences(SequenceI seq)
1631 return (SequenceGroup) (hiddenRepSequences == null ? null
1632 : hiddenRepSequences.get(seq));
1636 public int adjustForHiddenSeqs(int alignmentIndex)
1638 return alignment.getHiddenSequences()
1639 .adjustForHiddenSeqs(alignmentIndex);
1643 public void invertColumnSelection()
1645 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1646 isColSelChanged(true);
1650 public SequenceI[] getSelectionAsNewSequence()
1652 SequenceI[] sequences;
1653 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1654 // this was the only caller in the applet for this method
1655 // JBPNote: in applet, this method returned references to the alignment
1656 // sequences, and it did not honour the presence/absence of annotation
1657 // attached to the alignment (probably!)
1658 if (selectionGroup == null || selectionGroup.getSize() == 0)
1660 sequences = alignment.getSequencesArray();
1661 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1662 for (int i = 0; i < sequences.length; i++)
1664 // construct new sequence with subset of visible annotation
1665 sequences[i] = new Sequence(sequences[i], annots);
1670 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1677 public SequenceI[] getSequenceSelection()
1679 SequenceI[] sequences = null;
1680 if (selectionGroup != null)
1682 sequences = selectionGroup.getSequencesInOrder(alignment);
1684 if (sequences == null)
1686 sequences = alignment.getSequencesArray();
1692 public jalview.datamodel.AlignmentView getAlignmentView(
1693 boolean selectedOnly)
1695 return getAlignmentView(selectedOnly, false);
1699 public jalview.datamodel.AlignmentView getAlignmentView(
1700 boolean selectedOnly, boolean markGroups)
1702 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1704 alignment.getHiddenColumns() != null
1705 && alignment.getHiddenColumns().hasHiddenColumns(),
1706 selectedOnly, markGroups);
1710 public String[] getViewAsString(boolean selectedRegionOnly)
1712 return getViewAsString(selectedRegionOnly, true);
1716 public String[] getViewAsString(boolean selectedRegionOnly,
1717 boolean exportHiddenSeqs)
1719 String[] selection = null;
1720 SequenceI[] seqs = null;
1722 int start = 0, end = 0;
1723 if (selectedRegionOnly && selectionGroup != null)
1725 iSize = selectionGroup.getSize();
1726 seqs = selectionGroup.getSequencesInOrder(alignment);
1727 start = selectionGroup.getStartRes();
1728 end = selectionGroup.getEndRes() + 1;
1732 if (hasHiddenRows() && exportHiddenSeqs)
1734 AlignmentI fullAlignment = alignment.getHiddenSequences()
1735 .getFullAlignment();
1736 iSize = fullAlignment.getHeight();
1737 seqs = fullAlignment.getSequencesArray();
1738 end = fullAlignment.getWidth();
1742 iSize = alignment.getHeight();
1743 seqs = alignment.getSequencesArray();
1744 end = alignment.getWidth();
1748 selection = new String[iSize];
1749 if (alignment.getHiddenColumns() != null
1750 && alignment.getHiddenColumns().hasHiddenColumns())
1752 for (i = 0; i < iSize; i++)
1754 Iterator<int[]> blocks = alignment.getHiddenColumns()
1755 .getVisContigsIterator(start, end + 1, false);
1756 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1761 for (i = 0; i < iSize; i++)
1763 selection[i] = seqs[i].getSequenceAsString(start, end);
1771 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1773 ArrayList<int[]> regions = new ArrayList<>();
1779 HiddenColumns hidden = alignment.getHiddenColumns();
1780 if (hidden != null && hidden.hasHiddenColumns())
1784 start = hidden.visibleToAbsoluteColumn(start);
1787 end = hidden.getNextHiddenBoundary(false, start);
1798 regions.add(new int[] { start, end });
1800 if (hidden != null && hidden.hasHiddenColumns())
1802 start = hidden.visibleToAbsoluteColumn(end);
1803 start = hidden.getNextHiddenBoundary(true, start) + 1;
1805 } while (end < max);
1807 // int[][] startEnd = new int[regions.size()][2];
1813 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1814 boolean selectedOnly)
1816 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1817 AlignmentAnnotation[] aa;
1818 if ((aa = alignment.getAlignmentAnnotation()) != null)
1820 for (AlignmentAnnotation annot : aa)
1822 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1823 if (selectedOnly && selectionGroup != null)
1825 clone.makeVisibleAnnotation(selectionGroup.getStartRes(),
1826 selectionGroup.getEndRes(), alignment.getHiddenColumns());
1830 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1839 public boolean isPadGaps()
1845 public void setPadGaps(boolean padGaps)
1847 this.padGaps = padGaps;
1851 * apply any post-edit constraints and trigger any calculations needed after
1852 * an edit has been performed on the alignment
1857 public void alignmentChanged(AlignmentViewPanel ap)
1861 alignment.padGaps();
1863 if (autoCalculateConsensus)
1865 updateConsensus(ap);
1867 if (hconsensus != null && autoCalculateConsensus)
1869 updateConservation(ap);
1871 if (autoCalculateStrucConsensus)
1873 updateStrucConsensus(ap);
1876 // Reset endRes of groups if beyond alignment width
1877 int alWidth = alignment.getWidth();
1878 List<SequenceGroup> groups = alignment.getGroups();
1881 for (SequenceGroup sg : groups)
1883 if (sg.getEndRes() > alWidth)
1885 sg.setEndRes(alWidth - 1);
1890 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1892 selectionGroup.setEndRes(alWidth - 1);
1895 updateAllColourSchemes();
1896 calculator.restartWorkers();
1897 // alignment.adjustSequenceAnnotations();
1901 * reset scope and do calculations for all applied colourschemes on alignment
1903 void updateAllColourSchemes()
1905 ResidueShaderI rs = residueShading;
1908 rs.alignmentChanged(alignment, hiddenRepSequences);
1910 rs.setConsensus(hconsensus);
1911 if (rs.conservationApplied())
1913 rs.setConservation(Conservation.calculateConservation("All",
1914 alignment.getSequences(), 0, alignment.getWidth(), false,
1915 getConsPercGaps(), false));
1919 for (SequenceGroup sg : alignment.getGroups())
1923 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1925 sg.recalcConservation();
1929 protected void initAutoAnnotation()
1931 // TODO: add menu option action that nulls or creates consensus object
1932 // depending on if the user wants to see the annotation or not in a
1933 // specific alignment
1935 if (hconsensus == null && !isDataset)
1937 if (!alignment.isNucleotide())
1946 consensus = new AlignmentAnnotation("Consensus",
1947 MessageManager.getString("label.consensus_descr"),
1948 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1949 initConsensus(consensus);
1952 initComplementConsensus();
1957 * If this is a protein alignment and there are mappings to cDNA, adds the
1958 * cDNA consensus annotation and returns true, else returns false.
1960 public boolean initComplementConsensus()
1962 if (!alignment.isNucleotide())
1964 final List<AlignedCodonFrame> codonMappings = alignment
1966 if (codonMappings != null && !codonMappings.isEmpty())
1968 boolean doConsensus = false;
1969 for (AlignedCodonFrame mapping : codonMappings)
1971 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1972 MapList[] mapLists = mapping.getdnaToProt();
1973 // mapLists can be empty if project load has not finished resolving
1975 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1983 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1985 .getString("label.complement_consensus_descr"),
1986 new Annotation[1], 0f, 100f,
1987 AlignmentAnnotation.BAR_GRAPH);
1988 initConsensus(complementConsensus);
1996 private void initConsensus(AlignmentAnnotation aa)
1999 aa.autoCalculated = true;
2003 alignment.addAnnotation(aa);
2007 // these should be extracted from the view model - style and settings for
2008 // derived annotation
2009 private void initGapCounts()
2013 gapcounts = new AlignmentAnnotation("Occupancy",
2014 MessageManager.getString("label.occupancy_descr"),
2015 new Annotation[1], 0f, alignment.getHeight(),
2016 AlignmentAnnotation.BAR_GRAPH);
2017 gapcounts.hasText = true;
2018 gapcounts.autoCalculated = true;
2019 gapcounts.scaleColLabel = true;
2020 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2022 alignment.addAnnotation(gapcounts);
2026 private void initConservation()
2028 if (showConservation)
2030 if (conservation == null)
2032 conservation = new AlignmentAnnotation("Conservation",
2033 MessageManager.formatMessage("label.conservation_descr",
2035 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2036 conservation.hasText = true;
2037 conservation.autoCalculated = true;
2038 alignment.addAnnotation(conservation);
2043 private void initQuality()
2047 if (quality == null)
2049 quality = new AlignmentAnnotation("Quality",
2050 MessageManager.getString("label.quality_descr"),
2051 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2052 quality.hasText = true;
2053 quality.autoCalculated = true;
2054 alignment.addAnnotation(quality);
2059 private void initRNAStructure()
2061 if (alignment.hasRNAStructure() && strucConsensus == null)
2063 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2064 MessageManager.getString("label.strucconsensus_descr"),
2065 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2066 strucConsensus.hasText = true;
2067 strucConsensus.autoCalculated = true;
2071 alignment.addAnnotation(strucConsensus);
2079 * @see jalview.api.AlignViewportI#calcPanelHeight()
2082 public int calcPanelHeight()
2084 // setHeight of panels
2085 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2087 int charHeight = getCharHeight();
2090 BitSet graphgrp = new BitSet();
2091 for (AlignmentAnnotation aa : anns)
2095 System.err.println("Null annotation row: ignoring.");
2102 if (aa.graphGroup > -1)
2104 if (graphgrp.get(aa.graphGroup))
2110 graphgrp.set(aa.graphGroup);
2117 aa.height += charHeight;
2127 aa.height += aa.graphHeight;
2135 height += aa.height;
2147 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2148 boolean preserveNewGroupSettings)
2150 boolean updateCalcs = false;
2151 boolean conv = isShowGroupConservation();
2152 boolean cons = isShowGroupConsensus();
2153 boolean showprf = isShowSequenceLogo();
2154 boolean showConsHist = isShowConsensusHistogram();
2155 boolean normLogo = isNormaliseSequenceLogo();
2158 * TODO reorder the annotation rows according to group/sequence ordering on
2161 // boolean sortg = true;
2163 // remove old automatic annotation
2164 // add any new annotation
2166 // intersect alignment annotation with alignment groups
2168 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2169 List<SequenceGroup> oldrfs = new ArrayList<>();
2172 for (int an = 0; an < aan.length; an++)
2174 if (aan[an].autoCalculated && aan[an].groupRef != null)
2176 oldrfs.add(aan[an].groupRef);
2177 alignment.deleteAnnotation(aan[an], false);
2181 if (alignment.getGroups() != null)
2183 for (SequenceGroup sg : alignment.getGroups())
2185 updateCalcs = false;
2186 if (applyGlobalSettings
2187 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2189 // set defaults for this group's conservation/consensus
2190 sg.setshowSequenceLogo(showprf);
2191 sg.setShowConsensusHistogram(showConsHist);
2192 sg.setNormaliseSequenceLogo(normLogo);
2197 alignment.addAnnotation(sg.getConservationRow(), 0);
2202 alignment.addAnnotation(sg.getConsensus(), 0);
2204 // refresh the annotation rows
2207 sg.recalcConservation();
2215 public boolean isDisplayReferenceSeq()
2217 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2221 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2223 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2227 public boolean isColourByReferenceSeq()
2229 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2233 public Color getSequenceColour(SequenceI seq)
2235 Color sqc = sequenceColours.get(seq);
2236 return (sqc == null ? Color.white : sqc);
2240 public void setSequenceColour(SequenceI seq, Color col)
2244 sequenceColours.remove(seq);
2248 sequenceColours.put(seq, col);
2253 public void updateSequenceIdColours()
2255 for (SequenceGroup sg : alignment.getGroups())
2257 if (sg.idColour != null)
2259 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2261 sequenceColours.put(s, sg.idColour);
2268 public void clearSequenceColours()
2270 sequenceColours.clear();
2274 public AlignViewportI getCodingComplement()
2276 return this.codingComplement;
2280 * Set this as the (cDna/protein) complement of the given viewport. Also
2281 * ensures the reverse relationship is set on the given viewport.
2284 public void setCodingComplement(AlignViewportI av)
2288 System.err.println("Ignoring recursive setCodingComplement request");
2292 this.codingComplement = av;
2293 // avoid infinite recursion!
2294 if (av.getCodingComplement() != this)
2296 av.setCodingComplement(this);
2302 public boolean isNucleotide()
2304 return getAlignment() == null ? false : getAlignment().isNucleotide();
2308 public FeaturesDisplayedI getFeaturesDisplayed()
2310 return featuresDisplayed;
2314 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2316 featuresDisplayed = featuresDisplayedI;
2320 public boolean areFeaturesDisplayed()
2322 return featuresDisplayed != null
2323 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2330 * features are displayed if true
2333 public void setShowSequenceFeatures(boolean b)
2335 viewStyle.setShowSequenceFeatures(b);
2339 public boolean isShowSequenceFeatures()
2341 return viewStyle.isShowSequenceFeatures();
2345 public void setShowSequenceFeaturesHeight(boolean selected)
2347 viewStyle.setShowSequenceFeaturesHeight(selected);
2351 public boolean isShowSequenceFeaturesHeight()
2353 return viewStyle.isShowSequenceFeaturesHeight();
2357 public void setShowAnnotation(boolean b)
2359 viewStyle.setShowAnnotation(b);
2363 public boolean isShowAnnotation()
2365 return viewStyle.isShowAnnotation();
2369 public boolean isRightAlignIds()
2371 return viewStyle.isRightAlignIds();
2375 public void setRightAlignIds(boolean rightAlignIds)
2377 viewStyle.setRightAlignIds(rightAlignIds);
2381 public boolean getConservationSelected()
2383 return viewStyle.getConservationSelected();
2387 public void setShowBoxes(boolean state)
2389 viewStyle.setShowBoxes(state);
2394 * @see jalview.api.ViewStyleI#getTextColour()
2397 public Color getTextColour()
2399 return viewStyle.getTextColour();
2404 * @see jalview.api.ViewStyleI#getTextColour2()
2407 public Color getTextColour2()
2409 return viewStyle.getTextColour2();
2414 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2417 public int getThresholdTextColour()
2419 return viewStyle.getThresholdTextColour();
2424 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2427 public boolean isConservationColourSelected()
2429 return viewStyle.isConservationColourSelected();
2434 * @see jalview.api.ViewStyleI#isRenderGaps()
2437 public boolean isRenderGaps()
2439 return viewStyle.isRenderGaps();
2444 * @see jalview.api.ViewStyleI#isShowColourText()
2447 public boolean isShowColourText()
2449 return viewStyle.isShowColourText();
2453 * @param conservationColourSelected
2454 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2457 public void setConservationColourSelected(
2458 boolean conservationColourSelected)
2460 viewStyle.setConservationColourSelected(conservationColourSelected);
2464 * @param showColourText
2465 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2468 public void setShowColourText(boolean showColourText)
2470 viewStyle.setShowColourText(showColourText);
2475 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2478 public void setTextColour(Color textColour)
2480 viewStyle.setTextColour(textColour);
2484 * @param thresholdTextColour
2485 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2488 public void setThresholdTextColour(int thresholdTextColour)
2490 viewStyle.setThresholdTextColour(thresholdTextColour);
2494 * @param textColour2
2495 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2498 public void setTextColour2(Color textColour2)
2500 viewStyle.setTextColour2(textColour2);
2504 public ViewStyleI getViewStyle()
2506 return new ViewStyle(viewStyle);
2510 public void setViewStyle(ViewStyleI settingsForView)
2512 viewStyle = new ViewStyle(settingsForView);
2513 if (residueShading != null)
2515 residueShading.setConservationApplied(
2516 settingsForView.isConservationColourSelected());
2521 public boolean sameStyle(ViewStyleI them)
2523 return viewStyle.sameStyle(them);
2528 * @see jalview.api.ViewStyleI#getIdWidth()
2531 public int getIdWidth()
2533 return viewStyle.getIdWidth();
2538 * @see jalview.api.ViewStyleI#setIdWidth(int)
2541 public void setIdWidth(int i)
2543 viewStyle.setIdWidth(i);
2548 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2551 public boolean isCentreColumnLabels()
2553 return viewStyle.isCentreColumnLabels();
2557 * @param centreColumnLabels
2558 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2561 public void setCentreColumnLabels(boolean centreColumnLabels)
2563 viewStyle.setCentreColumnLabels(centreColumnLabels);
2568 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2571 public void setShowDBRefs(boolean showdbrefs)
2573 viewStyle.setShowDBRefs(showdbrefs);
2578 * @see jalview.api.ViewStyleI#isShowDBRefs()
2581 public boolean isShowDBRefs()
2583 return viewStyle.isShowDBRefs();
2588 * @see jalview.api.ViewStyleI#isShowNPFeats()
2591 public boolean isShowNPFeats()
2593 return viewStyle.isShowNPFeats();
2597 * @param shownpfeats
2598 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2601 public void setShowNPFeats(boolean shownpfeats)
2603 viewStyle.setShowNPFeats(shownpfeats);
2606 public abstract StructureSelectionManager getStructureSelectionManager();
2609 * Add one command to the command history list.
2613 public void addToHistoryList(CommandI command)
2615 if (this.historyList != null)
2617 this.historyList.push(command);
2618 broadcastCommand(command, false);
2622 protected void broadcastCommand(CommandI command, boolean undo)
2624 getStructureSelectionManager().commandPerformed(command, undo,
2629 * Add one command to the command redo list.
2633 public void addToRedoList(CommandI command)
2635 if (this.redoList != null)
2637 this.redoList.push(command);
2639 broadcastCommand(command, true);
2643 * Clear the command redo list.
2645 public void clearRedoList()
2647 if (this.redoList != null)
2649 this.redoList.clear();
2653 public void setHistoryList(Deque<CommandI> list)
2655 this.historyList = list;
2658 public Deque<CommandI> getHistoryList()
2660 return this.historyList;
2663 public void setRedoList(Deque<CommandI> list)
2665 this.redoList = list;
2668 public Deque<CommandI> getRedoList()
2670 return this.redoList;
2674 public VamsasSource getVamsasSource()
2679 public SequenceAnnotationOrder getSortAnnotationsBy()
2681 return sortAnnotationsBy;
2684 public void setSortAnnotationsBy(
2685 SequenceAnnotationOrder sortAnnotationsBy)
2687 this.sortAnnotationsBy = sortAnnotationsBy;
2690 public boolean isShowAutocalculatedAbove()
2692 return showAutocalculatedAbove;
2695 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2697 this.showAutocalculatedAbove = showAutocalculatedAbove;
2701 public boolean isScaleProteinAsCdna()
2703 return viewStyle.isScaleProteinAsCdna();
2707 public void setScaleProteinAsCdna(boolean b)
2709 viewStyle.setScaleProteinAsCdna(b);
2713 public boolean isProteinFontAsCdna()
2715 return viewStyle.isProteinFontAsCdna();
2719 public void setProteinFontAsCdna(boolean b)
2721 viewStyle.setProteinFontAsCdna(b);
2725 public void setShowComplementFeatures(boolean b)
2727 viewStyle.setShowComplementFeatures(b);
2731 public boolean isShowComplementFeatures()
2733 return viewStyle.isShowComplementFeatures();
2737 public void setShowComplementFeaturesOnTop(boolean b)
2739 viewStyle.setShowComplementFeaturesOnTop(b);
2743 public boolean isShowComplementFeaturesOnTop()
2745 return viewStyle.isShowComplementFeaturesOnTop();
2749 * @return true if view should scroll to show the highlighted region of a
2754 public final boolean isFollowHighlight()
2756 return followHighlight;
2760 public final void setFollowHighlight(boolean b)
2762 this.followHighlight = b;
2766 public ViewportRanges getRanges()
2772 * Helper method to populate the SearchResults with the location in the
2773 * complementary alignment to scroll to, in order to match this one.
2776 * the SearchResults to add to
2777 * @return the offset (below top of visible region) of the matched sequence
2779 protected int findComplementScrollTarget(SearchResultsI sr)
2781 final AlignViewportI complement = getCodingComplement();
2782 if (complement == null || !complement.isFollowHighlight())
2786 boolean iAmProtein = !getAlignment().isNucleotide();
2787 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2788 : complement.getAlignment();
2789 if (proteinAlignment == null)
2793 final List<AlignedCodonFrame> mappings = proteinAlignment
2797 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2798 * residue in the middle column of the visible region. Scroll the
2799 * complementary alignment to line up the corresponding residue.
2802 SequenceI sequence = null;
2805 * locate 'middle' column (true middle if an odd number visible, left of
2806 * middle if an even number visible)
2808 int middleColumn = ranges.getStartRes()
2809 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2810 final HiddenSequences hiddenSequences = getAlignment()
2811 .getHiddenSequences();
2814 * searching to the bottom of the alignment gives smoother scrolling across
2815 * all gapped visible regions
2817 int lastSeq = alignment.getHeight() - 1;
2818 List<AlignedCodonFrame> seqMappings = null;
2819 for (int seqNo = ranges
2820 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2822 sequence = getAlignment().getSequenceAt(seqNo);
2823 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2827 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2831 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2833 getCodingComplement().getAlignment().getSequences());
2834 if (!seqMappings.isEmpty())
2840 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2843 * No ungapped mapped sequence in middle column - do nothing
2847 MappingUtils.addSearchResults(sr, sequence,
2848 sequence.findPosition(middleColumn), seqMappings);
2853 * synthesize a column selection if none exists so it covers the given
2854 * selection group. if wholewidth is false, no column selection is made if the
2855 * selection group covers the whole alignment width.
2860 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2863 if (sg != null && (sgs = sg.getStartRes()) >= 0
2864 && sg.getStartRes() <= (sge = sg.getEndRes())
2865 && !this.hasSelectedColumns())
2867 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2874 colSel = new ColumnSelection();
2876 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2878 colSel.addElement(cspos);
2884 * hold status of current selection group - defined on alignment or not.
2886 private boolean selectionIsDefinedGroup = false;
2889 public boolean isSelectionDefinedGroup()
2891 if (selectionGroup == null)
2895 if (isSelectionGroupChanged(true))
2897 selectionIsDefinedGroup = false;
2898 List<SequenceGroup> gps = alignment.getGroups();
2899 if (gps == null || gps.size() == 0)
2901 selectionIsDefinedGroup = false;
2905 selectionIsDefinedGroup = gps.contains(selectionGroup);
2908 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2912 * null, or currently highlighted results on this view
2914 private SearchResultsI searchResults = null;
2916 protected TreeModel currentTree = null;
2918 protected TreeI currentExtTree = null;
2921 public boolean hasSearchResults()
2923 return searchResults != null;
2927 public void setSearchResults(SearchResultsI results)
2929 searchResults = results;
2933 public SearchResultsI getSearchResults()
2935 return searchResults;
2939 * get the consensus sequence as displayed under the PID consensus annotation
2942 * @return consensus sequence as a new sequence object
2944 public SequenceI getConsensusSeq()
2946 if (consensus == null)
2948 updateConsensus(null);
2950 if (consensus == null)
2954 StringBuffer seqs = new StringBuffer();
2955 for (int i = 0; i < consensus.annotations.length; i++)
2957 Annotation annotation = consensus.annotations[i];
2958 if (annotation != null)
2960 String description = annotation.description;
2961 if (description != null && description.startsWith("["))
2963 // consensus is a tie - just pick the first one
2964 seqs.append(description.charAt(1));
2968 seqs.append(annotation.displayCharacter);
2973 SequenceI sq = new Sequence("Consensus", seqs.toString());
2974 sq.setDescription("Percentage Identity Consensus "
2975 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
2980 public void setCurrentTree(TreeModel tree) // adapt to Aptx
2986 public TreeModel getCurrentTree()
2992 public AlignmentExportData getAlignExportData(
2993 AlignExportSettingsI options)
2995 AlignmentI alignmentToExport = null;
2996 String[] omitHidden = null;
2997 alignmentToExport = null;
2999 if (hasHiddenColumns() && !options.isExportHiddenColumns())
3001 omitHidden = getViewAsString(false,
3002 options.isExportHiddenSequences());
3005 int[] alignmentStartEnd = new int[2];
3006 if (hasHiddenRows() && options.isExportHiddenSequences())
3008 alignmentToExport = getAlignment().getHiddenSequences()
3009 .getFullAlignment();
3013 alignmentToExport = getAlignment();
3015 alignmentStartEnd = getAlignment().getHiddenColumns()
3016 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
3017 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
3018 omitHidden, alignmentStartEnd);
3023 * flag set to indicate if structure views might be out of sync with sequences
3027 private boolean needToUpdateStructureViews = false;
3030 public boolean isUpdateStructures()
3032 return needToUpdateStructureViews;
3036 public void setUpdateStructures(boolean update)
3038 needToUpdateStructureViews = update;
3042 public boolean needToUpdateStructureViews()
3044 boolean update = needToUpdateStructureViews;
3045 needToUpdateStructureViews = false;
3050 public void addSequenceGroup(SequenceGroup sequenceGroup)
3052 alignment.addGroup(sequenceGroup);
3054 Color col = sequenceGroup.idColour;
3057 col = col.brighter();
3059 for (SequenceI sq : sequenceGroup.getSequences())
3061 setSequenceColour(sq, col);
3065 if (codingComplement != null)
3067 SequenceGroup mappedGroup = MappingUtils
3068 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3069 if (mappedGroup.getSequences().size() > 0)
3071 codingComplement.getAlignment().addGroup(mappedGroup);
3075 for (SequenceI seq : mappedGroup.getSequences())
3077 codingComplement.setSequenceColour(seq, col);
3081 // propagate the structure view update flag according to our own setting
3082 codingComplement.setUpdateStructures(needToUpdateStructureViews);
3087 public Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly)
3091 if (selectedRegionOnly && selectionGroup != null)
3093 start = selectionGroup.getStartRes();
3094 end = selectionGroup.getEndRes() + 1;
3098 end = alignment.getWidth();
3100 return (alignment.getHiddenColumns().getVisContigsIterator(start, end,
3103 public TreeI getCurrentExtTree()
3105 return currentExtTree;
3108 public void setCurrentExtTree(TreeI externalTree)
3110 currentExtTree = externalTree;