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.
Duplicate post? http://biostar.stackexchange.com/questions/10298/how-to-set-registry-file-to-access-a-online-db-like-cosmic-or-ensembl
Very similar post, but that was Perl so I think we can leave this one open.
Ah, yes! Didn't see that, lol :S Thanks Neil :)