From 9359a2279fcaa47910e31805b967390bffd6a573 Mon Sep 17 00:00:00 2001 From: tcofoegbu Date: Wed, 30 Sep 2015 14:28:41 +0100 Subject: [PATCH] JAL-1912 added support of tcoffee annotation and other per sequence annotation for BioJSON --- src/jalview/gui/AlignFrame.java | 5 + src/jalview/io/JSONFile.java | 121 ++++++++++++++++++-- src/jalview/jbgui/GAlignFrame.java | 5 + .../biojson/v1/AlignmentAnnotationPojo.java | 72 ++++++++++++ .../biojson/v1/AnnotationDisplaySettingPojo.java | 64 +++++++++++ .../json/binding/biojson/v1/AnnotationPojo.java | 13 +++ src/jalview/schemes/UserColourScheme.java | 2 +- 7 files changed, 272 insertions(+), 10 deletions(-) create mode 100644 src/jalview/json/binding/biojson/v1/AnnotationDisplaySettingPojo.java diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index eda4a1c..d08e1a3 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -3517,6 +3517,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs, "Background")); } + if (cs instanceof TCoffeeColourScheme) + { + tcoffeeColour.setEnabled(true); + tcoffeeColour.setSelected(true); + } } viewport.setGlobalColourScheme(cs); diff --git a/src/jalview/io/JSONFile.java b/src/jalview/io/JSONFile.java index 3ac4aa7..3a08409 100644 --- a/src/jalview/io/JSONFile.java +++ b/src/jalview/io/JSONFile.java @@ -39,12 +39,14 @@ import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.json.binding.biojson.v1.AlignmentAnnotationPojo; import jalview.json.binding.biojson.v1.AlignmentPojo; +import jalview.json.binding.biojson.v1.AnnotationDisplaySettingPojo; import jalview.json.binding.biojson.v1.AnnotationPojo; import jalview.json.binding.biojson.v1.ColourSchemeMapper; import jalview.json.binding.biojson.v1.SequenceFeaturesPojo; import jalview.json.binding.biojson.v1.SequenceGrpPojo; import jalview.json.binding.biojson.v1.SequencePojo; import jalview.schemes.ColourSchemeProperty; +import jalview.schemes.UserColourScheme; import jalview.viewmodel.seqfeatures.FeaturesDisplayed; import java.awt.Color; @@ -90,6 +92,8 @@ public class JSONFile extends AlignFile implements ComplexAlignFile private ArrayList hiddenSequences; + private final static String TCOFFEE_SCORE = "TCoffeeScore"; + public JSONFile() { super(); @@ -207,7 +211,8 @@ public class JSONFile extends AlignFile implements ComplexAlignFile if (exportSettings.isExportAnnotations()) { jsonAlignmentPojo - .setAlignAnnotation(annotationToJsonPojo(annotations)); +.setAlignAnnotation(annotationToJsonPojo( + annotations, seqs)); } else { @@ -355,7 +360,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile } public static List annotationToJsonPojo( - Vector annotations) + Vector annotations, Vector seqs) { List jsonAnnotations = new ArrayList(); if (annotations == null) @@ -364,9 +369,24 @@ public class JSONFile extends AlignFile implements ComplexAlignFile } for (AlignmentAnnotation annot : annotations) { + AnnotationDisplaySettingPojo annotSetting = new AnnotationDisplaySettingPojo(); + annotSetting.setBelowAlignment(annot.belowAlignment); + annotSetting.setCentreColLabels(annot.centreColLabels); + annotSetting.setScaleColLabel(annot.centreColLabels); + annotSetting.setShowAllColLabels(annot.showAllColLabels); + annotSetting.setVisible(annot.visible); + + AlignmentAnnotationPojo alignAnnotPojo = new AlignmentAnnotationPojo(); + alignAnnotPojo.setScore(annot.score); + alignAnnotPojo.setCalcId(annot.getCalcId()); alignAnnotPojo.setDescription(annot.description); alignAnnotPojo.setLabel(annot.label); + alignAnnotPojo.setGraphType(annot.graph); + alignAnnotPojo.setAnnotationSettings(annotSetting); + int seqHash = setAnnotationRefSeq(annot, seqs); + alignAnnotPojo.setSequenceRef(seqHash == 0 ? null : String + .valueOf(seqHash)); for (Annotation annotation : annot.annotations) { AnnotationPojo annotationPojo = new AnnotationPojo(); @@ -377,11 +397,24 @@ public class JSONFile extends AlignFile implements ComplexAlignFile annotationPojo .setSecondaryStructure(annotation.secondaryStructure); annotationPojo.setDisplayCharacter(annotation.displayCharacter); + if (annotation.colour != null) + { + annotationPojo.setColour(jalview.util.Format + .getHexString(annotation.colour)); + } alignAnnotPojo.getAnnotations().add(annotationPojo); } else { - alignAnnotPojo.getAnnotations().add(annotationPojo); + if (annot.getCalcId() != null + && annot.getCalcId().equalsIgnoreCase(TCOFFEE_SCORE)) + { + // do nothing + } + else + { + alignAnnotPojo.getAnnotations().add(null); + } } } jsonAnnotations.add(alignAnnotPojo); @@ -389,6 +422,29 @@ public class JSONFile extends AlignFile implements ComplexAlignFile return jsonAnnotations; } + private static int setAnnotationRefSeq(AlignmentAnnotation annot, + Vector seqs) + { + if (annot == null || seqs == null || seqs.size() == 0) + { + return 0; + } + for (SequenceI seq : seqs) + { + if (seq == null || seq.getAnnotation() == null) + { + continue; + } + for (AlignmentAnnotation seqAnnot : seq.getAnnotation()) + { + if (seqAnnot == annot) + { + return seq.hashCode(); + } + } + } + return 0; + } @SuppressWarnings("unchecked") public JSONFile parse(Reader jsonAlignmentString) { @@ -492,9 +548,18 @@ public class JSONFile extends AlignFile implements ComplexAlignFile .hasNext();) { JSONObject alAnnot = alAnnotIter.next(); + if (alAnnot == null) + { + continue; + } + JSONObject diplaySettings = (JSONObject) alAnnot + .get("annotationSettings"); + JSONArray annotJsonArray = (JSONArray) alAnnot.get("annotations"); Annotation[] annotations = new Annotation[annotJsonArray.size()]; int count = 0; + String calcId = alAnnot.get("calcId") == null ? "" : alAnnot.get( + "calcId").toString(); for (Iterator annotIter = annotJsonArray.iterator(); annotIter .hasNext();) { @@ -515,8 +580,11 @@ public class JSONFile extends AlignFile implements ComplexAlignFile .get("secondaryStructure").toString().charAt(0); String displayChar = annot.get("displayCharacter") == null ? "" : annot.get("displayCharacter").toString(); - - annotations[count] = new Annotation(displayChar, desc, ss, val); + Color color = annot.get("colour") == null ? Color.white + : UserColourScheme.getColourFromString(annot.get( + "colour").toString()); + annotations[count] = new Annotation(displayChar, desc, ss, val, + color); } ++count; } @@ -524,7 +592,46 @@ public class JSONFile extends AlignFile implements ComplexAlignFile AlignmentAnnotation alignAnnot = new AlignmentAnnotation(alAnnot .get("label").toString(), alAnnot.get("description") .toString(), annotations); + alignAnnot.graph = (alAnnot.get("graphType") == null) ? 0 : Integer + .valueOf(alAnnot.get("graphType") + .toString()); + alignAnnot.scaleColLabel = (diplaySettings.get("scaleColLabel") == null) ? false + : Boolean.valueOf(diplaySettings.get("scaleColLabel") + .toString()); + alignAnnot.showAllColLabels = (diplaySettings + .get("showAllColLabels") == null) ? true : Boolean + .valueOf(diplaySettings.get("showAllColLabels").toString()); + alignAnnot.centreColLabels = (diplaySettings.get("centreColLabels") == null) ? true + : Boolean.valueOf(diplaySettings.get("centreColLabels") + .toString()); + alignAnnot.belowAlignment = (diplaySettings.get("belowAlignment") == null) ? false + : Boolean.valueOf(diplaySettings.get("belowAlignment") + .toString()); + alignAnnot.visible = (diplaySettings.get("visible") == null) ? true + : Boolean.valueOf(diplaySettings.get("visible").toString()); + + + alignAnnot.score = alAnnot.get("score") == null ? null : Double + .valueOf(alAnnot.get("score").toString()); + alignAnnot.setCalcId(calcId); + String seqHash = (alAnnot.get("sequenceRef") != null) ? alAnnot + .get("sequenceRef").toString() : null; + + Sequence sequence = (seqHash != null) ? seqMap.get(seqHash) : null; + if (sequence != null) + { + alignAnnot.sequenceRef = sequence; + sequence.addAlignmentAnnotation(alignAnnot); + if (alignAnnot.label.equalsIgnoreCase("T-COFFEE")) + { + alignAnnot.createSequenceMapping(sequence, sequence.getStart(), + false); + sequence.addAlignmentAnnotation(alignAnnot); + alignAnnot.adjustForAlignment(); + } + } this.annotations.add(alignAnnot); + alignAnnot.validateRangeAndDisplay(); } } catch (Exception e) { @@ -641,10 +748,6 @@ public class JSONFile extends AlignFile implements ComplexAlignFile { if (annot != null && !annot.autoCalculated) { - if (!annot.visible) - { - continue; - } annotations.add(annot); } } diff --git a/src/jalview/jbgui/GAlignFrame.java b/src/jalview/jbgui/GAlignFrame.java index 73d34c2..e629932 100755 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@ -3110,4 +3110,9 @@ public class GAlignFrame extends JInternalFrame protected void showComplement_actionPerformed(boolean state) { } + + public JRadioButtonMenuItem getTcoffeColour() + { + return tcoffeeColour; + } } diff --git a/src/jalview/json/binding/biojson/v1/AlignmentAnnotationPojo.java b/src/jalview/json/binding/biojson/v1/AlignmentAnnotationPojo.java index 5e43f6d..9ac3957 100644 --- a/src/jalview/json/binding/biojson/v1/AlignmentAnnotationPojo.java +++ b/src/jalview/json/binding/biojson/v1/AlignmentAnnotationPojo.java @@ -41,6 +41,27 @@ public class AlignmentAnnotationPojo @Attributes(required = false) private List annotations = new ArrayList(); + @Attributes( + required = false, + enums = { "0", "1", "2" }, + description = "Determines the rendered for the annotation
  • 0 - No graph
  • 1 - Bar Graph
  • 2 - Line graph
") + private int graphType; + + @Attributes( + required = false, + description = "Reference to the sequence in the alignment
if per-sequence annotation") + private String sequenceRef; + + @Attributes( + required = false, + description = "Stores display settings for an annotation") + private AnnotationDisplaySettingPojo annotationSettings; + + @Attributes(required = false, description = "Score of the annotation") + private double score; + + private String calcId; + public String getLabel() { return label; @@ -71,4 +92,55 @@ public class AlignmentAnnotationPojo this.annotations = annotations; } + public String getSequenceRef() + { + return sequenceRef; + } + + public void setSequenceRef(String sequenceRef) + { + this.sequenceRef = sequenceRef; + } + + public int getGraphType() + { + return graphType; + } + + public void setGraphType(int graphType) + { + this.graphType = graphType; + } + + public AnnotationDisplaySettingPojo getAnnotationSettings() + { + return annotationSettings; + } + + public void setAnnotationSettings( + AnnotationDisplaySettingPojo annotationSettings) + { + this.annotationSettings = annotationSettings; + } + + public double getScore() + { + return score; + } + + public void setScore(double score) + { + this.score = score; + } + + public String getCalcId() + { + return calcId; + } + + public void setCalcId(String calcId) + { + this.calcId = calcId; + } + } diff --git a/src/jalview/json/binding/biojson/v1/AnnotationDisplaySettingPojo.java b/src/jalview/json/binding/biojson/v1/AnnotationDisplaySettingPojo.java new file mode 100644 index 0000000..a3011a0 --- /dev/null +++ b/src/jalview/json/binding/biojson/v1/AnnotationDisplaySettingPojo.java @@ -0,0 +1,64 @@ +package jalview.json.binding.biojson.v1; + +public class AnnotationDisplaySettingPojo +{ + private boolean scaleColLabel; + + private boolean showAllColLabels; + + private boolean centreColLabels; + + private boolean belowAlignment; + + private boolean visible; + + public boolean isScaleColLabel() + { + return scaleColLabel; + } + + public void setScaleColLabel(boolean scaleColLabel) + { + this.scaleColLabel = scaleColLabel; + } + + public boolean isShowAllColLabels() + { + return showAllColLabels; + } + + public void setShowAllColLabels(boolean showAllColLabels) + { + this.showAllColLabels = showAllColLabels; + } + + public boolean isCentreColLabels() + { + return centreColLabels; + } + + public void setCentreColLabels(boolean centreColLabels) + { + this.centreColLabels = centreColLabels; + } + + public boolean isBelowAlignment() + { + return belowAlignment; + } + + public void setBelowAlignment(boolean belowAlignment) + { + this.belowAlignment = belowAlignment; + } + + public boolean isVisible() + { + return visible; + } + + public void setVisible(boolean visible) + { + this.visible = visible; + } +} diff --git a/src/jalview/json/binding/biojson/v1/AnnotationPojo.java b/src/jalview/json/binding/biojson/v1/AnnotationPojo.java index 407ade4..a4d7f17 100644 --- a/src/jalview/json/binding/biojson/v1/AnnotationPojo.java +++ b/src/jalview/json/binding/biojson/v1/AnnotationPojo.java @@ -43,6 +43,9 @@ public class AnnotationPojo @Attributes(required = false, description = "Value of the annotation") private float value; + @Attributes(required = false, description = "Colour for position") + private String colour; + public String getDisplayCharacter() { return displayCharacter; @@ -83,4 +86,14 @@ public class AnnotationPojo this.value = value; } + public String getColour() + { + return colour; + } + + public void setColour(String colour) + { + this.colour = colour; + } + } diff --git a/src/jalview/schemes/UserColourScheme.java b/src/jalview/schemes/UserColourScheme.java index 92989fb..7aff05a 100755 --- a/src/jalview/schemes/UserColourScheme.java +++ b/src/jalview/schemes/UserColourScheme.java @@ -99,7 +99,7 @@ public class UserColourScheme extends ResidueColourScheme return schemeName; } - public Color getColourFromString(String colour) + public static Color getColourFromString(String colour) { colour = colour.trim(); -- 1.7.10.2