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.ColumnSelection;
34 import jalview.datamodel.Sequence;
35 import jalview.datamodel.SequenceCollectionI;
36 import jalview.datamodel.SequenceGroup;
37 import jalview.datamodel.SequenceI;
38 import jalview.schemes.Blosum62ColourScheme;
39 import jalview.schemes.ColourSchemeI;
40 import jalview.schemes.PIDColourScheme;
41 import jalview.schemes.ResidueProperties;
42 import jalview.viewmodel.styles.ViewStyle;
43 import jalview.workers.AlignCalcManager;
44 import jalview.workers.ConsensusThread;
45 import jalview.workers.StrucConsensusThread;
47 import java.awt.Color;
48 import java.util.ArrayList;
49 import java.util.BitSet;
50 import java.util.Hashtable;
51 import java.util.List;
53 import java.util.Vector;
56 * base class holding visualization and analysis attributes and common logic for
57 * an active alignment view displayed in the GUI
62 public abstract class AlignmentViewport implements AlignViewportI,
65 protected ViewStyleI viewStyle = new ViewStyle();
70 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
72 public void setFontName(String name)
74 viewStyle.setFontName(name);
79 * @see jalview.api.ViewStyleI#setFontStyle(int)
81 public void setFontStyle(int style)
83 viewStyle.setFontStyle(style);
88 * @see jalview.api.ViewStyleI#setFontSize(int)
90 public void setFontSize(int size)
92 viewStyle.setFontSize(size);
97 * @see jalview.api.ViewStyleI#getFontStyle()
99 public int getFontStyle()
101 return viewStyle.getFontStyle();
106 * @see jalview.api.ViewStyleI#getFontName()
108 public String getFontName()
110 return viewStyle.getFontName();
115 * @see jalview.api.ViewStyleI#getFontSize()
117 public int getFontSize()
119 return viewStyle.getFontSize();
123 * @param upperCasebold
124 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
126 public void setUpperCasebold(boolean upperCasebold)
128 viewStyle.setUpperCasebold(upperCasebold);
133 * @see jalview.api.ViewStyleI#isUpperCasebold()
135 public boolean isUpperCasebold()
137 return viewStyle.isUpperCasebold();
142 * @see jalview.api.ViewStyleI#isSeqNameItalics()
144 public boolean isSeqNameItalics()
146 return viewStyle.isSeqNameItalics();
150 * @param colourByReferenceSeq
151 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
153 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
155 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
160 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
162 public void setColourAppliesToAllGroups(boolean b)
164 viewStyle.setColourAppliesToAllGroups(b);
169 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
171 public boolean getColourAppliesToAllGroups()
173 return viewStyle.getColourAppliesToAllGroups();
178 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
180 public boolean getAbovePIDThreshold()
182 return viewStyle.getAbovePIDThreshold();
187 * @see jalview.api.ViewStyleI#setIncrement(int)
189 public void setIncrement(int inc)
191 viewStyle.setIncrement(inc);
196 * @see jalview.api.ViewStyleI#getIncrement()
198 public int getIncrement()
200 return viewStyle.getIncrement();
205 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
207 public void setConservationSelected(boolean b)
209 viewStyle.setConservationSelected(b);
214 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
216 public void setShowHiddenMarkers(boolean show)
218 viewStyle.setShowHiddenMarkers(show);
223 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
225 public boolean getShowHiddenMarkers()
227 return viewStyle.getShowHiddenMarkers();
232 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
234 public void setScaleRightWrapped(boolean b)
236 viewStyle.setScaleRightWrapped(b);
241 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
243 public void setScaleLeftWrapped(boolean b)
245 viewStyle.setScaleLeftWrapped(b);
250 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
252 public void setScaleAboveWrapped(boolean b)
254 viewStyle.setScaleAboveWrapped(b);
259 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
261 public boolean getScaleLeftWrapped()
263 return viewStyle.getScaleLeftWrapped();
268 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
270 public boolean getScaleAboveWrapped()
272 return viewStyle.getScaleAboveWrapped();
277 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
279 public boolean getScaleRightWrapped()
281 return viewStyle.getScaleRightWrapped();
286 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
288 public void setAbovePIDThreshold(boolean b)
290 viewStyle.setAbovePIDThreshold(b);
295 * @see jalview.api.ViewStyleI#setThreshold(int)
297 public void setThreshold(int thresh)
299 viewStyle.setThreshold(thresh);
304 * @see jalview.api.ViewStyleI#getThreshold()
306 public int getThreshold()
308 return viewStyle.getThreshold();
313 * @see jalview.api.ViewStyleI#getShowJVSuffix()
315 public boolean getShowJVSuffix()
317 return viewStyle.getShowJVSuffix();
322 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
324 public void setShowJVSuffix(boolean b)
326 viewStyle.setShowJVSuffix(b);
331 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
333 public void setWrapAlignment(boolean state)
335 viewStyle.setWrapAlignment(state);
340 * @see jalview.api.ViewStyleI#setShowText(boolean)
342 public void setShowText(boolean state)
344 viewStyle.setShowText(state);
349 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
351 public void setRenderGaps(boolean state)
353 viewStyle.setRenderGaps(state);
358 * @see jalview.api.ViewStyleI#getColourText()
360 public boolean getColourText()
362 return viewStyle.getColourText();
367 * @see jalview.api.ViewStyleI#setColourText(boolean)
369 public void setColourText(boolean state)
371 viewStyle.setColourText(state);
376 * @see jalview.api.ViewStyleI#getWrapAlignment()
378 public boolean getWrapAlignment()
380 return viewStyle.getWrapAlignment();
385 * @see jalview.api.ViewStyleI#getShowText()
387 public boolean getShowText()
389 return viewStyle.getShowText();
394 * @see jalview.api.ViewStyleI#getWrappedWidth()
396 public int getWrappedWidth()
398 return viewStyle.getWrappedWidth();
403 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
405 public void setWrappedWidth(int w)
407 viewStyle.setWrappedWidth(w);
412 * @see jalview.api.ViewStyleI#getCharHeight()
414 public int getCharHeight()
416 return viewStyle.getCharHeight();
421 * @see jalview.api.ViewStyleI#setCharHeight(int)
423 public void setCharHeight(int h)
425 viewStyle.setCharHeight(h);
430 * @see jalview.api.ViewStyleI#getCharWidth()
432 public int getCharWidth()
434 return viewStyle.getCharWidth();
439 * @see jalview.api.ViewStyleI#setCharWidth(int)
441 public void setCharWidth(int w)
443 viewStyle.setCharWidth(w);
448 * @see jalview.api.ViewStyleI#getShowBoxes()
450 public boolean getShowBoxes()
452 return viewStyle.getShowBoxes();
457 * @see jalview.api.ViewStyleI#getShowUnconserved()
459 public boolean getShowUnconserved()
461 return viewStyle.getShowUnconserved();
465 * @param showunconserved
466 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
468 public void setShowUnconserved(boolean showunconserved)
470 viewStyle.setShowUnconserved(showunconserved);
475 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
477 public void setSeqNameItalics(boolean default1)
479 viewStyle.setSeqNameItalics(default1);
484 * @see jalview.api.ViewStyleI#setShowSeqFeaturesHeight(boolean)
486 public void setShowSeqFeaturesHeight(boolean selected)
488 viewStyle.setShowSeqFeaturesHeight(selected);
492 * alignment displayed in the viewport. Please use get/setter
494 protected AlignmentI alignment;
497 public AlignmentI getAlignment()
503 public char getGapCharacter()
505 return alignment.getGapCharacter();
508 protected String sequenceSetID;
511 * probably unused indicator that view is of a dataset rather than an
514 protected boolean isDataset = false;
516 public void setDataset(boolean b)
521 public boolean isDataset()
527 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
529 protected ColumnSelection colSel = new ColumnSelection();
531 public boolean autoCalculateConsensus = true;
533 protected boolean autoCalculateStrucConsensus = true;
535 protected boolean ignoreGapsInConsensusCalculation = false;
537 protected ColourSchemeI globalColourScheme = null;
541 public void setGlobalColourScheme(ColourSchemeI cs)
543 // TODO: logic refactored from AlignFrame changeColour -
544 // autorecalc stuff should be changed to rely on the worker system
545 // check to see if we should implement a changeColour(cs) method rather than
546 // put th logic in here
547 // - means that caller decides if they want to just modify state and defer
548 // calculation till later or to do all calculations in thread.
550 globalColourScheme = cs;
551 boolean recalc = false;
554 cs.setConservationApplied(recalc = getConservationSelected());
555 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
556 || cs instanceof Blosum62ColourScheme)
559 cs.setThreshold(viewStyle.getThreshold(),
560 ignoreGapsInConsensusCalculation);
564 cs.setThreshold(0, ignoreGapsInConsensusCalculation);
568 cs.setConsensus(hconsensus);
569 cs.setConservation(hconservation);
571 cs.alignmentChanged(alignment, hiddenRepSequences);
573 if (getColourAppliesToAllGroups())
575 for (SequenceGroup sg : getAlignment().getGroups())
582 sg.cs = cs.applyTo(sg, getHiddenRepSequences());
583 sg.setConsPercGaps(ConsPercGaps);
584 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
585 || cs instanceof Blosum62ColourScheme)
587 sg.cs.setThreshold(viewStyle.getThreshold(),
588 isIgnoreGapsConsensus());
593 sg.cs.setThreshold(0, isIgnoreGapsConsensus());
596 if (getConservationSelected())
598 sg.cs.setConservationApplied(true);
603 sg.cs.setConservation(null);
604 // sg.cs.setThreshold(0, getIgnoreGapsConsensus());
608 sg.recalcConservation();
612 sg.cs.alignmentChanged(sg, hiddenRepSequences);
620 public ColourSchemeI getGlobalColourScheme()
622 return globalColourScheme;
625 protected AlignmentAnnotation consensus;
627 protected AlignmentAnnotation strucConsensus;
629 protected AlignmentAnnotation conservation;
631 protected AlignmentAnnotation quality;
633 protected AlignmentAnnotation[] groupConsensus;
635 protected AlignmentAnnotation[] groupConservation;
638 * results of alignment consensus analysis for visible portion of view
640 protected Hashtable[] hconsensus = null;
643 * results of secondary structure base pair consensus for visible portion of
646 protected Hashtable[] hStrucConsensus = null;
648 protected Conservation hconservation = null;
651 public void setConservation(Conservation cons)
653 hconservation = cons;
657 * percentage gaps allowed in a column before all amino acid properties should
658 * be considered unconserved
660 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
663 public int getConsPercGaps()
669 public void setSequenceConsensusHash(Hashtable[] hconsensus)
671 this.hconsensus = hconsensus;
676 public Hashtable[] getSequenceConsensusHash()
682 public Hashtable[] getRnaStructureConsensusHash()
684 return hStrucConsensus;
688 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
690 this.hStrucConsensus = hStrucConsensus;
695 public AlignmentAnnotation getAlignmentQualityAnnot()
701 public AlignmentAnnotation getAlignmentConservationAnnotation()
707 public AlignmentAnnotation getAlignmentConsensusAnnotation()
713 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
715 return strucConsensus;
718 protected AlignCalcManagerI calculator = new AlignCalcManager();
721 * trigger update of conservation annotation
723 public void updateConservation(final AlignmentViewPanel ap)
725 // see note in mantis : issue number 8585
726 if (alignment.isNucleotide() || conservation == null
727 || !autoCalculateConsensus)
732 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
734 calculator.registerWorker(new jalview.workers.ConservationThread(
740 * trigger update of consensus annotation
742 public void updateConsensus(final AlignmentViewPanel ap)
744 // see note in mantis : issue number 8585
745 if (consensus == null || !autoCalculateConsensus)
749 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
751 calculator.registerWorker(new ConsensusThread(this, ap));
755 // --------START Structure Conservation
756 public void updateStrucConsensus(final AlignmentViewPanel ap)
758 if (autoCalculateStrucConsensus && strucConsensus == null
759 && alignment.isNucleotide() && alignment.hasRNAStructure())
761 // secondary structure has been added - so init the consensus line
765 // see note in mantis : issue number 8585
766 if (strucConsensus == null || !autoCalculateStrucConsensus)
770 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
772 calculator.registerWorker(new StrucConsensusThread(this, ap));
776 public boolean isCalcInProgress()
778 return calculator.isWorking();
782 public boolean isCalculationInProgress(
783 AlignmentAnnotation alignmentAnnotation)
785 if (!alignmentAnnotation.autoCalculated)
789 if (calculator.workingInvolvedWith(alignmentAnnotation))
791 // System.err.println("grey out ("+alignmentAnnotation.label+")");
798 public boolean isClosed()
800 // TODO: check that this isClosed is only true after panel is closed, not
801 // before it is fully constructed.
802 return alignment == null;
806 public AlignCalcManagerI getCalcManager()
812 * should conservation rows be shown for groups
814 protected boolean showGroupConservation = false;
817 * should consensus rows be shown for groups
819 protected boolean showGroupConsensus = false;
822 * should consensus profile be rendered by default
824 protected boolean showSequenceLogo = false;
827 * should consensus profile be rendered normalised to row height
829 protected boolean normaliseSequenceLogo = false;
832 * should consensus histograms be rendered by default
834 protected boolean showConsensusHistogram = true;
837 * @return the showConsensusProfile
840 public boolean isShowSequenceLogo()
842 return showSequenceLogo;
846 * @param showSequenceLogo
849 public void setShowSequenceLogo(boolean showSequenceLogo)
851 if (showSequenceLogo != this.showSequenceLogo)
853 // TODO: decouple settings setting from calculation when refactoring
854 // annotation update method from alignframe to viewport
855 this.showSequenceLogo = showSequenceLogo;
856 calculator.updateAnnotationFor(ConsensusThread.class);
857 calculator.updateAnnotationFor(StrucConsensusThread.class);
859 this.showSequenceLogo = showSequenceLogo;
863 * @param showConsensusHistogram
864 * the showConsensusHistogram to set
866 public void setShowConsensusHistogram(boolean showConsensusHistogram)
868 this.showConsensusHistogram = showConsensusHistogram;
872 * @return the showGroupConservation
874 public boolean isShowGroupConservation()
876 return showGroupConservation;
880 * @param showGroupConservation
881 * the showGroupConservation to set
883 public void setShowGroupConservation(boolean showGroupConservation)
885 this.showGroupConservation = showGroupConservation;
889 * @return the showGroupConsensus
891 public boolean isShowGroupConsensus()
893 return showGroupConsensus;
897 * @param showGroupConsensus
898 * the showGroupConsensus to set
900 public void setShowGroupConsensus(boolean showGroupConsensus)
902 this.showGroupConsensus = showGroupConsensus;
907 * @return flag to indicate if the consensus histogram should be rendered by
911 public boolean isShowConsensusHistogram()
913 return this.showConsensusHistogram;
917 * when set, updateAlignment will always ensure sequences are of equal length
919 private boolean padGaps = false;
922 * when set, alignment should be reordered according to a newly opened tree
924 public boolean sortByTree = false;
930 * @return null or the currently selected sequence region
933 public SequenceGroup getSelectionGroup()
935 return selectionGroup;
939 * Set the selection group for this window.
942 * - group holding references to sequences in this alignment view
946 public void setSelectionGroup(SequenceGroup sg)
951 public void setHiddenColumns(ColumnSelection colsel)
953 this.colSel = colsel;
957 public ColumnSelection getColumnSelection()
963 public void setColumnSelection(ColumnSelection colSel)
965 this.colSel = colSel;
968 updateHiddenColumns();
977 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
979 return hiddenRepSequences;
983 public void setHiddenRepSequences(
984 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
986 this.hiddenRepSequences = hiddenRepSequences;
990 public boolean hasHiddenColumns()
992 return colSel != null && colSel.hasHiddenColumns();
995 public void updateHiddenColumns()
997 // this method doesn't really do anything now. But - it could, since a
998 // column Selection could be in the process of modification
999 // hasHiddenColumns = colSel.hasHiddenColumns();
1002 protected boolean hasHiddenRows = false;
1005 public boolean hasHiddenRows()
1007 return hasHiddenRows;
1010 protected SequenceGroup selectionGroup;
1012 public void setSequenceSetId(String newid)
1014 if (sequenceSetID != null)
1017 .println("Warning - overwriting a sequenceSetId for a viewport!");
1019 sequenceSetID = new String(newid);
1023 public String getSequenceSetId()
1025 if (sequenceSetID == null)
1027 sequenceSetID = alignment.hashCode() + "";
1030 return sequenceSetID;
1034 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1037 protected String viewId = null;
1039 public String getViewId()
1043 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1048 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1050 ignoreGapsInConsensusCalculation = b;
1053 updateConsensus(ap);
1054 if (globalColourScheme != null)
1056 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1057 ignoreGapsInConsensusCalculation);
1063 private long sgrouphash = -1, colselhash = -1;
1066 * checks current SelectionGroup against record of last hash value, and
1070 * update the record of last hash value
1072 * @return true if SelectionGroup changed since last call (when b is true)
1074 public boolean isSelectionGroupChanged(boolean b)
1076 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1077 : selectionGroup.hashCode();
1078 if (hc != -1 && hc != sgrouphash)
1090 * checks current colsel against record of last hash value, and optionally
1094 * update the record of last hash value
1095 * @return true if colsel changed since last call (when b is true)
1097 public boolean isColSelChanged(boolean b)
1099 int hc = (colSel == null || colSel.size() == 0) ? -1 : colSel
1101 if (hc != -1 && hc != colselhash)
1113 public boolean isIgnoreGapsConsensus()
1115 return ignoreGapsInConsensusCalculation;
1118 // / property change stuff
1120 // JBPNote Prolly only need this in the applet version.
1121 private final java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
1124 protected boolean showConservation = true;
1126 protected boolean showQuality = true;
1128 protected boolean showConsensus = true;
1130 Hashtable sequenceColours;
1133 * Property change listener for changes in alignment
1138 public void addPropertyChangeListener(
1139 java.beans.PropertyChangeListener listener)
1141 changeSupport.addPropertyChangeListener(listener);
1150 public void removePropertyChangeListener(
1151 java.beans.PropertyChangeListener listener)
1153 changeSupport.removePropertyChangeListener(listener);
1157 * Property change listener for changes in alignment
1166 public void firePropertyChange(String prop, Object oldvalue,
1169 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1172 // common hide/show column stuff
1174 public void hideSelectedColumns()
1176 if (colSel.size() < 1)
1181 colSel.hideSelectedColumns();
1182 setSelectionGroup(null);
1186 public void hideColumns(int start, int end)
1190 colSel.hideColumns(start);
1194 colSel.hideColumns(start, end);
1198 public void showColumn(int col)
1200 colSel.revealHiddenColumns(col);
1204 public void showAllHiddenColumns()
1206 colSel.revealAllHiddenColumns();
1209 // common hide/show seq stuff
1210 public void showAllHiddenSeqs()
1212 if (alignment.getHiddenSequences().getSize() > 0)
1214 if (selectionGroup == null)
1216 selectionGroup = new SequenceGroup();
1217 selectionGroup.setEndRes(alignment.getWidth() - 1);
1219 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1220 hiddenRepSequences);
1221 for (SequenceI seq : tmp)
1223 selectionGroup.addSequence(seq, false);
1224 setSequenceAnnotationsVisible(seq, true);
1227 hasHiddenRows = false;
1228 hiddenRepSequences = null;
1230 firePropertyChange("alignment", null, alignment.getSequences());
1231 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1237 public void showSequence(int index)
1239 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1241 hiddenRepSequences);
1244 if (selectionGroup == null)
1246 selectionGroup = new SequenceGroup();
1247 selectionGroup.setEndRes(alignment.getWidth() - 1);
1250 for (SequenceI seq : tmp)
1252 selectionGroup.addSequence(seq, false);
1253 setSequenceAnnotationsVisible(seq, true);
1255 // JBPNote: refactor: only update flag if we modified visiblity (used to
1256 // do this regardless)
1257 if (alignment.getHiddenSequences().getSize() < 1)
1259 hasHiddenRows = false;
1261 firePropertyChange("alignment", null, alignment.getSequences());
1266 public void hideAllSelectedSeqs()
1268 if (selectionGroup == null || selectionGroup.getSize() < 1)
1273 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1277 setSelectionGroup(null);
1280 public void hideSequence(SequenceI[] seq)
1284 for (int i = 0; i < seq.length; i++)
1286 alignment.getHiddenSequences().hideSequence(seq[i]);
1287 setSequenceAnnotationsVisible(seq[i], false);
1289 hasHiddenRows = true;
1290 firePropertyChange("alignment", null, alignment.getSequences());
1295 * Set visibility for any annotations for the given sequence.
1299 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1302 for (AlignmentAnnotation ann : alignment.getAlignmentAnnotation())
1304 if (ann.sequenceRef == sequenceI)
1306 ann.visible = visible;
1311 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1313 int sSize = sg.getSize();
1319 if (hiddenRepSequences == null)
1321 hiddenRepSequences = new Hashtable();
1324 hiddenRepSequences.put(repSequence, sg);
1326 // Hide all sequences except the repSequence
1327 SequenceI[] seqs = new SequenceI[sSize - 1];
1329 for (int i = 0; i < sSize; i++)
1331 if (sg.getSequenceAt(i) != repSequence)
1333 if (index == sSize - 1)
1338 seqs[index++] = sg.getSequenceAt(i);
1341 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1342 sg.setHidereps(true); // note: not done in 2.7applet
1347 public boolean isHiddenRepSequence(SequenceI seq)
1349 return alignment.getSeqrep()==seq || (hiddenRepSequences != null
1350 && hiddenRepSequences.containsKey(seq));
1353 public SequenceGroup getRepresentedSequences(SequenceI seq)
1355 return (SequenceGroup) (hiddenRepSequences == null ? null
1356 : hiddenRepSequences.get(seq));
1360 public int adjustForHiddenSeqs(int alignmentIndex)
1362 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1367 public abstract void sendSelection();
1370 public void invertColumnSelection()
1372 colSel.invertColumnSelection(0, alignment.getWidth());
1377 public SequenceI[] getSelectionAsNewSequence()
1379 SequenceI[] sequences;
1380 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1381 // this was the only caller in the applet for this method
1382 // JBPNote: in applet, this method returned references to the alignment
1383 // sequences, and it did not honour the presence/absence of annotation
1384 // attached to the alignment (probably!)
1385 if (selectionGroup == null || selectionGroup.getSize() == 0)
1387 sequences = alignment.getSequencesArray();
1388 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1389 for (int i = 0; i < sequences.length; i++)
1391 sequences[i] = new Sequence(sequences[i], annots); // construct new
1393 // subset of visible
1399 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1407 public SequenceI[] getSequenceSelection()
1409 SequenceI[] sequences = null;
1410 if (selectionGroup != null)
1412 sequences = selectionGroup.getSequencesInOrder(alignment);
1414 if (sequences == null)
1416 sequences = alignment.getSequencesArray();
1423 public jalview.datamodel.CigarArray getViewAsCigars(
1424 boolean selectedRegionOnly)
1426 return new jalview.datamodel.CigarArray(alignment, colSel,
1427 (selectedRegionOnly ? selectionGroup : null));
1432 public jalview.datamodel.AlignmentView getAlignmentView(
1433 boolean selectedOnly)
1435 return getAlignmentView(selectedOnly, false);
1440 public jalview.datamodel.AlignmentView getAlignmentView(
1441 boolean selectedOnly, boolean markGroups)
1443 return new AlignmentView(alignment, colSel, selectionGroup,
1444 colSel != null && colSel.hasHiddenColumns(), selectedOnly,
1450 public String[] getViewAsString(boolean selectedRegionOnly)
1452 String[] selection = null;
1453 SequenceI[] seqs = null;
1455 int start = 0, end = 0;
1456 if (selectedRegionOnly && selectionGroup != null)
1458 iSize = selectionGroup.getSize();
1459 seqs = selectionGroup.getSequencesInOrder(alignment);
1460 start = selectionGroup.getStartRes();
1461 end = selectionGroup.getEndRes() + 1;
1465 iSize = alignment.getHeight();
1466 seqs = alignment.getSequencesArray();
1467 end = alignment.getWidth();
1470 selection = new String[iSize];
1471 if (colSel != null && colSel.hasHiddenColumns())
1473 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1477 for (i = 0; i < iSize; i++)
1479 selection[i] = seqs[i].getSequenceAsString(start, end);
1488 public int[][] getVisibleRegionBoundaries(int min, int max)
1490 Vector regions = new Vector();
1496 if (colSel != null && colSel.hasHiddenColumns())
1500 start = colSel.adjustForHiddenColumns(start);
1503 end = colSel.getHiddenBoundaryRight(start);
1514 regions.addElement(new int[]
1517 if (colSel != null && colSel.hasHiddenColumns())
1519 start = colSel.adjustForHiddenColumns(end);
1520 start = colSel.getHiddenBoundaryLeft(start) + 1;
1522 } while (end < max);
1524 int[][] startEnd = new int[regions.size()][2];
1526 regions.copyInto(startEnd);
1533 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(boolean selectedOnly)
1535 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1536 AlignmentAnnotation[] aa;
1537 if ((aa=alignment.getAlignmentAnnotation())!=null)
1539 for (AlignmentAnnotation annot:aa)
1541 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1542 if (selectedOnly && selectionGroup!=null)
1544 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(), selectionGroup.getEndRes(),clone);
1546 colSel.makeVisibleAnnotation(clone);
1556 public boolean isPadGaps()
1563 public void setPadGaps(boolean padGaps)
1565 this.padGaps = padGaps;
1569 * apply any post-edit constraints and trigger any calculations needed after
1570 * an edit has been performed on the alignment
1575 public void alignmentChanged(AlignmentViewPanel ap)
1579 alignment.padGaps();
1581 if (autoCalculateConsensus)
1583 updateConsensus(ap);
1585 if (hconsensus != null && autoCalculateConsensus)
1587 updateConservation(ap);
1589 if (autoCalculateStrucConsensus)
1591 updateStrucConsensus(ap);
1594 // Reset endRes of groups if beyond alignment width
1595 int alWidth = alignment.getWidth();
1596 List<SequenceGroup> groups = alignment.getGroups();
1599 for (SequenceGroup sg : groups)
1601 if (sg.getEndRes() > alWidth)
1603 sg.setEndRes(alWidth - 1);
1608 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1610 selectionGroup.setEndRes(alWidth - 1);
1613 resetAllColourSchemes();
1614 calculator.restartWorkers();
1615 // alignment.adjustSequenceAnnotations();
1619 * reset scope and do calculations for all applied colourschemes on alignment
1621 void resetAllColourSchemes()
1623 ColourSchemeI cs = globalColourScheme;
1626 cs.alignmentChanged(alignment, hiddenRepSequences);
1628 cs.setConsensus(hconsensus);
1629 if (cs.conservationApplied())
1631 cs.setConservation(Conservation.calculateConservation("All",
1632 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1633 alignment.getWidth(), false, getConsPercGaps(), false));
1637 for (SequenceGroup sg : alignment.getGroups())
1641 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1643 sg.recalcConservation();
1647 protected void initAutoAnnotation()
1649 // TODO: add menu option action that nulls or creates consensus object
1650 // depending on if the user wants to see the annotation or not in a
1651 // specific alignment
1653 if (hconsensus == null && !isDataset)
1655 if (!alignment.isNucleotide())
1668 private void initConsensus()
1671 consensus = new AlignmentAnnotation("Consensus", "PID",
1672 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1673 consensus.hasText = true;
1674 consensus.autoCalculated = true;
1678 alignment.addAnnotation(consensus);
1682 private void initConservation()
1684 if (showConservation)
1686 if (conservation == null)
1688 conservation = new AlignmentAnnotation("Conservation",
1689 "Conservation of total alignment less than "
1690 + getConsPercGaps() + "% gaps", new Annotation[1],
1691 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1692 conservation.hasText = true;
1693 conservation.autoCalculated = true;
1694 alignment.addAnnotation(conservation);
1699 private void initQuality()
1703 if (quality == null)
1705 quality = new AlignmentAnnotation("Quality",
1706 "Alignment Quality based on Blosum62 scores",
1707 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1708 quality.hasText = true;
1709 quality.autoCalculated = true;
1710 alignment.addAnnotation(quality);
1715 private void initRNAStructure()
1717 if (alignment.hasRNAStructure() && strucConsensus == null)
1719 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1720 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1721 strucConsensus.hasText = true;
1722 strucConsensus.autoCalculated = true;
1726 alignment.addAnnotation(strucConsensus);
1734 * @see jalview.api.AlignViewportI#calcPanelHeight()
1737 public int calcPanelHeight()
1739 // setHeight of panels
1740 AlignmentAnnotation[] aa = getAlignment().getAlignmentAnnotation();
1742 int charHeight = getCharHeight();
1745 BitSet graphgrp = new BitSet();
1746 for (int i = 0; i < aa.length; i++)
1750 System.err.println("Null annotation row: ignoring.");
1757 if (aa[i].graphGroup > -1)
1759 if (graphgrp.get(aa[i].graphGroup))
1765 graphgrp.set(aa[i].graphGroup);
1772 aa[i].height += charHeight;
1780 if (aa[i].graph > 0)
1782 aa[i].height += aa[i].graphHeight;
1785 if (aa[i].height == 0)
1790 height += aa[i].height;
1802 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1803 boolean preserveNewGroupSettings)
1805 boolean updateCalcs = false;
1806 boolean conv = isShowGroupConservation();
1807 boolean cons = isShowGroupConsensus();
1808 boolean showprf = isShowSequenceLogo();
1809 boolean showConsHist = isShowConsensusHistogram();
1810 boolean normLogo = isNormaliseSequenceLogo();
1813 * TODO reorder the annotation rows according to group/sequence ordering on
1816 boolean sortg = true;
1818 // remove old automatic annotation
1819 // add any new annotation
1821 // intersect alignment annotation with alignment groups
1823 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
1824 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
1827 for (int an = 0; an < aan.length; an++)
1829 if (aan[an].autoCalculated && aan[an].groupRef != null)
1831 oldrfs.add(aan[an].groupRef);
1832 alignment.deleteAnnotation(aan[an], false);
1836 if (alignment.getGroups() != null)
1838 for (SequenceGroup sg : alignment.getGroups())
1840 updateCalcs = false;
1841 if (applyGlobalSettings
1842 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
1844 // set defaults for this group's conservation/consensus
1845 sg.setshowSequenceLogo(showprf);
1846 sg.setShowConsensusHistogram(showConsHist);
1847 sg.setNormaliseSequenceLogo(normLogo);
1852 alignment.addAnnotation(sg.getConservationRow(), 0);
1857 alignment.addAnnotation(sg.getConsensus(), 0);
1859 // refresh the annotation rows
1862 sg.recalcConservation();
1869 public boolean isDisplayReferenceSeq()
1871 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
1875 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
1877 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
1880 public boolean isColourByReferenceSeq()
1882 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
1887 public Color getSequenceColour(SequenceI seq)
1889 Color sqc = Color.white;
1890 if (sequenceColours != null)
1892 sqc = (Color) sequenceColours.get(seq);
1902 public void setSequenceColour(SequenceI seq, Color col)
1904 if (sequenceColours == null)
1906 sequenceColours = new Hashtable();
1911 sequenceColours.remove(seq);
1915 sequenceColours.put(seq, col);
1920 public void updateSequenceIdColours()
1922 if (sequenceColours == null)
1924 sequenceColours = new Hashtable();
1926 for (SequenceGroup sg : alignment.getGroups())
1928 if (sg.idColour != null)
1930 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
1932 sequenceColours.put(s, sg.idColour);
1939 public void clearSequenceColours()
1941 sequenceColours = null;
1944 FeaturesDisplayedI featuresDisplayed = null;
1947 public FeaturesDisplayedI getFeaturesDisplayed()
1949 return featuresDisplayed;
1953 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
1955 featuresDisplayed = featuresDisplayedI;
1959 public boolean areFeaturesDisplayed()
1961 return featuresDisplayed != null && featuresDisplayed.getRegisterdFeaturesCount()>0;
1968 * features are displayed if true
1971 public void setShowSequenceFeatures(boolean b)
1973 viewStyle.setShowSequenceFeatures(b);
1976 public boolean isShowSequenceFeatures()
1978 return viewStyle.isShowSequenceFeatures();
1982 public void setShowSequenceFeaturesHeight(boolean selected)
1984 viewStyle.setShowSeqFeaturesHeight(selected);
1988 public boolean isShowSequenceFeaturesHeight()
1990 return viewStyle.isShowSequenceFeaturesHeight();
1996 public void setShowAnnotation(boolean b)
1998 viewStyle.setShowAnnotation(b);
2002 public boolean isShowAnnotation()
2004 return viewStyle.isShowAnnotation();
2008 public boolean isRightAlignIds()
2010 return viewStyle.isRightAlignIds();
2014 public void setRightAlignIds(boolean rightAlignIds)
2016 viewStyle.setRightAlignIds(rightAlignIds);
2020 public boolean getConservationSelected()
2022 return viewStyle.getConservationSelected();
2026 public void setShowBoxes(boolean state)
2028 viewStyle.setShowBoxes(state);
2033 * @see jalview.api.ViewStyleI#getTextColour()
2035 public Color getTextColour()
2037 return viewStyle.getTextColour();
2042 * @see jalview.api.ViewStyleI#getTextColour2()
2044 public Color getTextColour2()
2046 return viewStyle.getTextColour2();
2051 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2053 public int getThresholdTextColour()
2055 return viewStyle.getThresholdTextColour();
2060 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2062 public boolean isConservationColourSelected()
2064 return viewStyle.isConservationColourSelected();
2069 * @see jalview.api.ViewStyleI#isRenderGaps()
2071 public boolean isRenderGaps()
2073 return viewStyle.isRenderGaps();
2078 * @see jalview.api.ViewStyleI#isShowColourText()
2080 public boolean isShowColourText()
2082 return viewStyle.isShowColourText();
2087 * @see jalview.api.ViewStyleI#isShowSeqFeaturesHeight()
2089 public boolean isShowSeqFeaturesHeight()
2091 return viewStyle.isShowSeqFeaturesHeight();
2095 * @param conservationColourSelected
2096 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2098 public void setConservationColourSelected(
2099 boolean conservationColourSelected)
2101 viewStyle.setConservationColourSelected(conservationColourSelected);
2105 * @param showColourText
2106 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2108 public void setShowColourText(boolean showColourText)
2110 viewStyle.setShowColourText(showColourText);
2115 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2117 public void setTextColour(Color textColour)
2119 viewStyle.setTextColour(textColour);
2123 * @param thresholdTextColour
2124 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2126 public void setThresholdTextColour(int thresholdTextColour)
2128 viewStyle.setThresholdTextColour(thresholdTextColour);
2132 * @param textColour2
2133 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2135 public void setTextColour2(Color textColour2)
2137 viewStyle.setTextColour2(textColour2);
2141 public ViewStyleI getViewStyle()
2143 return new ViewStyle(viewStyle);
2147 public void setViewStyle(ViewStyleI settingsForView)
2149 viewStyle = new ViewStyle(settingsForView);
2153 public boolean sameStyle(ViewStyleI them)
2155 return viewStyle.sameStyle(them);
2160 * @see jalview.api.ViewStyleI#getIdWidth()
2162 public int getIdWidth()
2164 return viewStyle.getIdWidth();
2169 * @see jalview.api.ViewStyleI#setIdWidth(int)
2171 public void setIdWidth(int i)
2173 viewStyle.setIdWidth(i);
2178 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2180 public boolean isCentreColumnLabels()
2182 return viewStyle.isCentreColumnLabels();
2186 * @param centreColumnLabels
2187 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2189 public void setCentreColumnLabels(boolean centreColumnLabels)
2191 viewStyle.setCentreColumnLabels(centreColumnLabels);
2196 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2198 public void setShowDBRefs(boolean showdbrefs)
2200 viewStyle.setShowDBRefs(showdbrefs);
2205 * @see jalview.api.ViewStyleI#isShowDBRefs()
2207 public boolean isShowDBRefs()
2209 return viewStyle.isShowDBRefs();
2214 * @see jalview.api.ViewStyleI#isShowNPFeats()
2216 public boolean isShowNPFeats()
2218 return viewStyle.isShowNPFeats();
2222 * @param shownpfeats
2223 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2225 public void setShowNPFeats(boolean shownpfeats)
2227 viewStyle.setShowNPFeats(shownpfeats);