From 1114b02996b00b0518df1e4abc43757dc9fb8e66 Mon Sep 17 00:00:00 2001 From: EstelleDa Date: Mon, 18 Nov 2024 19:04:23 +1100 Subject: [PATCH 1/3] Add a meta-analysis test. --- tests/routers/test_score_set.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/tests/routers/test_score_set.py b/tests/routers/test_score_set.py index 25d13b9b..f7ca5377 100644 --- a/tests/routers/test_score_set.py +++ b/tests/routers/test_score_set.py @@ -7,7 +7,7 @@ from arq import ArqRedis from sqlalchemy import select -from mavedb.lib.validation.urn_re import MAVEDB_TMP_URN_RE +from mavedb.lib.validation.urn_re import MAVEDB_TMP_URN_RE, MAVEDB_SCORE_SET_URN_RE from mavedb.models.enums.processing_state import ProcessingState from mavedb.models.experiment import Experiment as ExperimentDbModel from mavedb.models.score_set import ScoreSet as ScoreSetDbModel @@ -1057,6 +1057,34 @@ def test_multiple_score_set_meta_analysis_multiple_experiment_sets_different_sco assert meta_score_set_3["urn"] == "urn:mavedb:00000003-0-3" +def test_cannot_add_score_set_to_meta_analysis_experiment(session, data_provider, client, setup_router_db, data_files): + experiment = create_experiment(client) + score_set_1 = create_seq_score_set_with_variants( + client, session, data_provider, experiment["urn"], data_files / "scores.csv" + ) + + score_set_1 = (client.post(f"/api/v1/score-sets/{score_set_1['urn']}/publish")).json() + meta_score_set_1 = create_seq_score_set_with_variants( + client, + session, + data_provider, + None, + data_files / "scores.csv", + update={"title": "Test Meta Analysis", "metaAnalyzesScoreSetUrns": [score_set_1["urn"]]}, + ) + + meta_score_set_1 = (client.post(f"/api/v1/score-sets/{meta_score_set_1['urn']}/publish")).json() + assert isinstance(MAVEDB_SCORE_SET_URN_RE.fullmatch(meta_score_set_1["urn"]), re.Match) + score_set_2 = deepcopy(TEST_MINIMAL_SEQ_SCORESET) + score_set_2["experimentUrn"] = meta_score_set_1['experiment']['urn'] + jsonschema.validate(instance=score_set_2, schema=ScoreSetCreate.schema()) + + response = client.post("/api/v1/score-sets/", json=score_set_2) + response_data = response.json() + assert response.status_code == 403 + assert "Score sets may not be added to a meta-analysis experiment." in response_data["detail"] + + def test_search_score_sets_no_match(session, data_provider, client, setup_router_db, data_files): experiment_1 = create_experiment(client, {"title": "Experiment 1"}) create_seq_score_set_with_variants( From a5c4943eb3e579a4390f549034964d746b100755 Mon Sep 17 00:00:00 2001 From: EstelleDa Date: Thu, 21 Nov 2024 12:08:09 +1100 Subject: [PATCH 2/3] Add some meta-analysis tests. --- tests/routers/test_score_set.py | 86 +++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/tests/routers/test_score_set.py b/tests/routers/test_score_set.py index f7ca5377..72604ca7 100644 --- a/tests/routers/test_score_set.py +++ b/tests/routers/test_score_set.py @@ -1085,6 +1085,92 @@ def test_cannot_add_score_set_to_meta_analysis_experiment(session, data_provider assert "Score sets may not be added to a meta-analysis experiment." in response_data["detail"] +def test_create_single_score_set_meta_analysis_to_others_score_set(session, data_provider, client, setup_router_db, data_files): + experiment = create_experiment(client) + score_set = create_seq_score_set_with_variants( + client, session, data_provider, experiment["urn"], data_files / "scores.csv" + ) + + score_set = (client.post(f"/api/v1/score-sets/{score_set['urn']}/publish")).json() + change_ownership(session, score_set["urn"], ScoreSetDbModel) + meta_score_set = create_seq_score_set_with_variants( + client, + session, + data_provider, + None, + data_files / "scores.csv", + update={"title": "Test Meta Analysis", "metaAnalyzesScoreSetUrns": [score_set["urn"]]}, + ) + + score_set_refresh = (client.get(f"/api/v1/score-sets/{score_set['urn']}")).json() + assert meta_score_set["metaAnalyzesScoreSetUrns"] == [score_set["urn"]] + assert score_set_refresh["metaAnalyzedByScoreSetUrns"] == [meta_score_set["urn"]] + assert isinstance(MAVEDB_TMP_URN_RE.fullmatch(meta_score_set["urn"]), re.Match) + + +def test_multiple_score_set_meta_analysis_single_experiment_with_different_creator( + session, data_provider, client, setup_router_db, data_files +): + experiment = create_experiment(client) + score_set_1 = create_seq_score_set_with_variants( + client, session, data_provider, experiment["urn"], data_files / "scores.csv", update={"title": "Score Set 1"} + ) + score_set_2 = create_seq_score_set_with_variants( + client, session, data_provider, experiment["urn"], data_files / "scores.csv", update={"title": "Score Set 2"} + ) + + score_set_1 = (client.post(f"/api/v1/score-sets/{score_set_1['urn']}/publish")).json() + score_set_2 = (client.post(f"/api/v1/score-sets/{score_set_2['urn']}/publish")).json() + + change_ownership(session, score_set_2["urn"], ScoreSetDbModel) + meta_score_set = create_seq_score_set_with_variants( + client, + session, + data_provider, + None, + data_files / "scores.csv", + update={"title": "Test Meta Analysis", "metaAnalyzesScoreSetUrns": [score_set_1["urn"], score_set_2["urn"]]}, + ) + score_set_1_refresh = (client.get(f"/api/v1/score-sets/{score_set_1['urn']}")).json() + assert meta_score_set["metaAnalyzesScoreSetUrns"] == sorted([score_set_1["urn"], score_set_2["urn"]]) + assert score_set_1_refresh["metaAnalyzedByScoreSetUrns"] == [meta_score_set["urn"]] + + meta_score_set = (client.post(f"/api/v1/score-sets/{meta_score_set['urn']}/publish")).json() + assert meta_score_set["urn"] == "urn:mavedb:00000001-0-1" + + +def test_multiple_score_set_meta_analysis_multiple_experiment_sets_with_different_creator( + session, data_provider, client, setup_router_db, data_files +): + experiment_1 = create_experiment(client, {"title": "Experiment 1"}) + experiment_2 = create_experiment(client, {"title": "Experiment 2"}) + score_set_1 = create_seq_score_set_with_variants( + client, session, data_provider, experiment_1["urn"], data_files / "scores.csv", update={"title": "Score Set 1"} + ) + score_set_2 = create_seq_score_set_with_variants( + client, session, data_provider, experiment_2["urn"], data_files / "scores.csv", update={"title": "Score Set 2"} + ) + + score_set_1 = (client.post(f"/api/v1/score-sets/{score_set_1['urn']}/publish")).json() + score_set_2 = (client.post(f"/api/v1/score-sets/{score_set_2['urn']}/publish")).json() + + change_ownership(session, score_set_2["urn"], ScoreSetDbModel) + meta_score_set = create_seq_score_set_with_variants( + client, + session, + data_provider, + None, + data_files / "scores.csv", + update={"title": "Test Meta Analysis", "metaAnalyzesScoreSetUrns": [score_set_1["urn"], score_set_2["urn"]]}, + ) + score_set_1_refresh = (client.get(f"/api/v1/score-sets/{score_set_1['urn']}")).json() + assert meta_score_set["metaAnalyzesScoreSetUrns"] == sorted([score_set_1["urn"], score_set_2["urn"]]) + assert score_set_1_refresh["metaAnalyzedByScoreSetUrns"] == [meta_score_set["urn"]] + + meta_score_set = (client.post(f"/api/v1/score-sets/{meta_score_set['urn']}/publish")).json() + assert meta_score_set["urn"] == "urn:mavedb:00000003-0-1" + + def test_search_score_sets_no_match(session, data_provider, client, setup_router_db, data_files): experiment_1 = create_experiment(client, {"title": "Experiment 1"}) create_seq_score_set_with_variants( From 039da08901ba32c0bcfb910a2e043158593d4463 Mon Sep 17 00:00:00 2001 From: EstelleDa Date: Fri, 13 Dec 2024 17:56:38 +1100 Subject: [PATCH 3/3] Add some more checks in meta-analysis tests. --- tests/routers/test_score_set.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/routers/test_score_set.py b/tests/routers/test_score_set.py index 15c251e9..c0d598fe 100644 --- a/tests/routers/test_score_set.py +++ b/tests/routers/test_score_set.py @@ -1071,6 +1071,7 @@ def test_publish_single_score_set_meta_analysis(session, data_provider, client, ) meta_score_set = (client.post(f"/api/v1/score-sets/{meta_score_set['urn']}/publish")).json() + assert isinstance(MAVEDB_SCORE_SET_URN_RE.fullmatch(meta_score_set["urn"]), re.Match) assert meta_score_set["urn"] == "urn:mavedb:00000001-0-1" @@ -1101,6 +1102,7 @@ def test_multiple_score_set_meta_analysis_single_experiment( assert score_set_1_refresh["metaAnalyzedByScoreSetUrns"] == [meta_score_set["urn"]] meta_score_set = (client.post(f"/api/v1/score-sets/{meta_score_set['urn']}/publish")).json() + assert isinstance(MAVEDB_SCORE_SET_URN_RE.fullmatch(meta_score_set["urn"]), re.Match) assert meta_score_set["urn"] == "urn:mavedb:00000001-0-1" @@ -1132,6 +1134,7 @@ def test_multiple_score_set_meta_analysis_multiple_experiment_sets( assert score_set_1_refresh["metaAnalyzedByScoreSetUrns"] == [meta_score_set["urn"]] meta_score_set = (client.post(f"/api/v1/score-sets/{meta_score_set['urn']}/publish")).json() + assert isinstance(MAVEDB_SCORE_SET_URN_RE.fullmatch(meta_score_set["urn"]), re.Match) assert meta_score_set["urn"] == "urn:mavedb:00000003-0-1" @@ -1165,6 +1168,7 @@ def test_multiple_score_set_meta_analysis_multiple_experiments( assert score_set_1_refresh["metaAnalyzedByScoreSetUrns"] == [meta_score_set["urn"]] meta_score_set = (client.post(f"/api/v1/score-sets/{meta_score_set['urn']}/publish")).json() + assert isinstance(MAVEDB_SCORE_SET_URN_RE.fullmatch(meta_score_set["urn"]), re.Match) assert meta_score_set["urn"] == "urn:mavedb:00000001-0-1" @@ -1254,6 +1258,9 @@ def test_multiple_score_set_meta_analysis_multiple_experiment_sets_different_sco assert meta_score_set_2["urn"] == "urn:mavedb:00000003-0-2" meta_score_set_3 = (client.post(f"/api/v1/score-sets/{meta_score_set_3['urn']}/publish")).json() assert meta_score_set_3["urn"] == "urn:mavedb:00000003-0-3" + assert isinstance(MAVEDB_SCORE_SET_URN_RE.fullmatch(meta_score_set_1["urn"]), re.Match) + assert isinstance(MAVEDB_SCORE_SET_URN_RE.fullmatch(meta_score_set_2["urn"]), re.Match) + assert isinstance(MAVEDB_SCORE_SET_URN_RE.fullmatch(meta_score_set_3["urn"]), re.Match) def test_cannot_add_score_set_to_meta_analysis_experiment(session, data_provider, client, setup_router_db, data_files): @@ -1336,6 +1343,7 @@ def test_multiple_score_set_meta_analysis_single_experiment_with_different_creat meta_score_set = (client.post(f"/api/v1/score-sets/{meta_score_set['urn']}/publish")).json() assert meta_score_set["urn"] == "urn:mavedb:00000001-0-1" + assert isinstance(MAVEDB_SCORE_SET_URN_RE.fullmatch(meta_score_set["urn"]), re.Match) def test_multiple_score_set_meta_analysis_multiple_experiment_sets_with_different_creator( @@ -1368,6 +1376,7 @@ def test_multiple_score_set_meta_analysis_multiple_experiment_sets_with_differen meta_score_set = (client.post(f"/api/v1/score-sets/{meta_score_set['urn']}/publish")).json() assert meta_score_set["urn"] == "urn:mavedb:00000003-0-1" + assert isinstance(MAVEDB_SCORE_SET_URN_RE.fullmatch(meta_score_set["urn"]), re.Match) ######################################################################################################################## # Score set search