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 iSize = alignment.getHeight();
1571 seqs = alignment.getSequencesArray();
1572 end = alignment.getWidth();
1575 selection = new String[iSize];
1576 if (colSel != null && colSel.hasHiddenColumns())
1578 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1582 for (i = 0; i < iSize; i++)
1584 selection[i] = seqs[i].getSequenceAsString(start, end);
1592 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1594 ArrayList<int[]> regions = new ArrayList<int[]>();
1600 if (colSel != null && colSel.hasHiddenColumns())
1604 start = colSel.adjustForHiddenColumns(start);
1607 end = colSel.getHiddenBoundaryRight(start);
1618 regions.add(new int[] { start, end });
1620 if (colSel != null && colSel.hasHiddenColumns())
1622 start = colSel.adjustForHiddenColumns(end);
1623 start = colSel.getHiddenBoundaryLeft(start) + 1;
1625 } while (end < max);
1627 int[][] startEnd = new int[regions.size()][2];
1633 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1634 boolean selectedOnly)
1636 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1637 AlignmentAnnotation[] aa;
1638 if ((aa = alignment.getAlignmentAnnotation()) != null)
1640 for (AlignmentAnnotation annot : aa)
1642 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1643 if (selectedOnly && selectionGroup != null)
1645 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(),
1646 selectionGroup.getEndRes(), clone);
1650 colSel.makeVisibleAnnotation(clone);
1659 public boolean isPadGaps()
1665 public void setPadGaps(boolean padGaps)
1667 this.padGaps = padGaps;
1671 * apply any post-edit constraints and trigger any calculations needed after
1672 * an edit has been performed on the alignment
1677 public void alignmentChanged(AlignmentViewPanel ap)
1681 alignment.padGaps();
1683 if (autoCalculateConsensus)
1685 updateConsensus(ap);
1687 if (hconsensus != null && autoCalculateConsensus)
1689 updateConservation(ap);
1691 if (autoCalculateStrucConsensus)
1693 updateStrucConsensus(ap);
1696 // Reset endRes of groups if beyond alignment width
1697 int alWidth = alignment.getWidth();
1698 List<SequenceGroup> groups = alignment.getGroups();
1701 for (SequenceGroup sg : groups)
1703 if (sg.getEndRes() > alWidth)
1705 sg.setEndRes(alWidth - 1);
1710 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1712 selectionGroup.setEndRes(alWidth - 1);
1715 resetAllColourSchemes();
1716 calculator.restartWorkers();
1717 // alignment.adjustSequenceAnnotations();
1721 * reset scope and do calculations for all applied colourschemes on alignment
1723 void resetAllColourSchemes()
1725 ColourSchemeI cs = globalColourScheme;
1728 cs.alignmentChanged(alignment, hiddenRepSequences);
1730 cs.setConsensus(hconsensus);
1731 if (cs.conservationApplied())
1733 cs.setConservation(Conservation.calculateConservation("All",
1734 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1735 alignment.getWidth(), false, getConsPercGaps(), false));
1739 for (SequenceGroup sg : alignment.getGroups())
1743 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1745 sg.recalcConservation();
1749 protected void initAutoAnnotation()
1751 // TODO: add menu option action that nulls or creates consensus object
1752 // depending on if the user wants to see the annotation or not in a
1753 // specific alignment
1755 if (hconsensus == null && !isDataset)
1757 if (!alignment.isNucleotide())
1766 consensus = new AlignmentAnnotation("Consensus", "PID",
1767 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1768 initConsensus(consensus);
1770 initComplementConsensus();
1775 * If this is a protein alignment and there are mappings to cDNA, add the cDNA
1776 * consensus annotation.
1778 public void initComplementConsensus()
1780 if (!alignment.isNucleotide())
1782 final List<AlignedCodonFrame> codonMappings = alignment
1784 if (codonMappings != null && !codonMappings.isEmpty())
1786 // fudge: check mappings are not protein-to-protein
1788 AlignedCodonFrame mapping = codonMappings.iterator().next();
1789 if (mapping.getdnaToProt()[0].getFromRatio() == 3)
1791 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1792 "PID for cDNA", new Annotation[1], 0f, 100f,
1793 AlignmentAnnotation.BAR_GRAPH);
1794 initConsensus(complementConsensus);
1800 private void initConsensus(AlignmentAnnotation aa)
1803 aa.autoCalculated = true;
1807 alignment.addAnnotation(aa);
1811 private void initConservation()
1813 if (showConservation)
1815 if (conservation == null)
1817 conservation = new AlignmentAnnotation("Conservation",
1818 "Conservation of total alignment less than "
1819 + getConsPercGaps() + "% gaps", new Annotation[1],
1820 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1821 conservation.hasText = true;
1822 conservation.autoCalculated = true;
1823 alignment.addAnnotation(conservation);
1828 private void initQuality()
1832 if (quality == null)
1834 quality = new AlignmentAnnotation("Quality",
1835 "Alignment Quality based on Blosum62 scores",
1836 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1837 quality.hasText = true;
1838 quality.autoCalculated = true;
1839 alignment.addAnnotation(quality);
1844 private void initRNAStructure()
1846 if (alignment.hasRNAStructure() && strucConsensus == null)
1848 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1849 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1850 strucConsensus.hasText = true;
1851 strucConsensus.autoCalculated = true;
1855 alignment.addAnnotation(strucConsensus);
1863 * @see jalview.api.AlignViewportI#calcPanelHeight()
1866 public int calcPanelHeight()
1868 // setHeight of panels
1869 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
1871 int charHeight = getCharHeight();
1874 BitSet graphgrp = new BitSet();
1875 for (AlignmentAnnotation aa : anns)
1879 System.err.println("Null annotation row: ignoring.");
1886 if (aa.graphGroup > -1)
1888 if (graphgrp.get(aa.graphGroup))
1894 graphgrp.set(aa.graphGroup);
1901 aa.height += charHeight;
1911 aa.height += aa.graphHeight;
1919 height += aa.height;
1931 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1932 boolean preserveNewGroupSettings)
1934 boolean updateCalcs = false;
1935 boolean conv = isShowGroupConservation();
1936 boolean cons = isShowGroupConsensus();
1937 boolean showprf = isShowSequenceLogo();
1938 boolean showConsHist = isShowConsensusHistogram();
1939 boolean normLogo = isNormaliseSequenceLogo();
1942 * TODO reorder the annotation rows according to group/sequence ordering on
1945 boolean sortg = true;
1947 // remove old automatic annotation
1948 // add any new annotation
1950 // intersect alignment annotation with alignment groups
1952 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
1953 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
1956 for (int an = 0; an < aan.length; an++)
1958 if (aan[an].autoCalculated && aan[an].groupRef != null)
1960 oldrfs.add(aan[an].groupRef);
1961 alignment.deleteAnnotation(aan[an], false);
1965 if (alignment.getGroups() != null)
1967 for (SequenceGroup sg : alignment.getGroups())
1969 updateCalcs = false;
1970 if (applyGlobalSettings
1971 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
1973 // set defaults for this group's conservation/consensus
1974 sg.setshowSequenceLogo(showprf);
1975 sg.setShowConsensusHistogram(showConsHist);
1976 sg.setNormaliseSequenceLogo(normLogo);
1981 alignment.addAnnotation(sg.getConservationRow(), 0);
1986 alignment.addAnnotation(sg.getConsensus(), 0);
1988 // refresh the annotation rows
1991 sg.recalcConservation();
1999 public boolean isDisplayReferenceSeq()
2001 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2005 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2007 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2011 public boolean isColourByReferenceSeq()
2013 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2017 public Color getSequenceColour(SequenceI seq)
2019 Color sqc = sequenceColours.get(seq);
2020 return (sqc == null ? Color.white : sqc);
2024 public void setSequenceColour(SequenceI seq, Color col)
2028 sequenceColours.remove(seq);
2032 sequenceColours.put(seq, col);
2037 public void updateSequenceIdColours()
2039 for (SequenceGroup sg : alignment.getGroups())
2041 if (sg.idColour != null)
2043 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2045 sequenceColours.put(s, sg.idColour);
2052 public void clearSequenceColours()
2054 sequenceColours.clear();
2058 public AlignViewportI getCodingComplement()
2060 return this.codingComplement;
2064 * Set this as the (cDna/protein) complement of the given viewport. Also
2065 * ensures the reverse relationship is set on the given viewport.
2068 public void setCodingComplement(AlignViewportI av)
2072 System.err.println("Ignoring recursive setCodingComplement request");
2076 this.codingComplement = av;
2077 // avoid infinite recursion!
2078 if (av.getCodingComplement() != this)
2080 av.setCodingComplement(this);
2086 public boolean isNucleotide()
2088 return getAlignment() == null ? false : getAlignment().isNucleotide();
2092 public FeaturesDisplayedI getFeaturesDisplayed()
2094 return featuresDisplayed;
2098 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2100 featuresDisplayed = featuresDisplayedI;
2104 public boolean areFeaturesDisplayed()
2106 return featuresDisplayed != null
2107 && featuresDisplayed.getRegisterdFeaturesCount() > 0;
2114 * features are displayed if true
2117 public void setShowSequenceFeatures(boolean b)
2119 viewStyle.setShowSequenceFeatures(b);
2123 public boolean isShowSequenceFeatures()
2125 return viewStyle.isShowSequenceFeatures();
2129 public void setShowSequenceFeaturesHeight(boolean selected)
2131 viewStyle.setShowSequenceFeaturesHeight(selected);
2135 public boolean isShowSequenceFeaturesHeight()
2137 return viewStyle.isShowSequenceFeaturesHeight();
2141 public void setShowAnnotation(boolean b)
2143 viewStyle.setShowAnnotation(b);
2147 public boolean isShowAnnotation()
2149 return viewStyle.isShowAnnotation();
2153 public boolean isRightAlignIds()
2155 return viewStyle.isRightAlignIds();
2159 public void setRightAlignIds(boolean rightAlignIds)
2161 viewStyle.setRightAlignIds(rightAlignIds);
2165 public boolean getConservationSelected()
2167 return viewStyle.getConservationSelected();
2171 public void setShowBoxes(boolean state)
2173 viewStyle.setShowBoxes(state);
2178 * @see jalview.api.ViewStyleI#getTextColour()
2181 public Color getTextColour()
2183 return viewStyle.getTextColour();
2188 * @see jalview.api.ViewStyleI#getTextColour2()
2191 public Color getTextColour2()
2193 return viewStyle.getTextColour2();
2198 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2201 public int getThresholdTextColour()
2203 return viewStyle.getThresholdTextColour();
2208 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2211 public boolean isConservationColourSelected()
2213 return viewStyle.isConservationColourSelected();
2218 * @see jalview.api.ViewStyleI#isRenderGaps()
2221 public boolean isRenderGaps()
2223 return viewStyle.isRenderGaps();
2228 * @see jalview.api.ViewStyleI#isShowColourText()
2231 public boolean isShowColourText()
2233 return viewStyle.isShowColourText();
2237 * @param conservationColourSelected
2238 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2241 public void setConservationColourSelected(
2242 boolean conservationColourSelected)
2244 viewStyle.setConservationColourSelected(conservationColourSelected);
2248 * @param showColourText
2249 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2252 public void setShowColourText(boolean showColourText)
2254 viewStyle.setShowColourText(showColourText);
2259 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2262 public void setTextColour(Color textColour)
2264 viewStyle.setTextColour(textColour);
2268 * @param thresholdTextColour
2269 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2272 public void setThresholdTextColour(int thresholdTextColour)
2274 viewStyle.setThresholdTextColour(thresholdTextColour);
2278 * @param textColour2
2279 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2282 public void setTextColour2(Color textColour2)
2284 viewStyle.setTextColour2(textColour2);
2288 public ViewStyleI getViewStyle()
2290 return new ViewStyle(viewStyle);
2294 public void setViewStyle(ViewStyleI settingsForView)
2296 viewStyle = new ViewStyle(settingsForView);
2300 public boolean sameStyle(ViewStyleI them)
2302 return viewStyle.sameStyle(them);
2307 * @see jalview.api.ViewStyleI#getIdWidth()
2310 public int getIdWidth()
2312 return viewStyle.getIdWidth();
2317 * @see jalview.api.ViewStyleI#setIdWidth(int)
2320 public void setIdWidth(int i)
2322 viewStyle.setIdWidth(i);
2327 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2330 public boolean isCentreColumnLabels()
2332 return viewStyle.isCentreColumnLabels();
2336 * @param centreColumnLabels
2337 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2340 public void setCentreColumnLabels(boolean centreColumnLabels)
2342 viewStyle.setCentreColumnLabels(centreColumnLabels);
2347 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2350 public void setShowDBRefs(boolean showdbrefs)
2352 viewStyle.setShowDBRefs(showdbrefs);
2357 * @see jalview.api.ViewStyleI#isShowDBRefs()
2360 public boolean isShowDBRefs()
2362 return viewStyle.isShowDBRefs();
2367 * @see jalview.api.ViewStyleI#isShowNPFeats()
2370 public boolean isShowNPFeats()
2372 return viewStyle.isShowNPFeats();
2376 * @param shownpfeats
2377 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2380 public void setShowNPFeats(boolean shownpfeats)
2382 viewStyle.setShowNPFeats(shownpfeats);
2385 public abstract StructureSelectionManager getStructureSelectionManager();
2388 * Add one command to the command history list.
2392 public void addToHistoryList(CommandI command)
2394 if (this.historyList != null)
2396 this.historyList.push(command);
2397 broadcastCommand(command, false);
2401 protected void broadcastCommand(CommandI command, boolean undo)
2403 getStructureSelectionManager().commandPerformed(command, undo,
2408 * Add one command to the command redo list.
2412 public void addToRedoList(CommandI command)
2414 if (this.redoList != null)
2416 this.redoList.push(command);
2418 broadcastCommand(command, true);
2422 * Clear the command redo list.
2424 public void clearRedoList()
2426 if (this.redoList != null)
2428 this.redoList.clear();
2432 public void setHistoryList(Deque<CommandI> list)
2434 this.historyList = list;
2437 public Deque<CommandI> getHistoryList()
2439 return this.historyList;
2442 public void setRedoList(Deque<CommandI> list)
2444 this.redoList = list;
2447 public Deque<CommandI> getRedoList()
2449 return this.redoList;
2453 public VamsasSource getVamsasSource()
2458 public SequenceAnnotationOrder getSortAnnotationsBy()
2460 return sortAnnotationsBy;
2463 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2465 this.sortAnnotationsBy = sortAnnotationsBy;
2468 public boolean isShowAutocalculatedAbove()
2470 return showAutocalculatedAbove;
2473 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2475 this.showAutocalculatedAbove = showAutocalculatedAbove;
2479 public boolean isScaleProteinAsCdna()
2481 return viewStyle.isScaleProteinAsCdna();
2485 public void setScaleProteinAsCdna(boolean b)
2487 viewStyle.setScaleProteinAsCdna(b);
2491 * @return true if view should scroll to show the highlighted region of a
2496 public final boolean isFollowHighlight()
2498 return followHighlight;
2502 public final void setFollowHighlight(boolean b)
2504 this.followHighlight = b;
2507 public int getStartRes()
2513 public int getEndRes()
2518 public int getStartSeq()
2523 public void setStartRes(int res)
2525 this.startRes = res;
2528 public void setStartSeq(int seq)
2530 this.startSeq = seq;
2533 public void setEndRes(int res)
2535 if (res > alignment.getWidth() - 1)
2537 // log.System.out.println(" Corrected res from " + res + " to maximum " +
2538 // (alignment.getWidth()-1));
2539 res = alignment.getWidth() - 1;
2548 public void setEndSeq(int seq)
2550 if (seq > alignment.getHeight())
2552 seq = alignment.getHeight();
2561 public int getEndSeq()
2567 * Helper method to populate the SearchResults with the location in the
2568 * complementary alignment to scroll to, in order to match this one.
2571 * the SearchResults to add to
2572 * @return the offset (below top of visible region) of the matched sequence
2574 protected int findComplementScrollTarget(SearchResults sr)
2576 final AlignViewportI complement = getCodingComplement();
2577 if (complement == null || !complement.isFollowHighlight())
2581 boolean iAmProtein = !getAlignment().isNucleotide();
2582 AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement
2584 if (proteinAlignment == null)
2588 final List<AlignedCodonFrame> mappings = proteinAlignment
2592 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2593 * residue in the middle column of the visible region. Scroll the
2594 * complementary alignment to line up the corresponding residue.
2597 SequenceI sequence = null;
2600 * locate 'middle' column (true middle if an odd number visible, left of
2601 * middle if an even number visible)
2603 int middleColumn = getStartRes() + (getEndRes() - getStartRes()) / 2;
2604 final HiddenSequences hiddenSequences = getAlignment()
2605 .getHiddenSequences();
2608 * searching to the bottom of the alignment gives smoother scrolling across
2609 * all gapped visible regions
2611 int lastSeq = alignment.getHeight() - 1;
2612 for (int seqNo = getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2614 sequence = getAlignment().getSequenceAt(seqNo);
2615 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2619 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2623 List<AlignedCodonFrame> seqMappings = MappingUtils
2624 .findMappingsForSequence(sequence, mappings);
2625 if (!seqMappings.isEmpty())
2631 if (sequence == null)
2634 * No ungapped mapped sequence in middle column - do nothing
2638 MappingUtils.addSearchResults(sr, sequence,
2639 sequence.findPosition(middleColumn), mappings);