Next changeset 1:35cd50b8ccf2 (2018-02-16) |
Commit message:
planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty |
added:
README.rst reactome_analysis.py reactome_analysis.xml template.html test-data/UnipIDs.txt test-data/reactome_invalide_ids.txt test-data/reactome_output.html |
b |
diff -r 000000000000 -r 216bd2a75b1d README.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.rst Sun Nov 26 19:29:17 2017 -0500 |
b |
@@ -0,0 +1,20 @@ +Wrapper for Reactome web service +================================ + +Reactome web service (https://reactome.org) + +**Galaxy integration** + +T.P. Lien Nguyen, Florence Combes, Yves Vandenbrouck CEA, INSERM, CNRS, Grenoble-Alpes University, BIG Institute, FR + +Sandra Dérozier, Olivier Rué, Christophe Caron, Valentin Loux INRA, Paris-Saclay University, MAIAGE Unit,Migale Bioinformatics platform + +Contact support@proteore.org for any questions or concerns about the Galaxy implementation of this tool. + +================================ + +Reactome software provides service of creating diagram representing the relations between the biological processes. This tool allows linking to Reactome web service with pre-loaded data from a list of IDs, a file containing IDs or from a column of a complexed file. + +**For the rows that have more than 1 ID, only the first one is taken into account** + +**This tool only accepts letters (a-z or A-Z), numbers (0-9) and 3 characters "." "-" "_" for IDs. If there is ID containing other than these characters, it will be removed from the queue and placed in "Invalid identifiers" file** |
b |
diff -r 000000000000 -r 216bd2a75b1d reactome_analysis.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/reactome_analysis.py Sun Nov 26 19:29:17 2017 -0500 |
[ |
@@ -0,0 +1,99 @@ +import os +import re +import json +import argparse + +CURRENT_DIR = os.path.dirname(os.path.abspath(__file__)) + +def id_valid(identifiers): + """ + Validate IDs if they contain special characters + """ + res = [] + remove = [] + for id in identifiers: + id = id.split(";")[0] + if re.match("^[A-Za-z0-9_-]*$", id): + res.append(id) + else: + remove.append(id) + return res, remove + +def isnumber(format, n): + """ + Check if an variable is numeric + """ + float_format = re.compile("^[\-]?[1-9][0-9]*\.?[0-9]+$") + int_format = re.compile("^[\-]?[1-9][0-9]*$") + test = "" + if format == "int": + test = re.match(int_format, n) + elif format == "float": + test = re.match(float_format, n) + if test: + return True + else: + return False + +def data_json(identifiers): + """ + Submit IDs list to Reactome and return results in json format + Return error in HTML format if web service is not available + """ + trash = [] + if identifiers[1] == "list": + ids = "\n".join(id_valid(identifiers[0].split())[0]) + #print(ids) + #print("curl -H \"Content-Type: text/plain\" -d \"$(printf '%s')\" -X POST --url www.reactome.org/AnalysisService/identifiers/projection/\?pageSize\=1\&page\=1" % ids) + json_string = os.popen("curl -H \"Content-Type: text/plain\" -d \"$(printf '%s')\" -X POST --url www.reactome.org/AnalysisService/identifiers/projection/\?pageSize\=1\&page\=1" % ids).read() + if len(id_valid(identifiers[0].split())[1]) > 0: + trash = id_valid(identifiers[0].split())[1] + elif identifiers[1] == "file": + header = identifiers[2] + mq = open(identifiers[0]).readlines() + if isnumber("int", identifiers[3].replace("c", "")): + if header == "true": + idens = [x.split("\t")[int(identifiers[3].replace("c", ""))-1] for x in mq[1:]] + else: + idens = [x.split("\t")[int(identifiers[3].replace("c", ""))-1] for x in mq] + ids = "\n".join(id_valid(idens)[0]) + #print(ids) + #print("curl -H \"Content-Type: text/plain\" -d \"$(printf '%s')\" -X POST --url www.reactome.org/AnalysisService/identifiers/projection/\?pageSize\=1\&page\=1" % ids) + json_string = os.popen("curl -H \"Content-Type: text/plain\" -d \"$(printf '%s')\" -X POST --url www.reactome.org/AnalysisService/identifiers/projection/\?pageSize\=1\&page\=1" % ids).read() + if len(id_valid(idens)[1]) > 0: + trash = id_valid(idens)[1] + print(json_string) + return json_string, trash + +def write_output(filename, json_string, trash_file, trash): + """ + Replace json result in template and print to output + """ + template = open(os.path.join(CURRENT_DIR, "template.html")) + output = open(filename, "w") + try: + for line in template: + if "{token}" in line: + line = line.replace("{token}", json.loads(json_string)["summary"]["token"]) + output.write(line) + except ValueError: + output.write("An error occurred due to unavailability of Reactome web service. Please return later.") + template.close() + output.close() + + trash_out = open(trash_file, "w") + trash_out.write("\n".join(trash)) + trash_out.close() + +def options(): + parser = argparse.ArgumentParser() + argument = parser.add_argument("--json", nargs="+", required=True) + argument = parser.add_argument("--output", default="output.html") + argument = parser.add_argument("--trash", default="trash.txt") + args = parser.parse_args() + filename = args.output + json_string, trash = data_json(args.json) + write_output(filename, json_string, args.trash, trash) + +if __name__ == "__main__": + options() |
b |
diff -r 000000000000 -r 216bd2a75b1d reactome_analysis.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/reactome_analysis.xml Sun Nov 26 19:29:17 2017 -0500 |
[ |
@@ -0,0 +1,63 @@ +<tool id="reactome_analysis" name="Reactome Analysis Tools" version="0.1.0"> + <description>query Reactome with your IDs list + </description> + <requirements> + </requirements> + <stdio> + <exit_code range="1:" /> + </stdio> + <command><![CDATA[ + #if $opt.input == "text" + python $__tool_directory__/reactome_analysis.py --json "$opt.list" "list" --output "$output" --trash "$trash" + #else if $opt.input == "file" + python $__tool_directory__/reactome_analysis.py --json "$opt.file" "file" $opt.header $opt.ncol --output "$output" --trash "$trash" + #end if + + ]]></command> + <inputs> + <conditional name="opt"> + <param name="input" type="select" label="Input identifiers" multiple="False" > + <option value="text">Copy/paste your list of IDs </option> + <!--option value="file">Choose a single-column file </option--> + <option value="file">Choose a multiple-columns file </option> + </param> + <when value="text" > + <param name="list" type="text" label="Enter list of identifiers" /> + </when> + <!--when value="file" > + <param name="idfile" type="data" format="txt" label="Choose a single-column file" /> + </when--> + <when value="file" > + <param name="file" type="data" format="txt, tabular" label="Choose a multiple-columns file" help="Input file is a tab-delimited file containing different information of proteins, such as an output of MaxQuant software" /> + <param name="header" type="boolean" checked="true" truevalue="true" falsevalue="false" label="Does your input file contain header?" /> + <param type="text" name="ncol" value="c1" label="Please specify the column where you would like to apply the comparison" help ='For example, fill in "c1" if you want to filter the first column' /> + </when> + + </conditional> + </inputs> + <outputs> + <data name="output" format="html" label="" /> + <data name="trash" format="tabular" label="Invalid identifiers" /> + </outputs> + <tests> + <test> + <conditional name="opt" > + <param name="input" value="mq" /> + <param name="file" value="UnipIDs.txt" /> + <param name="header" value="false" /> + <param name="ncol" value="c1" /> + </conditional> + <output name="output" file="reactome_output.html" ftype="html" /> + <output name="trash" file="reactome_invalide_ids.txt" ftype="tab" /> + </test> + </tests> + <help><![CDATA[ +Reactome software provides service of creating diagram representing the relations between the biological processes. This tool allows linking to Reactome web service with pre-loaded data from a list of IDs, a file containing IDs or from a column of a complexed file. + +**For the rows that have more than 1 ID, only the first one is taken into account** + +**This tool only accepts letters (a-z or A-Z), numbers (0-9) and 3 characters "." "-" "_" for IDs. If there is ID containing other than these characters, it will be removed from the queue and placed in "Invalid identifiers" file** + ]]></help> + <citations> + </citations> +</tool> |
b |
diff -r 000000000000 -r 216bd2a75b1d template.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/template.html Sun Nov 26 19:29:17 2017 -0500 |
b |
@@ -0,0 +1,48 @@ +<html> + + <head> + + <title>Connection to the Reactome Analysis Service</title> + + <style> + body { + margin: 40px; + background-color: #ffffff; + text-align: center; + } + h1 { + color: #19334d; + } + p { + margin-top: 40px; + } + button { + background-color: #ccddff; + border: 2px solid #19334d; + border-radius: 4px; + color: black; + padding: 16px 32px; + margin: 4px 2px; + cursor: pointer; + } + </style> + + </head> + + <body> + + <h1>Connection to the Reactome Analysis Service</h1> + + <p>Please click the button to execute the analysis:</p> + + <form action="http://www.reactome.org/PathwayBrowser/#/DTAB=AN&ANALYSIS={token}" target="_blank"> + + <button>Analyse</button> + + </form> + + <br> <br> + + </body> + +</html> |
b |
diff -r 000000000000 -r 216bd2a75b1d test-data/UnipIDs.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/UnipIDs.txt Sun Nov 26 19:29:17 2017 -0500 |
b |
@@ -0,0 +1,25 @@ +P04637 +P08246 +P63244 +P10275 +P00533 +Q14524 +P05067 +P35555 +P35222 +O95273 +P00451 +P38398 +Q05086 +Q12802 +P68871 +P04585 +Q96EB6 +Q9NYL2 +P31749 +P01137 +Q5S007 +Q08379 +P02649 +P35498 +P12931 |
b |
diff -r 000000000000 -r 216bd2a75b1d test-data/reactome_output.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/reactome_output.html Sun Nov 26 19:29:17 2017 -0500 |
b |
@@ -0,0 +1,48 @@ +<html> + + <head> + + <title>Connection to the Reactome Analysis Service</title> + + <style> + body { + margin: 40px; + background-color: #ffffff; + text-align: center; + } + h1 { + color: #19334d; + } + p { + margin-top: 40px; + } + button { + background-color: #ccddff; + border: 2px solid #19334d; + border-radius: 4px; + color: black; + padding: 16px 32px; + margin: 4px 2px; + cursor: pointer; + } + </style> + + </head> + + <body> + + <h1>Connection to the Reactome Analysis Service</h1> + + <p>Please click the button to execute the analysis:</p> + + <form action="http://www.reactome.org/PathwayBrowser/#/DTAB=AN&ANALYSIS=MjAxNzA4MzAwODM0MDRfMTMxNQ%3D%3D" target="_blank"> + + <button>Analyse</button> + + </form> + + <br> <br> + + </body> + +</html> |