17
17
from mars_lib .logging import print_and_log
18
18
from pydantic import ValidationError
19
19
20
+ from mars_lib .ftp_upload import FTPUploader
21
+ from pathlib import Path
22
+ from typing import List
23
+
20
24
21
25
def submission (
22
26
credential_service_name : str ,
@@ -26,6 +30,8 @@ def submission(
26
30
target_repositories : list [str ],
27
31
investigation_is_root : bool ,
28
32
urls : dict [str , Any ],
33
+ file_transfer : str ,
34
+ data_file_paths = None ,
29
35
):
30
36
# If credential manager info found:
31
37
# Get password from the credential manager
@@ -53,7 +59,18 @@ def submission(
53
59
f"ISA JSON with investigation '{ isa_json .investigation .title } ' is valid."
54
60
)
55
61
56
- if TargetRepository .ENA in target_repositories :
62
+ if (
63
+ TargetRepository .ENA in target_repositories
64
+ and data_file_paths
65
+ and file_transfer
66
+ ):
67
+ upload_to_ena (
68
+ file_paths = data_file_paths ,
69
+ user_credentials = user_credentials ,
70
+ submission_url = urls ["ENA" ]["DATA-SUBMISSION" ],
71
+ file_transfer = file_transfer ,
72
+ )
73
+ elif TargetRepository .ENA in target_repositories :
57
74
# TODO: Filter out other assays
58
75
ena_result = submit_to_ena (
59
76
isa_json = isa_json ,
@@ -64,6 +81,7 @@ def submission(
64
81
f"Submission to { TargetRepository .ENA } was successful. Result:\n { ena_result .json ()} "
65
82
)
66
83
# TODO: Update `isa_json`, based on the receipt returned
84
+
67
85
elif TargetRepository .BIOSAMPLES in target_repositories :
68
86
# Submit to Biosamples
69
87
biosamples_result = submit_to_biosamples (
@@ -158,6 +176,26 @@ def submit_to_ena(
158
176
return result
159
177
160
178
179
+ def upload_to_ena (
180
+ file_paths : List [Path ],
181
+ user_credentials : dict [str , str ],
182
+ submission_url : str ,
183
+ file_transfer : str ,
184
+ ):
185
+ ALLOWED_FILE_TRANSFER_SOLUTIONS = {"ftp" , "aspera" }
186
+ file_transfer = file_transfer .lower ()
187
+
188
+ if file_transfer not in ALLOWED_FILE_TRANSFER_SOLUTIONS :
189
+ raise ValueError (f"Unsupported transfer protocol: { file_transfer } " )
190
+ if file_transfer == "ftp" :
191
+ uploader = FTPUploader (
192
+ submission_url ,
193
+ user_credentials ["username" ],
194
+ user_credentials ["password" ],
195
+ )
196
+ uploader .upload (file_paths )
197
+
198
+
161
199
def create_external_references (
162
200
biosamples_credentials : dict [str , str ],
163
201
biosamples_externalReferences : dict [str , Any ],
0 commit comments