Skip to content

Commit 456a5ed

Browse files
committed
Add Study accession to the target repository's assay
1 parent 98d739c commit 456a5ed

2 files changed

Lines changed: 32 additions & 3 deletions

File tree

mars-cli/mars_lib/isa_json.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ def detect_target_repo_comment(comments: List[Comment]) -> Comment:
7474

7575
def is_assay_for_target_repo(assay: Assay, target_repo: str) -> bool:
7676
"""
77-
Defines whether the assays is meant for the target repository.
77+
Defines whether the assays are meant for the target repository.
7878
7979
Args:
80-
assay_dict (Dict[str, str]): Dictionary representation of an assay.
80+
assay (Assay): Assay model.
8181
target_repo (TargetRepository): Target repository as a constant.
8282
8383
Returns:
@@ -484,6 +484,7 @@ def update_isa_json(isa_json: IsaJson, repo_response: RepositoryResponse) -> Isa
484484

485485
add_accession_to_data_file_node(updated_node, accession.value)
486486
else:
487+
# Add study accession to study comments
487488
updated_study = apply_filter(study_filter, investigation.studies)
488489

489490
study_accession_comment: Comment = Comment(
@@ -492,6 +493,20 @@ def update_isa_json(isa_json: IsaJson, repo_response: RepositoryResponse) -> Isa
492493
)
493494
updated_study.comments.append(study_accession_comment)
494495

496+
# Add study accession to assay comments
497+
updated_assay = next(
498+
filter(
499+
lambda assay: is_assay_for_target_repo(assay, target_repository),
500+
updated_study.assays,
501+
),
502+
None,
503+
)
504+
if updated_assay:
505+
assay_accession_comment: Comment = Comment(
506+
name=f"{target_repository}_{target_level}_accession",
507+
value=accession.value,
508+
)
509+
updated_assay.comments.append(assay_accession_comment)
495510
isa_json.investigation = investigation
496511
return isa_json
497512

mars-cli/tests/test_isa_json.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
load_isa_json,
77
update_isa_json,
88
map_data_files_to_repositories,
9+
is_assay_for_target_repo,
910
)
1011
from mars_lib.target_repo import TargetRepository, TARGET_REPO_KEY
1112
import pytest
@@ -244,7 +245,7 @@ def test_update_study_materials_with_accession_categories():
244245
)
245246

246247

247-
def test_update_study_with_ena_study_accession_comment():
248+
def test_update_study_and_assay_with_ena_study_accession_comment():
248249
json_path = "tests/fixtures/isa_jsons/1_after_biosamples.json"
249250
isa_json = load_isa_json(json_path, False)
250251
response_file_path = "tests/fixtures/mars_receipts/ena_success_response.json"
@@ -258,6 +259,19 @@ def test_update_study_with_ena_study_accession_comment():
258259
)
259260
assert next(accession_comment).value == ena_study_accession_number
260261

262+
ena_assay = next(
263+
filter(
264+
lambda assay: is_assay_for_target_repo(assay, "ena"),
265+
updated_isa_json.investigation.studies[0].assays,
266+
),
267+
None,
268+
)
269+
assay_comments = ena_assay.comments
270+
accession_comment = filter(
271+
lambda x: x.name == "ena_study_accession", assay_comments
272+
)
273+
assert next(accession_comment).value == ena_study_accession_number
274+
261275

262276
def test_update_datafile_comment_with_accession_comment_present():
263277
json_path = "tests/fixtures/isa_jsons/1_after_biosamples.json"

0 commit comments

Comments
 (0)