comparison reactome_analysis.py @ 2:db63d069b5e6 draft

planemo upload commit a0b73386d86dc3d60ad33b944dad88fd5ff4d9ab-dirty
author proteore
date Tue, 11 Dec 2018 07:46:12 -0500
parents 8200968789c1
children 988a6f43acdb
comparison
equal deleted inserted replaced
1:8200968789c1 2:db63d069b5e6
41 Return error in HTML format if web service is not available 41 Return error in HTML format if web service is not available
42 """ 42 """
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)
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/\?pageSize\=1\&page\=1" % ids).read() 46 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: 47 if len(id_valid(identifiers[0].split())[1]) > 0:
50 trash = id_valid(identifiers[0].split())[1] 48 trash = id_valid(identifiers[0].split())[1]
51 elif identifiers[1] == "file": 49 elif identifiers[1] == "file":
52 header = identifiers[2] 50 header = identifiers[2]
55 if header == "true": 53 if header == "true":
56 idens = [x.split("\t")[int(identifiers[3].replace("c", ""))-1] for x in mq[1:]] 54 idens = [x.split("\t")[int(identifiers[3].replace("c", ""))-1] for x in mq[1:]]
57 else: 55 else:
58 idens = [x.split("\t")[int(identifiers[3].replace("c", ""))-1] for x in mq] 56 idens = [x.split("\t")[int(identifiers[3].replace("c", ""))-1] for x in mq]
59 ids = "\n".join(id_valid(idens)[0]) 57 ids = "\n".join(id_valid(idens)[0])
60 #print(ids) 58 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 2> /dev/null" % ids).read()
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/\?pageSize\=1\&page\=1" % ids).read()
63 if len(id_valid(idens)[1]) > 0: 59 if len(id_valid(idens)[1]) > 0:
64 trash = id_valid(idens)[1] 60 trash = id_valid(idens)[1]
65 print(json_string) 61 #print(json_string)
62 j = json.loads(json_string)
63 print ("Identifiers not found: " + str(j["identifiersNotFound"]))
64 print ("Pathways found: " + str(j["pathwaysFound"]))
66 return json_string, trash 65 return json_string, trash
67 66
68 def write_output(filename, json_string, species, trash_file, trash): 67 def write_output(filename, json_string, species, trash_file, trash):
69 """ 68 """
70 Replace json result in template and print to output 69 Replace json result in template and print to output
81 output.write("An error occurred due to unavailability of Reactome web service. Please return later.") 80 output.write("An error occurred due to unavailability of Reactome web service. Please return later.")
82 template.close() 81 template.close()
83 output.close() 82 output.close()
84 83
85 if trash: 84 if trash:
86 print(trash) 85 #print(trash)
87 trash_out = open(trash_file, "w") 86 trash_out = open(trash_file, "w")
88 trash_out.write("\n".join(trash)) 87 trash_out.write("\n".join(trash))
89 trash_out.close() 88 trash_out.close()
90 89
91 def options(): 90 def options():