2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.viewmodel;
23 import java.awt.Color;
24 import java.beans.PropertyChangeSupport;
25 import java.util.ArrayDeque;
26 import java.util.ArrayList;
27 import java.util.BitSet;
28 import java.util.Deque;
29 import java.util.HashMap;
30 import java.util.Hashtable;
31 import java.util.List;
34 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
35 import jalview.analysis.Conservation;
36 import jalview.api.AlignCalcManagerI;
37 import jalview.api.AlignViewportI;
38 import jalview.api.AlignmentViewPanel;
39 import jalview.api.FeaturesDisplayedI;
40 import jalview.api.ViewStyleI;
41 import jalview.commands.CommandI;
42 import jalview.datamodel.AlignedCodonFrame;
43 import jalview.datamodel.AlignmentAnnotation;
44 import jalview.datamodel.AlignmentI;
45 import jalview.datamodel.AlignmentView;
46 import jalview.datamodel.Annotation;
47 import jalview.datamodel.CigarArray;
48 import jalview.datamodel.ColumnSelection;
49 import jalview.datamodel.HiddenSequences;
50 import jalview.datamodel.ProfilesI;
51 import jalview.datamodel.SearchResultsI;
52 import jalview.datamodel.Sequence;
53 import jalview.datamodel.SequenceCollectionI;
54 import jalview.datamodel.SequenceGroup;
55 import jalview.datamodel.SequenceI;
56 import jalview.renderer.ResidueShader;
57 import jalview.renderer.ResidueShaderI;
58 import jalview.schemes.ColourSchemeI;
59 import jalview.structure.CommandListener;
60 import jalview.structure.StructureSelectionManager;
61 import jalview.structure.VamsasSource;
62 import jalview.util.Comparison;
63 import jalview.util.MapList;
64 import jalview.util.MappingUtils;
65 import jalview.viewmodel.styles.ViewStyle;
66 import jalview.workers.AlignCalcManager;
67 import jalview.workers.ComplementConsensusThread;
68 import jalview.workers.ConsensusThread;
69 import jalview.workers.StrucConsensusThread;
72 * base class holding visualization and analysis attributes and common logic for
73 * an active alignment view displayed in the GUI
78 public abstract class AlignmentViewport implements AlignViewportI,
79 CommandListener, VamsasSource
81 protected ViewStyleI viewStyle = new ViewStyle();
84 * A viewport that hosts the cDna view of this (protein), or vice versa (if
87 AlignViewportI codingComplement = null;
89 FeaturesDisplayedI featuresDisplayed = null;
91 protected Deque<CommandI> historyList = new ArrayDeque<CommandI>();
93 protected Deque<CommandI> redoList = new ArrayDeque<CommandI>();
97 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
100 public void setFontName(String name)
102 viewStyle.setFontName(name);
107 * @see jalview.api.ViewStyleI#setFontStyle(int)
110 public void setFontStyle(int style)
112 viewStyle.setFontStyle(style);
117 * @see jalview.api.ViewStyleI#setFontSize(int)
120 public void setFontSize(int size)
122 viewStyle.setFontSize(size);
127 * @see jalview.api.ViewStyleI#getFontStyle()
130 public int getFontStyle()
132 return viewStyle.getFontStyle();
137 * @see jalview.api.ViewStyleI#getFontName()
140 public String getFontName()
142 return viewStyle.getFontName();
147 * @see jalview.api.ViewStyleI#getFontSize()
150 public int getFontSize()
152 return viewStyle.getFontSize();
156 * @param upperCasebold
157 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
160 public void setUpperCasebold(boolean upperCasebold)
162 viewStyle.setUpperCasebold(upperCasebold);
167 * @see jalview.api.ViewStyleI#isUpperCasebold()
170 public boolean isUpperCasebold()
172 return viewStyle.isUpperCasebold();
177 * @see jalview.api.ViewStyleI#isSeqNameItalics()
180 public boolean isSeqNameItalics()
182 return viewStyle.isSeqNameItalics();
186 * @param colourByReferenceSeq
187 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
190 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
192 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
197 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
200 public void setColourAppliesToAllGroups(boolean b)
202 viewStyle.setColourAppliesToAllGroups(b);
207 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
210 public boolean getColourAppliesToAllGroups()
212 return viewStyle.getColourAppliesToAllGroups();
217 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
220 public boolean getAbovePIDThreshold()
222 return viewStyle.getAbovePIDThreshold();
227 * @see jalview.api.ViewStyleI#setIncrement(int)
230 public void setIncrement(int inc)
232 viewStyle.setIncrement(inc);
237 * @see jalview.api.ViewStyleI#getIncrement()
240 public int getIncrement()
242 return viewStyle.getIncrement();
247 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
250 public void setConservationSelected(boolean b)
252 viewStyle.setConservationSelected(b);
257 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
260 public void setShowHiddenMarkers(boolean show)
262 viewStyle.setShowHiddenMarkers(show);
267 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
270 public boolean getShowHiddenMarkers()
272 return viewStyle.getShowHiddenMarkers();
277 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
280 public void setScaleRightWrapped(boolean b)
282 viewStyle.setScaleRightWrapped(b);
287 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
290 public void setScaleLeftWrapped(boolean b)
292 viewStyle.setScaleLeftWrapped(b);
297 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
300 public void setScaleAboveWrapped(boolean b)
302 viewStyle.setScaleAboveWrapped(b);
307 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
310 public boolean getScaleLeftWrapped()
312 return viewStyle.getScaleLeftWrapped();
317 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
320 public boolean getScaleAboveWrapped()
322 return viewStyle.getScaleAboveWrapped();
327 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
330 public boolean getScaleRightWrapped()
332 return viewStyle.getScaleRightWrapped();
337 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
340 public void setAbovePIDThreshold(boolean b)
342 viewStyle.setAbovePIDThreshold(b);
347 * @see jalview.api.ViewStyleI#setThreshold(int)
350 public void setThreshold(int thresh)
352 viewStyle.setThreshold(thresh);
357 * @see jalview.api.ViewStyleI#getThreshold()
360 public int getThreshold()
362 return viewStyle.getThreshold();
367 * @see jalview.api.ViewStyleI#getShowJVSuffix()
370 public boolean getShowJVSuffix()
372 return viewStyle.getShowJVSuffix();
377 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
380 public void setShowJVSuffix(boolean b)
382 viewStyle.setShowJVSuffix(b);
387 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
390 public void setWrapAlignment(boolean state)
392 viewStyle.setWrapAlignment(state);
397 * @see jalview.api.ViewStyleI#setShowText(boolean)
400 public void setShowText(boolean state)
402 viewStyle.setShowText(state);
407 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
410 public void setRenderGaps(boolean state)
412 viewStyle.setRenderGaps(state);
417 * @see jalview.api.ViewStyleI#getColourText()
420 public boolean getColourText()
422 return viewStyle.getColourText();
427 * @see jalview.api.ViewStyleI#setColourText(boolean)
430 public void setColourText(boolean state)
432 viewStyle.setColourText(state);
437 * @see jalview.api.ViewStyleI#getWrapAlignment()
440 public boolean getWrapAlignment()
442 return viewStyle.getWrapAlignment();
447 * @see jalview.api.ViewStyleI#getShowText()
450 public boolean getShowText()
452 return viewStyle.getShowText();
457 * @see jalview.api.ViewStyleI#getWrappedWidth()
460 public int getWrappedWidth()
462 return viewStyle.getWrappedWidth();
467 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
470 public void setWrappedWidth(int w)
472 viewStyle.setWrappedWidth(w);
477 * @see jalview.api.ViewStyleI#getCharHeight()
480 public int getCharHeight()
482 return viewStyle.getCharHeight();
487 * @see jalview.api.ViewStyleI#setCharHeight(int)
490 public void setCharHeight(int h)
492 viewStyle.setCharHeight(h);
497 * @see jalview.api.ViewStyleI#getCharWidth()
500 public int getCharWidth()
502 return viewStyle.getCharWidth();
507 * @see jalview.api.ViewStyleI#setCharWidth(int)
510 public void setCharWidth(int w)
512 viewStyle.setCharWidth(w);
517 * @see jalview.api.ViewStyleI#getShowBoxes()
520 public boolean getShowBoxes()
522 return viewStyle.getShowBoxes();
527 * @see jalview.api.ViewStyleI#getShowUnconserved()
530 public boolean getShowUnconserved()
532 return viewStyle.getShowUnconserved();
536 * @param showunconserved
537 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
540 public void setShowUnconserved(boolean showunconserved)
542 viewStyle.setShowUnconserved(showunconserved);
547 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
550 public void setSeqNameItalics(boolean default1)
552 viewStyle.setSeqNameItalics(default1);
556 * alignment displayed in the viewport. Please use get/setter
558 protected AlignmentI alignment;
561 public AlignmentI getAlignment()
567 public char getGapCharacter()
569 return alignment.getGapCharacter();
572 protected String sequenceSetID;
575 * probably unused indicator that view is of a dataset rather than an
578 protected boolean isDataset = false;
580 public void setDataset(boolean b)
585 public boolean isDataset()
590 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
592 protected ColumnSelection colSel = new ColumnSelection();
594 public boolean autoCalculateConsensus = true;
596 protected boolean autoCalculateStrucConsensus = true;
598 protected boolean ignoreGapsInConsensusCalculation = false;
600 protected ResidueShaderI residueShading;
603 public void setGlobalColourScheme(ColourSchemeI cs)
605 // TODO: logic refactored from AlignFrame changeColour -
606 // TODO: autorecalc stuff should be changed to rely on the worker system
607 // check to see if we should implement a changeColour(cs) method rather than
608 // put the logic in here
609 // - means that caller decides if they want to just modify state and defer
610 // calculation till later or to do all calculations in thread.
614 * only instantiate alignment colouring once, thereafter update it;
615 * this means that any conservation or PID threshold settings
616 * persist when the alignment colour scheme is changed
618 if (residueShading == null)
620 residueShading = new ResidueShader(viewStyle);
622 residueShading.setColourScheme(cs);
624 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
625 // ...problem: groups need these, but do not currently have a ViewStyle
629 if (getConservationSelected())
631 residueShading.setConservation(hconservation);
633 residueShading.alignmentChanged(alignment, hiddenRepSequences);
637 * if 'apply colour to all groups' is selected... do so
638 * (but don't transfer any colour threshold settings to groups)
640 if (getColourAppliesToAllGroups())
642 for (SequenceGroup sg : getAlignment().getGroups())
645 * retain any colour thresholds per group while
646 * changing choice of colour scheme (JAL-2386)
648 sg.setColourScheme(cs);
651 sg.getGroupColourScheme()
652 .alignmentChanged(sg, hiddenRepSequences);
659 public ColourSchemeI getGlobalColourScheme()
661 return residueShading == null ? null : residueShading
666 public ResidueShaderI getResidueShading()
668 return residueShading;
671 protected AlignmentAnnotation consensus;
673 protected AlignmentAnnotation complementConsensus;
675 protected AlignmentAnnotation gapcounts;
677 protected AlignmentAnnotation strucConsensus;
679 protected AlignmentAnnotation conservation;
681 protected AlignmentAnnotation quality;
683 protected AlignmentAnnotation[] groupConsensus;
685 protected AlignmentAnnotation[] groupConservation;
688 * results of alignment consensus analysis for visible portion of view
690 protected ProfilesI hconsensus = null;
693 * results of cDNA complement consensus visible portion of view
695 protected Hashtable[] hcomplementConsensus = null;
698 * results of secondary structure base pair consensus for visible portion of
701 protected Hashtable[] hStrucConsensus = null;
703 protected Conservation hconservation = null;
706 public void setConservation(Conservation cons)
708 hconservation = cons;
712 * percentage gaps allowed in a column before all amino acid properties should
713 * be considered unconserved
715 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
718 public int getConsPercGaps()
724 public void setSequenceConsensusHash(ProfilesI hconsensus)
726 this.hconsensus = hconsensus;
730 public void setComplementConsensusHash(Hashtable[] hconsensus)
732 this.hcomplementConsensus = hconsensus;
736 public ProfilesI getSequenceConsensusHash()
742 public Hashtable[] getComplementConsensusHash()
744 return hcomplementConsensus;
748 public Hashtable[] getRnaStructureConsensusHash()
750 return hStrucConsensus;
754 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
756 this.hStrucConsensus = hStrucConsensus;
761 public AlignmentAnnotation getAlignmentQualityAnnot()
767 public AlignmentAnnotation getAlignmentConservationAnnotation()
773 public AlignmentAnnotation getAlignmentConsensusAnnotation()
779 public AlignmentAnnotation getAlignmentGapAnnotation()
785 public AlignmentAnnotation getComplementConsensusAnnotation()
787 return complementConsensus;
791 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
793 return strucConsensus;
796 protected AlignCalcManagerI calculator = new AlignCalcManager();
799 * trigger update of conservation annotation
801 public void updateConservation(final AlignmentViewPanel ap)
803 // see note in mantis : issue number 8585
804 if (alignment.isNucleotide()
805 || (conservation == null && quality == null)
806 || !autoCalculateConsensus)
811 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
813 calculator.registerWorker(new jalview.workers.ConservationThread(
819 * trigger update of consensus annotation
821 public void updateConsensus(final AlignmentViewPanel ap)
823 // see note in mantis : issue number 8585
824 if ((consensus == null || gapcounts == null) || !autoCalculateConsensus)
828 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
830 calculator.registerWorker(new ConsensusThread(this, ap));
834 * A separate thread to compute cDNA consensus for a protein alignment
835 * which has mapping to cDNA
837 final AlignmentI al = this.getAlignment();
838 if (!al.isNucleotide() && al.getCodonFrames() != null
839 && !al.getCodonFrames().isEmpty())
842 * fudge - check first for protein-to-nucleotide mappings
843 * (we don't want to do this for protein-to-protein)
845 boolean doConsensus = false;
846 for (AlignedCodonFrame mapping : al.getCodonFrames())
848 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
849 MapList[] mapLists = mapping.getdnaToProt();
850 // mapLists can be empty if project load has not finished resolving seqs
851 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
860 .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null)
863 .registerWorker(new ComplementConsensusThread(this, ap));
869 // --------START Structure Conservation
870 public void updateStrucConsensus(final AlignmentViewPanel ap)
872 if (autoCalculateStrucConsensus && strucConsensus == null
873 && alignment.isNucleotide() && alignment.hasRNAStructure())
875 // secondary structure has been added - so init the consensus line
879 // see note in mantis : issue number 8585
880 if (strucConsensus == null || !autoCalculateStrucConsensus)
884 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
886 calculator.registerWorker(new StrucConsensusThread(this, ap));
890 public boolean isCalcInProgress()
892 return calculator.isWorking();
896 public boolean isCalculationInProgress(
897 AlignmentAnnotation alignmentAnnotation)
899 if (!alignmentAnnotation.autoCalculated)
903 if (calculator.workingInvolvedWith(alignmentAnnotation))
905 // System.err.println("grey out ("+alignmentAnnotation.label+")");
911 public void setAlignment(AlignmentI align)
913 this.alignment = align;
917 * Clean up references when this viewport is closed
920 public void dispose()
923 * defensively null out references to large objects in case
924 * this object is not garbage collected (as if!)
927 complementConsensus = null;
928 strucConsensus = null;
931 groupConsensus = null;
932 groupConservation = null;
934 hcomplementConsensus = null;
935 // colour scheme may hold reference to consensus
936 residueShading = null;
937 // TODO remove listeners from changeSupport?
938 changeSupport = null;
943 public boolean isClosed()
945 // TODO: check that this isClosed is only true after panel is closed, not
946 // before it is fully constructed.
947 return alignment == null;
951 public AlignCalcManagerI getCalcManager()
957 * should conservation rows be shown for groups
959 protected boolean showGroupConservation = false;
962 * should consensus rows be shown for groups
964 protected boolean showGroupConsensus = false;
967 * should consensus profile be rendered by default
969 protected boolean showSequenceLogo = false;
972 * should consensus profile be rendered normalised to row height
974 protected boolean normaliseSequenceLogo = false;
977 * should consensus histograms be rendered by default
979 protected boolean showConsensusHistogram = true;
982 * @return the showConsensusProfile
985 public boolean isShowSequenceLogo()
987 return showSequenceLogo;
991 * @param showSequenceLogo
994 public void setShowSequenceLogo(boolean showSequenceLogo)
996 if (showSequenceLogo != this.showSequenceLogo)
998 // TODO: decouple settings setting from calculation when refactoring
999 // annotation update method from alignframe to viewport
1000 this.showSequenceLogo = showSequenceLogo;
1001 calculator.updateAnnotationFor(ConsensusThread.class);
1002 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1003 calculator.updateAnnotationFor(StrucConsensusThread.class);
1005 this.showSequenceLogo = showSequenceLogo;
1009 * @param showConsensusHistogram
1010 * the showConsensusHistogram to set
1012 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1014 this.showConsensusHistogram = showConsensusHistogram;
1018 * @return the showGroupConservation
1020 public boolean isShowGroupConservation()
1022 return showGroupConservation;
1026 * @param showGroupConservation
1027 * the showGroupConservation to set
1029 public void setShowGroupConservation(boolean showGroupConservation)
1031 this.showGroupConservation = showGroupConservation;
1035 * @return the showGroupConsensus
1037 public boolean isShowGroupConsensus()
1039 return showGroupConsensus;
1043 * @param showGroupConsensus
1044 * the showGroupConsensus to set
1046 public void setShowGroupConsensus(boolean showGroupConsensus)
1048 this.showGroupConsensus = showGroupConsensus;
1053 * @return flag to indicate if the consensus histogram should be rendered by
1057 public boolean isShowConsensusHistogram()
1059 return this.showConsensusHistogram;
1063 * when set, updateAlignment will always ensure sequences are of equal length
1065 private boolean padGaps = false;
1068 * when set, alignment should be reordered according to a newly opened tree
1070 public boolean sortByTree = false;
1075 * @return null or the currently selected sequence region
1078 public SequenceGroup getSelectionGroup()
1080 return selectionGroup;
1084 * Set the selection group for this window. Also sets the current alignment as
1085 * the context for the group, if it does not already have one.
1088 * - group holding references to sequences in this alignment view
1092 public void setSelectionGroup(SequenceGroup sg)
1094 selectionGroup = sg;
1095 if (sg != null && sg.getContext() == null)
1097 sg.setContext(alignment);
1101 public void setHiddenColumns(ColumnSelection colsel)
1103 this.colSel = colsel;
1107 public ColumnSelection getColumnSelection()
1113 public void setColumnSelection(ColumnSelection colSel)
1115 this.colSel = colSel;
1118 updateHiddenColumns();
1120 isColSelChanged(true);
1128 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1130 return hiddenRepSequences;
1134 public void setHiddenRepSequences(
1135 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1137 this.hiddenRepSequences = hiddenRepSequences;
1141 public boolean hasSelectedColumns()
1143 ColumnSelection columnSelection = getColumnSelection();
1144 return columnSelection != null && columnSelection.hasSelectedColumns();
1148 public boolean hasHiddenColumns()
1150 return colSel != null && colSel.hasHiddenColumns();
1153 public void updateHiddenColumns()
1155 // this method doesn't really do anything now. But - it could, since a
1156 // column Selection could be in the process of modification
1157 // hasHiddenColumns = colSel.hasHiddenColumns();
1161 public boolean hasHiddenRows()
1163 return alignment.getHiddenSequences().getSize() > 0;
1166 protected SequenceGroup selectionGroup;
1168 public void setSequenceSetId(String newid)
1170 if (sequenceSetID != null)
1173 .println("Warning - overwriting a sequenceSetId for a viewport!");
1175 sequenceSetID = new String(newid);
1179 public String getSequenceSetId()
1181 if (sequenceSetID == null)
1183 sequenceSetID = alignment.hashCode() + "";
1186 return sequenceSetID;
1190 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1193 protected String viewId = null;
1196 public String getViewId()
1200 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1205 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1207 ignoreGapsInConsensusCalculation = b;
1210 updateConsensus(ap);
1211 if (residueShading != null)
1213 residueShading.setThreshold(residueShading.getThreshold(),
1214 ignoreGapsInConsensusCalculation);
1220 private long sgrouphash = -1, colselhash = -1;
1223 * checks current SelectionGroup against record of last hash value, and
1227 * update the record of last hash value
1229 * @return true if SelectionGroup changed since last call (when b is true)
1231 public boolean isSelectionGroupChanged(boolean b)
1233 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1234 : selectionGroup.hashCode();
1235 if (hc != -1 && hc != sgrouphash)
1247 * checks current colsel against record of last hash value, and optionally
1251 * update the record of last hash value
1252 * @return true if colsel changed since last call (when b is true)
1254 public boolean isColSelChanged(boolean b)
1256 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1257 if (hc != -1 && hc != colselhash)
1269 public boolean isIgnoreGapsConsensus()
1271 return ignoreGapsInConsensusCalculation;
1274 // property change stuff
1275 // JBPNote Prolly only need this in the applet version.
1276 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1279 protected boolean showConservation = true;
1281 protected boolean showQuality = true;
1283 protected boolean showConsensus = true;
1285 private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
1287 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1289 protected boolean showAutocalculatedAbove;
1292 * when set, view will scroll to show the highlighted position
1294 private boolean followHighlight = true;
1296 // TODO private with getters and setters?
1297 public int startRes;
1301 public int startSeq;
1306 * Property change listener for changes in alignment
1311 public void addPropertyChangeListener(
1312 java.beans.PropertyChangeListener listener)
1314 changeSupport.addPropertyChangeListener(listener);
1323 public void removePropertyChangeListener(
1324 java.beans.PropertyChangeListener listener)
1326 changeSupport.removePropertyChangeListener(listener);
1330 * Property change listener for changes in alignment
1339 public void firePropertyChange(String prop, Object oldvalue,
1342 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1345 // common hide/show column stuff
1347 public void hideSelectedColumns()
1349 if (colSel.isEmpty())
1354 colSel.hideSelectedColumns();
1355 setSelectionGroup(null);
1356 isColSelChanged(true);
1359 public void hideColumns(int start, int end)
1363 colSel.hideColumns(start);
1367 colSel.hideColumns(start, end);
1369 isColSelChanged(true);
1372 public void showColumn(int col)
1374 colSel.revealHiddenColumns(col);
1375 isColSelChanged(true);
1378 public void showAllHiddenColumns()
1380 colSel.revealAllHiddenColumns();
1381 isColSelChanged(true);
1384 // common hide/show seq stuff
1385 public void showAllHiddenSeqs()
1387 if (alignment.getHiddenSequences().getSize() > 0)
1389 if (selectionGroup == null)
1391 selectionGroup = new SequenceGroup();
1392 selectionGroup.setEndRes(alignment.getWidth() - 1);
1394 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1395 hiddenRepSequences);
1396 for (SequenceI seq : tmp)
1398 selectionGroup.addSequence(seq, false);
1399 setSequenceAnnotationsVisible(seq, true);
1402 hiddenRepSequences = null;
1404 firePropertyChange("alignment", null, alignment.getSequences());
1405 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1411 public void showSequence(int index)
1413 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1414 index, hiddenRepSequences);
1417 if (selectionGroup == null)
1419 selectionGroup = new SequenceGroup();
1420 selectionGroup.setEndRes(alignment.getWidth() - 1);
1423 for (SequenceI seq : tmp)
1425 selectionGroup.addSequence(seq, false);
1426 setSequenceAnnotationsVisible(seq, true);
1428 firePropertyChange("alignment", null, alignment.getSequences());
1433 public void hideAllSelectedSeqs()
1435 if (selectionGroup == null || selectionGroup.getSize() < 1)
1440 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1444 setSelectionGroup(null);
1447 public void hideSequence(SequenceI[] seq)
1451 for (int i = 0; i < seq.length; i++)
1453 alignment.getHiddenSequences().hideSequence(seq[i]);
1454 setSequenceAnnotationsVisible(seq[i], false);
1456 firePropertyChange("alignment", null, alignment.getSequences());
1461 * Hides the specified sequence, or the sequences it represents
1464 * the sequence to hide, or keep as representative
1465 * @param representGroup
1466 * if true, hide the current selection group except for the
1467 * representative sequence
1469 public void hideSequences(SequenceI sequence, boolean representGroup)
1471 if (selectionGroup == null || selectionGroup.getSize() < 1)
1473 hideSequence(new SequenceI[] { sequence });
1479 hideRepSequences(sequence, selectionGroup);
1480 setSelectionGroup(null);
1484 int gsize = selectionGroup.getSize();
1485 SequenceI[] hseqs = selectionGroup.getSequences().toArray(
1486 new SequenceI[gsize]);
1488 hideSequence(hseqs);
1489 setSelectionGroup(null);
1494 * Set visibility for any annotations for the given sequence.
1498 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1501 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1504 for (AlignmentAnnotation ann : anns)
1506 if (ann.sequenceRef == sequenceI)
1508 ann.visible = visible;
1514 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1516 int sSize = sg.getSize();
1522 if (hiddenRepSequences == null)
1524 hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
1527 hiddenRepSequences.put(repSequence, sg);
1529 // Hide all sequences except the repSequence
1530 SequenceI[] seqs = new SequenceI[sSize - 1];
1532 for (int i = 0; i < sSize; i++)
1534 if (sg.getSequenceAt(i) != repSequence)
1536 if (index == sSize - 1)
1541 seqs[index++] = sg.getSequenceAt(i);
1544 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1545 sg.setHidereps(true); // note: not done in 2.7applet
1552 * @return null or the current reference sequence
1554 public SequenceI getReferenceSeq()
1556 return alignment.getSeqrep();
1561 * @return true iff seq is the reference for the alignment
1563 public boolean isReferenceSeq(SequenceI seq)
1565 return alignment.getSeqrep() == seq;
1571 * @return true if there are sequences represented by this sequence that are
1574 public boolean isHiddenRepSequence(SequenceI seq)
1576 return (hiddenRepSequences != null && hiddenRepSequences
1583 * @return null or a sequence group containing the sequences that seq
1586 public SequenceGroup getRepresentedSequences(SequenceI seq)
1588 return (SequenceGroup) (hiddenRepSequences == null ? null
1589 : hiddenRepSequences.get(seq));
1593 public int adjustForHiddenSeqs(int alignmentIndex)
1595 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1600 public void invertColumnSelection()
1602 colSel.invertColumnSelection(0, alignment.getWidth());
1606 public SequenceI[] getSelectionAsNewSequence()
1608 SequenceI[] sequences;
1609 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1610 // this was the only caller in the applet for this method
1611 // JBPNote: in applet, this method returned references to the alignment
1612 // sequences, and it did not honour the presence/absence of annotation
1613 // attached to the alignment (probably!)
1614 if (selectionGroup == null || selectionGroup.getSize() == 0)
1616 sequences = alignment.getSequencesArray();
1617 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1618 for (int i = 0; i < sequences.length; i++)
1620 // construct new sequence with subset of visible annotation
1621 sequences[i] = new Sequence(sequences[i], annots);
1626 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1633 public SequenceI[] getSequenceSelection()
1635 SequenceI[] sequences = null;
1636 if (selectionGroup != null)
1638 sequences = selectionGroup.getSequencesInOrder(alignment);
1640 if (sequences == null)
1642 sequences = alignment.getSequencesArray();
1648 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1650 return new CigarArray(alignment, colSel,
1651 (selectedRegionOnly ? selectionGroup : null));
1655 public jalview.datamodel.AlignmentView getAlignmentView(
1656 boolean selectedOnly)
1658 return getAlignmentView(selectedOnly, false);
1662 public jalview.datamodel.AlignmentView getAlignmentView(
1663 boolean selectedOnly, boolean markGroups)
1665 return new AlignmentView(alignment, colSel, selectionGroup,
1666 colSel != null && colSel.hasHiddenColumns(), selectedOnly,
1671 public String[] getViewAsString(boolean selectedRegionOnly)
1673 return getViewAsString(selectedRegionOnly, true);
1677 public String[] getViewAsString(boolean selectedRegionOnly,
1678 boolean exportHiddenSeqs)
1680 String[] selection = null;
1681 SequenceI[] seqs = null;
1683 int start = 0, end = 0;
1684 if (selectedRegionOnly && selectionGroup != null)
1686 iSize = selectionGroup.getSize();
1687 seqs = selectionGroup.getSequencesInOrder(alignment);
1688 start = selectionGroup.getStartRes();
1689 end = selectionGroup.getEndRes() + 1;
1693 if (hasHiddenRows() && exportHiddenSeqs)
1695 AlignmentI fullAlignment = alignment.getHiddenSequences()
1696 .getFullAlignment();
1697 iSize = fullAlignment.getHeight();
1698 seqs = fullAlignment.getSequencesArray();
1699 end = fullAlignment.getWidth();
1703 iSize = alignment.getHeight();
1704 seqs = alignment.getSequencesArray();
1705 end = alignment.getWidth();
1709 selection = new String[iSize];
1710 if (colSel != null && colSel.hasHiddenColumns())
1712 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1716 for (i = 0; i < iSize; i++)
1718 selection[i] = seqs[i].getSequenceAsString(start, end);
1726 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1728 ArrayList<int[]> regions = new ArrayList<int[]>();
1734 if (colSel != null && colSel.hasHiddenColumns())
1738 start = colSel.adjustForHiddenColumns(start);
1741 end = colSel.getHiddenBoundaryRight(start);
1752 regions.add(new int[] { start, end });
1754 if (colSel != null && colSel.hasHiddenColumns())
1756 start = colSel.adjustForHiddenColumns(end);
1757 start = colSel.getHiddenBoundaryLeft(start) + 1;
1759 } while (end < max);
1761 int[][] startEnd = new int[regions.size()][2];
1767 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1768 boolean selectedOnly)
1770 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1771 AlignmentAnnotation[] aa;
1772 if ((aa = alignment.getAlignmentAnnotation()) != null)
1774 for (AlignmentAnnotation annot : aa)
1776 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1777 if (selectedOnly && selectionGroup != null)
1779 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(),
1780 selectionGroup.getEndRes(), clone);
1784 colSel.makeVisibleAnnotation(clone);
1793 public boolean isPadGaps()
1799 public void setPadGaps(boolean padGaps)
1801 this.padGaps = padGaps;
1805 * apply any post-edit constraints and trigger any calculations needed after
1806 * an edit has been performed on the alignment
1811 public void alignmentChanged(AlignmentViewPanel ap)
1815 alignment.padGaps();
1817 if (autoCalculateConsensus)
1819 updateConsensus(ap);
1821 if (hconsensus != null && autoCalculateConsensus)
1823 updateConservation(ap);
1825 if (autoCalculateStrucConsensus)
1827 updateStrucConsensus(ap);
1830 // Reset endRes of groups if beyond alignment width
1831 int alWidth = alignment.getWidth();
1832 List<SequenceGroup> groups = alignment.getGroups();
1835 for (SequenceGroup sg : groups)
1837 if (sg.getEndRes() > alWidth)
1839 sg.setEndRes(alWidth - 1);
1844 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1846 selectionGroup.setEndRes(alWidth - 1);
1849 updateAllColourSchemes();
1850 calculator.restartWorkers();
1851 // alignment.adjustSequenceAnnotations();
1855 * reset scope and do calculations for all applied colourschemes on alignment
1857 void updateAllColourSchemes()
1859 ResidueShaderI rs = residueShading;
1862 rs.alignmentChanged(alignment, hiddenRepSequences);
1864 rs.setConsensus(hconsensus);
1865 if (rs.conservationApplied())
1867 rs.setConservation(Conservation.calculateConservation("All",
1868 alignment.getSequences(), 0, alignment.getWidth(), false,
1869 getConsPercGaps(), false));
1873 for (SequenceGroup sg : alignment.getGroups())
1877 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1879 sg.recalcConservation();
1883 protected void initAutoAnnotation()
1885 // TODO: add menu option action that nulls or creates consensus object
1886 // depending on if the user wants to see the annotation or not in a
1887 // specific alignment
1889 if (hconsensus == null && !isDataset)
1891 if (!alignment.isNucleotide())
1900 consensus = new AlignmentAnnotation("Consensus", "PID",
1901 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1902 initConsensus(consensus);
1903 gapcounts = new AlignmentAnnotation("Occupancy",
1904 "Number of aligned positions",
1905 new Annotation[1], 0f, alignment.getHeight(),
1906 AlignmentAnnotation.BAR_GRAPH);
1907 initGapCounts(gapcounts);
1909 initComplementConsensus();
1914 * If this is a protein alignment and there are mappings to cDNA, add the cDNA
1915 * consensus annotation.
1917 public void initComplementConsensus()
1919 if (!alignment.isNucleotide())
1921 final List<AlignedCodonFrame> codonMappings = alignment
1923 if (codonMappings != null && !codonMappings.isEmpty())
1925 boolean doConsensus = false;
1926 for (AlignedCodonFrame mapping : codonMappings)
1928 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1929 MapList[] mapLists = mapping.getdnaToProt();
1930 // mapLists can be empty if project load has not finished resolving
1932 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1940 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1941 "PID for cDNA", new Annotation[1], 0f, 100f,
1942 AlignmentAnnotation.BAR_GRAPH);
1943 initConsensus(complementConsensus);
1949 private void initConsensus(AlignmentAnnotation aa)
1952 aa.autoCalculated = true;
1956 alignment.addAnnotation(aa);
1960 // these should be extracted from the view model - style and settings for
1961 // derived annotation
1962 private void initGapCounts(AlignmentAnnotation counts)
1964 counts.hasText = false;
1965 counts.autoCalculated = true;
1966 counts.graph = AlignmentAnnotation.BAR_GRAPH;
1970 alignment.addAnnotation(counts);
1974 private void initConservation()
1976 if (showConservation)
1978 if (conservation == null)
1980 conservation = new AlignmentAnnotation("Conservation",
1981 "Conservation of total alignment less than "
1982 + getConsPercGaps() + "% gaps", new Annotation[1],
1983 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1984 conservation.hasText = true;
1985 conservation.autoCalculated = true;
1986 alignment.addAnnotation(conservation);
1991 private void initQuality()
1995 if (quality == null)
1997 quality = new AlignmentAnnotation("Quality",
1998 "Alignment Quality based on Blosum62 scores",
1999 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2000 quality.hasText = true;
2001 quality.autoCalculated = true;
2002 alignment.addAnnotation(quality);
2007 private void initRNAStructure()
2009 if (alignment.hasRNAStructure() && strucConsensus == null)
2011 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
2012 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2013 strucConsensus.hasText = true;
2014 strucConsensus.autoCalculated = true;
2018 alignment.addAnnotation(strucConsensus);
2026 * @see jalview.api.AlignViewportI#calcPanelHeight()
2029 public int calcPanelHeight()
2031 // setHeight of panels
2032 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2034 int charHeight = getCharHeight();
2037 BitSet graphgrp = new BitSet();
2038 for (AlignmentAnnotation aa : anns)
2042 System.err.println("Null annotation row: ignoring.");
2049 if (aa.graphGroup > -1)
2051 if (graphgrp.get(aa.graphGroup))
2057 graphgrp.set(aa.graphGroup);
2064 aa.height += charHeight;
2074 aa.height += aa.graphHeight;
2082 height += aa.height;
2094 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2095 boolean preserveNewGroupSettings)
2097 boolean updateCalcs = false;
2098 boolean conv = isShowGroupConservation();
2099 boolean cons = isShowGroupConsensus();
2100 boolean showprf = isShowSequenceLogo();
2101 boolean showConsHist = isShowConsensusHistogram();
2102 boolean normLogo = isNormaliseSequenceLogo();
2105 * TODO reorder the annotation rows according to group/sequence ordering on
2108 boolean sortg = true;
2110 // remove old automatic annotation
2111 // add any new annotation
2113 // intersect alignment annotation with alignment groups
2115 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2116 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
2119 for (int an = 0; an < aan.length; an++)
2121 if (aan[an].autoCalculated && aan[an].groupRef != null)
2123 oldrfs.add(aan[an].groupRef);
2124 alignment.deleteAnnotation(aan[an], false);
2128 if (alignment.getGroups() != null)
2130 for (SequenceGroup sg : alignment.getGroups())
2132 updateCalcs = false;
2133 if (applyGlobalSettings
2134 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2136 // set defaults for this group's conservation/consensus
2137 sg.setshowSequenceLogo(showprf);
2138 sg.setShowConsensusHistogram(showConsHist);
2139 sg.setNormaliseSequenceLogo(normLogo);
2144 alignment.addAnnotation(sg.getConservationRow(), 0);
2149 alignment.addAnnotation(sg.getConsensus(), 0);
2151 // refresh the annotation rows
2154 sg.recalcConservation();
2162 public boolean isDisplayReferenceSeq()
2164 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2168 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2170 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2174 public boolean isColourByReferenceSeq()
2176 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2180 public Color getSequenceColour(SequenceI seq)
2182 Color sqc = sequenceColours.get(seq);
2183 return (sqc == null ? Color.white : sqc);
2187 public void setSequenceColour(SequenceI seq, Color col)
2191 sequenceColours.remove(seq);
2195 sequenceColours.put(seq, col);
2200 public void updateSequenceIdColours()
2202 for (SequenceGroup sg : alignment.getGroups())
2204 if (sg.idColour != null)
2206 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2208 sequenceColours.put(s, sg.idColour);
2215 public void clearSequenceColours()
2217 sequenceColours.clear();
2221 public AlignViewportI getCodingComplement()
2223 return this.codingComplement;
2227 * Set this as the (cDna/protein) complement of the given viewport. Also
2228 * ensures the reverse relationship is set on the given viewport.
2231 public void setCodingComplement(AlignViewportI av)
2235 System.err.println("Ignoring recursive setCodingComplement request");
2239 this.codingComplement = av;
2240 // avoid infinite recursion!
2241 if (av.getCodingComplement() != this)
2243 av.setCodingComplement(this);
2249 public boolean isNucleotide()
2251 return getAlignment() == null ? false : getAlignment().isNucleotide();
2255 public FeaturesDisplayedI getFeaturesDisplayed()
2257 return featuresDisplayed;
2261 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2263 featuresDisplayed = featuresDisplayedI;
2267 public boolean areFeaturesDisplayed()
2269 return featuresDisplayed != null
2270 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2277 * features are displayed if true
2280 public void setShowSequenceFeatures(boolean b)
2282 viewStyle.setShowSequenceFeatures(b);
2286 public boolean isShowSequenceFeatures()
2288 return viewStyle.isShowSequenceFeatures();
2292 public void setShowSequenceFeaturesHeight(boolean selected)
2294 viewStyle.setShowSequenceFeaturesHeight(selected);
2298 public boolean isShowSequenceFeaturesHeight()
2300 return viewStyle.isShowSequenceFeaturesHeight();
2304 public void setShowAnnotation(boolean b)
2306 viewStyle.setShowAnnotation(b);
2310 public boolean isShowAnnotation()
2312 return viewStyle.isShowAnnotation();
2316 public boolean isRightAlignIds()
2318 return viewStyle.isRightAlignIds();
2322 public void setRightAlignIds(boolean rightAlignIds)
2324 viewStyle.setRightAlignIds(rightAlignIds);
2328 public boolean getConservationSelected()
2330 return viewStyle.getConservationSelected();
2334 public void setShowBoxes(boolean state)
2336 viewStyle.setShowBoxes(state);
2341 * @see jalview.api.ViewStyleI#getTextColour()
2344 public Color getTextColour()
2346 return viewStyle.getTextColour();
2351 * @see jalview.api.ViewStyleI#getTextColour2()
2354 public Color getTextColour2()
2356 return viewStyle.getTextColour2();
2361 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2364 public int getThresholdTextColour()
2366 return viewStyle.getThresholdTextColour();
2371 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2374 public boolean isConservationColourSelected()
2376 return viewStyle.isConservationColourSelected();
2381 * @see jalview.api.ViewStyleI#isRenderGaps()
2384 public boolean isRenderGaps()
2386 return viewStyle.isRenderGaps();
2391 * @see jalview.api.ViewStyleI#isShowColourText()
2394 public boolean isShowColourText()
2396 return viewStyle.isShowColourText();
2400 * @param conservationColourSelected
2401 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2404 public void setConservationColourSelected(
2405 boolean conservationColourSelected)
2407 viewStyle.setConservationColourSelected(conservationColourSelected);
2411 * @param showColourText
2412 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2415 public void setShowColourText(boolean showColourText)
2417 viewStyle.setShowColourText(showColourText);
2422 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2425 public void setTextColour(Color textColour)
2427 viewStyle.setTextColour(textColour);
2431 * @param thresholdTextColour
2432 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2435 public void setThresholdTextColour(int thresholdTextColour)
2437 viewStyle.setThresholdTextColour(thresholdTextColour);
2441 * @param textColour2
2442 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2445 public void setTextColour2(Color textColour2)
2447 viewStyle.setTextColour2(textColour2);
2451 public ViewStyleI getViewStyle()
2453 return new ViewStyle(viewStyle);
2457 public void setViewStyle(ViewStyleI settingsForView)
2459 viewStyle = new ViewStyle(settingsForView);
2460 if (residueShading != null)
2462 residueShading.setConservationApplied(settingsForView
2463 .isConservationColourSelected());
2468 public boolean sameStyle(ViewStyleI them)
2470 return viewStyle.sameStyle(them);
2475 * @see jalview.api.ViewStyleI#getIdWidth()
2478 public int getIdWidth()
2480 return viewStyle.getIdWidth();
2485 * @see jalview.api.ViewStyleI#setIdWidth(int)
2488 public void setIdWidth(int i)
2490 viewStyle.setIdWidth(i);
2495 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2498 public boolean isCentreColumnLabels()
2500 return viewStyle.isCentreColumnLabels();
2504 * @param centreColumnLabels
2505 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2508 public void setCentreColumnLabels(boolean centreColumnLabels)
2510 viewStyle.setCentreColumnLabels(centreColumnLabels);
2515 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2518 public void setShowDBRefs(boolean showdbrefs)
2520 viewStyle.setShowDBRefs(showdbrefs);
2525 * @see jalview.api.ViewStyleI#isShowDBRefs()
2528 public boolean isShowDBRefs()
2530 return viewStyle.isShowDBRefs();
2535 * @see jalview.api.ViewStyleI#isShowNPFeats()
2538 public boolean isShowNPFeats()
2540 return viewStyle.isShowNPFeats();
2544 * @param shownpfeats
2545 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2548 public void setShowNPFeats(boolean shownpfeats)
2550 viewStyle.setShowNPFeats(shownpfeats);
2553 public abstract StructureSelectionManager getStructureSelectionManager();
2556 * Add one command to the command history list.
2560 public void addToHistoryList(CommandI command)
2562 if (this.historyList != null)
2564 this.historyList.push(command);
2565 broadcastCommand(command, false);
2569 protected void broadcastCommand(CommandI command, boolean undo)
2571 getStructureSelectionManager().commandPerformed(command, undo,
2576 * Add one command to the command redo list.
2580 public void addToRedoList(CommandI command)
2582 if (this.redoList != null)
2584 this.redoList.push(command);
2586 broadcastCommand(command, true);
2590 * Clear the command redo list.
2592 public void clearRedoList()
2594 if (this.redoList != null)
2596 this.redoList.clear();
2600 public void setHistoryList(Deque<CommandI> list)
2602 this.historyList = list;
2605 public Deque<CommandI> getHistoryList()
2607 return this.historyList;
2610 public void setRedoList(Deque<CommandI> list)
2612 this.redoList = list;
2615 public Deque<CommandI> getRedoList()
2617 return this.redoList;
2621 public VamsasSource getVamsasSource()
2626 public SequenceAnnotationOrder getSortAnnotationsBy()
2628 return sortAnnotationsBy;
2631 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2633 this.sortAnnotationsBy = sortAnnotationsBy;
2636 public boolean isShowAutocalculatedAbove()
2638 return showAutocalculatedAbove;
2641 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2643 this.showAutocalculatedAbove = showAutocalculatedAbove;
2647 public boolean isScaleProteinAsCdna()
2649 return viewStyle.isScaleProteinAsCdna();
2653 public void setScaleProteinAsCdna(boolean b)
2655 viewStyle.setScaleProteinAsCdna(b);
2659 * @return true if view should scroll to show the highlighted region of a
2664 public final boolean isFollowHighlight()
2666 return followHighlight;
2670 public final void setFollowHighlight(boolean b)
2672 this.followHighlight = b;
2675 public int getStartRes()
2681 public int getEndRes()
2686 public int getStartSeq()
2691 public void setStartRes(int res)
2693 this.startRes = res;
2696 public void setStartSeq(int seq)
2698 this.startSeq = seq;
2701 public void setEndRes(int res)
2703 if (res > alignment.getWidth() - 1)
2705 // log.System.out.println(" Corrected res from " + res + " to maximum " +
2706 // (alignment.getWidth()-1));
2707 res = alignment.getWidth() - 1;
2716 public void setEndSeq(int seq)
2718 if (seq > alignment.getHeight())
2720 seq = alignment.getHeight();
2729 public int getEndSeq()
2735 * Helper method to populate the SearchResults with the location in the
2736 * complementary alignment to scroll to, in order to match this one.
2739 * the SearchResults to add to
2740 * @return the offset (below top of visible region) of the matched sequence
2742 protected int findComplementScrollTarget(SearchResultsI sr)
2744 final AlignViewportI complement = getCodingComplement();
2745 if (complement == null || !complement.isFollowHighlight())
2749 boolean iAmProtein = !getAlignment().isNucleotide();
2750 AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement
2752 if (proteinAlignment == null)
2756 final List<AlignedCodonFrame> mappings = proteinAlignment
2760 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2761 * residue in the middle column of the visible region. Scroll the
2762 * complementary alignment to line up the corresponding residue.
2765 SequenceI sequence = null;
2768 * locate 'middle' column (true middle if an odd number visible, left of
2769 * middle if an even number visible)
2771 int middleColumn = getStartRes() + (getEndRes() - getStartRes()) / 2;
2772 final HiddenSequences hiddenSequences = getAlignment()
2773 .getHiddenSequences();
2776 * searching to the bottom of the alignment gives smoother scrolling across
2777 * all gapped visible regions
2779 int lastSeq = alignment.getHeight() - 1;
2780 List<AlignedCodonFrame> seqMappings = null;
2781 for (int seqNo = getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2783 sequence = getAlignment().getSequenceAt(seqNo);
2784 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2788 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2792 seqMappings = MappingUtils
2793 .findMappingsForSequenceAndOthers(sequence, mappings,
2794 getCodingComplement().getAlignment().getSequences());
2795 if (!seqMappings.isEmpty())
2801 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2804 * No ungapped mapped sequence in middle column - do nothing
2808 MappingUtils.addSearchResults(sr, sequence,
2809 sequence.findPosition(middleColumn), seqMappings);
2814 * synthesize a column selection if none exists so it covers the given
2815 * selection group. if wholewidth is false, no column selection is made if the
2816 * selection group covers the whole alignment width.
2821 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2824 if (sg != null && (sgs = sg.getStartRes()) >= 0
2825 && sg.getStartRes() <= (sge = sg.getEndRes())
2826 && !this.hasSelectedColumns())
2828 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2835 colSel = new ColumnSelection();
2837 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2839 colSel.addElement(cspos);
2845 * hold status of current selection group - defined on alignment or not.
2847 private boolean selectionIsDefinedGroup = false;
2850 public boolean isSelectionDefinedGroup()
2852 if (selectionGroup == null)
2856 if (isSelectionGroupChanged(true))
2858 selectionIsDefinedGroup = false;
2859 List<SequenceGroup> gps = alignment.getGroups();
2860 if (gps == null || gps.size() == 0)
2862 selectionIsDefinedGroup = false;
2866 selectionIsDefinedGroup = gps.contains(selectionGroup);
2869 return selectionGroup.getContext() == alignment
2870 || selectionIsDefinedGroup;
2874 * null, or currently highlighted results on this view
2876 private SearchResultsI searchResults = null;
2879 public boolean hasSearchResults()
2881 return searchResults != null;
2885 public void setSearchResults(SearchResultsI results)
2887 searchResults = results;
2891 public SearchResultsI getSearchResults()
2893 return searchResults;