2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.viewmodel;
23 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
24 import jalview.analysis.Conservation;
25 import jalview.analysis.TreeModel;
26 import jalview.api.AlignCalcManagerI;
27 import jalview.api.AlignCalcManagerI2;
28 import jalview.api.AlignCalcWorkerI;
29 import jalview.api.AlignExportSettingsI;
30 import jalview.api.AlignViewportI;
31 import jalview.api.AlignmentViewPanel;
32 import jalview.api.FeaturesDisplayedI;
33 import jalview.api.ViewStyleI;
34 import jalview.commands.CommandI;
35 import jalview.datamodel.AlignedCodonFrame;
36 import jalview.datamodel.AlignmentAnnotation;
37 import jalview.datamodel.AlignmentExportData;
38 import jalview.datamodel.AlignmentI;
39 import jalview.datamodel.AlignmentView;
40 import jalview.datamodel.Annotation;
41 import jalview.datamodel.ColumnSelection;
42 import jalview.datamodel.HiddenColumns;
43 import jalview.datamodel.HiddenSequences;
44 import jalview.datamodel.ProfilesI;
45 import jalview.datamodel.SearchResultsI;
46 import jalview.datamodel.Sequence;
47 import jalview.datamodel.SequenceCollectionI;
48 import jalview.datamodel.SequenceGroup;
49 import jalview.datamodel.SequenceI;
50 import jalview.renderer.ResidueShader;
51 import jalview.renderer.ResidueShaderI;
52 import jalview.schemes.ColourSchemeI;
53 import jalview.structure.CommandListener;
54 import jalview.structure.StructureSelectionManager;
55 import jalview.structure.VamsasSource;
56 import jalview.util.Comparison;
57 import jalview.util.MapList;
58 import jalview.util.MappingUtils;
59 import jalview.util.MessageManager;
60 import jalview.viewmodel.styles.ViewStyle;
61 import jalview.workers.AlignCalcManager;
62 import jalview.workers.AlignCalcManager2;
63 import jalview.workers.ComplementConsensusThread;
64 import jalview.workers.ConsensusThread;
65 import jalview.workers.InformationThread;
66 import jalview.workers.StrucConsensusThread;
68 import java.awt.Color;
69 import java.beans.PropertyChangeSupport;
70 import java.util.ArrayDeque;
71 import java.util.ArrayList;
72 import java.util.BitSet;
73 import java.util.Deque;
74 import java.util.HashMap;
75 import java.util.Hashtable;
76 import java.util.Iterator;
77 import java.util.List;
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 * alignment displayed in the viewport. Please use get/setter
109 protected AlignmentI alignment;
112 * probably unused indicator that view is of a dataset rather than an
116 protected boolean ignoreBelowBackGroundFrequencyCalculation = false;
118 protected boolean infoLetterHeight = false;
120 protected AlignmentAnnotation occupancy;
123 * results of alignment consensus analysis for visible portion of view
125 protected ProfilesI consensusProfiles;
128 * HMM profile for the alignment
130 protected ProfilesI hmmProfiles;
132 public AlignmentViewport(AlignmentI al)
135 ranges = new ViewportRanges(al);
140 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
143 public void setFontName(String name)
145 viewStyle.setFontName(name);
150 * @see jalview.api.ViewStyleI#setFontStyle(int)
153 public void setFontStyle(int style)
155 viewStyle.setFontStyle(style);
160 * @see jalview.api.ViewStyleI#setFontSize(int)
163 public void setFontSize(int size)
165 viewStyle.setFontSize(size);
170 * @see jalview.api.ViewStyleI#getFontStyle()
173 public int getFontStyle()
175 return viewStyle.getFontStyle();
180 * @see jalview.api.ViewStyleI#getFontName()
183 public String getFontName()
185 return viewStyle.getFontName();
190 * @see jalview.api.ViewStyleI#getFontSize()
193 public int getFontSize()
195 return viewStyle.getFontSize();
199 * @param upperCasebold
200 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
203 public void setUpperCasebold(boolean upperCasebold)
205 viewStyle.setUpperCasebold(upperCasebold);
210 * @see jalview.api.ViewStyleI#isUpperCasebold()
213 public boolean isUpperCasebold()
215 return viewStyle.isUpperCasebold();
220 * @see jalview.api.ViewStyleI#isSeqNameItalics()
223 public boolean isSeqNameItalics()
225 return viewStyle.isSeqNameItalics();
229 * @param colourByReferenceSeq
230 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
233 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
235 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
240 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
243 public void setColourAppliesToAllGroups(boolean b)
245 viewStyle.setColourAppliesToAllGroups(b);
250 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
253 public boolean getColourAppliesToAllGroups()
255 return viewStyle.getColourAppliesToAllGroups();
260 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
263 public boolean getAbovePIDThreshold()
265 return viewStyle.getAbovePIDThreshold();
270 * @see jalview.api.ViewStyleI#setIncrement(int)
273 public void setIncrement(int inc)
275 viewStyle.setIncrement(inc);
280 * @see jalview.api.ViewStyleI#getIncrement()
283 public int getIncrement()
285 return viewStyle.getIncrement();
290 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
293 public void setConservationSelected(boolean b)
295 viewStyle.setConservationSelected(b);
300 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
303 public void setShowHiddenMarkers(boolean show)
305 viewStyle.setShowHiddenMarkers(show);
310 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
313 public boolean getShowHiddenMarkers()
315 return viewStyle.getShowHiddenMarkers();
320 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
323 public void setScaleRightWrapped(boolean b)
325 viewStyle.setScaleRightWrapped(b);
330 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
333 public void setScaleLeftWrapped(boolean b)
335 viewStyle.setScaleLeftWrapped(b);
340 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
343 public void setScaleAboveWrapped(boolean b)
345 viewStyle.setScaleAboveWrapped(b);
350 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
353 public boolean getScaleLeftWrapped()
355 return viewStyle.getScaleLeftWrapped();
360 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
363 public boolean getScaleAboveWrapped()
365 return viewStyle.getScaleAboveWrapped();
370 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
373 public boolean getScaleRightWrapped()
375 return viewStyle.getScaleRightWrapped();
380 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
383 public void setAbovePIDThreshold(boolean b)
385 viewStyle.setAbovePIDThreshold(b);
390 * @see jalview.api.ViewStyleI#setThreshold(int)
393 public void setThreshold(int thresh)
395 viewStyle.setThreshold(thresh);
400 * @see jalview.api.ViewStyleI#getThreshold()
403 public int getThreshold()
405 return viewStyle.getThreshold();
410 * @see jalview.api.ViewStyleI#getShowJVSuffix()
413 public boolean getShowJVSuffix()
415 return viewStyle.getShowJVSuffix();
420 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
423 public void setShowJVSuffix(boolean b)
425 viewStyle.setShowJVSuffix(b);
430 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
433 public void setWrapAlignment(boolean state)
435 viewStyle.setWrapAlignment(state);
436 ranges.setWrappedMode(state);
441 * @see jalview.api.ViewStyleI#setShowText(boolean)
444 public void setShowText(boolean state)
446 viewStyle.setShowText(state);
451 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
454 public void setRenderGaps(boolean state)
456 viewStyle.setRenderGaps(state);
461 * @see jalview.api.ViewStyleI#getColourText()
464 public boolean getColourText()
466 return viewStyle.getColourText();
471 * @see jalview.api.ViewStyleI#setColourText(boolean)
474 public void setColourText(boolean state)
476 viewStyle.setColourText(state);
481 * @see jalview.api.ViewStyleI#getWrapAlignment()
484 public boolean getWrapAlignment()
486 return viewStyle.getWrapAlignment();
491 * @see jalview.api.ViewStyleI#getShowText()
494 public boolean getShowText()
496 return viewStyle.getShowText();
501 * @see jalview.api.ViewStyleI#getWrappedWidth()
504 public int getWrappedWidth()
506 return viewStyle.getWrappedWidth();
511 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
514 public void setWrappedWidth(int w)
516 viewStyle.setWrappedWidth(w);
521 * @see jalview.api.ViewStyleI#getCharHeight()
524 public int getCharHeight()
526 return viewStyle.getCharHeight();
531 * @see jalview.api.ViewStyleI#setCharHeight(int)
534 public void setCharHeight(int h)
536 viewStyle.setCharHeight(h);
541 * @see jalview.api.ViewStyleI#getCharWidth()
544 public int getCharWidth()
546 return viewStyle.getCharWidth();
551 * @see jalview.api.ViewStyleI#setCharWidth(int)
554 public void setCharWidth(int w)
556 viewStyle.setCharWidth(w);
561 * @see jalview.api.ViewStyleI#getShowBoxes()
564 public boolean getShowBoxes()
566 return viewStyle.getShowBoxes();
571 * @see jalview.api.ViewStyleI#getShowUnconserved()
574 public boolean getShowUnconserved()
576 return viewStyle.getShowUnconserved();
580 * @param showunconserved
581 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
584 public void setShowUnconserved(boolean showunconserved)
586 viewStyle.setShowUnconserved(showunconserved);
591 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
594 public void setSeqNameItalics(boolean default1)
596 viewStyle.setSeqNameItalics(default1);
600 public AlignmentI getAlignment()
606 public char getGapCharacter()
608 return alignment.getGapCharacter();
611 protected String sequenceSetID;
614 * probably unused indicator that view is of a dataset rather than an
617 protected boolean isDataset = false;
619 public void setDataset(boolean b)
624 public boolean isDataset()
629 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
631 protected ColumnSelection colSel = new ColumnSelection();
633 public boolean autoCalculateConsensus = true;
635 protected boolean autoCalculateStrucConsensus = true;
637 protected boolean ignoreGapsInConsensusCalculation = false;
639 protected ResidueShaderI residueShading = new ResidueShader();
642 public void setGlobalColourScheme(ColourSchemeI cs)
644 // TODO: logic refactored from AlignFrame changeColour -
645 // TODO: autorecalc stuff should be changed to rely on the worker system
646 // check to see if we should implement a changeColour(cs) method rather than
647 // put the logic in here
648 // - means that caller decides if they want to just modify state and defer
649 // calculation till later or to do all calculations in thread.
653 * only instantiate alignment colouring once, thereafter update it;
654 * this means that any conservation or PID threshold settings
655 * persist when the alignment colour scheme is changed
657 if (residueShading == null)
659 residueShading = new ResidueShader(viewStyle);
661 residueShading.setColourScheme(cs);
663 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
664 // ...problem: groups need these, but do not currently have a ViewStyle
668 if (getConservationSelected())
670 residueShading.setConservation(hconservation);
673 * reset conservation flag in case just set to false if
674 * Conservation was null (calculation still in progress)
676 residueShading.setConservationApplied(getConservationSelected());
677 residueShading.alignmentChanged(alignment, hiddenRepSequences);
681 * if 'apply colour to all groups' is selected... do so
682 * (but don't transfer any colour threshold settings to groups)
684 if (getColourAppliesToAllGroups())
686 for (SequenceGroup sg : getAlignment().getGroups())
689 * retain any colour thresholds per group while
690 * changing choice of colour scheme (JAL-2386)
693 cs == null ? null : cs.getInstance(this, sg));
696 sg.getGroupColourScheme().alignmentChanged(sg,
704 public ColourSchemeI getGlobalColourScheme()
706 return residueShading == null ? null : residueShading.getColourScheme();
710 public ResidueShaderI getResidueShading()
712 return residueShading;
715 protected AlignmentAnnotation consensus;
717 protected AlignmentAnnotation complementConsensus;
719 protected AlignmentAnnotation gapcounts;
721 protected AlignmentAnnotation strucConsensus;
723 protected AlignmentAnnotation conservation;
725 protected AlignmentAnnotation quality;
727 protected AlignmentAnnotation[] groupConsensus;
729 protected AlignmentAnnotation[] groupConservation;
732 * results of alignment consensus analysis for visible portion of view
734 protected ProfilesI hconsensus = null;
737 * results of cDNA complement consensus visible portion of view
739 protected Hashtable<String, Object>[] hcomplementConsensus = null;
742 * results of secondary structure base pair consensus for visible portion of
745 protected Hashtable<String, Object>[] hStrucConsensus = null;
747 protected Conservation hconservation = null;
750 public void setConservation(Conservation cons)
752 hconservation = cons;
756 * percentage gaps allowed in a column before all amino acid properties should
757 * be considered unconserved
759 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
762 public int getConsPercGaps()
768 public void setSequenceConsensusHash(ProfilesI hconsensus)
770 this.hconsensus = hconsensus;
774 public void setComplementConsensusHash(
775 Hashtable<String, Object>[] hconsensus)
777 this.hcomplementConsensus = hconsensus;
781 public ProfilesI getSequenceConsensusHash()
787 public void setHmmProfiles(ProfilesI info)
793 public ProfilesI getHmmProfiles()
799 public Hashtable<String, Object>[] getComplementConsensusHash()
801 return hcomplementConsensus;
805 public Hashtable<String, Object>[] getRnaStructureConsensusHash()
807 return hStrucConsensus;
811 public void setRnaStructureConsensusHash(
812 Hashtable<String, Object>[] hStrucConsensus)
814 this.hStrucConsensus = hStrucConsensus;
819 public AlignmentAnnotation getAlignmentQualityAnnot()
825 public AlignmentAnnotation getAlignmentConservationAnnotation()
831 public AlignmentAnnotation getAlignmentConsensusAnnotation()
837 public AlignmentAnnotation getAlignmentGapAnnotation()
843 public AlignmentAnnotation getComplementConsensusAnnotation()
845 return complementConsensus;
849 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
851 return strucConsensus;
854 protected AlignCalcManagerI2 calculator = new AlignCalcManager2();
857 * trigger update of conservation annotation
859 public void updateConservation(final AlignmentViewPanel ap)
861 // see note in mantis : issue number 8585
862 if (alignment.isNucleotide()
863 || (conservation == null && quality == null)
864 || !autoCalculateConsensus)
868 if (calculator.getWorkersOfClass(
869 jalview.workers.ConservationThread.class).isEmpty())
871 calculator.registerWorker(
872 new jalview.workers.ConservationThread(this, ap));
877 * trigger update of consensus annotation
879 public void updateConsensus(final AlignmentViewPanel ap)
881 // see note in mantis : issue number 8585
882 if (consensus == null || !autoCalculateConsensus)
886 if (calculator.getWorkersOfClass(ConsensusThread.class).isEmpty())
888 calculator.registerWorker(new ConsensusThread(this, ap));
892 * A separate thread to compute cDNA consensus for a protein alignment
893 * which has mapping to cDNA
895 final AlignmentI al = this.getAlignment();
896 if (!al.isNucleotide() && al.getCodonFrames() != null
897 && !al.getCodonFrames().isEmpty())
900 * fudge - check first for protein-to-nucleotide mappings
901 * (we don't want to do this for protein-to-protein)
903 boolean doConsensus = false;
904 for (AlignedCodonFrame mapping : al.getCodonFrames())
906 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
907 MapList[] mapLists = mapping.getdnaToProt();
908 // mapLists can be empty if project load has not finished resolving seqs
909 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
917 if (calculator.getWorkersOfClass(ComplementConsensusThread.class).isEmpty())
919 calculator.registerWorker(new ComplementConsensusThread(this, ap));
926 public void initInformationWorker(final AlignmentViewPanel ap)
928 if (calculator.getWorkersOfClass(InformationThread.class).isEmpty())
930 calculator.registerWorker(new InformationThread(this, ap));
934 // --------START Structure Conservation
935 public void updateStrucConsensus(final AlignmentViewPanel ap)
937 if (autoCalculateStrucConsensus && strucConsensus == null
938 && alignment.isNucleotide() && alignment.hasRNAStructure())
940 // secondary structure has been added - so init the consensus line
944 // see note in mantis : issue number 8585
945 if (strucConsensus == null || !autoCalculateStrucConsensus)
949 if (calculator.getWorkersOfClass(StrucConsensusThread.class).isEmpty())
951 calculator.registerWorker(new StrucConsensusThread(this, ap));
955 public boolean isCalcInProgress()
957 return calculator.isWorking();
961 public boolean isCalculationInProgress(
962 AlignmentAnnotation alignmentAnnotation)
964 if (!alignmentAnnotation.autoCalculated)
968 if (calculator.isWorkingWithAnnotation(alignmentAnnotation))
970 // System.err.println("grey out ("+alignmentAnnotation.label+")");
976 public void setAlignment(AlignmentI align)
978 this.alignment = align;
982 * Clean up references when this viewport is closed
985 public void dispose()
988 * defensively null out references to large objects in case
989 * this object is not garbage collected (as if!)
992 complementConsensus = null;
993 strucConsensus = null;
996 consensusProfiles = null;
997 groupConsensus = null;
998 groupConservation = null;
1000 hconservation = null;
1001 hcomplementConsensus = null;
1004 residueShading = null; // may hold a reference to Consensus
1005 changeSupport = null;
1008 selectionGroup = null;
1013 public boolean isClosed()
1015 // TODO: check that this isClosed is only true after panel is closed, not
1016 // before it is fully constructed.
1017 return alignment == null;
1021 public AlignCalcManagerI2 getCalcManager()
1027 * should conservation rows be shown for groups
1029 protected boolean showGroupConservation = false;
1032 * should consensus rows be shown for groups
1034 protected boolean showGroupConsensus = false;
1037 * should consensus profile be rendered by default
1039 protected boolean showSequenceLogo = false;
1042 * should consensus profile be rendered normalised to row height
1044 protected boolean normaliseSequenceLogo = false;
1047 * should consensus histograms be rendered by default
1049 protected boolean showConsensusHistogram = true;
1052 * should hmm profile be rendered by default
1054 protected boolean hmmShowSequenceLogo = false;
1057 * should hmm profile be rendered normalised to row height
1059 protected boolean hmmNormaliseSequenceLogo = false;
1062 * should information histograms be rendered by default
1064 protected boolean hmmShowHistogram = true;
1067 * @return the showConsensusProfile
1070 public boolean isShowSequenceLogo()
1072 return showSequenceLogo;
1076 * @return the showInformationProfile
1079 public boolean isShowHMMSequenceLogo()
1081 return hmmShowSequenceLogo;
1085 * @param showSequenceLogo
1088 public void setShowSequenceLogo(boolean showSequenceLogo)
1090 if (showSequenceLogo != this.showSequenceLogo)
1092 // TODO: decouple settings setting from calculation when refactoring
1093 // annotation update method from alignframe to viewport
1094 this.showSequenceLogo = showSequenceLogo;
1095 for (AlignCalcWorkerI worker : calculator.getWorkers())
1097 if (worker.getClass().equals(ConsensusThread.class) ||
1098 worker.getClass().equals(ComplementConsensusThread.class) ||
1099 worker.getClass().equals(StrucConsensusThread.class))
1101 worker.updateAnnotation();
1105 this.showSequenceLogo = showSequenceLogo;
1108 public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo)
1110 if (showHMMSequenceLogo != this.hmmShowSequenceLogo)
1112 this.hmmShowSequenceLogo = showHMMSequenceLogo;
1113 // TODO: updateAnnotation if description (tooltip) will show
1114 // profile in place of information content?
1115 // calculator.updateAnnotationFor(InformationThread.class);
1117 this.hmmShowSequenceLogo = showHMMSequenceLogo;
1121 * @param showConsensusHistogram
1122 * the showConsensusHistogram to set
1124 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1126 this.showConsensusHistogram = showConsensusHistogram;
1130 * @param showInformationHistogram
1132 public void setShowInformationHistogram(boolean showInformationHistogram)
1134 this.hmmShowHistogram = showInformationHistogram;
1138 * @return the showGroupConservation
1140 public boolean isShowGroupConservation()
1142 return showGroupConservation;
1146 * @param showGroupConservation
1147 * the showGroupConservation to set
1149 public void setShowGroupConservation(boolean showGroupConservation)
1151 this.showGroupConservation = showGroupConservation;
1155 * @return the showGroupConsensus
1157 public boolean isShowGroupConsensus()
1159 return showGroupConsensus;
1163 * @param showGroupConsensus
1164 * the showGroupConsensus to set
1166 public void setShowGroupConsensus(boolean showGroupConsensus)
1168 this.showGroupConsensus = showGroupConsensus;
1173 * @return flag to indicate if the consensus histogram should be rendered by
1177 public boolean isShowConsensusHistogram()
1179 return this.showConsensusHistogram;
1184 * @return flag to indicate if the information content histogram should be
1185 * rendered by default
1188 public boolean isShowInformationHistogram()
1190 return this.hmmShowHistogram;
1194 * when set, updateAlignment will always ensure sequences are of equal length
1196 private boolean padGaps = false;
1199 * when set, alignment should be reordered according to a newly opened tree
1201 public boolean sortByTree = false;
1206 * @return null or the currently selected sequence region
1209 public SequenceGroup getSelectionGroup()
1211 return selectionGroup;
1215 * Set the selection group for this window. Also sets the current alignment as
1216 * the context for the group, if it does not already have one.
1219 * - group holding references to sequences in this alignment view
1223 public void setSelectionGroup(SequenceGroup sg)
1225 selectionGroup = sg;
1226 if (sg != null && sg.getContext() == null)
1228 sg.setContext(alignment);
1232 public void setHiddenColumns(HiddenColumns hidden)
1234 this.alignment.setHiddenColumns(hidden);
1238 public ColumnSelection getColumnSelection()
1244 public void setColumnSelection(ColumnSelection colSel)
1246 this.colSel = colSel;
1249 updateHiddenColumns();
1251 isColSelChanged(true);
1259 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1261 return hiddenRepSequences;
1265 public void setHiddenRepSequences(
1266 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1268 this.hiddenRepSequences = hiddenRepSequences;
1272 public boolean hasSelectedColumns()
1274 ColumnSelection columnSelection = getColumnSelection();
1275 return columnSelection != null && columnSelection.hasSelectedColumns();
1279 public boolean hasHiddenColumns()
1281 return alignment.getHiddenColumns() != null
1282 && alignment.getHiddenColumns().hasHiddenColumns();
1285 public void updateHiddenColumns()
1287 // this method doesn't really do anything now. But - it could, since a
1288 // column Selection could be in the process of modification
1289 // hasHiddenColumns = colSel.hasHiddenColumns();
1293 public boolean hasHiddenRows()
1295 return alignment.getHiddenSequences().getSize() > 0;
1298 protected SequenceGroup selectionGroup;
1300 public void setSequenceSetId(String newid)
1302 if (sequenceSetID != null)
1305 "Warning - overwriting a sequenceSetId for a viewport!");
1307 sequenceSetID = new String(newid);
1311 public String getSequenceSetId()
1313 if (sequenceSetID == null)
1315 sequenceSetID = alignment.hashCode() + "";
1318 return sequenceSetID;
1322 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1325 protected String viewId = null;
1328 public String getViewId()
1332 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1337 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1339 ignoreGapsInConsensusCalculation = b;
1342 updateConsensus(ap);
1343 if (residueShading != null)
1345 residueShading.setThreshold(residueShading.getThreshold(),
1346 ignoreGapsInConsensusCalculation);
1351 public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap)
1353 ignoreBelowBackGroundFrequencyCalculation = b;
1356 public void setInfoLetterHeight(boolean b, AlignmentViewPanel ap)
1358 infoLetterHeight = b;
1361 private long sgrouphash = -1, colselhash = -1;
1364 * checks current SelectionGroup against record of last hash value, and
1368 * update the record of last hash value
1370 * @return true if SelectionGroup changed since last call (when b is true)
1372 public boolean isSelectionGroupChanged(boolean b)
1374 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1375 : selectionGroup.hashCode();
1376 if (hc != -1 && hc != sgrouphash)
1388 * checks current colsel against record of last hash value, and optionally
1392 * update the record of last hash value
1393 * @return true if colsel changed since last call (when b is true)
1395 public boolean isColSelChanged(boolean b)
1397 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1398 if (hc != -1 && hc != colselhash)
1410 public boolean isIgnoreGapsConsensus()
1412 return ignoreGapsInConsensusCalculation;
1416 public boolean isIgnoreBelowBackground()
1418 return ignoreBelowBackGroundFrequencyCalculation;
1422 public boolean isInfoLetterHeight()
1424 return infoLetterHeight;
1427 // property change stuff
1428 // JBPNote Prolly only need this in the applet version.
1429 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1432 protected boolean showConservation = true;
1434 protected boolean showQuality = true;
1436 protected boolean showConsensus = true;
1438 protected boolean showOccupancy = true;
1440 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1442 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1444 protected boolean showAutocalculatedAbove;
1447 * when set, view will scroll to show the highlighted position
1449 private boolean followHighlight = true;
1452 * Property change listener for changes in alignment
1457 public void addPropertyChangeListener(
1458 java.beans.PropertyChangeListener listener)
1460 changeSupport.addPropertyChangeListener(listener);
1469 public void removePropertyChangeListener(
1470 java.beans.PropertyChangeListener listener)
1472 if (changeSupport != null)
1474 changeSupport.removePropertyChangeListener(listener);
1479 * Property change listener for changes in alignment
1488 public void firePropertyChange(String prop, Object oldvalue,
1491 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1494 // common hide/show column stuff
1496 public void hideSelectedColumns()
1498 if (colSel.isEmpty())
1503 colSel.hideSelectedColumns(alignment);
1504 setSelectionGroup(null);
1505 isColSelChanged(true);
1508 public void hideColumns(int start, int end)
1512 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1516 alignment.getHiddenColumns().hideColumns(start, end);
1518 isColSelChanged(true);
1521 public void showColumn(int col)
1523 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1524 isColSelChanged(true);
1527 public void showAllHiddenColumns()
1529 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1530 isColSelChanged(true);
1533 // common hide/show seq stuff
1534 public void showAllHiddenSeqs()
1536 int startSeq = ranges.getStartSeq();
1537 int endSeq = ranges.getEndSeq();
1539 if (alignment.getHiddenSequences().getSize() > 0)
1541 if (selectionGroup == null)
1543 selectionGroup = new SequenceGroup();
1544 selectionGroup.setEndRes(alignment.getWidth() - 1);
1546 List<SequenceI> tmp = alignment.getHiddenSequences()
1547 .showAll(hiddenRepSequences);
1548 for (SequenceI seq : tmp)
1550 selectionGroup.addSequence(seq, false);
1551 setSequenceAnnotationsVisible(seq, true);
1554 hiddenRepSequences = null;
1556 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1558 firePropertyChange("alignment", null, alignment.getSequences());
1559 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1565 public void showSequence(int index)
1567 int startSeq = ranges.getStartSeq();
1568 int endSeq = ranges.getEndSeq();
1570 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1571 hiddenRepSequences);
1574 if (selectionGroup == null)
1576 selectionGroup = new SequenceGroup();
1577 selectionGroup.setEndRes(alignment.getWidth() - 1);
1580 for (SequenceI seq : tmp)
1582 selectionGroup.addSequence(seq, false);
1583 setSequenceAnnotationsVisible(seq, true);
1586 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1588 firePropertyChange("alignment", null, alignment.getSequences());
1593 public void hideAllSelectedSeqs()
1595 if (selectionGroup == null || selectionGroup.getSize() < 1)
1600 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1604 setSelectionGroup(null);
1607 public void hideSequence(SequenceI[] seq)
1610 * cache offset to first visible sequence
1612 int startSeq = ranges.getStartSeq();
1616 for (int i = 0; i < seq.length; i++)
1618 alignment.getHiddenSequences().hideSequence(seq[i]);
1619 setSequenceAnnotationsVisible(seq[i], false);
1621 ranges.setStartSeq(startSeq);
1622 firePropertyChange("alignment", null, alignment.getSequences());
1627 * Hides the specified sequence, or the sequences it represents
1630 * the sequence to hide, or keep as representative
1631 * @param representGroup
1632 * if true, hide the current selection group except for the
1633 * representative sequence
1635 public void hideSequences(SequenceI sequence, boolean representGroup)
1637 if (selectionGroup == null || selectionGroup.getSize() < 1)
1639 hideSequence(new SequenceI[] { sequence });
1645 hideRepSequences(sequence, selectionGroup);
1646 setSelectionGroup(null);
1650 int gsize = selectionGroup.getSize();
1651 SequenceI[] hseqs = selectionGroup.getSequences()
1652 .toArray(new SequenceI[gsize]);
1654 hideSequence(hseqs);
1655 setSelectionGroup(null);
1660 * Set visibility for any annotations for the given sequence.
1664 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1667 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1670 for (AlignmentAnnotation ann : anns)
1672 if (ann.sequenceRef == sequenceI)
1674 ann.visible = visible;
1680 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1682 int sSize = sg.getSize();
1688 if (hiddenRepSequences == null)
1690 hiddenRepSequences = new Hashtable<>();
1693 hiddenRepSequences.put(repSequence, sg);
1695 // Hide all sequences except the repSequence
1696 SequenceI[] seqs = new SequenceI[sSize - 1];
1698 for (int i = 0; i < sSize; i++)
1700 if (sg.getSequenceAt(i) != repSequence)
1702 if (index == sSize - 1)
1707 seqs[index++] = sg.getSequenceAt(i);
1710 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1711 sg.setHidereps(true); // note: not done in 2.7applet
1718 * @return null or the current reference sequence
1720 public SequenceI getReferenceSeq()
1722 return alignment.getSeqrep();
1727 * @return true iff seq is the reference for the alignment
1729 public boolean isReferenceSeq(SequenceI seq)
1731 return alignment.getSeqrep() == seq;
1737 * @return true if there are sequences represented by this sequence that are
1740 public boolean isHiddenRepSequence(SequenceI seq)
1742 return (hiddenRepSequences != null
1743 && hiddenRepSequences.containsKey(seq));
1749 * @return null or a sequence group containing the sequences that seq
1752 public SequenceGroup getRepresentedSequences(SequenceI seq)
1754 return (SequenceGroup) (hiddenRepSequences == null ? null
1755 : hiddenRepSequences.get(seq));
1759 public int adjustForHiddenSeqs(int alignmentIndex)
1761 return alignment.getHiddenSequences()
1762 .adjustForHiddenSeqs(alignmentIndex);
1766 public void invertColumnSelection()
1768 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1769 isColSelChanged(true);
1773 public SequenceI[] getSelectionAsNewSequence()
1775 SequenceI[] sequences;
1776 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1777 // this was the only caller in the applet for this method
1778 // JBPNote: in applet, this method returned references to the alignment
1779 // sequences, and it did not honour the presence/absence of annotation
1780 // attached to the alignment (probably!)
1781 if (selectionGroup == null || selectionGroup.getSize() == 0)
1783 sequences = alignment.getSequencesArray();
1784 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1785 for (int i = 0; i < sequences.length; i++)
1787 // construct new sequence with subset of visible annotation
1788 sequences[i] = new Sequence(sequences[i], annots);
1793 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1800 public SequenceI[] getSequenceSelection()
1802 SequenceI[] sequences = null;
1803 if (selectionGroup != null)
1805 sequences = selectionGroup.getSequencesInOrder(alignment);
1807 if (sequences == null)
1809 sequences = alignment.getSequencesArray();
1815 public jalview.datamodel.AlignmentView getAlignmentView(
1816 boolean selectedOnly)
1818 return getAlignmentView(selectedOnly, false);
1822 public jalview.datamodel.AlignmentView getAlignmentView(
1823 boolean selectedOnly, boolean markGroups)
1825 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1827 alignment.getHiddenColumns() != null
1828 && alignment.getHiddenColumns().hasHiddenColumns(),
1829 selectedOnly, markGroups);
1833 public String[] getViewAsString(boolean selectedRegionOnly)
1835 return getViewAsString(selectedRegionOnly, true);
1839 public String[] getViewAsString(boolean selectedRegionOnly,
1840 boolean exportHiddenSeqs)
1842 String[] selection = null;
1843 SequenceI[] seqs = null;
1845 int start = 0, end = 0;
1846 if (selectedRegionOnly && selectionGroup != null)
1848 iSize = selectionGroup.getSize();
1849 seqs = selectionGroup.getSequencesInOrder(alignment);
1850 start = selectionGroup.getStartRes();
1851 end = selectionGroup.getEndRes() + 1;
1855 if (hasHiddenRows() && exportHiddenSeqs)
1857 AlignmentI fullAlignment = alignment.getHiddenSequences()
1858 .getFullAlignment();
1859 iSize = fullAlignment.getHeight();
1860 seqs = fullAlignment.getSequencesArray();
1861 end = fullAlignment.getWidth();
1865 iSize = alignment.getHeight();
1866 seqs = alignment.getSequencesArray();
1867 end = alignment.getWidth();
1871 selection = new String[iSize];
1872 if (alignment.getHiddenColumns() != null
1873 && alignment.getHiddenColumns().hasHiddenColumns())
1875 for (i = 0; i < iSize; i++)
1877 Iterator<int[]> blocks = alignment.getHiddenColumns()
1878 .getVisContigsIterator(start, end + 1, false);
1879 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1884 for (i = 0; i < iSize; i++)
1886 selection[i] = seqs[i].getSequenceAsString(start, end);
1894 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1896 ArrayList<int[]> regions = new ArrayList<>();
1902 HiddenColumns hidden = alignment.getHiddenColumns();
1903 if (hidden != null && hidden.hasHiddenColumns())
1907 start = hidden.visibleToAbsoluteColumn(start);
1910 end = hidden.getNextHiddenBoundary(false, start);
1921 regions.add(new int[] { start, end });
1923 if (hidden != null && hidden.hasHiddenColumns())
1925 start = hidden.visibleToAbsoluteColumn(end);
1926 start = hidden.getNextHiddenBoundary(true, start) + 1;
1928 } while (end < max);
1930 // int[][] startEnd = new int[regions.size()][2];
1936 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1937 boolean selectedOnly)
1939 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1940 AlignmentAnnotation[] aa;
1941 if ((aa = alignment.getAlignmentAnnotation()) != null)
1943 for (AlignmentAnnotation annot : aa)
1945 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1946 if (selectedOnly && selectionGroup != null)
1948 clone.makeVisibleAnnotation(
1949 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1950 alignment.getHiddenColumns());
1954 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1963 public boolean isPadGaps()
1969 public void setPadGaps(boolean padGaps)
1971 this.padGaps = padGaps;
1975 * apply any post-edit constraints and trigger any calculations needed after
1976 * an edit has been performed on the alignment
1981 public void alignmentChanged(AlignmentViewPanel ap)
1985 alignment.padGaps();
1987 if (autoCalculateConsensus)
1989 updateConsensus(ap);
1991 if (hconsensus != null && autoCalculateConsensus)
1993 updateConservation(ap);
1995 if (autoCalculateStrucConsensus)
1997 updateStrucConsensus(ap);
2000 // Reset endRes of groups if beyond alignment width
2001 int alWidth = alignment.getWidth();
2002 List<SequenceGroup> groups = alignment.getGroups();
2005 for (SequenceGroup sg : groups)
2007 if (sg.getEndRes() > alWidth)
2009 sg.setEndRes(alWidth - 1);
2014 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
2016 selectionGroup.setEndRes(alWidth - 1);
2019 updateAllColourSchemes();
2020 calculator.restartWorkers();
2024 * reset scope and do calculations for all applied colourschemes on alignment
2026 void updateAllColourSchemes()
2028 ResidueShaderI rs = residueShading;
2031 rs.alignmentChanged(alignment, hiddenRepSequences);
2033 rs.setConsensus(hconsensus);
2034 if (rs.conservationApplied())
2036 rs.setConservation(Conservation.calculateConservation("All",
2037 alignment.getSequences(), 0, alignment.getWidth(), false,
2038 getConsPercGaps(), false));
2042 for (SequenceGroup sg : alignment.getGroups())
2046 sg.cs.alignmentChanged(sg, hiddenRepSequences);
2048 sg.recalcConservation();
2052 protected void initAutoAnnotation()
2054 // TODO: add menu option action that nulls or creates consensus object
2055 // depending on if the user wants to see the annotation or not in a
2056 // specific alignment
2058 if (hconsensus == null && !isDataset)
2060 if (!alignment.isNucleotide())
2069 consensus = new AlignmentAnnotation("Consensus",
2070 MessageManager.getString("label.consensus_descr"),
2071 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2072 initConsensus(consensus);
2076 initComplementConsensus();
2081 * If this is a protein alignment and there are mappings to cDNA, adds the
2082 * cDNA consensus annotation and returns true, else returns false.
2084 public boolean initComplementConsensus()
2086 if (!alignment.isNucleotide())
2088 final List<AlignedCodonFrame> codonMappings = alignment
2090 if (codonMappings != null && !codonMappings.isEmpty())
2092 boolean doConsensus = false;
2093 for (AlignedCodonFrame mapping : codonMappings)
2095 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2096 MapList[] mapLists = mapping.getdnaToProt();
2097 // mapLists can be empty if project load has not finished resolving
2099 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2107 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2109 .getString("label.complement_consensus_descr"),
2110 new Annotation[1], 0f, 100f,
2111 AlignmentAnnotation.BAR_GRAPH);
2112 initConsensus(complementConsensus);
2120 private void initConsensus(AlignmentAnnotation aa)
2123 aa.autoCalculated = true;
2127 alignment.addAnnotation(aa);
2131 // these should be extracted from the view model - style and settings for
2132 // derived annotation
2133 private void initGapCounts()
2137 gapcounts = new AlignmentAnnotation("Occupancy",
2138 MessageManager.getString("label.occupancy_descr"),
2139 new Annotation[1], 0f, alignment.getHeight(),
2140 AlignmentAnnotation.BAR_GRAPH);
2141 gapcounts.hasText = true;
2142 gapcounts.autoCalculated = true;
2143 gapcounts.scaleColLabel = true;
2144 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2146 alignment.addAnnotation(gapcounts);
2150 private void initConservation()
2152 if (showConservation)
2154 if (conservation == null)
2156 conservation = new AlignmentAnnotation("Conservation",
2157 MessageManager.formatMessage("label.conservation_descr",
2159 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2160 conservation.hasText = true;
2161 conservation.autoCalculated = true;
2162 alignment.addAnnotation(conservation);
2167 private void initQuality()
2171 if (quality == null)
2173 quality = new AlignmentAnnotation("Quality",
2174 MessageManager.getString("label.quality_descr"),
2175 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2176 quality.hasText = true;
2177 quality.autoCalculated = true;
2178 alignment.addAnnotation(quality);
2183 private void initRNAStructure()
2185 if (alignment.hasRNAStructure() && strucConsensus == null)
2187 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2188 MessageManager.getString("label.strucconsensus_descr"),
2189 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2190 strucConsensus.hasText = true;
2191 strucConsensus.autoCalculated = true;
2195 alignment.addAnnotation(strucConsensus);
2203 * @see jalview.api.AlignViewportI#calcPanelHeight()
2206 public int calcPanelHeight()
2208 // setHeight of panels
2209 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2211 int charHeight = getCharHeight();
2214 BitSet graphgrp = new BitSet();
2215 for (AlignmentAnnotation aa : anns)
2219 System.err.println("Null annotation row: ignoring.");
2226 if (aa.graphGroup > -1)
2228 if (graphgrp.get(aa.graphGroup))
2234 graphgrp.set(aa.graphGroup);
2241 aa.height += charHeight;
2251 aa.height += aa.graphHeight;
2259 height += aa.height;
2271 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2272 boolean preserveNewGroupSettings)
2274 boolean updateCalcs = false;
2275 boolean conv = isShowGroupConservation();
2276 boolean cons = isShowGroupConsensus();
2277 boolean showprf = isShowSequenceLogo();
2278 boolean showConsHist = isShowConsensusHistogram();
2279 boolean normLogo = isNormaliseSequenceLogo();
2280 boolean showHMMPrf = isShowHMMSequenceLogo();
2281 boolean showInfoHist = isShowInformationHistogram();
2282 boolean normHMMLogo = isNormaliseHMMSequenceLogo();
2285 * TODO reorder the annotation rows according to group/sequence ordering on
2288 // boolean sortg = true;
2290 // remove old automatic annotation
2291 // add any new annotation
2293 // intersect alignment annotation with alignment groups
2295 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2296 List<SequenceGroup> oldrfs = new ArrayList<>();
2299 for (int an = 0; an < aan.length; an++)
2301 if (aan[an].autoCalculated && aan[an].groupRef != null)
2303 oldrfs.add(aan[an].groupRef);
2304 alignment.deleteAnnotation(aan[an], false);
2308 if (alignment.getGroups() != null)
2310 for (SequenceGroup sg : alignment.getGroups())
2312 updateCalcs = false;
2313 if (applyGlobalSettings
2314 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2316 // set defaults for this group's conservation/consensus
2317 sg.setshowSequenceLogo(showprf);
2318 sg.setShowConsensusHistogram(showConsHist);
2319 sg.setNormaliseSequenceLogo(normLogo);
2320 sg.setShowHMMSequenceLogo(showHMMPrf);
2321 sg.setShowInformationHistogram(showInfoHist);
2322 sg.setNormaliseHMMSequenceLogo(normHMMLogo);
2327 alignment.addAnnotation(sg.getConservationRow(), 0);
2332 alignment.addAnnotation(sg.getConsensus(), 0);
2334 // refresh the annotation rows
2337 sg.recalcConservation();
2345 public boolean isDisplayReferenceSeq()
2347 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2351 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2353 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2357 public boolean isColourByReferenceSeq()
2359 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2363 public Color getSequenceColour(SequenceI seq)
2365 Color sqc = sequenceColours.get(seq);
2366 return (sqc == null ? Color.white : sqc);
2370 public void setSequenceColour(SequenceI seq, Color col)
2374 sequenceColours.remove(seq);
2378 sequenceColours.put(seq, col);
2383 public void updateSequenceIdColours()
2385 for (SequenceGroup sg : alignment.getGroups())
2387 if (sg.idColour != null)
2389 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2391 sequenceColours.put(s, sg.idColour);
2398 public void clearSequenceColours()
2400 sequenceColours.clear();
2404 public AlignViewportI getCodingComplement()
2406 return this.codingComplement;
2410 * Set this as the (cDna/protein) complement of the given viewport. Also
2411 * ensures the reverse relationship is set on the given viewport.
2414 public void setCodingComplement(AlignViewportI av)
2418 System.err.println("Ignoring recursive setCodingComplement request");
2422 this.codingComplement = av;
2423 // avoid infinite recursion!
2424 if (av.getCodingComplement() != this)
2426 av.setCodingComplement(this);
2432 public boolean isNucleotide()
2434 return getAlignment() == null ? false : getAlignment().isNucleotide();
2438 public FeaturesDisplayedI getFeaturesDisplayed()
2440 return featuresDisplayed;
2444 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2446 featuresDisplayed = featuresDisplayedI;
2450 public boolean areFeaturesDisplayed()
2452 return featuresDisplayed != null
2453 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2460 * features are displayed if true
2463 public void setShowSequenceFeatures(boolean b)
2465 viewStyle.setShowSequenceFeatures(b);
2469 public boolean isShowSequenceFeatures()
2471 return viewStyle.isShowSequenceFeatures();
2475 public void setShowSequenceFeaturesHeight(boolean selected)
2477 viewStyle.setShowSequenceFeaturesHeight(selected);
2481 public boolean isShowSequenceFeaturesHeight()
2483 return viewStyle.isShowSequenceFeaturesHeight();
2487 public void setShowAnnotation(boolean b)
2489 viewStyle.setShowAnnotation(b);
2493 public boolean isShowAnnotation()
2495 return viewStyle.isShowAnnotation();
2499 public boolean isRightAlignIds()
2501 return viewStyle.isRightAlignIds();
2505 public void setRightAlignIds(boolean rightAlignIds)
2507 viewStyle.setRightAlignIds(rightAlignIds);
2511 public boolean getConservationSelected()
2513 return viewStyle.getConservationSelected();
2517 public void setShowBoxes(boolean state)
2519 viewStyle.setShowBoxes(state);
2524 * @see jalview.api.ViewStyleI#getTextColour()
2527 public Color getTextColour()
2529 return viewStyle.getTextColour();
2534 * @see jalview.api.ViewStyleI#getTextColour2()
2537 public Color getTextColour2()
2539 return viewStyle.getTextColour2();
2544 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2547 public int getThresholdTextColour()
2549 return viewStyle.getThresholdTextColour();
2554 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2557 public boolean isConservationColourSelected()
2559 return viewStyle.isConservationColourSelected();
2564 * @see jalview.api.ViewStyleI#isRenderGaps()
2567 public boolean isRenderGaps()
2569 return viewStyle.isRenderGaps();
2574 * @see jalview.api.ViewStyleI#isShowColourText()
2577 public boolean isShowColourText()
2579 return viewStyle.isShowColourText();
2583 * @param conservationColourSelected
2584 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2587 public void setConservationColourSelected(
2588 boolean conservationColourSelected)
2590 viewStyle.setConservationColourSelected(conservationColourSelected);
2594 * @param showColourText
2595 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2598 public void setShowColourText(boolean showColourText)
2600 viewStyle.setShowColourText(showColourText);
2605 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2608 public void setTextColour(Color textColour)
2610 viewStyle.setTextColour(textColour);
2614 * @param thresholdTextColour
2615 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2618 public void setThresholdTextColour(int thresholdTextColour)
2620 viewStyle.setThresholdTextColour(thresholdTextColour);
2624 * @param textColour2
2625 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2628 public void setTextColour2(Color textColour2)
2630 viewStyle.setTextColour2(textColour2);
2634 public ViewStyleI getViewStyle()
2636 return new ViewStyle(viewStyle);
2640 public void setViewStyle(ViewStyleI settingsForView)
2642 viewStyle = new ViewStyle(settingsForView);
2643 if (residueShading != null)
2645 residueShading.setConservationApplied(
2646 settingsForView.isConservationColourSelected());
2651 public boolean sameStyle(ViewStyleI them)
2653 return viewStyle.sameStyle(them);
2658 * @see jalview.api.ViewStyleI#getIdWidth()
2661 public int getIdWidth()
2663 return viewStyle.getIdWidth();
2668 * @see jalview.api.ViewStyleI#setIdWidth(int)
2671 public void setIdWidth(int i)
2673 viewStyle.setIdWidth(i);
2678 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2681 public boolean isCentreColumnLabels()
2683 return viewStyle.isCentreColumnLabels();
2687 * @param centreColumnLabels
2688 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2691 public void setCentreColumnLabels(boolean centreColumnLabels)
2693 viewStyle.setCentreColumnLabels(centreColumnLabels);
2698 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2701 public void setShowDBRefs(boolean showdbrefs)
2703 viewStyle.setShowDBRefs(showdbrefs);
2708 * @see jalview.api.ViewStyleI#isShowDBRefs()
2711 public boolean isShowDBRefs()
2713 return viewStyle.isShowDBRefs();
2718 * @see jalview.api.ViewStyleI#isShowNPFeats()
2721 public boolean isShowNPFeats()
2723 return viewStyle.isShowNPFeats();
2727 * @param shownpfeats
2728 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2731 public void setShowNPFeats(boolean shownpfeats)
2733 viewStyle.setShowNPFeats(shownpfeats);
2736 public abstract StructureSelectionManager getStructureSelectionManager();
2739 * Add one command to the command history list.
2743 public void addToHistoryList(CommandI command)
2745 if (this.historyList != null)
2747 this.historyList.push(command);
2748 broadcastCommand(command, false);
2752 protected void broadcastCommand(CommandI command, boolean undo)
2754 getStructureSelectionManager().commandPerformed(command, undo,
2759 * Add one command to the command redo list.
2763 public void addToRedoList(CommandI command)
2765 if (this.redoList != null)
2767 this.redoList.push(command);
2769 broadcastCommand(command, true);
2773 * Clear the command redo list.
2775 public void clearRedoList()
2777 if (this.redoList != null)
2779 this.redoList.clear();
2783 public void setHistoryList(Deque<CommandI> list)
2785 this.historyList = list;
2788 public Deque<CommandI> getHistoryList()
2790 return this.historyList;
2793 public void setRedoList(Deque<CommandI> list)
2795 this.redoList = list;
2798 public Deque<CommandI> getRedoList()
2800 return this.redoList;
2804 public VamsasSource getVamsasSource()
2809 public SequenceAnnotationOrder getSortAnnotationsBy()
2811 return sortAnnotationsBy;
2814 public void setSortAnnotationsBy(
2815 SequenceAnnotationOrder sortAnnotationsBy)
2817 this.sortAnnotationsBy = sortAnnotationsBy;
2820 public boolean isShowAutocalculatedAbove()
2822 return showAutocalculatedAbove;
2825 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2827 this.showAutocalculatedAbove = showAutocalculatedAbove;
2831 public boolean isScaleProteinAsCdna()
2833 return viewStyle.isScaleProteinAsCdna();
2837 public void setScaleProteinAsCdna(boolean b)
2839 viewStyle.setScaleProteinAsCdna(b);
2843 public boolean isProteinFontAsCdna()
2845 return viewStyle.isProteinFontAsCdna();
2849 public void setProteinFontAsCdna(boolean b)
2851 viewStyle.setProteinFontAsCdna(b);
2855 public void setShowComplementFeatures(boolean b)
2857 viewStyle.setShowComplementFeatures(b);
2861 public boolean isShowComplementFeatures()
2863 return viewStyle.isShowComplementFeatures();
2867 public void setShowComplementFeaturesOnTop(boolean b)
2869 viewStyle.setShowComplementFeaturesOnTop(b);
2873 public boolean isShowComplementFeaturesOnTop()
2875 return viewStyle.isShowComplementFeaturesOnTop();
2879 * @return true if view should scroll to show the highlighted region of a
2884 public final boolean isFollowHighlight()
2886 return followHighlight;
2890 public final void setFollowHighlight(boolean b)
2892 this.followHighlight = b;
2896 public ViewportRanges getRanges()
2902 * Helper method to populate the SearchResults with the location in the
2903 * complementary alignment to scroll to, in order to match this one.
2906 * the SearchResults to add to
2907 * @return the offset (below top of visible region) of the matched sequence
2909 protected int findComplementScrollTarget(SearchResultsI sr)
2911 final AlignViewportI complement = getCodingComplement();
2912 if (complement == null || !complement.isFollowHighlight())
2916 boolean iAmProtein = !getAlignment().isNucleotide();
2917 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2918 : complement.getAlignment();
2919 if (proteinAlignment == null)
2923 final List<AlignedCodonFrame> mappings = proteinAlignment
2927 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2928 * residue in the middle column of the visible region. Scroll the
2929 * complementary alignment to line up the corresponding residue.
2932 SequenceI sequence = null;
2935 * locate 'middle' column (true middle if an odd number visible, left of
2936 * middle if an even number visible)
2938 int middleColumn = ranges.getStartRes()
2939 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2940 final HiddenSequences hiddenSequences = getAlignment()
2941 .getHiddenSequences();
2944 * searching to the bottom of the alignment gives smoother scrolling across
2945 * all gapped visible regions
2947 int lastSeq = alignment.getHeight() - 1;
2948 List<AlignedCodonFrame> seqMappings = null;
2949 for (int seqNo = ranges
2950 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2952 sequence = getAlignment().getSequenceAt(seqNo);
2953 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2957 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2961 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2963 getCodingComplement().getAlignment().getSequences());
2964 if (!seqMappings.isEmpty())
2970 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2973 * No ungapped mapped sequence in middle column - do nothing
2977 MappingUtils.addSearchResults(sr, sequence,
2978 sequence.findPosition(middleColumn), seqMappings);
2983 * synthesize a column selection if none exists so it covers the given
2984 * selection group. if wholewidth is false, no column selection is made if the
2985 * selection group covers the whole alignment width.
2990 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2993 if (sg != null && (sgs = sg.getStartRes()) >= 0
2994 && sg.getStartRes() <= (sge = sg.getEndRes())
2995 && !this.hasSelectedColumns())
2997 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
3004 colSel = new ColumnSelection();
3006 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
3008 colSel.addElement(cspos);
3014 * hold status of current selection group - defined on alignment or not.
3016 private boolean selectionIsDefinedGroup = false;
3019 public boolean isSelectionDefinedGroup()
3021 if (selectionGroup == null)
3025 if (isSelectionGroupChanged(true))
3027 selectionIsDefinedGroup = false;
3028 List<SequenceGroup> gps = alignment.getGroups();
3029 if (gps == null || gps.size() == 0)
3031 selectionIsDefinedGroup = false;
3035 selectionIsDefinedGroup = gps.contains(selectionGroup);
3038 return selectionGroup.isDefined() || selectionIsDefinedGroup;
3042 * null, or currently highlighted results on this view
3044 private SearchResultsI searchResults = null;
3046 protected TreeModel currentTree = null;
3049 public boolean hasSearchResults()
3051 return searchResults != null;
3055 public void setSearchResults(SearchResultsI results)
3057 searchResults = results;
3061 public SearchResultsI getSearchResults()
3063 return searchResults;
3067 * get the consensus sequence as displayed under the PID consensus annotation
3070 * @return consensus sequence as a new sequence object
3072 public SequenceI getConsensusSeq()
3074 if (consensus == null)
3076 updateConsensus(null);
3078 if (consensus == null)
3082 StringBuffer seqs = new StringBuffer();
3083 for (int i = 0; i < consensus.annotations.length; i++)
3085 Annotation annotation = consensus.annotations[i];
3086 if (annotation != null)
3088 String description = annotation.description;
3089 if (description != null && description.startsWith("["))
3091 // consensus is a tie - just pick the first one
3092 seqs.append(description.charAt(1));
3096 seqs.append(annotation.displayCharacter);
3101 SequenceI sq = new Sequence("Consensus", seqs.toString());
3102 sq.setDescription("Percentage Identity Consensus "
3103 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3107 public boolean hasReferenceAnnotation()
3109 AlignmentAnnotation[] annots = this.alignment.getAlignmentAnnotation();
3110 for (AlignmentAnnotation annot : annots)
3112 if ("RF".equals(annot.label) || annot.label.contains("Reference"))
3121 public void setCurrentTree(TreeModel tree)
3127 public TreeModel getCurrentTree()
3133 public AlignmentExportData getAlignExportData(AlignExportSettingsI options)
3135 AlignmentI alignmentToExport = null;
3136 String[] omitHidden = null;
3137 alignmentToExport = null;
3139 if (hasHiddenColumns() && !options.isExportHiddenColumns())
3141 omitHidden = getViewAsString(false,
3142 options.isExportHiddenSequences());
3145 int[] alignmentStartEnd = new int[2];
3146 if (hasHiddenRows() && options.isExportHiddenSequences())
3148 alignmentToExport = getAlignment().getHiddenSequences()
3149 .getFullAlignment();
3153 alignmentToExport = getAlignment();
3155 alignmentStartEnd = getAlignment().getHiddenColumns()
3156 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
3157 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
3158 omitHidden, alignmentStartEnd);
3163 public boolean isNormaliseSequenceLogo()
3165 return normaliseSequenceLogo;
3168 public void setNormaliseSequenceLogo(boolean state)
3170 normaliseSequenceLogo = state;
3174 public boolean isNormaliseHMMSequenceLogo()
3176 return hmmNormaliseSequenceLogo;
3179 public void setNormaliseHMMSequenceLogo(boolean state)
3181 hmmNormaliseSequenceLogo = state;
3184 * flag set to indicate if structure views might be out of sync with sequences
3188 private boolean needToUpdateStructureViews = false;
3191 public boolean isUpdateStructures()
3193 return needToUpdateStructureViews;
3197 public void setUpdateStructures(boolean update)
3199 needToUpdateStructureViews = update;
3203 public boolean needToUpdateStructureViews()
3205 boolean update = needToUpdateStructureViews;
3206 needToUpdateStructureViews = false;
3211 public void addSequenceGroup(SequenceGroup sequenceGroup)
3213 alignment.addGroup(sequenceGroup);
3215 Color col = sequenceGroup.idColour;
3218 col = col.brighter();
3220 for (SequenceI sq : sequenceGroup.getSequences())
3222 setSequenceColour(sq, col);
3226 if (codingComplement != null)
3228 SequenceGroup mappedGroup = MappingUtils
3229 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3230 if (mappedGroup.getSequences().size() > 0)
3232 codingComplement.getAlignment().addGroup(mappedGroup);
3236 for (SequenceI seq : mappedGroup.getSequences())
3238 codingComplement.setSequenceColour(seq, col);
3242 // propagate the structure view update flag according to our own setting
3243 codingComplement.setUpdateStructures(needToUpdateStructureViews);
3248 * Filters out sequences with an eValue higher than the specified value. The
3249 * filtered sequences are hidden or deleted. Sequences with no eValues are also
3255 public void filterByEvalue(double eValue)
3257 for (SequenceI seq : alignment.getSequencesArray())
3259 if ((seq.getAnnotation("Search Scores") == null
3260 || seq.getAnnotation("Search Scores")[0].getEValue() > eValue)
3261 && seq.getHMM() == null)
3263 hideSequence(new SequenceI[] { seq });
3269 * Filters out sequences with an score lower than the specified value. The
3270 * filtered sequences are hidden or deleted.
3275 public void filterByScore(double score)
3277 for (SequenceI seq : alignment.getSequencesArray())
3279 if ((seq.getAnnotation("Search Scores") == null
3280 || seq.getAnnotation("Search Scores")[0]
3281 .getBitScore() < score)
3282 && seq.getHMM() == null)
3284 hideSequence(new SequenceI[] { seq });