# HG changeset patch # User bernhardlutz # Date 1395684006 14400 # Node ID d3f9c70919dc297c242ae4a8df2689d9906d1264 # Parent 954a489c1606e32c8b54d960f395e32cbc0e6d6f Uploaded diff -r 954a489c1606 -r d3f9c70919dc rest_tool.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rest_tool.py Mon Mar 24 14:00:06 2014 -0400 @@ -0,0 +1,53 @@ +#!/usr/bin/env python +# Aufruf convert_graph.py --type type --operation op --id id --outformat format --outfile outfile + +import sys, os +import networkx as nx +import argparse +import urllib2 + +#supported graph_types +output_types = ["tsv", "csv", "png", "json", "txt", "xml", "sdf", "asnt", "asnb", "jsonp"] + + +def getresult(url): + try: + connection = urllib2.urlopen(url) + except urllib2.HTTPError, e: + return "" + else: + return connection.read().rstrip() +def main(args): + url="http://pubchem.ncbi.nlm.nih.gov/rest/pug/"+args.type+"/" + if args.type == "assay": + url+="aid/" + elif args.type == "compound": + url+="cid/" + url+=args.id+"/"+args.operation+"/"+args.outformat + print(url) + print(args.type) + data=getresult(url) + file=args.outfile + file.write(data) + file.close() + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument('--type', type=str, + help="That you want BioAssay Compund ...") + parser.add_argument('--id', type=str, + help="Specify the ID") + parser.add_argument('--operation', type=str, + help="Specify the operation") + parser.add_argument('--property-value', type=str, + help="Specify the property") + parser.add_argument('--outformat', type=str, + help="Specify the format of the output", choices = output_types) + parser.add_argument('--outfile', type=argparse.FileType('w'), + help="Specify one output file") + if len(sys.argv) < 8: + print "Too few arguments..." + parser.print_help() + exit(1) + args = parser.parse_args() + main( args ) diff -r 954a489c1606 -r d3f9c70919dc rest_tool.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rest_tool.xml Mon Mar 24 14:00:06 2014 -0400 @@ -0,0 +1,85 @@ + + Fetch pubchem data + echo "0.1.0" + + REST_TOOL_SCRIPT_PATH + + + #if $choose_action.action == 'specific_data': + rest_tool.py + --id $choose_action.id + --type $choose_action.input_type + --outformat $choose_action.output_format + + --operation $choose_action.operation_property.operation + #if $choose_action.operation_property.operation == 'property': + --property-value $choose_action.operation_property.property + #end if + + --outfile $output + #elif $choose_action.action == 'compounds_for_assay': + rest_tool_comp_for_assay.py --aid $choose_action.aid --outfile $output + #end if + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +**What it does** + +This tool fetches data from pubchem + + diff -r 954a489c1606 -r d3f9c70919dc rest_tool_comp_for_assay.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rest_tool_comp_for_assay.py Mon Mar 24 14:00:06 2014 -0400 @@ -0,0 +1,59 @@ +#!/usr/bin/env python +# Aufruf convert_graph.py --aid list of ids --aid-from-file file + +import sys, os +import networkx as nx +import argparse +import urllib2, urllib, httplib + +#supported graph_types +#output_types = ["tsv", "csv", "png", "json", "txt", "xml", "sdf", "asnt", "asnb", "jsonp"] + + +def getresult(url): + try: + connection = urllib2.urlopen(url) + except urllib2.HTTPError, e: + return "" + else: + return connection.read().rstrip() + + +def getresultPost(url, aidList): + values={'aids': ",".join(aidList)} + data=urllib.urlencode(values) + print(data) + + headers = {"Content-type": "application/x-www-form-urlencoded"} + conn = httplib.HTTPConnection("pubchem.ncbi.nlm.nih.gov") + conn.request("POST", "/rest/pug/assay/aid/aids/csv", data, headers) + response = conn.getresponse() + conn.close() + return response.read() + + + +#get the cids for bioassay aid +def getCompoundList(aid): + url="http://pubchem.ncbi.nlm.nih.gov/rest/pug/assay/aid/"+aid+"/cids/txt" + data=getresult(url) + return data + +def main(args): + cids=getCompoundList(args.aid) + args.outfile.write(cids) + args.outfile.close() +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument('--aid', type=str, + help="AIDs of the BioAssay") + parser.add_argument('--aid-from-file', type=argparse.FileType('r'), + help="Specify a file with a list of aids, one per line") + parser.add_argument('--outfile', type=argparse.FileType('w'), + help="Specify output file") + if len(sys.argv) < 2: + print "Too few arguments..." + parser.print_help() + exit(1) + args = parser.parse_args() + main( args ) diff -r 954a489c1606 -r d3f9c70919dc tool_dependencies.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tool_dependencies.xml Mon Mar 24 14:00:06 2014 -0400 @@ -0,0 +1,5 @@ + + + $REPOSITORY_INSTALL_DIR + +