@@ -66,38 +66,6 @@ def wf_info(workflow_path):
6666 return version , file_type .upper ()
6767
6868
69- def build_wes_request (workflow_file , json_path , attachments = None ):
70- """
71- :param str workflow_file: Path to cwl/wdl file. Can be http/https/file.
72- :param json_path: Path to accompanying json file. Currently must be local.
73- :param attachments: Any other files needing to be uploaded to the server.
74-
75- :return: A list of tuples formatted to be sent in a post to the wes-server (Swagger API).
76- """
77- workflow_file = "file://" + workflow_file if ":" not in workflow_file else workflow_file
78- json_path = json_path [7 :] if json_path .startswith ("file://" ) else json_path
79- wf_version , wf_type = wf_info (workflow_file )
80-
81- parts = [("workflow_params" , json .dumps (json .load (open (json_path )))),
82- ("workflow_type" , wf_type ),
83- ("workflow_type_version" , wf_version )]
84-
85- if workflow_file .startswith ("file://" ):
86- parts .append (("workflow_attachment" , (os .path .basename (workflow_file [7 :]), open (workflow_file [7 :], "rb" ))))
87- parts .append (("workflow_url" , os .path .basename (workflow_file [7 :])))
88- else :
89- parts .append (("workflow_url" , workflow_file ))
90-
91- if attachments :
92- for attachment in attachments :
93- attachment = attachment [7 :] if attachment .startswith ("file://" ) else attachment
94- if ':' in attachment :
95- raise TypeError ('Only local files supported for attachment: %s' % attachment )
96- parts .append (("workflow_attachment" , (os .path .basename (attachment ), open (attachment , "rb" ))))
97-
98- return parts
99-
100-
10169def modify_jsonyaml_paths (jsonyaml_file ):
10270 """
10371 Changes relative paths in a json/yaml file to be relative
@@ -124,6 +92,49 @@ def fixpaths(d):
12492 del d ["path" ]
12593
12694 visit (input_dict , fixpaths )
95+ return json .dumps (input_dict )
96+
97+
98+ def build_wes_request (workflow_file , json_path , attachments = None ):
99+ """
100+ :param str workflow_file: Path to cwl/wdl file. Can be http/https/file.
101+ :param json_path: Path to accompanying json file.
102+ :param attachments: Any other files needing to be uploaded to the server.
103+
104+ :return: A list of tuples formatted to be sent in a post to the wes-server (Swagger API).
105+ """
106+ workflow_file = "file://" + workflow_file if ":" not in workflow_file else workflow_file
107+ if json_path .startswith ("file://" ):
108+ json_path = json_path [7 :]
109+ with open (json_path ) as f :
110+ wf_params = json .dumps (json .load (f ))
111+ elif json_path .startswith ("http" ):
112+ wf_params = modify_jsonyaml_paths (json_path )
113+ else :
114+ wf_params = json_path
115+ wf_version , wf_type = wf_info (workflow_file )
116+
117+ parts = [("workflow_params" , wf_params ),
118+ ("workflow_type" , wf_type ),
119+ ("workflow_type_version" , wf_version )]
120+
121+ if workflow_file .startswith ("file://" ):
122+ parts .append (("workflow_attachment" , (os .path .basename (workflow_file [7 :]), open (workflow_file [7 :], "rb" ))))
123+ parts .append (("workflow_url" , os .path .basename (workflow_file [7 :])))
124+ else :
125+ parts .append (("workflow_url" , workflow_file ))
126+
127+ if attachments :
128+ for attachment in attachments :
129+ if attachment .startswith ("file://" ):
130+ attachment = attachment [7 :]
131+ attach_f = open (attachment , "rb" )
132+ elif attachment .startswith ("http" ):
133+ attach_f = urlopen (attachment )
134+
135+ parts .append (("workflow_attachment" , (os .path .basename (attachment ), attach_f )))
136+
137+ return parts
127138
128139
129140def expand_globs (attachments ):
@@ -167,7 +178,7 @@ def get_service_info(self):
167178 :return: The body of the get result as a dictionary.
168179 """
169180 postresult = requests .get ("%s://%s/ga4gh/wes/v1/service-info" % (self .proto , self .host ),
170- headers = { "Authorization" : self .auth } )
181+ headers = self .auth )
171182 return wes_reponse (postresult )
172183
173184 def list_runs (self ):
@@ -183,7 +194,7 @@ def list_runs(self):
183194 :return: The body of the get result as a dictionary.
184195 """
185196 postresult = requests .get ("%s://%s/ga4gh/wes/v1/runs" % (self .proto , self .host ),
186- headers = { "Authorization" : self .auth } )
197+ headers = self .auth )
187198 return wes_reponse (postresult )
188199
189200 def run (self , wf , jsonyaml , attachments ):
@@ -203,7 +214,7 @@ def run(self, wf, jsonyaml, attachments):
203214 parts = build_wes_request (wf , jsonyaml , attachments )
204215 postresult = requests .post ("%s://%s/ga4gh/wes/v1/runs" % (self .proto , self .host ),
205216 files = parts ,
206- headers = { "Authorization" : self .auth } )
217+ headers = self .auth )
207218 return wes_reponse (postresult )
208219
209220 def cancel (self , run_id ):
@@ -217,7 +228,7 @@ def cancel(self, run_id):
217228 :return: The body of the delete result as a dictionary.
218229 """
219230 postresult = requests .delete ("%s://%s/ga4gh/wes/v1/runs/%s" % (self .proto , self .host , run_id ),
220- headers = { "Authorization" : self .auth } )
231+ headers = self .auth )
221232 return wes_reponse (postresult )
222233
223234 def get_run_log (self , run_id ):
@@ -231,7 +242,7 @@ def get_run_log(self, run_id):
231242 :return: The body of the get result as a dictionary.
232243 """
233244 postresult = requests .get ("%s://%s/ga4gh/wes/v1/runs/%s" % (self .proto , self .host , run_id ),
234- headers = { "Authorization" : self .auth } )
245+ headers = self .auth )
235246 return wes_reponse (postresult )
236247
237248 def get_run_status (self , run_id ):
@@ -245,5 +256,5 @@ def get_run_status(self, run_id):
245256 :return: The body of the get result as a dictionary.
246257 """
247258 postresult = requests .get ("%s://%s/ga4gh/wes/v1/runs/%s/status" % (self .proto , self .host , run_id ),
248- headers = { "Authorization" : self .auth } )
259+ headers = self .auth )
249260 return wes_reponse (postresult )
0 commit comments