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.SearchResults;
40 import jalview.datamodel.Sequence;
41 import jalview.datamodel.SequenceCollectionI;
42 import jalview.datamodel.SequenceGroup;
43 import jalview.datamodel.SequenceI;
44 import jalview.schemes.Blosum62ColourScheme;
45 import jalview.schemes.ColourSchemeI;
46 import jalview.schemes.PIDColourScheme;
47 import jalview.schemes.ResidueProperties;
48 import jalview.structure.CommandListener;
49 import jalview.structure.StructureSelectionManager;
50 import jalview.structure.VamsasSource;
51 import jalview.util.Comparison;
52 import jalview.util.MappingUtils;
53 import jalview.viewmodel.styles.ViewStyle;
54 import jalview.workers.AlignCalcManager;
55 import jalview.workers.ComplementConsensusThread;
56 import jalview.workers.ConsensusThread;
57 import jalview.workers.StrucConsensusThread;
59 import java.awt.Color;
60 import java.util.ArrayDeque;
61 import java.util.ArrayList;
62 import java.util.BitSet;
63 import java.util.Deque;
64 import java.util.HashMap;
65 import java.util.Hashtable;
66 import java.util.List;
70 * base class holding visualization and analysis attributes and common logic for
71 * an active alignment view displayed in the GUI
76 public abstract class AlignmentViewport implements AlignViewportI,
77 CommandListener, VamsasSource
79 protected ViewStyleI viewStyle = new ViewStyle();
82 * A viewport that hosts the cDna view of this (protein), or vice versa (if
85 AlignViewportI codingComplement = null;
87 FeaturesDisplayedI featuresDisplayed = null;
89 protected Deque<CommandI> historyList = new ArrayDeque<CommandI>();
91 protected Deque<CommandI> redoList = new ArrayDeque<CommandI>();
95 * @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)
108 public void setFontStyle(int style)
110 viewStyle.setFontStyle(style);
115 * @see jalview.api.ViewStyleI#setFontSize(int)
118 public void setFontSize(int size)
120 viewStyle.setFontSize(size);
125 * @see jalview.api.ViewStyleI#getFontStyle()
128 public int getFontStyle()
130 return viewStyle.getFontStyle();
135 * @see jalview.api.ViewStyleI#getFontName()
138 public String getFontName()
140 return viewStyle.getFontName();
145 * @see jalview.api.ViewStyleI#getFontSize()
148 public int getFontSize()
150 return viewStyle.getFontSize();
154 * @param upperCasebold
155 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
158 public void setUpperCasebold(boolean upperCasebold)
160 viewStyle.setUpperCasebold(upperCasebold);
165 * @see jalview.api.ViewStyleI#isUpperCasebold()
168 public boolean isUpperCasebold()
170 return viewStyle.isUpperCasebold();
175 * @see jalview.api.ViewStyleI#isSeqNameItalics()
178 public boolean isSeqNameItalics()
180 return viewStyle.isSeqNameItalics();
184 * @param colourByReferenceSeq
185 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
188 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
190 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
195 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
198 public void setColourAppliesToAllGroups(boolean b)
200 viewStyle.setColourAppliesToAllGroups(b);
205 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
208 public boolean getColourAppliesToAllGroups()
210 return viewStyle.getColourAppliesToAllGroups();
215 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
218 public boolean getAbovePIDThreshold()
220 return viewStyle.getAbovePIDThreshold();
225 * @see jalview.api.ViewStyleI#setIncrement(int)
228 public void setIncrement(int inc)
230 viewStyle.setIncrement(inc);
235 * @see jalview.api.ViewStyleI#getIncrement()
238 public int getIncrement()
240 return viewStyle.getIncrement();
245 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
248 public void setConservationSelected(boolean b)
250 viewStyle.setConservationSelected(b);
255 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
258 public void setShowHiddenMarkers(boolean show)
260 viewStyle.setShowHiddenMarkers(show);
265 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
268 public boolean getShowHiddenMarkers()
270 return viewStyle.getShowHiddenMarkers();
275 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
278 public void setScaleRightWrapped(boolean b)
280 viewStyle.setScaleRightWrapped(b);
285 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
288 public void setScaleLeftWrapped(boolean b)
290 viewStyle.setScaleLeftWrapped(b);
295 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
298 public void setScaleAboveWrapped(boolean b)
300 viewStyle.setScaleAboveWrapped(b);
305 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
308 public boolean getScaleLeftWrapped()
310 return viewStyle.getScaleLeftWrapped();
315 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
318 public boolean getScaleAboveWrapped()
320 return viewStyle.getScaleAboveWrapped();
325 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
328 public boolean getScaleRightWrapped()
330 return viewStyle.getScaleRightWrapped();
335 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
338 public void setAbovePIDThreshold(boolean b)
340 viewStyle.setAbovePIDThreshold(b);
345 * @see jalview.api.ViewStyleI#setThreshold(int)
348 public void setThreshold(int thresh)
350 viewStyle.setThreshold(thresh);
355 * @see jalview.api.ViewStyleI#getThreshold()
358 public int getThreshold()
360 return viewStyle.getThreshold();
365 * @see jalview.api.ViewStyleI#getShowJVSuffix()
368 public boolean getShowJVSuffix()
370 return viewStyle.getShowJVSuffix();
375 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
378 public void setShowJVSuffix(boolean b)
380 viewStyle.setShowJVSuffix(b);
385 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
388 public void setWrapAlignment(boolean state)
390 viewStyle.setWrapAlignment(state);
395 * @see jalview.api.ViewStyleI#setShowText(boolean)
398 public void setShowText(boolean state)
400 viewStyle.setShowText(state);
405 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
408 public void setRenderGaps(boolean state)
410 viewStyle.setRenderGaps(state);
415 * @see jalview.api.ViewStyleI#getColourText()
418 public boolean getColourText()
420 return viewStyle.getColourText();
425 * @see jalview.api.ViewStyleI#setColourText(boolean)
428 public void setColourText(boolean state)
430 viewStyle.setColourText(state);
435 * @see jalview.api.ViewStyleI#getWrapAlignment()
438 public boolean getWrapAlignment()
440 return viewStyle.getWrapAlignment();
445 * @see jalview.api.ViewStyleI#getShowText()
448 public boolean getShowText()
450 return viewStyle.getShowText();
455 * @see jalview.api.ViewStyleI#getWrappedWidth()
458 public int getWrappedWidth()
460 return viewStyle.getWrappedWidth();
465 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
468 public void setWrappedWidth(int w)
470 viewStyle.setWrappedWidth(w);
475 * @see jalview.api.ViewStyleI#getCharHeight()
478 public int getCharHeight()
480 return viewStyle.getCharHeight();
485 * @see jalview.api.ViewStyleI#setCharHeight(int)
488 public void setCharHeight(int h)
490 viewStyle.setCharHeight(h);
495 * @see jalview.api.ViewStyleI#getCharWidth()
498 public int getCharWidth()
500 return viewStyle.getCharWidth();
505 * @see jalview.api.ViewStyleI#setCharWidth(int)
508 public void setCharWidth(int w)
510 viewStyle.setCharWidth(w);
515 * @see jalview.api.ViewStyleI#getShowBoxes()
518 public boolean getShowBoxes()
520 return viewStyle.getShowBoxes();
525 * @see jalview.api.ViewStyleI#getShowUnconserved()
528 public boolean getShowUnconserved()
530 return viewStyle.getShowUnconserved();
534 * @param showunconserved
535 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
538 public void setShowUnconserved(boolean showunconserved)
540 viewStyle.setShowUnconserved(showunconserved);
545 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
548 public void setSeqNameItalics(boolean default1)
550 viewStyle.setSeqNameItalics(default1);
554 * alignment displayed in the viewport. Please use get/setter
556 protected AlignmentI alignment;
559 public AlignmentI getAlignment()
565 public char getGapCharacter()
567 return alignment.getGapCharacter();
570 protected String sequenceSetID;
573 * probably unused indicator that view is of a dataset rather than an
576 protected boolean isDataset = false;
578 public void setDataset(boolean b)
583 public boolean isDataset()
588 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
590 protected ColumnSelection colSel = new ColumnSelection();
592 public boolean autoCalculateConsensus = true;
594 protected boolean autoCalculateStrucConsensus = true;
596 protected boolean ignoreGapsInConsensusCalculation = false;
598 protected ColourSchemeI globalColourScheme = null;
601 public void setGlobalColourScheme(ColourSchemeI cs)
603 // TODO: logic refactored from AlignFrame changeColour -
604 // TODO: autorecalc stuff should be changed to rely on the worker system
605 // check to see if we should implement a changeColour(cs) method rather than
606 // put th logic in here
607 // - means that caller decides if they want to just modify state and defer
608 // calculation till later or to do all calculations in thread.
610 globalColourScheme = cs;
611 boolean recalc = false;
614 cs.setConservationApplied(recalc = getConservationSelected());
615 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
616 || cs instanceof Blosum62ColourScheme)
619 cs.setThreshold(viewStyle.getThreshold(),
620 ignoreGapsInConsensusCalculation);
624 cs.setThreshold(0, ignoreGapsInConsensusCalculation);
628 cs.setConsensus(hconsensus);
629 cs.setConservation(hconservation);
631 cs.alignmentChanged(alignment, hiddenRepSequences);
633 if (getColourAppliesToAllGroups())
635 for (SequenceGroup sg : getAlignment().getGroups())
642 sg.cs = cs.applyTo(sg, getHiddenRepSequences());
643 sg.setConsPercGaps(ConsPercGaps);
644 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
645 || cs instanceof Blosum62ColourScheme)
647 sg.cs.setThreshold(viewStyle.getThreshold(),
648 isIgnoreGapsConsensus());
653 sg.cs.setThreshold(0, isIgnoreGapsConsensus());
656 if (getConservationSelected())
658 sg.cs.setConservationApplied(true);
663 sg.cs.setConservation(null);
664 // sg.cs.setThreshold(0, getIgnoreGapsConsensus());
668 sg.recalcConservation();
672 sg.cs.alignmentChanged(sg, hiddenRepSequences);
679 public ColourSchemeI getGlobalColourScheme()
681 return globalColourScheme;
684 protected AlignmentAnnotation consensus;
686 protected AlignmentAnnotation complementConsensus;
688 protected AlignmentAnnotation strucConsensus;
690 protected AlignmentAnnotation conservation;
692 protected AlignmentAnnotation quality;
694 protected AlignmentAnnotation[] groupConsensus;
696 protected AlignmentAnnotation[] groupConservation;
699 * results of alignment consensus analysis for visible portion of view
701 protected Hashtable[] hconsensus = null;
704 * results of cDNA complement consensus visible portion of view
706 protected Hashtable[] hcomplementConsensus = null;
709 * results of secondary structure base pair consensus for visible portion of
712 protected Hashtable[] hStrucConsensus = null;
714 protected Conservation hconservation = null;
717 public void setConservation(Conservation cons)
719 hconservation = cons;
723 * percentage gaps allowed in a column before all amino acid properties should
724 * be considered unconserved
726 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
729 public int getConsPercGaps()
735 public void setSequenceConsensusHash(Hashtable[] hconsensus)
737 this.hconsensus = hconsensus;
741 public void setComplementConsensusHash(Hashtable[] hconsensus)
743 this.hcomplementConsensus = hconsensus;
747 public Hashtable[] getSequenceConsensusHash()
753 public Hashtable[] getComplementConsensusHash()
755 return hcomplementConsensus;
759 public Hashtable[] getRnaStructureConsensusHash()
761 return hStrucConsensus;
765 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
767 this.hStrucConsensus = hStrucConsensus;
772 public AlignmentAnnotation getAlignmentQualityAnnot()
778 public AlignmentAnnotation getAlignmentConservationAnnotation()
784 public AlignmentAnnotation getAlignmentConsensusAnnotation()
790 public AlignmentAnnotation getComplementConsensusAnnotation()
792 return complementConsensus;
796 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
798 return strucConsensus;
801 protected AlignCalcManagerI calculator = new AlignCalcManager();
804 * trigger update of conservation annotation
806 public void updateConservation(final AlignmentViewPanel ap)
808 // see note in mantis : issue number 8585
809 if (alignment.isNucleotide() || conservation == null
810 || !autoCalculateConsensus)
815 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
817 calculator.registerWorker(new jalview.workers.ConservationThread(
823 * trigger update of consensus annotation
825 public void updateConsensus(final AlignmentViewPanel ap)
827 // see note in mantis : issue number 8585
828 if (consensus == null || !autoCalculateConsensus)
832 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
834 calculator.registerWorker(new ConsensusThread(this, ap));
838 * A separate thread to compute cDNA consensus for a protein alignment
839 * which has mapping to cDNA
841 final AlignmentI al = this.getAlignment();
842 if (!al.isNucleotide() && al.getCodonFrames() != null
843 && !al.getCodonFrames().isEmpty())
846 * fudge - check first mapping is protein-to-nucleotide
847 * (we don't want to do this for protein-to-protein)
849 AlignedCodonFrame mapping = al.getCodonFrames().iterator().next();
850 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
851 if (mapping.getdnaToProt()[0].getFromRatio() == 3)
854 .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null)
857 .registerWorker(new ComplementConsensusThread(this, ap));
863 // --------START Structure Conservation
864 public void updateStrucConsensus(final AlignmentViewPanel ap)
866 if (autoCalculateStrucConsensus && strucConsensus == null
867 && alignment.isNucleotide() && alignment.hasRNAStructure())
869 // secondary structure has been added - so init the consensus line
873 // see note in mantis : issue number 8585
874 if (strucConsensus == null || !autoCalculateStrucConsensus)
878 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
880 calculator.registerWorker(new StrucConsensusThread(this, ap));
884 public boolean isCalcInProgress()
886 return calculator.isWorking();
890 public boolean isCalculationInProgress(
891 AlignmentAnnotation alignmentAnnotation)
893 if (!alignmentAnnotation.autoCalculated)
897 if (calculator.workingInvolvedWith(alignmentAnnotation))
899 // System.err.println("grey out ("+alignmentAnnotation.label+")");
906 public boolean isClosed()
908 // TODO: check that this isClosed is only true after panel is closed, not
909 // before it is fully constructed.
910 return alignment == null;
914 public AlignCalcManagerI getCalcManager()
920 * should conservation rows be shown for groups
922 protected boolean showGroupConservation = false;
925 * should consensus rows be shown for groups
927 protected boolean showGroupConsensus = false;
930 * should consensus profile be rendered by default
932 protected boolean showSequenceLogo = false;
935 * should consensus profile be rendered normalised to row height
937 protected boolean normaliseSequenceLogo = false;
940 * should consensus histograms be rendered by default
942 protected boolean showConsensusHistogram = true;
945 * @return the showConsensusProfile
948 public boolean isShowSequenceLogo()
950 return showSequenceLogo;
954 * @param showSequenceLogo
957 public void setShowSequenceLogo(boolean showSequenceLogo)
959 if (showSequenceLogo != this.showSequenceLogo)
961 // TODO: decouple settings setting from calculation when refactoring
962 // annotation update method from alignframe to viewport
963 this.showSequenceLogo = showSequenceLogo;
964 calculator.updateAnnotationFor(ConsensusThread.class);
965 calculator.updateAnnotationFor(ComplementConsensusThread.class);
966 calculator.updateAnnotationFor(StrucConsensusThread.class);
968 this.showSequenceLogo = showSequenceLogo;
972 * @param showConsensusHistogram
973 * the showConsensusHistogram to set
975 public void setShowConsensusHistogram(boolean showConsensusHistogram)
977 this.showConsensusHistogram = showConsensusHistogram;
981 * @return the showGroupConservation
983 public boolean isShowGroupConservation()
985 return showGroupConservation;
989 * @param showGroupConservation
990 * the showGroupConservation to set
992 public void setShowGroupConservation(boolean showGroupConservation)
994 this.showGroupConservation = showGroupConservation;
998 * @return the showGroupConsensus
1000 public boolean isShowGroupConsensus()
1002 return showGroupConsensus;
1006 * @param showGroupConsensus
1007 * the showGroupConsensus to set
1009 public void setShowGroupConsensus(boolean showGroupConsensus)
1011 this.showGroupConsensus = showGroupConsensus;
1016 * @return flag to indicate if the consensus histogram should be rendered by
1020 public boolean isShowConsensusHistogram()
1022 return this.showConsensusHistogram;
1026 * when set, updateAlignment will always ensure sequences are of equal length
1028 private boolean padGaps = false;
1031 * when set, alignment should be reordered according to a newly opened tree
1033 public boolean sortByTree = false;
1038 * @return null or the currently selected sequence region
1041 public SequenceGroup getSelectionGroup()
1043 return selectionGroup;
1047 * Set the selection group for this window.
1050 * - group holding references to sequences in this alignment view
1054 public void setSelectionGroup(SequenceGroup sg)
1056 selectionGroup = sg;
1059 public void setHiddenColumns(ColumnSelection colsel)
1061 this.colSel = colsel;
1065 public ColumnSelection getColumnSelection()
1071 public void setColumnSelection(ColumnSelection colSel)
1073 this.colSel = colSel;
1076 updateHiddenColumns();
1085 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1087 return hiddenRepSequences;
1091 public void setHiddenRepSequences(
1092 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1094 this.hiddenRepSequences = hiddenRepSequences;
1098 public boolean hasHiddenColumns()
1100 return colSel != null && colSel.hasHiddenColumns();
1103 public void updateHiddenColumns()
1105 // this method doesn't really do anything now. But - it could, since a
1106 // column Selection could be in the process of modification
1107 // hasHiddenColumns = colSel.hasHiddenColumns();
1111 public boolean hasHiddenRows()
1113 return alignment.getHiddenSequences().getSize() > 0;
1116 protected SequenceGroup selectionGroup;
1118 public void setSequenceSetId(String newid)
1120 if (sequenceSetID != null)
1123 .println("Warning - overwriting a sequenceSetId for a viewport!");
1125 sequenceSetID = new String(newid);
1129 public String getSequenceSetId()
1131 if (sequenceSetID == null)
1133 sequenceSetID = alignment.hashCode() + "";
1136 return sequenceSetID;
1140 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1143 protected String viewId = null;
1146 public String getViewId()
1150 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1155 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1157 ignoreGapsInConsensusCalculation = b;
1160 updateConsensus(ap);
1161 if (globalColourScheme != null)
1163 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1164 ignoreGapsInConsensusCalculation);
1170 private long sgrouphash = -1, colselhash = -1;
1173 * checks current SelectionGroup against record of last hash value, and
1177 * update the record of last hash value
1179 * @return true if SelectionGroup changed since last call (when b is true)
1181 public boolean isSelectionGroupChanged(boolean b)
1183 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1184 : selectionGroup.hashCode();
1185 if (hc != -1 && hc != sgrouphash)
1197 * checks current colsel against record of last hash value, and optionally
1201 * update the record of last hash value
1202 * @return true if colsel changed since last call (when b is true)
1204 public boolean isColSelChanged(boolean b)
1206 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel
1208 if (hc != -1 && hc != colselhash)
1220 public boolean isIgnoreGapsConsensus()
1222 return ignoreGapsInConsensusCalculation;
1225 // / property change stuff
1227 // JBPNote Prolly only need this in the applet version.
1228 private final java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
1231 protected boolean showConservation = true;
1233 protected boolean showQuality = true;
1235 protected boolean showConsensus = true;
1237 private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
1239 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1241 protected boolean showAutocalculatedAbove;
1244 * when set, view will scroll to show the highlighted position
1246 private boolean followHighlight = true;
1248 // TODO private with getters and setters?
1249 public int startRes;
1253 public int startSeq;
1258 * Property change listener for changes in alignment
1263 public void addPropertyChangeListener(
1264 java.beans.PropertyChangeListener listener)
1266 changeSupport.addPropertyChangeListener(listener);
1275 public void removePropertyChangeListener(
1276 java.beans.PropertyChangeListener listener)
1278 changeSupport.removePropertyChangeListener(listener);
1282 * Property change listener for changes in alignment
1291 public void firePropertyChange(String prop, Object oldvalue,
1294 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1297 // common hide/show column stuff
1299 public void hideSelectedColumns()
1301 if (colSel.isEmpty())
1306 colSel.hideSelectedColumns();
1307 setSelectionGroup(null);
1311 public void hideColumns(int start, int end)
1315 colSel.hideColumns(start);
1319 colSel.hideColumns(start, end);
1323 public void showColumn(int col)
1325 colSel.revealHiddenColumns(col);
1329 public void showAllHiddenColumns()
1331 colSel.revealAllHiddenColumns();
1334 // common hide/show seq stuff
1335 public void showAllHiddenSeqs()
1337 if (alignment.getHiddenSequences().getSize() > 0)
1339 if (selectionGroup == null)
1341 selectionGroup = new SequenceGroup();
1342 selectionGroup.setEndRes(alignment.getWidth() - 1);
1344 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1345 hiddenRepSequences);
1346 for (SequenceI seq : tmp)
1348 selectionGroup.addSequence(seq, false);
1349 setSequenceAnnotationsVisible(seq, true);
1352 hiddenRepSequences = null;
1354 firePropertyChange("alignment", null, alignment.getSequences());
1355 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1361 public void showSequence(int index)
1363 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1364 index, hiddenRepSequences);
1367 if (selectionGroup == null)
1369 selectionGroup = new SequenceGroup();
1370 selectionGroup.setEndRes(alignment.getWidth() - 1);
1373 for (SequenceI seq : tmp)
1375 selectionGroup.addSequence(seq, false);
1376 setSequenceAnnotationsVisible(seq, true);
1378 firePropertyChange("alignment", null, alignment.getSequences());
1383 public void hideAllSelectedSeqs()
1385 if (selectionGroup == null || selectionGroup.getSize() < 1)
1390 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1394 setSelectionGroup(null);
1397 public void hideSequence(SequenceI[] seq)
1401 for (int i = 0; i < seq.length; i++)
1403 alignment.getHiddenSequences().hideSequence(seq[i]);
1404 setSequenceAnnotationsVisible(seq[i], false);
1406 firePropertyChange("alignment", null, alignment.getSequences());
1411 * Set visibility for any annotations for the given sequence.
1415 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1418 for (AlignmentAnnotation ann : alignment.getAlignmentAnnotation())
1420 if (ann.sequenceRef == sequenceI)
1422 ann.visible = visible;
1427 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1429 int sSize = sg.getSize();
1435 if (hiddenRepSequences == null)
1437 hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
1440 hiddenRepSequences.put(repSequence, sg);
1442 // Hide all sequences except the repSequence
1443 SequenceI[] seqs = new SequenceI[sSize - 1];
1445 for (int i = 0; i < sSize; i++)
1447 if (sg.getSequenceAt(i) != repSequence)
1449 if (index == sSize - 1)
1454 seqs[index++] = sg.getSequenceAt(i);
1457 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1458 sg.setHidereps(true); // note: not done in 2.7applet
1463 public boolean isHiddenRepSequence(SequenceI seq)
1465 return alignment.getSeqrep() == seq
1466 || (hiddenRepSequences != null && hiddenRepSequences
1470 public SequenceGroup getRepresentedSequences(SequenceI seq)
1472 return (SequenceGroup) (hiddenRepSequences == null ? null
1473 : hiddenRepSequences.get(seq));
1477 public int adjustForHiddenSeqs(int alignmentIndex)
1479 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1484 public void invertColumnSelection()
1486 colSel.invertColumnSelection(0, alignment.getWidth());
1490 public SequenceI[] getSelectionAsNewSequence()
1492 SequenceI[] sequences;
1493 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1494 // this was the only caller in the applet for this method
1495 // JBPNote: in applet, this method returned references to the alignment
1496 // sequences, and it did not honour the presence/absence of annotation
1497 // attached to the alignment (probably!)
1498 if (selectionGroup == null || selectionGroup.getSize() == 0)
1500 sequences = alignment.getSequencesArray();
1501 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1502 for (int i = 0; i < sequences.length; i++)
1504 // construct new sequence with subset of visible annotation
1505 sequences[i] = new Sequence(sequences[i], annots);
1510 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1517 public SequenceI[] getSequenceSelection()
1519 SequenceI[] sequences = null;
1520 if (selectionGroup != null)
1522 sequences = selectionGroup.getSequencesInOrder(alignment);
1524 if (sequences == null)
1526 sequences = alignment.getSequencesArray();
1532 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1534 return new CigarArray(alignment, colSel,
1535 (selectedRegionOnly ? selectionGroup : null));
1539 public jalview.datamodel.AlignmentView getAlignmentView(
1540 boolean selectedOnly)
1542 return getAlignmentView(selectedOnly, false);
1546 public jalview.datamodel.AlignmentView getAlignmentView(
1547 boolean selectedOnly, boolean markGroups)
1549 return new AlignmentView(alignment, colSel, selectionGroup,
1550 colSel != null && colSel.hasHiddenColumns(), selectedOnly,
1555 public String[] getViewAsString(boolean selectedRegionOnly)
1557 String[] selection = null;
1558 SequenceI[] seqs = null;
1560 int start = 0, end = 0;
1561 if (selectedRegionOnly && selectionGroup != null)
1563 iSize = selectionGroup.getSize();
1564 seqs = selectionGroup.getSequencesInOrder(alignment);
1565 start = selectionGroup.getStartRes();
1566 end = selectionGroup.getEndRes() + 1;
1570 if (hasHiddenRows())
1572 iSize = alignment.getHiddenSequences().getFullAlignment()
1574 seqs = alignment.getHiddenSequences().getFullAlignment()
1575 .getSequencesArray();
1576 end = alignment.getHiddenSequences().getFullAlignment().getWidth();
1580 iSize = alignment.getHeight();
1581 seqs = alignment.getSequencesArray();
1582 end = alignment.getWidth();
1586 selection = new String[iSize];
1587 if (colSel != null && colSel.hasHiddenColumns())
1589 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1593 for (i = 0; i < iSize; i++)
1595 selection[i] = seqs[i].getSequenceAsString(start, end);
1603 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1605 ArrayList<int[]> regions = new ArrayList<int[]>();
1611 if (colSel != null && colSel.hasHiddenColumns())
1615 start = colSel.adjustForHiddenColumns(start);
1618 end = colSel.getHiddenBoundaryRight(start);
1629 regions.add(new int[] { start, end });
1631 if (colSel != null && colSel.hasHiddenColumns())
1633 start = colSel.adjustForHiddenColumns(end);
1634 start = colSel.getHiddenBoundaryLeft(start) + 1;
1636 } while (end < max);
1638 int[][] startEnd = new int[regions.size()][2];
1644 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1645 boolean selectedOnly)
1647 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1648 AlignmentAnnotation[] aa;
1649 if ((aa = alignment.getAlignmentAnnotation()) != null)
1651 for (AlignmentAnnotation annot : aa)
1653 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1654 if (selectedOnly && selectionGroup != null)
1656 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(),
1657 selectionGroup.getEndRes(), clone);
1661 colSel.makeVisibleAnnotation(clone);
1670 public boolean isPadGaps()
1676 public void setPadGaps(boolean padGaps)
1678 this.padGaps = padGaps;
1682 * apply any post-edit constraints and trigger any calculations needed after
1683 * an edit has been performed on the alignment
1688 public void alignmentChanged(AlignmentViewPanel ap)
1692 alignment.padGaps();
1694 if (autoCalculateConsensus)
1696 updateConsensus(ap);
1698 if (hconsensus != null && autoCalculateConsensus)
1700 updateConservation(ap);
1702 if (autoCalculateStrucConsensus)
1704 updateStrucConsensus(ap);
1707 // Reset endRes of groups if beyond alignment width
1708 int alWidth = alignment.getWidth();
1709 List<SequenceGroup> groups = alignment.getGroups();
1712 for (SequenceGroup sg : groups)
1714 if (sg.getEndRes() > alWidth)
1716 sg.setEndRes(alWidth - 1);
1721 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1723 selectionGroup.setEndRes(alWidth - 1);
1726 resetAllColourSchemes();
1727 calculator.restartWorkers();
1728 // alignment.adjustSequenceAnnotations();
1732 * reset scope and do calculations for all applied colourschemes on alignment
1734 void resetAllColourSchemes()
1736 ColourSchemeI cs = globalColourScheme;
1739 cs.alignmentChanged(alignment, hiddenRepSequences);
1741 cs.setConsensus(hconsensus);
1742 if (cs.conservationApplied())
1744 cs.setConservation(Conservation.calculateConservation("All",
1745 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1746 alignment.getWidth(), false, getConsPercGaps(), false));
1750 for (SequenceGroup sg : alignment.getGroups())
1754 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1756 sg.recalcConservation();
1760 protected void initAutoAnnotation()
1762 // TODO: add menu option action that nulls or creates consensus object
1763 // depending on if the user wants to see the annotation or not in a
1764 // specific alignment
1766 if (hconsensus == null && !isDataset)
1768 if (!alignment.isNucleotide())
1777 consensus = new AlignmentAnnotation("Consensus", "PID",
1778 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1779 initConsensus(consensus);
1781 initComplementConsensus();
1786 * If this is a protein alignment and there are mappings to cDNA, add the cDNA
1787 * consensus annotation.
1789 public void initComplementConsensus()
1791 if (!alignment.isNucleotide())
1793 final List<AlignedCodonFrame> codonMappings = alignment
1795 if (codonMappings != null && !codonMappings.isEmpty())
1797 // fudge: check mappings are not protein-to-protein
1799 AlignedCodonFrame mapping = codonMappings.iterator().next();
1800 if (mapping.getdnaToProt()[0].getFromRatio() == 3)
1802 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1803 "PID for cDNA", new Annotation[1], 0f, 100f,
1804 AlignmentAnnotation.BAR_GRAPH);
1805 initConsensus(complementConsensus);
1811 private void initConsensus(AlignmentAnnotation aa)
1814 aa.autoCalculated = true;
1818 alignment.addAnnotation(aa);
1822 private void initConservation()
1824 if (showConservation)
1826 if (conservation == null)
1828 conservation = new AlignmentAnnotation("Conservation",
1829 "Conservation of total alignment less than "
1830 + getConsPercGaps() + "% gaps", new Annotation[1],
1831 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1832 conservation.hasText = true;
1833 conservation.autoCalculated = true;
1834 alignment.addAnnotation(conservation);
1839 private void initQuality()
1843 if (quality == null)
1845 quality = new AlignmentAnnotation("Quality",
1846 "Alignment Quality based on Blosum62 scores",
1847 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1848 quality.hasText = true;
1849 quality.autoCalculated = true;
1850 alignment.addAnnotation(quality);
1855 private void initRNAStructure()
1857 if (alignment.hasRNAStructure() && strucConsensus == null)
1859 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1860 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1861 strucConsensus.hasText = true;
1862 strucConsensus.autoCalculated = true;
1866 alignment.addAnnotation(strucConsensus);
1874 * @see jalview.api.AlignViewportI#calcPanelHeight()
1877 public int calcPanelHeight()
1879 // setHeight of panels
1880 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
1882 int charHeight = getCharHeight();
1885 BitSet graphgrp = new BitSet();
1886 for (AlignmentAnnotation aa : anns)
1890 System.err.println("Null annotation row: ignoring.");
1897 if (aa.graphGroup > -1)
1899 if (graphgrp.get(aa.graphGroup))
1905 graphgrp.set(aa.graphGroup);
1912 aa.height += charHeight;
1922 aa.height += aa.graphHeight;
1930 height += aa.height;
1942 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1943 boolean preserveNewGroupSettings)
1945 boolean updateCalcs = false;
1946 boolean conv = isShowGroupConservation();
1947 boolean cons = isShowGroupConsensus();
1948 boolean showprf = isShowSequenceLogo();
1949 boolean showConsHist = isShowConsensusHistogram();
1950 boolean normLogo = isNormaliseSequenceLogo();
1953 * TODO reorder the annotation rows according to group/sequence ordering on
1956 boolean sortg = true;
1958 // remove old automatic annotation
1959 // add any new annotation
1961 // intersect alignment annotation with alignment groups
1963 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
1964 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
1967 for (int an = 0; an < aan.length; an++)
1969 if (aan[an].autoCalculated && aan[an].groupRef != null)
1971 oldrfs.add(aan[an].groupRef);
1972 alignment.deleteAnnotation(aan[an], false);
1976 if (alignment.getGroups() != null)
1978 for (SequenceGroup sg : alignment.getGroups())
1980 updateCalcs = false;
1981 if (applyGlobalSettings
1982 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
1984 // set defaults for this group's conservation/consensus
1985 sg.setshowSequenceLogo(showprf);
1986 sg.setShowConsensusHistogram(showConsHist);
1987 sg.setNormaliseSequenceLogo(normLogo);
1992 alignment.addAnnotation(sg.getConservationRow(), 0);
1997 alignment.addAnnotation(sg.getConsensus(), 0);
1999 // refresh the annotation rows
2002 sg.recalcConservation();
2010 public boolean isDisplayReferenceSeq()
2012 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2016 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2018 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2022 public boolean isColourByReferenceSeq()
2024 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2028 public Color getSequenceColour(SequenceI seq)
2030 Color sqc = sequenceColours.get(seq);
2031 return (sqc == null ? Color.white : sqc);
2035 public void setSequenceColour(SequenceI seq, Color col)
2039 sequenceColours.remove(seq);
2043 sequenceColours.put(seq, col);
2048 public void updateSequenceIdColours()
2050 for (SequenceGroup sg : alignment.getGroups())
2052 if (sg.idColour != null)
2054 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2056 sequenceColours.put(s, sg.idColour);
2063 public void clearSequenceColours()
2065 sequenceColours.clear();
2069 public AlignViewportI getCodingComplement()
2071 return this.codingComplement;
2075 * Set this as the (cDna/protein) complement of the given viewport. Also
2076 * ensures the reverse relationship is set on the given viewport.
2079 public void setCodingComplement(AlignViewportI av)
2083 System.err.println("Ignoring recursive setCodingComplement request");
2087 this.codingComplement = av;
2088 // avoid infinite recursion!
2089 if (av.getCodingComplement() != this)
2091 av.setCodingComplement(this);
2097 public boolean isNucleotide()
2099 return getAlignment() == null ? false : getAlignment().isNucleotide();
2103 public FeaturesDisplayedI getFeaturesDisplayed()
2105 return featuresDisplayed;
2109 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2111 featuresDisplayed = featuresDisplayedI;
2115 public boolean areFeaturesDisplayed()
2117 return featuresDisplayed != null
2118 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2125 * features are displayed if true
2128 public void setShowSequenceFeatures(boolean b)
2130 viewStyle.setShowSequenceFeatures(b);
2134 public boolean isShowSequenceFeatures()
2136 return viewStyle.isShowSequenceFeatures();
2140 public void setShowSequenceFeaturesHeight(boolean selected)
2142 viewStyle.setShowSequenceFeaturesHeight(selected);
2146 public boolean isShowSequenceFeaturesHeight()
2148 return viewStyle.isShowSequenceFeaturesHeight();
2152 public void setShowAnnotation(boolean b)
2154 viewStyle.setShowAnnotation(b);
2158 public boolean isShowAnnotation()
2160 return viewStyle.isShowAnnotation();
2164 public boolean isRightAlignIds()
2166 return viewStyle.isRightAlignIds();
2170 public void setRightAlignIds(boolean rightAlignIds)
2172 viewStyle.setRightAlignIds(rightAlignIds);
2176 public boolean getConservationSelected()
2178 return viewStyle.getConservationSelected();
2182 public void setShowBoxes(boolean state)
2184 viewStyle.setShowBoxes(state);
2189 * @see jalview.api.ViewStyleI#getTextColour()
2192 public Color getTextColour()
2194 return viewStyle.getTextColour();
2199 * @see jalview.api.ViewStyleI#getTextColour2()
2202 public Color getTextColour2()
2204 return viewStyle.getTextColour2();
2209 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2212 public int getThresholdTextColour()
2214 return viewStyle.getThresholdTextColour();
2219 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2222 public boolean isConservationColourSelected()
2224 return viewStyle.isConservationColourSelected();
2229 * @see jalview.api.ViewStyleI#isRenderGaps()
2232 public boolean isRenderGaps()
2234 return viewStyle.isRenderGaps();
2239 * @see jalview.api.ViewStyleI#isShowColourText()
2242 public boolean isShowColourText()
2244 return viewStyle.isShowColourText();
2248 * @param conservationColourSelected
2249 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2252 public void setConservationColourSelected(
2253 boolean conservationColourSelected)
2255 viewStyle.setConservationColourSelected(conservationColourSelected);
2259 * @param showColourText
2260 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2263 public void setShowColourText(boolean showColourText)
2265 viewStyle.setShowColourText(showColourText);
2270 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2273 public void setTextColour(Color textColour)
2275 viewStyle.setTextColour(textColour);
2279 * @param thresholdTextColour
2280 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2283 public void setThresholdTextColour(int thresholdTextColour)
2285 viewStyle.setThresholdTextColour(thresholdTextColour);
2289 * @param textColour2
2290 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2293 public void setTextColour2(Color textColour2)
2295 viewStyle.setTextColour2(textColour2);
2299 public ViewStyleI getViewStyle()
2301 return new ViewStyle(viewStyle);
2305 public void setViewStyle(ViewStyleI settingsForView)
2307 viewStyle = new ViewStyle(settingsForView);
2311 public boolean sameStyle(ViewStyleI them)
2313 return viewStyle.sameStyle(them);
2318 * @see jalview.api.ViewStyleI#getIdWidth()
2321 public int getIdWidth()
2323 return viewStyle.getIdWidth();
2328 * @see jalview.api.ViewStyleI#setIdWidth(int)
2331 public void setIdWidth(int i)
2333 viewStyle.setIdWidth(i);
2338 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2341 public boolean isCentreColumnLabels()
2343 return viewStyle.isCentreColumnLabels();
2347 * @param centreColumnLabels
2348 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2351 public void setCentreColumnLabels(boolean centreColumnLabels)
2353 viewStyle.setCentreColumnLabels(centreColumnLabels);
2358 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2361 public void setShowDBRefs(boolean showdbrefs)
2363 viewStyle.setShowDBRefs(showdbrefs);
2368 * @see jalview.api.ViewStyleI#isShowDBRefs()
2371 public boolean isShowDBRefs()
2373 return viewStyle.isShowDBRefs();
2378 * @see jalview.api.ViewStyleI#isShowNPFeats()
2381 public boolean isShowNPFeats()
2383 return viewStyle.isShowNPFeats();
2387 * @param shownpfeats
2388 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2391 public void setShowNPFeats(boolean shownpfeats)
2393 viewStyle.setShowNPFeats(shownpfeats);
2396 public abstract StructureSelectionManager getStructureSelectionManager();
2399 * Add one command to the command history list.
2403 public void addToHistoryList(CommandI command)
2405 if (this.historyList != null)
2407 this.historyList.push(command);
2408 broadcastCommand(command, false);
2412 protected void broadcastCommand(CommandI command, boolean undo)
2414 getStructureSelectionManager().commandPerformed(command, undo,
2419 * Add one command to the command redo list.
2423 public void addToRedoList(CommandI command)
2425 if (this.redoList != null)
2427 this.redoList.push(command);
2429 broadcastCommand(command, true);
2433 * Clear the command redo list.
2435 public void clearRedoList()
2437 if (this.redoList != null)
2439 this.redoList.clear();
2443 public void setHistoryList(Deque<CommandI> list)
2445 this.historyList = list;
2448 public Deque<CommandI> getHistoryList()
2450 return this.historyList;
2453 public void setRedoList(Deque<CommandI> list)
2455 this.redoList = list;
2458 public Deque<CommandI> getRedoList()
2460 return this.redoList;
2464 public VamsasSource getVamsasSource()
2469 public SequenceAnnotationOrder getSortAnnotationsBy()
2471 return sortAnnotationsBy;
2474 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2476 this.sortAnnotationsBy = sortAnnotationsBy;
2479 public boolean isShowAutocalculatedAbove()
2481 return showAutocalculatedAbove;
2484 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2486 this.showAutocalculatedAbove = showAutocalculatedAbove;
2490 public boolean isScaleProteinAsCdna()
2492 return viewStyle.isScaleProteinAsCdna();
2496 public void setScaleProteinAsCdna(boolean b)
2498 viewStyle.setScaleProteinAsCdna(b);
2502 * @return true if view should scroll to show the highlighted region of a
2507 public final boolean isFollowHighlight()
2509 return followHighlight;
2513 public final void setFollowHighlight(boolean b)
2515 this.followHighlight = b;
2518 public int getStartRes()
2524 public int getEndRes()
2529 public int getStartSeq()
2534 public void setStartRes(int res)
2536 this.startRes = res;
2539 public void setStartSeq(int seq)
2541 this.startSeq = seq;
2544 public void setEndRes(int res)
2546 if (res > alignment.getWidth() - 1)
2548 // log.System.out.println(" Corrected res from " + res + " to maximum " +
2549 // (alignment.getWidth()-1));
2550 res = alignment.getWidth() - 1;
2559 public void setEndSeq(int seq)
2561 if (seq > alignment.getHeight())
2563 seq = alignment.getHeight();
2572 public int getEndSeq()
2578 * Helper method to populate the SearchResults with the location in the
2579 * complementary alignment to scroll to, in order to match this one.
2582 * the SearchResults to add to
2583 * @return the offset (below top of visible region) of the matched sequence
2585 protected int findComplementScrollTarget(SearchResults sr)
2587 final AlignViewportI complement = getCodingComplement();
2588 if (complement == null || !complement.isFollowHighlight())
2592 boolean iAmProtein = !getAlignment().isNucleotide();
2593 AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement
2595 if (proteinAlignment == null)
2599 final List<AlignedCodonFrame> mappings = proteinAlignment
2603 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2604 * residue in the middle column of the visible region. Scroll the
2605 * complementary alignment to line up the corresponding residue.
2608 SequenceI sequence = null;
2611 * locate 'middle' column (true middle if an odd number visible, left of
2612 * middle if an even number visible)
2614 int middleColumn = getStartRes() + (getEndRes() - getStartRes()) / 2;
2615 final HiddenSequences hiddenSequences = getAlignment()
2616 .getHiddenSequences();
2619 * searching to the bottom of the alignment gives smoother scrolling across
2620 * all gapped visible regions
2622 int lastSeq = alignment.getHeight() - 1;
2623 for (int seqNo = getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2625 sequence = getAlignment().getSequenceAt(seqNo);
2626 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2630 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2634 List<AlignedCodonFrame> seqMappings = MappingUtils
2635 .findMappingsForSequence(sequence, mappings);
2636 if (!seqMappings.isEmpty())
2642 if (sequence == null)
2645 * No ungapped mapped sequence in middle column - do nothing
2649 MappingUtils.addSearchResults(sr, sequence,
2650 sequence.findPosition(middleColumn), mappings);