Mercurial > repos > bernhardlutz > rest_tool
changeset 7:35b41070c20d draft
Deleted selected files
author | bernhardlutz |
---|---|
date | Thu, 03 Apr 2014 06:51:54 -0400 |
parents | 9ee84d9fd3a7 |
children | 3c1e862e8cd6 |
files | rest_tool_alt.xml rest_tool_assays_with_cids_given_target.py |
diffstat | 2 files changed, 0 insertions(+), 249 deletions(-) [+] |
line wrap: on
line diff
--- a/rest_tool_alt.xml Thu Apr 03 06:50:57 2014 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,156 +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 a/some Assay/Compound/Substance</option> - <option value="compounds_for_assay">Get all compound IDs to given BioAssay IDs</option> - <option value="assays_by_activity">Get BioAssay IDs with compound IDs given activity/target</option> - </param> - <when value="specific_data"> - <conditional name="choose_acs"> - <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> - <when value="assay"> - <conditional name="field_or_file1"> - <param name="field_or_file1" multiple="false" type="select" label="Specify the ID by"> - <option value="field" selected="True">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="assay"> - <param format="txt,csv" name="file_ids_1" type="data" label="Give the file" /> - </when> - </conditional> - </when> - <when value="assay"> - <conditional name="operation_property"> - <param name="operation" type="select" multiple="false" label="Operation"> - <option value="cids">CIDs</option> - <option value="sids">SIDs</option> - <option value="record">Record</option> - <option value="classification">Classification</option> - <option value="property">Property</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="compound"> - <conditional name="operation_property"> - <param name="operation" type="select" multiple="false" label="Operation"> - <option value="aids">AIDs</option> - <option value="sids">SIDs</option> - <option value="assaysummary">Assaysummary</option> - <option value="synonyms">Synonyms</option> - <option value="record">Record</option> - <option value="classification">Classification</option> - <option value="property">Property</option> - <option value="description">Discription</option> - </param> - <when value="property"> - <param name="property" label="Specify Property" type="text" /> - </when> - </conditional> - </when> - <when value="substance"> - <conditional name="operation_property"> - <param name="operation" type="select" multiple="false" label="Operation"> - <option value="cids">CIDs</option> - <option value="sids">SIDs</option> - <option value="assaysummary">Assaysummary</option> - <option value="synonyms">Synonyms</option> - <option value="record">Record</option> - <option value="classification">Classification</option> - <option value="property">Property</option> - <option value="description">Discription</option> - </param> - <when value="property"> - <param name="property" label="Specify Property" type="text" /> - </when> - </conditional> - </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_assays_with_cids_given_target.py Thu Apr 03 06:50:57 2014 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,93 +0,0 @@ -#!/usr/bin/env python - - -import sys, os -import argparse -import readfile - -#get every aid as a list -#returns a dictionary with aid as key and as value the list of cids -def getAllAssayIDs(): - url="http://pubchem.ncbi.nlm.nih.gov/rest/pug/assay/type/all/aids/TXT" - data=readfile.getresult(url) - aidlist=readfile.getListFromString(data) - return aidlist - - -def getIDofLine(line): - arr=line.split(">") - if len(arr) > 1: - aid=arr[1].split("<")[0] - return aid - else: - return "-1" - -#get xml of all aids with cids for an activity -def getAllCidsForAssayActivity(activity): - url="http://pubchem.ncbi.nlm.nih.gov/rest/pug/assay/activity/"+activity+"/aids/txt?list_return=listkey" - listkey=readfile.getresult(url) -# url="http://pubchem.ncbi.nlm.nih.gov/rest/pug/assay/listkey/"+listkey+"/cids/xml" - url="http://pubchem.ncbi.nlm.nih.gov/rest/pug/assay/aid/25425,12345/cids/xml" - print("url: "+url) - xml=readfile.getresult(url) - - #init parser - handler = DictHandler() - parser = sax.make_parser() - parser.setContentHandler(handler) - - tempfile=open("tempfile","w") - #handle the last line, there is sometimes some random output - lastline_arr=xml.split("\n") - #print(lastline_arr) - - print("l: ") - print(len(lastline_arr)) - lastline=lastline_arr[len(lastline_arr)-1] - print("lastline: "+lastline) - print("lastline-2: "+lastline_arr[len(lastline_arr)-2]) - cidlastline=getIDofLine(lastline) - aidkey="-1" - if cidlastline != "-1": - i=len(lastline_arr)-2 - #search for nex aid entry - while i >= 0 and "AID" not in lastline_arr[i]: - i-=1 - if i >= 0: - aid=getIDofLine(lastline_arr[i]) - if aid != "-1": - aidkey=aid - #remove the last line and put the array back together - - lastline_arr_list=list(lastline_arr) - #lastline_arr_list.remove(lastline) - xml2="\n".join(lastline_arr_list) - tempfile.write(xml2) - #add the last tags - #tempfile.write("</Information></InformationList>") - tempfile.close() - parser.parse(open("tempfile","r")) - dic=handler.ergebnis - - #add the last line - #if cidlastline != "-1": - # dic[aidkey].append(cidlastline) - return dic - - -def main(args): - aid_cid_dict=getAllCidsForAssayActivity(args.target) - write_to_csv(aid_cid_dict, args.outfile) - -if __name__ == "__main__": - parser = argparse.ArgumentParser() - parser.add_argument('--outfile', type=argparse.FileType('w'), - help="Specify output file") - parser.add_argument('--target', type=str, - help="Specify output file") - if len(sys.argv) < 2: - print "Too few arguments..." - parser.print_help() - exit(1) - args = parser.parse_args() - main( args )