JAL-1541 upadated BioJs emmitter to store alignment data as json
authorCharles Ofoegbu <tcnofoegbu@dundee.ac.uk>
Fri, 31 Oct 2014 09:56:45 +0000 (09:56 +0000)
committerCharles Ofoegbu <tcnofoegbu@dundee.ac.uk>
Fri, 31 Oct 2014 09:56:45 +0000 (09:56 +0000)
lib/jsoup-1.8.1.jar [new file with mode: 0644]
resources/templates/BioJSTemplate.txt
src/jalview/io/BioJsHTMLOutput.java
src/jalview/json/binding/v1/BioJsAlignmentPojo.java [new file with mode: 0644]
src/jalview/json/binding/v1/BioJsSeqPojo.java [new file with mode: 0644]

diff --git a/lib/jsoup-1.8.1.jar b/lib/jsoup-1.8.1.jar
new file mode 100644 (file)
index 0000000..ae717d4
Binary files /dev/null and b/lib/jsoup-1.8.1.jar differ
index 67ed26a..8314a25 100644 (file)
@@ -11,7 +11,9 @@
 <link type=text/css rel=stylesheet href=  https://raw.githubusercontent.com/greenify/biojs-vis-msa/master/external/jquery.dropdown.css />
   
 <div id="menuDiv"></div>
+<div> This data was generated from Jalview<div>
 <div id="yourDiv">press "Run with JS"</div>
+<input type='hidden' id='seqData' name='seqData' value='#sequenceData#'/>
 </body>
 </html>
 
@@ -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");
index 5a236dc..6869292 100644 (file)
@@ -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 (file)
index 0000000..893e16b
--- /dev/null
@@ -0,0 +1,22 @@
+package jalview.json.binding.v1;
+
+import java.util.ArrayList;
+
+public class BioJsAlignmentPojo
+{
+  private ArrayList<BioJsSeqPojo> seqs = new ArrayList<BioJsSeqPojo>();
+
+  public BioJsAlignmentPojo()
+  {
+
+  }
+  public ArrayList<BioJsSeqPojo> getSeqs()
+  {
+    return seqs;
+  }
+
+  public void setSeqs(ArrayList<BioJsSeqPojo> 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 (file)
index 0000000..6a6c7fe
--- /dev/null
@@ -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;
+  }
+}