# HG changeset patch # User bernhardlutz # Date 1399068996 14400 # Node ID 80bf0039c0dce0da58603726263d2b510e64b8d9 # Parent 3c1e862e8cd68fe471633da361a704dcbf58e99f Uploaded diff -r 3c1e862e8cd6 -r 80bf0039c0dc readfile.py --- a/readfile.py Fri May 02 05:40:28 2014 -0400 +++ b/readfile.py Fri May 02 18:16:36 2014 -0400 @@ -17,7 +17,16 @@ else: return connection.read().rstrip() -def store_result(url, outfile): +def store_result_get(url, outfile): data=getresult(url) outfile.write(data) outfile.close() + +def store_result_post(url, post, outfile): + data = urllib.urlencode(post) + headers={"Content-Type" : "application/x-www-form-urlencoded"} + req = urllib2.Request(url, data, headers) + response = urllib2.urlopen(req) + the_page = response.read() + outfile.write(the_page) + outfile.close() diff -r 3c1e862e8cd6 -r 80bf0039c0dc rest_tool.xml --- a/rest_tool.xml Fri May 02 05:40:28 2014 -0400 +++ b/rest_tool.xml Fri May 02 18:16:36 2014 -0400 @@ -68,7 +68,7 @@ --id-type-ff $choose_action.input_type.namespace_id.field_or_file.field_or_file_select --id-value $choose_action.input_type.namespace_id.field_or_file.id_value #elif $choose_action.input_type.namespace_id.namespace_id_select == 'target': - --id-value $choose_action.input_type.namespace_id.target_select + --id-value $choose_action.input_type.namespace_id.target_select"/"$choose_action.input_type.namespace_id.target_value #elif $choose_action.input_type.namespace_id.namespace_id_select == 'type': --id-value $choose_action.input_type.namespace_id.type_select #elif $choose_action.input_type.namespace_id.namespace_id_select == 'activity': @@ -81,6 +81,10 @@ --operation-value $choose_action.input_type.operation_assay.operation_assay_select.property_assay #elif $choose_action.input_type.operation_assay.operation_assay_select == 'target': --operation-value $choose_action.input_type.operation_assay.operation_assay_select.target_assay + #elif $choose_action.input_type.operation_assay.operation_assay_select == 'xrefs': + --operation-value $choose_action.input_type.operation_assay.xref_operation + #elif $choose_action.input_type.operation_assay.operation_assay_select == 'doseresponse': + --sid-filter $choose_action.input_type.operation_assay.doseresponse_sids #elif $choose_action.input_type.operation_assay.operation_assay_select == 'aids' or $choose_action.input_type.operation_assay.operation_assay_select == 'cids' or $choose_action.input_type.operation_assay.operation_assay_select == 'sids': --ids-operation-type $choose_action.input_type.operation_assay.ids_type_assay #end if @@ -97,7 +101,7 @@ #if $choose_action.input_type.operation_compound.operation_compound_select == 'property': --operation-value $choose_action.input_type.operation_compound.property_compound #elif $choose_action.input_type.operation_compound.operation_compound_select == 'xrefs': - --operation-value $choose_action.input_type.operation_compound.xref_compound + --operation-value $choose_action.input_type.operation_compound.xref_operation #elif $choose_action.input_type.operation_compound.operation_compound_select == 'aids' or $choose_action.input_type.operation_compound.operation_compound_select == 'cids' or $choose_action.input_type.operation_compound.operation_compound_select == 'sids': --ids-operation-type $choose_action.input_type.operation_compound.ids_type_compound #end if @@ -114,7 +118,7 @@ #if $choose_action.input_type.operation_substance.operation_substance_select == 'property': --operation-value $choose_action.input_type.operation_substance.operation_substance_select.property_substance #elif $choose_action.input_type.operation_substance.operation_substance_select == 'xref': - --operation-value $choose_action.input_type.operation_substance.xref_substance + --operation-value $choose_action.input_type.operation_substance.xref_operation #elif $choose_action.input_type.operation_substance.operation_substance_select == 'aids' or $choose_action.input_type.operation_substance.operation_substance_select == 'cids' or $choose_action.input_type.operation_substance.operation_substance_select == 'sids': --ids-operation-type $choose_action.input_type.operation_substance.ids_type_substance #end if @@ -188,9 +192,78 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + **What it does** diff -r 3c1e862e8cd6 -r 80bf0039c0dc rest_tool_advanced.py --- a/rest_tool_advanced.py Fri May 02 05:40:28 2014 -0400 +++ b/rest_tool_advanced.py Fri May 02 18:16:36 2014 -0400 @@ -7,11 +7,13 @@ #dicitionary for the output format -dict_output={"cids" :"txt", "aids" : "txt", "sids" : "txt", "description": "xml", "summary" : "xml", "record" : "csv", "classification": "xml", "targets" : "txt", "xrefs" : "txt", "synonyms" : "txt", "property": "csv" } +dict_output={"cids" :"txt", "aids" : "txt", "sids" : "txt", "description": "xml", "summary" : "xml", "record" : "csv", "classification": "xml", "targets" : "txt", "xrefs" : "txt", "synonyms" : "txt", "property": "csv", "doseresponse" : "csv" } #alles andere ist xml check_for_id_type=["cids", "aids", "sids"] +post_id_types=["inchi", "sdf", "smiles"] + id_dict={"compound": "cid", "assay": "aid", "substance" : "sid" } def getListString(args): @@ -19,31 +21,43 @@ #build comma list list_string=",".join(getListFromFile(open(args.id_value,"r"))) else: - list_string=args.id_value + print (args.id_value) + list_string=args.id_value.strip().replace("__cr____cn__", ",") return list_string - + def main(args): - url="http://pubchem.ncbi.nlm.nih.gov/rest/pug/"+args.type+"/" url+=args.id_type+"/" - if args.id_type ==id_dict[args.type]: - url+=getListString(args)+"/" - else: - url+=args.id_value+"/" + # check if we are post then skip this part otherwise put the ids in the url + if not args.id_type in post_id_types: + if args.id_type ==id_dict[args.type]: + url+=getListString(args)+"/" + else: + url+=args.id_value+"/" + url+=args.operation+"/" if args.operation == "target" or args.operation == "property" or args.operation == "xrefs": url+=args.operation_value+"/" - url+=dict_output[args.operation] - if args.operation in check_for_id_type: - url+="?"+args.operation+"_type="+args.ids_operation_type + if args.operation == "xrefs": + if "," in args.operation_value: + url+="xml" + else: + url+="txt" + else: + url+=dict_output[args.operation] + if args.operation in check_for_id_type and args.id_type not in post_id_types: + url+="?%s_type=%s" % (args.operation, args.ids_operation_type) print(url) - readfile.store_result(url, args.outfile) - - - - + if args.id_type in post_id_types: + postfile=open(args.id_value,"r") + post_value=postfile.read() + post_dict={args.id_type : post_value} + print(post_dict) + readfile.store_result_post(url, post_dict, args.outfile) + else: + readfile.store_result_get(url, args.outfile) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('--type', type=str, required=True, diff -r 3c1e862e8cd6 -r 80bf0039c0dc rest_tool_macro_advanced.xml --- a/rest_tool_macro_advanced.xml Fri May 02 05:40:28 2014 -0400 +++ b/rest_tool_macro_advanced.xml Fri May 02 18:16:36 2014 -0400 @@ -33,6 +33,8 @@ + + diff -r 3c1e862e8cd6 -r 80bf0039c0dc rest_tool_macros.xml --- a/rest_tool_macros.xml Fri May 02 05:40:28 2014 -0400 +++ b/rest_tool_macros.xml Fri May 02 18:16:36 2014 -0400 @@ -155,7 +155,7 @@ - + @@ -184,11 +184,17 @@ + - + + + + + + @@ -226,7 +232,7 @@ - + diff -r 3c1e862e8cd6 -r 80bf0039c0dc rest_tool_search.py --- a/rest_tool_search.py Fri May 02 05:40:28 2014 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -#!/usr/bin/env python - -import sys, os -import argparse -import readfile - -def main(args): - #search for acitivity or target - url="http://pubchem.ncbi.nlm.nih.gov/rest/pug/"+args.type+"/name/"+args.name - if args.type == "assay": - url+="/aids" - elif args.type == "compound": - url+="/cids" - else: - url+="/sids" - url+="/txt" - #print("url: "+url) - data=readfile.getresult(url) - args.outfile.write(data) - args.outfile.close() - - -if __name__ == "__main__": - parser = argparse.ArgumentParser() - parser.add_argument('--name', type=str, required=True, - help="Enter the name") - parser.add_argument('--type', type=str, required=True, - help="What you want to search for") - parser.add_argument('--outfile', type=argparse.FileType('w'), required=True, - 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 3c1e862e8cd6 -r 80bf0039c0dc test-data/empty-file diff -r 3c1e862e8cd6 -r 80bf0039c0dc test-data/postfile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/postfile Fri May 02 18:16:36 2014 -0400 @@ -0,0 +1,2 @@ +InChI=1S/C3H8/c1-3-2/h3H2,1-2H3 + diff -r 3c1e862e8cd6 -r 80bf0039c0dc tool_dependencies.xml --- a/tool_dependencies.xml Fri May 02 05:40:28 2014 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ - - - $REPOSITORY_INSTALL_DIR - -