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 java.awt.Color;
24 import java.beans.PropertyChangeSupport;
25 import java.util.ArrayDeque;
26 import java.util.ArrayList;
27 import java.util.BitSet;
28 import java.util.Deque;
29 import java.util.HashMap;
30 import java.util.Hashtable;
31 import java.util.Iterator;
32 import java.util.List;
35 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
36 import jalview.analysis.Conservation;
37 import jalview.analysis.TreeModel;
38 import jalview.api.AlignCalcManagerI;
39 import jalview.api.AlignExportSettingsI;
40 import jalview.api.AlignViewportI;
41 import jalview.api.AlignmentViewPanel;
42 import jalview.api.FeaturesDisplayedI;
43 import jalview.api.ViewStyleI;
44 import jalview.bin.Console;
45 import jalview.commands.CommandI;
46 import jalview.datamodel.AlignedCodonFrame;
47 import jalview.datamodel.AlignmentAnnotation;
48 import jalview.datamodel.AlignmentExportData;
49 import jalview.datamodel.AlignmentI;
50 import jalview.datamodel.AlignmentView;
51 import jalview.datamodel.Annotation;
52 import jalview.datamodel.ColumnSelection;
53 import jalview.datamodel.ContactListI;
54 import jalview.datamodel.HiddenColumns;
55 import jalview.datamodel.HiddenSequences;
56 import jalview.datamodel.ProfilesI;
57 import jalview.datamodel.SearchResultsI;
58 import jalview.datamodel.Sequence;
59 import jalview.datamodel.SequenceCollectionI;
60 import jalview.datamodel.SequenceGroup;
61 import jalview.datamodel.SequenceI;
62 import jalview.gui.QuitHandler;
63 import jalview.project.Jalview2XML;
64 import jalview.renderer.ResidueShader;
65 import jalview.renderer.ResidueShaderI;
66 import jalview.schemes.ColourSchemeI;
67 import jalview.structure.CommandListener;
68 import jalview.structure.StructureSelectionManager;
69 import jalview.structure.VamsasSource;
70 import jalview.util.Comparison;
71 import jalview.util.MapList;
72 import jalview.util.MappingUtils;
73 import jalview.util.MessageManager;
74 import jalview.viewmodel.styles.ViewStyle;
75 import jalview.workers.AlignCalcManager;
76 import jalview.workers.ComplementConsensusThread;
77 import jalview.workers.ConsensusThread;
78 import jalview.workers.StrucConsensusThread;
81 * base class holding visualization and analysis attributes and common logic for
82 * an active alignment view displayed in the GUI
87 public abstract class AlignmentViewport
88 implements AlignViewportI, CommandListener, VamsasSource
90 protected ViewportRanges ranges;
92 protected ViewStyleI viewStyle = new ViewStyle();
95 * A viewport that hosts the cDna view of this (protein), or vice versa (if
98 AlignViewportI codingComplement = null;
100 FeaturesDisplayedI featuresDisplayed = null;
102 protected Deque<CommandI> historyList = new ArrayDeque<>();
104 protected Deque<CommandI> redoList = new ArrayDeque<>();
107 * used to determine if quit should be confirmed
109 private boolean savedUpToDate = false;
112 * alignment displayed in the viewport. Please use get/setter
114 protected AlignmentI alignment;
116 public AlignmentViewport(AlignmentI al)
119 ranges = new ViewportRanges(al);
124 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
127 public void setFontName(String name)
129 viewStyle.setFontName(name);
134 * @see jalview.api.ViewStyleI#setFontStyle(int)
137 public void setFontStyle(int style)
139 viewStyle.setFontStyle(style);
144 * @see jalview.api.ViewStyleI#setFontSize(int)
147 public void setFontSize(int size)
149 viewStyle.setFontSize(size);
154 * @see jalview.api.ViewStyleI#getFontStyle()
157 public int getFontStyle()
159 return viewStyle.getFontStyle();
164 * @see jalview.api.ViewStyleI#getFontName()
167 public String getFontName()
169 return viewStyle.getFontName();
174 * @see jalview.api.ViewStyleI#getFontSize()
177 public int getFontSize()
179 return viewStyle.getFontSize();
183 * @param upperCasebold
184 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
187 public void setUpperCasebold(boolean upperCasebold)
189 viewStyle.setUpperCasebold(upperCasebold);
194 * @see jalview.api.ViewStyleI#isUpperCasebold()
197 public boolean isUpperCasebold()
199 return viewStyle.isUpperCasebold();
204 * @see jalview.api.ViewStyleI#isSeqNameItalics()
207 public boolean isSeqNameItalics()
209 return viewStyle.isSeqNameItalics();
213 * @param colourByReferenceSeq
214 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
217 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
219 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
224 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
227 public void setColourAppliesToAllGroups(boolean b)
229 viewStyle.setColourAppliesToAllGroups(b);
234 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
237 public boolean getColourAppliesToAllGroups()
239 return viewStyle.getColourAppliesToAllGroups();
244 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
247 public boolean getAbovePIDThreshold()
249 return viewStyle.getAbovePIDThreshold();
254 * @see jalview.api.ViewStyleI#setIncrement(int)
257 public void setIncrement(int inc)
259 viewStyle.setIncrement(inc);
264 * @see jalview.api.ViewStyleI#getIncrement()
267 public int getIncrement()
269 return viewStyle.getIncrement();
274 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
277 public void setConservationSelected(boolean b)
279 viewStyle.setConservationSelected(b);
284 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
287 public void setShowHiddenMarkers(boolean show)
289 viewStyle.setShowHiddenMarkers(show);
294 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
297 public boolean getShowHiddenMarkers()
299 return viewStyle.getShowHiddenMarkers();
304 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
307 public void setScaleRightWrapped(boolean b)
309 viewStyle.setScaleRightWrapped(b);
314 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
317 public void setScaleLeftWrapped(boolean b)
319 viewStyle.setScaleLeftWrapped(b);
324 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
327 public void setScaleAboveWrapped(boolean b)
329 viewStyle.setScaleAboveWrapped(b);
334 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
337 public boolean getScaleLeftWrapped()
339 return viewStyle.getScaleLeftWrapped();
344 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
347 public boolean getScaleAboveWrapped()
349 return viewStyle.getScaleAboveWrapped();
354 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
357 public boolean getScaleRightWrapped()
359 return viewStyle.getScaleRightWrapped();
364 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
367 public void setAbovePIDThreshold(boolean b)
369 viewStyle.setAbovePIDThreshold(b);
374 * @see jalview.api.ViewStyleI#setThreshold(int)
377 public void setThreshold(int thresh)
379 viewStyle.setThreshold(thresh);
384 * @see jalview.api.ViewStyleI#getThreshold()
387 public int getThreshold()
389 return viewStyle.getThreshold();
394 * @see jalview.api.ViewStyleI#getShowJVSuffix()
397 public boolean getShowJVSuffix()
399 return viewStyle.getShowJVSuffix();
404 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
407 public void setShowJVSuffix(boolean b)
409 viewStyle.setShowJVSuffix(b);
414 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
417 public void setWrapAlignment(boolean state)
419 viewStyle.setWrapAlignment(state);
420 ranges.setWrappedMode(state);
425 * @see jalview.api.ViewStyleI#setShowText(boolean)
428 public void setShowText(boolean state)
430 viewStyle.setShowText(state);
435 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
438 public void setRenderGaps(boolean state)
440 viewStyle.setRenderGaps(state);
445 * @see jalview.api.ViewStyleI#getColourText()
448 public boolean getColourText()
450 return viewStyle.getColourText();
455 * @see jalview.api.ViewStyleI#setColourText(boolean)
458 public void setColourText(boolean state)
460 viewStyle.setColourText(state);
465 * @see jalview.api.ViewStyleI#getWrapAlignment()
468 public boolean getWrapAlignment()
470 return viewStyle.getWrapAlignment();
475 * @see jalview.api.ViewStyleI#getShowText()
478 public boolean getShowText()
480 return viewStyle.getShowText();
485 * @see jalview.api.ViewStyleI#getWrappedWidth()
488 public int getWrappedWidth()
490 return viewStyle.getWrappedWidth();
495 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
498 public void setWrappedWidth(int w)
500 viewStyle.setWrappedWidth(w);
505 * @see jalview.api.ViewStyleI#getCharHeight()
508 public int getCharHeight()
510 return viewStyle.getCharHeight();
515 * @see jalview.api.ViewStyleI#setCharHeight(int)
518 public void setCharHeight(int h)
520 viewStyle.setCharHeight(h);
525 * @see jalview.api.ViewStyleI#getCharWidth()
528 public int getCharWidth()
530 return viewStyle.getCharWidth();
535 * @see jalview.api.ViewStyleI#setCharWidth(int)
538 public void setCharWidth(int w)
540 viewStyle.setCharWidth(w);
545 * @see jalview.api.ViewStyleI#getShowBoxes()
548 public boolean getShowBoxes()
550 return viewStyle.getShowBoxes();
555 * @see jalview.api.ViewStyleI#getShowUnconserved()
558 public boolean getShowUnconserved()
560 return viewStyle.getShowUnconserved();
564 * @param showunconserved
565 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
568 public void setShowUnconserved(boolean showunconserved)
570 viewStyle.setShowUnconserved(showunconserved);
575 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
578 public void setSeqNameItalics(boolean default1)
580 viewStyle.setSeqNameItalics(default1);
584 public AlignmentI getAlignment()
590 public char getGapCharacter()
592 return alignment.getGapCharacter();
595 protected String sequenceSetID;
598 * probably unused indicator that view is of a dataset rather than an
601 protected boolean isDataset = false;
603 public void setDataset(boolean b)
608 public boolean isDataset()
613 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
615 protected ColumnSelection colSel = new ColumnSelection();
617 public boolean autoCalculateConsensus = true;
619 protected boolean autoCalculateStrucConsensus = true;
621 protected boolean ignoreGapsInConsensusCalculation = false;
623 protected ResidueShaderI residueShading = new ResidueShader();
626 public void setGlobalColourScheme(ColourSchemeI cs)
628 // TODO: logic refactored from AlignFrame changeColour -
629 // TODO: autorecalc stuff should be changed to rely on the worker system
630 // check to see if we should implement a changeColour(cs) method rather than
631 // put the logic in here
632 // - means that caller decides if they want to just modify state and defer
633 // calculation till later or to do all calculations in thread.
637 * only instantiate alignment colouring once, thereafter update it;
638 * this means that any conservation or PID threshold settings
639 * persist when the alignment colour scheme is changed
641 if (residueShading == null)
643 residueShading = new ResidueShader(viewStyle);
645 residueShading.setColourScheme(cs);
647 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
648 // ...problem: groups need these, but do not currently have a ViewStyle
652 if (getConservationSelected())
654 residueShading.setConservation(hconservation);
657 * reset conservation flag in case just set to false if
658 * Conservation was null (calculation still in progress)
660 residueShading.setConservationApplied(getConservationSelected());
661 residueShading.alignmentChanged(alignment, hiddenRepSequences);
665 * if 'apply colour to all groups' is selected... do so
666 * (but don't transfer any colour threshold settings to groups)
668 if (getColourAppliesToAllGroups())
670 for (SequenceGroup sg : getAlignment().getGroups())
673 * retain any colour thresholds per group while
674 * changing choice of colour scheme (JAL-2386)
676 sg.setColourScheme(cs == null ? null : cs.getInstance(this, sg));
679 sg.getGroupColourScheme().alignmentChanged(sg,
687 public ColourSchemeI getGlobalColourScheme()
689 return residueShading == null ? null : residueShading.getColourScheme();
693 public ResidueShaderI getResidueShading()
695 return residueShading;
698 protected AlignmentAnnotation consensus;
700 protected AlignmentAnnotation complementConsensus;
702 protected AlignmentAnnotation gapcounts;
704 protected AlignmentAnnotation strucConsensus;
706 protected AlignmentAnnotation conservation;
708 protected AlignmentAnnotation quality;
710 protected AlignmentAnnotation[] groupConsensus;
712 protected AlignmentAnnotation[] groupConservation;
715 * results of alignment consensus analysis for visible portion of view
717 protected ProfilesI hconsensus = null;
720 * results of cDNA complement consensus visible portion of view
722 protected Hashtable<String, Object>[] hcomplementConsensus = null;
725 * results of secondary structure base pair consensus for visible portion of
728 protected Hashtable<String, Object>[] hStrucConsensus = null;
730 protected Conservation hconservation = null;
733 public void setConservation(Conservation cons)
735 hconservation = cons;
739 * percentage gaps allowed in a column before all amino acid properties should
740 * be considered unconserved
742 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
745 public int getConsPercGaps()
751 public void setSequenceConsensusHash(ProfilesI hconsensus)
753 this.hconsensus = hconsensus;
757 public void setComplementConsensusHash(
758 Hashtable<String, Object>[] hconsensus)
760 this.hcomplementConsensus = hconsensus;
764 public ProfilesI getSequenceConsensusHash()
770 public Hashtable<String, Object>[] getComplementConsensusHash()
772 return hcomplementConsensus;
776 public Hashtable<String, Object>[] getRnaStructureConsensusHash()
778 return hStrucConsensus;
782 public void setRnaStructureConsensusHash(
783 Hashtable<String, Object>[] hStrucConsensus)
785 this.hStrucConsensus = hStrucConsensus;
790 public AlignmentAnnotation getAlignmentQualityAnnot()
796 public AlignmentAnnotation getAlignmentConservationAnnotation()
802 public AlignmentAnnotation getAlignmentConsensusAnnotation()
808 public AlignmentAnnotation getAlignmentGapAnnotation()
814 public AlignmentAnnotation getComplementConsensusAnnotation()
816 return complementConsensus;
820 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
822 return strucConsensus;
825 protected AlignCalcManagerI calculator = new AlignCalcManager();
828 * trigger update of conservation annotation
830 public void updateConservation(final AlignmentViewPanel ap)
832 // see note in mantis : issue number 8585
833 if (alignment.isNucleotide()
834 || (conservation == null && quality == null)
835 || !autoCalculateConsensus)
839 if (calculator.getRegisteredWorkersOfClass(
840 jalview.workers.ConservationThread.class) == null)
842 calculator.registerWorker(
843 new jalview.workers.ConservationThread(this, ap));
848 * trigger update of consensus annotation
850 public void updateConsensus(final AlignmentViewPanel ap)
852 // see note in mantis : issue number 8585
853 if (consensus == null || !autoCalculateConsensus)
858 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
860 calculator.registerWorker(new ConsensusThread(this, ap));
864 * A separate thread to compute cDNA consensus for a protein alignment
865 * which has mapping to cDNA
867 final AlignmentI al = this.getAlignment();
868 if (!al.isNucleotide() && al.getCodonFrames() != null
869 && !al.getCodonFrames().isEmpty())
872 * fudge - check first for protein-to-nucleotide mappings
873 * (we don't want to do this for protein-to-protein)
875 boolean doConsensus = false;
876 for (AlignedCodonFrame mapping : al.getCodonFrames())
878 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
879 MapList[] mapLists = mapping.getdnaToProt();
880 // mapLists can be empty if project load has not finished resolving seqs
881 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
889 if (calculator.getRegisteredWorkersOfClass(
890 ComplementConsensusThread.class) == null)
893 .registerWorker(new ComplementConsensusThread(this, ap));
899 // --------START Structure Conservation
900 public void updateStrucConsensus(final AlignmentViewPanel ap)
902 if (autoCalculateStrucConsensus && strucConsensus == null
903 && alignment.isNucleotide() && alignment.hasRNAStructure())
905 // secondary structure has been added - so init the consensus line
909 // see note in mantis : issue number 8585
910 if (strucConsensus == null || !autoCalculateStrucConsensus)
914 if (calculator.getRegisteredWorkersOfClass(
915 StrucConsensusThread.class) == null)
917 calculator.registerWorker(new StrucConsensusThread(this, ap));
921 public boolean isCalcInProgress()
923 return calculator.isWorking();
927 public boolean isCalculationInProgress(
928 AlignmentAnnotation alignmentAnnotation)
930 if (!alignmentAnnotation.autoCalculated)
934 if (calculator.workingInvolvedWith(alignmentAnnotation))
936 // System.err.println("grey out ("+alignmentAnnotation.label+")");
942 public void setAlignment(AlignmentI align)
944 this.alignment = align;
948 * Clean up references when this viewport is closed
951 public void dispose()
954 * defensively null out references to large objects in case
955 * this object is not garbage collected (as if!)
958 complementConsensus = null;
959 strucConsensus = null;
962 groupConsensus = null;
963 groupConservation = null;
965 hconservation = null;
966 hcomplementConsensus = null;
969 residueShading = null; // may hold a reference to Consensus
970 changeSupport = null;
973 selectionGroup = null;
979 public boolean isClosed()
981 // TODO: check that this isClosed is only true after panel is closed, not
982 // before it is fully constructed.
983 return alignment == null;
987 public AlignCalcManagerI getCalcManager()
993 * should conservation rows be shown for groups
995 protected boolean showGroupConservation = false;
998 * should consensus rows be shown for groups
1000 protected boolean showGroupConsensus = false;
1003 * should consensus profile be rendered by default
1005 protected boolean showSequenceLogo = false;
1008 * should consensus profile be rendered normalised to row height
1010 protected boolean normaliseSequenceLogo = false;
1013 * should consensus histograms be rendered by default
1015 protected boolean showConsensusHistogram = true;
1018 * @return the showConsensusProfile
1021 public boolean isShowSequenceLogo()
1023 return showSequenceLogo;
1027 * @param showSequenceLogo
1030 public void setShowSequenceLogo(boolean showSequenceLogo)
1032 if (showSequenceLogo != this.showSequenceLogo)
1034 // TODO: decouple settings setting from calculation when refactoring
1035 // annotation update method from alignframe to viewport
1036 this.showSequenceLogo = showSequenceLogo;
1037 calculator.updateAnnotationFor(ConsensusThread.class);
1038 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1039 calculator.updateAnnotationFor(StrucConsensusThread.class);
1041 this.showSequenceLogo = showSequenceLogo;
1045 * @param showConsensusHistogram
1046 * the showConsensusHistogram to set
1048 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1050 this.showConsensusHistogram = showConsensusHistogram;
1054 * @return the showGroupConservation
1056 public boolean isShowGroupConservation()
1058 return showGroupConservation;
1062 * @param showGroupConservation
1063 * the showGroupConservation to set
1065 public void setShowGroupConservation(boolean showGroupConservation)
1067 this.showGroupConservation = showGroupConservation;
1071 * @return the showGroupConsensus
1073 public boolean isShowGroupConsensus()
1075 return showGroupConsensus;
1079 * @param showGroupConsensus
1080 * the showGroupConsensus to set
1082 public void setShowGroupConsensus(boolean showGroupConsensus)
1084 this.showGroupConsensus = showGroupConsensus;
1089 * @return flag to indicate if the consensus histogram should be rendered by
1093 public boolean isShowConsensusHistogram()
1095 return this.showConsensusHistogram;
1099 * when set, updateAlignment will always ensure sequences are of equal length
1101 private boolean padGaps = false;
1104 * when set, alignment should be reordered according to a newly opened tree
1106 public boolean sortByTree = false;
1111 * @return null or the currently selected sequence region
1114 public SequenceGroup getSelectionGroup()
1116 return selectionGroup;
1120 * Set the selection group for this window. Also sets the current alignment as
1121 * the context for the group, if it does not already have one.
1124 * - group holding references to sequences in this alignment view
1128 public void setSelectionGroup(SequenceGroup sg)
1130 selectionGroup = sg;
1131 if (sg != null && sg.getContext() == null)
1133 sg.setContext(alignment);
1137 public void setHiddenColumns(HiddenColumns hidden)
1139 this.alignment.setHiddenColumns(hidden);
1143 public ColumnSelection getColumnSelection()
1149 public void setColumnSelection(ColumnSelection colSel)
1151 this.colSel = colSel;
1154 updateHiddenColumns();
1156 isColSelChanged(true);
1164 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1166 return hiddenRepSequences;
1170 public void setHiddenRepSequences(
1171 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1173 this.hiddenRepSequences = hiddenRepSequences;
1177 public boolean hasSelectedColumns()
1179 ColumnSelection columnSelection = getColumnSelection();
1180 return columnSelection != null && columnSelection.hasSelectedColumns();
1184 public boolean hasHiddenColumns()
1186 return alignment.getHiddenColumns() != null
1187 && alignment.getHiddenColumns().hasHiddenColumns();
1190 public void updateHiddenColumns()
1192 // this method doesn't really do anything now. But - it could, since a
1193 // column Selection could be in the process of modification
1194 // hasHiddenColumns = colSel.hasHiddenColumns();
1198 public boolean hasHiddenRows()
1200 return alignment.getHiddenSequences().getSize() > 0;
1203 protected SequenceGroup selectionGroup;
1205 public void setSequenceSetId(String newid)
1207 if (sequenceSetID != null)
1210 "Warning - overwriting a sequenceSetId for a viewport!");
1212 sequenceSetID = new String(newid);
1216 public String getSequenceSetId()
1218 if (sequenceSetID == null)
1220 sequenceSetID = alignment.hashCode() + "";
1223 return sequenceSetID;
1227 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1230 protected String viewId = null;
1233 public String getViewId()
1237 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1242 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1244 ignoreGapsInConsensusCalculation = b;
1247 updateConsensus(ap);
1248 if (residueShading != null)
1250 residueShading.setThreshold(residueShading.getThreshold(),
1251 ignoreGapsInConsensusCalculation);
1257 private long sgrouphash = -1, colselhash = -1;
1260 * checks current SelectionGroup against record of last hash value, and
1264 * update the record of last hash value
1266 * @return true if SelectionGroup changed since last call (when b is true)
1268 public boolean isSelectionGroupChanged(boolean b)
1270 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1271 : selectionGroup.hashCode();
1272 if (hc != -1 && hc != sgrouphash)
1284 * checks current colsel against record of last hash value, and optionally
1288 * update the record of last hash value
1289 * @return true if colsel changed since last call (when b is true)
1291 public boolean isColSelChanged(boolean b)
1293 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1294 if (hc != -1 && hc != colselhash)
1306 public boolean isIgnoreGapsConsensus()
1308 return ignoreGapsInConsensusCalculation;
1311 // property change stuff
1312 // JBPNote Prolly only need this in the applet version.
1313 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1316 protected boolean showConservation = true;
1318 protected boolean showQuality = true;
1320 protected boolean showConsensus = true;
1322 protected boolean showOccupancy = true;
1324 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1326 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1328 protected boolean showAutocalculatedAbove;
1331 * when set, view will scroll to show the highlighted position
1333 private boolean followHighlight = true;
1336 * Property change listener for changes in alignment
1341 public void addPropertyChangeListener(
1342 java.beans.PropertyChangeListener listener)
1344 changeSupport.addPropertyChangeListener(listener);
1353 public void removePropertyChangeListener(
1354 java.beans.PropertyChangeListener listener)
1356 if (changeSupport != null)
1358 changeSupport.removePropertyChangeListener(listener);
1363 * Property change listener for changes in alignment
1372 public void firePropertyChange(String prop, Object oldvalue,
1375 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1378 // common hide/show column stuff
1380 public void hideSelectedColumns()
1382 if (colSel.isEmpty())
1387 colSel.hideSelectedColumns(alignment);
1388 setSelectionGroup(null);
1389 isColSelChanged(true);
1392 public void hideColumns(int start, int end)
1396 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1400 alignment.getHiddenColumns().hideColumns(start, end);
1402 isColSelChanged(true);
1405 public void showColumn(int col)
1407 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1408 isColSelChanged(true);
1411 public void showAllHiddenColumns()
1413 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1414 isColSelChanged(true);
1417 // common hide/show seq stuff
1418 public void showAllHiddenSeqs()
1420 int startSeq = ranges.getStartSeq();
1421 int endSeq = ranges.getEndSeq();
1423 if (alignment.getHiddenSequences().getSize() > 0)
1425 if (selectionGroup == null)
1427 selectionGroup = new SequenceGroup();
1428 selectionGroup.setEndRes(alignment.getWidth() - 1);
1430 List<SequenceI> tmp = alignment.getHiddenSequences()
1431 .showAll(hiddenRepSequences);
1432 for (SequenceI seq : tmp)
1434 selectionGroup.addSequence(seq, false);
1435 setSequenceAnnotationsVisible(seq, true);
1438 hiddenRepSequences = null;
1440 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1442 firePropertyChange("alignment", null, alignment.getSequences());
1443 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1449 public void showSequence(int index)
1451 int startSeq = ranges.getStartSeq();
1452 int endSeq = ranges.getEndSeq();
1454 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1455 hiddenRepSequences);
1458 if (selectionGroup == null)
1460 selectionGroup = new SequenceGroup();
1461 selectionGroup.setEndRes(alignment.getWidth() - 1);
1464 for (SequenceI seq : tmp)
1466 selectionGroup.addSequence(seq, false);
1467 setSequenceAnnotationsVisible(seq, true);
1470 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1472 firePropertyChange("alignment", null, alignment.getSequences());
1477 public void hideAllSelectedSeqs()
1479 if (selectionGroup == null || selectionGroup.getSize() < 1)
1484 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1488 setSelectionGroup(null);
1491 public void hideSequence(SequenceI[] seq)
1494 * cache offset to first visible sequence
1496 int startSeq = ranges.getStartSeq();
1500 for (int i = 0; i < seq.length; i++)
1502 alignment.getHiddenSequences().hideSequence(seq[i]);
1503 setSequenceAnnotationsVisible(seq[i], false);
1505 ranges.setStartSeq(startSeq);
1506 firePropertyChange("alignment", null, alignment.getSequences());
1511 * Hides the specified sequence, or the sequences it represents
1514 * the sequence to hide, or keep as representative
1515 * @param representGroup
1516 * if true, hide the current selection group except for the
1517 * representative sequence
1519 public void hideSequences(SequenceI sequence, boolean representGroup)
1521 if (selectionGroup == null || selectionGroup.getSize() < 1)
1523 hideSequence(new SequenceI[] { sequence });
1529 hideRepSequences(sequence, selectionGroup);
1530 setSelectionGroup(null);
1534 int gsize = selectionGroup.getSize();
1535 SequenceI[] hseqs = selectionGroup.getSequences()
1536 .toArray(new SequenceI[gsize]);
1538 hideSequence(hseqs);
1539 setSelectionGroup(null);
1544 * Set visibility for any annotations for the given sequence.
1548 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1551 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1554 for (AlignmentAnnotation ann : anns)
1556 if (ann.sequenceRef == sequenceI)
1558 ann.visible = visible;
1564 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1566 int sSize = sg.getSize();
1572 if (hiddenRepSequences == null)
1574 hiddenRepSequences = new Hashtable<>();
1577 hiddenRepSequences.put(repSequence, sg);
1579 // Hide all sequences except the repSequence
1580 SequenceI[] seqs = new SequenceI[sSize - 1];
1582 for (int i = 0; i < sSize; i++)
1584 if (sg.getSequenceAt(i) != repSequence)
1586 if (index == sSize - 1)
1591 seqs[index++] = sg.getSequenceAt(i);
1594 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1595 sg.setHidereps(true); // note: not done in 2.7applet
1602 * @return null or the current reference sequence
1604 public SequenceI getReferenceSeq()
1606 return alignment.getSeqrep();
1611 * @return true iff seq is the reference for the alignment
1613 public boolean isReferenceSeq(SequenceI seq)
1615 return alignment.getSeqrep() == seq;
1621 * @return true if there are sequences represented by this sequence that are
1624 public boolean isHiddenRepSequence(SequenceI seq)
1626 return (hiddenRepSequences != null
1627 && hiddenRepSequences.containsKey(seq));
1633 * @return null or a sequence group containing the sequences that seq
1636 public SequenceGroup getRepresentedSequences(SequenceI seq)
1638 return (SequenceGroup) (hiddenRepSequences == null ? null
1639 : hiddenRepSequences.get(seq));
1643 public int adjustForHiddenSeqs(int alignmentIndex)
1645 return alignment.getHiddenSequences()
1646 .adjustForHiddenSeqs(alignmentIndex);
1650 public void invertColumnSelection()
1652 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1653 isColSelChanged(true);
1657 public SequenceI[] getSelectionAsNewSequence()
1659 SequenceI[] sequences;
1660 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1661 // this was the only caller in the applet for this method
1662 // JBPNote: in applet, this method returned references to the alignment
1663 // sequences, and it did not honour the presence/absence of annotation
1664 // attached to the alignment (probably!)
1665 if (selectionGroup == null || selectionGroup.getSize() == 0)
1667 sequences = alignment.getSequencesArray();
1668 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1669 for (int i = 0; i < sequences.length; i++)
1671 // construct new sequence with subset of visible annotation
1672 sequences[i] = new Sequence(sequences[i], annots);
1677 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1684 public SequenceI[] getSequenceSelection()
1686 SequenceI[] sequences = null;
1687 if (selectionGroup != null)
1689 sequences = selectionGroup.getSequencesInOrder(alignment);
1691 if (sequences == null)
1693 sequences = alignment.getSequencesArray();
1699 public jalview.datamodel.AlignmentView getAlignmentView(
1700 boolean selectedOnly)
1702 return getAlignmentView(selectedOnly, false);
1706 public jalview.datamodel.AlignmentView getAlignmentView(
1707 boolean selectedOnly, boolean markGroups)
1709 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1711 alignment.getHiddenColumns() != null
1712 && alignment.getHiddenColumns().hasHiddenColumns(),
1713 selectedOnly, markGroups);
1717 public String[] getViewAsString(boolean selectedRegionOnly)
1719 return getViewAsString(selectedRegionOnly, true);
1723 public String[] getViewAsString(boolean selectedRegionOnly,
1724 boolean exportHiddenSeqs)
1726 String[] selection = null;
1727 SequenceI[] seqs = null;
1729 int start = 0, end = 0;
1730 if (selectedRegionOnly && selectionGroup != null)
1732 iSize = selectionGroup.getSize();
1733 seqs = selectionGroup.getSequencesInOrder(alignment);
1734 start = selectionGroup.getStartRes();
1735 end = selectionGroup.getEndRes() + 1;
1739 if (hasHiddenRows() && exportHiddenSeqs)
1741 AlignmentI fullAlignment = alignment.getHiddenSequences()
1742 .getFullAlignment();
1743 iSize = fullAlignment.getHeight();
1744 seqs = fullAlignment.getSequencesArray();
1745 end = fullAlignment.getWidth();
1749 iSize = alignment.getHeight();
1750 seqs = alignment.getSequencesArray();
1751 end = alignment.getWidth();
1755 selection = new String[iSize];
1756 if (alignment.getHiddenColumns() != null
1757 && alignment.getHiddenColumns().hasHiddenColumns())
1759 for (i = 0; i < iSize; i++)
1761 Iterator<int[]> blocks = alignment.getHiddenColumns()
1762 .getVisContigsIterator(start, end + 1, false);
1763 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1768 for (i = 0; i < iSize; i++)
1770 selection[i] = seqs[i].getSequenceAsString(start, end);
1778 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1780 ArrayList<int[]> regions = new ArrayList<>();
1786 HiddenColumns hidden = alignment.getHiddenColumns();
1787 if (hidden != null && hidden.hasHiddenColumns())
1791 start = hidden.visibleToAbsoluteColumn(start);
1794 end = hidden.getNextHiddenBoundary(false, start);
1805 regions.add(new int[] { start, end });
1807 if (hidden != null && hidden.hasHiddenColumns())
1809 start = hidden.visibleToAbsoluteColumn(end);
1810 start = hidden.getNextHiddenBoundary(true, start) + 1;
1812 } while (end < max);
1814 // int[][] startEnd = new int[regions.size()][2];
1820 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1821 boolean selectedOnly)
1823 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1824 AlignmentAnnotation[] aa;
1825 if ((aa = alignment.getAlignmentAnnotation()) != null)
1827 for (AlignmentAnnotation annot : aa)
1829 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1830 if (selectedOnly && selectionGroup != null)
1832 clone.makeVisibleAnnotation(selectionGroup.getStartRes(),
1833 selectionGroup.getEndRes(), alignment.getHiddenColumns());
1837 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1846 public boolean isPadGaps()
1852 public void setPadGaps(boolean padGaps)
1854 this.padGaps = padGaps;
1858 * apply any post-edit constraints and trigger any calculations needed after
1859 * an edit has been performed on the alignment
1864 public void alignmentChanged(AlignmentViewPanel ap)
1868 alignment.padGaps();
1870 if (autoCalculateConsensus)
1872 updateConsensus(ap);
1874 if (hconsensus != null && autoCalculateConsensus)
1876 updateConservation(ap);
1878 if (autoCalculateStrucConsensus)
1880 updateStrucConsensus(ap);
1883 // Reset endRes of groups if beyond alignment width
1884 int alWidth = alignment.getWidth();
1885 List<SequenceGroup> groups = alignment.getGroups();
1888 for (SequenceGroup sg : groups)
1890 if (sg.getEndRes() > alWidth)
1892 sg.setEndRes(alWidth - 1);
1897 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1899 selectionGroup.setEndRes(alWidth - 1);
1902 updateAllColourSchemes();
1903 calculator.restartWorkers();
1904 // alignment.adjustSequenceAnnotations();
1908 * reset scope and do calculations for all applied colourschemes on alignment
1910 void updateAllColourSchemes()
1912 ResidueShaderI rs = residueShading;
1915 rs.alignmentChanged(alignment, hiddenRepSequences);
1917 rs.setConsensus(hconsensus);
1918 if (rs.conservationApplied())
1920 rs.setConservation(Conservation.calculateConservation("All",
1921 alignment.getSequences(), 0, alignment.getWidth(), false,
1922 getConsPercGaps(), false));
1926 for (SequenceGroup sg : alignment.getGroups())
1930 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1932 sg.recalcConservation();
1936 protected void initAutoAnnotation()
1938 // TODO: add menu option action that nulls or creates consensus object
1939 // depending on if the user wants to see the annotation or not in a
1940 // specific alignment
1942 if (hconsensus == null && !isDataset)
1944 if (!alignment.isNucleotide())
1953 consensus = new AlignmentAnnotation("Consensus",
1954 MessageManager.getString("label.consensus_descr"),
1955 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1956 initConsensus(consensus);
1959 initComplementConsensus();
1964 * If this is a protein alignment and there are mappings to cDNA, adds the
1965 * cDNA consensus annotation and returns true, else returns false.
1967 public boolean initComplementConsensus()
1969 if (!alignment.isNucleotide())
1971 final List<AlignedCodonFrame> codonMappings = alignment
1973 if (codonMappings != null && !codonMappings.isEmpty())
1975 boolean doConsensus = false;
1976 for (AlignedCodonFrame mapping : codonMappings)
1978 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1979 MapList[] mapLists = mapping.getdnaToProt();
1980 // mapLists can be empty if project load has not finished resolving
1982 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1990 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1992 .getString("label.complement_consensus_descr"),
1993 new Annotation[1], 0f, 100f,
1994 AlignmentAnnotation.BAR_GRAPH);
1995 initConsensus(complementConsensus);
2003 private void initConsensus(AlignmentAnnotation aa)
2006 aa.autoCalculated = true;
2010 alignment.addAnnotation(aa);
2014 // these should be extracted from the view model - style and settings for
2015 // derived annotation
2016 private void initGapCounts()
2020 gapcounts = new AlignmentAnnotation("Occupancy",
2021 MessageManager.getString("label.occupancy_descr"),
2022 new Annotation[1], 0f, alignment.getHeight(),
2023 AlignmentAnnotation.BAR_GRAPH);
2024 gapcounts.hasText = true;
2025 gapcounts.autoCalculated = true;
2026 gapcounts.scaleColLabel = true;
2027 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2029 alignment.addAnnotation(gapcounts);
2033 private void initConservation()
2035 if (showConservation)
2037 if (conservation == null)
2039 conservation = new AlignmentAnnotation("Conservation",
2040 MessageManager.formatMessage("label.conservation_descr",
2042 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2043 conservation.hasText = true;
2044 conservation.autoCalculated = true;
2045 alignment.addAnnotation(conservation);
2050 private void initQuality()
2054 if (quality == null)
2056 quality = new AlignmentAnnotation("Quality",
2057 MessageManager.getString("label.quality_descr"),
2058 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2059 quality.hasText = true;
2060 quality.autoCalculated = true;
2061 alignment.addAnnotation(quality);
2066 private void initRNAStructure()
2068 if (alignment.hasRNAStructure() && strucConsensus == null)
2070 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2071 MessageManager.getString("label.strucconsensus_descr"),
2072 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2073 strucConsensus.hasText = true;
2074 strucConsensus.autoCalculated = true;
2078 alignment.addAnnotation(strucConsensus);
2086 * @see jalview.api.AlignViewportI#calcPanelHeight()
2089 public int calcPanelHeight()
2091 // setHeight of panels
2092 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2094 int charHeight = getCharHeight();
2097 BitSet graphgrp = new BitSet();
2098 for (AlignmentAnnotation aa : anns)
2102 System.err.println("Null annotation row: ignoring.");
2109 if (aa.graphGroup > -1)
2111 if (graphgrp.get(aa.graphGroup))
2117 graphgrp.set(aa.graphGroup);
2124 aa.height += charHeight;
2134 aa.height += aa.graphHeight;
2142 height += aa.height;
2154 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2155 boolean preserveNewGroupSettings)
2157 boolean updateCalcs = false;
2158 boolean conv = isShowGroupConservation();
2159 boolean cons = isShowGroupConsensus();
2160 boolean showprf = isShowSequenceLogo();
2161 boolean showConsHist = isShowConsensusHistogram();
2162 boolean normLogo = isNormaliseSequenceLogo();
2165 * TODO reorder the annotation rows according to group/sequence ordering on
2168 // boolean sortg = true;
2170 // remove old automatic annotation
2171 // add any new annotation
2173 // intersect alignment annotation with alignment groups
2175 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2176 List<SequenceGroup> oldrfs = new ArrayList<>();
2179 for (int an = 0; an < aan.length; an++)
2181 if (aan[an].autoCalculated && aan[an].groupRef != null)
2183 oldrfs.add(aan[an].groupRef);
2184 alignment.deleteAnnotation(aan[an], false);
2188 if (alignment.getGroups() != null)
2190 for (SequenceGroup sg : alignment.getGroups())
2192 updateCalcs = false;
2193 if (applyGlobalSettings
2194 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2196 // set defaults for this group's conservation/consensus
2197 sg.setshowSequenceLogo(showprf);
2198 sg.setShowConsensusHistogram(showConsHist);
2199 sg.setNormaliseSequenceLogo(normLogo);
2204 alignment.addAnnotation(sg.getConservationRow(), 0);
2209 alignment.addAnnotation(sg.getConsensus(), 0);
2211 // refresh the annotation rows
2214 sg.recalcConservation();
2222 public boolean isDisplayReferenceSeq()
2224 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2228 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2230 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2234 public boolean isColourByReferenceSeq()
2236 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2240 public Color getSequenceColour(SequenceI seq)
2242 Color sqc = sequenceColours.get(seq);
2243 return (sqc == null ? Color.white : sqc);
2247 public void setSequenceColour(SequenceI seq, Color col)
2251 sequenceColours.remove(seq);
2255 sequenceColours.put(seq, col);
2260 public void updateSequenceIdColours()
2262 for (SequenceGroup sg : alignment.getGroups())
2264 if (sg.idColour != null)
2266 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2268 sequenceColours.put(s, sg.idColour);
2275 public void clearSequenceColours()
2277 sequenceColours.clear();
2281 public AlignViewportI getCodingComplement()
2283 return this.codingComplement;
2287 * Set this as the (cDna/protein) complement of the given viewport. Also
2288 * ensures the reverse relationship is set on the given viewport.
2291 public void setCodingComplement(AlignViewportI av)
2295 System.err.println("Ignoring recursive setCodingComplement request");
2299 this.codingComplement = av;
2300 // avoid infinite recursion!
2301 if (av.getCodingComplement() != this)
2303 av.setCodingComplement(this);
2309 public boolean isNucleotide()
2311 return getAlignment() == null ? false : getAlignment().isNucleotide();
2315 public FeaturesDisplayedI getFeaturesDisplayed()
2317 return featuresDisplayed;
2321 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2323 featuresDisplayed = featuresDisplayedI;
2327 public boolean areFeaturesDisplayed()
2329 return featuresDisplayed != null
2330 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2337 * features are displayed if true
2340 public void setShowSequenceFeatures(boolean b)
2342 viewStyle.setShowSequenceFeatures(b);
2346 public boolean isShowSequenceFeatures()
2348 return viewStyle.isShowSequenceFeatures();
2352 public void setShowSequenceFeaturesHeight(boolean selected)
2354 viewStyle.setShowSequenceFeaturesHeight(selected);
2358 public boolean isShowSequenceFeaturesHeight()
2360 return viewStyle.isShowSequenceFeaturesHeight();
2364 public void setShowAnnotation(boolean b)
2366 viewStyle.setShowAnnotation(b);
2370 public boolean isShowAnnotation()
2372 return viewStyle.isShowAnnotation();
2376 public boolean isRightAlignIds()
2378 return viewStyle.isRightAlignIds();
2382 public void setRightAlignIds(boolean rightAlignIds)
2384 viewStyle.setRightAlignIds(rightAlignIds);
2388 public boolean getConservationSelected()
2390 return viewStyle.getConservationSelected();
2394 public void setShowBoxes(boolean state)
2396 viewStyle.setShowBoxes(state);
2401 * @see jalview.api.ViewStyleI#getTextColour()
2404 public Color getTextColour()
2406 return viewStyle.getTextColour();
2411 * @see jalview.api.ViewStyleI#getTextColour2()
2414 public Color getTextColour2()
2416 return viewStyle.getTextColour2();
2421 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2424 public int getThresholdTextColour()
2426 return viewStyle.getThresholdTextColour();
2431 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2434 public boolean isConservationColourSelected()
2436 return viewStyle.isConservationColourSelected();
2441 * @see jalview.api.ViewStyleI#isRenderGaps()
2444 public boolean isRenderGaps()
2446 return viewStyle.isRenderGaps();
2451 * @see jalview.api.ViewStyleI#isShowColourText()
2454 public boolean isShowColourText()
2456 return viewStyle.isShowColourText();
2460 * @param conservationColourSelected
2461 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2464 public void setConservationColourSelected(
2465 boolean conservationColourSelected)
2467 viewStyle.setConservationColourSelected(conservationColourSelected);
2471 * @param showColourText
2472 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2475 public void setShowColourText(boolean showColourText)
2477 viewStyle.setShowColourText(showColourText);
2482 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2485 public void setTextColour(Color textColour)
2487 viewStyle.setTextColour(textColour);
2491 * @param thresholdTextColour
2492 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2495 public void setThresholdTextColour(int thresholdTextColour)
2497 viewStyle.setThresholdTextColour(thresholdTextColour);
2501 * @param textColour2
2502 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2505 public void setTextColour2(Color textColour2)
2507 viewStyle.setTextColour2(textColour2);
2511 public ViewStyleI getViewStyle()
2513 return new ViewStyle(viewStyle);
2517 public void setViewStyle(ViewStyleI settingsForView)
2519 viewStyle = new ViewStyle(settingsForView);
2520 if (residueShading != null)
2522 residueShading.setConservationApplied(
2523 settingsForView.isConservationColourSelected());
2528 public boolean sameStyle(ViewStyleI them)
2530 return viewStyle.sameStyle(them);
2535 * @see jalview.api.ViewStyleI#getIdWidth()
2538 public int getIdWidth()
2540 return viewStyle.getIdWidth();
2545 * @see jalview.api.ViewStyleI#setIdWidth(int)
2548 public void setIdWidth(int i)
2550 viewStyle.setIdWidth(i);
2555 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2558 public boolean isCentreColumnLabels()
2560 return viewStyle.isCentreColumnLabels();
2564 * @param centreColumnLabels
2565 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2568 public void setCentreColumnLabels(boolean centreColumnLabels)
2570 viewStyle.setCentreColumnLabels(centreColumnLabels);
2575 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2578 public void setShowDBRefs(boolean showdbrefs)
2580 viewStyle.setShowDBRefs(showdbrefs);
2585 * @see jalview.api.ViewStyleI#isShowDBRefs()
2588 public boolean isShowDBRefs()
2590 return viewStyle.isShowDBRefs();
2595 * @see jalview.api.ViewStyleI#isShowNPFeats()
2598 public boolean isShowNPFeats()
2600 return viewStyle.isShowNPFeats();
2604 * @param shownpfeats
2605 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2608 public void setShowNPFeats(boolean shownpfeats)
2610 viewStyle.setShowNPFeats(shownpfeats);
2613 public abstract StructureSelectionManager getStructureSelectionManager();
2616 * Add one command to the command history list.
2620 public void addToHistoryList(CommandI command)
2622 if (this.historyList != null)
2624 this.historyList.push(command);
2625 broadcastCommand(command, false);
2626 setSavedUpToDate(false);
2627 Jalview2XML.setStateSavedUpToDate(false);
2631 protected void broadcastCommand(CommandI command, boolean undo)
2633 getStructureSelectionManager().commandPerformed(command, undo,
2638 * Add one command to the command redo list.
2642 public void addToRedoList(CommandI command)
2644 if (this.redoList != null)
2646 this.redoList.push(command);
2648 broadcastCommand(command, true);
2652 * Clear the command redo list.
2654 public void clearRedoList()
2656 if (this.redoList != null)
2658 this.redoList.clear();
2662 public void setHistoryList(Deque<CommandI> list)
2664 this.historyList = list;
2667 public Deque<CommandI> getHistoryList()
2669 return this.historyList;
2672 public void setRedoList(Deque<CommandI> list)
2674 this.redoList = list;
2677 public Deque<CommandI> getRedoList()
2679 return this.redoList;
2683 public VamsasSource getVamsasSource()
2688 public SequenceAnnotationOrder getSortAnnotationsBy()
2690 return sortAnnotationsBy;
2693 public void setSortAnnotationsBy(
2694 SequenceAnnotationOrder sortAnnotationsBy)
2696 this.sortAnnotationsBy = sortAnnotationsBy;
2699 public boolean isShowAutocalculatedAbove()
2701 return showAutocalculatedAbove;
2704 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2706 this.showAutocalculatedAbove = showAutocalculatedAbove;
2710 public boolean isScaleProteinAsCdna()
2712 return viewStyle.isScaleProteinAsCdna();
2716 public void setScaleProteinAsCdna(boolean b)
2718 viewStyle.setScaleProteinAsCdna(b);
2722 public boolean isProteinFontAsCdna()
2724 return viewStyle.isProteinFontAsCdna();
2728 public void setProteinFontAsCdna(boolean b)
2730 viewStyle.setProteinFontAsCdna(b);
2734 public void setShowComplementFeatures(boolean b)
2736 viewStyle.setShowComplementFeatures(b);
2740 public boolean isShowComplementFeatures()
2742 return viewStyle.isShowComplementFeatures();
2746 public void setShowComplementFeaturesOnTop(boolean b)
2748 viewStyle.setShowComplementFeaturesOnTop(b);
2752 public boolean isShowComplementFeaturesOnTop()
2754 return viewStyle.isShowComplementFeaturesOnTop();
2758 * @return true if view should scroll to show the highlighted region of a
2763 public final boolean isFollowHighlight()
2765 return followHighlight;
2769 public final void setFollowHighlight(boolean b)
2771 this.followHighlight = b;
2775 public ViewportRanges getRanges()
2781 * Helper method to populate the SearchResults with the location in the
2782 * complementary alignment to scroll to, in order to match this one.
2785 * the SearchResults to add to
2786 * @return the offset (below top of visible region) of the matched sequence
2788 protected int findComplementScrollTarget(SearchResultsI sr)
2790 final AlignViewportI complement = getCodingComplement();
2791 if (complement == null || !complement.isFollowHighlight())
2795 boolean iAmProtein = !getAlignment().isNucleotide();
2796 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2797 : complement.getAlignment();
2798 if (proteinAlignment == null)
2802 final List<AlignedCodonFrame> mappings = proteinAlignment
2806 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2807 * residue in the middle column of the visible region. Scroll the
2808 * complementary alignment to line up the corresponding residue.
2811 SequenceI sequence = null;
2814 * locate 'middle' column (true middle if an odd number visible, left of
2815 * middle if an even number visible)
2817 int middleColumn = ranges.getStartRes()
2818 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2819 final HiddenSequences hiddenSequences = getAlignment()
2820 .getHiddenSequences();
2823 * searching to the bottom of the alignment gives smoother scrolling across
2824 * all gapped visible regions
2826 int lastSeq = alignment.getHeight() - 1;
2827 List<AlignedCodonFrame> seqMappings = null;
2828 for (int seqNo = ranges
2829 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2831 sequence = getAlignment().getSequenceAt(seqNo);
2832 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2836 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2840 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2842 getCodingComplement().getAlignment().getSequences());
2843 if (!seqMappings.isEmpty())
2849 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2852 * No ungapped mapped sequence in middle column - do nothing
2856 MappingUtils.addSearchResults(sr, sequence,
2857 sequence.findPosition(middleColumn), seqMappings);
2862 * synthesize a column selection if none exists so it covers the given
2863 * selection group. if wholewidth is false, no column selection is made if the
2864 * selection group covers the whole alignment width.
2869 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2872 if (sg != null && (sgs = sg.getStartRes()) >= 0
2873 && sg.getStartRes() <= (sge = sg.getEndRes())
2874 && !this.hasSelectedColumns())
2876 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2883 colSel = new ColumnSelection();
2885 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2887 colSel.addElement(cspos);
2893 * hold status of current selection group - defined on alignment or not.
2895 private boolean selectionIsDefinedGroup = false;
2898 public boolean isSelectionDefinedGroup()
2900 if (selectionGroup == null)
2904 if (isSelectionGroupChanged(true))
2906 selectionIsDefinedGroup = false;
2907 List<SequenceGroup> gps = alignment.getGroups();
2908 if (gps == null || gps.size() == 0)
2910 selectionIsDefinedGroup = false;
2914 selectionIsDefinedGroup = gps.contains(selectionGroup);
2917 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2921 * null, or currently highlighted results on this view
2923 private SearchResultsI searchResults = null;
2925 protected TreeModel currentTree = null;
2928 public boolean hasSearchResults()
2930 return searchResults != null;
2934 public void setSearchResults(SearchResultsI results)
2936 searchResults = results;
2940 public SearchResultsI getSearchResults()
2942 return searchResults;
2946 public ContactListI getContactList(AlignmentAnnotation _aa, int column)
2948 return alignment.getContactListFor(_aa, column);
2952 * get the consensus sequence as displayed under the PID consensus annotation
2955 * @return consensus sequence as a new sequence object
2957 public SequenceI getConsensusSeq()
2959 if (consensus == null)
2961 updateConsensus(null);
2963 if (consensus == null)
2967 StringBuffer seqs = new StringBuffer();
2968 for (int i = 0; i < consensus.annotations.length; i++)
2970 Annotation annotation = consensus.annotations[i];
2971 if (annotation != null)
2973 String description = annotation.description;
2974 if (description != null && description.startsWith("["))
2976 // consensus is a tie - just pick the first one
2977 seqs.append(description.charAt(1));
2981 seqs.append(annotation.displayCharacter);
2986 SequenceI sq = new Sequence("Consensus", seqs.toString());
2987 sq.setDescription("Percentage Identity Consensus "
2988 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
2993 public void setCurrentTree(TreeModel tree)
2999 public TreeModel getCurrentTree()
3005 public AlignmentExportData getAlignExportData(
3006 AlignExportSettingsI options)
3008 AlignmentI alignmentToExport = null;
3009 String[] omitHidden = null;
3010 alignmentToExport = null;
3012 if (hasHiddenColumns() && !options.isExportHiddenColumns())
3014 omitHidden = getViewAsString(false,
3015 options.isExportHiddenSequences());
3018 int[] alignmentStartEnd = new int[2];
3019 if (hasHiddenRows() && options.isExportHiddenSequences())
3021 alignmentToExport = getAlignment().getHiddenSequences()
3022 .getFullAlignment();
3026 alignmentToExport = getAlignment();
3028 alignmentStartEnd = getAlignment().getHiddenColumns()
3029 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
3030 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
3031 omitHidden, alignmentStartEnd);
3036 * flag set to indicate if structure views might be out of sync with sequences
3040 private boolean needToUpdateStructureViews = false;
3043 public boolean isUpdateStructures()
3045 return needToUpdateStructureViews;
3049 public void setUpdateStructures(boolean update)
3051 needToUpdateStructureViews = update;
3055 public boolean needToUpdateStructureViews()
3057 boolean update = needToUpdateStructureViews;
3058 needToUpdateStructureViews = false;
3063 public void addSequenceGroup(SequenceGroup sequenceGroup)
3065 alignment.addGroup(sequenceGroup);
3067 Color col = sequenceGroup.idColour;
3070 col = col.brighter();
3072 for (SequenceI sq : sequenceGroup.getSequences())
3074 setSequenceColour(sq, col);
3078 if (codingComplement != null)
3080 SequenceGroup mappedGroup = MappingUtils
3081 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3082 if (mappedGroup.getSequences().size() > 0)
3084 codingComplement.getAlignment().addGroup(mappedGroup);
3088 for (SequenceI seq : mappedGroup.getSequences())
3090 codingComplement.setSequenceColour(seq, col);
3094 // propagate the structure view update flag according to our own setting
3095 codingComplement.setUpdateStructures(needToUpdateStructureViews);
3100 public Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly)
3104 if (selectedRegionOnly && selectionGroup != null)
3106 start = selectionGroup.getStartRes();
3107 end = selectionGroup.getEndRes() + 1;
3111 end = alignment.getWidth();
3113 return (alignment.getHiddenColumns().getVisContigsIterator(start, end,
3117 public void setSavedUpToDate(boolean s)
3119 setSavedUpToDate(s, QuitHandler.Message.UNSAVED_CHANGES);
3122 public void setSavedUpToDate(boolean s, QuitHandler.Message m)
3125 "Setting " + this.getViewId() + " setSavedUpToDate to " + s);
3127 QuitHandler.setMessage(m);
3130 public boolean savedUpToDate()
3132 Console.debug("Returning " + this.getViewId() + " savedUpToDate value: "
3134 return savedUpToDate;