Mercurial > repos > bernhardlutz > rest_tool
comparison rest_tool.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 --type type --operation op --id id --outfile outfile | |
3 | |
4 import sys, os | |
5 import argparse | |
6 | |
7 import readfile | |
8 | |
9 txt_output=["cids", "summary", "synonyms" ] | |
10 | |
11 def main(args): | |
12 url="http://pubchem.ncbi.nlm.nih.gov/rest/pug/"+args.type+"/" | |
13 if args.type == "assay": | |
14 url+="aid/" | |
15 elif args.type == "compound": | |
16 url+="cid/" | |
17 elif args.type == "substance": | |
18 url+="sid/" | |
19 if args.idfile is None: | |
20 idstring=str(args.id) | |
21 else: | |
22 idlist=readfile.getListFromFile(args.idfile) | |
23 idstring=",".join(idlist) | |
24 url+=idstring+"/"+args.operation+"/" | |
25 if args.operation in txt_output: | |
26 url+="txt" | |
27 else: | |
28 url+="csv" | |
29 print(url) | |
30 data=readfile.getresult(url) | |
31 outfile=args.outfile | |
32 outfile.write(data) | |
33 outfile.close() | |
34 | |
35 if __name__ == "__main__": | |
36 parser = argparse.ArgumentParser() | |
37 parser.add_argument('--type', type=str, | |
38 help="That you want BioAssay Compund ...") | |
39 parser.add_argument('--id', type=str, | |
40 help="Specify the ID") | |
41 parser.add_argument('--operation', type=str, | |
42 help="Specify the operation") | |
43 parser.add_argument('--property-value', type=str, | |
44 help="Specify the property") | |
45 parser.add_argument('--outfile', type=argparse.FileType('w'), | |
46 help="Specify one output file") | |
47 parser.add_argument('--idfile', type=argparse.FileType('r'), | |
48 help="Specify a file with a list of ids, one per line") | |
49 if len(sys.argv) < 8: | |
50 print "Too few arguments..." | |
51 parser.print_help() | |
52 exit(1) | |
53 args = parser.parse_args() | |
54 main( args ) |