Skip to content

Commit

Permalink
Merge pull request #44 from usegalaxy-eu/draft
Browse files Browse the repository at this point in the history
Adding draft flag to not perform a submission
  • Loading branch information
bgruening authored Oct 21, 2021
2 parents e2c9c36 + ca108ce commit 4db250f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 30 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ All supported arguments:
--tool TOOL_NAME specify the name of the tool this submission is done with. Default: ena-upload-cli
--tool_version TOOL_VERSION
specify the version of the tool this submission is done with
--no_data_upload Indicate if no upload should be performed and you like to submit a RUN object (e.g. if uploaded was done separately).
--no_data_upload indicate if no upload should be performed and you like to submit a RUN object (e.g. if uploaded was done separately).
--draft indicate if no submission should be performed
--secret SECRET .secret.yml file containing the password and Webin ID of your ENA account
-d, --dev flag to use the dev/sandbox endpoint of ENA
```
Expand Down
69 changes: 40 additions & 29 deletions ena_upload/ena_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def submit_data(file_paths, password, webin_id):
"""

try:
print("\nconnecting to ftp.webin.ebi.ac.uk....")
print("\nConnecting to ftp.webin.ebi.ac.uk....")
ftp = ftplib.FTP("webin.ebi.ac.uk", webin_id, password)
except IOError:
print(ftp.lastErrorText())
Expand Down Expand Up @@ -616,7 +616,12 @@ def process_args():
parser.add_argument('--no_data_upload',
default=False,
action="store_true",
help='Indicate if no upload should be performed and you like to submit a RUN object (e.g. if uploaded was done separately).')
help='indicate if no upload should be performed and you like to submit a RUN object (e.g. if uploaded was done separately).')

parser.add_argument('--draft',
default=False,
action="store_true",
help='indicate if no submission should be performed')

parser.add_argument('--secret',
required=True,
Expand Down Expand Up @@ -677,6 +682,7 @@ def main():
dev = args.dev
checklist = args.checklist
secret = args.secret
draft = args.draft

with open(secret, 'r') as secret_file:
credentials = yaml.load(secret_file, Loader=yaml.FullLoader)
Expand Down Expand Up @@ -711,7 +717,6 @@ def main():
# submit data
if 'run' in schema_targets:
# a dictionary of filename:file_path
# ? do I have to define the absolute path
df = schema_targets['run']

file_paths = {os.path.basename(path): os.path.abspath(path)
Expand All @@ -734,16 +739,19 @@ def main():
schema_targets['run'] = df

# submit data to webin ftp server
if not args.no_data_upload:
submit_data(file_paths, password, webin_id)
else:
if args.no_data_upload:
print("No files will be uploaded, remove `--no_data_upload' argument to perform upload.")
elif draft:
print("No files will be uploaded, remove `--draft' argument to perform upload.")
else:
submit_data(file_paths, password, webin_id)


# when adding sample
# update schema_targets with taxon ids or scientific names
if 'sample' in schema_targets:
df = schema_targets['sample']
print('retrieving taxon IDs and scientific names if needed')
print('Retrieving taxon IDs and scientific names if needed')
for index, row in df.iterrows():
if pd.notna(row['scientific_name']) and pd.isna(row['taxon_id']):
# retrieve taxon id using scientific name
Expand All @@ -755,7 +763,7 @@ def main():
df.loc[index, 'scientific_name'] = scientificName
elif pd.isna(row['taxon_id']) and pd.isna(row['scientific_name']):
sys.exit(f"No taxon_id or scientific_name was given with sample {row['alias']}.")
print('taxon IDs and scientific names are retrieved')
print('Taxon IDs and scientific names are retrieved')
schema_targets['sample'] = df

# ? need to add a place holder for setting up
Expand All @@ -781,28 +789,31 @@ def main():

schema_xmls['submission'] = submission_xml

if dev:
url = 'https://wwwdev.ebi.ac.uk/ena/submit/drop-box/submit/?auth=ENA'
if draft:
print("No submission will be performed, remove `--draft' argument to perform submission.")
else:
url = 'https://www.ebi.ac.uk/ena/submit/drop-box/submit/?auth=ENA'

print(f'\nSubmitting XMLs to ENA server: {url}')
receipt = send_schemas(schema_xmls, url, webin_id, password).text
print("Printing receipt to ./receipt.xml")
with open('receipt.xml', 'w') as fw:
fw.write(receipt)
try:
schema_update = process_receipt(receipt.encode("utf-8"), action)
except ValueError:
print("There was an ERROR during submission:")
sys.exit(receipt)

schema_dataframe = update_table(schema_dataframe,
schema_targets,
schema_update)

# save updates in new tables
save_update(schema_tables, schema_dataframe)
if dev:
url = 'https://wwwdev.ebi.ac.uk/ena/submit/drop-box/submit/?auth=ENA'
else:
url = 'https://www.ebi.ac.uk/ena/submit/drop-box/submit/?auth=ENA'

print(f'\nSubmitting XMLs to ENA server: {url}')
receipt = send_schemas(schema_xmls, url, webin_id, password).text
print("Printing receipt to ./receipt.xml")
with open('receipt.xml', 'w') as fw:
fw.write(receipt)
try:
schema_update = process_receipt(receipt.encode("utf-8"), action)
except ValueError:
print("There was an ERROR during submission:")
sys.exit(receipt)

schema_dataframe = update_table(schema_dataframe,
schema_targets,
schema_update)

# save updates in new tables
save_update(schema_tables, schema_dataframe)


if __name__ == "__main__":
Expand Down

0 comments on commit 4db250f

Please sign in to comment.