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

Estelle/test meta analysis #365

Merged
merged 4 commits into from
Dec 17, 2024
Merged
Changes from 3 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
113 changes: 113 additions & 0 deletions tests/routers/test_score_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,119 @@ 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_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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In so far as we check the URNs of test objects, I think we only need to check that the URN matches the URN RegEx.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the RegEx checks to all meta-analysis tests, but I support keeping them cause the meta-analysis urn is more special. This way is more accurate. RegEx only confirms they match the basic rules, but can't make sure the middle one is number 0 or letters.



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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same RegEx comment as above.


########################################################################################################################
# Score set search
########################################################################################################################
Expand Down
Loading