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.util.ArrayDeque;
25 import java.util.ArrayList;
26 import java.util.BitSet;
27 import java.util.Deque;
28 import java.util.HashMap;
29 import java.util.Hashtable;
30 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.SearchResults;
51 import jalview.datamodel.Sequence;
52 import jalview.datamodel.SequenceCollectionI;
53 import jalview.datamodel.SequenceGroup;
54 import jalview.datamodel.SequenceI;
55 import jalview.schemes.Blosum62ColourScheme;
56 import jalview.schemes.ColourSchemeI;
57 import jalview.schemes.PIDColourScheme;
58 import jalview.schemes.ResidueProperties;
59 import jalview.structure.CommandListener;
60 import jalview.structure.StructureSelectionManager;
61 import jalview.structure.VamsasSource;
62 import jalview.util.Comparison;
63 import jalview.util.MappingUtils;
64 import jalview.viewmodel.styles.ViewStyle;
65 import jalview.workers.AlignCalcManager;
66 import jalview.workers.ComplementConsensusThread;
67 import jalview.workers.ConsensusThread;
68 import jalview.workers.StrucConsensusThread;
71 * base class holding visualization and analysis attributes and common logic for
72 * an active alignment view displayed in the GUI
77 public abstract class AlignmentViewport implements AlignViewportI,
78 ViewStyleI, CommandListener, VamsasSource
80 protected ViewStyleI viewStyle = new ViewStyle();
83 * A viewport that hosts the cDna view of this (protein), or vice versa (if
86 AlignViewportI codingComplement = null;
88 FeaturesDisplayedI featuresDisplayed = null;
90 protected Deque<CommandI> historyList = new ArrayDeque<CommandI>();
92 protected Deque<CommandI> redoList = new ArrayDeque<CommandI>();
96 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
98 public void setFontName(String name)
100 viewStyle.setFontName(name);
105 * @see jalview.api.ViewStyleI#setFontStyle(int)
107 public void setFontStyle(int style)
109 viewStyle.setFontStyle(style);
114 * @see jalview.api.ViewStyleI#setFontSize(int)
116 public void setFontSize(int size)
118 viewStyle.setFontSize(size);
123 * @see jalview.api.ViewStyleI#getFontStyle()
125 public int getFontStyle()
127 return viewStyle.getFontStyle();
132 * @see jalview.api.ViewStyleI#getFontName()
134 public String getFontName()
136 return viewStyle.getFontName();
141 * @see jalview.api.ViewStyleI#getFontSize()
143 public int getFontSize()
145 return viewStyle.getFontSize();
149 * @param upperCasebold
150 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
152 public void setUpperCasebold(boolean upperCasebold)
154 viewStyle.setUpperCasebold(upperCasebold);
159 * @see jalview.api.ViewStyleI#isUpperCasebold()
161 public boolean isUpperCasebold()
163 return viewStyle.isUpperCasebold();
168 * @see jalview.api.ViewStyleI#isSeqNameItalics()
170 public boolean isSeqNameItalics()
172 return viewStyle.isSeqNameItalics();
176 * @param colourByReferenceSeq
177 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
179 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
181 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
186 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
188 public void setColourAppliesToAllGroups(boolean b)
190 viewStyle.setColourAppliesToAllGroups(b);
195 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
197 public boolean getColourAppliesToAllGroups()
199 return viewStyle.getColourAppliesToAllGroups();
204 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
206 public boolean getAbovePIDThreshold()
208 return viewStyle.getAbovePIDThreshold();
213 * @see jalview.api.ViewStyleI#setIncrement(int)
215 public void setIncrement(int inc)
217 viewStyle.setIncrement(inc);
222 * @see jalview.api.ViewStyleI#getIncrement()
224 public int getIncrement()
226 return viewStyle.getIncrement();
231 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
233 public void setConservationSelected(boolean b)
235 viewStyle.setConservationSelected(b);
240 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
242 public void setShowHiddenMarkers(boolean show)
244 viewStyle.setShowHiddenMarkers(show);
249 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
251 public boolean getShowHiddenMarkers()
253 return viewStyle.getShowHiddenMarkers();
258 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
260 public void setScaleRightWrapped(boolean b)
262 viewStyle.setScaleRightWrapped(b);
267 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
269 public void setScaleLeftWrapped(boolean b)
271 viewStyle.setScaleLeftWrapped(b);
276 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
278 public void setScaleAboveWrapped(boolean b)
280 viewStyle.setScaleAboveWrapped(b);
285 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
287 public boolean getScaleLeftWrapped()
289 return viewStyle.getScaleLeftWrapped();
294 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
296 public boolean getScaleAboveWrapped()
298 return viewStyle.getScaleAboveWrapped();
303 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
305 public boolean getScaleRightWrapped()
307 return viewStyle.getScaleRightWrapped();
312 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
314 public void setAbovePIDThreshold(boolean b)
316 viewStyle.setAbovePIDThreshold(b);
321 * @see jalview.api.ViewStyleI#setThreshold(int)
323 public void setThreshold(int thresh)
325 viewStyle.setThreshold(thresh);
330 * @see jalview.api.ViewStyleI#getThreshold()
332 public int getThreshold()
334 return viewStyle.getThreshold();
339 * @see jalview.api.ViewStyleI#getShowJVSuffix()
341 public boolean getShowJVSuffix()
343 return viewStyle.getShowJVSuffix();
348 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
350 public void setShowJVSuffix(boolean b)
352 viewStyle.setShowJVSuffix(b);
357 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
359 public void setWrapAlignment(boolean state)
361 viewStyle.setWrapAlignment(state);
366 * @see jalview.api.ViewStyleI#setShowText(boolean)
368 public void setShowText(boolean state)
370 viewStyle.setShowText(state);
375 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
377 public void setRenderGaps(boolean state)
379 viewStyle.setRenderGaps(state);
384 * @see jalview.api.ViewStyleI#getColourText()
386 public boolean getColourText()
388 return viewStyle.getColourText();
393 * @see jalview.api.ViewStyleI#setColourText(boolean)
395 public void setColourText(boolean state)
397 viewStyle.setColourText(state);
402 * @see jalview.api.ViewStyleI#getWrapAlignment()
404 public boolean getWrapAlignment()
406 return viewStyle.getWrapAlignment();
411 * @see jalview.api.ViewStyleI#getShowText()
413 public boolean getShowText()
415 return viewStyle.getShowText();
420 * @see jalview.api.ViewStyleI#getWrappedWidth()
422 public int getWrappedWidth()
424 return viewStyle.getWrappedWidth();
429 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
431 public void setWrappedWidth(int w)
433 viewStyle.setWrappedWidth(w);
438 * @see jalview.api.ViewStyleI#getCharHeight()
440 public int getCharHeight()
442 return viewStyle.getCharHeight();
447 * @see jalview.api.ViewStyleI#setCharHeight(int)
449 public void setCharHeight(int h)
451 viewStyle.setCharHeight(h);
456 * @see jalview.api.ViewStyleI#getCharWidth()
458 public int getCharWidth()
460 return viewStyle.getCharWidth();
465 * @see jalview.api.ViewStyleI#setCharWidth(int)
467 public void setCharWidth(int w)
469 viewStyle.setCharWidth(w);
474 * @see jalview.api.ViewStyleI#getShowBoxes()
476 public boolean getShowBoxes()
478 return viewStyle.getShowBoxes();
483 * @see jalview.api.ViewStyleI#getShowUnconserved()
485 public boolean getShowUnconserved()
487 return viewStyle.getShowUnconserved();
491 * @param showunconserved
492 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
494 public void setShowUnconserved(boolean showunconserved)
496 viewStyle.setShowUnconserved(showunconserved);
501 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
503 public void setSeqNameItalics(boolean default1)
505 viewStyle.setSeqNameItalics(default1);
510 * @see jalview.api.ViewStyleI#setShowSeqFeaturesHeight(boolean)
512 public void setShowSeqFeaturesHeight(boolean selected)
514 viewStyle.setShowSeqFeaturesHeight(selected);
518 * alignment displayed in the viewport. Please use get/setter
520 protected AlignmentI alignment;
523 public AlignmentI getAlignment()
529 public char getGapCharacter()
531 return alignment.getGapCharacter();
534 protected String sequenceSetID;
537 * probably unused indicator that view is of a dataset rather than an
540 protected boolean isDataset = false;
542 public void setDataset(boolean b)
547 public boolean isDataset()
553 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
555 protected ColumnSelection colSel = new ColumnSelection();
557 public boolean autoCalculateConsensus = true;
559 protected boolean autoCalculateStrucConsensus = true;
561 protected boolean ignoreGapsInConsensusCalculation = false;
563 protected ColourSchemeI globalColourScheme = null;
567 public void setGlobalColourScheme(ColourSchemeI cs)
569 // TODO: logic refactored from AlignFrame changeColour -
570 // autorecalc stuff should be changed to rely on the worker system
571 // check to see if we should implement a changeColour(cs) method rather than
572 // put th logic in here
573 // - means that caller decides if they want to just modify state and defer
574 // calculation till later or to do all calculations in thread.
576 globalColourScheme = cs;
577 boolean recalc = false;
580 cs.setConservationApplied(recalc = getConservationSelected());
581 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
582 || cs instanceof Blosum62ColourScheme)
585 cs.setThreshold(viewStyle.getThreshold(),
586 ignoreGapsInConsensusCalculation);
590 cs.setThreshold(0, ignoreGapsInConsensusCalculation);
594 cs.setConsensus(hconsensus);
595 cs.setConservation(hconservation);
597 cs.alignmentChanged(alignment, hiddenRepSequences);
599 if (getColourAppliesToAllGroups())
601 for (SequenceGroup sg : getAlignment().getGroups())
608 sg.cs = cs.applyTo(sg, getHiddenRepSequences());
609 sg.setConsPercGaps(ConsPercGaps);
610 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
611 || cs instanceof Blosum62ColourScheme)
613 sg.cs.setThreshold(viewStyle.getThreshold(),
614 isIgnoreGapsConsensus());
619 sg.cs.setThreshold(0, isIgnoreGapsConsensus());
622 if (getConservationSelected())
624 sg.cs.setConservationApplied(true);
629 sg.cs.setConservation(null);
630 // sg.cs.setThreshold(0, getIgnoreGapsConsensus());
634 sg.recalcConservation();
638 sg.cs.alignmentChanged(sg, hiddenRepSequences);
646 public ColourSchemeI getGlobalColourScheme()
648 return globalColourScheme;
651 protected AlignmentAnnotation consensus;
653 protected AlignmentAnnotation complementConsensus;
655 protected AlignmentAnnotation strucConsensus;
657 protected AlignmentAnnotation conservation;
659 protected AlignmentAnnotation quality;
661 protected AlignmentAnnotation[] groupConsensus;
663 protected AlignmentAnnotation[] groupConservation;
666 * results of alignment consensus analysis for visible portion of view
668 protected Hashtable[] hconsensus = null;
671 * results of cDNA complement consensus visible portion of view
673 protected Hashtable[] hcomplementConsensus = null;
676 * results of secondary structure base pair consensus for visible portion of
679 protected Hashtable[] hStrucConsensus = null;
681 protected Conservation hconservation = null;
684 public void setConservation(Conservation cons)
686 hconservation = cons;
690 * percentage gaps allowed in a column before all amino acid properties should
691 * be considered unconserved
693 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
696 public int getConsPercGaps()
702 public void setSequenceConsensusHash(Hashtable[] hconsensus)
704 this.hconsensus = hconsensus;
708 public void setComplementConsensusHash(Hashtable[] hconsensus)
710 this.hcomplementConsensus = hconsensus;
714 public Hashtable[] getSequenceConsensusHash()
720 public Hashtable[] getComplementConsensusHash()
722 return hcomplementConsensus;
726 public Hashtable[] getRnaStructureConsensusHash()
728 return hStrucConsensus;
732 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
734 this.hStrucConsensus = hStrucConsensus;
739 public AlignmentAnnotation getAlignmentQualityAnnot()
745 public AlignmentAnnotation getAlignmentConservationAnnotation()
751 public AlignmentAnnotation getAlignmentConsensusAnnotation()
757 public AlignmentAnnotation getComplementConsensusAnnotation()
759 return complementConsensus;
763 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
765 return strucConsensus;
768 protected AlignCalcManagerI calculator = new AlignCalcManager();
771 * trigger update of conservation annotation
773 public void updateConservation(final AlignmentViewPanel ap)
775 // see note in mantis : issue number 8585
776 if (alignment.isNucleotide() || conservation == null
777 || !autoCalculateConsensus)
782 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
784 calculator.registerWorker(new jalview.workers.ConservationThread(
790 * trigger update of consensus annotation
792 public void updateConsensus(final AlignmentViewPanel ap)
794 // see note in mantis : issue number 8585
795 if (consensus == null || !autoCalculateConsensus)
799 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
801 calculator.registerWorker(new ConsensusThread(this, ap));
805 * A separate thread to compute cDNA consensus for a protein alignment
807 final AlignmentI al = this.getAlignment();
808 if (!al.isNucleotide() && al.getCodonFrames() != null
809 && !al.getCodonFrames().isEmpty())
812 .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null)
814 calculator.registerWorker(new ComplementConsensusThread(this, ap));
819 // --------START Structure Conservation
820 public void updateStrucConsensus(final AlignmentViewPanel ap)
822 if (autoCalculateStrucConsensus && strucConsensus == null
823 && alignment.isNucleotide() && alignment.hasRNAStructure())
825 // secondary structure has been added - so init the consensus line
829 // see note in mantis : issue number 8585
830 if (strucConsensus == null || !autoCalculateStrucConsensus)
834 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
836 calculator.registerWorker(new StrucConsensusThread(this, ap));
840 public boolean isCalcInProgress()
842 return calculator.isWorking();
846 public boolean isCalculationInProgress(
847 AlignmentAnnotation alignmentAnnotation)
849 if (!alignmentAnnotation.autoCalculated)
853 if (calculator.workingInvolvedWith(alignmentAnnotation))
855 // System.err.println("grey out ("+alignmentAnnotation.label+")");
862 public boolean isClosed()
864 // TODO: check that this isClosed is only true after panel is closed, not
865 // before it is fully constructed.
866 return alignment == null;
870 public AlignCalcManagerI getCalcManager()
876 * should conservation rows be shown for groups
878 protected boolean showGroupConservation = false;
881 * should consensus rows be shown for groups
883 protected boolean showGroupConsensus = false;
886 * should consensus profile be rendered by default
888 protected boolean showSequenceLogo = false;
891 * should consensus profile be rendered normalised to row height
893 protected boolean normaliseSequenceLogo = false;
896 * should consensus histograms be rendered by default
898 protected boolean showConsensusHistogram = true;
901 * @return the showConsensusProfile
904 public boolean isShowSequenceLogo()
906 return showSequenceLogo;
910 * @param showSequenceLogo
913 public void setShowSequenceLogo(boolean showSequenceLogo)
915 if (showSequenceLogo != this.showSequenceLogo)
917 // TODO: decouple settings setting from calculation when refactoring
918 // annotation update method from alignframe to viewport
919 this.showSequenceLogo = showSequenceLogo;
920 calculator.updateAnnotationFor(ConsensusThread.class);
921 calculator.updateAnnotationFor(ComplementConsensusThread.class);
922 calculator.updateAnnotationFor(StrucConsensusThread.class);
924 this.showSequenceLogo = showSequenceLogo;
928 * @param showConsensusHistogram
929 * the showConsensusHistogram to set
931 public void setShowConsensusHistogram(boolean showConsensusHistogram)
933 this.showConsensusHistogram = showConsensusHistogram;
937 * @return the showGroupConservation
939 public boolean isShowGroupConservation()
941 return showGroupConservation;
945 * @param showGroupConservation
946 * the showGroupConservation to set
948 public void setShowGroupConservation(boolean showGroupConservation)
950 this.showGroupConservation = showGroupConservation;
954 * @return the showGroupConsensus
956 public boolean isShowGroupConsensus()
958 return showGroupConsensus;
962 * @param showGroupConsensus
963 * the showGroupConsensus to set
965 public void setShowGroupConsensus(boolean showGroupConsensus)
967 this.showGroupConsensus = showGroupConsensus;
972 * @return flag to indicate if the consensus histogram should be rendered by
976 public boolean isShowConsensusHistogram()
978 return this.showConsensusHistogram;
982 * when set, updateAlignment will always ensure sequences are of equal length
984 private boolean padGaps = false;
987 * when set, alignment should be reordered according to a newly opened tree
989 public boolean sortByTree = false;
995 * @return null or the currently selected sequence region
998 public SequenceGroup getSelectionGroup()
1000 return selectionGroup;
1004 * Set the selection group for this window.
1007 * - group holding references to sequences in this alignment view
1011 public void setSelectionGroup(SequenceGroup sg)
1013 selectionGroup = sg;
1016 public void setHiddenColumns(ColumnSelection colsel)
1018 this.colSel = colsel;
1022 public ColumnSelection getColumnSelection()
1028 public void setColumnSelection(ColumnSelection colSel)
1030 this.colSel = colSel;
1033 updateHiddenColumns();
1042 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1044 return hiddenRepSequences;
1048 public void setHiddenRepSequences(
1049 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1051 this.hiddenRepSequences = hiddenRepSequences;
1055 public boolean hasHiddenColumns()
1057 return colSel != null && colSel.hasHiddenColumns();
1060 public void updateHiddenColumns()
1062 // this method doesn't really do anything now. But - it could, since a
1063 // column Selection could be in the process of modification
1064 // hasHiddenColumns = colSel.hasHiddenColumns();
1067 protected boolean hasHiddenRows = false;
1070 public boolean hasHiddenRows()
1072 return hasHiddenRows;
1075 protected SequenceGroup selectionGroup;
1077 public void setSequenceSetId(String newid)
1079 if (sequenceSetID != null)
1082 .println("Warning - overwriting a sequenceSetId for a viewport!");
1084 sequenceSetID = new String(newid);
1088 public String getSequenceSetId()
1090 if (sequenceSetID == null)
1092 sequenceSetID = alignment.hashCode() + "";
1095 return sequenceSetID;
1099 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1102 protected String viewId = null;
1105 public String getViewId()
1109 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1114 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1116 ignoreGapsInConsensusCalculation = b;
1119 updateConsensus(ap);
1120 if (globalColourScheme != null)
1122 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1123 ignoreGapsInConsensusCalculation);
1129 private long sgrouphash = -1, colselhash = -1;
1132 * checks current SelectionGroup against record of last hash value, and
1136 * update the record of last hash value
1138 * @return true if SelectionGroup changed since last call (when b is true)
1140 public boolean isSelectionGroupChanged(boolean b)
1142 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1143 : selectionGroup.hashCode();
1144 if (hc != -1 && hc != sgrouphash)
1156 * checks current colsel against record of last hash value, and optionally
1160 * update the record of last hash value
1161 * @return true if colsel changed since last call (when b is true)
1163 public boolean isColSelChanged(boolean b)
1165 int hc = (colSel == null || colSel.size() == 0) ? -1 : colSel
1167 if (hc != -1 && hc != colselhash)
1179 public boolean isIgnoreGapsConsensus()
1181 return ignoreGapsInConsensusCalculation;
1184 // / property change stuff
1186 // JBPNote Prolly only need this in the applet version.
1187 private final java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
1190 protected boolean showConservation = true;
1192 protected boolean showQuality = true;
1194 protected boolean showConsensus = true;
1196 private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
1198 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1200 protected boolean showAutocalculatedAbove;
1203 * when set, view will scroll to show the highlighted position
1205 private boolean followHighlight = true;
1207 // TODO private with getters and setters?
1208 public int startRes;
1212 public int startSeq;
1217 * Property change listener for changes in alignment
1222 public void addPropertyChangeListener(
1223 java.beans.PropertyChangeListener listener)
1225 changeSupport.addPropertyChangeListener(listener);
1234 public void removePropertyChangeListener(
1235 java.beans.PropertyChangeListener listener)
1237 changeSupport.removePropertyChangeListener(listener);
1241 * Property change listener for changes in alignment
1250 public void firePropertyChange(String prop, Object oldvalue,
1253 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1256 // common hide/show column stuff
1258 public void hideSelectedColumns()
1260 if (colSel.size() < 1)
1265 colSel.hideSelectedColumns();
1266 setSelectionGroup(null);
1270 public void hideColumns(int start, int end)
1274 colSel.hideColumns(start);
1278 colSel.hideColumns(start, end);
1282 public void showColumn(int col)
1284 colSel.revealHiddenColumns(col);
1288 public void showAllHiddenColumns()
1290 colSel.revealAllHiddenColumns();
1293 // common hide/show seq stuff
1294 public void showAllHiddenSeqs()
1296 if (alignment.getHiddenSequences().getSize() > 0)
1298 if (selectionGroup == null)
1300 selectionGroup = new SequenceGroup();
1301 selectionGroup.setEndRes(alignment.getWidth() - 1);
1303 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1304 hiddenRepSequences);
1305 for (SequenceI seq : tmp)
1307 selectionGroup.addSequence(seq, false);
1308 setSequenceAnnotationsVisible(seq, true);
1311 hasHiddenRows = false;
1312 hiddenRepSequences = null;
1314 firePropertyChange("alignment", null, alignment.getSequences());
1315 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1321 public void showSequence(int index)
1323 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1325 hiddenRepSequences);
1328 if (selectionGroup == null)
1330 selectionGroup = new SequenceGroup();
1331 selectionGroup.setEndRes(alignment.getWidth() - 1);
1334 for (SequenceI seq : tmp)
1336 selectionGroup.addSequence(seq, false);
1337 setSequenceAnnotationsVisible(seq, true);
1339 // JBPNote: refactor: only update flag if we modified visiblity (used to
1340 // do this regardless)
1341 if (alignment.getHiddenSequences().getSize() < 1)
1343 hasHiddenRows = false;
1345 firePropertyChange("alignment", null, alignment.getSequences());
1350 public void hideAllSelectedSeqs()
1352 if (selectionGroup == null || selectionGroup.getSize() < 1)
1357 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1361 setSelectionGroup(null);
1364 public void hideSequence(SequenceI[] seq)
1368 for (int i = 0; i < seq.length; i++)
1370 alignment.getHiddenSequences().hideSequence(seq[i]);
1371 setSequenceAnnotationsVisible(seq[i], false);
1373 hasHiddenRows = true;
1374 firePropertyChange("alignment", null, alignment.getSequences());
1379 * Set visibility for any annotations for the given sequence.
1383 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1386 for (AlignmentAnnotation ann : alignment.getAlignmentAnnotation())
1388 if (ann.sequenceRef == sequenceI)
1390 ann.visible = visible;
1395 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1397 int sSize = sg.getSize();
1403 if (hiddenRepSequences == null)
1405 hiddenRepSequences = new Hashtable();
1408 hiddenRepSequences.put(repSequence, sg);
1410 // Hide all sequences except the repSequence
1411 SequenceI[] seqs = new SequenceI[sSize - 1];
1413 for (int i = 0; i < sSize; i++)
1415 if (sg.getSequenceAt(i) != repSequence)
1417 if (index == sSize - 1)
1422 seqs[index++] = sg.getSequenceAt(i);
1425 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1426 sg.setHidereps(true); // note: not done in 2.7applet
1431 public boolean isHiddenRepSequence(SequenceI seq)
1433 return alignment.getSeqrep()==seq || (hiddenRepSequences != null
1434 && hiddenRepSequences.containsKey(seq));
1437 public SequenceGroup getRepresentedSequences(SequenceI seq)
1439 return (SequenceGroup) (hiddenRepSequences == null ? null
1440 : hiddenRepSequences.get(seq));
1444 public int adjustForHiddenSeqs(int alignmentIndex)
1446 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1451 public void invertColumnSelection()
1453 colSel.invertColumnSelection(0, alignment.getWidth());
1458 public SequenceI[] getSelectionAsNewSequence()
1460 SequenceI[] sequences;
1461 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1462 // this was the only caller in the applet for this method
1463 // JBPNote: in applet, this method returned references to the alignment
1464 // sequences, and it did not honour the presence/absence of annotation
1465 // attached to the alignment (probably!)
1466 if (selectionGroup == null || selectionGroup.getSize() == 0)
1468 sequences = alignment.getSequencesArray();
1469 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1470 for (int i = 0; i < sequences.length; i++)
1472 // construct new sequence with subset of visible annotation
1473 sequences[i] = new Sequence(sequences[i], annots);
1478 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1486 public SequenceI[] getSequenceSelection()
1488 SequenceI[] sequences = null;
1489 if (selectionGroup != null)
1491 sequences = selectionGroup.getSequencesInOrder(alignment);
1493 if (sequences == null)
1495 sequences = alignment.getSequencesArray();
1502 public CigarArray getViewAsCigars(
1503 boolean selectedRegionOnly)
1505 return new CigarArray(alignment, colSel,
1506 (selectedRegionOnly ? selectionGroup : null));
1511 public jalview.datamodel.AlignmentView getAlignmentView(
1512 boolean selectedOnly)
1514 return getAlignmentView(selectedOnly, false);
1519 public jalview.datamodel.AlignmentView getAlignmentView(
1520 boolean selectedOnly, boolean markGroups)
1522 return new AlignmentView(alignment, colSel, selectionGroup,
1523 colSel != null && colSel.hasHiddenColumns(), selectedOnly,
1529 public String[] getViewAsString(boolean selectedRegionOnly)
1531 String[] selection = null;
1532 SequenceI[] seqs = null;
1534 int start = 0, end = 0;
1535 if (selectedRegionOnly && selectionGroup != null)
1537 iSize = selectionGroup.getSize();
1538 seqs = selectionGroup.getSequencesInOrder(alignment);
1539 start = selectionGroup.getStartRes();
1540 end = selectionGroup.getEndRes() + 1;
1544 iSize = alignment.getHeight();
1545 seqs = alignment.getSequencesArray();
1546 end = alignment.getWidth();
1549 selection = new String[iSize];
1550 if (colSel != null && colSel.hasHiddenColumns())
1552 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1556 for (i = 0; i < iSize; i++)
1558 selection[i] = seqs[i].getSequenceAsString(start, end);
1567 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1569 ArrayList<int[]> regions = new ArrayList<int[]>();
1575 if (colSel != null && colSel.hasHiddenColumns())
1579 start = colSel.adjustForHiddenColumns(start);
1582 end = colSel.getHiddenBoundaryRight(start);
1593 regions.add(new int[]
1596 if (colSel != null && colSel.hasHiddenColumns())
1598 start = colSel.adjustForHiddenColumns(end);
1599 start = colSel.getHiddenBoundaryLeft(start) + 1;
1601 } while (end < max);
1603 int[][] startEnd = new int[regions.size()][2];
1609 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(boolean selectedOnly)
1611 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1612 AlignmentAnnotation[] aa;
1613 if ((aa=alignment.getAlignmentAnnotation())!=null)
1615 for (AlignmentAnnotation annot:aa)
1617 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1618 if (selectedOnly && selectionGroup!=null)
1620 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(), selectionGroup.getEndRes(),clone);
1622 colSel.makeVisibleAnnotation(clone);
1632 public boolean isPadGaps()
1639 public void setPadGaps(boolean padGaps)
1641 this.padGaps = padGaps;
1645 * apply any post-edit constraints and trigger any calculations needed after
1646 * an edit has been performed on the alignment
1651 public void alignmentChanged(AlignmentViewPanel ap)
1655 alignment.padGaps();
1657 if (autoCalculateConsensus)
1659 updateConsensus(ap);
1661 if (hconsensus != null && autoCalculateConsensus)
1663 updateConservation(ap);
1665 if (autoCalculateStrucConsensus)
1667 updateStrucConsensus(ap);
1670 // Reset endRes of groups if beyond alignment width
1671 int alWidth = alignment.getWidth();
1672 List<SequenceGroup> groups = alignment.getGroups();
1675 for (SequenceGroup sg : groups)
1677 if (sg.getEndRes() > alWidth)
1679 sg.setEndRes(alWidth - 1);
1684 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1686 selectionGroup.setEndRes(alWidth - 1);
1689 resetAllColourSchemes();
1690 calculator.restartWorkers();
1691 // alignment.adjustSequenceAnnotations();
1695 * reset scope and do calculations for all applied colourschemes on alignment
1697 void resetAllColourSchemes()
1699 ColourSchemeI cs = globalColourScheme;
1702 cs.alignmentChanged(alignment, hiddenRepSequences);
1704 cs.setConsensus(hconsensus);
1705 if (cs.conservationApplied())
1707 cs.setConservation(Conservation.calculateConservation("All",
1708 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1709 alignment.getWidth(), false, getConsPercGaps(), false));
1713 for (SequenceGroup sg : alignment.getGroups())
1717 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1719 sg.recalcConservation();
1723 protected void initAutoAnnotation()
1725 // TODO: add menu option action that nulls or creates consensus object
1726 // depending on if the user wants to see the annotation or not in a
1727 // specific alignment
1729 if (hconsensus == null && !isDataset)
1731 if (!alignment.isNucleotide())
1740 consensus = new AlignmentAnnotation("Consensus", "PID",
1741 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1742 initConsensus(consensus);
1744 initComplementConsensus();
1749 * If this is a protein alignment and there are mappings to cDNA, add the cDNA
1750 * consensus annotation.
1752 public void initComplementConsensus()
1754 if (!alignment.isNucleotide())
1756 final Set<AlignedCodonFrame> codonMappings = alignment
1758 if (codonMappings != null && !codonMappings.isEmpty())
1760 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1761 "PID for cDNA", new Annotation[1], 0f, 100f,
1762 AlignmentAnnotation.BAR_GRAPH);
1763 initConsensus(complementConsensus);
1768 private void initConsensus(AlignmentAnnotation aa)
1771 aa.autoCalculated = true;
1775 alignment.addAnnotation(aa);
1779 private void initConservation()
1781 if (showConservation)
1783 if (conservation == null)
1785 conservation = new AlignmentAnnotation("Conservation",
1786 "Conservation of total alignment less than "
1787 + getConsPercGaps() + "% gaps", new Annotation[1],
1788 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1789 conservation.hasText = true;
1790 conservation.autoCalculated = true;
1791 alignment.addAnnotation(conservation);
1796 private void initQuality()
1800 if (quality == null)
1802 quality = new AlignmentAnnotation("Quality",
1803 "Alignment Quality based on Blosum62 scores",
1804 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1805 quality.hasText = true;
1806 quality.autoCalculated = true;
1807 alignment.addAnnotation(quality);
1812 private void initRNAStructure()
1814 if (alignment.hasRNAStructure() && strucConsensus == null)
1816 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1817 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1818 strucConsensus.hasText = true;
1819 strucConsensus.autoCalculated = true;
1823 alignment.addAnnotation(strucConsensus);
1831 * @see jalview.api.AlignViewportI#calcPanelHeight()
1834 public int calcPanelHeight()
1836 // setHeight of panels
1837 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
1839 int charHeight = getCharHeight();
1842 BitSet graphgrp = new BitSet();
1843 for (AlignmentAnnotation aa : anns)
1847 System.err.println("Null annotation row: ignoring.");
1854 if (aa.graphGroup > -1)
1856 if (graphgrp.get(aa.graphGroup))
1862 graphgrp.set(aa.graphGroup);
1869 aa.height += charHeight;
1879 aa.height += aa.graphHeight;
1887 height += aa.height;
1899 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1900 boolean preserveNewGroupSettings)
1902 boolean updateCalcs = false;
1903 boolean conv = isShowGroupConservation();
1904 boolean cons = isShowGroupConsensus();
1905 boolean showprf = isShowSequenceLogo();
1906 boolean showConsHist = isShowConsensusHistogram();
1907 boolean normLogo = isNormaliseSequenceLogo();
1910 * TODO reorder the annotation rows according to group/sequence ordering on
1913 boolean sortg = true;
1915 // remove old automatic annotation
1916 // add any new annotation
1918 // intersect alignment annotation with alignment groups
1920 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
1921 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
1924 for (int an = 0; an < aan.length; an++)
1926 if (aan[an].autoCalculated && aan[an].groupRef != null)
1928 oldrfs.add(aan[an].groupRef);
1929 alignment.deleteAnnotation(aan[an], false);
1933 if (alignment.getGroups() != null)
1935 for (SequenceGroup sg : alignment.getGroups())
1937 updateCalcs = false;
1938 if (applyGlobalSettings
1939 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
1941 // set defaults for this group's conservation/consensus
1942 sg.setshowSequenceLogo(showprf);
1943 sg.setShowConsensusHistogram(showConsHist);
1944 sg.setNormaliseSequenceLogo(normLogo);
1949 alignment.addAnnotation(sg.getConservationRow(), 0);
1954 alignment.addAnnotation(sg.getConsensus(), 0);
1956 // refresh the annotation rows
1959 sg.recalcConservation();
1966 public boolean isDisplayReferenceSeq()
1968 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
1972 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
1974 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
1978 public boolean isColourByReferenceSeq()
1980 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
1984 public Color getSequenceColour(SequenceI seq)
1986 Color sqc = sequenceColours.get(seq);
1987 return (sqc == null ? Color.white : sqc);
1991 public void setSequenceColour(SequenceI seq, Color col)
1995 sequenceColours.remove(seq);
1999 sequenceColours.put(seq, col);
2004 public void updateSequenceIdColours()
2006 for (SequenceGroup sg : alignment.getGroups())
2008 if (sg.idColour != null)
2010 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2012 sequenceColours.put(s, sg.idColour);
2019 public void clearSequenceColours()
2021 sequenceColours.clear();
2025 public AlignViewportI getCodingComplement()
2027 return this.codingComplement;
2031 * Set this as the (cDna/protein) complement of the given viewport. Also
2032 * ensures the reverse relationship is set on the given viewport.
2035 public void setCodingComplement(AlignViewportI av)
2039 System.err.println("Ignoring recursive setCodingComplement request");
2043 this.codingComplement = av;
2044 // avoid infinite recursion!
2045 if (av.getCodingComplement() != this)
2047 av.setCodingComplement(this);
2053 public boolean isNucleotide()
2055 return getAlignment() == null ? false : getAlignment().isNucleotide();
2059 public FeaturesDisplayedI getFeaturesDisplayed()
2061 return featuresDisplayed;
2065 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2067 featuresDisplayed = featuresDisplayedI;
2071 public boolean areFeaturesDisplayed()
2073 return featuresDisplayed != null && featuresDisplayed.getRegisterdFeaturesCount()>0;
2080 * features are displayed if true
2083 public void setShowSequenceFeatures(boolean b)
2085 viewStyle.setShowSequenceFeatures(b);
2088 public boolean isShowSequenceFeatures()
2090 return viewStyle.isShowSequenceFeatures();
2094 public void setShowSequenceFeaturesHeight(boolean selected)
2096 viewStyle.setShowSeqFeaturesHeight(selected);
2100 public boolean isShowSequenceFeaturesHeight()
2102 return viewStyle.isShowSequenceFeaturesHeight();
2108 public void setShowAnnotation(boolean b)
2110 viewStyle.setShowAnnotation(b);
2114 public boolean isShowAnnotation()
2116 return viewStyle.isShowAnnotation();
2120 public boolean isRightAlignIds()
2122 return viewStyle.isRightAlignIds();
2126 public void setRightAlignIds(boolean rightAlignIds)
2128 viewStyle.setRightAlignIds(rightAlignIds);
2132 public boolean getConservationSelected()
2134 return viewStyle.getConservationSelected();
2138 public void setShowBoxes(boolean state)
2140 viewStyle.setShowBoxes(state);
2145 * @see jalview.api.ViewStyleI#getTextColour()
2147 public Color getTextColour()
2149 return viewStyle.getTextColour();
2154 * @see jalview.api.ViewStyleI#getTextColour2()
2156 public Color getTextColour2()
2158 return viewStyle.getTextColour2();
2163 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2165 public int getThresholdTextColour()
2167 return viewStyle.getThresholdTextColour();
2172 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2174 public boolean isConservationColourSelected()
2176 return viewStyle.isConservationColourSelected();
2181 * @see jalview.api.ViewStyleI#isRenderGaps()
2183 public boolean isRenderGaps()
2185 return viewStyle.isRenderGaps();
2190 * @see jalview.api.ViewStyleI#isShowColourText()
2192 public boolean isShowColourText()
2194 return viewStyle.isShowColourText();
2198 * @see jalview.api.ViewStyleI#isShowSeqFeaturesHeight()
2200 public boolean isShowSeqFeaturesHeight()
2202 return viewStyle.isShowSeqFeaturesHeight();
2206 * @param conservationColourSelected
2207 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2209 public void setConservationColourSelected(
2210 boolean conservationColourSelected)
2212 viewStyle.setConservationColourSelected(conservationColourSelected);
2216 * @param showColourText
2217 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2219 public void setShowColourText(boolean showColourText)
2221 viewStyle.setShowColourText(showColourText);
2226 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2228 public void setTextColour(Color textColour)
2230 viewStyle.setTextColour(textColour);
2234 * @param thresholdTextColour
2235 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2237 public void setThresholdTextColour(int thresholdTextColour)
2239 viewStyle.setThresholdTextColour(thresholdTextColour);
2243 * @param textColour2
2244 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2246 public void setTextColour2(Color textColour2)
2248 viewStyle.setTextColour2(textColour2);
2252 public ViewStyleI getViewStyle()
2254 return new ViewStyle(viewStyle);
2258 public void setViewStyle(ViewStyleI settingsForView)
2260 viewStyle = new ViewStyle(settingsForView);
2264 public boolean sameStyle(ViewStyleI them)
2266 return viewStyle.sameStyle(them);
2271 * @see jalview.api.ViewStyleI#getIdWidth()
2273 public int getIdWidth()
2275 return viewStyle.getIdWidth();
2280 * @see jalview.api.ViewStyleI#setIdWidth(int)
2282 public void setIdWidth(int i)
2284 viewStyle.setIdWidth(i);
2289 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2291 public boolean isCentreColumnLabels()
2293 return viewStyle.isCentreColumnLabels();
2297 * @param centreColumnLabels
2298 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2300 public void setCentreColumnLabels(boolean centreColumnLabels)
2302 viewStyle.setCentreColumnLabels(centreColumnLabels);
2307 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2309 public void setShowDBRefs(boolean showdbrefs)
2311 viewStyle.setShowDBRefs(showdbrefs);
2316 * @see jalview.api.ViewStyleI#isShowDBRefs()
2318 public boolean isShowDBRefs()
2320 return viewStyle.isShowDBRefs();
2325 * @see jalview.api.ViewStyleI#isShowNPFeats()
2327 public boolean isShowNPFeats()
2329 return viewStyle.isShowNPFeats();
2333 * @param shownpfeats
2334 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2336 public void setShowNPFeats(boolean shownpfeats)
2338 viewStyle.setShowNPFeats(shownpfeats);
2341 public abstract StructureSelectionManager getStructureSelectionManager();
2344 * Add one command to the command history list.
2348 public void addToHistoryList(CommandI command)
2350 if (this.historyList != null)
2352 this.historyList.push(command);
2353 broadcastCommand(command, false);
2357 protected void broadcastCommand(CommandI command, boolean undo)
2359 getStructureSelectionManager().commandPerformed(command, undo, getVamsasSource());
2363 * Add one command to the command redo list.
2367 public void addToRedoList(CommandI command)
2369 if (this.redoList != null)
2371 this.redoList.push(command);
2373 broadcastCommand(command, true);
2377 * Clear the command redo list.
2379 public void clearRedoList()
2381 if (this.redoList != null)
2383 this.redoList.clear();
2387 public void setHistoryList(Deque<CommandI> list)
2389 this.historyList = list;
2392 public Deque<CommandI> getHistoryList()
2394 return this.historyList;
2397 public void setRedoList(Deque<CommandI> list)
2399 this.redoList = list;
2402 public Deque<CommandI> getRedoList()
2404 return this.redoList;
2408 public VamsasSource getVamsasSource()
2413 public SequenceAnnotationOrder getSortAnnotationsBy()
2415 return sortAnnotationsBy;
2418 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2420 this.sortAnnotationsBy = sortAnnotationsBy;
2423 public boolean isShowAutocalculatedAbove()
2425 return showAutocalculatedAbove;
2428 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2430 this.showAutocalculatedAbove = showAutocalculatedAbove;
2434 public boolean isScaleProteinAsCdna()
2436 return viewStyle.isScaleProteinAsCdna();
2440 public void setScaleProteinAsCdna(boolean b)
2442 viewStyle.setScaleProteinAsCdna(b);
2446 * @return true if view should scroll to show the highlighted region of a
2451 public final boolean isFollowHighlight()
2453 return followHighlight;
2457 public final void setFollowHighlight(boolean b)
2459 this.followHighlight = b;
2462 public int getStartRes()
2467 public int getEndRes()
2472 public int getStartSeq()
2477 public void setStartRes(int res)
2479 this.startRes = res;
2482 public void setStartSeq(int seq)
2484 this.startSeq = seq;
2487 public void setEndRes(int res)
2489 if (res > alignment.getWidth() - 1)
2491 // log.System.out.println(" Corrected res from " + res + " to maximum " +
2492 // (alignment.getWidth()-1));
2493 res = alignment.getWidth() - 1;
2502 public void setEndSeq(int seq)
2504 if (seq > alignment.getHeight())
2506 seq = alignment.getHeight();
2515 public int getEndSeq()
2521 * Helper method to populate the SearchResults with the location in the
2522 * complementary alignment to scroll to, in order to match this one.
2525 * the SearchResults to add to
2526 * @return the offset (below top of visible region) of the matched sequence
2528 protected int findComplementScrollTarget(SearchResults sr)
2530 final AlignViewportI codingComplement = getCodingComplement();
2531 if (codingComplement == null || !codingComplement.isFollowHighlight())
2535 boolean iAmProtein = !getAlignment().isNucleotide();
2536 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2537 : codingComplement.getAlignment();
2538 if (proteinAlignment == null)
2542 final Set<AlignedCodonFrame> mappings = proteinAlignment
2546 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2547 * residue in the middle column of the visible region. Scroll the
2548 * complementary alignment to line up the corresponding residue.
2551 SequenceI sequence = null;
2552 int middleColumn = getStartRes() + (getEndRes() - getStartRes()) / 2;
2553 final HiddenSequences hiddenSequences = getAlignment()
2554 .getHiddenSequences();
2555 for (int seqNo = getStartSeq(); seqNo < getEndSeq(); seqNo++, seqOffset++)
2557 sequence = getAlignment().getSequenceAt(seqNo);
2558 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2562 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2566 List<AlignedCodonFrame> seqMappings = MappingUtils
2567 .findMappingsForSequence(sequence, mappings);
2568 if (!seqMappings.isEmpty())
2574 if (sequence == null)
2577 * No ungapped mapped sequence in middle column - do nothing
2581 MappingUtils.addSearchResults(sr, sequence,
2582 sequence.findPosition(middleColumn), mappings);