Mercurial > repos > bernhardlutz > rest_tool
comparison rest_tool_comp_for_assay.py @ 4:54358dfa62c0 draft
Uploaded
author | bernhardlutz |
---|---|
date | Fri, 28 Mar 2014 13:41:22 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3:0bbb107a2cf2 | 4:54358dfa62c0 |
---|---|
1 #!/usr/bin/env python | |
2 # Aufruf convert_graph.py --aid list of ids --aid-from-file file | |
3 | |
4 import sys, os | |
5 import networkx as nx | |
6 import argparse | |
7 import urllib2, urllib, httplib | |
8 | |
9 import readfile | |
10 #supported graph_types | |
11 #output_types = ["tsv", "csv", "png", "json", "txt", "xml", "sdf", "asnt", "asnb", "jsonp"] | |
12 | |
13 | |
14 #get the cids for bioassay aid | |
15 def getCompoundList(aidlist): | |
16 aidliststring=",".join(aidlist) | |
17 url="http://pubchem.ncbi.nlm.nih.gov/rest/pug/assay/aid/"+aidliststring+"/cids/txt" | |
18 data=readfile.getresult(url) | |
19 return data | |
20 | |
21 def main(args): | |
22 if args.aidfile is None: | |
23 aidlist=args.aid.split(",") | |
24 else: | |
25 aidlist=readfile.getListFromFile(args.aidfile) | |
26 cids=getCompoundList(aidlist) | |
27 args.outfile.write(cids) | |
28 args.outfile.close() | |
29 | |
30 | |
31 if __name__ == "__main__": | |
32 parser = argparse.ArgumentParser() | |
33 parser.add_argument('--aid', type=str, | |
34 help="AIDs of the BioAssay") | |
35 parser.add_argument('--aidfile', type=argparse.FileType('r'), | |
36 help="Specify a file with a list of aids, one per line") | |
37 parser.add_argument('--outfile', type=argparse.FileType('w'), | |
38 help="Specify output file") | |
39 if len(sys.argv) < 2: | |
40 print "Too few arguments..." | |
41 parser.print_help() | |
42 exit(1) | |
43 args = parser.parse_args() | |
44 main( args ) |