2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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.Conservation;
24 import jalview.api.AlignCalcManagerI;
25 import jalview.api.AlignViewportI;
26 import jalview.api.AlignmentViewPanel;
27 import jalview.api.FeaturesDisplayedI;
28 import jalview.api.ViewStyleI;
29 import jalview.datamodel.AlignmentAnnotation;
30 import jalview.datamodel.AlignmentI;
31 import jalview.datamodel.AlignmentView;
32 import jalview.datamodel.Annotation;
33 import jalview.datamodel.CigarArray;
34 import jalview.datamodel.ColumnSelection;
35 import jalview.datamodel.Sequence;
36 import jalview.datamodel.SequenceCollectionI;
37 import jalview.datamodel.SequenceGroup;
38 import jalview.datamodel.SequenceI;
39 import jalview.schemes.Blosum62ColourScheme;
40 import jalview.schemes.ColourSchemeI;
41 import jalview.schemes.PIDColourScheme;
42 import jalview.schemes.ResidueProperties;
43 import jalview.viewmodel.styles.ViewStyle;
44 import jalview.workers.AlignCalcManager;
45 import jalview.workers.ConsensusThread;
46 import jalview.workers.StrucConsensusThread;
48 import java.awt.Color;
49 import java.util.ArrayList;
50 import java.util.BitSet;
51 import java.util.HashMap;
52 import java.util.Hashtable;
53 import java.util.List;
55 import java.util.Vector;
58 * base class holding visualization and analysis attributes and common logic for
59 * an active alignment view displayed in the GUI
64 public abstract class AlignmentViewport implements AlignViewportI,
67 protected ViewStyleI viewStyle = new ViewStyle();
70 * A viewport that hosts the cDna view of this (protein), or vice versa (if
73 AlignViewportI codingComplement = null;
77 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
79 public void setFontName(String name)
81 viewStyle.setFontName(name);
86 * @see jalview.api.ViewStyleI#setFontStyle(int)
88 public void setFontStyle(int style)
90 viewStyle.setFontStyle(style);
95 * @see jalview.api.ViewStyleI#setFontSize(int)
97 public void setFontSize(int size)
99 viewStyle.setFontSize(size);
104 * @see jalview.api.ViewStyleI#getFontStyle()
106 public int getFontStyle()
108 return viewStyle.getFontStyle();
113 * @see jalview.api.ViewStyleI#getFontName()
115 public String getFontName()
117 return viewStyle.getFontName();
122 * @see jalview.api.ViewStyleI#getFontSize()
124 public int getFontSize()
126 return viewStyle.getFontSize();
130 * @param upperCasebold
131 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
133 public void setUpperCasebold(boolean upperCasebold)
135 viewStyle.setUpperCasebold(upperCasebold);
140 * @see jalview.api.ViewStyleI#isUpperCasebold()
142 public boolean isUpperCasebold()
144 return viewStyle.isUpperCasebold();
149 * @see jalview.api.ViewStyleI#isSeqNameItalics()
151 public boolean isSeqNameItalics()
153 return viewStyle.isSeqNameItalics();
157 * @param colourByReferenceSeq
158 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
160 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
162 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
167 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
169 public void setColourAppliesToAllGroups(boolean b)
171 viewStyle.setColourAppliesToAllGroups(b);
176 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
178 public boolean getColourAppliesToAllGroups()
180 return viewStyle.getColourAppliesToAllGroups();
185 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
187 public boolean getAbovePIDThreshold()
189 return viewStyle.getAbovePIDThreshold();
194 * @see jalview.api.ViewStyleI#setIncrement(int)
196 public void setIncrement(int inc)
198 viewStyle.setIncrement(inc);
203 * @see jalview.api.ViewStyleI#getIncrement()
205 public int getIncrement()
207 return viewStyle.getIncrement();
212 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
214 public void setConservationSelected(boolean b)
216 viewStyle.setConservationSelected(b);
221 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
223 public void setShowHiddenMarkers(boolean show)
225 viewStyle.setShowHiddenMarkers(show);
230 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
232 public boolean getShowHiddenMarkers()
234 return viewStyle.getShowHiddenMarkers();
239 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
241 public void setScaleRightWrapped(boolean b)
243 viewStyle.setScaleRightWrapped(b);
248 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
250 public void setScaleLeftWrapped(boolean b)
252 viewStyle.setScaleLeftWrapped(b);
257 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
259 public void setScaleAboveWrapped(boolean b)
261 viewStyle.setScaleAboveWrapped(b);
266 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
268 public boolean getScaleLeftWrapped()
270 return viewStyle.getScaleLeftWrapped();
275 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
277 public boolean getScaleAboveWrapped()
279 return viewStyle.getScaleAboveWrapped();
284 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
286 public boolean getScaleRightWrapped()
288 return viewStyle.getScaleRightWrapped();
293 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
295 public void setAbovePIDThreshold(boolean b)
297 viewStyle.setAbovePIDThreshold(b);
302 * @see jalview.api.ViewStyleI#setThreshold(int)
304 public void setThreshold(int thresh)
306 viewStyle.setThreshold(thresh);
311 * @see jalview.api.ViewStyleI#getThreshold()
313 public int getThreshold()
315 return viewStyle.getThreshold();
320 * @see jalview.api.ViewStyleI#getShowJVSuffix()
322 public boolean getShowJVSuffix()
324 return viewStyle.getShowJVSuffix();
329 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
331 public void setShowJVSuffix(boolean b)
333 viewStyle.setShowJVSuffix(b);
338 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
340 public void setWrapAlignment(boolean state)
342 viewStyle.setWrapAlignment(state);
347 * @see jalview.api.ViewStyleI#setShowText(boolean)
349 public void setShowText(boolean state)
351 viewStyle.setShowText(state);
356 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
358 public void setRenderGaps(boolean state)
360 viewStyle.setRenderGaps(state);
365 * @see jalview.api.ViewStyleI#getColourText()
367 public boolean getColourText()
369 return viewStyle.getColourText();
374 * @see jalview.api.ViewStyleI#setColourText(boolean)
376 public void setColourText(boolean state)
378 viewStyle.setColourText(state);
383 * @see jalview.api.ViewStyleI#getWrapAlignment()
385 public boolean getWrapAlignment()
387 return viewStyle.getWrapAlignment();
392 * @see jalview.api.ViewStyleI#getShowText()
394 public boolean getShowText()
396 return viewStyle.getShowText();
401 * @see jalview.api.ViewStyleI#getWrappedWidth()
403 public int getWrappedWidth()
405 return viewStyle.getWrappedWidth();
410 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
412 public void setWrappedWidth(int w)
414 viewStyle.setWrappedWidth(w);
419 * @see jalview.api.ViewStyleI#getCharHeight()
421 public int getCharHeight()
423 return viewStyle.getCharHeight();
428 * @see jalview.api.ViewStyleI#setCharHeight(int)
430 public void setCharHeight(int h)
432 viewStyle.setCharHeight(h);
437 * @see jalview.api.ViewStyleI#getCharWidth()
439 public int getCharWidth()
441 return viewStyle.getCharWidth();
446 * @see jalview.api.ViewStyleI#setCharWidth(int)
448 public void setCharWidth(int w)
450 viewStyle.setCharWidth(w);
455 * @see jalview.api.ViewStyleI#getShowBoxes()
457 public boolean getShowBoxes()
459 return viewStyle.getShowBoxes();
464 * @see jalview.api.ViewStyleI#getShowUnconserved()
466 public boolean getShowUnconserved()
468 return viewStyle.getShowUnconserved();
472 * @param showunconserved
473 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
475 public void setShowUnconserved(boolean showunconserved)
477 viewStyle.setShowUnconserved(showunconserved);
482 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
484 public void setSeqNameItalics(boolean default1)
486 viewStyle.setSeqNameItalics(default1);
491 * @see jalview.api.ViewStyleI#setShowSeqFeaturesHeight(boolean)
493 public void setShowSeqFeaturesHeight(boolean selected)
495 viewStyle.setShowSeqFeaturesHeight(selected);
499 * alignment displayed in the viewport. Please use get/setter
501 protected AlignmentI alignment;
504 public AlignmentI getAlignment()
510 public char getGapCharacter()
512 return alignment.getGapCharacter();
515 protected String sequenceSetID;
518 * probably unused indicator that view is of a dataset rather than an
521 protected boolean isDataset = false;
523 public void setDataset(boolean b)
528 public boolean isDataset()
534 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
536 protected ColumnSelection colSel = new ColumnSelection();
538 public boolean autoCalculateConsensus = true;
540 protected boolean autoCalculateStrucConsensus = true;
542 protected boolean ignoreGapsInConsensusCalculation = false;
544 protected ColourSchemeI globalColourScheme = null;
548 public void setGlobalColourScheme(ColourSchemeI cs)
550 // TODO: logic refactored from AlignFrame changeColour -
551 // autorecalc stuff should be changed to rely on the worker system
552 // check to see if we should implement a changeColour(cs) method rather than
553 // put th logic in here
554 // - means that caller decides if they want to just modify state and defer
555 // calculation till later or to do all calculations in thread.
557 globalColourScheme = cs;
558 boolean recalc = false;
561 cs.setConservationApplied(recalc = getConservationSelected());
562 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
563 || cs instanceof Blosum62ColourScheme)
566 cs.setThreshold(viewStyle.getThreshold(),
567 ignoreGapsInConsensusCalculation);
571 cs.setThreshold(0, ignoreGapsInConsensusCalculation);
575 cs.setConsensus(hconsensus);
576 cs.setConservation(hconservation);
578 cs.alignmentChanged(alignment, hiddenRepSequences);
580 if (getColourAppliesToAllGroups())
582 for (SequenceGroup sg : getAlignment().getGroups())
589 sg.cs = cs.applyTo(sg, getHiddenRepSequences());
590 sg.setConsPercGaps(ConsPercGaps);
591 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
592 || cs instanceof Blosum62ColourScheme)
594 sg.cs.setThreshold(viewStyle.getThreshold(),
595 isIgnoreGapsConsensus());
600 sg.cs.setThreshold(0, isIgnoreGapsConsensus());
603 if (getConservationSelected())
605 sg.cs.setConservationApplied(true);
610 sg.cs.setConservation(null);
611 // sg.cs.setThreshold(0, getIgnoreGapsConsensus());
615 sg.recalcConservation();
619 sg.cs.alignmentChanged(sg, hiddenRepSequences);
627 public ColourSchemeI getGlobalColourScheme()
629 return globalColourScheme;
632 protected AlignmentAnnotation consensus;
634 protected AlignmentAnnotation strucConsensus;
636 protected AlignmentAnnotation conservation;
638 protected AlignmentAnnotation quality;
640 protected AlignmentAnnotation[] groupConsensus;
642 protected AlignmentAnnotation[] groupConservation;
645 * results of alignment consensus analysis for visible portion of view
647 protected Hashtable[] hconsensus = null;
650 * results of secondary structure base pair consensus for visible portion of
653 protected Hashtable[] hStrucConsensus = null;
655 protected Conservation hconservation = null;
658 public void setConservation(Conservation cons)
660 hconservation = cons;
664 * percentage gaps allowed in a column before all amino acid properties should
665 * be considered unconserved
667 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
670 public int getConsPercGaps()
676 public void setSequenceConsensusHash(Hashtable[] hconsensus)
678 this.hconsensus = hconsensus;
683 public Hashtable[] getSequenceConsensusHash()
689 public Hashtable[] getRnaStructureConsensusHash()
691 return hStrucConsensus;
695 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
697 this.hStrucConsensus = hStrucConsensus;
702 public AlignmentAnnotation getAlignmentQualityAnnot()
708 public AlignmentAnnotation getAlignmentConservationAnnotation()
714 public AlignmentAnnotation getAlignmentConsensusAnnotation()
720 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
722 return strucConsensus;
725 protected AlignCalcManagerI calculator = new AlignCalcManager();
728 * trigger update of conservation annotation
730 public void updateConservation(final AlignmentViewPanel ap)
732 // see note in mantis : issue number 8585
733 if (alignment.isNucleotide() || conservation == null
734 || !autoCalculateConsensus)
739 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
741 calculator.registerWorker(new jalview.workers.ConservationThread(
747 * trigger update of consensus annotation
749 public void updateConsensus(final AlignmentViewPanel ap)
751 // see note in mantis : issue number 8585
752 if (consensus == null || !autoCalculateConsensus)
756 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
758 calculator.registerWorker(new ConsensusThread(this, ap));
762 // --------START Structure Conservation
763 public void updateStrucConsensus(final AlignmentViewPanel ap)
765 if (autoCalculateStrucConsensus && strucConsensus == null
766 && alignment.isNucleotide() && alignment.hasRNAStructure())
768 // secondary structure has been added - so init the consensus line
772 // see note in mantis : issue number 8585
773 if (strucConsensus == null || !autoCalculateStrucConsensus)
777 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
779 calculator.registerWorker(new StrucConsensusThread(this, ap));
783 public boolean isCalcInProgress()
785 return calculator.isWorking();
789 public boolean isCalculationInProgress(
790 AlignmentAnnotation alignmentAnnotation)
792 if (!alignmentAnnotation.autoCalculated)
796 if (calculator.workingInvolvedWith(alignmentAnnotation))
798 // System.err.println("grey out ("+alignmentAnnotation.label+")");
805 public boolean isClosed()
807 // TODO: check that this isClosed is only true after panel is closed, not
808 // before it is fully constructed.
809 return alignment == null;
813 public AlignCalcManagerI getCalcManager()
819 * should conservation rows be shown for groups
821 protected boolean showGroupConservation = false;
824 * should consensus rows be shown for groups
826 protected boolean showGroupConsensus = false;
829 * should consensus profile be rendered by default
831 protected boolean showSequenceLogo = false;
834 * should consensus profile be rendered normalised to row height
836 protected boolean normaliseSequenceLogo = false;
839 * should consensus histograms be rendered by default
841 protected boolean showConsensusHistogram = true;
844 * @return the showConsensusProfile
847 public boolean isShowSequenceLogo()
849 return showSequenceLogo;
853 * @param showSequenceLogo
856 public void setShowSequenceLogo(boolean showSequenceLogo)
858 if (showSequenceLogo != this.showSequenceLogo)
860 // TODO: decouple settings setting from calculation when refactoring
861 // annotation update method from alignframe to viewport
862 this.showSequenceLogo = showSequenceLogo;
863 calculator.updateAnnotationFor(ConsensusThread.class);
864 calculator.updateAnnotationFor(StrucConsensusThread.class);
866 this.showSequenceLogo = showSequenceLogo;
870 * @param showConsensusHistogram
871 * the showConsensusHistogram to set
873 public void setShowConsensusHistogram(boolean showConsensusHistogram)
875 this.showConsensusHistogram = showConsensusHistogram;
879 * @return the showGroupConservation
881 public boolean isShowGroupConservation()
883 return showGroupConservation;
887 * @param showGroupConservation
888 * the showGroupConservation to set
890 public void setShowGroupConservation(boolean showGroupConservation)
892 this.showGroupConservation = showGroupConservation;
896 * @return the showGroupConsensus
898 public boolean isShowGroupConsensus()
900 return showGroupConsensus;
904 * @param showGroupConsensus
905 * the showGroupConsensus to set
907 public void setShowGroupConsensus(boolean showGroupConsensus)
909 this.showGroupConsensus = showGroupConsensus;
914 * @return flag to indicate if the consensus histogram should be rendered by
918 public boolean isShowConsensusHistogram()
920 return this.showConsensusHistogram;
924 * when set, updateAlignment will always ensure sequences are of equal length
926 private boolean padGaps = false;
929 * when set, alignment should be reordered according to a newly opened tree
931 public boolean sortByTree = false;
937 * @return null or the currently selected sequence region
940 public SequenceGroup getSelectionGroup()
942 return selectionGroup;
946 * Set the selection group for this window.
949 * - group holding references to sequences in this alignment view
953 public void setSelectionGroup(SequenceGroup sg)
958 public void setHiddenColumns(ColumnSelection colsel)
960 this.colSel = colsel;
964 public ColumnSelection getColumnSelection()
970 public void setColumnSelection(ColumnSelection colSel)
972 this.colSel = colSel;
975 updateHiddenColumns();
984 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
986 return hiddenRepSequences;
990 public void setHiddenRepSequences(
991 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
993 this.hiddenRepSequences = hiddenRepSequences;
997 public boolean hasHiddenColumns()
999 return colSel != null && colSel.hasHiddenColumns();
1002 public void updateHiddenColumns()
1004 // this method doesn't really do anything now. But - it could, since a
1005 // column Selection could be in the process of modification
1006 // hasHiddenColumns = colSel.hasHiddenColumns();
1009 protected boolean hasHiddenRows = false;
1012 public boolean hasHiddenRows()
1014 return hasHiddenRows;
1017 protected SequenceGroup selectionGroup;
1019 public void setSequenceSetId(String newid)
1021 if (sequenceSetID != null)
1024 .println("Warning - overwriting a sequenceSetId for a viewport!");
1026 sequenceSetID = new String(newid);
1030 public String getSequenceSetId()
1032 if (sequenceSetID == null)
1034 sequenceSetID = alignment.hashCode() + "";
1037 return sequenceSetID;
1041 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1044 protected String viewId = null;
1046 public String getViewId()
1050 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1055 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1057 ignoreGapsInConsensusCalculation = b;
1060 updateConsensus(ap);
1061 if (globalColourScheme != null)
1063 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1064 ignoreGapsInConsensusCalculation);
1070 private long sgrouphash = -1, colselhash = -1;
1073 * checks current SelectionGroup against record of last hash value, and
1077 * update the record of last hash value
1079 * @return true if SelectionGroup changed since last call (when b is true)
1081 public boolean isSelectionGroupChanged(boolean b)
1083 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1084 : selectionGroup.hashCode();
1085 if (hc != -1 && hc != sgrouphash)
1097 * checks current colsel against record of last hash value, and optionally
1101 * update the record of last hash value
1102 * @return true if colsel changed since last call (when b is true)
1104 public boolean isColSelChanged(boolean b)
1106 int hc = (colSel == null || colSel.size() == 0) ? -1 : colSel
1108 if (hc != -1 && hc != colselhash)
1120 public boolean isIgnoreGapsConsensus()
1122 return ignoreGapsInConsensusCalculation;
1125 // / property change stuff
1127 // JBPNote Prolly only need this in the applet version.
1128 private final java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
1131 protected boolean showConservation = true;
1133 protected boolean showQuality = true;
1135 protected boolean showConsensus = true;
1137 private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
1140 * Property change listener for changes in alignment
1145 public void addPropertyChangeListener(
1146 java.beans.PropertyChangeListener listener)
1148 changeSupport.addPropertyChangeListener(listener);
1157 public void removePropertyChangeListener(
1158 java.beans.PropertyChangeListener listener)
1160 changeSupport.removePropertyChangeListener(listener);
1164 * Property change listener for changes in alignment
1173 public void firePropertyChange(String prop, Object oldvalue,
1176 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1179 // common hide/show column stuff
1181 public void hideSelectedColumns()
1183 if (colSel.size() < 1)
1188 colSel.hideSelectedColumns();
1189 setSelectionGroup(null);
1193 public void hideColumns(int start, int end)
1197 colSel.hideColumns(start);
1201 colSel.hideColumns(start, end);
1205 public void showColumn(int col)
1207 colSel.revealHiddenColumns(col);
1211 public void showAllHiddenColumns()
1213 colSel.revealAllHiddenColumns();
1216 // common hide/show seq stuff
1217 public void showAllHiddenSeqs()
1219 if (alignment.getHiddenSequences().getSize() > 0)
1221 if (selectionGroup == null)
1223 selectionGroup = new SequenceGroup();
1224 selectionGroup.setEndRes(alignment.getWidth() - 1);
1226 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1227 hiddenRepSequences);
1228 for (SequenceI seq : tmp)
1230 selectionGroup.addSequence(seq, false);
1231 setSequenceAnnotationsVisible(seq, true);
1234 hasHiddenRows = false;
1235 hiddenRepSequences = null;
1237 firePropertyChange("alignment", null, alignment.getSequences());
1238 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1244 public void showSequence(int index)
1246 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1248 hiddenRepSequences);
1251 if (selectionGroup == null)
1253 selectionGroup = new SequenceGroup();
1254 selectionGroup.setEndRes(alignment.getWidth() - 1);
1257 for (SequenceI seq : tmp)
1259 selectionGroup.addSequence(seq, false);
1260 setSequenceAnnotationsVisible(seq, true);
1262 // JBPNote: refactor: only update flag if we modified visiblity (used to
1263 // do this regardless)
1264 if (alignment.getHiddenSequences().getSize() < 1)
1266 hasHiddenRows = false;
1268 firePropertyChange("alignment", null, alignment.getSequences());
1273 public void hideAllSelectedSeqs()
1275 if (selectionGroup == null || selectionGroup.getSize() < 1)
1280 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1284 setSelectionGroup(null);
1287 public void hideSequence(SequenceI[] seq)
1291 for (int i = 0; i < seq.length; i++)
1293 alignment.getHiddenSequences().hideSequence(seq[i]);
1294 setSequenceAnnotationsVisible(seq[i], false);
1296 hasHiddenRows = true;
1297 firePropertyChange("alignment", null, alignment.getSequences());
1302 * Set visibility for any annotations for the given sequence.
1306 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1309 for (AlignmentAnnotation ann : alignment.getAlignmentAnnotation())
1311 if (ann.sequenceRef == sequenceI)
1313 ann.visible = visible;
1318 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1320 int sSize = sg.getSize();
1326 if (hiddenRepSequences == null)
1328 hiddenRepSequences = new Hashtable();
1331 hiddenRepSequences.put(repSequence, sg);
1333 // Hide all sequences except the repSequence
1334 SequenceI[] seqs = new SequenceI[sSize - 1];
1336 for (int i = 0; i < sSize; i++)
1338 if (sg.getSequenceAt(i) != repSequence)
1340 if (index == sSize - 1)
1345 seqs[index++] = sg.getSequenceAt(i);
1348 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1349 sg.setHidereps(true); // note: not done in 2.7applet
1354 public boolean isHiddenRepSequence(SequenceI seq)
1356 return alignment.getSeqrep()==seq || (hiddenRepSequences != null
1357 && hiddenRepSequences.containsKey(seq));
1360 public SequenceGroup getRepresentedSequences(SequenceI seq)
1362 return (SequenceGroup) (hiddenRepSequences == null ? null
1363 : hiddenRepSequences.get(seq));
1367 public int adjustForHiddenSeqs(int alignmentIndex)
1369 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1374 public void invertColumnSelection()
1376 colSel.invertColumnSelection(0, alignment.getWidth());
1381 public SequenceI[] getSelectionAsNewSequence()
1383 SequenceI[] sequences;
1384 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1385 // this was the only caller in the applet for this method
1386 // JBPNote: in applet, this method returned references to the alignment
1387 // sequences, and it did not honour the presence/absence of annotation
1388 // attached to the alignment (probably!)
1389 if (selectionGroup == null || selectionGroup.getSize() == 0)
1391 sequences = alignment.getSequencesArray();
1392 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1393 for (int i = 0; i < sequences.length; i++)
1395 sequences[i] = new Sequence(sequences[i], annots); // construct new
1397 // subset of visible
1403 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1411 public SequenceI[] getSequenceSelection()
1413 SequenceI[] sequences = null;
1414 if (selectionGroup != null)
1416 sequences = selectionGroup.getSequencesInOrder(alignment);
1418 if (sequences == null)
1420 sequences = alignment.getSequencesArray();
1427 public CigarArray getViewAsCigars(
1428 boolean selectedRegionOnly)
1430 return new CigarArray(alignment, colSel,
1431 (selectedRegionOnly ? selectionGroup : null));
1436 public jalview.datamodel.AlignmentView getAlignmentView(
1437 boolean selectedOnly)
1439 return getAlignmentView(selectedOnly, false);
1444 public jalview.datamodel.AlignmentView getAlignmentView(
1445 boolean selectedOnly, boolean markGroups)
1447 return new AlignmentView(alignment, colSel, selectionGroup,
1448 colSel != null && colSel.hasHiddenColumns(), selectedOnly,
1454 public String[] getViewAsString(boolean selectedRegionOnly)
1456 String[] selection = null;
1457 SequenceI[] seqs = null;
1459 int start = 0, end = 0;
1460 if (selectedRegionOnly && selectionGroup != null)
1462 iSize = selectionGroup.getSize();
1463 seqs = selectionGroup.getSequencesInOrder(alignment);
1464 start = selectionGroup.getStartRes();
1465 end = selectionGroup.getEndRes() + 1;
1469 iSize = alignment.getHeight();
1470 seqs = alignment.getSequencesArray();
1471 end = alignment.getWidth();
1474 selection = new String[iSize];
1475 if (colSel != null && colSel.hasHiddenColumns())
1477 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1481 for (i = 0; i < iSize; i++)
1483 selection[i] = seqs[i].getSequenceAsString(start, end);
1492 public int[][] getVisibleRegionBoundaries(int min, int max)
1494 Vector regions = new Vector();
1500 if (colSel != null && colSel.hasHiddenColumns())
1504 start = colSel.adjustForHiddenColumns(start);
1507 end = colSel.getHiddenBoundaryRight(start);
1518 regions.addElement(new int[]
1521 if (colSel != null && colSel.hasHiddenColumns())
1523 start = colSel.adjustForHiddenColumns(end);
1524 start = colSel.getHiddenBoundaryLeft(start) + 1;
1526 } while (end < max);
1528 int[][] startEnd = new int[regions.size()][2];
1530 regions.copyInto(startEnd);
1537 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(boolean selectedOnly)
1539 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1540 AlignmentAnnotation[] aa;
1541 if ((aa=alignment.getAlignmentAnnotation())!=null)
1543 for (AlignmentAnnotation annot:aa)
1545 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1546 if (selectedOnly && selectionGroup!=null)
1548 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(), selectionGroup.getEndRes(),clone);
1550 colSel.makeVisibleAnnotation(clone);
1560 public boolean isPadGaps()
1567 public void setPadGaps(boolean padGaps)
1569 this.padGaps = padGaps;
1573 * apply any post-edit constraints and trigger any calculations needed after
1574 * an edit has been performed on the alignment
1579 public void alignmentChanged(AlignmentViewPanel ap)
1583 alignment.padGaps();
1585 if (autoCalculateConsensus)
1587 updateConsensus(ap);
1589 if (hconsensus != null && autoCalculateConsensus)
1591 updateConservation(ap);
1593 if (autoCalculateStrucConsensus)
1595 updateStrucConsensus(ap);
1598 // Reset endRes of groups if beyond alignment width
1599 int alWidth = alignment.getWidth();
1600 List<SequenceGroup> groups = alignment.getGroups();
1603 for (SequenceGroup sg : groups)
1605 if (sg.getEndRes() > alWidth)
1607 sg.setEndRes(alWidth - 1);
1612 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1614 selectionGroup.setEndRes(alWidth - 1);
1617 resetAllColourSchemes();
1618 calculator.restartWorkers();
1619 // alignment.adjustSequenceAnnotations();
1623 * reset scope and do calculations for all applied colourschemes on alignment
1625 void resetAllColourSchemes()
1627 ColourSchemeI cs = globalColourScheme;
1630 cs.alignmentChanged(alignment, hiddenRepSequences);
1632 cs.setConsensus(hconsensus);
1633 if (cs.conservationApplied())
1635 cs.setConservation(Conservation.calculateConservation("All",
1636 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1637 alignment.getWidth(), false, getConsPercGaps(), false));
1641 for (SequenceGroup sg : alignment.getGroups())
1645 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1647 sg.recalcConservation();
1651 protected void initAutoAnnotation()
1653 // TODO: add menu option action that nulls or creates consensus object
1654 // depending on if the user wants to see the annotation or not in a
1655 // specific alignment
1657 if (hconsensus == null && !isDataset)
1659 if (!alignment.isNucleotide())
1672 private void initConsensus()
1675 consensus = new AlignmentAnnotation("Consensus", "PID",
1676 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1677 consensus.hasText = true;
1678 consensus.autoCalculated = true;
1682 alignment.addAnnotation(consensus);
1686 private void initConservation()
1688 if (showConservation)
1690 if (conservation == null)
1692 conservation = new AlignmentAnnotation("Conservation",
1693 "Conservation of total alignment less than "
1694 + getConsPercGaps() + "% gaps", new Annotation[1],
1695 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1696 conservation.hasText = true;
1697 conservation.autoCalculated = true;
1698 alignment.addAnnotation(conservation);
1703 private void initQuality()
1707 if (quality == null)
1709 quality = new AlignmentAnnotation("Quality",
1710 "Alignment Quality based on Blosum62 scores",
1711 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1712 quality.hasText = true;
1713 quality.autoCalculated = true;
1714 alignment.addAnnotation(quality);
1719 private void initRNAStructure()
1721 if (alignment.hasRNAStructure() && strucConsensus == null)
1723 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1724 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1725 strucConsensus.hasText = true;
1726 strucConsensus.autoCalculated = true;
1730 alignment.addAnnotation(strucConsensus);
1738 * @see jalview.api.AlignViewportI#calcPanelHeight()
1741 public int calcPanelHeight()
1743 // setHeight of panels
1744 AlignmentAnnotation[] aa = getAlignment().getAlignmentAnnotation();
1746 int charHeight = getCharHeight();
1749 BitSet graphgrp = new BitSet();
1750 for (int i = 0; i < aa.length; i++)
1754 System.err.println("Null annotation row: ignoring.");
1761 if (aa[i].graphGroup > -1)
1763 if (graphgrp.get(aa[i].graphGroup))
1769 graphgrp.set(aa[i].graphGroup);
1776 aa[i].height += charHeight;
1784 if (aa[i].graph > 0)
1786 aa[i].height += aa[i].graphHeight;
1789 if (aa[i].height == 0)
1794 height += aa[i].height;
1806 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1807 boolean preserveNewGroupSettings)
1809 boolean updateCalcs = false;
1810 boolean conv = isShowGroupConservation();
1811 boolean cons = isShowGroupConsensus();
1812 boolean showprf = isShowSequenceLogo();
1813 boolean showConsHist = isShowConsensusHistogram();
1814 boolean normLogo = isNormaliseSequenceLogo();
1817 * TODO reorder the annotation rows according to group/sequence ordering on
1820 boolean sortg = true;
1822 // remove old automatic annotation
1823 // add any new annotation
1825 // intersect alignment annotation with alignment groups
1827 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
1828 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
1831 for (int an = 0; an < aan.length; an++)
1833 if (aan[an].autoCalculated && aan[an].groupRef != null)
1835 oldrfs.add(aan[an].groupRef);
1836 alignment.deleteAnnotation(aan[an], false);
1840 if (alignment.getGroups() != null)
1842 for (SequenceGroup sg : alignment.getGroups())
1844 updateCalcs = false;
1845 if (applyGlobalSettings
1846 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
1848 // set defaults for this group's conservation/consensus
1849 sg.setshowSequenceLogo(showprf);
1850 sg.setShowConsensusHistogram(showConsHist);
1851 sg.setNormaliseSequenceLogo(normLogo);
1856 alignment.addAnnotation(sg.getConservationRow(), 0);
1861 alignment.addAnnotation(sg.getConsensus(), 0);
1863 // refresh the annotation rows
1866 sg.recalcConservation();
1873 public boolean isDisplayReferenceSeq()
1875 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
1879 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
1881 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
1885 public boolean isColourByReferenceSeq()
1887 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
1891 public Color getSequenceColour(SequenceI seq)
1893 Color sqc = sequenceColours.get(seq);
1894 return (sqc == null ? Color.white : sqc);
1898 public void setSequenceColour(SequenceI seq, Color col)
1902 sequenceColours.remove(seq);
1906 sequenceColours.put(seq, col);
1911 public void updateSequenceIdColours()
1913 for (SequenceGroup sg : alignment.getGroups())
1915 if (sg.idColour != null)
1917 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
1919 sequenceColours.put(s, sg.idColour);
1926 public void clearSequenceColours()
1928 sequenceColours.clear();
1932 public AlignViewportI getCodingComplement()
1934 return this.codingComplement;
1938 * Set this as the (cDna/protein) complement of the given viewport. Also
1939 * ensures the reverse relationship is set on the given viewport.
1942 public void setCodingComplement(AlignViewportI av)
1946 System.err.println("Ignoring recursive setCodingComplement request");
1950 this.codingComplement = av;
1951 // avoid infinite recursion!
1952 if (av.getCodingComplement() != this)
1954 av.setCodingComplement(this);
1960 public boolean isNucleotide()
1962 return getAlignment() == null ? false : getAlignment().isNucleotide();
1965 FeaturesDisplayedI featuresDisplayed = null;
1968 public FeaturesDisplayedI getFeaturesDisplayed()
1970 return featuresDisplayed;
1974 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
1976 featuresDisplayed = featuresDisplayedI;
1980 public boolean areFeaturesDisplayed()
1982 return featuresDisplayed != null && featuresDisplayed.getRegisterdFeaturesCount()>0;
1989 * features are displayed if true
1992 public void setShowSequenceFeatures(boolean b)
1994 viewStyle.setShowSequenceFeatures(b);
1997 public boolean isShowSequenceFeatures()
1999 return viewStyle.isShowSequenceFeatures();
2003 public void setShowSequenceFeaturesHeight(boolean selected)
2005 viewStyle.setShowSeqFeaturesHeight(selected);
2009 public boolean isShowSequenceFeaturesHeight()
2011 return viewStyle.isShowSequenceFeaturesHeight();
2017 public void setShowAnnotation(boolean b)
2019 viewStyle.setShowAnnotation(b);
2023 public boolean isShowAnnotation()
2025 return viewStyle.isShowAnnotation();
2029 public boolean isRightAlignIds()
2031 return viewStyle.isRightAlignIds();
2035 public void setRightAlignIds(boolean rightAlignIds)
2037 viewStyle.setRightAlignIds(rightAlignIds);
2041 public boolean getConservationSelected()
2043 return viewStyle.getConservationSelected();
2047 public void setShowBoxes(boolean state)
2049 viewStyle.setShowBoxes(state);
2054 * @see jalview.api.ViewStyleI#getTextColour()
2056 public Color getTextColour()
2058 return viewStyle.getTextColour();
2063 * @see jalview.api.ViewStyleI#getTextColour2()
2065 public Color getTextColour2()
2067 return viewStyle.getTextColour2();
2072 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2074 public int getThresholdTextColour()
2076 return viewStyle.getThresholdTextColour();
2081 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2083 public boolean isConservationColourSelected()
2085 return viewStyle.isConservationColourSelected();
2090 * @see jalview.api.ViewStyleI#isRenderGaps()
2092 public boolean isRenderGaps()
2094 return viewStyle.isRenderGaps();
2099 * @see jalview.api.ViewStyleI#isShowColourText()
2101 public boolean isShowColourText()
2103 return viewStyle.isShowColourText();
2107 * @see jalview.api.ViewStyleI#isShowSeqFeaturesHeight()
2109 public boolean isShowSeqFeaturesHeight()
2111 return viewStyle.isShowSeqFeaturesHeight();
2115 * @param conservationColourSelected
2116 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2118 public void setConservationColourSelected(
2119 boolean conservationColourSelected)
2121 viewStyle.setConservationColourSelected(conservationColourSelected);
2125 * @param showColourText
2126 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2128 public void setShowColourText(boolean showColourText)
2130 viewStyle.setShowColourText(showColourText);
2135 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2137 public void setTextColour(Color textColour)
2139 viewStyle.setTextColour(textColour);
2143 * @param thresholdTextColour
2144 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2146 public void setThresholdTextColour(int thresholdTextColour)
2148 viewStyle.setThresholdTextColour(thresholdTextColour);
2152 * @param textColour2
2153 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2155 public void setTextColour2(Color textColour2)
2157 viewStyle.setTextColour2(textColour2);
2161 public ViewStyleI getViewStyle()
2163 return new ViewStyle(viewStyle);
2167 public void setViewStyle(ViewStyleI settingsForView)
2169 viewStyle = new ViewStyle(settingsForView);
2173 public boolean sameStyle(ViewStyleI them)
2175 return viewStyle.sameStyle(them);
2180 * @see jalview.api.ViewStyleI#getIdWidth()
2182 public int getIdWidth()
2184 return viewStyle.getIdWidth();
2189 * @see jalview.api.ViewStyleI#setIdWidth(int)
2191 public void setIdWidth(int i)
2193 viewStyle.setIdWidth(i);
2198 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2200 public boolean isCentreColumnLabels()
2202 return viewStyle.isCentreColumnLabels();
2206 * @param centreColumnLabels
2207 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2209 public void setCentreColumnLabels(boolean centreColumnLabels)
2211 viewStyle.setCentreColumnLabels(centreColumnLabels);
2216 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2218 public void setShowDBRefs(boolean showdbrefs)
2220 viewStyle.setShowDBRefs(showdbrefs);
2225 * @see jalview.api.ViewStyleI#isShowDBRefs()
2227 public boolean isShowDBRefs()
2229 return viewStyle.isShowDBRefs();
2234 * @see jalview.api.ViewStyleI#isShowNPFeats()
2236 public boolean isShowNPFeats()
2238 return viewStyle.isShowNPFeats();
2242 * @param shownpfeats
2243 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2245 public void setShowNPFeats(boolean shownpfeats)
2247 viewStyle.setShowNPFeats(shownpfeats);