8
|
1 #!/usr/bin/env python
|
|
2
|
|
3 import sys, os
|
|
4 import argparse
|
|
5
|
|
6 import readfile
|
|
7
|
|
8 #dicitionary for the output format
|
|
9
|
|
10 dict_output={"cids" :"txt", "aids" : "txt", "sids" : "txt", "description": "xml", "summary" : "xml", "record" : "csv", "classification": "xml", "targets" : "txt", "xrefs" : "txt", "synonyms" : "txt", "property": "csv" }
|
|
11
|
|
12 #alles andere ist xml
|
|
13 check_for_id_type=["cids", "aids", "sids"]
|
|
14
|
|
15 id_dict={"compound": "cid", "assay": "aid", "substance" : "sid" }
|
|
16
|
|
17 def getListString(args):
|
|
18 if args.id_type_ff == "file":
|
|
19 #build comma list
|
|
20 list_string=",".join(getListFromFile(open(args.id_value,"r")))
|
|
21 else:
|
|
22 list_string=args.id_value
|
|
23 return list_string
|
|
24
|
|
25
|
|
26 def main(args):
|
|
27
|
|
28 url="http://pubchem.ncbi.nlm.nih.gov/rest/pug/"+args.type+"/"
|
|
29 url+=args.id_type+"/"
|
|
30 if args.id_type ==id_dict[args.type]:
|
|
31 url+=getListString(args)+"/"
|
|
32 else:
|
|
33 url+=args.id_value+"/"
|
|
34 url+=args.operation+"/"
|
|
35 if args.operation == "target" or args.operation == "property" or args.operation == "xrefs":
|
|
36 url+=args.operation_value+"/"
|
|
37
|
|
38 url+=dict_output[args.operation]
|
|
39 if args.operation in check_for_id_type:
|
|
40 url+="?"+args.operation+"_type="+args.ids_operation_type
|
|
41 print(url)
|
|
42 readfile.store_result(url, args.outfile)
|
|
43
|
|
44
|
|
45
|
|
46
|
|
47 if __name__ == "__main__":
|
|
48 parser = argparse.ArgumentParser()
|
|
49 parser.add_argument('--type', type=str, required=True,
|
|
50 help="That you want BioAssay Compund ...")
|
|
51 parser.add_argument('--id-type', type=str,
|
|
52 help="Specify the ID type")
|
|
53 parser.add_argument('--operation', type=str, required=True,
|
|
54 help="Specify the operation")
|
|
55 parser.add_argument('--operation-value', dest="operation_value", type=str, required=False,
|
|
56 help="Specify the additional operation value")
|
|
57 parser.add_argument('--xref-operation-value', dest="xref_operation_value", type=str, required=False,
|
|
58 help="Specify the xref operation ")
|
|
59 parser.add_argument('--ids-operation-type', dest="ids_operation_type", type=str, required=False,
|
|
60 help="all inactive ...")
|
|
61 parser.add_argument('--xref', dest="xref", type=str,
|
|
62 help="use xref to identify the searched thing")
|
|
63 parser.add_argument('--xref-value', dest="xref_value", type=str,
|
|
64 help="Specify the xref")
|
|
65 parser.add_argument('--property-value', dest="property_value", type=str,
|
|
66 help="Specify the property value")
|
|
67 parser.add_argument('--id-type-ff', dest="id_type_ff", type=str,
|
|
68 help="file or field")
|
|
69 parser.add_argument('--id-value', dest="id_value", type=str, required=True,
|
|
70 help="Specify the id")
|
|
71 parser.add_argument('--outfile', type=argparse.FileType('w'), required=True,
|
|
72 help="Specify the output file")
|
|
73
|
|
74
|
|
75 if len(sys.argv) < 8:
|
|
76 print "Too few arguments..."
|
|
77 parser.print_help()
|
|
78 exit(1)
|
|
79 args = parser.parse_args()
|
|
80 main( args )
|