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.HiddenSequences;
39 import jalview.datamodel.ProfilesI;
40 import jalview.datamodel.SearchResultsI;
41 import jalview.datamodel.Sequence;
42 import jalview.datamodel.SequenceCollectionI;
43 import jalview.datamodel.SequenceGroup;
44 import jalview.datamodel.SequenceI;
45 import jalview.schemes.Blosum62ColourScheme;
46 import jalview.schemes.CollectionColourScheme;
47 import jalview.schemes.CollectionColourSchemeI;
48 import jalview.schemes.ColourSchemeI;
49 import jalview.schemes.PIDColourScheme;
50 import jalview.structure.CommandListener;
51 import jalview.structure.StructureSelectionManager;
52 import jalview.structure.VamsasSource;
53 import jalview.util.Comparison;
54 import jalview.util.MapList;
55 import jalview.util.MappingUtils;
56 import jalview.viewmodel.styles.ViewStyle;
57 import jalview.workers.AlignCalcManager;
58 import jalview.workers.ComplementConsensusThread;
59 import jalview.workers.ConsensusThread;
60 import jalview.workers.StrucConsensusThread;
62 import java.awt.Color;
63 import java.beans.PropertyChangeSupport;
64 import java.util.ArrayDeque;
65 import java.util.ArrayList;
66 import java.util.BitSet;
67 import java.util.Deque;
68 import java.util.HashMap;
69 import java.util.Hashtable;
70 import java.util.List;
74 * base class holding visualization and analysis attributes and common logic for
75 * an active alignment view displayed in the GUI
80 public abstract class AlignmentViewport implements AlignViewportI,
81 CommandListener, VamsasSource
83 protected ViewStyleI viewStyle = new ViewStyle();
86 * A viewport that hosts the cDna view of this (protein), or vice versa (if
89 AlignViewportI codingComplement = null;
91 FeaturesDisplayedI featuresDisplayed = null;
93 protected Deque<CommandI> historyList = new ArrayDeque<CommandI>();
95 protected Deque<CommandI> redoList = new ArrayDeque<CommandI>();
99 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
102 public void setFontName(String name)
104 viewStyle.setFontName(name);
109 * @see jalview.api.ViewStyleI#setFontStyle(int)
112 public void setFontStyle(int style)
114 viewStyle.setFontStyle(style);
119 * @see jalview.api.ViewStyleI#setFontSize(int)
122 public void setFontSize(int size)
124 viewStyle.setFontSize(size);
129 * @see jalview.api.ViewStyleI#getFontStyle()
132 public int getFontStyle()
134 return viewStyle.getFontStyle();
139 * @see jalview.api.ViewStyleI#getFontName()
142 public String getFontName()
144 return viewStyle.getFontName();
149 * @see jalview.api.ViewStyleI#getFontSize()
152 public int getFontSize()
154 return viewStyle.getFontSize();
158 * @param upperCasebold
159 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
162 public void setUpperCasebold(boolean upperCasebold)
164 viewStyle.setUpperCasebold(upperCasebold);
169 * @see jalview.api.ViewStyleI#isUpperCasebold()
172 public boolean isUpperCasebold()
174 return viewStyle.isUpperCasebold();
179 * @see jalview.api.ViewStyleI#isSeqNameItalics()
182 public boolean isSeqNameItalics()
184 return viewStyle.isSeqNameItalics();
188 * @param colourByReferenceSeq
189 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
192 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
194 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
199 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
202 public void setColourAppliesToAllGroups(boolean b)
204 viewStyle.setColourAppliesToAllGroups(b);
209 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
212 public boolean getColourAppliesToAllGroups()
214 return viewStyle.getColourAppliesToAllGroups();
219 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
222 public boolean getAbovePIDThreshold()
224 return viewStyle.getAbovePIDThreshold();
229 * @see jalview.api.ViewStyleI#setIncrement(int)
232 public void setIncrement(int inc)
234 viewStyle.setIncrement(inc);
239 * @see jalview.api.ViewStyleI#getIncrement()
242 public int getIncrement()
244 return viewStyle.getIncrement();
249 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
252 public void setConservationSelected(boolean b)
254 viewStyle.setConservationSelected(b);
259 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
262 public void setShowHiddenMarkers(boolean show)
264 viewStyle.setShowHiddenMarkers(show);
269 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
272 public boolean getShowHiddenMarkers()
274 return viewStyle.getShowHiddenMarkers();
279 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
282 public void setScaleRightWrapped(boolean b)
284 viewStyle.setScaleRightWrapped(b);
289 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
292 public void setScaleLeftWrapped(boolean b)
294 viewStyle.setScaleLeftWrapped(b);
299 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
302 public void setScaleAboveWrapped(boolean b)
304 viewStyle.setScaleAboveWrapped(b);
309 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
312 public boolean getScaleLeftWrapped()
314 return viewStyle.getScaleLeftWrapped();
319 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
322 public boolean getScaleAboveWrapped()
324 return viewStyle.getScaleAboveWrapped();
329 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
332 public boolean getScaleRightWrapped()
334 return viewStyle.getScaleRightWrapped();
339 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
342 public void setAbovePIDThreshold(boolean b)
344 viewStyle.setAbovePIDThreshold(b);
349 * @see jalview.api.ViewStyleI#setThreshold(int)
352 public void setThreshold(int thresh)
354 viewStyle.setThreshold(thresh);
359 * @see jalview.api.ViewStyleI#getThreshold()
362 public int getThreshold()
364 return viewStyle.getThreshold();
369 * @see jalview.api.ViewStyleI#getShowJVSuffix()
372 public boolean getShowJVSuffix()
374 return viewStyle.getShowJVSuffix();
379 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
382 public void setShowJVSuffix(boolean b)
384 viewStyle.setShowJVSuffix(b);
389 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
392 public void setWrapAlignment(boolean state)
394 viewStyle.setWrapAlignment(state);
399 * @see jalview.api.ViewStyleI#setShowText(boolean)
402 public void setShowText(boolean state)
404 viewStyle.setShowText(state);
409 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
412 public void setRenderGaps(boolean state)
414 viewStyle.setRenderGaps(state);
419 * @see jalview.api.ViewStyleI#getColourText()
422 public boolean getColourText()
424 return viewStyle.getColourText();
429 * @see jalview.api.ViewStyleI#setColourText(boolean)
432 public void setColourText(boolean state)
434 viewStyle.setColourText(state);
439 * @see jalview.api.ViewStyleI#getWrapAlignment()
442 public boolean getWrapAlignment()
444 return viewStyle.getWrapAlignment();
449 * @see jalview.api.ViewStyleI#getShowText()
452 public boolean getShowText()
454 return viewStyle.getShowText();
459 * @see jalview.api.ViewStyleI#getWrappedWidth()
462 public int getWrappedWidth()
464 return viewStyle.getWrappedWidth();
469 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
472 public void setWrappedWidth(int w)
474 viewStyle.setWrappedWidth(w);
479 * @see jalview.api.ViewStyleI#getCharHeight()
482 public int getCharHeight()
484 return viewStyle.getCharHeight();
489 * @see jalview.api.ViewStyleI#setCharHeight(int)
492 public void setCharHeight(int h)
494 viewStyle.setCharHeight(h);
499 * @see jalview.api.ViewStyleI#getCharWidth()
502 public int getCharWidth()
504 return viewStyle.getCharWidth();
509 * @see jalview.api.ViewStyleI#setCharWidth(int)
512 public void setCharWidth(int w)
514 viewStyle.setCharWidth(w);
519 * @see jalview.api.ViewStyleI#getShowBoxes()
522 public boolean getShowBoxes()
524 return viewStyle.getShowBoxes();
529 * @see jalview.api.ViewStyleI#getShowUnconserved()
532 public boolean getShowUnconserved()
534 return viewStyle.getShowUnconserved();
538 * @param showunconserved
539 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
542 public void setShowUnconserved(boolean showunconserved)
544 viewStyle.setShowUnconserved(showunconserved);
549 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
552 public void setSeqNameItalics(boolean default1)
554 viewStyle.setSeqNameItalics(default1);
558 * alignment displayed in the viewport. Please use get/setter
560 protected AlignmentI alignment;
563 public AlignmentI getAlignment()
569 public char getGapCharacter()
571 return alignment.getGapCharacter();
574 protected String sequenceSetID;
577 * probably unused indicator that view is of a dataset rather than an
580 protected boolean isDataset = false;
582 public void setDataset(boolean b)
587 public boolean isDataset()
592 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
594 protected ColumnSelection colSel = new ColumnSelection();
596 public boolean autoCalculateConsensus = true;
598 protected boolean autoCalculateStrucConsensus = true;
600 protected boolean ignoreGapsInConsensusCalculation = false;
602 protected CollectionColourSchemeI globalColourScheme;
605 public void setGlobalColourScheme(ColourSchemeI cs)
607 // TODO: logic refactored from AlignFrame changeColour -
608 // TODO: autorecalc stuff should be changed to rely on the worker system
609 // check to see if we should implement a changeColour(cs) method rather than
610 // put th logic in here
611 // - means that caller decides if they want to just modify state and defer
612 // calculation till later or to do all calculations in thread.
616 * only instantiate colour scheme once, thereafter update it
617 * this means that any conservation or PID threshold settings
618 * persist when the alignment colour scheme is changed
620 if (globalColourScheme == null)
622 globalColourScheme = new CollectionColourScheme();
624 globalColourScheme.setColourScheme(cs);
626 // boolean recalc = false;
627 // TODO: do threshold and increment belong in ViewStyle or colour scheme?
628 // problem: groups need this but do not currently have a ViewStyle
632 if (getConservationSelected() || getAbovePIDThreshold()
633 || cs instanceof PIDColourScheme
634 || cs instanceof Blosum62ColourScheme)
636 globalColourScheme.setConservation(hconservation);
638 globalColourScheme.alignmentChanged(alignment, hiddenRepSequences);
642 * if 'apply colour to all groups' is selected... do so
643 * (but don't transfer any colour threshold settings to groups)
645 if (getColourAppliesToAllGroups())
647 for (SequenceGroup sg : getAlignment().getGroups())
650 * retain any colour thresholds per group while
651 * changing choice of colour scheme (JAL-2386)
653 sg.setColourScheme(cs);
656 sg.getGroupColourScheme()
657 .alignmentChanged(sg, hiddenRepSequences);
664 public ColourSchemeI getGlobalColourScheme()
666 return globalColourScheme == null ? null : globalColourScheme
671 public CollectionColourSchemeI getViewportColourScheme()
673 return globalColourScheme;
676 protected AlignmentAnnotation consensus;
678 protected AlignmentAnnotation complementConsensus;
680 protected AlignmentAnnotation strucConsensus;
682 protected AlignmentAnnotation conservation;
684 protected AlignmentAnnotation quality;
686 protected AlignmentAnnotation[] groupConsensus;
688 protected AlignmentAnnotation[] groupConservation;
691 * results of alignment consensus analysis for visible portion of view
693 protected ProfilesI hconsensus = null;
696 * results of cDNA complement consensus visible portion of view
698 protected Hashtable[] hcomplementConsensus = null;
701 * results of secondary structure base pair consensus for visible portion of
704 protected Hashtable[] hStrucConsensus = null;
706 protected Conservation hconservation = null;
709 public void setConservation(Conservation cons)
711 hconservation = cons;
715 * percentage gaps allowed in a column before all amino acid properties should
716 * be considered unconserved
718 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
721 public int getConsPercGaps()
727 public void setSequenceConsensusHash(ProfilesI hconsensus)
729 this.hconsensus = hconsensus;
733 public void setComplementConsensusHash(Hashtable[] hconsensus)
735 this.hcomplementConsensus = hconsensus;
739 public ProfilesI getSequenceConsensusHash()
745 public Hashtable[] getComplementConsensusHash()
747 return hcomplementConsensus;
751 public Hashtable[] getRnaStructureConsensusHash()
753 return hStrucConsensus;
757 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
759 this.hStrucConsensus = hStrucConsensus;
764 public AlignmentAnnotation getAlignmentQualityAnnot()
770 public AlignmentAnnotation getAlignmentConservationAnnotation()
776 public AlignmentAnnotation getAlignmentConsensusAnnotation()
782 public AlignmentAnnotation getComplementConsensusAnnotation()
784 return complementConsensus;
788 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
790 return strucConsensus;
793 protected AlignCalcManagerI calculator = new AlignCalcManager();
796 * trigger update of conservation annotation
798 public void updateConservation(final AlignmentViewPanel ap)
800 // see note in mantis : issue number 8585
801 if (alignment.isNucleotide()
802 || (conservation == null && quality == null)
803 || !autoCalculateConsensus)
808 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
810 calculator.registerWorker(new jalview.workers.ConservationThread(
816 * trigger update of consensus annotation
818 public void updateConsensus(final AlignmentViewPanel ap)
820 // see note in mantis : issue number 8585
821 if (consensus == null || !autoCalculateConsensus)
825 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
827 calculator.registerWorker(new ConsensusThread(this, ap));
831 * A separate thread to compute cDNA consensus for a protein alignment
832 * which has mapping to cDNA
834 final AlignmentI al = this.getAlignment();
835 if (!al.isNucleotide() && al.getCodonFrames() != null
836 && !al.getCodonFrames().isEmpty())
839 * fudge - check first for protein-to-nucleotide mappings
840 * (we don't want to do this for protein-to-protein)
842 boolean doConsensus = false;
843 for (AlignedCodonFrame mapping : al.getCodonFrames())
845 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
846 MapList[] mapLists = mapping.getdnaToProt();
847 // mapLists can be empty if project load has not finished resolving seqs
848 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
857 .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null)
860 .registerWorker(new ComplementConsensusThread(this, ap));
866 // --------START Structure Conservation
867 public void updateStrucConsensus(final AlignmentViewPanel ap)
869 if (autoCalculateStrucConsensus && strucConsensus == null
870 && alignment.isNucleotide() && alignment.hasRNAStructure())
872 // secondary structure has been added - so init the consensus line
876 // see note in mantis : issue number 8585
877 if (strucConsensus == null || !autoCalculateStrucConsensus)
881 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
883 calculator.registerWorker(new StrucConsensusThread(this, ap));
887 public boolean isCalcInProgress()
889 return calculator.isWorking();
893 public boolean isCalculationInProgress(
894 AlignmentAnnotation alignmentAnnotation)
896 if (!alignmentAnnotation.autoCalculated)
900 if (calculator.workingInvolvedWith(alignmentAnnotation))
902 // System.err.println("grey out ("+alignmentAnnotation.label+")");
908 public void setAlignment(AlignmentI align)
910 this.alignment = align;
914 * Clean up references when this viewport is closed
917 public void dispose()
920 * defensively null out references to large objects in case
921 * this object is not garbage collected (as if!)
924 complementConsensus = null;
925 strucConsensus = null;
928 groupConsensus = null;
929 groupConservation = null;
931 hcomplementConsensus = null;
932 // colour scheme may hold reference to consensus
933 globalColourScheme = null;
934 // TODO remove listeners from changeSupport?
935 changeSupport = null;
940 public boolean isClosed()
942 // TODO: check that this isClosed is only true after panel is closed, not
943 // before it is fully constructed.
944 return alignment == null;
948 public AlignCalcManagerI getCalcManager()
954 * should conservation rows be shown for groups
956 protected boolean showGroupConservation = false;
959 * should consensus rows be shown for groups
961 protected boolean showGroupConsensus = false;
964 * should consensus profile be rendered by default
966 protected boolean showSequenceLogo = false;
969 * should consensus profile be rendered normalised to row height
971 protected boolean normaliseSequenceLogo = false;
974 * should consensus histograms be rendered by default
976 protected boolean showConsensusHistogram = true;
979 * @return the showConsensusProfile
982 public boolean isShowSequenceLogo()
984 return showSequenceLogo;
988 * @param showSequenceLogo
991 public void setShowSequenceLogo(boolean showSequenceLogo)
993 if (showSequenceLogo != this.showSequenceLogo)
995 // TODO: decouple settings setting from calculation when refactoring
996 // annotation update method from alignframe to viewport
997 this.showSequenceLogo = showSequenceLogo;
998 calculator.updateAnnotationFor(ConsensusThread.class);
999 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1000 calculator.updateAnnotationFor(StrucConsensusThread.class);
1002 this.showSequenceLogo = showSequenceLogo;
1006 * @param showConsensusHistogram
1007 * the showConsensusHistogram to set
1009 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1011 this.showConsensusHistogram = showConsensusHistogram;
1015 * @return the showGroupConservation
1017 public boolean isShowGroupConservation()
1019 return showGroupConservation;
1023 * @param showGroupConservation
1024 * the showGroupConservation to set
1026 public void setShowGroupConservation(boolean showGroupConservation)
1028 this.showGroupConservation = showGroupConservation;
1032 * @return the showGroupConsensus
1034 public boolean isShowGroupConsensus()
1036 return showGroupConsensus;
1040 * @param showGroupConsensus
1041 * the showGroupConsensus to set
1043 public void setShowGroupConsensus(boolean showGroupConsensus)
1045 this.showGroupConsensus = showGroupConsensus;
1050 * @return flag to indicate if the consensus histogram should be rendered by
1054 public boolean isShowConsensusHistogram()
1056 return this.showConsensusHistogram;
1060 * when set, updateAlignment will always ensure sequences are of equal length
1062 private boolean padGaps = false;
1065 * when set, alignment should be reordered according to a newly opened tree
1067 public boolean sortByTree = false;
1072 * @return null or the currently selected sequence region
1075 public SequenceGroup getSelectionGroup()
1077 return selectionGroup;
1081 * Set the selection group for this window.
1084 * - group holding references to sequences in this alignment view
1088 public void setSelectionGroup(SequenceGroup sg)
1090 selectionGroup = sg;
1093 public void setHiddenColumns(ColumnSelection colsel)
1095 this.colSel = colsel;
1099 public ColumnSelection getColumnSelection()
1105 public void setColumnSelection(ColumnSelection colSel)
1107 this.colSel = colSel;
1110 updateHiddenColumns();
1112 isColSelChanged(true);
1120 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1122 return hiddenRepSequences;
1126 public void setHiddenRepSequences(
1127 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1129 this.hiddenRepSequences = hiddenRepSequences;
1133 public boolean hasSelectedColumns()
1135 ColumnSelection columnSelection = getColumnSelection();
1136 return columnSelection != null && columnSelection.hasSelectedColumns();
1140 public boolean hasHiddenColumns()
1142 return colSel != null && colSel.hasHiddenColumns();
1145 public void updateHiddenColumns()
1147 // this method doesn't really do anything now. But - it could, since a
1148 // column Selection could be in the process of modification
1149 // hasHiddenColumns = colSel.hasHiddenColumns();
1153 public boolean hasHiddenRows()
1155 return alignment.getHiddenSequences().getSize() > 0;
1158 protected SequenceGroup selectionGroup;
1160 public void setSequenceSetId(String newid)
1162 if (sequenceSetID != null)
1165 .println("Warning - overwriting a sequenceSetId for a viewport!");
1167 sequenceSetID = new String(newid);
1171 public String getSequenceSetId()
1173 if (sequenceSetID == null)
1175 sequenceSetID = alignment.hashCode() + "";
1178 return sequenceSetID;
1182 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1185 protected String viewId = null;
1188 public String getViewId()
1192 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1197 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1199 ignoreGapsInConsensusCalculation = b;
1202 updateConsensus(ap);
1203 if (globalColourScheme != null)
1205 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1206 ignoreGapsInConsensusCalculation);
1212 private long sgrouphash = -1, colselhash = -1;
1215 * checks current SelectionGroup against record of last hash value, and
1219 * update the record of last hash value
1221 * @return true if SelectionGroup changed since last call (when b is true)
1223 public boolean isSelectionGroupChanged(boolean b)
1225 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1226 : selectionGroup.hashCode();
1227 if (hc != -1 && hc != sgrouphash)
1239 * checks current colsel against record of last hash value, and optionally
1243 * update the record of last hash value
1244 * @return true if colsel changed since last call (when b is true)
1246 public boolean isColSelChanged(boolean b)
1248 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1249 if (hc != -1 && hc != colselhash)
1261 public boolean isIgnoreGapsConsensus()
1263 return ignoreGapsInConsensusCalculation;
1266 // property change stuff
1267 // JBPNote Prolly only need this in the applet version.
1268 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1271 protected boolean showConservation = true;
1273 protected boolean showQuality = true;
1275 protected boolean showConsensus = true;
1277 private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
1279 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1281 protected boolean showAutocalculatedAbove;
1284 * when set, view will scroll to show the highlighted position
1286 private boolean followHighlight = true;
1288 // TODO private with getters and setters?
1289 public int startRes;
1293 public int startSeq;
1298 * Property change listener for changes in alignment
1303 public void addPropertyChangeListener(
1304 java.beans.PropertyChangeListener listener)
1306 changeSupport.addPropertyChangeListener(listener);
1315 public void removePropertyChangeListener(
1316 java.beans.PropertyChangeListener listener)
1318 changeSupport.removePropertyChangeListener(listener);
1322 * Property change listener for changes in alignment
1331 public void firePropertyChange(String prop, Object oldvalue,
1334 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1337 // common hide/show column stuff
1339 public void hideSelectedColumns()
1341 if (colSel.isEmpty())
1346 colSel.hideSelectedColumns();
1347 setSelectionGroup(null);
1348 isColSelChanged(true);
1351 public void hideColumns(int start, int end)
1355 colSel.hideColumns(start);
1359 colSel.hideColumns(start, end);
1361 isColSelChanged(true);
1364 public void showColumn(int col)
1366 colSel.revealHiddenColumns(col);
1367 isColSelChanged(true);
1370 public void showAllHiddenColumns()
1372 colSel.revealAllHiddenColumns();
1373 isColSelChanged(true);
1376 // common hide/show seq stuff
1377 public void showAllHiddenSeqs()
1379 if (alignment.getHiddenSequences().getSize() > 0)
1381 if (selectionGroup == null)
1383 selectionGroup = new SequenceGroup();
1384 selectionGroup.setEndRes(alignment.getWidth() - 1);
1386 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1387 hiddenRepSequences);
1388 for (SequenceI seq : tmp)
1390 selectionGroup.addSequence(seq, false);
1391 setSequenceAnnotationsVisible(seq, true);
1394 hiddenRepSequences = null;
1396 firePropertyChange("alignment", null, alignment.getSequences());
1397 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1403 public void showSequence(int index)
1405 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1406 index, hiddenRepSequences);
1409 if (selectionGroup == null)
1411 selectionGroup = new SequenceGroup();
1412 selectionGroup.setEndRes(alignment.getWidth() - 1);
1415 for (SequenceI seq : tmp)
1417 selectionGroup.addSequence(seq, false);
1418 setSequenceAnnotationsVisible(seq, true);
1420 firePropertyChange("alignment", null, alignment.getSequences());
1425 public void hideAllSelectedSeqs()
1427 if (selectionGroup == null || selectionGroup.getSize() < 1)
1432 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1436 setSelectionGroup(null);
1439 public void hideSequence(SequenceI[] seq)
1443 for (int i = 0; i < seq.length; i++)
1445 alignment.getHiddenSequences().hideSequence(seq[i]);
1446 setSequenceAnnotationsVisible(seq[i], false);
1448 firePropertyChange("alignment", null, alignment.getSequences());
1453 * Hides the specified sequence, or the sequences it represents
1456 * the sequence to hide, or keep as representative
1457 * @param representGroup
1458 * if true, hide the current selection group except for the
1459 * representative sequence
1461 public void hideSequences(SequenceI sequence, boolean representGroup)
1463 if (selectionGroup == null || selectionGroup.getSize() < 1)
1465 hideSequence(new SequenceI[] { sequence });
1471 hideRepSequences(sequence, selectionGroup);
1472 setSelectionGroup(null);
1476 int gsize = selectionGroup.getSize();
1477 SequenceI[] hseqs = selectionGroup.getSequences().toArray(
1478 new SequenceI[gsize]);
1480 hideSequence(hseqs);
1481 setSelectionGroup(null);
1486 * Set visibility for any annotations for the given sequence.
1490 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1493 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1496 for (AlignmentAnnotation ann : anns)
1498 if (ann.sequenceRef == sequenceI)
1500 ann.visible = visible;
1506 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1508 int sSize = sg.getSize();
1514 if (hiddenRepSequences == null)
1516 hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
1519 hiddenRepSequences.put(repSequence, sg);
1521 // Hide all sequences except the repSequence
1522 SequenceI[] seqs = new SequenceI[sSize - 1];
1524 for (int i = 0; i < sSize; i++)
1526 if (sg.getSequenceAt(i) != repSequence)
1528 if (index == sSize - 1)
1533 seqs[index++] = sg.getSequenceAt(i);
1536 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1537 sg.setHidereps(true); // note: not done in 2.7applet
1544 * @return null or the current reference sequence
1546 public SequenceI getReferenceSeq()
1548 return alignment.getSeqrep();
1553 * @return true iff seq is the reference for the alignment
1555 public boolean isReferenceSeq(SequenceI seq)
1557 return alignment.getSeqrep() == seq;
1563 * @return true if there are sequences represented by this sequence that are
1566 public boolean isHiddenRepSequence(SequenceI seq)
1568 return (hiddenRepSequences != null && hiddenRepSequences
1575 * @return null or a sequence group containing the sequences that seq
1578 public SequenceGroup getRepresentedSequences(SequenceI seq)
1580 return (SequenceGroup) (hiddenRepSequences == null ? null
1581 : hiddenRepSequences.get(seq));
1585 public int adjustForHiddenSeqs(int alignmentIndex)
1587 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1592 public void invertColumnSelection()
1594 colSel.invertColumnSelection(0, alignment.getWidth());
1598 public SequenceI[] getSelectionAsNewSequence()
1600 SequenceI[] sequences;
1601 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1602 // this was the only caller in the applet for this method
1603 // JBPNote: in applet, this method returned references to the alignment
1604 // sequences, and it did not honour the presence/absence of annotation
1605 // attached to the alignment (probably!)
1606 if (selectionGroup == null || selectionGroup.getSize() == 0)
1608 sequences = alignment.getSequencesArray();
1609 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1610 for (int i = 0; i < sequences.length; i++)
1612 // construct new sequence with subset of visible annotation
1613 sequences[i] = new Sequence(sequences[i], annots);
1618 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1625 public SequenceI[] getSequenceSelection()
1627 SequenceI[] sequences = null;
1628 if (selectionGroup != null)
1630 sequences = selectionGroup.getSequencesInOrder(alignment);
1632 if (sequences == null)
1634 sequences = alignment.getSequencesArray();
1640 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1642 return new CigarArray(alignment, colSel,
1643 (selectedRegionOnly ? selectionGroup : null));
1647 public jalview.datamodel.AlignmentView getAlignmentView(
1648 boolean selectedOnly)
1650 return getAlignmentView(selectedOnly, false);
1654 public jalview.datamodel.AlignmentView getAlignmentView(
1655 boolean selectedOnly, boolean markGroups)
1657 return new AlignmentView(alignment, colSel, selectionGroup,
1658 colSel != null && colSel.hasHiddenColumns(), selectedOnly,
1663 public String[] getViewAsString(boolean selectedRegionOnly)
1665 return getViewAsString(selectedRegionOnly, true);
1669 public String[] getViewAsString(boolean selectedRegionOnly,
1670 boolean exportHiddenSeqs)
1672 String[] selection = null;
1673 SequenceI[] seqs = null;
1675 int start = 0, end = 0;
1676 if (selectedRegionOnly && selectionGroup != null)
1678 iSize = selectionGroup.getSize();
1679 seqs = selectionGroup.getSequencesInOrder(alignment);
1680 start = selectionGroup.getStartRes();
1681 end = selectionGroup.getEndRes() + 1;
1685 if (hasHiddenRows() && exportHiddenSeqs)
1687 AlignmentI fullAlignment = alignment.getHiddenSequences()
1688 .getFullAlignment();
1689 iSize = fullAlignment.getHeight();
1690 seqs = fullAlignment.getSequencesArray();
1691 end = fullAlignment.getWidth();
1695 iSize = alignment.getHeight();
1696 seqs = alignment.getSequencesArray();
1697 end = alignment.getWidth();
1701 selection = new String[iSize];
1702 if (colSel != null && colSel.hasHiddenColumns())
1704 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1708 for (i = 0; i < iSize; i++)
1710 selection[i] = seqs[i].getSequenceAsString(start, end);
1718 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1720 ArrayList<int[]> regions = new ArrayList<int[]>();
1726 if (colSel != null && colSel.hasHiddenColumns())
1730 start = colSel.adjustForHiddenColumns(start);
1733 end = colSel.getHiddenBoundaryRight(start);
1744 regions.add(new int[] { start, end });
1746 if (colSel != null && colSel.hasHiddenColumns())
1748 start = colSel.adjustForHiddenColumns(end);
1749 start = colSel.getHiddenBoundaryLeft(start) + 1;
1751 } while (end < max);
1753 int[][] startEnd = new int[regions.size()][2];
1759 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1760 boolean selectedOnly)
1762 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1763 AlignmentAnnotation[] aa;
1764 if ((aa = alignment.getAlignmentAnnotation()) != null)
1766 for (AlignmentAnnotation annot : aa)
1768 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1769 if (selectedOnly && selectionGroup != null)
1771 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(),
1772 selectionGroup.getEndRes(), clone);
1776 colSel.makeVisibleAnnotation(clone);
1785 public boolean isPadGaps()
1791 public void setPadGaps(boolean padGaps)
1793 this.padGaps = padGaps;
1797 * apply any post-edit constraints and trigger any calculations needed after
1798 * an edit has been performed on the alignment
1803 public void alignmentChanged(AlignmentViewPanel ap)
1807 alignment.padGaps();
1809 if (autoCalculateConsensus)
1811 updateConsensus(ap);
1813 if (hconsensus != null && autoCalculateConsensus)
1815 updateConservation(ap);
1817 if (autoCalculateStrucConsensus)
1819 updateStrucConsensus(ap);
1822 // Reset endRes of groups if beyond alignment width
1823 int alWidth = alignment.getWidth();
1824 List<SequenceGroup> groups = alignment.getGroups();
1827 for (SequenceGroup sg : groups)
1829 if (sg.getEndRes() > alWidth)
1831 sg.setEndRes(alWidth - 1);
1836 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1838 selectionGroup.setEndRes(alWidth - 1);
1841 resetAllColourSchemes();
1842 calculator.restartWorkers();
1843 // alignment.adjustSequenceAnnotations();
1847 * reset scope and do calculations for all applied colourschemes on alignment
1849 void resetAllColourSchemes()
1851 CollectionColourSchemeI cs = globalColourScheme;
1854 cs.alignmentChanged(alignment, hiddenRepSequences);
1856 cs.setConsensus(hconsensus);
1857 if (cs.conservationApplied())
1859 cs.setConservation(Conservation.calculateConservation("All",
1860 alignment.getSequences(), 0, alignment.getWidth(), false,
1861 getConsPercGaps(), false));
1865 for (SequenceGroup sg : alignment.getGroups())
1869 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1871 sg.recalcConservation();
1875 protected void initAutoAnnotation()
1877 // TODO: add menu option action that nulls or creates consensus object
1878 // depending on if the user wants to see the annotation or not in a
1879 // specific alignment
1881 if (hconsensus == null && !isDataset)
1883 if (!alignment.isNucleotide())
1892 consensus = new AlignmentAnnotation("Consensus", "PID",
1893 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1894 initConsensus(consensus);
1896 initComplementConsensus();
1901 * If this is a protein alignment and there are mappings to cDNA, add the cDNA
1902 * consensus annotation.
1904 public void initComplementConsensus()
1906 if (!alignment.isNucleotide())
1908 final List<AlignedCodonFrame> codonMappings = alignment
1910 if (codonMappings != null && !codonMappings.isEmpty())
1912 boolean doConsensus = false;
1913 for (AlignedCodonFrame mapping : codonMappings)
1915 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1916 MapList[] mapLists = mapping.getdnaToProt();
1917 // mapLists can be empty if project load has not finished resolving
1919 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1927 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1928 "PID for cDNA", new Annotation[1], 0f, 100f,
1929 AlignmentAnnotation.BAR_GRAPH);
1930 initConsensus(complementConsensus);
1936 private void initConsensus(AlignmentAnnotation aa)
1939 aa.autoCalculated = true;
1943 alignment.addAnnotation(aa);
1947 private void initConservation()
1949 if (showConservation)
1951 if (conservation == null)
1953 conservation = new AlignmentAnnotation("Conservation",
1954 "Conservation of total alignment less than "
1955 + getConsPercGaps() + "% gaps", new Annotation[1],
1956 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1957 conservation.hasText = true;
1958 conservation.autoCalculated = true;
1959 alignment.addAnnotation(conservation);
1964 private void initQuality()
1968 if (quality == null)
1970 quality = new AlignmentAnnotation("Quality",
1971 "Alignment Quality based on Blosum62 scores",
1972 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1973 quality.hasText = true;
1974 quality.autoCalculated = true;
1975 alignment.addAnnotation(quality);
1980 private void initRNAStructure()
1982 if (alignment.hasRNAStructure() && strucConsensus == null)
1984 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1985 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1986 strucConsensus.hasText = true;
1987 strucConsensus.autoCalculated = true;
1991 alignment.addAnnotation(strucConsensus);
1999 * @see jalview.api.AlignViewportI#calcPanelHeight()
2002 public int calcPanelHeight()
2004 // setHeight of panels
2005 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2007 int charHeight = getCharHeight();
2010 BitSet graphgrp = new BitSet();
2011 for (AlignmentAnnotation aa : anns)
2015 System.err.println("Null annotation row: ignoring.");
2022 if (aa.graphGroup > -1)
2024 if (graphgrp.get(aa.graphGroup))
2030 graphgrp.set(aa.graphGroup);
2037 aa.height += charHeight;
2047 aa.height += aa.graphHeight;
2055 height += aa.height;
2067 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2068 boolean preserveNewGroupSettings)
2070 boolean updateCalcs = false;
2071 boolean conv = isShowGroupConservation();
2072 boolean cons = isShowGroupConsensus();
2073 boolean showprf = isShowSequenceLogo();
2074 boolean showConsHist = isShowConsensusHistogram();
2075 boolean normLogo = isNormaliseSequenceLogo();
2078 * TODO reorder the annotation rows according to group/sequence ordering on
2081 boolean sortg = true;
2083 // remove old automatic annotation
2084 // add any new annotation
2086 // intersect alignment annotation with alignment groups
2088 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2089 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
2092 for (int an = 0; an < aan.length; an++)
2094 if (aan[an].autoCalculated && aan[an].groupRef != null)
2096 oldrfs.add(aan[an].groupRef);
2097 alignment.deleteAnnotation(aan[an], false);
2101 if (alignment.getGroups() != null)
2103 for (SequenceGroup sg : alignment.getGroups())
2105 updateCalcs = false;
2106 if (applyGlobalSettings
2107 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2109 // set defaults for this group's conservation/consensus
2110 sg.setshowSequenceLogo(showprf);
2111 sg.setShowConsensusHistogram(showConsHist);
2112 sg.setNormaliseSequenceLogo(normLogo);
2117 alignment.addAnnotation(sg.getConservationRow(), 0);
2122 alignment.addAnnotation(sg.getConsensus(), 0);
2124 // refresh the annotation rows
2127 sg.recalcConservation();
2135 public boolean isDisplayReferenceSeq()
2137 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2141 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2143 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2147 public boolean isColourByReferenceSeq()
2149 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2153 public Color getSequenceColour(SequenceI seq)
2155 Color sqc = sequenceColours.get(seq);
2156 return (sqc == null ? Color.white : sqc);
2160 public void setSequenceColour(SequenceI seq, Color col)
2164 sequenceColours.remove(seq);
2168 sequenceColours.put(seq, col);
2173 public void updateSequenceIdColours()
2175 for (SequenceGroup sg : alignment.getGroups())
2177 if (sg.idColour != null)
2179 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2181 sequenceColours.put(s, sg.idColour);
2188 public void clearSequenceColours()
2190 sequenceColours.clear();
2194 public AlignViewportI getCodingComplement()
2196 return this.codingComplement;
2200 * Set this as the (cDna/protein) complement of the given viewport. Also
2201 * ensures the reverse relationship is set on the given viewport.
2204 public void setCodingComplement(AlignViewportI av)
2208 System.err.println("Ignoring recursive setCodingComplement request");
2212 this.codingComplement = av;
2213 // avoid infinite recursion!
2214 if (av.getCodingComplement() != this)
2216 av.setCodingComplement(this);
2222 public boolean isNucleotide()
2224 return getAlignment() == null ? false : getAlignment().isNucleotide();
2228 public FeaturesDisplayedI getFeaturesDisplayed()
2230 return featuresDisplayed;
2234 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2236 featuresDisplayed = featuresDisplayedI;
2240 public boolean areFeaturesDisplayed()
2242 return featuresDisplayed != null
2243 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2250 * features are displayed if true
2253 public void setShowSequenceFeatures(boolean b)
2255 viewStyle.setShowSequenceFeatures(b);
2259 public boolean isShowSequenceFeatures()
2261 return viewStyle.isShowSequenceFeatures();
2265 public void setShowSequenceFeaturesHeight(boolean selected)
2267 viewStyle.setShowSequenceFeaturesHeight(selected);
2271 public boolean isShowSequenceFeaturesHeight()
2273 return viewStyle.isShowSequenceFeaturesHeight();
2277 public void setShowAnnotation(boolean b)
2279 viewStyle.setShowAnnotation(b);
2283 public boolean isShowAnnotation()
2285 return viewStyle.isShowAnnotation();
2289 public boolean isRightAlignIds()
2291 return viewStyle.isRightAlignIds();
2295 public void setRightAlignIds(boolean rightAlignIds)
2297 viewStyle.setRightAlignIds(rightAlignIds);
2301 public boolean getConservationSelected()
2303 return viewStyle.getConservationSelected();
2307 public void setShowBoxes(boolean state)
2309 viewStyle.setShowBoxes(state);
2314 * @see jalview.api.ViewStyleI#getTextColour()
2317 public Color getTextColour()
2319 return viewStyle.getTextColour();
2324 * @see jalview.api.ViewStyleI#getTextColour2()
2327 public Color getTextColour2()
2329 return viewStyle.getTextColour2();
2334 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2337 public int getThresholdTextColour()
2339 return viewStyle.getThresholdTextColour();
2344 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2347 public boolean isConservationColourSelected()
2349 return viewStyle.isConservationColourSelected();
2354 * @see jalview.api.ViewStyleI#isRenderGaps()
2357 public boolean isRenderGaps()
2359 return viewStyle.isRenderGaps();
2364 * @see jalview.api.ViewStyleI#isShowColourText()
2367 public boolean isShowColourText()
2369 return viewStyle.isShowColourText();
2373 * @param conservationColourSelected
2374 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2377 public void setConservationColourSelected(
2378 boolean conservationColourSelected)
2380 viewStyle.setConservationColourSelected(conservationColourSelected);
2384 * @param showColourText
2385 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2388 public void setShowColourText(boolean showColourText)
2390 viewStyle.setShowColourText(showColourText);
2395 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2398 public void setTextColour(Color textColour)
2400 viewStyle.setTextColour(textColour);
2404 * @param thresholdTextColour
2405 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2408 public void setThresholdTextColour(int thresholdTextColour)
2410 viewStyle.setThresholdTextColour(thresholdTextColour);
2414 * @param textColour2
2415 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2418 public void setTextColour2(Color textColour2)
2420 viewStyle.setTextColour2(textColour2);
2424 public ViewStyleI getViewStyle()
2426 return new ViewStyle(viewStyle);
2430 public void setViewStyle(ViewStyleI settingsForView)
2432 viewStyle = new ViewStyle(settingsForView);
2436 public boolean sameStyle(ViewStyleI them)
2438 return viewStyle.sameStyle(them);
2443 * @see jalview.api.ViewStyleI#getIdWidth()
2446 public int getIdWidth()
2448 return viewStyle.getIdWidth();
2453 * @see jalview.api.ViewStyleI#setIdWidth(int)
2456 public void setIdWidth(int i)
2458 viewStyle.setIdWidth(i);
2463 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2466 public boolean isCentreColumnLabels()
2468 return viewStyle.isCentreColumnLabels();
2472 * @param centreColumnLabels
2473 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2476 public void setCentreColumnLabels(boolean centreColumnLabels)
2478 viewStyle.setCentreColumnLabels(centreColumnLabels);
2483 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2486 public void setShowDBRefs(boolean showdbrefs)
2488 viewStyle.setShowDBRefs(showdbrefs);
2493 * @see jalview.api.ViewStyleI#isShowDBRefs()
2496 public boolean isShowDBRefs()
2498 return viewStyle.isShowDBRefs();
2503 * @see jalview.api.ViewStyleI#isShowNPFeats()
2506 public boolean isShowNPFeats()
2508 return viewStyle.isShowNPFeats();
2512 * @param shownpfeats
2513 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2516 public void setShowNPFeats(boolean shownpfeats)
2518 viewStyle.setShowNPFeats(shownpfeats);
2521 public abstract StructureSelectionManager getStructureSelectionManager();
2524 * Add one command to the command history list.
2528 public void addToHistoryList(CommandI command)
2530 if (this.historyList != null)
2532 this.historyList.push(command);
2533 broadcastCommand(command, false);
2537 protected void broadcastCommand(CommandI command, boolean undo)
2539 getStructureSelectionManager().commandPerformed(command, undo,
2544 * Add one command to the command redo list.
2548 public void addToRedoList(CommandI command)
2550 if (this.redoList != null)
2552 this.redoList.push(command);
2554 broadcastCommand(command, true);
2558 * Clear the command redo list.
2560 public void clearRedoList()
2562 if (this.redoList != null)
2564 this.redoList.clear();
2568 public void setHistoryList(Deque<CommandI> list)
2570 this.historyList = list;
2573 public Deque<CommandI> getHistoryList()
2575 return this.historyList;
2578 public void setRedoList(Deque<CommandI> list)
2580 this.redoList = list;
2583 public Deque<CommandI> getRedoList()
2585 return this.redoList;
2589 public VamsasSource getVamsasSource()
2594 public SequenceAnnotationOrder getSortAnnotationsBy()
2596 return sortAnnotationsBy;
2599 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2601 this.sortAnnotationsBy = sortAnnotationsBy;
2604 public boolean isShowAutocalculatedAbove()
2606 return showAutocalculatedAbove;
2609 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2611 this.showAutocalculatedAbove = showAutocalculatedAbove;
2615 public boolean isScaleProteinAsCdna()
2617 return viewStyle.isScaleProteinAsCdna();
2621 public void setScaleProteinAsCdna(boolean b)
2623 viewStyle.setScaleProteinAsCdna(b);
2627 * @return true if view should scroll to show the highlighted region of a
2632 public final boolean isFollowHighlight()
2634 return followHighlight;
2638 public final void setFollowHighlight(boolean b)
2640 this.followHighlight = b;
2643 public int getStartRes()
2649 public int getEndRes()
2654 public int getStartSeq()
2659 public void setStartRes(int res)
2661 this.startRes = res;
2664 public void setStartSeq(int seq)
2666 this.startSeq = seq;
2669 public void setEndRes(int res)
2671 if (res > alignment.getWidth() - 1)
2673 // log.System.out.println(" Corrected res from " + res + " to maximum " +
2674 // (alignment.getWidth()-1));
2675 res = alignment.getWidth() - 1;
2684 public void setEndSeq(int seq)
2686 if (seq > alignment.getHeight())
2688 seq = alignment.getHeight();
2697 public int getEndSeq()
2703 * Helper method to populate the SearchResults with the location in the
2704 * complementary alignment to scroll to, in order to match this one.
2707 * the SearchResults to add to
2708 * @return the offset (below top of visible region) of the matched sequence
2710 protected int findComplementScrollTarget(SearchResultsI sr)
2712 final AlignViewportI complement = getCodingComplement();
2713 if (complement == null || !complement.isFollowHighlight())
2717 boolean iAmProtein = !getAlignment().isNucleotide();
2718 AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement
2720 if (proteinAlignment == null)
2724 final List<AlignedCodonFrame> mappings = proteinAlignment
2728 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2729 * residue in the middle column of the visible region. Scroll the
2730 * complementary alignment to line up the corresponding residue.
2733 SequenceI sequence = null;
2736 * locate 'middle' column (true middle if an odd number visible, left of
2737 * middle if an even number visible)
2739 int middleColumn = getStartRes() + (getEndRes() - getStartRes()) / 2;
2740 final HiddenSequences hiddenSequences = getAlignment()
2741 .getHiddenSequences();
2744 * searching to the bottom of the alignment gives smoother scrolling across
2745 * all gapped visible regions
2747 int lastSeq = alignment.getHeight() - 1;
2748 List<AlignedCodonFrame> seqMappings = null;
2749 for (int seqNo = getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2751 sequence = getAlignment().getSequenceAt(seqNo);
2752 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2756 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2760 seqMappings = MappingUtils
2761 .findMappingsForSequenceAndOthers(sequence, mappings,
2762 getCodingComplement().getAlignment().getSequences());
2763 if (!seqMappings.isEmpty())
2769 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2772 * No ungapped mapped sequence in middle column - do nothing
2776 MappingUtils.addSearchResults(sr, sequence,
2777 sequence.findPosition(middleColumn), seqMappings);
2782 * synthesize a column selection if none exists so it covers the given
2783 * selection group. if wholewidth is false, no column selection is made if the
2784 * selection group covers the whole alignment width.
2789 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2792 if (sg != null && (sgs = sg.getStartRes()) >= 0
2793 && sg.getStartRes() <= (sge = sg.getEndRes())
2794 && !this.hasSelectedColumns())
2796 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2803 colSel = new ColumnSelection();
2805 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2807 colSel.addElement(cspos);
2813 * hold status of current selection group - defined on alignment or not.
2815 private boolean selectionIsDefinedGroup = false;
2819 public boolean isSelectionDefinedGroup()
2821 if (selectionGroup == null)
2825 if (isSelectionGroupChanged(true))
2827 selectionIsDefinedGroup = false;
2828 List<SequenceGroup> gps = alignment.getGroups();
2829 if (gps == null || gps.size() == 0)
2831 selectionIsDefinedGroup = false;
2835 selectionIsDefinedGroup = gps.contains(selectionGroup);
2838 return selectionGroup.getContext() == alignment
2839 || selectionIsDefinedGroup;
2843 * null, or currently highlighted results on this view
2845 private SearchResultsI searchResults = null;
2848 public boolean hasSearchResults()
2850 return searchResults != null;
2854 public void setSearchResults(SearchResultsI results)
2856 searchResults = results;
2860 public SearchResultsI getSearchResults()
2862 return searchResults;