Mercurial > repos > bernhardlutz > rest_tool
changeset 5:1ad356686717 draft
Deleted selected files
author | bernhardlutz |
---|---|
date | Thu, 03 Apr 2014 06:50:50 -0400 |
parents | 54358dfa62c0 |
children | 9ee84d9fd3a7 |
files | readfile.py readfile.pyc rest_tool.py rest_tool.xml rest_tool_assay_by_activity_or_target.py rest_tool_comp_for_assay.py tool_dependencies.xml |
diffstat | 7 files changed, 0 insertions(+), 280 deletions(-) [+] |
line wrap: on
line diff
--- a/readfile.py Fri Mar 28 13:41:22 2014 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -#!/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() -
--- a/rest_tool.py Fri Mar 28 13:41:22 2014 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -#!/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 )
--- a/rest_tool.xml Fri Mar 28 13:41:22 2014 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,119 +0,0 @@ -<tool id="rest_tool" name="Fetch Data from pubchem" version="0.1.0"> - <description>Fetch pubchem data</description> - <version_command>echo "0.1.0"</version_command> - <requirements> - <requirement type="set_environment">REST_TOOL_SCRIPT_PATH</requirement> - </requirements> - <command interpreter="python"> - #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 - </command> - - <inputs> - <conditional name="choose_action"> - <param name="action" multiple="false" type="select" label="Choose action"> - <option value="specific_data">Get Data for specific Assay/Compound/Substance</option> - <option value="compounds_for_assay">Get all compound IDs to given BioAssays</option> - <option value="all_assay_with_compounds">Get all BioAssay IDs with Compound IDs</option> - <option value="assays_by_activity">Get BioAssays for activity</option> - <option value="assays_by_targets">Get BioAssays for targets</option> - </param> - <when value="specific_data"> - <param name="input_type" multiple="false" type="select" label="Input Type"> - <option value="assay">BioAssay</option> - <option value="compound">Compound</option> - <option value="substance">Substance</option> - </param> - <conditional name="field_or_file1"> - <param name="field_or_file1" multiple="false" type="select" label="Specify the ID by"> - <option value="field">Textfield</option> - <option value="file">File</option> - </param> - <when value="field"> - <param format="txt" name="id1" type="text" label="Enter the ID(s)" /> - </when> - <when value="file"> - <param format="txt,csv" name="file_ids_1" type="data" label="Give the file" /> - </when> - </conditional> - - <conditional name="operation_property"> - <param name="operation" type="select" multiple="false" label="Operation"> - <option value="synonyms">Synonyms</option> - <option value="cids">CIDs</option> - <option value="property">Property</option> - <option value="xrefs">XRefs</option> - <option value="description">Discription</option> - <option value="summary">Summary</option> - </param> - <when value="property"> - <param name="property" label="Specify Property" type="text" /> - </when> - </conditional> - - </when> - <when value="compounds_for_assay"> - <conditional name="field_or_file2"> - <param name="field_or_file2" multiple="false" type="select" label="Specify the ID by"> - <option value="field">Textfield</option> - <option value="file">File</option> - </param> - <when value="field"> - <param format="txt" name="id2" type="text" label="Enter the ID(s)" /> - </when> - <when value="file"> - <param format="txt,csv" name="file_ids_2" type="data" label="Give the file" /> - </when> - </conditional> - </when> - <when value="assays_by_activity"> - <param format="txt" name="activity" type="text" label="Enter the activity " /> - </when> - <when value="assays_by_targets"> - <param name="target_identifier_type" multiple="false" type="select" label="Choose target identifier"> - <option value="gi">GI</option> - <option value="geneid">Gene ID</option> - <option value="genesymbol">Gene Symbol</option> - </param> - <param format="txt" name="target_id" type="text" label="Enter the target" /> - </when> - - </conditional> - </inputs> - <outputs> - <data format="csv" name="output" /> - </outputs> - <tests> - </tests> - <help> -**What it does** - -This tool fetches data from pubchem - </help> -</tool>
--- a/rest_tool_assay_by_activity_or_target.py Fri Mar 28 13:41:22 2014 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -#!/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 )
--- a/rest_tool_comp_for_assay.py Fri Mar 28 13:41:22 2014 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -#!/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 )
--- a/tool_dependencies.xml Fri Mar 28 13:41:22 2014 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -<tool_dependency> - <set_environment version="1.0"> - <environment_variable name="REST_TOOL_SCRIPT_PATH" action="set_to">$REPOSITORY_INSTALL_DIR</environment_variable> - </set_environment> -</tool_dependency>