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();
68 * @param upperCasebold
69 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
71 public void setUpperCasebold(boolean upperCasebold)
73 viewStyle.setUpperCasebold(upperCasebold);
78 * @see jalview.api.ViewStyleI#isUpperCasebold()
80 public boolean isUpperCasebold()
82 return viewStyle.isUpperCasebold();
87 * @see jalview.api.ViewStyleI#isSeqNameItalics()
89 public boolean isSeqNameItalics()
91 return viewStyle.isSeqNameItalics();
95 * @param colourByReferenceSeq
96 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
98 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
100 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
105 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
107 public void setColourAppliesToAllGroups(boolean b)
109 viewStyle.setColourAppliesToAllGroups(b);
114 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
116 public boolean getColourAppliesToAllGroups()
118 return viewStyle.getColourAppliesToAllGroups();
123 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
125 public boolean getAbovePIDThreshold()
127 return viewStyle.getAbovePIDThreshold();
132 * @see jalview.api.ViewStyleI#setIncrement(int)
134 public void setIncrement(int inc)
136 viewStyle.setIncrement(inc);
141 * @see jalview.api.ViewStyleI#getIncrement()
143 public int getIncrement()
145 return viewStyle.getIncrement();
150 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
152 public void setConservationSelected(boolean b)
154 viewStyle.setConservationSelected(b);
159 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
161 public void setShowHiddenMarkers(boolean show)
163 viewStyle.setShowHiddenMarkers(show);
168 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
170 public boolean getShowHiddenMarkers()
172 return viewStyle.getShowHiddenMarkers();
177 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
179 public void setScaleRightWrapped(boolean b)
181 viewStyle.setScaleRightWrapped(b);
186 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
188 public void setScaleLeftWrapped(boolean b)
190 viewStyle.setScaleLeftWrapped(b);
195 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
197 public void setScaleAboveWrapped(boolean b)
199 viewStyle.setScaleAboveWrapped(b);
204 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
206 public boolean getScaleLeftWrapped()
208 return viewStyle.getScaleLeftWrapped();
213 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
215 public boolean getScaleAboveWrapped()
217 return viewStyle.getScaleAboveWrapped();
222 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
224 public boolean getScaleRightWrapped()
226 return viewStyle.getScaleRightWrapped();
231 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
233 public void setAbovePIDThreshold(boolean b)
235 viewStyle.setAbovePIDThreshold(b);
240 * @see jalview.api.ViewStyleI#setThreshold(int)
242 public void setThreshold(int thresh)
244 viewStyle.setThreshold(thresh);
249 * @see jalview.api.ViewStyleI#getThreshold()
251 public int getThreshold()
253 return viewStyle.getThreshold();
258 * @see jalview.api.ViewStyleI#getShowJVSuffix()
260 public boolean getShowJVSuffix()
262 return viewStyle.getShowJVSuffix();
267 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
269 public void setShowJVSuffix(boolean b)
271 viewStyle.setShowJVSuffix(b);
276 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
278 public void setWrapAlignment(boolean state)
280 viewStyle.setWrapAlignment(state);
285 * @see jalview.api.ViewStyleI#setShowText(boolean)
287 public void setShowText(boolean state)
289 viewStyle.setShowText(state);
294 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
296 public void setRenderGaps(boolean state)
298 viewStyle.setRenderGaps(state);
303 * @see jalview.api.ViewStyleI#getColourText()
305 public boolean getColourText()
307 return viewStyle.getColourText();
312 * @see jalview.api.ViewStyleI#setColourText(boolean)
314 public void setColourText(boolean state)
316 viewStyle.setColourText(state);
321 * @see jalview.api.ViewStyleI#getWrapAlignment()
323 public boolean getWrapAlignment()
325 return viewStyle.getWrapAlignment();
330 * @see jalview.api.ViewStyleI#getShowText()
332 public boolean getShowText()
334 return viewStyle.getShowText();
339 * @see jalview.api.ViewStyleI#getWrappedWidth()
341 public int getWrappedWidth()
343 return viewStyle.getWrappedWidth();
348 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
350 public void setWrappedWidth(int w)
352 viewStyle.setWrappedWidth(w);
357 * @see jalview.api.ViewStyleI#getCharHeight()
359 public int getCharHeight()
361 return viewStyle.getCharHeight();
366 * @see jalview.api.ViewStyleI#setCharHeight(int)
368 public void setCharHeight(int h)
370 viewStyle.setCharHeight(h);
375 * @see jalview.api.ViewStyleI#getCharWidth()
377 public int getCharWidth()
379 return viewStyle.getCharWidth();
384 * @see jalview.api.ViewStyleI#setCharWidth(int)
386 public void setCharWidth(int w)
388 viewStyle.setCharWidth(w);
393 * @see jalview.api.ViewStyleI#getShowBoxes()
395 public boolean getShowBoxes()
397 return viewStyle.getShowBoxes();
402 * @see jalview.api.ViewStyleI#getShowUnconserved()
404 public boolean getShowUnconserved()
406 return viewStyle.getShowUnconserved();
410 * @param showunconserved
411 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
413 public void setShowUnconserved(boolean showunconserved)
415 viewStyle.setShowUnconserved(showunconserved);
420 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
422 public void setSeqNameItalics(boolean default1)
424 viewStyle.setSeqNameItalics(default1);
429 * @see jalview.api.ViewStyleI#setShowSeqFeaturesHeight(boolean)
431 public void setShowSeqFeaturesHeight(boolean selected)
433 viewStyle.setShowSeqFeaturesHeight(selected);
437 * alignment displayed in the viewport. Please use get/setter
439 protected AlignmentI alignment;
442 public AlignmentI getAlignment()
448 public char getGapCharacter()
450 return alignment.getGapCharacter();
453 protected String sequenceSetID;
456 * probably unused indicator that view is of a dataset rather than an
459 protected boolean isDataset = false;
461 public void setDataset(boolean b)
466 public boolean isDataset()
472 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
474 protected ColumnSelection colSel = new ColumnSelection();
476 public boolean autoCalculateConsensus = true;
478 protected boolean autoCalculateStrucConsensus = true;
480 protected boolean ignoreGapsInConsensusCalculation = false;
482 protected ColourSchemeI globalColourScheme = null;
486 public void setGlobalColourScheme(ColourSchemeI cs)
488 // TODO: logic refactored from AlignFrame changeColour -
489 // autorecalc stuff should be changed to rely on the worker system
490 // check to see if we should implement a changeColour(cs) method rather than
491 // put th logic in here
492 // - means that caller decides if they want to just modify state and defer
493 // calculation till later or to do all calculations in thread.
495 globalColourScheme = cs;
496 boolean recalc = false;
499 cs.setConservationApplied(recalc = getConservationSelected());
500 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
501 || cs instanceof Blosum62ColourScheme)
504 cs.setThreshold(viewStyle.getThreshold(),
505 ignoreGapsInConsensusCalculation);
509 cs.setThreshold(0, ignoreGapsInConsensusCalculation);
513 cs.setConsensus(hconsensus);
514 cs.setConservation(hconservation);
516 cs.alignmentChanged(alignment, hiddenRepSequences);
518 if (getColourAppliesToAllGroups())
520 for (SequenceGroup sg : getAlignment().getGroups())
527 sg.cs = cs.applyTo(sg, getHiddenRepSequences());
528 sg.setConsPercGaps(ConsPercGaps);
529 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
530 || cs instanceof Blosum62ColourScheme)
532 sg.cs.setThreshold(viewStyle.getThreshold(),
533 getIgnoreGapsConsensus());
538 sg.cs.setThreshold(0, getIgnoreGapsConsensus());
541 if (getConservationSelected())
543 sg.cs.setConservationApplied(true);
548 sg.cs.setConservation(null);
549 // sg.cs.setThreshold(0, getIgnoreGapsConsensus());
553 sg.recalcConservation();
557 sg.cs.alignmentChanged(sg, hiddenRepSequences);
565 public ColourSchemeI getGlobalColourScheme()
567 return globalColourScheme;
570 protected AlignmentAnnotation consensus;
572 protected AlignmentAnnotation strucConsensus;
574 protected AlignmentAnnotation conservation;
576 protected AlignmentAnnotation quality;
578 protected AlignmentAnnotation[] groupConsensus;
580 protected AlignmentAnnotation[] groupConservation;
583 * results of alignment consensus analysis for visible portion of view
585 protected Hashtable[] hconsensus = null;
588 * results of secondary structure base pair consensus for visible portion of
591 protected Hashtable[] hStrucConsensus = null;
593 protected Conservation hconservation = null;
596 public void setConservation(Conservation cons)
598 hconservation = cons;
602 * percentage gaps allowed in a column before all amino acid properties should
603 * be considered unconserved
605 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
608 public int getConsPercGaps()
614 public void setSequenceConsensusHash(Hashtable[] hconsensus)
616 this.hconsensus = hconsensus;
621 public Hashtable[] getSequenceConsensusHash()
627 public Hashtable[] getRnaStructureConsensusHash()
629 return hStrucConsensus;
633 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
635 this.hStrucConsensus = hStrucConsensus;
640 public AlignmentAnnotation getAlignmentQualityAnnot()
646 public AlignmentAnnotation getAlignmentConservationAnnotation()
652 public AlignmentAnnotation getAlignmentConsensusAnnotation()
658 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
660 return strucConsensus;
663 protected AlignCalcManagerI calculator = new AlignCalcManager();
666 * trigger update of conservation annotation
668 public void updateConservation(final AlignmentViewPanel ap)
670 // see note in mantis : issue number 8585
671 if (alignment.isNucleotide() || conservation == null
672 || !autoCalculateConsensus)
677 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
679 calculator.registerWorker(new jalview.workers.ConservationThread(
685 * trigger update of consensus annotation
687 public void updateConsensus(final AlignmentViewPanel ap)
689 // see note in mantis : issue number 8585
690 if (consensus == null || !autoCalculateConsensus)
694 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
696 calculator.registerWorker(new ConsensusThread(this, ap));
700 // --------START Structure Conservation
701 public void updateStrucConsensus(final AlignmentViewPanel ap)
703 if (autoCalculateStrucConsensus && strucConsensus == null
704 && alignment.isNucleotide() && alignment.hasRNAStructure())
706 // secondary structure has been added - so init the consensus line
710 // see note in mantis : issue number 8585
711 if (strucConsensus == null || !autoCalculateStrucConsensus)
715 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
717 calculator.registerWorker(new StrucConsensusThread(this, ap));
721 public boolean isCalcInProgress()
723 return calculator.isWorking();
727 public boolean isCalculationInProgress(
728 AlignmentAnnotation alignmentAnnotation)
730 if (!alignmentAnnotation.autoCalculated)
734 if (calculator.workingInvolvedWith(alignmentAnnotation))
736 // System.err.println("grey out ("+alignmentAnnotation.label+")");
743 public boolean isClosed()
745 // TODO: check that this isClosed is only true after panel is closed, not
746 // before it is fully constructed.
747 return alignment == null;
751 public AlignCalcManagerI getCalcManager()
757 * should conservation rows be shown for groups
759 protected boolean showGroupConservation = false;
762 * should consensus rows be shown for groups
764 protected boolean showGroupConsensus = false;
767 * should consensus profile be rendered by default
769 protected boolean showSequenceLogo = false;
772 * should consensus profile be rendered normalised to row height
774 protected boolean normaliseSequenceLogo = false;
777 * should consensus histograms be rendered by default
779 protected boolean showConsensusHistogram = true;
782 * @return the showConsensusProfile
785 public boolean isShowSequenceLogo()
787 return showSequenceLogo;
791 * @param showSequenceLogo
794 public void setShowSequenceLogo(boolean showSequenceLogo)
796 if (showSequenceLogo != this.showSequenceLogo)
798 // TODO: decouple settings setting from calculation when refactoring
799 // annotation update method from alignframe to viewport
800 this.showSequenceLogo = showSequenceLogo;
801 calculator.updateAnnotationFor(ConsensusThread.class);
802 calculator.updateAnnotationFor(StrucConsensusThread.class);
804 this.showSequenceLogo = showSequenceLogo;
808 * @param showConsensusHistogram
809 * the showConsensusHistogram to set
811 public void setShowConsensusHistogram(boolean showConsensusHistogram)
813 this.showConsensusHistogram = showConsensusHistogram;
817 * @return the showGroupConservation
819 public boolean isShowGroupConservation()
821 return showGroupConservation;
825 * @param showGroupConservation
826 * the showGroupConservation to set
828 public void setShowGroupConservation(boolean showGroupConservation)
830 this.showGroupConservation = showGroupConservation;
834 * @return the showGroupConsensus
836 public boolean isShowGroupConsensus()
838 return showGroupConsensus;
842 * @param showGroupConsensus
843 * the showGroupConsensus to set
845 public void setShowGroupConsensus(boolean showGroupConsensus)
847 this.showGroupConsensus = showGroupConsensus;
852 * @return flag to indicate if the consensus histogram should be rendered by
856 public boolean isShowConsensusHistogram()
858 return this.showConsensusHistogram;
862 * when set, updateAlignment will always ensure sequences are of equal length
864 private boolean padGaps = false;
867 * when set, alignment should be reordered according to a newly opened tree
869 public boolean sortByTree = false;
875 * @return null or the currently selected sequence region
878 public SequenceGroup getSelectionGroup()
880 return selectionGroup;
884 * Set the selection group for this window.
887 * - group holding references to sequences in this alignment view
891 public void setSelectionGroup(SequenceGroup sg)
896 public void setHiddenColumns(ColumnSelection colsel)
898 this.colSel = colsel;
902 public ColumnSelection getColumnSelection()
908 public void setColumnSelection(ColumnSelection colSel)
910 this.colSel = colSel;
913 updateHiddenColumns();
922 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
924 return hiddenRepSequences;
928 public void setHiddenRepSequences(
929 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
931 this.hiddenRepSequences = hiddenRepSequences;
935 public boolean hasHiddenColumns()
937 return colSel != null && colSel.hasHiddenColumns();
940 public void updateHiddenColumns()
942 // this method doesn't really do anything now. But - it could, since a
943 // column Selection could be in the process of modification
944 // hasHiddenColumns = colSel.hasHiddenColumns();
947 protected boolean hasHiddenRows = false;
950 public boolean hasHiddenRows()
952 return hasHiddenRows;
955 protected SequenceGroup selectionGroup;
957 public void setSequenceSetId(String newid)
959 if (sequenceSetID != null)
962 .println("Warning - overwriting a sequenceSetId for a viewport!");
964 sequenceSetID = new String(newid);
968 public String getSequenceSetId()
970 if (sequenceSetID == null)
972 sequenceSetID = alignment.hashCode() + "";
975 return sequenceSetID;
979 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
982 protected String viewId = null;
984 public String getViewId()
988 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
993 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
995 ignoreGapsInConsensusCalculation = b;
999 if (globalColourScheme != null)
1001 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1002 ignoreGapsInConsensusCalculation);
1008 private long sgrouphash = -1, colselhash = -1;
1011 * checks current SelectionGroup against record of last hash value, and
1015 * update the record of last hash value
1017 * @return true if SelectionGroup changed since last call (when b is true)
1019 public boolean isSelectionGroupChanged(boolean b)
1021 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1022 : selectionGroup.hashCode();
1023 if (hc != -1 && hc != sgrouphash)
1035 * checks current colsel against record of last hash value, and optionally
1039 * update the record of last hash value
1040 * @return true if colsel changed since last call (when b is true)
1042 public boolean isColSelChanged(boolean b)
1044 int hc = (colSel == null || colSel.size() == 0) ? -1 : colSel
1046 if (hc != -1 && hc != colselhash)
1058 public boolean getIgnoreGapsConsensus()
1060 return ignoreGapsInConsensusCalculation;
1063 // / property change stuff
1065 // JBPNote Prolly only need this in the applet version.
1066 private final java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
1069 protected boolean showConservation = true;
1071 protected boolean showQuality = true;
1073 protected boolean showConsensus = true;
1075 Hashtable sequenceColours;
1078 * Property change listener for changes in alignment
1083 public void addPropertyChangeListener(
1084 java.beans.PropertyChangeListener listener)
1086 changeSupport.addPropertyChangeListener(listener);
1095 public void removePropertyChangeListener(
1096 java.beans.PropertyChangeListener listener)
1098 changeSupport.removePropertyChangeListener(listener);
1102 * Property change listener for changes in alignment
1111 public void firePropertyChange(String prop, Object oldvalue,
1114 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1117 // common hide/show column stuff
1119 public void hideSelectedColumns()
1121 if (colSel.size() < 1)
1126 colSel.hideSelectedColumns();
1127 setSelectionGroup(null);
1131 public void hideColumns(int start, int end)
1135 colSel.hideColumns(start);
1139 colSel.hideColumns(start, end);
1143 public void showColumn(int col)
1145 colSel.revealHiddenColumns(col);
1149 public void showAllHiddenColumns()
1151 colSel.revealAllHiddenColumns();
1154 // common hide/show seq stuff
1155 public void showAllHiddenSeqs()
1157 if (alignment.getHiddenSequences().getSize() > 0)
1159 if (selectionGroup == null)
1161 selectionGroup = new SequenceGroup();
1162 selectionGroup.setEndRes(alignment.getWidth() - 1);
1164 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1165 hiddenRepSequences);
1166 for (SequenceI seq : tmp)
1168 selectionGroup.addSequence(seq, false);
1169 setSequenceAnnotationsVisible(seq, true);
1172 hasHiddenRows = false;
1173 hiddenRepSequences = null;
1175 firePropertyChange("alignment", null, alignment.getSequences());
1176 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1182 public void showSequence(int index)
1184 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1186 hiddenRepSequences);
1189 if (selectionGroup == null)
1191 selectionGroup = new SequenceGroup();
1192 selectionGroup.setEndRes(alignment.getWidth() - 1);
1195 for (SequenceI seq : tmp)
1197 selectionGroup.addSequence(seq, false);
1198 setSequenceAnnotationsVisible(seq, true);
1200 // JBPNote: refactor: only update flag if we modified visiblity (used to
1201 // do this regardless)
1202 if (alignment.getHiddenSequences().getSize() < 1)
1204 hasHiddenRows = false;
1206 firePropertyChange("alignment", null, alignment.getSequences());
1211 public void hideAllSelectedSeqs()
1213 if (selectionGroup == null || selectionGroup.getSize() < 1)
1218 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1222 setSelectionGroup(null);
1225 public void hideSequence(SequenceI[] seq)
1229 for (int i = 0; i < seq.length; i++)
1231 alignment.getHiddenSequences().hideSequence(seq[i]);
1232 setSequenceAnnotationsVisible(seq[i], false);
1234 hasHiddenRows = true;
1235 firePropertyChange("alignment", null, alignment.getSequences());
1240 * Set visibility for any annotations for the given sequence.
1244 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1247 for (AlignmentAnnotation ann : alignment.getAlignmentAnnotation())
1249 if (ann.sequenceRef == sequenceI)
1251 ann.visible = visible;
1256 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1258 int sSize = sg.getSize();
1264 if (hiddenRepSequences == null)
1266 hiddenRepSequences = new Hashtable();
1269 hiddenRepSequences.put(repSequence, sg);
1271 // Hide all sequences except the repSequence
1272 SequenceI[] seqs = new SequenceI[sSize - 1];
1274 for (int i = 0; i < sSize; i++)
1276 if (sg.getSequenceAt(i) != repSequence)
1278 if (index == sSize - 1)
1283 seqs[index++] = sg.getSequenceAt(i);
1286 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1287 sg.setHidereps(true); // note: not done in 2.7applet
1292 public boolean isHiddenRepSequence(SequenceI seq)
1294 return alignment.getSeqrep()==seq || (hiddenRepSequences != null
1295 && hiddenRepSequences.containsKey(seq));
1298 public SequenceGroup getRepresentedSequences(SequenceI seq)
1300 return (SequenceGroup) (hiddenRepSequences == null ? null
1301 : hiddenRepSequences.get(seq));
1305 public int adjustForHiddenSeqs(int alignmentIndex)
1307 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1312 public abstract void sendSelection();
1315 public void invertColumnSelection()
1317 colSel.invertColumnSelection(0, alignment.getWidth());
1322 public SequenceI[] getSelectionAsNewSequence()
1324 SequenceI[] sequences;
1325 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1326 // this was the only caller in the applet for this method
1327 // JBPNote: in applet, this method returned references to the alignment
1328 // sequences, and it did not honour the presence/absence of annotation
1329 // attached to the alignment (probably!)
1330 if (selectionGroup == null || selectionGroup.getSize() == 0)
1332 sequences = alignment.getSequencesArray();
1333 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1334 for (int i = 0; i < sequences.length; i++)
1336 sequences[i] = new Sequence(sequences[i], annots); // construct new
1338 // subset of visible
1344 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1352 public SequenceI[] getSequenceSelection()
1354 SequenceI[] sequences = null;
1355 if (selectionGroup != null)
1357 sequences = selectionGroup.getSequencesInOrder(alignment);
1359 if (sequences == null)
1361 sequences = alignment.getSequencesArray();
1368 public jalview.datamodel.CigarArray getViewAsCigars(
1369 boolean selectedRegionOnly)
1371 return new jalview.datamodel.CigarArray(alignment, colSel,
1372 (selectedRegionOnly ? selectionGroup : null));
1377 public jalview.datamodel.AlignmentView getAlignmentView(
1378 boolean selectedOnly)
1380 return getAlignmentView(selectedOnly, false);
1385 public jalview.datamodel.AlignmentView getAlignmentView(
1386 boolean selectedOnly, boolean markGroups)
1388 return new AlignmentView(alignment, colSel, selectionGroup,
1389 colSel != null && colSel.hasHiddenColumns(), selectedOnly,
1395 public String[] getViewAsString(boolean selectedRegionOnly)
1397 String[] selection = null;
1398 SequenceI[] seqs = null;
1400 int start = 0, end = 0;
1401 if (selectedRegionOnly && selectionGroup != null)
1403 iSize = selectionGroup.getSize();
1404 seqs = selectionGroup.getSequencesInOrder(alignment);
1405 start = selectionGroup.getStartRes();
1406 end = selectionGroup.getEndRes() + 1;
1410 iSize = alignment.getHeight();
1411 seqs = alignment.getSequencesArray();
1412 end = alignment.getWidth();
1415 selection = new String[iSize];
1416 if (colSel != null && colSel.hasHiddenColumns())
1418 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1422 for (i = 0; i < iSize; i++)
1424 selection[i] = seqs[i].getSequenceAsString(start, end);
1433 public int[][] getVisibleRegionBoundaries(int min, int max)
1435 Vector regions = new Vector();
1441 if (colSel != null && colSel.hasHiddenColumns())
1445 start = colSel.adjustForHiddenColumns(start);
1448 end = colSel.getHiddenBoundaryRight(start);
1459 regions.addElement(new int[]
1462 if (colSel != null && colSel.hasHiddenColumns())
1464 start = colSel.adjustForHiddenColumns(end);
1465 start = colSel.getHiddenBoundaryLeft(start) + 1;
1467 } while (end < max);
1469 int[][] startEnd = new int[regions.size()][2];
1471 regions.copyInto(startEnd);
1478 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(boolean selectedOnly)
1480 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1481 AlignmentAnnotation[] aa;
1482 if ((aa=alignment.getAlignmentAnnotation())!=null)
1484 for (AlignmentAnnotation annot:aa)
1486 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1487 if (selectedOnly && selectionGroup!=null)
1489 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(), selectionGroup.getEndRes(),clone);
1491 colSel.makeVisibleAnnotation(clone);
1501 public boolean isPadGaps()
1508 public void setPadGaps(boolean padGaps)
1510 this.padGaps = padGaps;
1514 * apply any post-edit constraints and trigger any calculations needed after
1515 * an edit has been performed on the alignment
1520 public void alignmentChanged(AlignmentViewPanel ap)
1524 alignment.padGaps();
1526 if (autoCalculateConsensus)
1528 updateConsensus(ap);
1530 if (hconsensus != null && autoCalculateConsensus)
1532 updateConservation(ap);
1534 if (autoCalculateStrucConsensus)
1536 updateStrucConsensus(ap);
1539 // Reset endRes of groups if beyond alignment width
1540 int alWidth = alignment.getWidth();
1541 List<SequenceGroup> groups = alignment.getGroups();
1544 for (SequenceGroup sg : groups)
1546 if (sg.getEndRes() > alWidth)
1548 sg.setEndRes(alWidth - 1);
1553 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1555 selectionGroup.setEndRes(alWidth - 1);
1558 resetAllColourSchemes();
1559 calculator.restartWorkers();
1560 // alignment.adjustSequenceAnnotations();
1564 * reset scope and do calculations for all applied colourschemes on alignment
1566 void resetAllColourSchemes()
1568 ColourSchemeI cs = globalColourScheme;
1571 cs.alignmentChanged(alignment, hiddenRepSequences);
1573 cs.setConsensus(hconsensus);
1574 if (cs.conservationApplied())
1576 cs.setConservation(Conservation.calculateConservation("All",
1577 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1578 alignment.getWidth(), false, getConsPercGaps(), false));
1582 for (SequenceGroup sg : alignment.getGroups())
1586 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1588 sg.recalcConservation();
1592 protected void initAutoAnnotation()
1594 // TODO: add menu option action that nulls or creates consensus object
1595 // depending on if the user wants to see the annotation or not in a
1596 // specific alignment
1598 if (hconsensus == null && !isDataset)
1600 if (!alignment.isNucleotide())
1613 private void initConsensus()
1616 consensus = new AlignmentAnnotation("Consensus", "PID",
1617 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1618 consensus.hasText = true;
1619 consensus.autoCalculated = true;
1623 alignment.addAnnotation(consensus);
1627 private void initConservation()
1629 if (showConservation)
1631 if (conservation == null)
1633 conservation = new AlignmentAnnotation("Conservation",
1634 "Conservation of total alignment less than "
1635 + getConsPercGaps() + "% gaps", new Annotation[1],
1636 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1637 conservation.hasText = true;
1638 conservation.autoCalculated = true;
1639 alignment.addAnnotation(conservation);
1644 private void initQuality()
1648 if (quality == null)
1650 quality = new AlignmentAnnotation("Quality",
1651 "Alignment Quality based on Blosum62 scores",
1652 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1653 quality.hasText = true;
1654 quality.autoCalculated = true;
1655 alignment.addAnnotation(quality);
1660 private void initRNAStructure()
1662 if (alignment.hasRNAStructure() && strucConsensus == null)
1664 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1665 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1666 strucConsensus.hasText = true;
1667 strucConsensus.autoCalculated = true;
1671 alignment.addAnnotation(strucConsensus);
1679 * @see jalview.api.AlignViewportI#calcPanelHeight()
1682 public int calcPanelHeight()
1684 // setHeight of panels
1685 AlignmentAnnotation[] aa = getAlignment().getAlignmentAnnotation();
1687 int charHeight = getCharHeight();
1690 BitSet graphgrp = new BitSet();
1691 for (int i = 0; i < aa.length; i++)
1695 System.err.println("Null annotation row: ignoring.");
1702 if (aa[i].graphGroup > -1)
1704 if (graphgrp.get(aa[i].graphGroup))
1710 graphgrp.set(aa[i].graphGroup);
1717 aa[i].height += charHeight;
1725 if (aa[i].graph > 0)
1727 aa[i].height += aa[i].graphHeight;
1730 if (aa[i].height == 0)
1735 height += aa[i].height;
1747 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1748 boolean preserveNewGroupSettings)
1750 boolean updateCalcs = false;
1751 boolean conv = isShowGroupConservation();
1752 boolean cons = isShowGroupConsensus();
1753 boolean showprf = isShowSequenceLogo();
1754 boolean showConsHist = isShowConsensusHistogram();
1755 boolean normLogo = isNormaliseSequenceLogo();
1758 * TODO reorder the annotation rows according to group/sequence ordering on
1761 boolean sortg = true;
1763 // remove old automatic annotation
1764 // add any new annotation
1766 // intersect alignment annotation with alignment groups
1768 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
1769 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
1772 for (int an = 0; an < aan.length; an++)
1774 if (aan[an].autoCalculated && aan[an].groupRef != null)
1776 oldrfs.add(aan[an].groupRef);
1777 alignment.deleteAnnotation(aan[an], false);
1781 if (alignment.getGroups() != null)
1783 for (SequenceGroup sg : alignment.getGroups())
1785 updateCalcs = false;
1786 if (applyGlobalSettings
1787 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
1789 // set defaults for this group's conservation/consensus
1790 sg.setshowSequenceLogo(showprf);
1791 sg.setShowConsensusHistogram(showConsHist);
1792 sg.setNormaliseSequenceLogo(normLogo);
1797 alignment.addAnnotation(sg.getConservationRow(), 0);
1802 alignment.addAnnotation(sg.getConsensus(), 0);
1804 // refresh the annotation rows
1807 sg.recalcConservation();
1814 public boolean isDisplayReferenceSeq()
1816 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
1820 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
1822 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
1825 public boolean isColourByReferenceSeq()
1827 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
1832 public Color getSequenceColour(SequenceI seq)
1834 Color sqc = Color.white;
1835 if (sequenceColours != null)
1837 sqc = (Color) sequenceColours.get(seq);
1847 public void setSequenceColour(SequenceI seq, Color col)
1849 if (sequenceColours == null)
1851 sequenceColours = new Hashtable();
1856 sequenceColours.remove(seq);
1860 sequenceColours.put(seq, col);
1865 public void updateSequenceIdColours()
1867 if (sequenceColours == null)
1869 sequenceColours = new Hashtable();
1871 for (SequenceGroup sg : alignment.getGroups())
1873 if (sg.idColour != null)
1875 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
1877 sequenceColours.put(s, sg.idColour);
1884 public void clearSequenceColours()
1886 sequenceColours = null;
1889 FeaturesDisplayedI featuresDisplayed = null;
1892 public FeaturesDisplayedI getFeaturesDisplayed()
1894 return featuresDisplayed;
1898 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
1900 featuresDisplayed = featuresDisplayedI;
1904 public boolean areFeaturesDisplayed()
1906 return featuresDisplayed != null && featuresDisplayed.getRegisterdFeaturesCount()>0;
1913 * features are displayed if true
1916 public void setShowSequenceFeatures(boolean b)
1918 viewStyle.setShowSequenceFeatures(b);
1921 public boolean isShowSequenceFeatures()
1923 return viewStyle.isShowSequenceFeatures();
1927 public void setShowSequenceFeaturesHeight(boolean selected)
1929 viewStyle.setShowSeqFeaturesHeight(selected);
1933 public boolean isShowSequenceFeaturesHeight()
1935 return viewStyle.isShowSequenceFeaturesHeight();
1941 public void setShowAnnotation(boolean b)
1943 viewStyle.setShowAnnotation(b);
1947 public boolean isShowAnnotation()
1949 return viewStyle.isShowAnnotation();
1953 public boolean isRightAlignIds()
1955 return viewStyle.isRightAlignIds();
1959 public void setRightAlignIds(boolean rightAlignIds)
1961 viewStyle.setRightAlignIds(rightAlignIds);
1965 public boolean getConservationSelected()
1967 return viewStyle.getConservationSelected();
1971 public void setShowBoxes(boolean state)
1973 viewStyle.setShowBoxes(state);
1978 * @see jalview.api.ViewStyleI#getTextColour()
1980 public Color getTextColour()
1982 return viewStyle.getTextColour();
1987 * @see jalview.api.ViewStyleI#getTextColour2()
1989 public Color getTextColour2()
1991 return viewStyle.getTextColour2();
1996 * @see jalview.api.ViewStyleI#getThresholdTextColour()
1998 public int getThresholdTextColour()
2000 return viewStyle.getThresholdTextColour();
2005 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2007 public boolean isConservationColourSelected()
2009 return viewStyle.isConservationColourSelected();
2014 * @see jalview.api.ViewStyleI#isRenderGaps()
2016 public boolean isRenderGaps()
2018 return viewStyle.isRenderGaps();
2023 * @see jalview.api.ViewStyleI#isShowColourText()
2025 public boolean isShowColourText()
2027 return viewStyle.isShowColourText();
2032 * @see jalview.api.ViewStyleI#isShowSeqFeaturesHeight()
2034 public boolean isShowSeqFeaturesHeight()
2036 return viewStyle.isShowSeqFeaturesHeight();
2040 * @param conservationColourSelected
2041 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2043 public void setConservationColourSelected(
2044 boolean conservationColourSelected)
2046 viewStyle.setConservationColourSelected(conservationColourSelected);
2050 * @param showColourText
2051 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2053 public void setShowColourText(boolean showColourText)
2055 viewStyle.setShowColourText(showColourText);
2060 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2062 public void setTextColour(Color textColour)
2064 viewStyle.setTextColour(textColour);
2068 * @param thresholdTextColour
2069 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2071 public void setThresholdTextColour(int thresholdTextColour)
2073 viewStyle.setThresholdTextColour(thresholdTextColour);
2077 * @param textColour2
2078 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2080 public void setTextColour2(Color textColour2)
2082 viewStyle.setTextColour2(textColour2);
2086 public ViewStyleI getViewStyle()
2088 return new ViewStyle(viewStyle);
2092 public void setViewStyle(ViewStyleI settingsForView)
2094 viewStyle = new ViewStyle(settingsForView);
2098 public boolean sameStyle(ViewStyleI them)
2100 return viewStyle.sameStyle(them);