Skip to content

Commit

Permalink
Add Study accession to the target repository's assay
Browse files Browse the repository at this point in the history
  • Loading branch information
kdp-cloud committed Jan 6, 2025
1 parent 98d739c commit 456a5ed
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
19 changes: 17 additions & 2 deletions mars-cli/mars_lib/isa_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ def detect_target_repo_comment(comments: List[Comment]) -> Comment:

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

add_accession_to_data_file_node(updated_node, accession.value)
else:
# Add study accession to study comments
updated_study = apply_filter(study_filter, investigation.studies)

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

# Add study accession to assay comments
updated_assay = next(
filter(
lambda assay: is_assay_for_target_repo(assay, target_repository),
updated_study.assays,
),
None,
)
if updated_assay:
assay_accession_comment: Comment = Comment(
name=f"{target_repository}_{target_level}_accession",
value=accession.value,
)
updated_assay.comments.append(assay_accession_comment)
isa_json.investigation = investigation
return isa_json

Expand Down
16 changes: 15 additions & 1 deletion mars-cli/tests/test_isa_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
load_isa_json,
update_isa_json,
map_data_files_to_repositories,
is_assay_for_target_repo,
)
from mars_lib.target_repo import TargetRepository, TARGET_REPO_KEY
import pytest
Expand Down Expand Up @@ -244,7 +245,7 @@ def test_update_study_materials_with_accession_categories():
)


def test_update_study_with_ena_study_accession_comment():
def test_update_study_and_assay_with_ena_study_accession_comment():
json_path = "tests/fixtures/isa_jsons/1_after_biosamples.json"
isa_json = load_isa_json(json_path, False)
response_file_path = "tests/fixtures/mars_receipts/ena_success_response.json"
Expand All @@ -258,6 +259,19 @@ def test_update_study_with_ena_study_accession_comment():
)
assert next(accession_comment).value == ena_study_accession_number

ena_assay = next(
filter(
lambda assay: is_assay_for_target_repo(assay, "ena"),
updated_isa_json.investigation.studies[0].assays,
),
None,
)
assay_comments = ena_assay.comments
accession_comment = filter(
lambda x: x.name == "ena_study_accession", assay_comments
)
assert next(accession_comment).value == ena_study_accession_number


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

0 comments on commit 456a5ed

Please sign in to comment.