Skip to content

Commit

Permalink
Access enum's value field
Browse files Browse the repository at this point in the history
  • Loading branch information
kdp-cloud committed Nov 8, 2024
1 parent 5ea2bd8 commit 9ee367d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 26 deletions.
6 changes: 3 additions & 3 deletions mars-cli/mars_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,13 @@ def submit(
target_repositories = []

if submit_to_biosamples:
target_repositories.append(TargetRepository.BIOSAMPLES)
target_repositories.append(TargetRepository.BIOSAMPLES.value)

if submit_to_ena:
target_repositories.append(TargetRepository.ENA)
target_repositories.append(TargetRepository.ENA.value)

if submit_to_metabolights:
target_repositories.append(TargetRepository.METABOLIGHTS)
target_repositories.append(TargetRepository.METABOLIGHTS.value)

print_and_log(
f"Starting submission of the ISA JSON to the target repositories: {', '.join(target_repositories)}."
Expand Down
2 changes: 1 addition & 1 deletion mars-cli/mars_lib/isa_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def reduce_isa_json_for_target_repo(
new_studies = []
studies = filtered_isa_json.investigation.studies
for study in studies:
if target_repo == TargetRepository.BIOSAMPLES:
if target_repo == TargetRepository.BIOSAMPLES.value:
filtered_assays = []
else:
assays = study.assays
Expand Down
36 changes: 20 additions & 16 deletions mars-cli/mars_lib/submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def submission(
):
raise ValueError("No target repository selected.")

if TargetRepository.BIOSAMPLES in target_repositories:
if TargetRepository.BIOSAMPLES.value in target_repositories:
# Submit to Biosamples
biosamples_result = submit_to_biosamples(
isa_json=isa_json,
Expand All @@ -106,7 +106,7 @@ def submission(
webin_token_url=urls["WEBIN"]["TOKEN"],
)
print_and_log(
f"Submission to {TargetRepository.BIOSAMPLES} was successful. Result:\n{biosamples_result.json()}",
f"Submission to {TargetRepository.BIOSAMPLES.value} was successful. Result:\n{biosamples_result.json()}",
level="info",
)
# Update `isa_json`, based on the receipt returned
Expand All @@ -117,16 +117,20 @@ def submission(
if DEBUG:
save_step_to_file(time_stamp, "1_after_biosamples", isa_json)

if TargetRepository.ENA in target_repositories:
if TargetRepository.ENA.value in target_repositories:
# Step 1 : upload data if file paths are provided
if data_file_paths and file_transfer:
upload_to_ena(
file_paths=[Path(df) for df in data_file_map[TargetRepository.ENA]],
file_paths=[
Path(df) for df in data_file_map[TargetRepository.ENA.value]
],
user_credentials=user_credentials,
submission_url=urls["ENA"]["DATA-SUBMISSION"],
file_transfer=file_transfer,
)
print_and_log(f"Start submitting to {TargetRepository.ENA}.", level="debug")
print_and_log(
f"Start submitting to {TargetRepository.ENA.value}.", level="debug"
)

# Step 2 : submit isa-json to ena
ena_result = submit_to_ena(
Expand All @@ -135,11 +139,11 @@ def submission(
submission_url=urls["ENA"]["SUBMISSION"],
)
print_and_log(
f"Submission to {TargetRepository.ENA} was successful. Result:\n{ena_result.json()}"
f"Submission to {TargetRepository.ENA.value} was successful. Result:\n{ena_result.json()}"
)

print_and_log(
f"Update ISA-JSON based on receipt from {TargetRepository.ENA}.",
f"Update ISA-JSON based on receipt from {TargetRepository.ENA.value}.",
level="debug",
)
ena_mars_receipt = RepositoryResponse.model_validate(
Expand All @@ -149,10 +153,10 @@ def submission(
if DEBUG:
save_step_to_file(time_stamp, "2_after_ena", isa_json)

if TargetRepository.METABOLIGHTS in target_repositories:
if TargetRepository.METABOLIGHTS.value in target_repositories:
# Submit to MetaboLights
metabolights_result = upload_to_metabolights(
file_paths=data_file_map[TargetRepository.ENA],
file_paths=data_file_map[TargetRepository.METABOLIGHTS.value],
file_transfer=file_transfer,
isa_json=isa_json,
metabolights_credentials=user_credentials,
Expand All @@ -161,7 +165,7 @@ def submission(
)
metabolights_receipt_obj = metabolights_result.json()
print_and_log(
f"Submission to {TargetRepository.METABOLIGHTS} was successful. Result:\n{metabolights_receipt_obj}",
f"Submission to {TargetRepository.METABOLIGHTS.value} was successful. Result:\n{metabolights_receipt_obj}",
level="info",
)
metabolights_receipt = RepositoryResponse.model_validate(
Expand All @@ -177,11 +181,11 @@ def submission(
if DEBUG:
save_step_to_file(time_stamp, "3_after_metabolights", isa_json)

if TargetRepository.EVA in target_repositories:
if TargetRepository.EVA.value in target_repositories:
# Submit to EVA
# TODO: Filter out other assays
print_and_log(
f"Submission to {TargetRepository.EVA} was successful.", level="info"
f"Submission to {TargetRepository.EVA.value} was successful.", level="info"
)
# TODO: Update `isa_json`, based on the receipt returned

Expand All @@ -207,7 +211,7 @@ def submit_to_biosamples(
headers=headers,
params=params,
json=reduce_isa_json_for_target_repo(
isa_json, TargetRepository.BIOSAMPLES
isa_json, TargetRepository.BIOSAMPLES.value
).model_dump(by_alias=True, exclude_none=True),
)

Expand Down Expand Up @@ -344,9 +348,9 @@ def submit_to_ena(
submission_url,
headers=headers,
params=params,
json=reduce_isa_json_for_target_repo(isa_json, TargetRepository.ENA).model_dump(
by_alias=True, exclude_none=True
),
json=reduce_isa_json_for_target_repo(
isa_json, TargetRepository.ENA.value
).model_dump(by_alias=True, exclude_none=True),
)

if result.status_code != 200:
Expand Down
12 changes: 6 additions & 6 deletions mars-cli/tests/test_isa_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_reduce_isa_json_for_target_repo():
)

filtered_isa_json = reduce_isa_json_for_target_repo(
good_isa_json, TargetRepository.ENA
good_isa_json, TargetRepository.ENA.value
)

good_isa_json_study = good_isa_json.investigation.studies[0]
Expand All @@ -63,7 +63,7 @@ def test_reduce_isa_json_for_biosamples():
)

filtered_isa_json = reduce_isa_json_for_target_repo(
good_isa_json, TargetRepository.BIOSAMPLES
good_isa_json, TargetRepository.BIOSAMPLES.value
)

assert len(filtered_isa_json.investigation.studies[0].assays) == 0
Expand Down Expand Up @@ -110,7 +110,7 @@ def test_target_repo_comment_validator():
{
"@id": "comment_001",
"name": f"{TARGET_REPO_KEY}",
"value": TargetRepository.ENA,
"value": TargetRepository.ENA.value,
}
],
}
Expand All @@ -134,12 +134,12 @@ def test_target_repo_comment_validator():
{
"@id": "comment_003",
"name": f"{TARGET_REPO_KEY}",
"value": TargetRepository.ENA,
"value": TargetRepository.ENA.value,
},
{
"@id": "comment_004",
"name": f"{TARGET_REPO_KEY}",
"value": TargetRepository.METABOLIGHTS,
"value": TargetRepository.METABOLIGHTS.value,
},
],
}
Expand Down Expand Up @@ -308,7 +308,7 @@ def test_map_data_files_to_repositories():

with pytest.raises(
ValueError,
match=rf"Assay for repository '{TargetRepository.ARRAYEXPRESS}' has encountered",
match=rf"Assay for repository '{TargetRepository.ARRAYEXPRESS.value}' has encountered",
):
map_data_files_to_repositories(not_enough_files, isa_json)

Expand Down

0 comments on commit 9ee367d

Please sign in to comment.