comparison rest_tool_comp_for_assay.py @ 6:9ee84d9fd3a7 draft

Uploaded
author bernhardlutz
date Thu, 03 Apr 2014 06:50:57 -0400
parents
children
comparison
equal deleted inserted replaced
5:1ad356686717 6:9ee84d9fd3a7
1 #!/usr/bin/env python
2
3 import sys, os
4 import argparse
5 import tempfile
6 import readfile
7 import rest_tool_functions
8
9
10 #get the cids for bioassay aid
11 def get_aid_cid_dict_for_list(aidlist):
12 aidliststring=",".join(aidlist)
13 url="http://pubchem.ncbi.nlm.nih.gov/rest/pug/assay/aid/"+aidliststring+"/cids/xml"
14 xml=readfile.getresult(url)
15 tmp = tempfile.TemporaryFile()
16 tmp.write(xml)
17 tmp.seek(0)
18 dic=rest_tool_functions.give_aid_cid_dict_from_xml(tmp)
19 tmp.close()
20 return dic
21
22 def main(args):
23 if args.aid_file is None:
24 aidlist=args.aid.split(",")
25 else:
26 aidlist=readfile.getListFromFile(args.aid_file)
27 dic=get_aid_cid_dict_for_list(aidlist)
28 rest_tool_functions.write_to_csv(dic, args.outfile)
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('--aid-file', dest="aid_file", 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 )