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.datamodel.AlignmentAnnotation;
29 import jalview.datamodel.AlignmentI;
30 import jalview.datamodel.AlignmentView;
31 import jalview.datamodel.Annotation;
32 import jalview.datamodel.ColumnSelection;
33 import jalview.datamodel.Sequence;
34 import jalview.datamodel.SequenceCollectionI;
35 import jalview.datamodel.SequenceGroup;
36 import jalview.datamodel.SequenceI;
37 import jalview.schemes.Blosum62ColourScheme;
38 import jalview.schemes.ColourSchemeI;
39 import jalview.schemes.PIDColourScheme;
40 import jalview.schemes.ResidueProperties;
41 import jalview.workers.AlignCalcManager;
42 import jalview.workers.ConsensusThread;
43 import jalview.workers.StrucConsensusThread;
45 import java.awt.Color;
46 import java.util.ArrayList;
47 import java.util.BitSet;
48 import java.util.Hashtable;
49 import java.util.List;
51 import java.util.Vector;
54 * base class holding visualization and analysis attributes and common logic for
55 * an active alignment view displayed in the GUI
60 public abstract class AlignmentViewport implements AlignViewportI
63 * alignment displayed in the viewport. Please use get/setter
65 protected AlignmentI alignment;
67 protected String sequenceSetID;
70 * probably unused indicator that view is of a dataset rather than an
73 protected boolean isDataset = false;
75 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
77 protected ColumnSelection colSel = new ColumnSelection();
79 public boolean autoCalculateConsensus = true;
81 protected boolean autoCalculateStrucConsensus = true;
83 protected boolean ignoreGapsInConsensusCalculation = false;
85 protected ColourSchemeI globalColourScheme = null;
88 * gui state - changes to colour scheme propagated to all groups
90 private boolean colourAppliesToAllGroups;
94 * indicating if subsequent colourscheme changes will be propagated
97 public void setColourAppliesToAllGroups(boolean b)
99 colourAppliesToAllGroups = b;
105 * @return flag indicating if colourchanges propagated to all groups
107 public boolean getColourAppliesToAllGroups()
109 return colourAppliesToAllGroups;
112 boolean abovePIDThreshold = false;
117 * @return true if percent identity threshold is applied to shading
119 public boolean getAbovePIDThreshold()
121 return abovePIDThreshold;
129 * indicate if percent identity threshold is applied to shading
131 public void setAbovePIDThreshold(boolean b)
133 abovePIDThreshold = b;
144 public void setThreshold(int thresh)
152 * @return DOCUMENT ME!
154 public int getThreshold()
164 * set the scalar for bleaching colourschemes according to degree of
167 public void setIncrement(int inc)
175 * @return get scalar for bleaching colourschemes by conservation
177 public int getIncrement()
182 boolean conservationColourSelected = false;
187 * @return true if conservation based shading is enabled
189 public boolean getConservationSelected()
191 return conservationColourSelected;
198 * enable conservation based shading
200 public void setConservationSelected(boolean b)
202 conservationColourSelected = b;
206 public void setGlobalColourScheme(ColourSchemeI cs)
208 // TODO: logic refactored from AlignFrame changeColour -
209 // autorecalc stuff should be changed to rely on the worker system
210 // check to see if we should implement a changeColour(cs) method rather than
211 // put th logic in here
212 // - means that caller decides if they want to just modify state and defer
213 // calculation till later or to do all calculations in thread.
215 globalColourScheme = cs;
216 boolean recalc = false;
219 cs.setConservationApplied(recalc = getConservationSelected());
220 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
221 || cs instanceof Blosum62ColourScheme)
224 cs.setThreshold(threshold, ignoreGapsInConsensusCalculation);
228 cs.setThreshold(0, ignoreGapsInConsensusCalculation);
232 cs.setConsensus(hconsensus);
233 cs.setConservation(hconservation);
235 cs.alignmentChanged(alignment, hiddenRepSequences);
237 if (getColourAppliesToAllGroups())
239 for (SequenceGroup sg : getAlignment().getGroups())
246 sg.cs = cs.applyTo(sg, getHiddenRepSequences());
247 sg.setConsPercGaps(ConsPercGaps);
248 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
249 || cs instanceof Blosum62ColourScheme)
251 sg.cs.setThreshold(threshold, getIgnoreGapsConsensus());
256 sg.cs.setThreshold(0, getIgnoreGapsConsensus());
259 if (getConservationSelected())
261 sg.cs.setConservationApplied(true);
266 sg.cs.setConservation(null);
267 // sg.cs.setThreshold(0, getIgnoreGapsConsensus());
271 sg.recalcConservation();
275 sg.cs.alignmentChanged(sg, hiddenRepSequences);
283 public ColourSchemeI getGlobalColourScheme()
285 return globalColourScheme;
288 protected AlignmentAnnotation consensus;
290 protected AlignmentAnnotation strucConsensus;
292 protected AlignmentAnnotation conservation;
294 protected AlignmentAnnotation quality;
296 protected AlignmentAnnotation[] groupConsensus;
298 protected AlignmentAnnotation[] groupConservation;
301 * results of alignment consensus analysis for visible portion of view
303 protected Hashtable[] hconsensus = null;
306 * results of secondary structure base pair consensus for visible portion of
309 protected Hashtable[] hStrucConsensus = null;
311 protected Conservation hconservation = null;
314 public void setConservation(Conservation cons)
316 hconservation = cons;
320 * percentage gaps allowed in a column before all amino acid properties should
321 * be considered unconserved
323 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
326 public int getConsPercGaps()
332 public void setSequenceConsensusHash(Hashtable[] hconsensus)
334 this.hconsensus = hconsensus;
339 public Hashtable[] getSequenceConsensusHash()
345 public Hashtable[] getRnaStructureConsensusHash()
347 return hStrucConsensus;
351 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
353 this.hStrucConsensus = hStrucConsensus;
358 public AlignmentAnnotation getAlignmentQualityAnnot()
364 public AlignmentAnnotation getAlignmentConservationAnnotation()
370 public AlignmentAnnotation getAlignmentConsensusAnnotation()
376 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
378 return strucConsensus;
381 protected AlignCalcManagerI calculator = new AlignCalcManager();
384 * trigger update of conservation annotation
386 public void updateConservation(final AlignmentViewPanel ap)
388 // see note in mantis : issue number 8585
389 if (alignment.isNucleotide() || conservation == null
390 || !autoCalculateConsensus)
395 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
397 calculator.registerWorker(new jalview.workers.ConservationThread(
403 * trigger update of consensus annotation
405 public void updateConsensus(final AlignmentViewPanel ap)
407 // see note in mantis : issue number 8585
408 if (consensus == null || !autoCalculateConsensus)
412 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
414 calculator.registerWorker(new ConsensusThread(this, ap));
418 // --------START Structure Conservation
419 public void updateStrucConsensus(final AlignmentViewPanel ap)
421 if (autoCalculateStrucConsensus && strucConsensus == null
422 && alignment.isNucleotide() && alignment.hasRNAStructure())
424 // secondary structure has been added - so init the consensus line
428 // see note in mantis : issue number 8585
429 if (strucConsensus == null || !autoCalculateStrucConsensus)
433 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
435 calculator.registerWorker(new StrucConsensusThread(this, ap));
439 public boolean isCalcInProgress()
441 return calculator.isWorking();
445 public boolean isCalculationInProgress(
446 AlignmentAnnotation alignmentAnnotation)
448 if (!alignmentAnnotation.autoCalculated)
452 if (calculator.workingInvolvedWith(alignmentAnnotation))
454 // System.err.println("grey out ("+alignmentAnnotation.label+")");
461 public boolean isClosed()
463 // TODO: check that this isClosed is only true after panel is closed, not
464 // before it is fully constructed.
465 return alignment == null;
469 public AlignCalcManagerI getCalcManager()
475 * should conservation rows be shown for groups
477 protected boolean showGroupConservation = false;
480 * should consensus rows be shown for groups
482 protected boolean showGroupConsensus = false;
485 * should consensus profile be rendered by default
487 protected boolean showSequenceLogo = false;
490 * should consensus profile be rendered normalised to row height
492 protected boolean normaliseSequenceLogo = false;
495 * should consensus histograms be rendered by default
497 protected boolean showConsensusHistogram = true;
500 * @return the showConsensusProfile
503 public boolean isShowSequenceLogo()
505 return showSequenceLogo;
509 * @param showSequenceLogo
512 public void setShowSequenceLogo(boolean showSequenceLogo)
514 if (showSequenceLogo != this.showSequenceLogo)
516 // TODO: decouple settings setting from calculation when refactoring
517 // annotation update method from alignframe to viewport
518 this.showSequenceLogo = showSequenceLogo;
519 calculator.updateAnnotationFor(ConsensusThread.class);
520 calculator.updateAnnotationFor(StrucConsensusThread.class);
522 this.showSequenceLogo = showSequenceLogo;
526 * @param showConsensusHistogram
527 * the showConsensusHistogram to set
529 public void setShowConsensusHistogram(boolean showConsensusHistogram)
531 this.showConsensusHistogram = showConsensusHistogram;
535 * @return the showGroupConservation
537 public boolean isShowGroupConservation()
539 return showGroupConservation;
543 * @param showGroupConservation
544 * the showGroupConservation to set
546 public void setShowGroupConservation(boolean showGroupConservation)
548 this.showGroupConservation = showGroupConservation;
552 * @return the showGroupConsensus
554 public boolean isShowGroupConsensus()
556 return showGroupConsensus;
560 * @param showGroupConsensus
561 * the showGroupConsensus to set
563 public void setShowGroupConsensus(boolean showGroupConsensus)
565 this.showGroupConsensus = showGroupConsensus;
570 * @return flag to indicate if the consensus histogram should be rendered by
574 public boolean isShowConsensusHistogram()
576 return this.showConsensusHistogram;
580 * show non-conserved residues only
582 protected boolean showUnconserved = false;
585 * when set, updateAlignment will always ensure sequences are of equal length
587 private boolean padGaps = false;
590 * when set, alignment should be reordered according to a newly opened tree
592 public boolean sortByTree = false;
594 public boolean getShowUnconserved()
596 return showUnconserved;
599 public void setShowUnconserved(boolean showunconserved)
601 showUnconserved = showunconserved;
605 * @param showNonconserved
606 * the showUnconserved to set
608 public void setShowunconserved(boolean displayNonconserved)
610 this.showUnconserved = displayNonconserved;
616 * @return null or the currently selected sequence region
619 public SequenceGroup getSelectionGroup()
621 return selectionGroup;
625 * Set the selection group for this window.
628 * - group holding references to sequences in this alignment view
632 public void setSelectionGroup(SequenceGroup sg)
637 public void setHiddenColumns(ColumnSelection colsel)
639 this.colSel = colsel;
643 public ColumnSelection getColumnSelection()
649 public void setColumnSelection(ColumnSelection colSel)
651 this.colSel = colSel;
654 updateHiddenColumns();
663 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
665 return hiddenRepSequences;
669 public void setHiddenRepSequences(
670 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
672 this.hiddenRepSequences = hiddenRepSequences;
676 public boolean hasHiddenColumns()
678 return colSel != null && colSel.hasHiddenColumns();
681 public void updateHiddenColumns()
683 // this method doesn't really do anything now. But - it could, since a
684 // column Selection could be in the process of modification
685 // hasHiddenColumns = colSel.hasHiddenColumns();
688 protected boolean hasHiddenRows = false;
691 public boolean hasHiddenRows()
693 return hasHiddenRows;
696 protected SequenceGroup selectionGroup;
698 public void setSequenceSetId(String newid)
700 if (sequenceSetID != null)
703 .println("Warning - overwriting a sequenceSetId for a viewport!");
705 sequenceSetID = new String(newid);
709 public String getSequenceSetId()
711 if (sequenceSetID == null)
713 sequenceSetID = alignment.hashCode() + "";
716 return sequenceSetID;
720 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
723 protected String viewId = null;
725 public String getViewId()
729 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
734 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
736 ignoreGapsInConsensusCalculation = b;
740 if (globalColourScheme != null)
742 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
743 ignoreGapsInConsensusCalculation);
749 private long sgrouphash = -1, colselhash = -1;
752 * checks current SelectionGroup against record of last hash value, and
756 * update the record of last hash value
758 * @return true if SelectionGroup changed since last call (when b is true)
760 public boolean isSelectionGroupChanged(boolean b)
762 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
763 : selectionGroup.hashCode();
764 if (hc != -1 && hc != sgrouphash)
776 * checks current colsel against record of last hash value, and optionally
780 * update the record of last hash value
781 * @return true if colsel changed since last call (when b is true)
783 public boolean isColSelChanged(boolean b)
785 int hc = (colSel == null || colSel.size() == 0) ? -1 : colSel
787 if (hc != -1 && hc != colselhash)
799 public boolean getIgnoreGapsConsensus()
801 return ignoreGapsInConsensusCalculation;
804 // / property change stuff
806 // JBPNote Prolly only need this in the applet version.
807 private final java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
810 protected boolean showConservation = true;
812 protected boolean showQuality = true;
814 protected boolean showConsensus = true;
816 Hashtable sequenceColours;
819 * Property change listener for changes in alignment
824 public void addPropertyChangeListener(
825 java.beans.PropertyChangeListener listener)
827 changeSupport.addPropertyChangeListener(listener);
836 public void removePropertyChangeListener(
837 java.beans.PropertyChangeListener listener)
839 changeSupport.removePropertyChangeListener(listener);
843 * Property change listener for changes in alignment
852 public void firePropertyChange(String prop, Object oldvalue,
855 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
858 // common hide/show column stuff
860 public void hideSelectedColumns()
862 if (colSel.size() < 1)
867 colSel.hideSelectedColumns();
868 setSelectionGroup(null);
872 public void hideColumns(int start, int end)
876 colSel.hideColumns(start);
880 colSel.hideColumns(start, end);
884 public void showColumn(int col)
886 colSel.revealHiddenColumns(col);
890 public void showAllHiddenColumns()
892 colSel.revealAllHiddenColumns();
895 // common hide/show seq stuff
896 public void showAllHiddenSeqs()
898 if (alignment.getHiddenSequences().getSize() > 0)
900 if (selectionGroup == null)
902 selectionGroup = new SequenceGroup();
903 selectionGroup.setEndRes(alignment.getWidth() - 1);
905 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
907 for (SequenceI seq : tmp)
909 selectionGroup.addSequence(seq, false);
910 setSequenceAnnotationsVisible(seq, true);
913 hasHiddenRows = false;
914 hiddenRepSequences = null;
916 firePropertyChange("alignment", null, alignment.getSequences());
917 // used to set hasHiddenRows/hiddenRepSequences here, after the property
923 public void showSequence(int index)
925 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
930 if (selectionGroup == null)
932 selectionGroup = new SequenceGroup();
933 selectionGroup.setEndRes(alignment.getWidth() - 1);
936 for (SequenceI seq : tmp)
938 selectionGroup.addSequence(seq, false);
939 setSequenceAnnotationsVisible(seq, true);
941 // JBPNote: refactor: only update flag if we modified visiblity (used to
942 // do this regardless)
943 if (alignment.getHiddenSequences().getSize() < 1)
945 hasHiddenRows = false;
947 firePropertyChange("alignment", null, alignment.getSequences());
952 public void hideAllSelectedSeqs()
954 if (selectionGroup == null || selectionGroup.getSize() < 1)
959 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
963 setSelectionGroup(null);
966 public void hideSequence(SequenceI[] seq)
970 for (int i = 0; i < seq.length; i++)
972 alignment.getHiddenSequences().hideSequence(seq[i]);
973 setSequenceAnnotationsVisible(seq[i], false);
975 hasHiddenRows = true;
976 firePropertyChange("alignment", null, alignment.getSequences());
981 * Set visibility for any annotations for the given sequence.
985 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
988 for (AlignmentAnnotation ann : alignment.getAlignmentAnnotation())
990 if (ann.sequenceRef == sequenceI)
992 ann.visible = visible;
997 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
999 int sSize = sg.getSize();
1005 if (hiddenRepSequences == null)
1007 hiddenRepSequences = new Hashtable();
1010 hiddenRepSequences.put(repSequence, sg);
1012 // Hide all sequences except the repSequence
1013 SequenceI[] seqs = new SequenceI[sSize - 1];
1015 for (int i = 0; i < sSize; i++)
1017 if (sg.getSequenceAt(i) != repSequence)
1019 if (index == sSize - 1)
1024 seqs[index++] = sg.getSequenceAt(i);
1027 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1028 sg.setHidereps(true); // note: not done in 2.7applet
1033 public boolean isHiddenRepSequence(SequenceI seq)
1035 return alignment.getSeqrep()==seq || (hiddenRepSequences != null
1036 && hiddenRepSequences.containsKey(seq));
1039 public SequenceGroup getRepresentedSequences(SequenceI seq)
1041 return (SequenceGroup) (hiddenRepSequences == null ? null
1042 : hiddenRepSequences.get(seq));
1046 public int adjustForHiddenSeqs(int alignmentIndex)
1048 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1053 public abstract void sendSelection();
1056 public void invertColumnSelection()
1058 colSel.invertColumnSelection(0, alignment.getWidth());
1063 public SequenceI[] getSelectionAsNewSequence()
1065 SequenceI[] sequences;
1066 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1067 // this was the only caller in the applet for this method
1068 // JBPNote: in applet, this method returned references to the alignment
1069 // sequences, and it did not honour the presence/absence of annotation
1070 // attached to the alignment (probably!)
1071 if (selectionGroup == null || selectionGroup.getSize() == 0)
1073 sequences = alignment.getSequencesArray();
1074 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1075 for (int i = 0; i < sequences.length; i++)
1077 sequences[i] = new Sequence(sequences[i], annots); // construct new
1079 // subset of visible
1085 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1093 public SequenceI[] getSequenceSelection()
1095 SequenceI[] sequences = null;
1096 if (selectionGroup != null)
1098 sequences = selectionGroup.getSequencesInOrder(alignment);
1100 if (sequences == null)
1102 sequences = alignment.getSequencesArray();
1109 public jalview.datamodel.CigarArray getViewAsCigars(
1110 boolean selectedRegionOnly)
1112 return new jalview.datamodel.CigarArray(alignment, colSel,
1113 (selectedRegionOnly ? selectionGroup : null));
1118 public jalview.datamodel.AlignmentView getAlignmentView(
1119 boolean selectedOnly)
1121 return getAlignmentView(selectedOnly, false);
1126 public jalview.datamodel.AlignmentView getAlignmentView(
1127 boolean selectedOnly, boolean markGroups)
1129 return new AlignmentView(alignment, colSel, selectionGroup,
1130 colSel != null && colSel.hasHiddenColumns(), selectedOnly,
1136 public String[] getViewAsString(boolean selectedRegionOnly)
1138 String[] selection = null;
1139 SequenceI[] seqs = null;
1141 int start = 0, end = 0;
1142 if (selectedRegionOnly && selectionGroup != null)
1144 iSize = selectionGroup.getSize();
1145 seqs = selectionGroup.getSequencesInOrder(alignment);
1146 start = selectionGroup.getStartRes();
1147 end = selectionGroup.getEndRes() + 1;
1151 iSize = alignment.getHeight();
1152 seqs = alignment.getSequencesArray();
1153 end = alignment.getWidth();
1156 selection = new String[iSize];
1157 if (colSel != null && colSel.hasHiddenColumns())
1159 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1163 for (i = 0; i < iSize; i++)
1165 selection[i] = seqs[i].getSequenceAsString(start, end);
1174 public int[][] getVisibleRegionBoundaries(int min, int max)
1176 Vector regions = new Vector();
1182 if (colSel != null && colSel.hasHiddenColumns())
1186 start = colSel.adjustForHiddenColumns(start);
1189 end = colSel.getHiddenBoundaryRight(start);
1200 regions.addElement(new int[]
1203 if (colSel != null && colSel.hasHiddenColumns())
1205 start = colSel.adjustForHiddenColumns(end);
1206 start = colSel.getHiddenBoundaryLeft(start) + 1;
1208 } while (end < max);
1210 int[][] startEnd = new int[regions.size()][2];
1212 regions.copyInto(startEnd);
1219 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(boolean selectedOnly)
1221 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1222 AlignmentAnnotation[] aa;
1223 if ((aa=alignment.getAlignmentAnnotation())!=null)
1225 for (AlignmentAnnotation annot:aa)
1227 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1228 if (selectedOnly && selectionGroup!=null)
1230 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(), selectionGroup.getEndRes(),clone);
1232 colSel.makeVisibleAnnotation(clone);
1242 public boolean isPadGaps()
1249 public void setPadGaps(boolean padGaps)
1251 this.padGaps = padGaps;
1255 * apply any post-edit constraints and trigger any calculations needed after
1256 * an edit has been performed on the alignment
1261 public void alignmentChanged(AlignmentViewPanel ap)
1265 alignment.padGaps();
1267 if (autoCalculateConsensus)
1269 updateConsensus(ap);
1271 if (hconsensus != null && autoCalculateConsensus)
1273 updateConservation(ap);
1275 if (autoCalculateStrucConsensus)
1277 updateStrucConsensus(ap);
1280 // Reset endRes of groups if beyond alignment width
1281 int alWidth = alignment.getWidth();
1282 List<SequenceGroup> groups = alignment.getGroups();
1285 for (SequenceGroup sg : groups)
1287 if (sg.getEndRes() > alWidth)
1289 sg.setEndRes(alWidth - 1);
1294 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1296 selectionGroup.setEndRes(alWidth - 1);
1299 resetAllColourSchemes();
1300 calculator.restartWorkers();
1301 // alignment.adjustSequenceAnnotations();
1305 * reset scope and do calculations for all applied colourschemes on alignment
1307 void resetAllColourSchemes()
1309 ColourSchemeI cs = globalColourScheme;
1312 cs.alignmentChanged(alignment, hiddenRepSequences);
1314 cs.setConsensus(hconsensus);
1315 if (cs.conservationApplied())
1317 cs.setConservation(Conservation.calculateConservation("All",
1318 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1319 alignment.getWidth(), false, getConsPercGaps(), false));
1323 for (SequenceGroup sg : alignment.getGroups())
1327 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1329 sg.recalcConservation();
1333 protected void initAutoAnnotation()
1335 // TODO: add menu option action that nulls or creates consensus object
1336 // depending on if the user wants to see the annotation or not in a
1337 // specific alignment
1339 if (hconsensus == null && !isDataset)
1341 if (!alignment.isNucleotide())
1354 private void initConsensus()
1357 consensus = new AlignmentAnnotation("Consensus", "PID",
1358 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1359 consensus.hasText = true;
1360 consensus.autoCalculated = true;
1364 alignment.addAnnotation(consensus);
1368 private void initConservation()
1370 if (showConservation)
1372 if (conservation == null)
1374 conservation = new AlignmentAnnotation("Conservation",
1375 "Conservation of total alignment less than "
1376 + getConsPercGaps() + "% gaps", new Annotation[1],
1377 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1378 conservation.hasText = true;
1379 conservation.autoCalculated = true;
1380 alignment.addAnnotation(conservation);
1385 private void initQuality()
1389 if (quality == null)
1391 quality = new AlignmentAnnotation("Quality",
1392 "Alignment Quality based on Blosum62 scores",
1393 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1394 quality.hasText = true;
1395 quality.autoCalculated = true;
1396 alignment.addAnnotation(quality);
1401 private void initRNAStructure()
1403 if (alignment.hasRNAStructure() && strucConsensus == null)
1405 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1406 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1407 strucConsensus.hasText = true;
1408 strucConsensus.autoCalculated = true;
1412 alignment.addAnnotation(strucConsensus);
1420 * @see jalview.api.AlignViewportI#calcPanelHeight()
1423 public int calcPanelHeight()
1425 // setHeight of panels
1426 AlignmentAnnotation[] aa = getAlignment().getAlignmentAnnotation();
1428 int charHeight = getCharHeight();
1431 BitSet graphgrp = new BitSet();
1432 for (int i = 0; i < aa.length; i++)
1436 System.err.println("Null annotation row: ignoring.");
1443 if (aa[i].graphGroup > -1)
1445 if (graphgrp.get(aa[i].graphGroup))
1451 graphgrp.set(aa[i].graphGroup);
1458 aa[i].height += charHeight;
1466 if (aa[i].graph > 0)
1468 aa[i].height += aa[i].graphHeight;
1471 if (aa[i].height == 0)
1476 height += aa[i].height;
1488 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1489 boolean preserveNewGroupSettings)
1491 boolean updateCalcs = false;
1492 boolean conv = isShowGroupConservation();
1493 boolean cons = isShowGroupConsensus();
1494 boolean showprf = isShowSequenceLogo();
1495 boolean showConsHist = isShowConsensusHistogram();
1496 boolean normLogo = isNormaliseSequenceLogo();
1499 * TODO reorder the annotation rows according to group/sequence ordering on
1502 boolean sortg = true;
1504 // remove old automatic annotation
1505 // add any new annotation
1507 // intersect alignment annotation with alignment groups
1509 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
1510 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
1513 for (int an = 0; an < aan.length; an++)
1515 if (aan[an].autoCalculated && aan[an].groupRef != null)
1517 oldrfs.add(aan[an].groupRef);
1518 alignment.deleteAnnotation(aan[an], false);
1522 if (alignment.getGroups() != null)
1524 for (SequenceGroup sg : alignment.getGroups())
1526 updateCalcs = false;
1527 if (applyGlobalSettings
1528 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
1530 // set defaults for this group's conservation/consensus
1531 sg.setshowSequenceLogo(showprf);
1532 sg.setShowConsensusHistogram(showConsHist);
1533 sg.setNormaliseSequenceLogo(normLogo);
1538 alignment.addAnnotation(sg.getConservationRow(), 0);
1543 alignment.addAnnotation(sg.getConsensus(), 0);
1545 // refresh the annotation rows
1548 sg.recalcConservation();
1555 * show the reference sequence in the alignment view
1557 private boolean displayReferenceSeq=false;
1559 * colour according to the reference sequence defined on the alignment
1561 private boolean colourByReferenceSeq=false;
1564 public boolean isDisplayReferenceSeq()
1566 return alignment.hasSeqrep() && displayReferenceSeq;
1570 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
1572 this.displayReferenceSeq = displayReferenceSeq;
1575 public boolean isColourByReferenceSeq()
1577 return alignment.hasSeqrep() && colourByReferenceSeq;
1580 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
1582 this.colourByReferenceSeq = colourByReferenceSeq;
1586 public Color getSequenceColour(SequenceI seq)
1588 Color sqc = Color.white;
1589 if (sequenceColours != null)
1591 sqc = (Color) sequenceColours.get(seq);
1601 public void setSequenceColour(SequenceI seq, Color col)
1603 if (sequenceColours == null)
1605 sequenceColours = new Hashtable();
1610 sequenceColours.remove(seq);
1614 sequenceColours.put(seq, col);
1619 public void updateSequenceIdColours()
1621 if (sequenceColours == null)
1623 sequenceColours = new Hashtable();
1625 for (SequenceGroup sg : alignment.getGroups())
1627 if (sg.idColour != null)
1629 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
1631 sequenceColours.put(s, sg.idColour);
1638 public void clearSequenceColours()
1640 sequenceColours = null;
1643 FeaturesDisplayedI featuresDisplayed = null;
1646 public FeaturesDisplayedI getFeaturesDisplayed()
1648 return featuresDisplayed;
1652 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
1654 featuresDisplayed = featuresDisplayedI;
1658 public boolean areFeaturesDisplayed()
1660 return featuresDisplayed != null && featuresDisplayed.getRegisterdFeaturesCount()>0;
1664 * display setting for showing/hiding sequence features on alignment view
1666 boolean showSequenceFeatures = false;
1672 * features are displayed if true
1675 public void setShowSequenceFeatures(boolean b)
1677 showSequenceFeatures = b;
1680 public boolean isShowSequenceFeatures()
1682 return showSequenceFeatures;
1685 boolean showSeqFeaturesHeight;
1688 public void setShowSequenceFeaturesHeight(boolean selected)
1690 showSeqFeaturesHeight = selected;
1694 public boolean isShowSequenceFeaturesHeight()
1696 return showSeqFeaturesHeight;
1699 private boolean showAnnotation = true;
1701 private boolean rightAlignIds = false;
1705 public void setShowAnnotation(boolean b)
1711 public boolean isShowAnnotation()
1713 return showAnnotation;
1717 public boolean isRightAlignIds()
1719 return rightAlignIds;
1723 public void setRightAlignIds(boolean rightAlignIds)
1725 this.rightAlignIds = rightAlignIds;