From 5d59bb58f5bcecc6b240d125e13bbe1f1868f681 Mon Sep 17 00:00:00 2001 From: tcofoegbu Date: Tue, 19 May 2015 11:03:24 +0100 Subject: [PATCH] JAL-1541 Modified BioJs exporter to take advantage of the abstracted JSONFile export/import mechanism --- resources/templates/BioJSTemplate.txt | 28 +++++++-- src/jalview/io/BioJsHTMLOutput.java | 104 ++------------------------------- 2 files changed, 28 insertions(+), 104 deletions(-) diff --git a/resources/templates/BioJSTemplate.txt b/resources/templates/BioJSTemplate.txt index bf780bb..c47b059 100644 --- a/resources/templates/BioJSTemplate.txt +++ b/resources/templates/BioJSTemplate.txt @@ -44,9 +44,9 @@ function toggleMenuVisibility(){ function openJalviewUsingCurrentUrl(){ - var jalviewData = JSON.parse(document.getElementById("seqData").value) - var jalviewVersion = jalviewData['jalviewVersion']; - var url = jalviewData['webStartUrl']; + var json = JSON.parse(document.getElementById("seqData").value) + var jalviewVersion = json['jalviewSettings'].jalviewVersion; + var url = json['jalviewSettings'].webStartUrl; var myForm = document.createElement("form"); myForm.action = url; @@ -9009,12 +9009,28 @@ opts.zoomer = {alignmentHeight: 225, labelWidth: 130,labelFontsize: "13px",label // init msa var m = new msa.msa(opts); -m.g.colorscheme.set("scheme", jalviewData['globalColorScheme']); +m.g.colorscheme.set("scheme", jalviewData['jalviewSettings'].globalColorScheme); var x = 0; -jalviewData.seqs.forEach( function (seq) +//jalviewData.seqs.forEach( function (seq) +//{ +//m.seqs.at(x++).set("features", new msa.model.featurecol(seq.features)); +//}); + +//console.debug(">>>>>>>>>>>>>" + m.seqs.length); +//console.debug(">>>>>>>>>>>>> Found features : " + jalviewData.seqFeatures.length); +m.seqs.forEach( function (seq ) { -m.seqs.at(x++).set("features", new msa.model.featurecol(seq.features)); + var seqFeats = []; + for (i = 0; i < jalviewData.seqFeatures.length; i++) { + console.debug('comparing >>>>>>>> '+ seq.id) + if(jalviewData.seqFeatures[i].sequenceRef === seq.id){ + // console.debug('>>>>>>>> '+jalviewData.seqFeatures[i].sequenceRef+' | '+ seq.id) + seqFeats.push(jalviewData.seqFeatures[i]); + } + } +console.debug('matched features count : '+seqFeats.length); +seq.set("features", new msa.model.featurecol(seqFeats)); }); // the menu is independent to the MSA container diff --git a/src/jalview/io/BioJsHTMLOutput.java b/src/jalview/io/BioJsHTMLOutput.java index 4945306..86b4c28 100644 --- a/src/jalview/io/BioJsHTMLOutput.java +++ b/src/jalview/io/BioJsHTMLOutput.java @@ -1,59 +1,33 @@ package jalview.io; -import jalview.api.FeaturesDisplayedI; -import jalview.datamodel.AlignmentI; -import jalview.datamodel.SequenceFeature; -import jalview.datamodel.SequenceI; import jalview.exceptions.NoFileSelectedException; +import jalview.gui.AlignViewport; import jalview.gui.AlignmentPanel; import jalview.gui.FeatureRenderer; -import jalview.json.binding.v1.AlignmentPojo; -import jalview.json.binding.v1.SequenceFeaturesPojo; -import jalview.json.binding.v1.SequencePojo; -import jalview.schemes.ColourSchemeProperty; import jalview.util.MessageManager; -import jalview.viewmodel.AlignmentViewport; -import java.awt.Color; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.URL; -import java.util.ArrayList; - -import com.json.JSONException; public class BioJsHTMLOutput { - private AlignmentViewport av; - - private jalview.api.FeatureRenderer fr; - - private String globalColorScheme; - - private FeaturesDisplayedI displayedFeatures; + private AlignViewport av; - private String jalviewVersion; - - private String webStartLaunchServletUrl = "http://www.jalview.org/services/launchApp"; public BioJsHTMLOutput(AlignmentPanel ap, FeatureRenderer fr1) { - jalviewVersion = jalview.bin.Cache.getProperty("VERSION"); - webStartLaunchServletUrl = jalview.bin.Cache.getDefault( - "www.jalview.org", "http://www.jalview.org") - + "/services/launchApp"; if (ap != null) { + this.av = ap.av; - this.globalColorScheme = ColourSchemeProperty.getColourName(av - .getGlobalColourScheme()); - this.fr = ap.cloneFeatureRenderer(); - displayedFeatures = av.getFeaturesDisplayed(); + av.setFeatureRenderer(new FeatureRenderer(ap)); } + exportJalviewAlignmentAsBioJsHtmlFile(); } private void exportJalviewAlignmentAsBioJsHtmlFile() @@ -61,8 +35,7 @@ public class BioJsHTMLOutput try { String outputFile = getOutputFile(); - String jalviewAlignmentJson = getJalviewAlignmentAsJsonString(av - .getAlignment()); + String jalviewAlignmentJson = JSONFile.getJSONData(av); String bioJSTemplateString = getBioJsTemplateAsString(this); String generatedBioJsWithJalviewAlignmentAsJson = bioJSTemplateString .replaceAll( @@ -110,63 +83,9 @@ public class BioJsHTMLOutput { throw new NoFileSelectedException("No file was selected."); } - return selectedFile; } - public String getJalviewAlignmentAsJsonString(AlignmentI alignment) - throws IOException, JSONException - { - AlignmentPojo bjsAlignment = new AlignmentPojo(); - - // bjsAlignment.setGlobalColorScheme(getGlobalColorScheme()); - // bjsAlignment.setJalviewVersion(jalviewVersion); - // bjsAlignment.setWebStartUrl(webStartLaunchServletUrl); - - int count = 0; - for (SequenceI seq : alignment.getSequences()) - { - StringBuilder name = new StringBuilder(); - name.append(seq.getName()).append("/").append(seq.getStart()) - .append("-").append(seq.getEnd()); - - SequencePojo seqPojo = new SequencePojo(); - seqPojo.setId(String.valueOf(++count)); - seqPojo.setEnd(seq.getEnd()); - seqPojo.setStart(seq.getStart()); - seqPojo.setName(name.toString()); - seqPojo.setSeq(seq.getSequenceAsString()); - - SequenceFeature[] seqFeatures = seq.getSequenceFeatures(); - if (seqFeatures != null) - { - ArrayList bjsSeqFeatures = new ArrayList(); - for (SequenceFeature sf : seqFeatures) - { - if (displayedFeatures != null - && displayedFeatures.isVisible(sf.getType())) - { - - // TODO: translate graduated/complex colourschemes to biojs model - String featureColour = jalview.util.Format.getHexString(fr - .findFeatureColour(Color.white, seq, - seq.findIndex(sf.getBegin()))); - // SequenceFeaturesPojo bjsFeature = new SequenceFeaturesPojo(); - // bjsFeature.setFillColor(featureColour); - // bjsFeature.setXstart(seq.findIndex(sf.getBegin()) - 1); - // bjsFeature.setXend(seq.findIndex(sf.getEnd())); - // bjsFeature.setType(sf.getType()); - // bjsSeqFeatures.add(bjsFeature); - } - } - // seqPojo.setFeatures(bjsSeqFeatures); - } - bjsAlignment.getSeqs().add(seqPojo); - } - - return new com.json.JSONObject(bjsAlignment).toString() - .replaceAll("xstart", "xStart").replaceAll("xend", "xEnd"); - } public static String getBioJsTemplateAsString(Object currentObj) throws IOException @@ -207,15 +126,4 @@ public class BioJsHTMLOutput } return sb.toString(); } - - public String getGlobalColorScheme() - { - return globalColorScheme; - } - - public void setGlobalColorScheme(String globalColorScheme) - { - this.globalColorScheme = globalColorScheme; - } - } -- 1.7.10.2