diff reactome_analysis.py @ 6:9cc475dcd0f2 draft

planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
author proteore
date Tue, 18 Dec 2018 10:03:50 -0500
parents 878128362e33
children a58dc5d4b8cd
line wrap: on
line diff
--- a/reactome_analysis.py	Tue Apr 10 04:35:05 2018 -0400
+++ b/reactome_analysis.py	Tue Dec 18 10:03:50 2018 -0500
@@ -43,9 +43,7 @@
     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()
+        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()
         if len(id_valid(identifiers[0].split())[1]) > 0:
             trash = id_valid(identifiers[0].split())[1]
     elif identifiers[1] == "file":
@@ -57,15 +55,16 @@
             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()
+            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> stderr" % ids).read()
             if len(id_valid(idens)[1]) > 0:
                 trash = id_valid(idens)[1]
-    print(json_string)
+    #print(json_string)
+    j = json.loads(json_string)
+    print ("Identifiers not found: " + str(j["identifiersNotFound"]))
+    print ("Pathways found: " + str(j["pathwaysFound"]))
     return json_string, trash
 
-def write_output(filename, json_string, trash_file, trash):
+def write_output(filename, json_string, species, trash_file, trash):
     """
     Replace json result in template and print to output
     """
@@ -74,6 +73,7 @@
     try: 
         for line in template:
             if "{token}" in line:
+                line = line.replace("{species}", species)
                 line = line.replace("{token}", json.loads(json_string)["summary"]["token"])
             output.write(line)
     except ValueError:
@@ -82,7 +82,7 @@
     output.close()
     
     if trash:
-        print(trash)
+        #print(trash)
         trash_out = open(trash_file, "w")
         trash_out.write("\n".join(trash))
         trash_out.close()
@@ -92,10 +92,11 @@
     argument = parser.add_argument("--json", nargs="+", required=True)
     argument = parser.add_argument("--output", default="output.html")
     argument = parser.add_argument("--trash", default="trash.txt")
+    argument = parser.add_argument("--species", default="48887")
     args = parser.parse_args()
     filename = args.output
     json_string, trash = data_json(args.json)
-    write_output(filename, json_string, args.trash, trash)
+    write_output(filename, json_string, args.species, args.trash, trash)
 
 if __name__ == "__main__":
     options()