comparison get_ontology_view.java @ 27:e2b16720ef25 draft

Directories re-arranged for easier installation via mercurial
author Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
date Mon, 08 Oct 2012 14:25:04 +0200
parents NCBO_services/get_ontology_view.java@1910c878378c
children
comparison
equal deleted inserted replaced
26:354aa87772e0 27:e2b16720ef25
1 package es.upm.fi.dia.oeg.ncbo.galaxy;
2
3 import java.io.BufferedReader;
4 import java.io.BufferedWriter;
5 import java.io.IOException;
6 import java.io.InputStream;
7 import java.io.InputStreamReader;
8 import java.io.OutputStreamWriter;
9
10 import org.apache.http.HttpEntity;
11 import org.apache.http.HttpResponse;
12 import org.apache.http.client.ClientProtocolException;
13 import org.apache.http.client.HttpClient;
14 import org.apache.http.client.methods.HttpGet;
15 import org.apache.http.client.methods.HttpPost;
16 import org.apache.http.impl.client.DefaultHttpClient;
17
18 public class get_ontology_view {
19
20 /**
21 * @param args
22 * @throws IOException
23 * @throws ClientProtocolException
24 */
25 public static void main(String[] args) throws ClientProtocolException, IOException {
26 // http://www.bioontology.org/wiki/index.php/BioPortal_REST_services#Download_a_specific_ontology_view_based_on_the_ontology_view_version_id
27 // Download a specific ontology view based on the ontology view version id
28
29 String api_key = args [0];
30 String ontology_view_id = args [1];
31
32 HttpClient client = new DefaultHttpClient();
33 // http://rest.bioontology.org/bioportal/ontologies/download/43072?apikey=YourAPIKey
34 HttpGet get = new HttpGet("http://rest.bioontology.org/bioportal/ontologies/download/" + ontology_view_id + "?apikey=" + api_key);
35
36 HttpResponse response = client.execute(get);
37 HttpEntity entity = response.getEntity();
38 if (entity != null) {
39 InputStream instream = entity.getContent();
40 InputStreamReader is=new InputStreamReader(instream);
41 BufferedReader br=new BufferedReader(is);
42 String read=br.readLine();
43 BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
44 while(read!=null){
45 // System.out.println(read);
46 bw.write(read);
47 bw.newLine();
48 read=br.readLine();
49 }
50 bw.close();
51 instream.close();
52 }
53 }
54 }