2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.viewmodel;
23 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
24 import jalview.analysis.Conservation;
25 import jalview.analysis.TreeModel;
26 import jalview.api.AlignCalcManagerI;
27 import jalview.api.AlignExportSettingsI;
28 import jalview.api.AlignViewportI;
29 import jalview.api.AlignmentViewPanel;
30 import jalview.api.FeaturesDisplayedI;
31 import jalview.api.ViewStyleI;
32 import jalview.commands.CommandI;
33 import jalview.datamodel.AlignedCodonFrame;
34 import jalview.datamodel.AlignmentAnnotation;
35 import jalview.datamodel.AlignmentExportData;
36 import jalview.datamodel.AlignmentI;
37 import jalview.datamodel.AlignmentView;
38 import jalview.datamodel.Annotation;
39 import jalview.datamodel.ColumnSelection;
40 import jalview.datamodel.HiddenColumns;
41 import jalview.datamodel.HiddenSequences;
42 import jalview.datamodel.ProfilesI;
43 import jalview.datamodel.SearchResultsI;
44 import jalview.datamodel.Sequence;
45 import jalview.datamodel.SequenceCollectionI;
46 import jalview.datamodel.SequenceGroup;
47 import jalview.datamodel.SequenceI;
48 import jalview.renderer.ResidueShader;
49 import jalview.renderer.ResidueShaderI;
50 import jalview.schemes.ColourSchemeI;
51 import jalview.structure.CommandListener;
52 import jalview.structure.StructureSelectionManager;
53 import jalview.structure.VamsasSource;
54 import jalview.util.Comparison;
55 import jalview.util.MapList;
56 import jalview.util.MappingUtils;
57 import jalview.util.MessageManager;
58 import jalview.viewmodel.styles.ViewStyle;
59 import jalview.workers.AlignCalcManager;
60 import jalview.workers.ComplementConsensusThread;
61 import jalview.workers.ConsensusThread;
62 import jalview.workers.StrucConsensusThread;
64 import java.awt.Color;
65 import java.beans.PropertyChangeSupport;
66 import java.util.ArrayDeque;
67 import java.util.ArrayList;
68 import java.util.BitSet;
69 import java.util.Deque;
70 import java.util.HashMap;
71 import java.util.Hashtable;
72 import java.util.Iterator;
73 import java.util.List;
77 * base class holding visualization and analysis attributes and common logic for
78 * an active alignment view displayed in the GUI
83 public abstract class AlignmentViewport
84 implements AlignViewportI, CommandListener, VamsasSource
86 protected ViewportRanges ranges;
88 protected ViewStyleI viewStyle = new ViewStyle();
91 * A viewport that hosts the cDna view of this (protein), or vice versa (if
94 AlignViewportI codingComplement = null;
96 FeaturesDisplayedI featuresDisplayed = null;
98 protected Deque<CommandI> historyList = new ArrayDeque<>();
100 protected Deque<CommandI> redoList = new ArrayDeque<>();
103 * alignment displayed in the viewport. Please use get/setter
105 protected AlignmentI alignment;
107 public AlignmentViewport(AlignmentI al)
110 ranges = new ViewportRanges(al);
115 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
118 public void setFontName(String name)
120 viewStyle.setFontName(name);
125 * @see jalview.api.ViewStyleI#setFontStyle(int)
128 public void setFontStyle(int style)
130 viewStyle.setFontStyle(style);
135 * @see jalview.api.ViewStyleI#setFontSize(int)
138 public void setFontSize(int size)
140 viewStyle.setFontSize(size);
145 * @see jalview.api.ViewStyleI#getFontStyle()
148 public int getFontStyle()
150 return viewStyle.getFontStyle();
155 * @see jalview.api.ViewStyleI#getFontName()
158 public String getFontName()
160 return viewStyle.getFontName();
165 * @see jalview.api.ViewStyleI#getFontSize()
168 public int getFontSize()
170 return viewStyle.getFontSize();
174 * @param upperCasebold
175 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
178 public void setUpperCasebold(boolean upperCasebold)
180 viewStyle.setUpperCasebold(upperCasebold);
185 * @see jalview.api.ViewStyleI#isUpperCasebold()
188 public boolean isUpperCasebold()
190 return viewStyle.isUpperCasebold();
195 * @see jalview.api.ViewStyleI#isSeqNameItalics()
198 public boolean isSeqNameItalics()
200 return viewStyle.isSeqNameItalics();
204 * @param colourByReferenceSeq
205 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
208 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
210 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
215 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
218 public void setColourAppliesToAllGroups(boolean b)
220 viewStyle.setColourAppliesToAllGroups(b);
225 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
228 public boolean getColourAppliesToAllGroups()
230 return viewStyle.getColourAppliesToAllGroups();
235 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
238 public boolean getAbovePIDThreshold()
240 return viewStyle.getAbovePIDThreshold();
245 * @see jalview.api.ViewStyleI#setIncrement(int)
248 public void setIncrement(int inc)
250 viewStyle.setIncrement(inc);
255 * @see jalview.api.ViewStyleI#getIncrement()
258 public int getIncrement()
260 return viewStyle.getIncrement();
265 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
268 public void setConservationSelected(boolean b)
270 viewStyle.setConservationSelected(b);
275 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
278 public void setShowHiddenMarkers(boolean show)
280 viewStyle.setShowHiddenMarkers(show);
285 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
288 public boolean getShowHiddenMarkers()
290 return viewStyle.getShowHiddenMarkers();
295 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
298 public void setScaleRightWrapped(boolean b)
300 viewStyle.setScaleRightWrapped(b);
305 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
308 public void setScaleLeftWrapped(boolean b)
310 viewStyle.setScaleLeftWrapped(b);
315 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
318 public void setScaleAboveWrapped(boolean b)
320 viewStyle.setScaleAboveWrapped(b);
325 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
328 public boolean getScaleLeftWrapped()
330 return viewStyle.getScaleLeftWrapped();
335 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
338 public boolean getScaleAboveWrapped()
340 return viewStyle.getScaleAboveWrapped();
345 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
348 public boolean getScaleRightWrapped()
350 return viewStyle.getScaleRightWrapped();
355 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
358 public void setAbovePIDThreshold(boolean b)
360 viewStyle.setAbovePIDThreshold(b);
365 * @see jalview.api.ViewStyleI#setThreshold(int)
368 public void setThreshold(int thresh)
370 viewStyle.setThreshold(thresh);
375 * @see jalview.api.ViewStyleI#getThreshold()
378 public int getThreshold()
380 return viewStyle.getThreshold();
385 * @see jalview.api.ViewStyleI#getShowJVSuffix()
388 public boolean getShowJVSuffix()
390 return viewStyle.getShowJVSuffix();
395 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
398 public void setShowJVSuffix(boolean b)
400 viewStyle.setShowJVSuffix(b);
405 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
408 public void setWrapAlignment(boolean state)
410 viewStyle.setWrapAlignment(state);
411 ranges.setWrappedMode(state);
416 * @see jalview.api.ViewStyleI#setShowText(boolean)
419 public void setShowText(boolean state)
421 viewStyle.setShowText(state);
426 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
429 public void setRenderGaps(boolean state)
431 viewStyle.setRenderGaps(state);
436 * @see jalview.api.ViewStyleI#getColourText()
439 public boolean getColourText()
441 return viewStyle.getColourText();
446 * @see jalview.api.ViewStyleI#setColourText(boolean)
449 public void setColourText(boolean state)
451 viewStyle.setColourText(state);
456 * @see jalview.api.ViewStyleI#getColourGaps()
459 public boolean getColourGaps()
461 return viewStyle.getColourGaps();
466 * @see jalview.api.ViewStyleI#setColourGaps(boolean)
469 public void setColourGaps(boolean state)
471 viewStyle.setColourGaps(state);
476 * @see jalview.api.ViewStyleI#getWrapAlignment()
479 public boolean getWrapAlignment()
481 return viewStyle.getWrapAlignment();
486 * @see jalview.api.ViewStyleI#getShowText()
489 public boolean getShowText()
491 return viewStyle.getShowText();
496 * @see jalview.api.ViewStyleI#getWrappedWidth()
499 public int getWrappedWidth()
501 return viewStyle.getWrappedWidth();
506 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
509 public void setWrappedWidth(int w)
511 viewStyle.setWrappedWidth(w);
516 * @see jalview.api.ViewStyleI#getCharHeight()
519 public int getCharHeight()
521 return viewStyle.getCharHeight();
526 * @see jalview.api.ViewStyleI#setCharHeight(int)
529 public void setCharHeight(int h)
531 viewStyle.setCharHeight(h);
536 * @see jalview.api.ViewStyleI#getCharWidth()
539 public int getCharWidth()
541 return viewStyle.getCharWidth();
546 * @see jalview.api.ViewStyleI#setCharWidth(int)
549 public void setCharWidth(int w)
551 viewStyle.setCharWidth(w);
556 * @see jalview.api.ViewStyleI#getShowBoxes()
559 public boolean getShowBoxes()
561 return viewStyle.getShowBoxes();
566 * @see jalview.api.ViewStyleI#getShowUnconserved()
569 public boolean getShowUnconserved()
571 return viewStyle.getShowUnconserved();
575 * @param showunconserved
576 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
579 public void setShowUnconserved(boolean showunconserved)
581 viewStyle.setShowUnconserved(showunconserved);
586 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
589 public void setSeqNameItalics(boolean default1)
591 viewStyle.setSeqNameItalics(default1);
595 public AlignmentI getAlignment()
601 public char getGapCharacter()
603 return alignment.getGapCharacter();
606 protected String sequenceSetID;
609 * probably unused indicator that view is of a dataset rather than an
612 protected boolean isDataset = false;
614 public void setDataset(boolean b)
619 public boolean isDataset()
624 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
626 protected ColumnSelection colSel = new ColumnSelection();
628 public boolean autoCalculateConsensus = true;
630 protected boolean autoCalculateStrucConsensus = true;
632 protected boolean ignoreGapsInConsensusCalculation = false;
634 protected ResidueShaderI residueShading = new ResidueShader();
637 public void setGlobalColourScheme(ColourSchemeI cs)
639 // TODO: logic refactored from AlignFrame changeColour -
640 // TODO: autorecalc stuff should be changed to rely on the worker system
641 // check to see if we should implement a changeColour(cs) method rather than
642 // put the logic in here
643 // - means that caller decides if they want to just modify state and defer
644 // calculation till later or to do all calculations in thread.
648 * only instantiate alignment colouring once, thereafter update it;
649 * this means that any conservation or PID threshold settings
650 * persist when the alignment colour scheme is changed
652 if (residueShading == null)
654 residueShading = new ResidueShader(viewStyle);
656 residueShading.setColourScheme(cs);
658 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
659 // ...problem: groups need these, but do not currently have a ViewStyle
663 if (getConservationSelected())
665 residueShading.setConservation(hconservation);
668 * reset conservation flag in case just set to false if
669 * Conservation was null (calculation still in progress)
671 residueShading.setConservationApplied(getConservationSelected());
672 residueShading.alignmentChanged(alignment, hiddenRepSequences);
676 * if 'apply colour to all groups' is selected... do so
677 * (but don't transfer any colour threshold settings to groups)
679 if (getColourAppliesToAllGroups())
681 for (SequenceGroup sg : getAlignment().getGroups())
684 * retain any colour thresholds per group while
685 * changing choice of colour scheme (JAL-2386)
688 cs == null ? null : cs.getInstance(this, sg));
691 sg.getGroupColourScheme().alignmentChanged(sg,
699 public ColourSchemeI getGlobalColourScheme()
701 return residueShading == null ? null : residueShading.getColourScheme();
705 public ResidueShaderI getResidueShading()
707 return residueShading;
710 protected AlignmentAnnotation consensus;
712 protected AlignmentAnnotation complementConsensus;
714 protected AlignmentAnnotation gapcounts;
716 protected AlignmentAnnotation strucConsensus;
718 protected AlignmentAnnotation conservation;
720 protected AlignmentAnnotation quality;
722 protected AlignmentAnnotation[] groupConsensus;
724 protected AlignmentAnnotation[] groupConservation;
727 * results of alignment consensus analysis for visible portion of view
729 protected ProfilesI hconsensus = null;
732 * results of cDNA complement consensus visible portion of view
734 protected Hashtable<String, Object>[] hcomplementConsensus = null;
737 * results of secondary structure base pair consensus for visible portion of
740 protected Hashtable<String, Object>[] hStrucConsensus = null;
742 protected Conservation hconservation = null;
745 public void setConservation(Conservation cons)
747 hconservation = cons;
751 * percentage gaps allowed in a column before all amino acid properties should
752 * be considered unconserved
754 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
757 public int getConsPercGaps()
763 public void setSequenceConsensusHash(ProfilesI hconsensus)
765 this.hconsensus = hconsensus;
769 public void setComplementConsensusHash(
770 Hashtable<String, Object>[] hconsensus)
772 this.hcomplementConsensus = hconsensus;
776 public ProfilesI getSequenceConsensusHash()
782 public Hashtable<String, Object>[] getComplementConsensusHash()
784 return hcomplementConsensus;
788 public Hashtable<String, Object>[] getRnaStructureConsensusHash()
790 return hStrucConsensus;
794 public void setRnaStructureConsensusHash(
795 Hashtable<String, Object>[] hStrucConsensus)
797 this.hStrucConsensus = hStrucConsensus;
802 public AlignmentAnnotation getAlignmentQualityAnnot()
808 public AlignmentAnnotation getAlignmentConservationAnnotation()
814 public AlignmentAnnotation getAlignmentConsensusAnnotation()
820 public AlignmentAnnotation getAlignmentGapAnnotation()
826 public AlignmentAnnotation getComplementConsensusAnnotation()
828 return complementConsensus;
832 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
834 return strucConsensus;
837 protected AlignCalcManagerI calculator = new AlignCalcManager();
840 * trigger update of conservation annotation
842 public void updateConservation(final AlignmentViewPanel ap)
844 // see note in mantis : issue number 8585
845 if (alignment.isNucleotide()
846 || (conservation == null && quality == null)
847 || !autoCalculateConsensus)
851 if (calculator.getRegisteredWorkersOfClass(
852 jalview.workers.ConservationThread.class) == null)
854 calculator.registerWorker(
855 new jalview.workers.ConservationThread(this, ap));
860 * trigger update of consensus annotation
862 public void updateConsensus(final AlignmentViewPanel ap)
864 // see note in mantis : issue number 8585
865 if (consensus == null || !autoCalculateConsensus)
870 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
872 calculator.registerWorker(new ConsensusThread(this, ap));
876 * A separate thread to compute cDNA consensus for a protein alignment
877 * which has mapping to cDNA
879 final AlignmentI al = this.getAlignment();
880 if (!al.isNucleotide() && al.getCodonFrames() != null
881 && !al.getCodonFrames().isEmpty())
884 * fudge - check first for protein-to-nucleotide mappings
885 * (we don't want to do this for protein-to-protein)
887 boolean doConsensus = false;
888 for (AlignedCodonFrame mapping : al.getCodonFrames())
890 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
891 MapList[] mapLists = mapping.getdnaToProt();
892 // mapLists can be empty if project load has not finished resolving seqs
893 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
901 if (calculator.getRegisteredWorkersOfClass(
902 ComplementConsensusThread.class) == null)
905 .registerWorker(new ComplementConsensusThread(this, ap));
911 // --------START Structure Conservation
912 public void updateStrucConsensus(final AlignmentViewPanel ap)
914 if (autoCalculateStrucConsensus && strucConsensus == null
915 && alignment.isNucleotide() && alignment.hasRNAStructure())
917 // secondary structure has been added - so init the consensus line
921 // see note in mantis : issue number 8585
922 if (strucConsensus == null || !autoCalculateStrucConsensus)
926 if (calculator.getRegisteredWorkersOfClass(
927 StrucConsensusThread.class) == null)
929 calculator.registerWorker(new StrucConsensusThread(this, ap));
933 public boolean isCalcInProgress()
935 return calculator.isWorking();
939 public boolean isCalculationInProgress(
940 AlignmentAnnotation alignmentAnnotation)
942 if (!alignmentAnnotation.autoCalculated)
946 if (calculator.workingInvolvedWith(alignmentAnnotation))
948 // System.err.println("grey out ("+alignmentAnnotation.label+")");
954 public void setAlignment(AlignmentI align)
956 this.alignment = align;
960 * Clean up references when this viewport is closed
963 public void dispose()
966 * defensively null out references to large objects in case
967 * this object is not garbage collected (as if!)
970 complementConsensus = null;
971 strucConsensus = null;
974 groupConsensus = null;
975 groupConservation = null;
977 hconservation = null;
978 hcomplementConsensus = null;
981 residueShading = null; // may hold a reference to Consensus
982 changeSupport = null;
985 selectionGroup = null;
991 public boolean isClosed()
993 // TODO: check that this isClosed is only true after panel is closed, not
994 // before it is fully constructed.
995 return alignment == null;
999 public AlignCalcManagerI getCalcManager()
1005 * should conservation rows be shown for groups
1007 protected boolean showGroupConservation = false;
1010 * should consensus rows be shown for groups
1012 protected boolean showGroupConsensus = false;
1015 * should consensus profile be rendered by default
1017 protected boolean showSequenceLogo = false;
1020 * should consensus profile be rendered normalised to row height
1022 protected boolean normaliseSequenceLogo = false;
1025 * should consensus histograms be rendered by default
1027 protected boolean showConsensusHistogram = true;
1030 * @return the showConsensusProfile
1033 public boolean isShowSequenceLogo()
1035 return showSequenceLogo;
1039 * @param showSequenceLogo
1042 public void setShowSequenceLogo(boolean showSequenceLogo)
1044 if (showSequenceLogo != this.showSequenceLogo)
1046 // TODO: decouple settings setting from calculation when refactoring
1047 // annotation update method from alignframe to viewport
1048 this.showSequenceLogo = showSequenceLogo;
1049 calculator.updateAnnotationFor(ConsensusThread.class);
1050 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1051 calculator.updateAnnotationFor(StrucConsensusThread.class);
1053 this.showSequenceLogo = showSequenceLogo;
1057 * @param showConsensusHistogram
1058 * the showConsensusHistogram to set
1060 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1062 this.showConsensusHistogram = showConsensusHistogram;
1066 * @return the showGroupConservation
1068 public boolean isShowGroupConservation()
1070 return showGroupConservation;
1074 * @param showGroupConservation
1075 * the showGroupConservation to set
1077 public void setShowGroupConservation(boolean showGroupConservation)
1079 this.showGroupConservation = showGroupConservation;
1083 * @return the showGroupConsensus
1085 public boolean isShowGroupConsensus()
1087 return showGroupConsensus;
1091 * @param showGroupConsensus
1092 * the showGroupConsensus to set
1094 public void setShowGroupConsensus(boolean showGroupConsensus)
1096 this.showGroupConsensus = showGroupConsensus;
1101 * @return flag to indicate if the consensus histogram should be rendered by
1105 public boolean isShowConsensusHistogram()
1107 return this.showConsensusHistogram;
1111 * when set, updateAlignment will always ensure sequences are of equal length
1113 private boolean padGaps = false;
1116 * when set, alignment should be reordered according to a newly opened tree
1118 public boolean sortByTree = false;
1123 * @return null or the currently selected sequence region
1126 public SequenceGroup getSelectionGroup()
1128 return selectionGroup;
1132 * Set the selection group for this window. Also sets the current alignment as
1133 * the context for the group, if it does not already have one.
1136 * - group holding references to sequences in this alignment view
1140 public void setSelectionGroup(SequenceGroup sg)
1142 selectionGroup = sg;
1143 if (sg != null && sg.getContext() == null)
1145 sg.setContext(alignment);
1149 public void setHiddenColumns(HiddenColumns hidden)
1151 this.alignment.setHiddenColumns(hidden);
1155 public ColumnSelection getColumnSelection()
1161 public void setColumnSelection(ColumnSelection colSel)
1163 this.colSel = colSel;
1166 updateHiddenColumns();
1168 isColSelChanged(true);
1176 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1178 return hiddenRepSequences;
1182 public void setHiddenRepSequences(
1183 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1185 this.hiddenRepSequences = hiddenRepSequences;
1189 public boolean hasSelectedColumns()
1191 ColumnSelection columnSelection = getColumnSelection();
1192 return columnSelection != null && columnSelection.hasSelectedColumns();
1196 public boolean hasHiddenColumns()
1198 return alignment.getHiddenColumns() != null
1199 && alignment.getHiddenColumns().hasHiddenColumns();
1202 public void updateHiddenColumns()
1204 // this method doesn't really do anything now. But - it could, since a
1205 // column Selection could be in the process of modification
1206 // hasHiddenColumns = colSel.hasHiddenColumns();
1210 public boolean hasHiddenRows()
1212 return alignment.getHiddenSequences().getSize() > 0;
1215 protected SequenceGroup selectionGroup;
1217 public void setSequenceSetId(String newid)
1219 if (sequenceSetID != null)
1222 "Warning - overwriting a sequenceSetId for a viewport!");
1224 sequenceSetID = new String(newid);
1228 public String getSequenceSetId()
1230 if (sequenceSetID == null)
1232 sequenceSetID = alignment.hashCode() + "";
1235 return sequenceSetID;
1239 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1242 protected String viewId = null;
1245 public String getViewId()
1249 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1254 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1256 ignoreGapsInConsensusCalculation = b;
1259 updateConsensus(ap);
1260 if (residueShading != null)
1262 residueShading.setThreshold(residueShading.getThreshold(),
1263 ignoreGapsInConsensusCalculation);
1269 private long sgrouphash = -1, colselhash = -1;
1272 * checks current SelectionGroup against record of last hash value, and
1276 * update the record of last hash value
1278 * @return true if SelectionGroup changed since last call (when b is true)
1280 public boolean isSelectionGroupChanged(boolean b)
1282 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1283 : selectionGroup.hashCode();
1284 if (hc != -1 && hc != sgrouphash)
1296 * checks current colsel against record of last hash value, and optionally
1300 * update the record of last hash value
1301 * @return true if colsel changed since last call (when b is true)
1303 public boolean isColSelChanged(boolean b)
1305 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1306 if (hc != -1 && hc != colselhash)
1318 public boolean isIgnoreGapsConsensus()
1320 return ignoreGapsInConsensusCalculation;
1323 // property change stuff
1324 // JBPNote Prolly only need this in the applet version.
1325 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1328 protected boolean showConservation = true;
1330 protected boolean showQuality = true;
1332 protected boolean showConsensus = true;
1334 protected boolean showOccupancy = true;
1336 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1338 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1340 protected boolean showAutocalculatedAbove;
1343 * when set, view will scroll to show the highlighted position
1345 private boolean followHighlight = true;
1348 * Property change listener for changes in alignment
1353 public void addPropertyChangeListener(
1354 java.beans.PropertyChangeListener listener)
1356 changeSupport.addPropertyChangeListener(listener);
1365 public void removePropertyChangeListener(
1366 java.beans.PropertyChangeListener listener)
1368 if (changeSupport != null)
1370 changeSupport.removePropertyChangeListener(listener);
1375 * Property change listener for changes in alignment
1384 public void firePropertyChange(String prop, Object oldvalue,
1387 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1390 // common hide/show column stuff
1392 public void hideSelectedColumns()
1394 if (colSel.isEmpty())
1399 colSel.hideSelectedColumns(alignment);
1400 setSelectionGroup(null);
1401 isColSelChanged(true);
1404 public void hideColumns(int start, int end)
1408 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1412 alignment.getHiddenColumns().hideColumns(start, end);
1414 isColSelChanged(true);
1417 public void showColumn(int col)
1419 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1420 isColSelChanged(true);
1423 public void showAllHiddenColumns()
1425 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1426 isColSelChanged(true);
1429 // common hide/show seq stuff
1430 public void showAllHiddenSeqs()
1432 int startSeq = ranges.getStartSeq();
1433 int endSeq = ranges.getEndSeq();
1435 if (alignment.getHiddenSequences().getSize() > 0)
1437 if (selectionGroup == null)
1439 selectionGroup = new SequenceGroup();
1440 selectionGroup.setEndRes(alignment.getWidth() - 1);
1442 List<SequenceI> tmp = alignment.getHiddenSequences()
1443 .showAll(hiddenRepSequences);
1444 for (SequenceI seq : tmp)
1446 selectionGroup.addSequence(seq, false);
1447 setSequenceAnnotationsVisible(seq, true);
1450 hiddenRepSequences = null;
1452 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1454 firePropertyChange("alignment", null, alignment.getSequences());
1455 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1461 public void showSequence(int index)
1463 int startSeq = ranges.getStartSeq();
1464 int endSeq = ranges.getEndSeq();
1466 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1467 hiddenRepSequences);
1470 if (selectionGroup == null)
1472 selectionGroup = new SequenceGroup();
1473 selectionGroup.setEndRes(alignment.getWidth() - 1);
1476 for (SequenceI seq : tmp)
1478 selectionGroup.addSequence(seq, false);
1479 setSequenceAnnotationsVisible(seq, true);
1482 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1484 firePropertyChange("alignment", null, alignment.getSequences());
1489 public void hideAllSelectedSeqs()
1491 if (selectionGroup == null || selectionGroup.getSize() < 1)
1496 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1500 setSelectionGroup(null);
1503 public void hideSequence(SequenceI[] seq)
1506 * cache offset to first visible sequence
1508 int startSeq = ranges.getStartSeq();
1512 for (int i = 0; i < seq.length; i++)
1514 alignment.getHiddenSequences().hideSequence(seq[i]);
1515 setSequenceAnnotationsVisible(seq[i], false);
1517 ranges.setStartSeq(startSeq);
1518 firePropertyChange("alignment", null, alignment.getSequences());
1523 * Hides the specified sequence, or the sequences it represents
1526 * the sequence to hide, or keep as representative
1527 * @param representGroup
1528 * if true, hide the current selection group except for the
1529 * representative sequence
1531 public void hideSequences(SequenceI sequence, boolean representGroup)
1533 if (selectionGroup == null || selectionGroup.getSize() < 1)
1535 hideSequence(new SequenceI[] { sequence });
1541 hideRepSequences(sequence, selectionGroup);
1542 setSelectionGroup(null);
1546 int gsize = selectionGroup.getSize();
1547 SequenceI[] hseqs = selectionGroup.getSequences()
1548 .toArray(new SequenceI[gsize]);
1550 hideSequence(hseqs);
1551 setSelectionGroup(null);
1556 * Set visibility for any annotations for the given sequence.
1560 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1563 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1566 for (AlignmentAnnotation ann : anns)
1568 if (ann.sequenceRef == sequenceI)
1570 ann.visible = visible;
1576 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1578 int sSize = sg.getSize();
1584 if (hiddenRepSequences == null)
1586 hiddenRepSequences = new Hashtable<>();
1589 hiddenRepSequences.put(repSequence, sg);
1591 // Hide all sequences except the repSequence
1592 SequenceI[] seqs = new SequenceI[sSize - 1];
1594 for (int i = 0; i < sSize; i++)
1596 if (sg.getSequenceAt(i) != repSequence)
1598 if (index == sSize - 1)
1603 seqs[index++] = sg.getSequenceAt(i);
1606 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1607 sg.setHidereps(true); // note: not done in 2.7applet
1614 * @return null or the current reference sequence
1616 public SequenceI getReferenceSeq()
1618 return alignment.getSeqrep();
1623 * @return true iff seq is the reference for the alignment
1625 public boolean isReferenceSeq(SequenceI seq)
1627 return alignment.getSeqrep() == seq;
1633 * @return true if there are sequences represented by this sequence that are
1636 public boolean isHiddenRepSequence(SequenceI seq)
1638 return (hiddenRepSequences != null
1639 && hiddenRepSequences.containsKey(seq));
1645 * @return null or a sequence group containing the sequences that seq
1648 public SequenceGroup getRepresentedSequences(SequenceI seq)
1650 return (SequenceGroup) (hiddenRepSequences == null ? null
1651 : hiddenRepSequences.get(seq));
1655 public int adjustForHiddenSeqs(int alignmentIndex)
1657 return alignment.getHiddenSequences()
1658 .adjustForHiddenSeqs(alignmentIndex);
1662 public void invertColumnSelection()
1664 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1665 isColSelChanged(true);
1669 public SequenceI[] getSelectionAsNewSequence()
1671 SequenceI[] sequences;
1672 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1673 // this was the only caller in the applet for this method
1674 // JBPNote: in applet, this method returned references to the alignment
1675 // sequences, and it did not honour the presence/absence of annotation
1676 // attached to the alignment (probably!)
1677 if (selectionGroup == null || selectionGroup.getSize() == 0)
1679 sequences = alignment.getSequencesArray();
1680 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1681 for (int i = 0; i < sequences.length; i++)
1683 // construct new sequence with subset of visible annotation
1684 sequences[i] = new Sequence(sequences[i], annots);
1689 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1696 public SequenceI[] getSequenceSelection()
1698 SequenceI[] sequences = null;
1699 if (selectionGroup != null)
1701 sequences = selectionGroup.getSequencesInOrder(alignment);
1703 if (sequences == null)
1705 sequences = alignment.getSequencesArray();
1711 public jalview.datamodel.AlignmentView getAlignmentView(
1712 boolean selectedOnly)
1714 return getAlignmentView(selectedOnly, false);
1718 public jalview.datamodel.AlignmentView getAlignmentView(
1719 boolean selectedOnly, boolean markGroups)
1721 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1723 alignment.getHiddenColumns() != null
1724 && alignment.getHiddenColumns().hasHiddenColumns(),
1725 selectedOnly, markGroups);
1729 public String[] getViewAsString(boolean selectedRegionOnly)
1731 return getViewAsString(selectedRegionOnly, true);
1735 public String[] getViewAsString(boolean selectedRegionOnly,
1736 boolean exportHiddenSeqs)
1738 String[] selection = null;
1739 SequenceI[] seqs = null;
1741 int start = 0, end = 0;
1742 if (selectedRegionOnly && selectionGroup != null)
1744 iSize = selectionGroup.getSize();
1745 seqs = selectionGroup.getSequencesInOrder(alignment);
1746 start = selectionGroup.getStartRes();
1747 end = selectionGroup.getEndRes() + 1;
1751 if (hasHiddenRows() && exportHiddenSeqs)
1753 AlignmentI fullAlignment = alignment.getHiddenSequences()
1754 .getFullAlignment();
1755 iSize = fullAlignment.getHeight();
1756 seqs = fullAlignment.getSequencesArray();
1757 end = fullAlignment.getWidth();
1761 iSize = alignment.getHeight();
1762 seqs = alignment.getSequencesArray();
1763 end = alignment.getWidth();
1767 selection = new String[iSize];
1768 if (alignment.getHiddenColumns() != null
1769 && alignment.getHiddenColumns().hasHiddenColumns())
1771 for (i = 0; i < iSize; i++)
1773 Iterator<int[]> blocks = alignment.getHiddenColumns()
1774 .getVisContigsIterator(start, end + 1, false);
1775 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1780 for (i = 0; i < iSize; i++)
1782 selection[i] = seqs[i].getSequenceAsString(start, end);
1790 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1792 ArrayList<int[]> regions = new ArrayList<>();
1798 HiddenColumns hidden = alignment.getHiddenColumns();
1799 if (hidden != null && hidden.hasHiddenColumns())
1803 start = hidden.visibleToAbsoluteColumn(start);
1806 end = hidden.getNextHiddenBoundary(false, start);
1817 regions.add(new int[] { start, end });
1819 if (hidden != null && hidden.hasHiddenColumns())
1821 start = hidden.visibleToAbsoluteColumn(end);
1822 start = hidden.getNextHiddenBoundary(true, start) + 1;
1824 } while (end < max);
1826 // int[][] startEnd = new int[regions.size()][2];
1832 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1833 boolean selectedOnly)
1835 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1836 AlignmentAnnotation[] aa;
1837 if ((aa = alignment.getAlignmentAnnotation()) != null)
1839 for (AlignmentAnnotation annot : aa)
1841 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1842 if (selectedOnly && selectionGroup != null)
1844 clone.makeVisibleAnnotation(
1845 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1846 alignment.getHiddenColumns());
1850 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1859 public boolean isPadGaps()
1865 public void setPadGaps(boolean padGaps)
1867 this.padGaps = padGaps;
1871 * apply any post-edit constraints and trigger any calculations needed after
1872 * an edit has been performed on the alignment
1877 public void alignmentChanged(AlignmentViewPanel ap)
1881 alignment.padGaps();
1883 if (autoCalculateConsensus)
1885 updateConsensus(ap);
1887 if (hconsensus != null && autoCalculateConsensus)
1889 updateConservation(ap);
1891 if (autoCalculateStrucConsensus)
1893 updateStrucConsensus(ap);
1896 // Reset endRes of groups if beyond alignment width
1897 int alWidth = alignment.getWidth();
1898 List<SequenceGroup> groups = alignment.getGroups();
1901 for (SequenceGroup sg : groups)
1903 if (sg.getEndRes() > alWidth)
1905 sg.setEndRes(alWidth - 1);
1910 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1912 selectionGroup.setEndRes(alWidth - 1);
1915 updateAllColourSchemes();
1916 calculator.restartWorkers();
1917 // alignment.adjustSequenceAnnotations();
1921 * reset scope and do calculations for all applied colourschemes on alignment
1923 void updateAllColourSchemes()
1925 ResidueShaderI rs = residueShading;
1928 rs.alignmentChanged(alignment, hiddenRepSequences);
1930 rs.setConsensus(hconsensus);
1931 if (rs.conservationApplied())
1933 rs.setConservation(Conservation.calculateConservation("All",
1934 alignment.getSequences(), 0, alignment.getWidth(), false,
1935 getConsPercGaps(), false));
1939 for (SequenceGroup sg : alignment.getGroups())
1943 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1945 sg.recalcConservation();
1949 protected void initAutoAnnotation()
1951 // TODO: add menu option action that nulls or creates consensus object
1952 // depending on if the user wants to see the annotation or not in a
1953 // specific alignment
1955 if (hconsensus == null && !isDataset)
1957 if (!alignment.isNucleotide())
1966 consensus = new AlignmentAnnotation("Consensus",
1967 MessageManager.getString("label.consensus_descr"),
1968 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1969 initConsensus(consensus);
1972 initComplementConsensus();
1977 * If this is a protein alignment and there are mappings to cDNA, adds the
1978 * cDNA consensus annotation and returns true, else returns false.
1980 public boolean initComplementConsensus()
1982 if (!alignment.isNucleotide())
1984 final List<AlignedCodonFrame> codonMappings = alignment
1986 if (codonMappings != null && !codonMappings.isEmpty())
1988 boolean doConsensus = false;
1989 for (AlignedCodonFrame mapping : codonMappings)
1991 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1992 MapList[] mapLists = mapping.getdnaToProt();
1993 // mapLists can be empty if project load has not finished resolving
1995 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2003 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2005 .getString("label.complement_consensus_descr"),
2006 new Annotation[1], 0f, 100f,
2007 AlignmentAnnotation.BAR_GRAPH);
2008 initConsensus(complementConsensus);
2016 private void initConsensus(AlignmentAnnotation aa)
2019 aa.autoCalculated = true;
2023 alignment.addAnnotation(aa);
2027 // these should be extracted from the view model - style and settings for
2028 // derived annotation
2029 private void initGapCounts()
2033 gapcounts = new AlignmentAnnotation("Occupancy",
2034 MessageManager.getString("label.occupancy_descr"),
2035 new Annotation[1], 0f, alignment.getHeight(),
2036 AlignmentAnnotation.BAR_GRAPH);
2037 gapcounts.hasText = true;
2038 gapcounts.autoCalculated = true;
2039 gapcounts.scaleColLabel = true;
2040 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2042 alignment.addAnnotation(gapcounts);
2046 private void initConservation()
2048 if (showConservation)
2050 if (conservation == null)
2052 conservation = new AlignmentAnnotation("Conservation",
2053 MessageManager.formatMessage("label.conservation_descr",
2055 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2056 conservation.hasText = true;
2057 conservation.autoCalculated = true;
2058 alignment.addAnnotation(conservation);
2063 private void initQuality()
2067 if (quality == null)
2069 quality = new AlignmentAnnotation("Quality",
2070 MessageManager.getString("label.quality_descr"),
2071 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2072 quality.hasText = true;
2073 quality.autoCalculated = true;
2074 alignment.addAnnotation(quality);
2079 private void initRNAStructure()
2081 if (alignment.hasRNAStructure() && strucConsensus == null)
2083 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2084 MessageManager.getString("label.strucconsensus_descr"),
2085 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2086 strucConsensus.hasText = true;
2087 strucConsensus.autoCalculated = true;
2091 alignment.addAnnotation(strucConsensus);
2099 * @see jalview.api.AlignViewportI#calcPanelHeight()
2102 public int calcPanelHeight()
2104 // setHeight of panels
2105 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2107 int charHeight = getCharHeight();
2110 BitSet graphgrp = new BitSet();
2111 for (AlignmentAnnotation aa : anns)
2115 System.err.println("Null annotation row: ignoring.");
2122 if (aa.graphGroup > -1)
2124 if (graphgrp.get(aa.graphGroup))
2130 graphgrp.set(aa.graphGroup);
2137 aa.height += charHeight;
2147 aa.height += aa.graphHeight;
2155 height += aa.height;
2167 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2168 boolean preserveNewGroupSettings)
2170 boolean updateCalcs = false;
2171 boolean conv = isShowGroupConservation();
2172 boolean cons = isShowGroupConsensus();
2173 boolean showprf = isShowSequenceLogo();
2174 boolean showConsHist = isShowConsensusHistogram();
2175 boolean normLogo = isNormaliseSequenceLogo();
2178 * TODO reorder the annotation rows according to group/sequence ordering on
2181 // boolean sortg = true;
2183 // remove old automatic annotation
2184 // add any new annotation
2186 // intersect alignment annotation with alignment groups
2188 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2189 List<SequenceGroup> oldrfs = new ArrayList<>();
2192 for (int an = 0; an < aan.length; an++)
2194 if (aan[an].autoCalculated && aan[an].groupRef != null)
2196 oldrfs.add(aan[an].groupRef);
2197 alignment.deleteAnnotation(aan[an], false);
2201 if (alignment.getGroups() != null)
2203 for (SequenceGroup sg : alignment.getGroups())
2205 updateCalcs = false;
2206 if (applyGlobalSettings
2207 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2209 // set defaults for this group's conservation/consensus
2210 sg.setshowSequenceLogo(showprf);
2211 sg.setShowConsensusHistogram(showConsHist);
2212 sg.setNormaliseSequenceLogo(normLogo);
2217 alignment.addAnnotation(sg.getConservationRow(), 0);
2222 alignment.addAnnotation(sg.getConsensus(), 0);
2224 // refresh the annotation rows
2227 sg.recalcConservation();
2235 public boolean isDisplayReferenceSeq()
2237 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2241 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2243 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2247 public boolean isColourByReferenceSeq()
2249 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2253 public Color getSequenceColour(SequenceI seq)
2255 Color sqc = sequenceColours.get(seq);
2256 return (sqc == null ? Color.white : sqc);
2260 public void setSequenceColour(SequenceI seq, Color col)
2264 sequenceColours.remove(seq);
2268 sequenceColours.put(seq, col);
2273 public void updateSequenceIdColours()
2275 for (SequenceGroup sg : alignment.getGroups())
2277 if (sg.idColour != null)
2279 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2281 sequenceColours.put(s, sg.idColour);
2288 public void clearSequenceColours()
2290 sequenceColours.clear();
2294 public AlignViewportI getCodingComplement()
2296 return this.codingComplement;
2300 * Set this as the (cDna/protein) complement of the given viewport. Also
2301 * ensures the reverse relationship is set on the given viewport.
2304 public void setCodingComplement(AlignViewportI av)
2308 System.err.println("Ignoring recursive setCodingComplement request");
2312 this.codingComplement = av;
2313 // avoid infinite recursion!
2314 if (av.getCodingComplement() != this)
2316 av.setCodingComplement(this);
2322 public boolean isNucleotide()
2324 return getAlignment() == null ? false : getAlignment().isNucleotide();
2328 public FeaturesDisplayedI getFeaturesDisplayed()
2330 return featuresDisplayed;
2334 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2336 featuresDisplayed = featuresDisplayedI;
2340 public boolean areFeaturesDisplayed()
2342 return featuresDisplayed != null
2343 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2350 * features are displayed if true
2353 public void setShowSequenceFeatures(boolean b)
2355 viewStyle.setShowSequenceFeatures(b);
2359 public boolean isShowSequenceFeatures()
2361 return viewStyle.isShowSequenceFeatures();
2365 public void setShowSequenceFeaturesHeight(boolean selected)
2367 viewStyle.setShowSequenceFeaturesHeight(selected);
2371 public boolean isShowSequenceFeaturesHeight()
2373 return viewStyle.isShowSequenceFeaturesHeight();
2377 public void setShowAnnotation(boolean b)
2379 viewStyle.setShowAnnotation(b);
2383 public boolean isShowAnnotation()
2385 return viewStyle.isShowAnnotation();
2389 public boolean isRightAlignIds()
2391 return viewStyle.isRightAlignIds();
2395 public void setRightAlignIds(boolean rightAlignIds)
2397 viewStyle.setRightAlignIds(rightAlignIds);
2401 public boolean getConservationSelected()
2403 return viewStyle.getConservationSelected();
2407 public void setShowBoxes(boolean state)
2409 viewStyle.setShowBoxes(state);
2414 * @see jalview.api.ViewStyleI#getTextColour()
2417 public Color getTextColour()
2419 return viewStyle.getTextColour();
2424 * @see jalview.api.ViewStyleI#getTextColour2()
2427 public Color getTextColour2()
2429 return viewStyle.getTextColour2();
2434 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2437 public int getThresholdTextColour()
2439 return viewStyle.getThresholdTextColour();
2444 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2447 public boolean isConservationColourSelected()
2449 return viewStyle.isConservationColourSelected();
2454 * @see jalview.api.ViewStyleI#isRenderGaps()
2457 public boolean isRenderGaps()
2459 return viewStyle.isRenderGaps();
2464 * @see jalview.api.ViewStyleI#isShowColourText()
2467 public boolean isShowColourText()
2469 return viewStyle.isShowColourText();
2473 * @param conservationColourSelected
2474 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2477 public void setConservationColourSelected(
2478 boolean conservationColourSelected)
2480 viewStyle.setConservationColourSelected(conservationColourSelected);
2484 * @param showColourText
2485 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2488 public void setShowColourText(boolean showColourText)
2490 viewStyle.setShowColourText(showColourText);
2495 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2498 public void setTextColour(Color textColour)
2500 viewStyle.setTextColour(textColour);
2504 * @param thresholdTextColour
2505 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2508 public void setThresholdTextColour(int thresholdTextColour)
2510 viewStyle.setThresholdTextColour(thresholdTextColour);
2514 * @param textColour2
2515 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2518 public void setTextColour2(Color textColour2)
2520 viewStyle.setTextColour2(textColour2);
2524 public ViewStyleI getViewStyle()
2526 return new ViewStyle(viewStyle);
2530 public void setViewStyle(ViewStyleI settingsForView)
2532 viewStyle = new ViewStyle(settingsForView);
2533 if (residueShading != null)
2535 residueShading.setConservationApplied(
2536 settingsForView.isConservationColourSelected());
2541 public boolean sameStyle(ViewStyleI them)
2543 return viewStyle.sameStyle(them);
2548 * @see jalview.api.ViewStyleI#getIdWidth()
2551 public int getIdWidth()
2553 return viewStyle.getIdWidth();
2558 * @see jalview.api.ViewStyleI#setIdWidth(int)
2561 public void setIdWidth(int i)
2563 viewStyle.setIdWidth(i);
2568 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2571 public boolean isCentreColumnLabels()
2573 return viewStyle.isCentreColumnLabels();
2577 * @param centreColumnLabels
2578 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2581 public void setCentreColumnLabels(boolean centreColumnLabels)
2583 viewStyle.setCentreColumnLabels(centreColumnLabels);
2588 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2591 public void setShowDBRefs(boolean showdbrefs)
2593 viewStyle.setShowDBRefs(showdbrefs);
2598 * @see jalview.api.ViewStyleI#isShowDBRefs()
2601 public boolean isShowDBRefs()
2603 return viewStyle.isShowDBRefs();
2608 * @see jalview.api.ViewStyleI#isShowNPFeats()
2611 public boolean isShowNPFeats()
2613 return viewStyle.isShowNPFeats();
2617 * @param shownpfeats
2618 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2621 public void setShowNPFeats(boolean shownpfeats)
2623 viewStyle.setShowNPFeats(shownpfeats);
2626 public abstract StructureSelectionManager getStructureSelectionManager();
2629 * Add one command to the command history list.
2633 public void addToHistoryList(CommandI command)
2635 if (this.historyList != null)
2637 this.historyList.push(command);
2638 broadcastCommand(command, false);
2642 protected void broadcastCommand(CommandI command, boolean undo)
2644 getStructureSelectionManager().commandPerformed(command, undo,
2649 * Add one command to the command redo list.
2653 public void addToRedoList(CommandI command)
2655 if (this.redoList != null)
2657 this.redoList.push(command);
2659 broadcastCommand(command, true);
2663 * Clear the command redo list.
2665 public void clearRedoList()
2667 if (this.redoList != null)
2669 this.redoList.clear();
2673 public void setHistoryList(Deque<CommandI> list)
2675 this.historyList = list;
2678 public Deque<CommandI> getHistoryList()
2680 return this.historyList;
2683 public void setRedoList(Deque<CommandI> list)
2685 this.redoList = list;
2688 public Deque<CommandI> getRedoList()
2690 return this.redoList;
2694 public VamsasSource getVamsasSource()
2699 public SequenceAnnotationOrder getSortAnnotationsBy()
2701 return sortAnnotationsBy;
2704 public void setSortAnnotationsBy(
2705 SequenceAnnotationOrder sortAnnotationsBy)
2707 this.sortAnnotationsBy = sortAnnotationsBy;
2710 public boolean isShowAutocalculatedAbove()
2712 return showAutocalculatedAbove;
2715 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2717 this.showAutocalculatedAbove = showAutocalculatedAbove;
2721 public boolean isScaleProteinAsCdna()
2723 return viewStyle.isScaleProteinAsCdna();
2727 public void setScaleProteinAsCdna(boolean b)
2729 viewStyle.setScaleProteinAsCdna(b);
2733 public boolean isProteinFontAsCdna()
2735 return viewStyle.isProteinFontAsCdna();
2739 public void setProteinFontAsCdna(boolean b)
2741 viewStyle.setProteinFontAsCdna(b);
2745 public void setShowComplementFeatures(boolean b)
2747 viewStyle.setShowComplementFeatures(b);
2751 public boolean isShowComplementFeatures()
2753 return viewStyle.isShowComplementFeatures();
2757 public void setShowComplementFeaturesOnTop(boolean b)
2759 viewStyle.setShowComplementFeaturesOnTop(b);
2763 public boolean isShowComplementFeaturesOnTop()
2765 return viewStyle.isShowComplementFeaturesOnTop();
2769 * @return true if view should scroll to show the highlighted region of a
2774 public final boolean isFollowHighlight()
2776 return followHighlight;
2780 public final void setFollowHighlight(boolean b)
2782 this.followHighlight = b;
2786 public ViewportRanges getRanges()
2792 * Helper method to populate the SearchResults with the location in the
2793 * complementary alignment to scroll to, in order to match this one.
2796 * the SearchResults to add to
2797 * @return the offset (below top of visible region) of the matched sequence
2799 protected int findComplementScrollTarget(SearchResultsI sr)
2801 final AlignViewportI complement = getCodingComplement();
2802 if (complement == null || !complement.isFollowHighlight())
2806 boolean iAmProtein = !getAlignment().isNucleotide();
2807 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2808 : complement.getAlignment();
2809 if (proteinAlignment == null)
2813 final List<AlignedCodonFrame> mappings = proteinAlignment
2817 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2818 * residue in the middle column of the visible region. Scroll the
2819 * complementary alignment to line up the corresponding residue.
2822 SequenceI sequence = null;
2825 * locate 'middle' column (true middle if an odd number visible, left of
2826 * middle if an even number visible)
2828 int middleColumn = ranges.getStartRes()
2829 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2830 final HiddenSequences hiddenSequences = getAlignment()
2831 .getHiddenSequences();
2834 * searching to the bottom of the alignment gives smoother scrolling across
2835 * all gapped visible regions
2837 int lastSeq = alignment.getHeight() - 1;
2838 List<AlignedCodonFrame> seqMappings = null;
2839 for (int seqNo = ranges
2840 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2842 sequence = getAlignment().getSequenceAt(seqNo);
2843 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2847 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2851 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2853 getCodingComplement().getAlignment().getSequences());
2854 if (!seqMappings.isEmpty())
2860 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2863 * No ungapped mapped sequence in middle column - do nothing
2867 MappingUtils.addSearchResults(sr, sequence,
2868 sequence.findPosition(middleColumn), seqMappings);
2873 * synthesize a column selection if none exists so it covers the given
2874 * selection group. if wholewidth is false, no column selection is made if the
2875 * selection group covers the whole alignment width.
2880 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2883 if (sg != null && (sgs = sg.getStartRes()) >= 0
2884 && sg.getStartRes() <= (sge = sg.getEndRes())
2885 && !this.hasSelectedColumns())
2887 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2894 colSel = new ColumnSelection();
2896 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2898 colSel.addElement(cspos);
2904 * hold status of current selection group - defined on alignment or not.
2906 private boolean selectionIsDefinedGroup = false;
2909 public boolean isSelectionDefinedGroup()
2911 if (selectionGroup == null)
2915 if (isSelectionGroupChanged(true))
2917 selectionIsDefinedGroup = false;
2918 List<SequenceGroup> gps = alignment.getGroups();
2919 if (gps == null || gps.size() == 0)
2921 selectionIsDefinedGroup = false;
2925 selectionIsDefinedGroup = gps.contains(selectionGroup);
2928 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2932 * null, or currently highlighted results on this view
2934 private SearchResultsI searchResults = null;
2936 protected TreeModel currentTree = null;
2939 public boolean hasSearchResults()
2941 return searchResults != null;
2945 public void setSearchResults(SearchResultsI results)
2947 searchResults = results;
2951 public SearchResultsI getSearchResults()
2953 return searchResults;
2957 * get the consensus sequence as displayed under the PID consensus annotation
2960 * @return consensus sequence as a new sequence object
2962 public SequenceI getConsensusSeq()
2964 if (consensus == null)
2966 updateConsensus(null);
2968 if (consensus == null)
2972 StringBuffer seqs = new StringBuffer();
2973 for (int i = 0; i < consensus.annotations.length; i++)
2975 Annotation annotation = consensus.annotations[i];
2976 if (annotation != null)
2978 String description = annotation.description;
2979 if (description != null && description.startsWith("["))
2981 // consensus is a tie - just pick the first one
2982 seqs.append(description.charAt(1));
2986 seqs.append(annotation.displayCharacter);
2991 SequenceI sq = new Sequence("Consensus", seqs.toString());
2992 sq.setDescription("Percentage Identity Consensus "
2993 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
2998 public void setCurrentTree(TreeModel tree)
3004 public TreeModel getCurrentTree()
3010 public AlignmentExportData getAlignExportData(AlignExportSettingsI options)
3012 AlignmentI alignmentToExport = null;
3013 String[] omitHidden = null;
3014 alignmentToExport = null;
3016 if (hasHiddenColumns() && !options.isExportHiddenColumns())
3018 omitHidden = getViewAsString(false,
3019 options.isExportHiddenSequences());
3022 int[] alignmentStartEnd = new int[2];
3023 if (hasHiddenRows() && options.isExportHiddenSequences())
3025 alignmentToExport = getAlignment().getHiddenSequences()
3026 .getFullAlignment();
3030 alignmentToExport = getAlignment();
3032 alignmentStartEnd = getAlignment().getHiddenColumns()
3033 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
3034 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
3035 omitHidden, alignmentStartEnd);
3040 * flag set to indicate if structure views might be out of sync with sequences
3044 private boolean needToUpdateStructureViews = false;
3047 public boolean isUpdateStructures()
3049 return needToUpdateStructureViews;
3053 public void setUpdateStructures(boolean update)
3055 needToUpdateStructureViews = update;
3059 public boolean needToUpdateStructureViews()
3061 boolean update = needToUpdateStructureViews;
3062 needToUpdateStructureViews = false;
3067 public void addSequenceGroup(SequenceGroup sequenceGroup)
3069 alignment.addGroup(sequenceGroup);
3071 Color col = sequenceGroup.idColour;
3074 col = col.brighter();
3076 for (SequenceI sq : sequenceGroup.getSequences())
3078 setSequenceColour(sq, col);
3082 if (codingComplement != null)
3084 SequenceGroup mappedGroup = MappingUtils
3085 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3086 if (mappedGroup.getSequences().size() > 0)
3088 codingComplement.getAlignment().addGroup(mappedGroup);
3092 for (SequenceI seq : mappedGroup.getSequences())
3094 codingComplement.setSequenceColour(seq, col);
3098 // propagate the structure view update flag according to our own setting
3099 codingComplement.setUpdateStructures(needToUpdateStructureViews);