@@ -66,38 +66,6 @@ def wf_info(workflow_path):
66
66
return version , file_type .upper ()
67
67
68
68
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
-
101
69
def modify_jsonyaml_paths (jsonyaml_file ):
102
70
"""
103
71
Changes relative paths in a json/yaml file to be relative
@@ -124,6 +92,49 @@ def fixpaths(d):
124
92
del d ["path" ]
125
93
126
94
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
127
138
128
139
129
140
def expand_globs (attachments ):
@@ -167,7 +178,7 @@ def get_service_info(self):
167
178
:return: The body of the get result as a dictionary.
168
179
"""
169
180
postresult = requests .get ("%s://%s/ga4gh/wes/v1/service-info" % (self .proto , self .host ),
170
- headers = { "Authorization" : self .auth } )
181
+ headers = self .auth )
171
182
return wes_reponse (postresult )
172
183
173
184
def list_runs (self ):
@@ -183,7 +194,7 @@ def list_runs(self):
183
194
:return: The body of the get result as a dictionary.
184
195
"""
185
196
postresult = requests .get ("%s://%s/ga4gh/wes/v1/runs" % (self .proto , self .host ),
186
- headers = { "Authorization" : self .auth } )
197
+ headers = self .auth )
187
198
return wes_reponse (postresult )
188
199
189
200
def run (self , wf , jsonyaml , attachments ):
@@ -203,7 +214,7 @@ def run(self, wf, jsonyaml, attachments):
203
214
parts = build_wes_request (wf , jsonyaml , attachments )
204
215
postresult = requests .post ("%s://%s/ga4gh/wes/v1/runs" % (self .proto , self .host ),
205
216
files = parts ,
206
- headers = { "Authorization" : self .auth } )
217
+ headers = self .auth )
207
218
return wes_reponse (postresult )
208
219
209
220
def cancel (self , run_id ):
@@ -217,7 +228,7 @@ def cancel(self, run_id):
217
228
:return: The body of the delete result as a dictionary.
218
229
"""
219
230
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 )
221
232
return wes_reponse (postresult )
222
233
223
234
def get_run_log (self , run_id ):
@@ -231,7 +242,7 @@ def get_run_log(self, run_id):
231
242
:return: The body of the get result as a dictionary.
232
243
"""
233
244
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 )
235
246
return wes_reponse (postresult )
236
247
237
248
def get_run_status (self , run_id ):
@@ -245,5 +256,5 @@ def get_run_status(self, run_id):
245
256
:return: The body of the get result as a dictionary.
246
257
"""
247
258
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 )
249
260
return wes_reponse (postresult )
0 commit comments