annotate NCBO_services/extract.java @ 23:02fd92020943

Deleted selected files
author jose-minyarro
date Mon, 19 Mar 2012 08:17:58 -0400
parents 1910c878378c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
1 package es.upm.fi.dia.oeg.ncbo.galaxy;
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
2
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
3 import java.io.BufferedReader;
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
4 import java.io.BufferedWriter;
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
5 import java.io.IOException;
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
6 import java.io.InputStream;
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
7 import java.io.InputStreamReader;
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
8 import java.io.OutputStreamWriter;
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
9
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
10 import org.apache.http.HttpEntity;
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
11 import org.apache.http.HttpResponse;
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
12 import org.apache.http.client.ClientProtocolException;
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
13 import org.apache.http.client.HttpClient;
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
14 import org.apache.http.client.methods.HttpGet;
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
15 import org.apache.http.impl.client.DefaultHttpClient;
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
16
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
17 public class extract {
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
18
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
19 /**
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
20 * @param args
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
21 * @throws IOException
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
22 * @throws ClientProtocolException
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
23 */
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
24 public static void main(String[] args) throws ClientProtocolException, IOException {
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
25
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
26 // http://www.bioontology.org/wiki/index.php/View_Extraction
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
27 // ./viewextractor/{ontology version id}[?{args}]&apikey={YourAPIKey}
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
28
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
29 String api_key = args [0];
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
30 String ontologyversionid = args [1]; // 35686
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
31 String conceptid = args [2]; // E800-E999.9
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
32 String filterrelations = args [3]; // PAR,isa,CHD,inverse_isa,SUBSETMEMBER,SubClass,SuperClass,[R]SIB,SI
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
33 String ontologyname = args [4]; // http://who.int/icd9
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
34
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
35 HttpClient client = new DefaultHttpClient();
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
36
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
37 // HttpGet get = new HttpGet("http://rest.bioontology.org/bioportal/viewextractor/35686/" +
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
38 // "?conceptid=E800-E999.9&filterrelations=PAR,isa,CHD,inverse_isa,SUBSETMEMBER,SubClass,SuperClass," +
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
39 // "[R]SIB,SIB&existontology=true&ontologyname=http://who.int/icd9&apikey=74c12fc6-9423-455a-a619-b94f47d1951b");
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
40
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
41 HttpGet get = new HttpGet("http://rest.bioontology.org/bioportal/viewextractor/" + ontologyversionid +
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
42 "/?conceptid="+ conceptid +"&filterrelations=" + filterrelations +
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
43 "&existontology=true&ontologyname="+ ontologyname + "&apikey=" + api_key);
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
44
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
45 HttpResponse response = client.execute(get);
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
46 HttpEntity entity = response.getEntity();
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
47 if (entity != null) {
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
48 InputStream instream = entity.getContent();
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
49 InputStreamReader is=new InputStreamReader(instream);
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
50 BufferedReader br=new BufferedReader(is);
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
51 String read=br.readLine();
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
52 BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
53 while(read!=null){
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
54 // System.out.println(read);
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
55 bw.write(read);
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
56 bw.newLine();
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
57 read=br.readLine();
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
58 }
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
59 bw.close();
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
60 instream.close();
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
61 }
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
62
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
63 }
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
64
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
65 }