# HG changeset patch # User proteore # Date 1511742557 18000 # Node ID 216bd2a75b1dfc8a4c4f7a8a762b132ab9418320 planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty 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 @@ -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** 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() 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 @@ + + query Reactome with your IDs list + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 @@ -0,0 +1,48 @@ + + + + + Connection to the Reactome Analysis Service + + + + + + + +

Connection to the Reactome Analysis Service

+ +

Please click the button to execute the analysis:

+ +
+ + + +
+ +

+ + + + 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 @@ -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 diff -r 000000000000 -r 216bd2a75b1d test-data/reactome_invalide_ids.txt 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 @@ -0,0 +1,48 @@ + + + + + Connection to the Reactome Analysis Service + + + + + + + +

Connection to the Reactome Analysis Service

+ +

Please click the button to execute the analysis:

+ +
+ + + +
+ +

+ + + +