How To Set The Registry File For Biomart 0.8 Java
2
0
Entering edit mode
12.9 years ago
Manjulapra ▴ 70

Hi, I want to access the COSMIC database online using Java. My application does not have it's own data source and uses online resources. I used the the Java code generated by the BioMart central portal. When I try to use it with my project it gives many errors. The help group has advised me to use 0.8 registry format and to use rc6 to create this. But I found it difficult to grab this. Lot of tutorials in the web are on creating your own marts. Please help me to create a 0.8 registry file format to access COSMIC database. Thanks in advance Regards, Manjula

biomart api java • 3.3k views
ADD COMMENT
0
Entering edit mode
ADD REPLY
0
Entering edit mode

Very similar post, but that was Perl so I think we can leave this one open.

ADD REPLY
0
Entering edit mode

Ah, yes! Didn't see that, lol :S Thanks Neil :)

ADD REPLY
1
Entering edit mode
12.8 years ago
Joachim ★ 2.9k

Hi!

It appears that the BioMart Central Portal configuration is currently not up-to-date, which essentially means that it does not work with COSMIC right now. However, since Central Portal is a BioMart 0.8 installation that only federates the real BioMart 0.7 COSMIC mart, you can still access COSMIC mart here.

The documentation to access this BioMart 0.7 COSMIC mart can be found here.

The BioMart 0.7 itself says about its Java API the following:

The Java API is out-of-date and is due for a complete rewrite.
The details here are presented for sake of completeness.

You can either try to formulate your queries completely independent of Java as described here, and then process the results in your Java program, or you try the following Java workaround:

import java.io.*;
import java.net.*;
import java.util.*;

public class BM7 {

    public static void main(String[] argv) throws Exception {
        String dataset;
        Map<String, String=""> filters = new HashMap<String, String="">();
        List<String> attributes = new LinkedList<String>();

        dataset = "COSMIC56";

        filters.put("samp_gene_mutated", "y");
        filters.put("sample_source", "blood");
        filters.put("tumour_source", "primary");

        attributes.add("id_sample");
        attributes.add("sample_name");
        attributes.add("sample_source");
        attributes.add("tumour_source");
        attributes.add("gene_name");
        attributes.add("accession_number");
        attributes.add("id_mutation");
        attributes.add("cds_mut_syntax");
        attributes.add("aa_mut_syntax");
        attributes.add("zygosity");
        attributes.add("site_primary");
        attributes.add("hist_primary");
        attributes.add("pubmed_pmid");

        String result = BM7.callRestfulWebService("http://www.sanger.ac.uk/genetics/CGP/cosmic/biomart/martservice", dataset, filters, attributes);

        System.out.println(result);
    }

    private static String buildWebQuery(String dataset, Map<String, String=""> filters, List<String> attributes) throws Exception {
        StringBuilder sb = new StringBuilder();

        sb.append("query=");

        sb.append("");

        sb.append("<Query virtualSchemaName="\"default\"" formatter="\"TSV\"" header="\"0\"" uniqueRows="\"0\"" count="\"\"" datasetConfigVersion="\"0.6\"">");

        sb.append("<Dataset name="\"").append(dataset).append("\"" interface="\"default\"">");

        for (Map.Entry<String, String=""> entry : filters.entrySet()) {
            String key = URLEncoder.encode(entry.getKey(), "UTF-8");
            String value = URLEncoder.encode(entry.getValue(), "UTF-8");

            sb.append("<Filter name="\"").append(key).append("\"" value="\"").append(value).append("\"/">");
        }

        for (String attribute : attributes) {
            String value = URLEncoder.encode(attribute, "UTF-8");

            sb.append("<Attribute name="\"").append(value).append("\"/">");
        }

        sb.append("</Dataset></Query>");

        return sb.toString();
    }

    public static String callRestfulWebService(String address, String dataset, Map<String, String=""> filters, List<String> attributes) throws Exception {
        String response = "";
        String query = buildWebQuery(dataset, filters, attributes);

        URL url = new URL(address);
        URLConnection urlc = null;

        urlc = url.openConnection();
        urlc.setDoOutput(true);
        urlc.setAllowUserInteraction(false);

        PrintStream ps = new PrintStream(urlc.getOutputStream());
        ps.print(query);
        ps.close();

        BufferedReader br = new BufferedReader(new InputStreamReader(urlc.getInputStream(), "UTF-8"));
        StringBuilder sb = new StringBuilder();
        String line;
        while ((line = br.readLine()) != null) {
            sb.append(line);
            sb.append("\n");
        }
        br.close();
        response = sb.toString();

        return response;
    }
}

This program will return the results in TSV-format in "String result".

Hope this helps,

Joachim

PS: For my Java example I borrowed extensively from here.

ADD COMMENT
0
Entering edit mode
12.9 years ago

I'm not a Java guy, but does this link help? It seems to have all the information one might need for BioMart 0.8 RC6? Section 11.6 specifically details the Java API! Section 5 (e.g. 5.7) mentions adding marts to the registry file! The Gmod link seems useful too?

ADD COMMENT
0
Entering edit mode

Thanks. I am working on this.

ADD REPLY

Login before adding your answer.

Traffic: 1338 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6