From: Charles Ofoegbu Date: Fri, 31 Oct 2014 09:56:45 +0000 (+0000) Subject: JAL-1541 upadated BioJs emmitter to store alignment data as json X-Git-Tag: Jalview_2_9~152^2~6 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=9e5effcac65476958e619298a1a939254f77bc4b;p=jalview.git JAL-1541 upadated BioJs emmitter to store alignment data as json --- diff --git a/lib/jsoup-1.8.1.jar b/lib/jsoup-1.8.1.jar new file mode 100644 index 0000000..ae717d4 Binary files /dev/null and b/lib/jsoup-1.8.1.jar differ diff --git a/resources/templates/BioJSTemplate.txt b/resources/templates/BioJSTemplate.txt index 67ed26a..8314a25 100644 --- a/resources/templates/BioJSTemplate.txt +++ b/resources/templates/BioJSTemplate.txt @@ -11,7 +11,9 @@ +
This data was generated from Jalview
press "Run with JS"
+ @@ -27,9 +29,11 @@ var opts = {}; // set your custom properties // @see: https://github.com/greenify/biojs-vis-msa/tree/master/src/g -var seqOnFly = []; -#sequenceData# -opts.seqs = seqOnFly; +//var seqOnFly = []; + +//alert(document.getElementById("seqData").value); + +opts.seqs = JSON.parse(document.getElementById("seqData").value); //opts.seqs = seqs; //msa.utils.seqgen.getDummySequences(1000,300); opts.el = document.getElementById("yourDiv"); diff --git a/src/jalview/io/BioJsHTMLOutput.java b/src/jalview/io/BioJsHTMLOutput.java index 5a236dc..6869292 100644 --- a/src/jalview/io/BioJsHTMLOutput.java +++ b/src/jalview/io/BioJsHTMLOutput.java @@ -8,11 +8,20 @@ import jalview.gui.AlignViewport; import jalview.gui.AlignmentPanel; import jalview.gui.FeatureRenderer; import jalview.gui.SequenceRenderer; +import jalview.json.binding.v1.BioJsAlignmentPojo; +import jalview.json.binding.v1.BioJsSeqPojo; import jalview.util.MessageManager; import java.io.IOException; import java.io.PrintWriter; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; + +import com.json.JSONException; +import com.json.JSONObject; + public class BioJsHTMLOutput { private AlignViewport av; @@ -21,7 +30,6 @@ public class BioJsHTMLOutput public BioJsHTMLOutput(AlignmentPanel ap, SequenceRenderer sr, FeatureRenderer fr1) { - System.out.println("BioJs working as expected so far"); this.av = ap.av; this.fr = new FeatureRenderer(ap); @@ -71,21 +79,33 @@ public class BioJsHTMLOutput } private String generateBioJsAlignmentData(AlignmentI alignment) - throws IOException + throws IOException, JSONException { - StringBuilder bioJsData = new StringBuilder(); + BioJsAlignmentPojo bjsAlignment = new BioJsAlignmentPojo(); + int count = 0; for (SequenceI seq : alignment.getSequences()) { - bioJsData.append("seqOnFly.push({seq:'" + seq.getSequenceAsString() - + "', name:'" + seq.getName() + "', id:" + ++count + "});"); + bjsAlignment.getSeqs().add( + new BioJsSeqPojo(String.valueOf(++count), seq.getName(), seq + .getSequenceAsString())); } + + String seqs = new JSONObject(bjsAlignment).getString("seqs"); String bioJSTemplate = new String( readAllBytes(get("resources/templates/BioJSTemplate.txt"))); - return bioJSTemplate.replaceAll("#sequenceData#", bioJsData.toString()); + return bioJSTemplate.replaceAll("#sequenceData#", seqs); } + public static void main(String[] args) throws IOException + { + Document doc = Jsoup.parse(new String( + readAllBytes(get("resources/templates/BioJSTemplate.txt")))); + + Element content = doc.getElementById("seqData"); + System.out.println(content.val()); + } } diff --git a/src/jalview/json/binding/v1/BioJsAlignmentPojo.java b/src/jalview/json/binding/v1/BioJsAlignmentPojo.java new file mode 100644 index 0000000..893e16b --- /dev/null +++ b/src/jalview/json/binding/v1/BioJsAlignmentPojo.java @@ -0,0 +1,22 @@ +package jalview.json.binding.v1; + +import java.util.ArrayList; + +public class BioJsAlignmentPojo +{ + private ArrayList seqs = new ArrayList(); + + public BioJsAlignmentPojo() + { + + } + public ArrayList getSeqs() + { + return seqs; + } + + public void setSeqs(ArrayList seqs) + { + this.seqs = seqs; + } +} diff --git a/src/jalview/json/binding/v1/BioJsSeqPojo.java b/src/jalview/json/binding/v1/BioJsSeqPojo.java new file mode 100644 index 0000000..6a6c7fe --- /dev/null +++ b/src/jalview/json/binding/v1/BioJsSeqPojo.java @@ -0,0 +1,52 @@ +package jalview.json.binding.v1; + + +public class BioJsSeqPojo +{ + private String seq; + + private String name; + + private String id; + + public BioJsSeqPojo() + { + } + + public BioJsSeqPojo(String id, String name, String seq) + { + this.id = id; + this.name = name; + this.seq = seq; + } + public String getSeq() + { + return seq; + } + + public void setSeq(String seq) + { + this.seq = seq; + } + + public String getName() + { + + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } +}