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.Connectivity;
37 import jalview.analysis.Conservation;
38 import jalview.analysis.TreeModel;
39 import jalview.api.AlignCalcManagerI;
40 import jalview.api.AlignExportSettingsI;
41 import jalview.api.AlignViewportI;
42 import jalview.api.AlignmentViewPanel;
43 import jalview.api.FeaturesDisplayedI;
44 import jalview.api.ViewStyleI;
45 import jalview.bin.Console;
46 import jalview.commands.CommandI;
47 import jalview.datamodel.AlignedCodonFrame;
48 import jalview.datamodel.AlignmentAnnotation;
49 import jalview.datamodel.AlignmentExportData;
50 import jalview.datamodel.AlignmentI;
51 import jalview.datamodel.AlignmentView;
52 import jalview.datamodel.Annotation;
53 import jalview.datamodel.ColumnSelection;
54 import jalview.datamodel.ContactListI;
55 import jalview.datamodel.ContactMatrixI;
56 import jalview.datamodel.HiddenColumns;
57 import jalview.datamodel.HiddenSequences;
58 import jalview.datamodel.ProfilesI;
59 import jalview.datamodel.SearchResultsI;
60 import jalview.datamodel.Sequence;
61 import jalview.datamodel.SequenceCollectionI;
62 import jalview.datamodel.SequenceGroup;
63 import jalview.datamodel.SequenceI;
64 import jalview.gui.QuitHandler;
65 import jalview.project.Jalview2XML;
66 import jalview.renderer.ResidueShader;
67 import jalview.renderer.ResidueShaderI;
68 import jalview.schemes.ColourSchemeI;
69 import jalview.structure.CommandListener;
70 import jalview.structure.StructureSelectionManager;
71 import jalview.structure.VamsasSource;
72 import jalview.util.Comparison;
73 import jalview.util.MapList;
74 import jalview.util.MappingUtils;
75 import jalview.util.MessageManager;
76 import jalview.viewmodel.styles.ViewStyle;
77 import jalview.workers.AlignCalcManager;
78 import jalview.workers.ComplementConsensusThread;
79 import jalview.workers.ConsensusThread;
80 import jalview.workers.SecondaryStructureConsensusThread;
81 import jalview.workers.StrucConsensusThread;
84 * base class holding visualization and analysis attributes and common logic for
85 * an active alignment view displayed in the GUI
90 public abstract class AlignmentViewport
91 implements AlignViewportI, CommandListener, VamsasSource
93 protected ViewportRanges ranges;
95 protected ViewStyleI viewStyle = new ViewStyle();
98 * A viewport that hosts the cDna view of this (protein), or vice versa (if
101 AlignViewportI codingComplement = null;
103 FeaturesDisplayedI featuresDisplayed = null;
105 protected Deque<CommandI> historyList = new ArrayDeque<>();
107 protected Deque<CommandI> redoList = new ArrayDeque<>();
110 * used to determine if quit should be confirmed
112 private boolean savedUpToDate = false;
115 * alignment displayed in the viewport. Please use get/setter
117 protected AlignmentI alignment;
119 public AlignmentViewport(AlignmentI al)
122 ranges = new ViewportRanges(al);
127 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
130 public void setFontName(String name)
132 viewStyle.setFontName(name);
137 * @see jalview.api.ViewStyleI#setFontStyle(int)
140 public void setFontStyle(int style)
142 viewStyle.setFontStyle(style);
147 * @see jalview.api.ViewStyleI#setFontSize(int)
150 public void setFontSize(int size)
152 viewStyle.setFontSize(size);
157 * @see jalview.api.ViewStyleI#getFontStyle()
160 public int getFontStyle()
162 return viewStyle.getFontStyle();
167 * @see jalview.api.ViewStyleI#getFontName()
170 public String getFontName()
172 return viewStyle.getFontName();
177 * @see jalview.api.ViewStyleI#getFontSize()
180 public int getFontSize()
182 return viewStyle.getFontSize();
186 * @param upperCasebold
187 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
190 public void setUpperCasebold(boolean upperCasebold)
192 viewStyle.setUpperCasebold(upperCasebold);
197 * @see jalview.api.ViewStyleI#isUpperCasebold()
200 public boolean isUpperCasebold()
202 return viewStyle.isUpperCasebold();
207 * @see jalview.api.ViewStyleI#isSeqNameItalics()
210 public boolean isSeqNameItalics()
212 return viewStyle.isSeqNameItalics();
216 * @param colourByReferenceSeq
217 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
220 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
222 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
227 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
230 public void setColourAppliesToAllGroups(boolean b)
232 viewStyle.setColourAppliesToAllGroups(b);
237 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
240 public boolean getColourAppliesToAllGroups()
242 return viewStyle.getColourAppliesToAllGroups();
247 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
250 public boolean getAbovePIDThreshold()
252 return viewStyle.getAbovePIDThreshold();
257 * @see jalview.api.ViewStyleI#setIncrement(int)
260 public void setIncrement(int inc)
262 viewStyle.setIncrement(inc);
267 * @see jalview.api.ViewStyleI#getIncrement()
270 public int getIncrement()
272 return viewStyle.getIncrement();
277 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
280 public void setConservationSelected(boolean b)
282 viewStyle.setConservationSelected(b);
287 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
290 public void setShowHiddenMarkers(boolean show)
292 viewStyle.setShowHiddenMarkers(show);
297 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
300 public boolean getShowHiddenMarkers()
302 return viewStyle.getShowHiddenMarkers();
307 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
310 public void setScaleRightWrapped(boolean b)
312 viewStyle.setScaleRightWrapped(b);
317 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
320 public void setScaleLeftWrapped(boolean b)
322 viewStyle.setScaleLeftWrapped(b);
327 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
330 public void setScaleAboveWrapped(boolean b)
332 viewStyle.setScaleAboveWrapped(b);
337 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
340 public boolean getScaleLeftWrapped()
342 return viewStyle.getScaleLeftWrapped();
347 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
350 public boolean getScaleAboveWrapped()
352 return viewStyle.getScaleAboveWrapped();
357 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
360 public boolean getScaleRightWrapped()
362 return viewStyle.getScaleRightWrapped();
367 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
370 public void setAbovePIDThreshold(boolean b)
372 viewStyle.setAbovePIDThreshold(b);
377 * @see jalview.api.ViewStyleI#setThreshold(int)
380 public void setThreshold(int thresh)
382 viewStyle.setThreshold(thresh);
387 * @see jalview.api.ViewStyleI#getThreshold()
390 public int getThreshold()
392 return viewStyle.getThreshold();
397 * @see jalview.api.ViewStyleI#getShowJVSuffix()
400 public boolean getShowJVSuffix()
402 return viewStyle.getShowJVSuffix();
407 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
410 public void setShowJVSuffix(boolean b)
412 viewStyle.setShowJVSuffix(b);
417 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
420 public void setWrapAlignment(boolean state)
422 viewStyle.setWrapAlignment(state);
423 ranges.setWrappedMode(state);
428 * @see jalview.api.ViewStyleI#setShowText(boolean)
431 public void setShowText(boolean state)
433 viewStyle.setShowText(state);
438 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
441 public void setRenderGaps(boolean state)
443 viewStyle.setRenderGaps(state);
448 * @see jalview.api.ViewStyleI#getColourText()
451 public boolean getColourText()
453 return viewStyle.getColourText();
458 * @see jalview.api.ViewStyleI#setColourText(boolean)
461 public void setColourText(boolean state)
463 viewStyle.setColourText(state);
468 * @see jalview.api.ViewStyleI#getWrapAlignment()
471 public boolean getWrapAlignment()
473 return viewStyle.getWrapAlignment();
478 * @see jalview.api.ViewStyleI#getShowText()
481 public boolean getShowText()
483 return viewStyle.getShowText();
488 * @see jalview.api.ViewStyleI#getWrappedWidth()
491 public int getWrappedWidth()
493 return viewStyle.getWrappedWidth();
498 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
501 public void setWrappedWidth(int w)
503 viewStyle.setWrappedWidth(w);
508 * @see jalview.api.ViewStyleI#getCharHeight()
511 public int getCharHeight()
513 return viewStyle.getCharHeight();
518 * @see jalview.api.ViewStyleI#setCharHeight(int)
521 public void setCharHeight(int h)
523 viewStyle.setCharHeight(h);
528 * @see jalview.api.ViewStyleI#getCharWidth()
531 public int getCharWidth()
533 return viewStyle.getCharWidth();
538 * @see jalview.api.ViewStyleI#setCharWidth(int)
541 public void setCharWidth(int w)
543 viewStyle.setCharWidth(w);
548 * @see jalview.api.ViewStyleI#getShowBoxes()
551 public boolean getShowBoxes()
553 return viewStyle.getShowBoxes();
558 * @see jalview.api.ViewStyleI#getShowUnconserved()
561 public boolean getShowUnconserved()
563 return viewStyle.getShowUnconserved();
567 * @param showunconserved
568 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
571 public void setShowUnconserved(boolean showunconserved)
573 viewStyle.setShowUnconserved(showunconserved);
578 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
581 public void setSeqNameItalics(boolean default1)
583 viewStyle.setSeqNameItalics(default1);
587 public AlignmentI getAlignment()
593 public char getGapCharacter()
595 return alignment.getGapCharacter();
598 protected String sequenceSetID;
601 * probably unused indicator that view is of a dataset rather than an
604 protected boolean isDataset = false;
606 public void setDataset(boolean b)
611 public boolean isDataset()
616 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
618 protected ColumnSelection colSel = new ColumnSelection();
620 public boolean autoCalculateConsensus = true;
622 protected boolean autoCalculateStrucConsensus = true;
624 protected boolean ignoreGapsInConsensusCalculation = false;
626 protected ResidueShaderI residueShading = new ResidueShader();
629 public void setGlobalColourScheme(ColourSchemeI cs)
631 // TODO: logic refactored from AlignFrame changeColour -
632 // TODO: autorecalc stuff should be changed to rely on the worker system
633 // check to see if we should implement a changeColour(cs) method rather than
634 // put the logic in here
635 // - means that caller decides if they want to just modify state and defer
636 // calculation till later or to do all calculations in thread.
640 * only instantiate alignment colouring once, thereafter update it;
641 * this means that any conservation or PID threshold settings
642 * persist when the alignment colour scheme is changed
644 if (residueShading == null)
646 residueShading = new ResidueShader(viewStyle);
648 residueShading.setColourScheme(cs);
650 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
651 // ...problem: groups need these, but do not currently have a ViewStyle
655 if (getConservationSelected())
657 residueShading.setConservation(hconservation);
660 * reset conservation flag in case just set to false if
661 * Conservation was null (calculation still in progress)
663 residueShading.setConservationApplied(getConservationSelected());
664 residueShading.alignmentChanged(alignment, hiddenRepSequences);
668 * if 'apply colour to all groups' is selected... do so
669 * (but don't transfer any colour threshold settings to groups)
671 if (getColourAppliesToAllGroups())
673 for (SequenceGroup sg : getAlignment().getGroups())
676 * retain any colour thresholds per group while
677 * changing choice of colour scheme (JAL-2386)
679 sg.setColourScheme(cs == null ? null : cs.getInstance(this, sg));
682 sg.getGroupColourScheme().alignmentChanged(sg,
690 public ColourSchemeI getGlobalColourScheme()
692 return residueShading == null ? null : residueShading.getColourScheme();
696 public ResidueShaderI getResidueShading()
698 return residueShading;
701 protected AlignmentAnnotation consensus;
703 protected AlignmentAnnotation secondaryStructureConsensus;
705 protected AlignmentAnnotation complementConsensus;
707 protected AlignmentAnnotation gapcounts;
709 protected AlignmentAnnotation strucConsensus;
711 protected AlignmentAnnotation conservation;
713 protected AlignmentAnnotation quality;
715 protected AlignmentAnnotation[] groupConsensus;
717 protected AlignmentAnnotation[] groupSSConsensus;
719 protected AlignmentAnnotation[] groupConservation;
722 * results of alignment consensus analysis for visible portion of view
724 protected ProfilesI hconsensus = null;
726 protected ProfilesI hSSConsensus = null;
731 * results of cDNA complement consensus visible portion of view
733 protected Hashtable<String, Object>[] hcomplementConsensus = null;
736 * results of secondary structure base pair consensus for visible portion of
739 protected Hashtable<String, Object>[] hStrucConsensus = null;
741 protected Conservation hconservation = null;
744 public void setConservation(Conservation cons)
746 hconservation = cons;
750 * percentage gaps allowed in a column before all amino acid properties should
751 * be considered unconserved
753 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
756 public int getConsPercGaps()
762 public void setSequenceConsensusHash(ProfilesI hconsensus)
764 this.hconsensus = hconsensus;
768 public void setSequenceSSConsensusHash(ProfilesI hSSConsensus)
770 this.hSSConsensus = hSSConsensus;
774 public void setComplementConsensusHash(
775 Hashtable<String, Object>[] hconsensus)
777 this.hcomplementConsensus = hconsensus;
781 public ProfilesI getSequenceConsensusHash()
787 public ProfilesI getSequenceSSConsensusHash()
793 public Hashtable<String, Object>[] getComplementConsensusHash()
795 return hcomplementConsensus;
799 public Hashtable<String, Object>[] getRnaStructureConsensusHash()
801 return hStrucConsensus;
805 public void setRnaStructureConsensusHash(
806 Hashtable<String, Object>[] hStrucConsensus)
808 this.hStrucConsensus = hStrucConsensus;
813 public AlignmentAnnotation getAlignmentQualityAnnot()
819 public AlignmentAnnotation getAlignmentConservationAnnotation()
825 public AlignmentAnnotation getAlignmentConsensusAnnotation()
832 public AlignmentAnnotation getAlignmentSecondaryStructureConsensusAnnotation()
834 return secondaryStructureConsensus;
839 public AlignmentAnnotation getAlignmentGapAnnotation()
845 public AlignmentAnnotation getComplementConsensusAnnotation()
847 return complementConsensus;
851 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
853 return strucConsensus;
856 protected AlignCalcManagerI calculator = new AlignCalcManager();
859 * trigger update of conservation annotation
861 public void updateConservation(final AlignmentViewPanel ap)
863 // see note in mantis : issue number 8585
864 if (alignment.isNucleotide()
865 || (conservation == null && quality == null)
866 || !autoCalculateConsensus)
870 if (calculator.getRegisteredWorkersOfClass(
871 jalview.workers.ConservationThread.class) == null)
873 calculator.registerWorker(
874 new jalview.workers.ConservationThread(this, ap));
879 * trigger update of consensus annotation
881 public void updateConsensus(final AlignmentViewPanel ap)
883 // see note in mantis : issue number 8585
884 if (consensus == null || !autoCalculateConsensus)
889 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
891 calculator.registerWorker(new ConsensusThread(this, ap));
895 * A separate thread to compute cDNA consensus for a protein alignment
896 * which has mapping to cDNA
898 final AlignmentI al = this.getAlignment();
899 if (!al.isNucleotide() && al.getCodonFrames() != null
900 && !al.getCodonFrames().isEmpty())
903 * fudge - check first for protein-to-nucleotide mappings
904 * (we don't want to do this for protein-to-protein)
906 boolean doConsensus = false;
907 for (AlignedCodonFrame mapping : al.getCodonFrames())
909 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
910 MapList[] mapLists = mapping.getdnaToProt();
911 // mapLists can be empty if project load has not finished resolving seqs
912 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
920 if (calculator.getRegisteredWorkersOfClass(
921 ComplementConsensusThread.class) == null)
924 .registerWorker(new ComplementConsensusThread(this, ap));
934 * trigger update of consensus annotation
936 public void updateSecondaryStructureConsensus(final AlignmentViewPanel ap)
938 // see note in mantis : issue number 8585
939 if (secondaryStructureConsensus == null || !autoCalculateConsensus)
944 .getRegisteredWorkersOfClass(SecondaryStructureConsensusThread.class) == null)
946 calculator.registerWorker(new SecondaryStructureConsensusThread(this, ap));
950 // --------START Structure Conservation
951 public void updateStrucConsensus(final AlignmentViewPanel ap)
953 if (autoCalculateStrucConsensus && strucConsensus == null
954 && alignment.isNucleotide() && alignment.hasRNAStructure())
956 // secondary structure has been added - so init the consensus line
960 // see note in mantis : issue number 8585
961 if (strucConsensus == null || !autoCalculateStrucConsensus)
965 if (calculator.getRegisteredWorkersOfClass(
966 StrucConsensusThread.class) == null)
968 calculator.registerWorker(new StrucConsensusThread(this, ap));
972 public boolean isCalcInProgress()
974 return calculator.isWorking();
978 public boolean isCalculationInProgress(
979 AlignmentAnnotation alignmentAnnotation)
981 if (!alignmentAnnotation.autoCalculated)
985 if (calculator.workingInvolvedWith(alignmentAnnotation))
987 // jalview.bin.Console.errPrintln("grey out
988 // ("+alignmentAnnotation.label+")");
994 public void setAlignment(AlignmentI align)
996 this.alignment = align;
1000 * Clean up references when this viewport is closed
1003 public void dispose()
1006 * defensively null out references to large objects in case
1007 * this object is not garbage collected (as if!)
1010 complementConsensus = null;
1011 strucConsensus = null;
1012 secondaryStructureConsensus = null;
1013 conservation = null;
1015 groupConsensus = null;
1016 groupConservation = null;
1018 hconservation = null;
1019 hcomplementConsensus = null;
1022 residueShading = null; // may hold a reference to Consensus
1023 changeSupport = null;
1026 selectionGroup = null;
1032 public boolean isClosed()
1034 // TODO: check that this isClosed is only true after panel is closed, not
1035 // before it is fully constructed.
1036 return alignment == null;
1040 public AlignCalcManagerI getCalcManager()
1046 * should conservation rows be shown for groups
1048 protected boolean showGroupConservation = false;
1051 * should consensus rows be shown for groups
1053 protected boolean showGroupConsensus = false;
1056 * should consensus profile be rendered by default
1058 protected boolean showSequenceLogo = false;
1060 protected boolean showSequenceSSLogo = false;
1063 * should consensus profile be rendered normalised to row height
1065 protected boolean normaliseSequenceLogo = false;
1068 * should consensus histograms be rendered by default
1070 protected boolean showConsensusHistogram = true;
1072 protected boolean showSSConsensusHistogram = true;
1074 public void setShowSSConsensusHistogram(boolean showSSConsensusHistogram)
1076 this.showSSConsensusHistogram = showSSConsensusHistogram;
1080 * @return the showConsensusProfile
1083 public boolean isShowSequenceLogo()
1085 return showSequenceLogo;
1089 public boolean isShowSequenceSSLogo()
1091 return showSequenceSSLogo;
1095 * @param showSequenceLogo
1098 public void setShowSequenceLogo(boolean showSequenceLogo)
1100 if (showSequenceLogo != this.showSequenceLogo)
1102 // TODO: decouple settings setting from calculation when refactoring
1103 // annotation update method from alignframe to viewport
1104 this.showSequenceLogo = showSequenceLogo;
1105 calculator.updateAnnotationFor(ConsensusThread.class);
1106 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1107 calculator.updateAnnotationFor(StrucConsensusThread.class);
1109 this.showSequenceLogo = showSequenceLogo;
1112 public void setShowSequenceSSLogo(boolean showSequenceSSLogo)
1114 if (showSequenceSSLogo != this.showSequenceSSLogo)
1116 // TODO: decouple settings setting from calculation when refactoring
1117 // annotation update method from alignframe to viewport
1118 this.showSequenceSSLogo = showSequenceSSLogo;
1119 calculator.updateAnnotationFor(SecondaryStructureConsensusThread.class);
1121 this.showSequenceSSLogo = showSequenceSSLogo;
1125 * @param showConsensusHistogram
1126 * the showConsensusHistogram to set
1128 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1130 this.showConsensusHistogram = showConsensusHistogram;
1134 * @return the showGroupConservation
1136 public boolean isShowGroupConservation()
1138 return showGroupConservation;
1142 * @param showGroupConservation
1143 * the showGroupConservation to set
1145 public void setShowGroupConservation(boolean showGroupConservation)
1147 this.showGroupConservation = showGroupConservation;
1151 * @return the showGroupConsensus
1153 public boolean isShowGroupConsensus()
1155 return showGroupConsensus;
1159 * @param showGroupConsensus
1160 * the showGroupConsensus to set
1162 public void setShowGroupConsensus(boolean showGroupConsensus)
1164 this.showGroupConsensus = showGroupConsensus;
1169 * @return flag to indicate if the consensus histogram should be rendered by
1173 public boolean isShowConsensusHistogram()
1175 return this.showConsensusHistogram;
1179 public boolean isShowSSConsensusHistogram()
1181 return this.showSSConsensusHistogram;
1185 * when set, updateAlignment will always ensure sequences are of equal length
1187 private boolean padGaps = false;
1190 * when set, alignment should be reordered according to a newly opened tree
1192 public boolean sortByTree = false;
1197 * @return null or the currently selected sequence region
1200 public SequenceGroup getSelectionGroup()
1202 return selectionGroup;
1206 * Set the selection group for this window. Also sets the current alignment as
1207 * the context for the group, if it does not already have one.
1210 * - group holding references to sequences in this alignment view
1214 public void setSelectionGroup(SequenceGroup sg)
1216 selectionGroup = sg;
1217 if (sg != null && sg.getContext() == null)
1219 sg.setContext(alignment);
1223 public void setHiddenColumns(HiddenColumns hidden)
1225 this.alignment.setHiddenColumns(hidden);
1229 public ColumnSelection getColumnSelection()
1235 public void setColumnSelection(ColumnSelection colSel)
1237 this.colSel = colSel;
1240 updateHiddenColumns();
1242 isColSelChanged(true);
1250 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1252 return hiddenRepSequences;
1256 public void setHiddenRepSequences(
1257 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1259 this.hiddenRepSequences = hiddenRepSequences;
1263 public boolean hasSelectedColumns()
1265 ColumnSelection columnSelection = getColumnSelection();
1266 return columnSelection != null && columnSelection.hasSelectedColumns();
1270 public boolean hasHiddenColumns()
1272 return alignment.getHiddenColumns() != null
1273 && alignment.getHiddenColumns().hasHiddenColumns();
1276 public void updateHiddenColumns()
1278 // this method doesn't really do anything now. But - it could, since a
1279 // column Selection could be in the process of modification
1280 // hasHiddenColumns = colSel.hasHiddenColumns();
1284 public boolean hasHiddenRows()
1286 return alignment.getHiddenSequences().getSize() > 0;
1289 protected SequenceGroup selectionGroup;
1291 public void setSequenceSetId(String newid)
1293 if (sequenceSetID != null)
1295 jalview.bin.Console.errPrintln(
1296 "Warning - overwriting a sequenceSetId for a viewport!");
1298 sequenceSetID = new String(newid);
1302 public String getSequenceSetId()
1304 if (sequenceSetID == null)
1306 sequenceSetID = alignment.hashCode() + "";
1309 return sequenceSetID;
1313 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1316 protected String viewId = null;
1319 public String getViewId()
1323 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1328 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1330 ignoreGapsInConsensusCalculation = b;
1333 updateConsensus(ap);
1334 updateSecondaryStructureConsensus(ap);
1335 if (residueShading != null)
1337 residueShading.setThreshold(residueShading.getThreshold(),
1338 ignoreGapsInConsensusCalculation);
1344 private long sgrouphash = -1, colselhash = -1;
1347 * checks current SelectionGroup against record of last hash value, and
1351 * update the record of last hash value
1353 * @return true if SelectionGroup changed since last call (when b is true)
1355 public boolean isSelectionGroupChanged(boolean b)
1357 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1358 : selectionGroup.hashCode();
1359 if (hc != -1 && hc != sgrouphash)
1371 * checks current colsel against record of last hash value, and optionally
1375 * update the record of last hash value
1376 * @return true if colsel changed since last call (when b is true)
1378 public boolean isColSelChanged(boolean b)
1380 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1381 if (hc != -1 && hc != colselhash)
1393 public boolean isIgnoreGapsConsensus()
1395 return ignoreGapsInConsensusCalculation;
1398 // property change stuff
1399 // JBPNote Prolly only need this in the applet version.
1400 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1403 protected boolean showConservation = true;
1405 protected boolean showQuality = true;
1407 protected boolean showConsensus = true;
1409 protected boolean showSSConsensus = false;
1411 protected boolean showOccupancy = true;
1413 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1415 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1417 protected boolean showAutocalculatedAbove;
1420 * when set, view will scroll to show the highlighted position
1422 private boolean followHighlight = true;
1425 * Property change listener for changes in alignment
1430 public void addPropertyChangeListener(
1431 java.beans.PropertyChangeListener listener)
1433 changeSupport.addPropertyChangeListener(listener);
1442 public void removePropertyChangeListener(
1443 java.beans.PropertyChangeListener listener)
1445 if (changeSupport != null)
1447 changeSupport.removePropertyChangeListener(listener);
1452 * Property change listener for changes in alignment
1461 public void firePropertyChange(String prop, Object oldvalue,
1464 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1468 public void notifyAlignmentChanged()
1470 firePropertyChange("alignment", null, alignment);
1473 // common hide/show column stuff
1475 public void hideSelectedColumns()
1477 if (colSel.isEmpty())
1482 colSel.hideSelectedColumns(alignment);
1483 setSelectionGroup(null);
1484 isColSelChanged(true);
1487 public void hideColumns(int start, int end)
1491 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1495 alignment.getHiddenColumns().hideColumns(start, end);
1497 isColSelChanged(true);
1500 public void showColumn(int col)
1502 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1503 isColSelChanged(true);
1506 public void showAllHiddenColumns()
1508 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1509 isColSelChanged(true);
1512 // common hide/show seq stuff
1513 public void showAllHiddenSeqs()
1515 int startSeq = ranges.getStartSeq();
1516 int endSeq = ranges.getEndSeq();
1518 if (alignment.getHiddenSequences().getSize() > 0)
1520 if (selectionGroup == null)
1522 selectionGroup = new SequenceGroup();
1523 selectionGroup.setEndRes(alignment.getWidth() - 1);
1525 List<SequenceI> tmp = alignment.getHiddenSequences()
1526 .showAll(hiddenRepSequences);
1527 for (SequenceI seq : tmp)
1529 selectionGroup.addSequence(seq, false);
1530 setSequenceAnnotationsVisible(seq, true);
1533 hiddenRepSequences = null;
1535 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1537 firePropertyChange("alignment", null, alignment.getSequences());
1538 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1544 public void showSequence(int index)
1546 int startSeq = ranges.getStartSeq();
1547 int endSeq = ranges.getEndSeq();
1549 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1550 hiddenRepSequences);
1553 if (selectionGroup == null)
1555 selectionGroup = new SequenceGroup();
1556 selectionGroup.setEndRes(alignment.getWidth() - 1);
1559 for (SequenceI seq : tmp)
1561 selectionGroup.addSequence(seq, false);
1562 setSequenceAnnotationsVisible(seq, true);
1565 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1567 firePropertyChange("alignment", null, alignment.getSequences());
1572 public void hideAllSelectedSeqs()
1574 if (selectionGroup == null || selectionGroup.getSize() < 1)
1579 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1583 setSelectionGroup(null);
1586 public void hideSequence(SequenceI[] seq)
1589 * cache offset to first visible sequence
1591 int startSeq = ranges.getStartSeq();
1595 for (int i = 0; i < seq.length; i++)
1597 alignment.getHiddenSequences().hideSequence(seq[i]);
1598 setSequenceAnnotationsVisible(seq[i], false);
1600 ranges.setStartSeq(startSeq);
1601 firePropertyChange("alignment", null, alignment.getSequences());
1606 * Hides the specified sequence, or the sequences it represents
1609 * the sequence to hide, or keep as representative
1610 * @param representGroup
1611 * if true, hide the current selection group except for the
1612 * representative sequence
1614 public void hideSequences(SequenceI sequence, boolean representGroup)
1616 if (selectionGroup == null || selectionGroup.getSize() < 1)
1618 hideSequence(new SequenceI[] { sequence });
1624 hideRepSequences(sequence, selectionGroup);
1625 setSelectionGroup(null);
1629 int gsize = selectionGroup.getSize();
1630 SequenceI[] hseqs = selectionGroup.getSequences()
1631 .toArray(new SequenceI[gsize]);
1633 hideSequence(hseqs);
1634 setSelectionGroup(null);
1639 * Set visibility for any annotations for the given sequence.
1643 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1646 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1649 for (AlignmentAnnotation ann : anns)
1651 if (ann.sequenceRef == sequenceI)
1653 ann.visible = visible;
1659 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1661 int sSize = sg.getSize();
1667 if (hiddenRepSequences == null)
1669 hiddenRepSequences = new Hashtable<>();
1672 hiddenRepSequences.put(repSequence, sg);
1674 // Hide all sequences except the repSequence
1675 SequenceI[] seqs = new SequenceI[sSize - 1];
1677 for (int i = 0; i < sSize; i++)
1679 if (sg.getSequenceAt(i) != repSequence)
1681 if (index == sSize - 1)
1686 seqs[index++] = sg.getSequenceAt(i);
1689 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1690 sg.setHidereps(true); // note: not done in 2.7applet
1697 * @return null or the current reference sequence
1699 public SequenceI getReferenceSeq()
1701 return alignment.getSeqrep();
1706 * @return true iff seq is the reference for the alignment
1708 public boolean isReferenceSeq(SequenceI seq)
1710 return alignment.getSeqrep() == seq;
1716 * @return true if there are sequences represented by this sequence that are
1719 public boolean isHiddenRepSequence(SequenceI seq)
1721 return (hiddenRepSequences != null
1722 && hiddenRepSequences.containsKey(seq));
1728 * @return null or a sequence group containing the sequences that seq
1731 public SequenceGroup getRepresentedSequences(SequenceI seq)
1733 return (SequenceGroup) (hiddenRepSequences == null ? null
1734 : hiddenRepSequences.get(seq));
1738 public int adjustForHiddenSeqs(int alignmentIndex)
1740 return alignment.getHiddenSequences()
1741 .adjustForHiddenSeqs(alignmentIndex);
1745 public void invertColumnSelection()
1747 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1748 isColSelChanged(true);
1752 public SequenceI[] getSelectionAsNewSequence()
1754 SequenceI[] sequences;
1755 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1756 // this was the only caller in the applet for this method
1757 // JBPNote: in applet, this method returned references to the alignment
1758 // sequences, and it did not honour the presence/absence of annotation
1759 // attached to the alignment (probably!)
1760 if (selectionGroup == null || selectionGroup.getSize() == 0)
1762 sequences = alignment.getSequencesArray();
1763 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1764 for (int i = 0; i < sequences.length; i++)
1766 // construct new sequence with subset of visible annotation
1767 sequences[i] = new Sequence(sequences[i], annots);
1772 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1779 public SequenceI[] getSequenceSelection()
1781 SequenceI[] sequences = null;
1782 if (selectionGroup != null)
1784 sequences = selectionGroup.getSequencesInOrder(alignment);
1786 if (sequences == null)
1788 sequences = alignment.getSequencesArray();
1794 public jalview.datamodel.AlignmentView getAlignmentView(
1795 boolean selectedOnly)
1797 return getAlignmentView(selectedOnly, false);
1801 public jalview.datamodel.AlignmentView getAlignmentView(
1802 boolean selectedOnly, boolean markGroups)
1804 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1806 alignment.getHiddenColumns() != null
1807 && alignment.getHiddenColumns().hasHiddenColumns(),
1808 selectedOnly, markGroups);
1812 public String[] getViewAsString(boolean selectedRegionOnly)
1814 return getViewAsString(selectedRegionOnly, true);
1818 public String[] getViewAsString(boolean selectedRegionOnly,
1819 boolean exportHiddenSeqs)
1821 String[] selection = null;
1822 SequenceI[] seqs = null;
1824 int start = 0, end = 0;
1825 if (selectedRegionOnly && selectionGroup != null)
1827 iSize = selectionGroup.getSize();
1828 seqs = selectionGroup.getSequencesInOrder(alignment);
1829 start = selectionGroup.getStartRes();
1830 end = selectionGroup.getEndRes() + 1;
1834 if (hasHiddenRows() && exportHiddenSeqs)
1836 AlignmentI fullAlignment = alignment.getHiddenSequences()
1837 .getFullAlignment();
1838 iSize = fullAlignment.getHeight();
1839 seqs = fullAlignment.getSequencesArray();
1840 end = fullAlignment.getWidth();
1844 iSize = alignment.getHeight();
1845 seqs = alignment.getSequencesArray();
1846 end = alignment.getWidth();
1850 selection = new String[iSize];
1851 if (alignment.getHiddenColumns() != null
1852 && alignment.getHiddenColumns().hasHiddenColumns())
1854 for (i = 0; i < iSize; i++)
1856 Iterator<int[]> blocks = alignment.getHiddenColumns()
1857 .getVisContigsIterator(start, end + 1, false);
1858 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1863 for (i = 0; i < iSize; i++)
1865 selection[i] = seqs[i].getSequenceAsString(start, end);
1873 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1875 ArrayList<int[]> regions = new ArrayList<>();
1881 HiddenColumns hidden = alignment.getHiddenColumns();
1882 if (hidden != null && hidden.hasHiddenColumns())
1886 start = hidden.visibleToAbsoluteColumn(start);
1889 end = hidden.getNextHiddenBoundary(false, start);
1900 regions.add(new int[] { start, end });
1902 if (hidden != null && hidden.hasHiddenColumns())
1904 start = hidden.visibleToAbsoluteColumn(end);
1905 start = hidden.getNextHiddenBoundary(true, start) + 1;
1907 } while (end < max);
1909 // int[][] startEnd = new int[regions.size()][2];
1915 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1916 boolean selectedOnly)
1918 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1919 AlignmentAnnotation[] aa;
1920 if ((aa = alignment.getAlignmentAnnotation()) != null)
1922 for (AlignmentAnnotation annot : aa)
1924 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1925 if (selectedOnly && selectionGroup != null)
1927 clone.makeVisibleAnnotation(selectionGroup.getStartRes(),
1928 selectionGroup.getEndRes(), alignment.getHiddenColumns());
1932 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1941 public boolean isPadGaps()
1947 public void setPadGaps(boolean padGaps)
1949 this.padGaps = padGaps;
1953 * apply any post-edit constraints and trigger any calculations needed after
1954 * an edit has been performed on the alignment
1959 public void alignmentChanged(AlignmentViewPanel ap)
1963 alignment.padGaps();
1965 if (autoCalculateConsensus)
1967 updateConsensus(ap);
1968 updateSecondaryStructureConsensus(ap);
1970 if (hconsensus != null && autoCalculateConsensus)
1972 updateConservation(ap);
1974 if (autoCalculateStrucConsensus)
1976 updateStrucConsensus(ap);
1979 // Reset endRes of groups if beyond alignment width
1980 int alWidth = alignment.getWidth();
1981 List<SequenceGroup> groups = alignment.getGroups();
1984 for (SequenceGroup sg : groups)
1986 if (sg.getEndRes() > alWidth)
1988 sg.setEndRes(alWidth - 1);
1993 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1995 selectionGroup.setEndRes(alWidth - 1);
1998 updateAllColourSchemes();
1999 calculator.restartWorkers();
2000 // alignment.adjustSequenceAnnotations();
2004 * reset scope and do calculations for all applied colourschemes on alignment
2006 void updateAllColourSchemes()
2008 ResidueShaderI rs = residueShading;
2011 rs.alignmentChanged(alignment, hiddenRepSequences);
2013 rs.setConsensus(hconsensus);
2014 if (rs.conservationApplied())
2016 rs.setConservation(Conservation.calculateConservation("All",
2017 alignment.getSequences(), 0, alignment.getWidth(), false,
2018 getConsPercGaps(), false));
2022 for (SequenceGroup sg : alignment.getGroups())
2026 sg.cs.alignmentChanged(sg, hiddenRepSequences);
2028 sg.recalcConservation();
2032 protected void initAutoAnnotation()
2034 // TODO: add menu option action that nulls or creates consensus object
2035 // depending on if the user wants to see the annotation or not in a
2036 // specific alignment
2038 if (hconsensus == null && !isDataset)
2040 if (!alignment.isNucleotide())
2049 consensus = new AlignmentAnnotation("Consensus",
2050 MessageManager.getString("label.consensus_descr"),
2051 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2053 secondaryStructureConsensus = new AlignmentAnnotation(MessageManager.getString("label.ssconsensus_label"),
2054 MessageManager.getString("label.ssconsensus_descr"),
2055 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2057 initConsensus(consensus);
2058 initSSConsensus(secondaryStructureConsensus);
2060 initComplementConsensus();
2066 * If this is a protein alignment and there are mappings to cDNA, adds the
2067 * cDNA consensus annotation and returns true, else returns false.
2069 public boolean initComplementConsensus()
2071 if (!alignment.isNucleotide())
2073 final List<AlignedCodonFrame> codonMappings = alignment
2075 if (codonMappings != null && !codonMappings.isEmpty())
2077 boolean doConsensus = false;
2078 for (AlignedCodonFrame mapping : codonMappings)
2080 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2081 MapList[] mapLists = mapping.getdnaToProt();
2082 // mapLists can be empty if project load has not finished resolving
2084 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2092 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2094 .getString("label.complement_consensus_descr"),
2095 new Annotation[1], 0f, 100f,
2096 AlignmentAnnotation.BAR_GRAPH);
2097 initConsensus(complementConsensus);
2105 private void initConsensus(AlignmentAnnotation aa)
2108 aa.autoCalculated = true;
2112 alignment.addAnnotation(aa);
2116 private void initSSConsensus(AlignmentAnnotation aa)
2119 aa.autoCalculated = true;
2121 if (showSSConsensus)
2123 alignment.addAnnotation(aa);
2127 // these should be extracted from the view model - style and settings for
2128 // derived annotation
2129 private void initGapCounts()
2133 gapcounts = new AlignmentAnnotation("Occupancy",
2134 MessageManager.getString("label.occupancy_descr"),
2135 new Annotation[1], 0f, alignment.getHeight(),
2136 AlignmentAnnotation.BAR_GRAPH);
2137 gapcounts.hasText = true;
2138 gapcounts.autoCalculated = true;
2139 gapcounts.scaleColLabel = true;
2140 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2142 alignment.addAnnotation(gapcounts);
2146 private void initConservation()
2148 if (showConservation)
2150 if (conservation == null)
2152 conservation = new AlignmentAnnotation("Conservation",
2153 MessageManager.formatMessage("label.conservation_descr",
2155 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2156 conservation.hasText = true;
2157 conservation.autoCalculated = true;
2158 alignment.addAnnotation(conservation);
2163 private void initQuality()
2167 if (quality == null)
2169 quality = new AlignmentAnnotation("Quality",
2170 MessageManager.getString("label.quality_descr"),
2171 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2172 quality.hasText = true;
2173 quality.autoCalculated = true;
2174 alignment.addAnnotation(quality);
2179 private void initRNAStructure()
2181 if (alignment.hasRNAStructure() && strucConsensus == null)
2183 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2184 MessageManager.getString("label.strucconsensus_descr"),
2185 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2186 strucConsensus.hasText = true;
2187 strucConsensus.autoCalculated = true;
2191 alignment.addAnnotation(strucConsensus);
2199 * @see jalview.api.AlignViewportI#calcPanelHeight()
2202 public int calcPanelHeight()
2204 // setHeight of panels
2205 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2207 int charHeight = getCharHeight();
2210 BitSet graphgrp = new BitSet();
2211 for (AlignmentAnnotation aa : anns)
2215 jalview.bin.Console.errPrintln("Null annotation row: ignoring.");
2222 if (aa.graphGroup > -1)
2224 if (graphgrp.get(aa.graphGroup))
2230 graphgrp.set(aa.graphGroup);
2237 aa.height += charHeight;
2247 aa.height += aa.graphHeight + 20;
2255 height += aa.height;
2267 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2268 boolean preserveNewGroupSettings)
2270 boolean updateCalcs = false;
2271 boolean conv = isShowGroupConservation();
2272 boolean cons = isShowGroupConsensus();
2273 boolean showprf = isShowSequenceLogo();
2274 boolean showSSprf = isShowSequenceSSLogo();
2275 boolean showConsHist = isShowConsensusHistogram();
2276 boolean showSSConsHist = isShowSSConsensusHistogram();
2277 boolean normLogo = isNormaliseSequenceLogo();
2280 * TODO reorder the annotation rows according to group/sequence ordering on
2283 // boolean sortg = true;
2285 // remove old automatic annotation
2286 // add any new annotation
2288 // intersect alignment annotation with alignment groups
2290 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2291 List<SequenceGroup> oldrfs = new ArrayList<>();
2294 for (int an = 0; an < aan.length; an++)
2296 if (aan[an].autoCalculated && aan[an].groupRef != null)
2298 oldrfs.add(aan[an].groupRef);
2299 alignment.deleteAnnotation(aan[an], false);
2303 if (alignment.getGroups() != null)
2305 for (SequenceGroup sg : alignment.getGroups())
2307 updateCalcs = false;
2308 if (applyGlobalSettings
2309 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2311 // set defaults for this group's conservation/consensus
2312 sg.setshowSequenceLogo(showprf);
2313 sg.setshowSequenceSSLogo(showSSprf);
2314 sg.setShowConsensusHistogram(showConsHist);
2315 sg.setShowSSConsensusHistogram(showSSConsHist);
2316 sg.setNormaliseSequenceLogo(normLogo);
2321 alignment.addAnnotation(sg.getConservationRow(), 0);
2326 alignment.addAnnotation(sg.getConsensus(), 0);
2327 alignment.addAnnotation(sg.getSSConsensus(), 0);
2329 // refresh the annotation rows
2332 sg.recalcConservation();
2340 public boolean isDisplayReferenceSeq()
2342 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2346 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2348 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2352 public boolean isColourByReferenceSeq()
2354 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2358 public Color getSequenceColour(SequenceI seq)
2360 Color sqc = sequenceColours.get(seq);
2361 return (sqc == null ? Color.white : sqc);
2365 public void setSequenceColour(SequenceI seq, Color col)
2369 sequenceColours.remove(seq);
2373 sequenceColours.put(seq, col);
2378 public void updateSequenceIdColours()
2380 for (SequenceGroup sg : alignment.getGroups())
2382 if (sg.idColour != null)
2384 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2386 sequenceColours.put(s, sg.idColour);
2393 public void clearSequenceColours()
2395 sequenceColours.clear();
2399 public AlignViewportI getCodingComplement()
2401 return this.codingComplement;
2405 * Set this as the (cDna/protein) complement of the given viewport. Also
2406 * ensures the reverse relationship is set on the given viewport.
2409 public void setCodingComplement(AlignViewportI av)
2414 .errPrintln("Ignoring recursive setCodingComplement request");
2418 this.codingComplement = av;
2419 // avoid infinite recursion!
2420 if (av.getCodingComplement() != this)
2422 av.setCodingComplement(this);
2428 public boolean isNucleotide()
2430 return getAlignment() == null ? false : getAlignment().isNucleotide();
2434 public FeaturesDisplayedI getFeaturesDisplayed()
2436 return featuresDisplayed;
2440 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2442 featuresDisplayed = featuresDisplayedI;
2446 public boolean areFeaturesDisplayed()
2448 return featuresDisplayed != null
2449 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2456 * features are displayed if true
2459 public void setShowSequenceFeatures(boolean b)
2461 viewStyle.setShowSequenceFeatures(b);
2465 public boolean isShowSequenceFeatures()
2467 return viewStyle.isShowSequenceFeatures();
2471 public void setShowSequenceFeaturesHeight(boolean selected)
2473 viewStyle.setShowSequenceFeaturesHeight(selected);
2477 public boolean isShowSequenceFeaturesHeight()
2479 return viewStyle.isShowSequenceFeaturesHeight();
2483 public void setShowAnnotation(boolean b)
2485 viewStyle.setShowAnnotation(b);
2489 public boolean isShowAnnotation()
2491 return viewStyle.isShowAnnotation();
2495 public boolean isRightAlignIds()
2497 return viewStyle.isRightAlignIds();
2501 public void setRightAlignIds(boolean rightAlignIds)
2503 viewStyle.setRightAlignIds(rightAlignIds);
2507 public boolean getConservationSelected()
2509 return viewStyle.getConservationSelected();
2513 public void setShowBoxes(boolean state)
2515 viewStyle.setShowBoxes(state);
2520 * @see jalview.api.ViewStyleI#getTextColour()
2523 public Color getTextColour()
2525 return viewStyle.getTextColour();
2530 * @see jalview.api.ViewStyleI#getTextColour2()
2533 public Color getTextColour2()
2535 return viewStyle.getTextColour2();
2540 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2543 public int getThresholdTextColour()
2545 return viewStyle.getThresholdTextColour();
2550 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2553 public boolean isConservationColourSelected()
2555 return viewStyle.isConservationColourSelected();
2560 * @see jalview.api.ViewStyleI#isRenderGaps()
2563 public boolean isRenderGaps()
2565 return viewStyle.isRenderGaps();
2570 * @see jalview.api.ViewStyleI#isShowColourText()
2573 public boolean isShowColourText()
2575 return viewStyle.isShowColourText();
2579 * @param conservationColourSelected
2580 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2583 public void setConservationColourSelected(
2584 boolean conservationColourSelected)
2586 viewStyle.setConservationColourSelected(conservationColourSelected);
2590 * @param showColourText
2591 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2594 public void setShowColourText(boolean showColourText)
2596 viewStyle.setShowColourText(showColourText);
2601 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2604 public void setTextColour(Color textColour)
2606 viewStyle.setTextColour(textColour);
2610 * @param thresholdTextColour
2611 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2614 public void setThresholdTextColour(int thresholdTextColour)
2616 viewStyle.setThresholdTextColour(thresholdTextColour);
2620 * @param textColour2
2621 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2624 public void setTextColour2(Color textColour2)
2626 viewStyle.setTextColour2(textColour2);
2630 public ViewStyleI getViewStyle()
2632 return new ViewStyle(viewStyle);
2636 public void setViewStyle(ViewStyleI settingsForView)
2638 viewStyle = new ViewStyle(settingsForView);
2639 if (residueShading != null)
2641 residueShading.setConservationApplied(
2642 settingsForView.isConservationColourSelected());
2647 public boolean sameStyle(ViewStyleI them)
2649 return viewStyle.sameStyle(them);
2654 * @see jalview.api.ViewStyleI#getIdWidth()
2657 public int getIdWidth()
2659 return viewStyle.getIdWidth();
2664 * @see jalview.api.ViewStyleI#setIdWidth(int)
2667 public void setIdWidth(int i)
2669 viewStyle.setIdWidth(i);
2674 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2677 public boolean isCentreColumnLabels()
2679 return viewStyle.isCentreColumnLabels();
2683 * @param centreColumnLabels
2684 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2687 public void setCentreColumnLabels(boolean centreColumnLabels)
2689 viewStyle.setCentreColumnLabels(centreColumnLabels);
2694 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2697 public void setShowDBRefs(boolean showdbrefs)
2699 viewStyle.setShowDBRefs(showdbrefs);
2704 * @see jalview.api.ViewStyleI#isShowDBRefs()
2707 public boolean isShowDBRefs()
2709 return viewStyle.isShowDBRefs();
2714 * @see jalview.api.ViewStyleI#isShowNPFeats()
2717 public boolean isShowNPFeats()
2719 return viewStyle.isShowNPFeats();
2723 * @param shownpfeats
2724 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2727 public void setShowNPFeats(boolean shownpfeats)
2729 viewStyle.setShowNPFeats(shownpfeats);
2732 public abstract StructureSelectionManager getStructureSelectionManager();
2735 * Add one command to the command history list.
2739 public void addToHistoryList(CommandI command)
2741 if (this.historyList != null)
2743 this.historyList.push(command);
2744 broadcastCommand(command, false);
2745 setSavedUpToDate(false);
2746 Jalview2XML.setStateSavedUpToDate(false);
2750 protected void broadcastCommand(CommandI command, boolean undo)
2752 getStructureSelectionManager().commandPerformed(command, undo,
2757 * Add one command to the command redo list.
2761 public void addToRedoList(CommandI command)
2763 if (this.redoList != null)
2765 this.redoList.push(command);
2767 broadcastCommand(command, true);
2771 * Clear the command redo list.
2773 public void clearRedoList()
2775 if (this.redoList != null)
2777 this.redoList.clear();
2781 public void setHistoryList(Deque<CommandI> list)
2783 this.historyList = list;
2786 public Deque<CommandI> getHistoryList()
2788 return this.historyList;
2791 public void setRedoList(Deque<CommandI> list)
2793 this.redoList = list;
2796 public Deque<CommandI> getRedoList()
2798 return this.redoList;
2802 public VamsasSource getVamsasSource()
2807 public SequenceAnnotationOrder getSortAnnotationsBy()
2809 return sortAnnotationsBy;
2812 public void setSortAnnotationsBy(
2813 SequenceAnnotationOrder sortAnnotationsBy)
2815 this.sortAnnotationsBy = sortAnnotationsBy;
2818 public boolean isShowAutocalculatedAbove()
2820 return showAutocalculatedAbove;
2823 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2825 this.showAutocalculatedAbove = showAutocalculatedAbove;
2829 public boolean isScaleProteinAsCdna()
2831 return viewStyle.isScaleProteinAsCdna();
2835 public void setScaleProteinAsCdna(boolean b)
2837 viewStyle.setScaleProteinAsCdna(b);
2841 public boolean isProteinFontAsCdna()
2843 return viewStyle.isProteinFontAsCdna();
2847 public void setProteinFontAsCdna(boolean b)
2849 viewStyle.setProteinFontAsCdna(b);
2853 public void setShowComplementFeatures(boolean b)
2855 viewStyle.setShowComplementFeatures(b);
2859 public boolean isShowComplementFeatures()
2861 return viewStyle.isShowComplementFeatures();
2865 public void setShowComplementFeaturesOnTop(boolean b)
2867 viewStyle.setShowComplementFeaturesOnTop(b);
2871 public boolean isShowComplementFeaturesOnTop()
2873 return viewStyle.isShowComplementFeaturesOnTop();
2877 * @return true if view should scroll to show the highlighted region of a
2882 public final boolean isFollowHighlight()
2884 return followHighlight;
2888 public final void setFollowHighlight(boolean b)
2890 this.followHighlight = b;
2894 public ViewportRanges getRanges()
2900 * Helper method to populate the SearchResults with the location in the
2901 * complementary alignment to scroll to, in order to match this one.
2904 * the SearchResults to add to
2905 * @return the offset (below top of visible region) of the matched sequence
2907 protected int findComplementScrollTarget(SearchResultsI sr)
2909 final AlignViewportI complement = getCodingComplement();
2910 if (complement == null || !complement.isFollowHighlight())
2914 boolean iAmProtein = !getAlignment().isNucleotide();
2915 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2916 : complement.getAlignment();
2917 if (proteinAlignment == null)
2921 final List<AlignedCodonFrame> mappings = proteinAlignment
2925 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2926 * residue in the middle column of the visible region. Scroll the
2927 * complementary alignment to line up the corresponding residue.
2930 SequenceI sequence = null;
2933 * locate 'middle' column (true middle if an odd number visible, left of
2934 * middle if an even number visible)
2936 int middleColumn = ranges.getStartRes()
2937 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2938 final HiddenSequences hiddenSequences = getAlignment()
2939 .getHiddenSequences();
2942 * searching to the bottom of the alignment gives smoother scrolling across
2943 * all gapped visible regions
2945 int lastSeq = alignment.getHeight() - 1;
2946 List<AlignedCodonFrame> seqMappings = null;
2947 for (int seqNo = ranges
2948 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2950 sequence = getAlignment().getSequenceAt(seqNo);
2951 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2955 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2959 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2961 getCodingComplement().getAlignment().getSequences());
2962 if (!seqMappings.isEmpty())
2968 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2971 * No ungapped mapped sequence in middle column - do nothing
2975 MappingUtils.addSearchResults(sr, sequence,
2976 sequence.findPosition(middleColumn), seqMappings);
2981 * synthesize a column selection if none exists so it covers the given
2982 * selection group. if wholewidth is false, no column selection is made if the
2983 * selection group covers the whole alignment width.
2988 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2991 if (sg != null && (sgs = sg.getStartRes()) >= 0
2992 && sg.getStartRes() <= (sge = sg.getEndRes())
2993 && !this.hasSelectedColumns())
2995 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
3002 colSel = new ColumnSelection();
3004 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
3006 colSel.addElement(cspos);
3012 * hold status of current selection group - defined on alignment or not.
3014 private boolean selectionIsDefinedGroup = false;
3017 public boolean isSelectionDefinedGroup()
3019 if (selectionGroup == null)
3023 if (isSelectionGroupChanged(true))
3025 selectionIsDefinedGroup = false;
3026 List<SequenceGroup> gps = alignment.getGroups();
3027 if (gps == null || gps.size() == 0)
3029 selectionIsDefinedGroup = false;
3033 selectionIsDefinedGroup = gps.contains(selectionGroup);
3036 return selectionGroup.isDefined() || selectionIsDefinedGroup;
3040 * null, or currently highlighted results on this view
3042 private SearchResultsI searchResults = null;
3044 protected TreeModel currentTree = null;
3047 public boolean hasSearchResults()
3049 return searchResults != null;
3053 public void setSearchResults(SearchResultsI results)
3055 searchResults = results;
3059 public SearchResultsI getSearchResults()
3061 return searchResults;
3065 public ContactListI getContactList(AlignmentAnnotation _aa, int column)
3067 return alignment.getContactListFor(_aa, column);
3071 public ContactMatrixI getContactMatrix(
3072 AlignmentAnnotation alignmentAnnotation)
3074 return alignment.getContactMatrixFor(alignmentAnnotation);
3078 * get the consensus sequence as displayed under the PID consensus annotation
3081 * @return consensus sequence as a new sequence object
3083 public SequenceI getConsensusSeq()
3085 if (consensus == null)
3087 updateConsensus(null);
3089 if (consensus == null)
3093 StringBuffer seqs = new StringBuffer();
3094 for (int i = 0; i < consensus.annotations.length; i++)
3096 Annotation annotation = consensus.annotations[i];
3097 if (annotation != null)
3099 String description = annotation.description;
3100 if (description != null && description.startsWith("["))
3102 // consensus is a tie - just pick the first one
3103 seqs.append(description.charAt(1));
3107 seqs.append(annotation.displayCharacter);
3112 SequenceI sq = new Sequence("Consensus", seqs.toString());
3113 sq.setDescription("Percentage Identity Consensus "
3114 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3118 public SequenceI getSSConsensusSeq()
3120 if (secondaryStructureConsensus == null)
3122 updateSecondaryStructureConsensus(null);
3124 if (secondaryStructureConsensus == null)
3128 StringBuffer seqs = new StringBuffer();
3129 for (int i = 0; i < secondaryStructureConsensus.annotations.length; i++)
3131 Annotation annotation = secondaryStructureConsensus.annotations[i];
3132 if (annotation != null)
3134 String description = annotation.description;
3135 if (description != null && description.startsWith("["))
3137 // consensus is a tie - just pick the first one
3138 seqs.append(description.charAt(1));
3142 seqs.append(annotation.displayCharacter);
3147 SequenceI sq = new Sequence("Sec Str Consensus", seqs.toString());
3148 sq.setDescription("Percentage Identity Sec Str Consensus "
3149 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3154 public void setCurrentTree(TreeModel tree)
3160 public TreeModel getCurrentTree()
3166 public AlignmentExportData getAlignExportData(
3167 AlignExportSettingsI options)
3169 AlignmentI alignmentToExport = null;
3170 String[] omitHidden = null;
3171 alignmentToExport = null;
3173 if (hasHiddenColumns() && !options.isExportHiddenColumns())
3175 omitHidden = getViewAsString(false,
3176 options.isExportHiddenSequences());
3179 int[] alignmentStartEnd = new int[2];
3180 if (hasHiddenRows() && options.isExportHiddenSequences())
3182 alignmentToExport = getAlignment().getHiddenSequences()
3183 .getFullAlignment();
3187 alignmentToExport = getAlignment();
3189 alignmentStartEnd = getAlignment().getHiddenColumns()
3190 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
3191 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
3192 omitHidden, alignmentStartEnd);
3197 * flag set to indicate if structure views might be out of sync with sequences
3201 private boolean needToUpdateStructureViews = false;
3204 public boolean isUpdateStructures()
3206 return needToUpdateStructureViews;
3210 public void setUpdateStructures(boolean update)
3212 needToUpdateStructureViews = update;
3216 public boolean needToUpdateStructureViews()
3218 boolean update = needToUpdateStructureViews;
3219 needToUpdateStructureViews = false;
3224 public void addSequenceGroup(SequenceGroup sequenceGroup)
3226 alignment.addGroup(sequenceGroup);
3228 Color col = sequenceGroup.idColour;
3231 col = col.brighter();
3233 for (SequenceI sq : sequenceGroup.getSequences())
3235 setSequenceColour(sq, col);
3239 if (codingComplement != null)
3241 SequenceGroup mappedGroup = MappingUtils
3242 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3243 if (mappedGroup.getSequences().size() > 0)
3245 codingComplement.getAlignment().addGroup(mappedGroup);
3249 for (SequenceI seq : mappedGroup.getSequences())
3251 codingComplement.setSequenceColour(seq, col);
3255 // propagate the structure view update flag according to our own setting
3256 codingComplement.setUpdateStructures(needToUpdateStructureViews);
3261 public Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly)
3265 if (selectedRegionOnly && selectionGroup != null)
3267 start = selectionGroup.getStartRes();
3268 end = selectionGroup.getEndRes() + 1;
3272 end = alignment.getWidth();
3274 return (alignment.getHiddenColumns().getVisContigsIterator(start, end,
3278 public void setSavedUpToDate(boolean s)
3280 setSavedUpToDate(s, QuitHandler.Message.UNSAVED_CHANGES);
3283 public void setSavedUpToDate(boolean s, QuitHandler.Message m)
3286 "Setting " + this.getViewId() + " setSavedUpToDate to " + s);
3288 QuitHandler.setMessage(m);
3291 public boolean savedUpToDate()
3293 Console.debug("Returning " + this.getViewId() + " savedUpToDate value: "
3295 return savedUpToDate;