@@ -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 ):
0 commit comments