changeset 6:9ee84d9fd3a7 draft

Uploaded
author bernhardlutz
date Thu, 03 Apr 2014 06:50:57 -0400
parents 1ad356686717
children 35b41070c20d
files readfile.py readfile.pyc rest_tool.py rest_tool.xml rest_tool_alt.xml rest_tool_assay_by_activity_or_target.py rest_tool_assays_with_cids_given_target.py rest_tool_comp_for_assay.py rest_tool_functions.py rest_tool_macros.xml rest_tool_search.py tool_dependencies.xml
diffstat 12 files changed, 846 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/readfile.py	Thu Apr 03 06:50:57 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()
+        
Binary file readfile.pyc has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rest_tool.py	Thu Apr 03 06:50:57 2014 -0400
@@ -0,0 +1,61 @@
+#!/usr/bin/env python
+
+import sys, os
+import argparse
+
+import readfile
+
+txt_output=["cids", "aids", "sids", "synonyms" ]
+csv_output=["assaysummary"]
+check_for_id_type=["cids", "aids", "sids"]
+
+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.id_file is None:
+        idstring=str(args.id)
+    else:
+        idlist=readfile.getListFromFile(args.id_file)
+        idstring=",".join(idlist)
+    url+=idstring+"/"+args.operation+"/"
+    if args.operation in csv_output:
+        url+="csv"
+    elif args.operation in txt_output:
+        url+="txt"
+    else:
+        url+="xml"
+    if args.operation in check_for_id_type and not args.id_type is None:
+        url+="?"+args.operation+"_type="+args.id_type
+    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, required=True,
+        help="That you want BioAssay Compund ...")
+    parser.add_argument('--id', type=str,
+        help="Specify the ID")
+    parser.add_argument('--operation', type=str, required=True,
+        help="Specify the operation")
+    parser.add_argument('--property-value', dest="property_value", type=str,
+        help="Specify the property")
+    parser.add_argument('--id-type', dest="id_type", type=str,
+        help="Specify the property")
+    parser.add_argument('--outfile', type=argparse.FileType('w'), required=True,
+        help="Specify one output file")
+    parser.add_argument('--id-file', dest="id_file", 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 )
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rest_tool.xml	Thu Apr 03 06:50:57 2014 -0400
@@ -0,0 +1,256 @@
+<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>
+    <macros>
+        <import>rest_tool_macros.xml</import>
+    </macros>
+    <command interpreter="python">
+        #if $choose_action.action == 'search':
+        rest_tool_search.py --type $choose_action.input_type_search --name $choose_action.search_name --outfile $output
+        
+        #elif $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:
+            --id-file $choose_action.field_or_file1.file_ids_1
+            #end if
+            --type $choose_action.choose_acs.input_type
+            
+            #if $choose_action.choose_acs.input_type == 'assay':
+            --operation $choose_action.choose_acs.operation_assay.operation_assay
+                #if $choose_action.choose_acs.operation_assay.operation_assay == 'property':
+                    --property-value $choose_action.choose_acs.operation_assay.property_assay
+                #elif $choose_action.choose_acs.operation_assay.operation_assay == 'aids':
+                    --id-type $choose_action.choose_acs.operation_assay.aids_type_assay
+                #elif $choose_action.choose_acs.operation_assay.operation_assay == 'cids':
+                    --id-type $choose_action.choose_acs.operation_assay.cids_type_assay
+                #elif $choose_action.choose_acs.operation_assay.operation_assay == 'sids':
+                    --id-type $choose_action.choose_acs.operation_assay.sids_type_assay
+                #end if
+            #elif $choose_action.choose_acs.input_type == 'compound':
+            --operation $choose_action.choose_acs.operation_compound.operation_compound
+                #if $choose_action.choose_acs.operation_compound.operation_compound == 'property':
+                    --property-value $choose_action.choose_acs.operation_compound.property_compound
+                #elif $choose_action.choose_acs.operation_compound.operation_compound == 'aids':
+                    --id-type $choose_action.choose_acs.operation_compound.aids_type_compound
+                #elif $choose_action.choose_acs.operation_compound.operation_compound == 'cids':
+                    --id-type $choose_action.choose_acs.operation_compound.cids_type_compound
+                #elif $choose_action.choose_acs.operation_compound.operation_compound == 'sids':
+                    --id-type $choose_action.choose_acs.operation_compound.sids_type_compound
+                #end if
+            #else:
+            --operation $choose_action.choose_acs.operation_substance.operation_substance
+                #if $choose_action.choose_acs.operation_substance.operation_substance == 'property':
+                    --property-value $choose_action.choose_acs.operation_substance.property_substance
+                #elif $choose_action.choose_acs.operation_substance.operation_substance == 'aids':
+                    --id-type $choose_action.choose_acs.operation_substance.aids_type_substance
+                #elif $choose_action.choose_acs.operation_substance.operation_substance == 'cids':
+                    --id-type $choose_action.choose_acs.operation_substance.cids_type_substance
+                #elif $choose_action.choose_acs.operation_substance.operation_substance == 'sids':
+                    --id-type $choose_action.choose_acs.operation_substance.sids_type_substance
+                #end if
+            #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:
+            --aid-file $choose_action.field_or_file2.file_ids_2
+            #end if
+            --outfile $output
+        #elif $choose_action.action == 'assays_by_activity_or_target':
+            rest_tool_assay_by_activity_or_target.py
+            #if $choose_action.activity_or_target.activity_or_target == 'activity':
+                --activity $choose_action.activity_or_target.activity
+            #else:
+                --target $choose_action.activity_or_target.target_id
+                --target-type $choose_action.activity_or_target.target_identifier_type
+            #end if
+            --outfile $output
+
+        #end if
+    </command>
+
+    <inputs>
+        <conditional name="choose_action">
+            <param name="action" multiple="false" type="select" label="Choose action">
+                <option value="search">Search for Assay/Compound/Substance</option>
+                <option value="specific_data">Get Data for specific Assay/Compound/Substance</option>
+                <option value="compounds_for_assay">Get all compound IDs given BioAssay IDs</option>
+                <option value="assays_by_activity_or_target">Get BioAssay IDs given activity/target</option>
+            </param>
+            <when value="search">
+                    <param name="input_type_search" multiple="false" type="select" label="Search for">
+                        <option value="assay">BioAssay</option>
+                        <option value="compound">Compound</option>
+                        <option value="substance">Substance</option>
+                    </param>
+                    <param name="input_type" multiple="false" type="select" label="Search By">
+                        <option value="name">Name</option>
+                    </param>
+                    <param format="txt" name="search_name" type="text" label="Enter the Name" />
+            </when>
+            <when value="specific_data">
+                <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="file">
+                            <param format="txt,csv" name="file_ids_1" type="data" label="Give the file" />
+                        </when>
+                </conditional>
+                <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="operation_assay">
+                            <param name="operation_assay" type="select" multiple="false" label="Operation">
+                                <expand macro="aid_cid_sid" />
+                                <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_assay" label="Specify Property" type="text" />
+                            </when>
+                            <when value="aids">
+                                <param name="aids_type_assay" multiple="false" type="select" label="AID Type">
+                                    <expand macro="aids_when_options" />
+                                </param>
+                            </when>
+                            <when value="cids">
+                                <param name="cids_type_assay" multiple="false" type="select" label="CID Type">
+                                    <expand macro="aids_when_options" />
+                                    
+                                </param>
+                            </when>
+                            <when value="sids">
+                                <param name="sids_type_assay" multiple="false" type="select" label="SID Type">
+                                    <expand macro="aids_when_options" />
+                                    <option value="doseresponse">doseresponse</option>
+                                </param>
+                            </when>
+                        </conditional>
+                    </when>
+                    <when value="compound">
+                        <conditional name="operation_compound">
+                            <param name="operation_compound" type="select" multiple="false" label="Operation">
+                                <expand macro="aid_cid_sid" />
+                                <expand macro="option_compound_substance" />
+                                <option value="property">Property</option>
+                            </param>
+                            <when value="property">
+                                <param name="property_compound" label="Specify Property" type="text" />
+                            </when>
+                            <when value="aids">
+                                <param name="aids_type_compound" multiple="false" type="select" label="AID Type">
+                                    <expand macro="aids_when_options" />
+                                </param>
+                            </when>
+                            <when value="sids">
+                                <param name="sids_type_compound" multiple="false" type="select" label="SID Type">
+
+                                    <expand macro="cid_sid_type_options" />
+                                </param>
+                            </when>
+                            <when value="cids">
+                                <param name="cids_type_compound" multiple="false" type="select" label="CID Type">
+                                    <expand macro="cid_cid_type_options" />
+                                </param>
+                            </when>
+                        </conditional>
+                    </when>
+                    <when value="substance">
+                        <conditional name="operation_substance">
+                            <param name="operation_substance" type="select" multiple="false" label="Operation">
+                                <expand macro="aid_cid_sid" />
+                                <expand macro="option_compound_substance" />
+                            </param>
+                            <when value="property">
+                                <param name="property_substance" label="Specify Property" type="text" />
+                            </when>
+                            <when value="aids">
+                                <param name="aids_type_substance" multiple="false" type="select" label="AID Type">
+                                    <expand macro="aids_when_options" />
+                                </param>
+                            </when>
+                            <when value="cids">
+                                <param name="cids_type_substance" multiple="false" type="select" label="CID Type">
+                                    <expand macro="sid_cid_type_options" />
+                                </param>
+                            </when>
+                            <when value="sids">
+                                <param name="sids_type_substance" multiple="false" type="select" label="SID Type">
+                                    <expand macro="sid_sid_type_options" />
+                                </param>
+                            </when>
+                            
+                        </conditional>
+                    </when>
+                </conditional>
+            </when>
+            <!-- second option -->
+            <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>
+            <!-- third option -->
+            <when value="assays_by_activity_or_target">
+                <conditional name="activity_or_target">
+                    <param name="activity_or_target" multiple="false" type="select" label="Look for">
+                        <option value="target">Target</option>
+                        <option value="activity">Activity</option>
+                    </param>
+                    <when value="activity">
+                        <param format="txt" name="activity" type="text" label="Enter the activity" />
+                    </when>
+            
+                    <when value="target">
+                        <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>
+            </when>
+            
+        </conditional>
+    </inputs>
+    <outputs>
+        <data format="csv" name="output" />
+    </outputs>
+    <tests>
+    </tests>
+    <help>
+**What it does**
+
+This tool fetches data from pubchem
+    </help>
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rest_tool_alt.xml	Thu Apr 03 06:50:57 2014 -0400
@@ -0,0 +1,156 @@
+<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>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rest_tool_assay_by_activity_or_target.py	Thu Apr 03 06:50:57 2014 -0400
@@ -0,0 +1,36 @@
+#!/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/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('--target-type', dest="target_type", type=str,
+        help="The target identifier type")
+    parser.add_argument('--target-id', dest="target_id", type=str,
+        help="The specific target")
+    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 )
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rest_tool_assays_with_cids_given_target.py	Thu Apr 03 06:50:57 2014 -0400
@@ -0,0 +1,93 @@
+#!/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 )
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rest_tool_comp_for_assay.py	Thu Apr 03 06:50:57 2014 -0400
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+
+import sys, os
+import argparse
+import tempfile
+import readfile
+import rest_tool_functions
+
+        
+#get the cids for bioassay aid
+def get_aid_cid_dict_for_list(aidlist):
+    aidliststring=",".join(aidlist)
+    url="http://pubchem.ncbi.nlm.nih.gov/rest/pug/assay/aid/"+aidliststring+"/cids/xml"
+    xml=readfile.getresult(url)
+    tmp = tempfile.TemporaryFile() 
+    tmp.write(xml)
+    tmp.seek(0)
+    dic=rest_tool_functions.give_aid_cid_dict_from_xml(tmp)
+    tmp.close()
+    return dic
+        
+def main(args):
+    if args.aid_file is None:
+        aidlist=args.aid.split(",")
+    else:
+        aidlist=readfile.getListFromFile(args.aid_file)
+    dic=get_aid_cid_dict_for_list(aidlist)
+    rest_tool_functions.write_to_csv(dic, args.outfile)
+    
+    
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser()
+    parser.add_argument('--aid', type=str,
+        help="AIDs of the BioAssay")
+    parser.add_argument('--aid-file', dest="aid_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 )
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rest_tool_functions.py	Thu Apr 03 06:50:57 2014 -0400
@@ -0,0 +1,74 @@
+#!/usr/bin/env python
+
+
+import sys, os
+import argparse
+import urllib2, urllib, httplib
+import readfile
+import xml.sax as sax
+
+class DictHandler(sax.handler.ContentHandler):
+
+    def __init__(self): 
+        self.ergebnis = {} 
+        self.schluessel = "" 
+        self.wert = "" 
+        self.aktiv = None 
+
+    def startElement(self, name, attrs): 
+        if name == "Information": 
+            self.schluessel = "" 
+            self.wert = "" 
+        elif name == "AID" or name=="CID": 
+            self.aktiv = name 
+
+    def endElement(self, name): 
+        if name == "AID":
+            self.schluessel=self.schluessel.strip()
+            self.ergebnis[self.schluessel]=[]
+            #print("huhn")
+            self.aktiv=None
+        elif name == "CID": 
+            self.aktiv = None
+            self.ergebnis[self.schluessel].append(self.wert)
+            self.wert=""
+    def characters(self, content): 
+        if self.aktiv == "AID": 
+            self.schluessel += content 
+        elif self.aktiv == "CID":
+            self.wert += content
+            
+
+def give_aid_cid_dict_from_xml(xmlfile):
+    handler = DictHandler() 
+    parser = sax.make_parser() 
+    parser.setContentHandler(handler)
+    parser.parse(xmlfile)
+    dic=handler.ergebnis
+    return dic
+    
+#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"
+
+def write_to_csv(aid_cid_dict, outfile):
+    for key in aid_cid_dict:
+        for cid in aid_cid_dict[key]:
+            outfile.write(key)
+            outfile.write(",")
+            outfile.write(cid)
+            outfile.write("\n")
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rest_tool_macros.xml	Thu Apr 03 06:50:57 2014 -0400
@@ -0,0 +1,66 @@
+<macros>
+    <xml name="aid_cid_sid">
+        <option value="aids">AIDs</option>
+        <option value="cids">CIDs</option>
+        <option value="sids">SIDs</option>
+    </xml>
+    
+    <xml name="cid_sid_type_options">
+        <option value="all">all</option>
+        <option value="standardized">standardized</option>
+        <option value="component">component</option>
+    </xml>
+    <xml name="cid_cid_type_options">
+        <option value="original">original</option>
+        <option value="parent">parent</option>
+        <option value="component">component</option>
+        <option value="similar_2d">similar_2d</option>
+        <option value="similar_3d">similar_3d</option>
+        <option value="same_stereo">same_stereo</option>
+        <option value="same_isotopes">same_isotopes</option>
+        <option value="same_connectivity">same_connectivity</option>
+        <option value="same_tautomer">same_tautomer</option>
+        <option value="same_parent">same_parent</option>
+        <option value="same_parent_stereo">same_parent_stereo</option>
+        <option value="same_parent_isotopes">same_parent_isotopes</option>
+        <option value="same_parent_connectivity">same_parent_connectivity</option>
+        <option value="same_parent_tautomer">same_parent_tautomer</option>
+    </xml>
+    <xml name="sid_cid_type_options">
+        <option value="all">all</option>
+        <option value="standardized">standardized</option>
+        <option value="component">component</option>
+    </xml>
+    <xml name="sid_sid_type_options">
+        <option value="original">original</option>
+        <option value="similar_2d">similar_2d</option>
+        <option value="similar_3d">similar_3d</option>
+        <option value="same_exact">same_exact</option>
+        <option value="same_stereo">same_stereo</option>
+        <option value="same_isotopes">same_isotopes</option>
+        <option value="same_connectivity">same_connectivity</option>
+        <option value="same_tautomer">same_tautomer</option>
+        <option value="same_parent">same_parent</option>
+        <option value="same_parent_stereo">same_parent_stereo</option>
+        <option value="same_parent_isotopes">same_parent_isotopes</option>
+        <option value="same_parent_connectivity">same_parent_connectivity</option>
+        <option value="same_parent_tautomer">same_parent_tautomer</option>
+    </xml>
+    <xml name="aids_when_options">
+
+                <option value="all" selected="True">all</option>
+                <option value="active">active</option>
+                <option value="inactive">inactive</option>
+    </xml>
+    <xml name="option_compound_substance">
+        <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>
+    </xml>
+    
+
+ 
+</macros>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rest_tool_search.py	Thu Apr 03 06:50:57 2014 -0400
@@ -0,0 +1,36 @@
+#!/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 )
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tool_dependencies.xml	Thu Apr 03 06:50:57 2014 -0400
@@ -0,0 +1,5 @@
+<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>