# HG changeset patch # User bernhardlutz # Date 1396028482 14400 # Node ID 54358dfa62c0d7c8af2f0a57555fd34d02685162 # Parent 0bbb107a2cf2e3b35869d3b1e8e679cc6e5a1e27 Uploaded diff -r 0bbb107a2cf2 -r 54358dfa62c0 readfile.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/readfile.py Fri Mar 28 13:41:22 2014 -0400 @@ -0,0 +1,19 @@ +#!/usr/bin/env python + +import io +import urllib2, urllib, httplib +def getListFromFile(file): + idlist=[] + for line in file: + if int(line): + idlist.append(line.strip()) + return idlist + +def getresult(url): + try: + connection = urllib2.urlopen(url) + except urllib2.HTTPError, e: + return "" + else: + return connection.read().rstrip() + diff -r 0bbb107a2cf2 -r 54358dfa62c0 readfile.pyc Binary file readfile.pyc has changed diff -r 0bbb107a2cf2 -r 54358dfa62c0 rest_tool.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rest_tool.py Fri Mar 28 13:41:22 2014 -0400 @@ -0,0 +1,54 @@ +#!/usr/bin/env python +# Aufruf convert_graph.py --type type --operation op --id id --outfile outfile + +import sys, os +import argparse + +import readfile + +txt_output=["cids", "summary", "synonyms" ] + +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/" + elif args.type == "substance": + url+="sid/" + if args.idfile is None: + idstring=str(args.id) + else: + idlist=readfile.getListFromFile(args.idfile) + idstring=",".join(idlist) + url+=idstring+"/"+args.operation+"/" + if args.operation in txt_output: + url+="txt" + else: + url+="csv" + print(url) + data=readfile.getresult(url) + outfile=args.outfile + outfile.write(data) + outfile.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('--outfile', type=argparse.FileType('w'), + help="Specify one output file") + parser.add_argument('--idfile', type=argparse.FileType('r'), + help="Specify a file with a list of ids, one per line") + if len(sys.argv) < 8: + print "Too few arguments..." + parser.print_help() + exit(1) + args = parser.parse_args() + main( args ) diff -r 0bbb107a2cf2 -r 54358dfa62c0 rest_tool.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rest_tool.xml Fri Mar 28 13:41:22 2014 -0400 @@ -0,0 +1,119 @@ + + Fetch pubchem data + echo "0.1.0" + + REST_TOOL_SCRIPT_PATH + + + #if $choose_action.action == 'specific_data': + rest_tool.py + #if $choose_action.field_or_file1.field_or_file1 == 'field': + --id $choose_action.field_or_file1.id1 + #else: + --idfile $choose_action.field_or_file1.file_ids_1 + #end if + --type $choose_action.input_type + + --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 + #if $choose_action.field_or_file2.field_or_file2 == 'field': + --aid $choose_action.field_or_file2.id2 + #else: + --aidfile $choose_action.field_or_file2.file_ids_2 + #end if + --outfile $output + #elif $choose_action.action == 'assays_by_activity': + rest_tool_assay_by_activity_or_target.py --activity $choose_action.activity --outfile $output + #elif $choose_action.action == 'assays_by_targets': + rest_tool_assay_by_activity_or_target.py --targettype $choose_action.target_identifier_type --targetid $choose_action.target_id --outfile $output + #end if + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +**What it does** + +This tool fetches data from pubchem + + diff -r 0bbb107a2cf2 -r 54358dfa62c0 rest_tool_assay_by_activity_or_target.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rest_tool_assay_by_activity_or_target.py Fri Mar 28 13:41:22 2014 -0400 @@ -0,0 +1,39 @@ +#!/usr/bin/env python +# Aufruf convert_graph.py --aid list of ids --aid-from-file file + +import sys, os +import argparse + + +import readfile + +def main(args): + #search for acitivity or target + url="http://pubchem.ncbi.nlm.nih.gov/rest/pug/assay/" + if args.activity is None: + #target + url+="target/"+args.targettype+"/"+args.targetid + else: + url+="activity/"+args.activity + url+="/aids/txt" + data=readfile.getresult(url) + args.outfile.write(data) + args.outfile.close() + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument('--activity', type=str, + help="Activities you are looking for") + parser.add_argument('--targettype', type=str, + help="The target identifier type") + parser.add_argument('--targetid', type=str, + help="The specific target") + 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 0bbb107a2cf2 -r 54358dfa62c0 rest_tool_comp_for_assay.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rest_tool_comp_for_assay.py Fri Mar 28 13:41:22 2014 -0400 @@ -0,0 +1,44 @@ +#!/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 + +import readfile +#supported graph_types +#output_types = ["tsv", "csv", "png", "json", "txt", "xml", "sdf", "asnt", "asnb", "jsonp"] + + +#get the cids for bioassay aid +def getCompoundList(aidlist): + aidliststring=",".join(aidlist) + url="http://pubchem.ncbi.nlm.nih.gov/rest/pug/assay/aid/"+aidliststring+"/cids/txt" + data=readfile.getresult(url) + return data + +def main(args): + if args.aidfile is None: + aidlist=args.aid.split(",") + else: + aidlist=readfile.getListFromFile(args.aidfile) + cids=getCompoundList(aidlist) + 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('--aidfile', 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 0bbb107a2cf2 -r 54358dfa62c0 tool_dependencies.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tool_dependencies.xml Fri Mar 28 13:41:22 2014 -0400 @@ -0,0 +1,5 @@ + + + $REPOSITORY_INSTALL_DIR + +