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.api.AlignCalcManagerI;
26 import jalview.api.AlignViewportI;
27 import jalview.api.AlignmentViewPanel;
28 import jalview.api.FeaturesDisplayedI;
29 import jalview.api.ViewStyleI;
30 import jalview.commands.CommandI;
31 import jalview.datamodel.AlignedCodonFrame;
32 import jalview.datamodel.AlignmentAnnotation;
33 import jalview.datamodel.AlignmentI;
34 import jalview.datamodel.AlignmentView;
35 import jalview.datamodel.Annotation;
36 import jalview.datamodel.CigarArray;
37 import jalview.datamodel.ColumnSelection;
38 import jalview.datamodel.HiddenColumns;
39 import jalview.datamodel.HiddenSequences;
40 import jalview.datamodel.ProfilesI;
41 import jalview.datamodel.SearchResultsI;
42 import jalview.datamodel.Sequence;
43 import jalview.datamodel.SequenceCollectionI;
44 import jalview.datamodel.SequenceGroup;
45 import jalview.datamodel.SequenceI;
46 import jalview.renderer.ResidueShader;
47 import jalview.renderer.ResidueShaderI;
48 import jalview.schemes.ColourSchemeI;
49 import jalview.structure.CommandListener;
50 import jalview.structure.StructureSelectionManager;
51 import jalview.structure.VamsasSource;
52 import jalview.util.Comparison;
53 import jalview.util.MapList;
54 import jalview.util.MappingUtils;
55 import jalview.viewmodel.styles.ViewStyle;
56 import jalview.workers.AlignCalcManager;
57 import jalview.workers.ComplementConsensusThread;
58 import jalview.workers.ConsensusThread;
59 import jalview.workers.StrucConsensusThread;
61 import java.awt.Color;
62 import java.beans.PropertyChangeSupport;
63 import java.util.ArrayDeque;
64 import java.util.ArrayList;
65 import java.util.BitSet;
66 import java.util.Deque;
67 import java.util.HashMap;
68 import java.util.Hashtable;
69 import java.util.List;
73 * base class holding visualization and analysis attributes and common logic for
74 * an active alignment view displayed in the GUI
79 public abstract class AlignmentViewport implements AlignViewportI,
80 CommandListener, VamsasSource
82 final protected ViewportRanges ranges;
84 protected ViewStyleI viewStyle = new ViewStyle();
87 * A viewport that hosts the cDna view of this (protein), or vice versa (if
90 AlignViewportI codingComplement = null;
92 FeaturesDisplayedI featuresDisplayed = null;
94 protected Deque<CommandI> historyList = new ArrayDeque<CommandI>();
96 protected Deque<CommandI> redoList = new ArrayDeque<CommandI>();
99 * alignment displayed in the viewport. Please use get/setter
101 protected AlignmentI alignment;
103 public AlignmentViewport(AlignmentI al)
106 ranges = new ViewportRanges(al);
111 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
114 public void setFontName(String name)
116 viewStyle.setFontName(name);
121 * @see jalview.api.ViewStyleI#setFontStyle(int)
124 public void setFontStyle(int style)
126 viewStyle.setFontStyle(style);
131 * @see jalview.api.ViewStyleI#setFontSize(int)
134 public void setFontSize(int size)
136 viewStyle.setFontSize(size);
141 * @see jalview.api.ViewStyleI#getFontStyle()
144 public int getFontStyle()
146 return viewStyle.getFontStyle();
151 * @see jalview.api.ViewStyleI#getFontName()
154 public String getFontName()
156 return viewStyle.getFontName();
161 * @see jalview.api.ViewStyleI#getFontSize()
164 public int getFontSize()
166 return viewStyle.getFontSize();
170 * @param upperCasebold
171 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
174 public void setUpperCasebold(boolean upperCasebold)
176 viewStyle.setUpperCasebold(upperCasebold);
181 * @see jalview.api.ViewStyleI#isUpperCasebold()
184 public boolean isUpperCasebold()
186 return viewStyle.isUpperCasebold();
191 * @see jalview.api.ViewStyleI#isSeqNameItalics()
194 public boolean isSeqNameItalics()
196 return viewStyle.isSeqNameItalics();
200 * @param colourByReferenceSeq
201 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
204 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
206 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
211 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
214 public void setColourAppliesToAllGroups(boolean b)
216 viewStyle.setColourAppliesToAllGroups(b);
221 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
224 public boolean getColourAppliesToAllGroups()
226 return viewStyle.getColourAppliesToAllGroups();
231 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
234 public boolean getAbovePIDThreshold()
236 return viewStyle.getAbovePIDThreshold();
241 * @see jalview.api.ViewStyleI#setIncrement(int)
244 public void setIncrement(int inc)
246 viewStyle.setIncrement(inc);
251 * @see jalview.api.ViewStyleI#getIncrement()
254 public int getIncrement()
256 return viewStyle.getIncrement();
261 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
264 public void setConservationSelected(boolean b)
266 viewStyle.setConservationSelected(b);
271 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
274 public void setShowHiddenMarkers(boolean show)
276 viewStyle.setShowHiddenMarkers(show);
281 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
284 public boolean getShowHiddenMarkers()
286 return viewStyle.getShowHiddenMarkers();
291 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
294 public void setScaleRightWrapped(boolean b)
296 viewStyle.setScaleRightWrapped(b);
301 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
304 public void setScaleLeftWrapped(boolean b)
306 viewStyle.setScaleLeftWrapped(b);
311 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
314 public void setScaleAboveWrapped(boolean b)
316 viewStyle.setScaleAboveWrapped(b);
321 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
324 public boolean getScaleLeftWrapped()
326 return viewStyle.getScaleLeftWrapped();
331 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
334 public boolean getScaleAboveWrapped()
336 return viewStyle.getScaleAboveWrapped();
341 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
344 public boolean getScaleRightWrapped()
346 return viewStyle.getScaleRightWrapped();
351 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
354 public void setAbovePIDThreshold(boolean b)
356 viewStyle.setAbovePIDThreshold(b);
361 * @see jalview.api.ViewStyleI#setThreshold(int)
364 public void setThreshold(int thresh)
366 viewStyle.setThreshold(thresh);
371 * @see jalview.api.ViewStyleI#getThreshold()
374 public int getThreshold()
376 return viewStyle.getThreshold();
381 * @see jalview.api.ViewStyleI#getShowJVSuffix()
384 public boolean getShowJVSuffix()
386 return viewStyle.getShowJVSuffix();
391 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
394 public void setShowJVSuffix(boolean b)
396 viewStyle.setShowJVSuffix(b);
401 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
404 public void setWrapAlignment(boolean state)
406 viewStyle.setWrapAlignment(state);
411 * @see jalview.api.ViewStyleI#setShowText(boolean)
414 public void setShowText(boolean state)
416 viewStyle.setShowText(state);
421 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
424 public void setRenderGaps(boolean state)
426 viewStyle.setRenderGaps(state);
431 * @see jalview.api.ViewStyleI#getColourText()
434 public boolean getColourText()
436 return viewStyle.getColourText();
441 * @see jalview.api.ViewStyleI#setColourText(boolean)
444 public void setColourText(boolean state)
446 viewStyle.setColourText(state);
451 * @see jalview.api.ViewStyleI#getWrapAlignment()
454 public boolean getWrapAlignment()
456 return viewStyle.getWrapAlignment();
461 * @see jalview.api.ViewStyleI#getShowText()
464 public boolean getShowText()
466 return viewStyle.getShowText();
471 * @see jalview.api.ViewStyleI#getWrappedWidth()
474 public int getWrappedWidth()
476 return viewStyle.getWrappedWidth();
481 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
484 public void setWrappedWidth(int w)
486 viewStyle.setWrappedWidth(w);
491 * @see jalview.api.ViewStyleI#getCharHeight()
494 public int getCharHeight()
496 return viewStyle.getCharHeight();
501 * @see jalview.api.ViewStyleI#setCharHeight(int)
504 public void setCharHeight(int h)
506 viewStyle.setCharHeight(h);
511 * @see jalview.api.ViewStyleI#getCharWidth()
514 public int getCharWidth()
516 return viewStyle.getCharWidth();
521 * @see jalview.api.ViewStyleI#setCharWidth(int)
524 public void setCharWidth(int w)
526 viewStyle.setCharWidth(w);
531 * @see jalview.api.ViewStyleI#getShowBoxes()
534 public boolean getShowBoxes()
536 return viewStyle.getShowBoxes();
541 * @see jalview.api.ViewStyleI#getShowUnconserved()
544 public boolean getShowUnconserved()
546 return viewStyle.getShowUnconserved();
550 * @param showunconserved
551 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
554 public void setShowUnconserved(boolean showunconserved)
556 viewStyle.setShowUnconserved(showunconserved);
561 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
564 public void setSeqNameItalics(boolean default1)
566 viewStyle.setSeqNameItalics(default1);
572 public AlignmentI getAlignment()
578 public char getGapCharacter()
580 return alignment.getGapCharacter();
583 protected String sequenceSetID;
586 * probably unused indicator that view is of a dataset rather than an
589 protected boolean isDataset = false;
591 public void setDataset(boolean b)
596 public boolean isDataset()
601 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
603 protected ColumnSelection colSel = new ColumnSelection();
605 public boolean autoCalculateConsensus = true;
607 protected boolean autoCalculateStrucConsensus = true;
609 protected boolean ignoreGapsInConsensusCalculation = false;
611 protected ResidueShaderI residueShading;
614 public void setGlobalColourScheme(ColourSchemeI cs)
616 // TODO: logic refactored from AlignFrame changeColour -
617 // TODO: autorecalc stuff should be changed to rely on the worker system
618 // check to see if we should implement a changeColour(cs) method rather than
619 // put the logic in here
620 // - means that caller decides if they want to just modify state and defer
621 // calculation till later or to do all calculations in thread.
625 * only instantiate alignment colouring once, thereafter update it;
626 * this means that any conservation or PID threshold settings
627 * persist when the alignment colour scheme is changed
629 if (residueShading == null)
631 residueShading = new ResidueShader(viewStyle);
633 residueShading.setColourScheme(cs);
635 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
636 // ...problem: groups need these, but do not currently have a ViewStyle
640 if (getConservationSelected())
642 residueShading.setConservation(hconservation);
644 residueShading.alignmentChanged(alignment, hiddenRepSequences);
648 * if 'apply colour to all groups' is selected... do so
649 * (but don't transfer any colour threshold settings to groups)
651 if (getColourAppliesToAllGroups())
653 for (SequenceGroup sg : getAlignment().getGroups())
656 * retain any colour thresholds per group while
657 * changing choice of colour scheme (JAL-2386)
659 sg.setColourScheme(cs);
662 sg.getGroupColourScheme()
663 .alignmentChanged(sg, hiddenRepSequences);
670 public ColourSchemeI getGlobalColourScheme()
672 return residueShading == null ? null : residueShading
677 public ResidueShaderI getResidueShading()
679 return residueShading;
682 protected AlignmentAnnotation consensus;
684 protected AlignmentAnnotation complementConsensus;
686 protected AlignmentAnnotation gapcounts;
688 protected AlignmentAnnotation strucConsensus;
690 protected AlignmentAnnotation conservation;
692 protected AlignmentAnnotation quality;
694 protected AlignmentAnnotation[] groupConsensus;
696 protected AlignmentAnnotation[] groupConservation;
699 * results of alignment consensus analysis for visible portion of view
701 protected ProfilesI hconsensus = null;
704 * results of cDNA complement consensus visible portion of view
706 protected Hashtable[] hcomplementConsensus = null;
709 * results of secondary structure base pair consensus for visible portion of
712 protected Hashtable[] hStrucConsensus = null;
714 protected Conservation hconservation = null;
717 public void setConservation(Conservation cons)
719 hconservation = cons;
723 * percentage gaps allowed in a column before all amino acid properties should
724 * be considered unconserved
726 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
729 public int getConsPercGaps()
735 public void setSequenceConsensusHash(ProfilesI hconsensus)
737 this.hconsensus = hconsensus;
741 public void setComplementConsensusHash(Hashtable[] hconsensus)
743 this.hcomplementConsensus = hconsensus;
747 public ProfilesI getSequenceConsensusHash()
753 public Hashtable[] getComplementConsensusHash()
755 return hcomplementConsensus;
759 public Hashtable[] getRnaStructureConsensusHash()
761 return hStrucConsensus;
765 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
767 this.hStrucConsensus = hStrucConsensus;
772 public AlignmentAnnotation getAlignmentQualityAnnot()
778 public AlignmentAnnotation getAlignmentConservationAnnotation()
784 public AlignmentAnnotation getAlignmentConsensusAnnotation()
790 public AlignmentAnnotation getAlignmentGapAnnotation()
796 public AlignmentAnnotation getComplementConsensusAnnotation()
798 return complementConsensus;
802 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
804 return strucConsensus;
807 protected AlignCalcManagerI calculator = new AlignCalcManager();
810 * trigger update of conservation annotation
812 public void updateConservation(final AlignmentViewPanel ap)
814 // see note in mantis : issue number 8585
815 if (alignment.isNucleotide()
816 || (conservation == null && quality == null)
817 || !autoCalculateConsensus)
822 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
824 calculator.registerWorker(new jalview.workers.ConservationThread(
830 * trigger update of consensus annotation
832 public void updateConsensus(final AlignmentViewPanel ap)
834 // see note in mantis : issue number 8585
835 if ((consensus == null || gapcounts == null) || !autoCalculateConsensus)
839 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
841 calculator.registerWorker(new ConsensusThread(this, ap));
845 * A separate thread to compute cDNA consensus for a protein alignment
846 * which has mapping to cDNA
848 final AlignmentI al = this.getAlignment();
849 if (!al.isNucleotide() && al.getCodonFrames() != null
850 && !al.getCodonFrames().isEmpty())
853 * fudge - check first for protein-to-nucleotide mappings
854 * (we don't want to do this for protein-to-protein)
856 boolean doConsensus = false;
857 for (AlignedCodonFrame mapping : al.getCodonFrames())
859 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
860 MapList[] mapLists = mapping.getdnaToProt();
861 // mapLists can be empty if project load has not finished resolving seqs
862 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
871 .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null)
874 .registerWorker(new ComplementConsensusThread(this, ap));
880 // --------START Structure Conservation
881 public void updateStrucConsensus(final AlignmentViewPanel ap)
883 if (autoCalculateStrucConsensus && strucConsensus == null
884 && alignment.isNucleotide() && alignment.hasRNAStructure())
886 // secondary structure has been added - so init the consensus line
890 // see note in mantis : issue number 8585
891 if (strucConsensus == null || !autoCalculateStrucConsensus)
895 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
897 calculator.registerWorker(new StrucConsensusThread(this, ap));
901 public boolean isCalcInProgress()
903 return calculator.isWorking();
907 public boolean isCalculationInProgress(
908 AlignmentAnnotation alignmentAnnotation)
910 if (!alignmentAnnotation.autoCalculated)
914 if (calculator.workingInvolvedWith(alignmentAnnotation))
916 // System.err.println("grey out ("+alignmentAnnotation.label+")");
922 public void setAlignment(AlignmentI align)
924 this.alignment = align;
928 * Clean up references when this viewport is closed
931 public void dispose()
934 * defensively null out references to large objects in case
935 * this object is not garbage collected (as if!)
938 complementConsensus = null;
939 strucConsensus = null;
942 groupConsensus = null;
943 groupConservation = null;
945 hcomplementConsensus = null;
946 // colour scheme may hold reference to consensus
947 residueShading = null;
948 // TODO remove listeners from changeSupport?
949 changeSupport = null;
954 public boolean isClosed()
956 // TODO: check that this isClosed is only true after panel is closed, not
957 // before it is fully constructed.
958 return alignment == null;
962 public AlignCalcManagerI getCalcManager()
968 * should conservation rows be shown for groups
970 protected boolean showGroupConservation = false;
973 * should consensus rows be shown for groups
975 protected boolean showGroupConsensus = false;
978 * should consensus profile be rendered by default
980 protected boolean showSequenceLogo = false;
983 * should consensus profile be rendered normalised to row height
985 protected boolean normaliseSequenceLogo = false;
988 * should consensus histograms be rendered by default
990 protected boolean showConsensusHistogram = true;
993 * @return the showConsensusProfile
996 public boolean isShowSequenceLogo()
998 return showSequenceLogo;
1002 * @param showSequenceLogo
1005 public void setShowSequenceLogo(boolean showSequenceLogo)
1007 if (showSequenceLogo != this.showSequenceLogo)
1009 // TODO: decouple settings setting from calculation when refactoring
1010 // annotation update method from alignframe to viewport
1011 this.showSequenceLogo = showSequenceLogo;
1012 calculator.updateAnnotationFor(ConsensusThread.class);
1013 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1014 calculator.updateAnnotationFor(StrucConsensusThread.class);
1016 this.showSequenceLogo = showSequenceLogo;
1020 * @param showConsensusHistogram
1021 * the showConsensusHistogram to set
1023 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1025 this.showConsensusHistogram = showConsensusHistogram;
1029 * @return the showGroupConservation
1031 public boolean isShowGroupConservation()
1033 return showGroupConservation;
1037 * @param showGroupConservation
1038 * the showGroupConservation to set
1040 public void setShowGroupConservation(boolean showGroupConservation)
1042 this.showGroupConservation = showGroupConservation;
1046 * @return the showGroupConsensus
1048 public boolean isShowGroupConsensus()
1050 return showGroupConsensus;
1054 * @param showGroupConsensus
1055 * the showGroupConsensus to set
1057 public void setShowGroupConsensus(boolean showGroupConsensus)
1059 this.showGroupConsensus = showGroupConsensus;
1064 * @return flag to indicate if the consensus histogram should be rendered by
1068 public boolean isShowConsensusHistogram()
1070 return this.showConsensusHistogram;
1074 * when set, updateAlignment will always ensure sequences are of equal length
1076 private boolean padGaps = false;
1079 * when set, alignment should be reordered according to a newly opened tree
1081 public boolean sortByTree = false;
1086 * @return null or the currently selected sequence region
1089 public SequenceGroup getSelectionGroup()
1091 return selectionGroup;
1095 * Set the selection group for this window. Also sets the current alignment as
1096 * the context for the group, if it does not already have one.
1099 * - group holding references to sequences in this alignment view
1103 public void setSelectionGroup(SequenceGroup sg)
1105 selectionGroup = sg;
1106 if (sg != null && sg.getContext() == null)
1108 sg.setContext(alignment);
1112 public void setHiddenColumns(HiddenColumns hidden)
1114 this.alignment.setHiddenColumns(hidden);
1115 // this.colSel = colsel;
1119 public ColumnSelection getColumnSelection()
1125 public void setColumnSelection(ColumnSelection colSel)
1127 this.colSel = colSel;
1130 updateHiddenColumns();
1132 isColSelChanged(true);
1140 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1142 return hiddenRepSequences;
1146 public void setHiddenRepSequences(
1147 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1149 this.hiddenRepSequences = hiddenRepSequences;
1153 public boolean hasSelectedColumns()
1155 ColumnSelection columnSelection = getColumnSelection();
1156 return columnSelection != null && columnSelection.hasSelectedColumns();
1160 public boolean hasHiddenColumns()
1162 return colSel != null
1163 && alignment.getHiddenColumns().hasHiddenColumns();
1166 public void updateHiddenColumns()
1168 // this method doesn't really do anything now. But - it could, since a
1169 // column Selection could be in the process of modification
1170 // hasHiddenColumns = colSel.hasHiddenColumns();
1174 public boolean hasHiddenRows()
1176 return alignment.getHiddenSequences().getSize() > 0;
1179 protected SequenceGroup selectionGroup;
1181 public void setSequenceSetId(String newid)
1183 if (sequenceSetID != null)
1186 .println("Warning - overwriting a sequenceSetId for a viewport!");
1188 sequenceSetID = new String(newid);
1192 public String getSequenceSetId()
1194 if (sequenceSetID == null)
1196 sequenceSetID = alignment.hashCode() + "";
1199 return sequenceSetID;
1203 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1206 protected String viewId = null;
1209 public String getViewId()
1213 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1218 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1220 ignoreGapsInConsensusCalculation = b;
1223 updateConsensus(ap);
1224 if (residueShading != null)
1226 residueShading.setThreshold(residueShading.getThreshold(),
1227 ignoreGapsInConsensusCalculation);
1233 private long sgrouphash = -1, colselhash = -1;
1236 * checks current SelectionGroup against record of last hash value, and
1240 * update the record of last hash value
1242 * @return true if SelectionGroup changed since last call (when b is true)
1244 public boolean isSelectionGroupChanged(boolean b)
1246 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1247 : selectionGroup.hashCode();
1248 if (hc != -1 && hc != sgrouphash)
1260 * checks current colsel against record of last hash value, and optionally
1264 * update the record of last hash value
1265 * @return true if colsel changed since last call (when b is true)
1267 public boolean isColSelChanged(boolean b)
1269 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1270 if (hc != -1 && hc != colselhash)
1282 public boolean isIgnoreGapsConsensus()
1284 return ignoreGapsInConsensusCalculation;
1287 // property change stuff
1288 // JBPNote Prolly only need this in the applet version.
1289 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1292 protected boolean showConservation = true;
1294 protected boolean showQuality = true;
1296 protected boolean showConsensus = true;
1298 private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
1300 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1302 protected boolean showAutocalculatedAbove;
1305 * when set, view will scroll to show the highlighted position
1307 private boolean followHighlight = true;
1310 * Property change listener for changes in alignment
1315 public void addPropertyChangeListener(
1316 java.beans.PropertyChangeListener listener)
1318 changeSupport.addPropertyChangeListener(listener);
1327 public void removePropertyChangeListener(
1328 java.beans.PropertyChangeListener listener)
1330 changeSupport.removePropertyChangeListener(listener);
1334 * Property change listener for changes in alignment
1343 public void firePropertyChange(String prop, Object oldvalue,
1346 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1349 // common hide/show column stuff
1351 public void hideSelectedColumns()
1353 if (colSel.isEmpty())
1358 colSel.hideSelectedColumns(alignment);
1359 setSelectionGroup(null);
1360 isColSelChanged(true);
1363 public void hideColumns(int start, int end)
1367 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1371 alignment.getHiddenColumns().hideColumns(start, end);
1373 isColSelChanged(true);
1376 public void showColumn(int col)
1378 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1379 isColSelChanged(true);
1382 public void showAllHiddenColumns()
1384 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1385 isColSelChanged(true);
1388 // common hide/show seq stuff
1389 public void showAllHiddenSeqs()
1391 if (alignment.getHiddenSequences().getSize() > 0)
1393 if (selectionGroup == null)
1395 selectionGroup = new SequenceGroup();
1396 selectionGroup.setEndRes(alignment.getWidth() - 1);
1398 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1399 hiddenRepSequences);
1400 for (SequenceI seq : tmp)
1402 selectionGroup.addSequence(seq, false);
1403 setSequenceAnnotationsVisible(seq, true);
1406 hiddenRepSequences = null;
1408 firePropertyChange("alignment", null, alignment.getSequences());
1409 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1415 public void showSequence(int index)
1417 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1418 index, hiddenRepSequences);
1421 if (selectionGroup == null)
1423 selectionGroup = new SequenceGroup();
1424 selectionGroup.setEndRes(alignment.getWidth() - 1);
1427 for (SequenceI seq : tmp)
1429 selectionGroup.addSequence(seq, false);
1430 setSequenceAnnotationsVisible(seq, true);
1432 firePropertyChange("alignment", null, alignment.getSequences());
1437 public void hideAllSelectedSeqs()
1439 if (selectionGroup == null || selectionGroup.getSize() < 1)
1444 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1448 setSelectionGroup(null);
1451 public void hideSequence(SequenceI[] seq)
1455 for (int i = 0; i < seq.length; i++)
1457 alignment.getHiddenSequences().hideSequence(seq[i]);
1458 setSequenceAnnotationsVisible(seq[i], false);
1460 firePropertyChange("alignment", null, alignment.getSequences());
1465 * Hides the specified sequence, or the sequences it represents
1468 * the sequence to hide, or keep as representative
1469 * @param representGroup
1470 * if true, hide the current selection group except for the
1471 * representative sequence
1473 public void hideSequences(SequenceI sequence, boolean representGroup)
1475 if (selectionGroup == null || selectionGroup.getSize() < 1)
1477 hideSequence(new SequenceI[] { sequence });
1483 hideRepSequences(sequence, selectionGroup);
1484 setSelectionGroup(null);
1488 int gsize = selectionGroup.getSize();
1489 SequenceI[] hseqs = selectionGroup.getSequences().toArray(
1490 new SequenceI[gsize]);
1492 hideSequence(hseqs);
1493 setSelectionGroup(null);
1498 * Set visibility for any annotations for the given sequence.
1502 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1505 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1508 for (AlignmentAnnotation ann : anns)
1510 if (ann.sequenceRef == sequenceI)
1512 ann.visible = visible;
1518 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1520 int sSize = sg.getSize();
1526 if (hiddenRepSequences == null)
1528 hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
1531 hiddenRepSequences.put(repSequence, sg);
1533 // Hide all sequences except the repSequence
1534 SequenceI[] seqs = new SequenceI[sSize - 1];
1536 for (int i = 0; i < sSize; i++)
1538 if (sg.getSequenceAt(i) != repSequence)
1540 if (index == sSize - 1)
1545 seqs[index++] = sg.getSequenceAt(i);
1548 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1549 sg.setHidereps(true); // note: not done in 2.7applet
1556 * @return null or the current reference sequence
1558 public SequenceI getReferenceSeq()
1560 return alignment.getSeqrep();
1565 * @return true iff seq is the reference for the alignment
1567 public boolean isReferenceSeq(SequenceI seq)
1569 return alignment.getSeqrep() == seq;
1575 * @return true if there are sequences represented by this sequence that are
1578 public boolean isHiddenRepSequence(SequenceI seq)
1580 return (hiddenRepSequences != null && hiddenRepSequences
1587 * @return null or a sequence group containing the sequences that seq
1590 public SequenceGroup getRepresentedSequences(SequenceI seq)
1592 return (SequenceGroup) (hiddenRepSequences == null ? null
1593 : hiddenRepSequences.get(seq));
1597 public int adjustForHiddenSeqs(int alignmentIndex)
1599 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1604 public void invertColumnSelection()
1606 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1610 public SequenceI[] getSelectionAsNewSequence()
1612 SequenceI[] sequences;
1613 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1614 // this was the only caller in the applet for this method
1615 // JBPNote: in applet, this method returned references to the alignment
1616 // sequences, and it did not honour the presence/absence of annotation
1617 // attached to the alignment (probably!)
1618 if (selectionGroup == null || selectionGroup.getSize() == 0)
1620 sequences = alignment.getSequencesArray();
1621 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1622 for (int i = 0; i < sequences.length; i++)
1624 // construct new sequence with subset of visible annotation
1625 sequences[i] = new Sequence(sequences[i], annots);
1630 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1637 public SequenceI[] getSequenceSelection()
1639 SequenceI[] sequences = null;
1640 if (selectionGroup != null)
1642 sequences = selectionGroup.getSequencesInOrder(alignment);
1644 if (sequences == null)
1646 sequences = alignment.getSequencesArray();
1652 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1654 return new CigarArray(alignment, alignment.getHiddenColumns(),
1655 (selectedRegionOnly ? selectionGroup : null));
1659 public jalview.datamodel.AlignmentView getAlignmentView(
1660 boolean selectedOnly)
1662 return getAlignmentView(selectedOnly, false);
1666 public jalview.datamodel.AlignmentView getAlignmentView(
1667 boolean selectedOnly, boolean markGroups)
1669 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1670 selectionGroup, alignment.getHiddenColumns() != null
1671 && alignment.getHiddenColumns().hasHiddenColumns(),
1677 public String[] getViewAsString(boolean selectedRegionOnly)
1679 return getViewAsString(selectedRegionOnly, true);
1683 public String[] getViewAsString(boolean selectedRegionOnly,
1684 boolean exportHiddenSeqs)
1686 String[] selection = null;
1687 SequenceI[] seqs = null;
1689 int start = 0, end = 0;
1690 if (selectedRegionOnly && selectionGroup != null)
1692 iSize = selectionGroup.getSize();
1693 seqs = selectionGroup.getSequencesInOrder(alignment);
1694 start = selectionGroup.getStartRes();
1695 end = selectionGroup.getEndRes() + 1;
1699 if (hasHiddenRows() && exportHiddenSeqs)
1701 AlignmentI fullAlignment = alignment.getHiddenSequences()
1702 .getFullAlignment();
1703 iSize = fullAlignment.getHeight();
1704 seqs = fullAlignment.getSequencesArray();
1705 end = fullAlignment.getWidth();
1709 iSize = alignment.getHeight();
1710 seqs = alignment.getSequencesArray();
1711 end = alignment.getWidth();
1715 selection = new String[iSize];
1716 if (alignment.getHiddenColumns() != null
1717 && alignment.getHiddenColumns().hasHiddenColumns())
1719 selection = alignment.getHiddenColumns().getVisibleSequenceStrings(
1724 for (i = 0; i < iSize; i++)
1726 selection[i] = seqs[i].getSequenceAsString(start, end);
1734 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1736 ArrayList<int[]> regions = new ArrayList<int[]>();
1742 HiddenColumns hidden = alignment.getHiddenColumns();
1743 if (hidden != null && hidden.hasHiddenColumns())
1747 start = hidden.adjustForHiddenColumns(start);
1750 end = hidden.getHiddenBoundaryRight(start);
1761 regions.add(new int[] { start, end });
1763 if (hidden != null && hidden.hasHiddenColumns())
1765 start = hidden.adjustForHiddenColumns(end);
1766 start = hidden.getHiddenBoundaryLeft(start) + 1;
1768 } while (end < max);
1770 int[][] startEnd = new int[regions.size()][2];
1776 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1777 boolean selectedOnly)
1779 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1780 AlignmentAnnotation[] aa;
1781 if ((aa = alignment.getAlignmentAnnotation()) != null)
1783 for (AlignmentAnnotation annot : aa)
1785 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1786 if (selectedOnly && selectionGroup != null)
1788 alignment.getHiddenColumns().makeVisibleAnnotation(
1789 selectionGroup.getStartRes(),
1790 selectionGroup.getEndRes(), clone);
1794 alignment.getHiddenColumns().makeVisibleAnnotation(clone);
1803 public boolean isPadGaps()
1809 public void setPadGaps(boolean padGaps)
1811 this.padGaps = padGaps;
1815 * apply any post-edit constraints and trigger any calculations needed after
1816 * an edit has been performed on the alignment
1821 public void alignmentChanged(AlignmentViewPanel ap)
1825 alignment.padGaps();
1827 if (autoCalculateConsensus)
1829 updateConsensus(ap);
1831 if (hconsensus != null && autoCalculateConsensus)
1833 updateConservation(ap);
1835 if (autoCalculateStrucConsensus)
1837 updateStrucConsensus(ap);
1840 // Reset endRes of groups if beyond alignment width
1841 int alWidth = alignment.getWidth();
1842 List<SequenceGroup> groups = alignment.getGroups();
1845 for (SequenceGroup sg : groups)
1847 if (sg.getEndRes() > alWidth)
1849 sg.setEndRes(alWidth - 1);
1854 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1856 selectionGroup.setEndRes(alWidth - 1);
1859 updateAllColourSchemes();
1860 calculator.restartWorkers();
1861 // alignment.adjustSequenceAnnotations();
1865 * reset scope and do calculations for all applied colourschemes on alignment
1867 void updateAllColourSchemes()
1869 ResidueShaderI rs = residueShading;
1872 rs.alignmentChanged(alignment, hiddenRepSequences);
1874 rs.setConsensus(hconsensus);
1875 if (rs.conservationApplied())
1877 rs.setConservation(Conservation.calculateConservation("All",
1878 alignment.getSequences(), 0, alignment.getWidth(), false,
1879 getConsPercGaps(), false));
1883 for (SequenceGroup sg : alignment.getGroups())
1887 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1889 sg.recalcConservation();
1893 protected void initAutoAnnotation()
1895 // TODO: add menu option action that nulls or creates consensus object
1896 // depending on if the user wants to see the annotation or not in a
1897 // specific alignment
1899 if (hconsensus == null && !isDataset)
1901 if (!alignment.isNucleotide())
1910 consensus = new AlignmentAnnotation("Consensus", "PID",
1911 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1912 initConsensus(consensus);
1913 gapcounts = new AlignmentAnnotation("Occupancy",
1914 "Number of aligned positions",
1915 new Annotation[1], 0f, alignment.getHeight(),
1916 AlignmentAnnotation.BAR_GRAPH);
1917 initGapCounts(gapcounts);
1919 initComplementConsensus();
1924 * If this is a protein alignment and there are mappings to cDNA, adds the
1925 * cDNA consensus annotation and returns true, else returns false.
1927 public boolean initComplementConsensus()
1929 if (!alignment.isNucleotide())
1931 final List<AlignedCodonFrame> codonMappings = alignment
1933 if (codonMappings != null && !codonMappings.isEmpty())
1935 boolean doConsensus = false;
1936 for (AlignedCodonFrame mapping : codonMappings)
1938 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1939 MapList[] mapLists = mapping.getdnaToProt();
1940 // mapLists can be empty if project load has not finished resolving
1942 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1950 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1951 "PID for cDNA", new Annotation[1], 0f, 100f,
1952 AlignmentAnnotation.BAR_GRAPH);
1953 initConsensus(complementConsensus);
1961 private void initConsensus(AlignmentAnnotation aa)
1964 aa.autoCalculated = true;
1968 alignment.addAnnotation(aa);
1972 // these should be extracted from the view model - style and settings for
1973 // derived annotation
1974 private void initGapCounts(AlignmentAnnotation counts)
1976 counts.hasText = false;
1977 counts.autoCalculated = true;
1978 counts.graph = AlignmentAnnotation.BAR_GRAPH;
1982 alignment.addAnnotation(counts);
1986 private void initConservation()
1988 if (showConservation)
1990 if (conservation == null)
1992 conservation = new AlignmentAnnotation("Conservation",
1993 "Conservation of total alignment less than "
1994 + getConsPercGaps() + "% gaps", new Annotation[1],
1995 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1996 conservation.hasText = true;
1997 conservation.autoCalculated = true;
1998 alignment.addAnnotation(conservation);
2003 private void initQuality()
2007 if (quality == null)
2009 quality = new AlignmentAnnotation("Quality",
2010 "Alignment Quality based on Blosum62 scores",
2011 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2012 quality.hasText = true;
2013 quality.autoCalculated = true;
2014 alignment.addAnnotation(quality);
2019 private void initRNAStructure()
2021 if (alignment.hasRNAStructure() && strucConsensus == null)
2023 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
2024 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2025 strucConsensus.hasText = true;
2026 strucConsensus.autoCalculated = true;
2030 alignment.addAnnotation(strucConsensus);
2038 * @see jalview.api.AlignViewportI#calcPanelHeight()
2041 public int calcPanelHeight()
2043 // setHeight of panels
2044 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2046 int charHeight = getCharHeight();
2049 BitSet graphgrp = new BitSet();
2050 for (AlignmentAnnotation aa : anns)
2054 System.err.println("Null annotation row: ignoring.");
2061 if (aa.graphGroup > -1)
2063 if (graphgrp.get(aa.graphGroup))
2069 graphgrp.set(aa.graphGroup);
2076 aa.height += charHeight;
2086 aa.height += aa.graphHeight;
2094 height += aa.height;
2106 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2107 boolean preserveNewGroupSettings)
2109 boolean updateCalcs = false;
2110 boolean conv = isShowGroupConservation();
2111 boolean cons = isShowGroupConsensus();
2112 boolean showprf = isShowSequenceLogo();
2113 boolean showConsHist = isShowConsensusHistogram();
2114 boolean normLogo = isNormaliseSequenceLogo();
2117 * TODO reorder the annotation rows according to group/sequence ordering on
2120 boolean sortg = true;
2122 // remove old automatic annotation
2123 // add any new annotation
2125 // intersect alignment annotation with alignment groups
2127 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2128 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
2131 for (int an = 0; an < aan.length; an++)
2133 if (aan[an].autoCalculated && aan[an].groupRef != null)
2135 oldrfs.add(aan[an].groupRef);
2136 alignment.deleteAnnotation(aan[an], false);
2140 if (alignment.getGroups() != null)
2142 for (SequenceGroup sg : alignment.getGroups())
2144 updateCalcs = false;
2145 if (applyGlobalSettings
2146 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2148 // set defaults for this group's conservation/consensus
2149 sg.setshowSequenceLogo(showprf);
2150 sg.setShowConsensusHistogram(showConsHist);
2151 sg.setNormaliseSequenceLogo(normLogo);
2156 alignment.addAnnotation(sg.getConservationRow(), 0);
2161 alignment.addAnnotation(sg.getConsensus(), 0);
2163 // refresh the annotation rows
2166 sg.recalcConservation();
2174 public boolean isDisplayReferenceSeq()
2176 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2180 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2182 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2186 public boolean isColourByReferenceSeq()
2188 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2192 public Color getSequenceColour(SequenceI seq)
2194 Color sqc = sequenceColours.get(seq);
2195 return (sqc == null ? Color.white : sqc);
2199 public void setSequenceColour(SequenceI seq, Color col)
2203 sequenceColours.remove(seq);
2207 sequenceColours.put(seq, col);
2212 public void updateSequenceIdColours()
2214 for (SequenceGroup sg : alignment.getGroups())
2216 if (sg.idColour != null)
2218 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2220 sequenceColours.put(s, sg.idColour);
2227 public void clearSequenceColours()
2229 sequenceColours.clear();
2233 public AlignViewportI getCodingComplement()
2235 return this.codingComplement;
2239 * Set this as the (cDna/protein) complement of the given viewport. Also
2240 * ensures the reverse relationship is set on the given viewport.
2243 public void setCodingComplement(AlignViewportI av)
2247 System.err.println("Ignoring recursive setCodingComplement request");
2251 this.codingComplement = av;
2252 // avoid infinite recursion!
2253 if (av.getCodingComplement() != this)
2255 av.setCodingComplement(this);
2261 public boolean isNucleotide()
2263 return getAlignment() == null ? false : getAlignment().isNucleotide();
2267 public FeaturesDisplayedI getFeaturesDisplayed()
2269 return featuresDisplayed;
2273 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2275 featuresDisplayed = featuresDisplayedI;
2279 public boolean areFeaturesDisplayed()
2281 return featuresDisplayed != null
2282 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2289 * features are displayed if true
2292 public void setShowSequenceFeatures(boolean b)
2294 viewStyle.setShowSequenceFeatures(b);
2298 public boolean isShowSequenceFeatures()
2300 return viewStyle.isShowSequenceFeatures();
2304 public void setShowSequenceFeaturesHeight(boolean selected)
2306 viewStyle.setShowSequenceFeaturesHeight(selected);
2310 public boolean isShowSequenceFeaturesHeight()
2312 return viewStyle.isShowSequenceFeaturesHeight();
2316 public void setShowAnnotation(boolean b)
2318 viewStyle.setShowAnnotation(b);
2322 public boolean isShowAnnotation()
2324 return viewStyle.isShowAnnotation();
2328 public boolean isRightAlignIds()
2330 return viewStyle.isRightAlignIds();
2334 public void setRightAlignIds(boolean rightAlignIds)
2336 viewStyle.setRightAlignIds(rightAlignIds);
2340 public boolean getConservationSelected()
2342 return viewStyle.getConservationSelected();
2346 public void setShowBoxes(boolean state)
2348 viewStyle.setShowBoxes(state);
2353 * @see jalview.api.ViewStyleI#getTextColour()
2356 public Color getTextColour()
2358 return viewStyle.getTextColour();
2363 * @see jalview.api.ViewStyleI#getTextColour2()
2366 public Color getTextColour2()
2368 return viewStyle.getTextColour2();
2373 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2376 public int getThresholdTextColour()
2378 return viewStyle.getThresholdTextColour();
2383 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2386 public boolean isConservationColourSelected()
2388 return viewStyle.isConservationColourSelected();
2393 * @see jalview.api.ViewStyleI#isRenderGaps()
2396 public boolean isRenderGaps()
2398 return viewStyle.isRenderGaps();
2403 * @see jalview.api.ViewStyleI#isShowColourText()
2406 public boolean isShowColourText()
2408 return viewStyle.isShowColourText();
2412 * @param conservationColourSelected
2413 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2416 public void setConservationColourSelected(
2417 boolean conservationColourSelected)
2419 viewStyle.setConservationColourSelected(conservationColourSelected);
2423 * @param showColourText
2424 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2427 public void setShowColourText(boolean showColourText)
2429 viewStyle.setShowColourText(showColourText);
2434 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2437 public void setTextColour(Color textColour)
2439 viewStyle.setTextColour(textColour);
2443 * @param thresholdTextColour
2444 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2447 public void setThresholdTextColour(int thresholdTextColour)
2449 viewStyle.setThresholdTextColour(thresholdTextColour);
2453 * @param textColour2
2454 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2457 public void setTextColour2(Color textColour2)
2459 viewStyle.setTextColour2(textColour2);
2463 public ViewStyleI getViewStyle()
2465 return new ViewStyle(viewStyle);
2469 public void setViewStyle(ViewStyleI settingsForView)
2471 viewStyle = new ViewStyle(settingsForView);
2472 if (residueShading != null)
2474 residueShading.setConservationApplied(settingsForView
2475 .isConservationColourSelected());
2480 public boolean sameStyle(ViewStyleI them)
2482 return viewStyle.sameStyle(them);
2487 * @see jalview.api.ViewStyleI#getIdWidth()
2490 public int getIdWidth()
2492 return viewStyle.getIdWidth();
2497 * @see jalview.api.ViewStyleI#setIdWidth(int)
2500 public void setIdWidth(int i)
2502 viewStyle.setIdWidth(i);
2507 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2510 public boolean isCentreColumnLabels()
2512 return viewStyle.isCentreColumnLabels();
2516 * @param centreColumnLabels
2517 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2520 public void setCentreColumnLabels(boolean centreColumnLabels)
2522 viewStyle.setCentreColumnLabels(centreColumnLabels);
2527 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2530 public void setShowDBRefs(boolean showdbrefs)
2532 viewStyle.setShowDBRefs(showdbrefs);
2537 * @see jalview.api.ViewStyleI#isShowDBRefs()
2540 public boolean isShowDBRefs()
2542 return viewStyle.isShowDBRefs();
2547 * @see jalview.api.ViewStyleI#isShowNPFeats()
2550 public boolean isShowNPFeats()
2552 return viewStyle.isShowNPFeats();
2556 * @param shownpfeats
2557 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2560 public void setShowNPFeats(boolean shownpfeats)
2562 viewStyle.setShowNPFeats(shownpfeats);
2565 public abstract StructureSelectionManager getStructureSelectionManager();
2568 * Add one command to the command history list.
2572 public void addToHistoryList(CommandI command)
2574 if (this.historyList != null)
2576 this.historyList.push(command);
2577 broadcastCommand(command, false);
2581 protected void broadcastCommand(CommandI command, boolean undo)
2583 getStructureSelectionManager().commandPerformed(command, undo,
2588 * Add one command to the command redo list.
2592 public void addToRedoList(CommandI command)
2594 if (this.redoList != null)
2596 this.redoList.push(command);
2598 broadcastCommand(command, true);
2602 * Clear the command redo list.
2604 public void clearRedoList()
2606 if (this.redoList != null)
2608 this.redoList.clear();
2612 public void setHistoryList(Deque<CommandI> list)
2614 this.historyList = list;
2617 public Deque<CommandI> getHistoryList()
2619 return this.historyList;
2622 public void setRedoList(Deque<CommandI> list)
2624 this.redoList = list;
2627 public Deque<CommandI> getRedoList()
2629 return this.redoList;
2633 public VamsasSource getVamsasSource()
2638 public SequenceAnnotationOrder getSortAnnotationsBy()
2640 return sortAnnotationsBy;
2643 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2645 this.sortAnnotationsBy = sortAnnotationsBy;
2648 public boolean isShowAutocalculatedAbove()
2650 return showAutocalculatedAbove;
2653 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2655 this.showAutocalculatedAbove = showAutocalculatedAbove;
2659 public boolean isScaleProteinAsCdna()
2661 return viewStyle.isScaleProteinAsCdna();
2665 public void setScaleProteinAsCdna(boolean b)
2667 viewStyle.setScaleProteinAsCdna(b);
2671 * @return true if view should scroll to show the highlighted region of a
2676 public final boolean isFollowHighlight()
2678 return followHighlight;
2682 public final void setFollowHighlight(boolean b)
2684 this.followHighlight = b;
2688 public ViewportRanges getRanges()
2694 * Helper method to populate the SearchResults with the location in the
2695 * complementary alignment to scroll to, in order to match this one.
2698 * the SearchResults to add to
2699 * @return the offset (below top of visible region) of the matched sequence
2701 protected int findComplementScrollTarget(SearchResultsI sr)
2703 final AlignViewportI complement = getCodingComplement();
2704 if (complement == null || !complement.isFollowHighlight())
2708 boolean iAmProtein = !getAlignment().isNucleotide();
2709 AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement
2711 if (proteinAlignment == null)
2715 final List<AlignedCodonFrame> mappings = proteinAlignment
2719 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2720 * residue in the middle column of the visible region. Scroll the
2721 * complementary alignment to line up the corresponding residue.
2724 SequenceI sequence = null;
2727 * locate 'middle' column (true middle if an odd number visible, left of
2728 * middle if an even number visible)
2730 int middleColumn = ranges.getStartRes()
2731 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2732 final HiddenSequences hiddenSequences = getAlignment()
2733 .getHiddenSequences();
2736 * searching to the bottom of the alignment gives smoother scrolling across
2737 * all gapped visible regions
2739 int lastSeq = alignment.getHeight() - 1;
2740 List<AlignedCodonFrame> seqMappings = null;
2741 for (int seqNo = ranges.getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2743 sequence = getAlignment().getSequenceAt(seqNo);
2744 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2748 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2752 seqMappings = MappingUtils
2753 .findMappingsForSequenceAndOthers(sequence, mappings,
2754 getCodingComplement().getAlignment().getSequences());
2755 if (!seqMappings.isEmpty())
2761 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2764 * No ungapped mapped sequence in middle column - do nothing
2768 MappingUtils.addSearchResults(sr, sequence,
2769 sequence.findPosition(middleColumn), seqMappings);
2774 * synthesize a column selection if none exists so it covers the given
2775 * selection group. if wholewidth is false, no column selection is made if the
2776 * selection group covers the whole alignment width.
2781 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2784 if (sg != null && (sgs = sg.getStartRes()) >= 0
2785 && sg.getStartRes() <= (sge = sg.getEndRes())
2786 && !this.hasSelectedColumns())
2788 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2795 colSel = new ColumnSelection();
2797 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2799 colSel.addElement(cspos);
2805 * hold status of current selection group - defined on alignment or not.
2807 private boolean selectionIsDefinedGroup = false;
2810 public boolean isSelectionDefinedGroup()
2812 if (selectionGroup == null)
2816 if (isSelectionGroupChanged(true))
2818 selectionIsDefinedGroup = false;
2819 List<SequenceGroup> gps = alignment.getGroups();
2820 if (gps == null || gps.size() == 0)
2822 selectionIsDefinedGroup = false;
2826 selectionIsDefinedGroup = gps.contains(selectionGroup);
2829 return selectionGroup.getContext() == alignment
2830 || selectionIsDefinedGroup;
2834 * null, or currently highlighted results on this view
2836 private SearchResultsI searchResults = null;
2839 public boolean hasSearchResults()
2841 return searchResults != null;
2845 public void setSearchResults(SearchResultsI results)
2847 searchResults = results;
2851 public SearchResultsI getSearchResults()
2853 return searchResults;