Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugging session biosamples ena #74

Merged
merged 9 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 12 additions & 33 deletions mars-cli/mars_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,39 +246,18 @@ def submit(

data_file_paths = [f.name for f in data_files] if file_transfer else []

try:
submission(
credential_service_name,
username_credentials,
credentials_file,
isa_json_file.name,
target_repositories,
investigation_is_root,
urls_dict,
file_transfer,
output,
data_file_paths,
)
except requests.RequestException as err:
tb = sys.exc_info()[2] # Traceback value
print_and_log(
f"Request to repository could not be made.\n{err.with_traceback(tb)}",
level="error",
)

except ValidationError as err:
tb = sys.exc_info()[2] # Traceback value
print_and_log(
f"A validation error occurred while reading the ISA JSON. Please correct the following mistakes:\n{err.with_traceback(tb)}",
level="error",
)

except Exception as err:
tb = sys.exc_info()[2] # Traceback value
print_and_log(
f"Unexpected error occurred during submission.\n{err.with_traceback(tb)}",
level="error",
)
submission(
credential_service_name,
username_credentials,
credentials_file,
isa_json_file.name,
target_repositories,
investigation_is_root,
urls_dict,
file_transfer,
output,
data_file_paths,
)


@cli.command()
Expand Down
66 changes: 40 additions & 26 deletions mars-cli/mars_lib/isa_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,44 +365,58 @@ def update_isa_json(isa_json: IsaJson, repo_response: RepositoryResponse) -> Isa
investigation = isa_json.investigation
for accession in repo_response.accessions:

has_assay_in_path = [p for p in accession.path if p.key == "assays"]
target_level = "assay" if len(has_assay_in_path) > 0 else "study"
material_type_path = next(
p
for p in accession.path
if p.key in ["sources", "samples", "otherMaterials"]
has_assay_in_path = len([p for p in accession.path if p.key == "assays"]) > 0
has_materials_in_path = (
len([p for p in accession.path if p.key == "materials"]) > 0
)
target_level = "assay" if has_assay_in_path else "study"

study_filter = get_filter_for_accession_key(accession, "studies")
if not study_filter:
raise ValueError(f"Study filter is not present in {accession.path}.")

updated_node = apply_filter(study_filter, investigation.studies)
if has_materials_in_path:
material_type_path = next(
p
for p in accession.path
if p.key in ["sources", "samples", "otherMaterials"]
)

if target_level == "assay":
assay_filter = get_filter_for_accession_key(accession, "assays")
if not assay_filter:
raise ValueError(f"Assay filter is not present in {accession.path}.")
updated_node = apply_filter(study_filter, investigation.studies)

updated_node = apply_filter(assay_filter, updated_node.assays)
if target_level == "assay":
assay_filter = get_filter_for_accession_key(accession, "assays")
if not assay_filter:
raise ValueError(
f"Assay filter is not present in {accession.path}."
)

if not updated_node:
raise ValueError(f"Node not found for {accession.value}.")
if not accession_characteristic_category_present(updated_node):
(accession_id, category) = create_accession_characteristic_category(
updated_node
)
updated_node = apply_filter(assay_filter, updated_node.assays)

if not updated_node:
raise ValueError(f"Node not found for {accession.value}.")
if not accession_characteristic_category_present(updated_node):
(accession_id, category) = create_accession_characteristic_category(
updated_node
)
else:
(accession_id, category) = fetch_existing_characteristic_category(
updated_node
)

if not accession_characteristic_present(updated_node, material_type_path):
create_accession_characteristic(
updated_node, material_type_path, category, accession_id
)

add_accession_to_node(updated_node, accession.value, material_type_path)
else:
(accession_id, category) = fetch_existing_characteristic_category(
updated_node
)
updated_study = apply_filter(study_filter, investigation.studies)

if not accession_characteristic_present(updated_node, material_type_path):
create_accession_characteristic(
updated_node, material_type_path, category, accession_id
study_accession_comment: Comment = Comment(
name="accession", value=accession.value
)

add_accession_to_node(updated_node, accession.value, material_type_path)
updated_study.comments.append(study_accession_comment)

isa_json.investigation = investigation
return isa_json
11 changes: 9 additions & 2 deletions mars-cli/mars_lib/submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def submission(
submission_url=urls["ENA"]["DATA-SUBMISSION"],
file_transfer=file_transfer,
)
print_and_log(f"Start submitting to {TargetRepository.ENA}.", level="debug")

# Step 2 : submit isa-json to ena
ena_result = submit_to_ena(
Expand All @@ -128,8 +129,14 @@ def submission(
print_and_log(
f"Submission to {TargetRepository.ENA} was successful. Result:\n{ena_result.json()}"
)
# Update `isa_json`, based on the receipt returned
ena_mars_receipt = RepositoryResponse.from_json(str(ena_result.content))

print_and_log(
f"Update ISA-JSON based on receipt from {TargetRepository.ENA}.",
level="debug",
)
ena_mars_receipt = RepositoryResponse.model_validate(
json.loads(ena_result.content)
)
isa_json = update_isa_json(isa_json, ena_mars_receipt)
if DEBUG:
save_step_to_file(time_stamp, "2_after_ena", isa_json)
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions test-data/biosamples-input-isa.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
{
"@id": "#characteristic_category/collection_date_323",
"characteristicType": {
"annotationValue": "collection_date",
"annotationValue": "collection date",
"termAccession": "",
"termSource": ""
}
Expand Down Expand Up @@ -853,7 +853,7 @@
"dataFiles": [
{
"@id": "#data/334",
"name": "RD file 1b",
"name": "ENA_TEST2.R2.fastq.gz",
"type": "Raw Data File",
"comments": [
{
Expand Down