Mercurial > repos > proteore > proteore_reactome
comparison reactome_analysis.py @ 1:8200968789c1 draft
planemo upload commit 1b95e5bc85662f10cdd6305587ccee8faf9a2354-dirty
| author | proteore |
|---|---|
| date | Fri, 07 Dec 2018 10:43:57 -0500 |
| parents | 19d8daa1eb2e |
| children | db63d069b5e6 |
comparison
equal
deleted
inserted
replaced
| 0:19d8daa1eb2e | 1:8200968789c1 |
|---|---|
| 43 trash = [] | 43 trash = [] |
| 44 if identifiers[1] == "list": | 44 if identifiers[1] == "list": |
| 45 ids = "\n".join(id_valid(identifiers[0].split())[0]) | 45 ids = "\n".join(id_valid(identifiers[0].split())[0]) |
| 46 #print(ids) | 46 #print(ids) |
| 47 #print("curl -H \"Content-Type: text/plain\" -d \"$(printf '%s')\" -X POST --url www.reactome.org/AnalysisService/identifiers/projection/\?pageSize\=1\&page\=1" % ids) | 47 #print("curl -H \"Content-Type: text/plain\" -d \"$(printf '%s')\" -X POST --url www.reactome.org/AnalysisService/identifiers/projection/\?pageSize\=1\&page\=1" % ids) |
| 48 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() | 48 json_string = os.popen("curl -H \"Content-Type: text/plain\" -d \"$(printf '%s')\" -X POST --url www.reactome.org/AnalysisService/identifiers/\?pageSize\=1\&page\=1" % ids).read() |
| 49 if len(id_valid(identifiers[0].split())[1]) > 0: | 49 if len(id_valid(identifiers[0].split())[1]) > 0: |
| 50 trash = id_valid(identifiers[0].split())[1] | 50 trash = id_valid(identifiers[0].split())[1] |
| 51 elif identifiers[1] == "file": | 51 elif identifiers[1] == "file": |
| 52 header = identifiers[2] | 52 header = identifiers[2] |
| 53 mq = open(identifiers[0]).readlines() | 53 mq = open(identifiers[0]).readlines() |
| 57 else: | 57 else: |
| 58 idens = [x.split("\t")[int(identifiers[3].replace("c", ""))-1] for x in mq] | 58 idens = [x.split("\t")[int(identifiers[3].replace("c", ""))-1] for x in mq] |
| 59 ids = "\n".join(id_valid(idens)[0]) | 59 ids = "\n".join(id_valid(idens)[0]) |
| 60 #print(ids) | 60 #print(ids) |
| 61 #print("curl -H \"Content-Type: text/plain\" -d \"$(printf '%s')\" -X POST --url www.reactome.org/AnalysisService/identifiers/projection/\?pageSize\=1\&page\=1" % ids) | 61 #print("curl -H \"Content-Type: text/plain\" -d \"$(printf '%s')\" -X POST --url www.reactome.org/AnalysisService/identifiers/projection/\?pageSize\=1\&page\=1" % ids) |
| 62 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() | 62 json_string = os.popen("curl -H \"Content-Type: text/plain\" -d \"$(printf '%s')\" -X POST --url www.reactome.org/AnalysisService/identifiers/\?pageSize\=1\&page\=1" % ids).read() |
| 63 if len(id_valid(idens)[1]) > 0: | 63 if len(id_valid(idens)[1]) > 0: |
| 64 trash = id_valid(idens)[1] | 64 trash = id_valid(idens)[1] |
| 65 print(json_string) | 65 print(json_string) |
| 66 return json_string, trash | 66 return json_string, trash |
| 67 | 67 |
| 68 def write_output(filename, json_string, trash_file, trash): | 68 def write_output(filename, json_string, species, trash_file, trash): |
| 69 """ | 69 """ |
| 70 Replace json result in template and print to output | 70 Replace json result in template and print to output |
| 71 """ | 71 """ |
| 72 template = open(os.path.join(CURRENT_DIR, "template.html")) | 72 template = open(os.path.join(CURRENT_DIR, "template.html")) |
| 73 output = open(filename, "w") | 73 output = open(filename, "w") |
| 74 try: | 74 try: |
| 75 for line in template: | 75 for line in template: |
| 76 if "{token}" in line: | 76 if "{token}" in line: |
| 77 line = line.replace("{species}", species) | |
| 77 line = line.replace("{token}", json.loads(json_string)["summary"]["token"]) | 78 line = line.replace("{token}", json.loads(json_string)["summary"]["token"]) |
| 78 output.write(line) | 79 output.write(line) |
| 79 except ValueError: | 80 except ValueError: |
| 80 output.write("An error occurred due to unavailability of Reactome web service. Please return later.") | 81 output.write("An error occurred due to unavailability of Reactome web service. Please return later.") |
| 81 template.close() | 82 template.close() |
| 90 def options(): | 91 def options(): |
| 91 parser = argparse.ArgumentParser() | 92 parser = argparse.ArgumentParser() |
| 92 argument = parser.add_argument("--json", nargs="+", required=True) | 93 argument = parser.add_argument("--json", nargs="+", required=True) |
| 93 argument = parser.add_argument("--output", default="output.html") | 94 argument = parser.add_argument("--output", default="output.html") |
| 94 argument = parser.add_argument("--trash", default="trash.txt") | 95 argument = parser.add_argument("--trash", default="trash.txt") |
| 96 argument = parser.add_argument("--species", default="48887") | |
| 95 args = parser.parse_args() | 97 args = parser.parse_args() |
| 96 filename = args.output | 98 filename = args.output |
| 97 json_string, trash = data_json(args.json) | 99 json_string, trash = data_json(args.json) |
| 98 write_output(filename, json_string, args.trash, trash) | 100 write_output(filename, json_string, args.species, args.trash, trash) |
| 99 | 101 |
| 100 if __name__ == "__main__": | 102 if __name__ == "__main__": |
| 101 options() | 103 options() |
