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

G3-428 get geneset endpoint modification to support multiple score types #95

Merged
merged 1 commit into from
Sep 5, 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
878 changes: 445 additions & 433 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "geneweaver-api"
version = "0.8.1a0"
version = "0.8.1a1"
description = "The Geneweaver API"
authors = [
"Alexander Berger <[email protected]>",
Expand All @@ -20,7 +20,7 @@ python = "^3.9"
geneweaver-core = "^0.10.0a3"
fastapi = {extras = ["all"], version = "^0.111.0"}
uvicorn = {extras = ["standard"], version = "^0.30.0"}
geneweaver-db = "0.5.0a16"
geneweaver-db = "0.5.0a17"
psycopg-pool = "^3.1.7"
requests = "^2.32.3"
python-jose = {extras = ["cryptography"], version = "^3.3.0"}
Expand Down
2 changes: 1 addition & 1 deletion src/geneweaver/api/controller/genesets.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def get_visible_genesets(
with_publication_info: Annotated[
bool, Query(description=api_message.ONLY_MY_GS)
] = True,
score_type: Optional[ScoreType] = None,
score_type: Annotated[Optional[Set[ScoreType]], Query()] = None,
size_less_than: Annotated[
Optional[int],
Query(
Expand Down
4 changes: 2 additions & 2 deletions src/geneweaver/api/services/geneset.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def get_visible_genesets(
search_text: Optional[str] = None,
ontology_term: Optional[str] = None,
with_publication_info: bool = True,
score_type: Optional[ScoreType] = None,
score_type: Optional[Set[ScoreType]] = None,
lte_count: Optional[int] = None,
gte_count: Optional[int] = None,
created_after: Optional[date] = None,
Expand All @@ -118,7 +118,7 @@ def get_visible_genesets(
:param search_text: Return genesets that match this search text (using PostgreSQL
full-text search).
:param ontology_term: Show only results associated with this ontology term.
:param score_type: Show only results with given score type.
:param score_type: Show only results for given score type(s).
:param lte_count: less than or equal geneset count.
:param gte_count: greater than or equal geneset count.
:param updated_before: Show only results updated before this date.
Expand Down
39 changes: 30 additions & 9 deletions tests/controllers/test_genesets.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,17 +401,45 @@ def test_delete_geneset_ontology_terms_errors(mock_delete_genenset_onto_terms, c
assert response.status_code == 404


@pytest.mark.parametrize("score_type", ["1", "binary"])
@pytest.mark.parametrize(
"score_type",
[
"score_type=p-value",
"score_type=q-value",
"score_type=effect",
"score_type=correlation",
"score_type=binary",
"score_type=p-value&score_type=q-value",
"score_type=p-value&score_type=q-value&score_type=effect",
"score_type=p-value&score_type=q-value&score_type=effect&score_type=correlation",
"score_type=p-value&score_type=q-value&score_type=effect&score_type=correlation&score_type=binary",
],
)
@patch("geneweaver.api.services.geneset.get_visible_genesets")
def test_get_geneset_by_score_type(mock_get_visible_genesets, score_type, client):
"""Test get geneset data response."""
mock_get_visible_genesets.return_value = geneset_by_id_resp.get("geneset")

response = client.get("/api/genesets?score_type=" + score_type)
response = client.get("/api/genesets?" + score_type)
assert response.status_code == 200
assert response.json() == geneset_by_id_resp.get("geneset")


@pytest.mark.parametrize(
"score_type",
["score_type=1233", "score_type=test", "score_type=p-value&score_type=test"],
)
@patch("geneweaver.api.services.geneset.get_visible_genesets")
def test_get_geneset_by_invalid_score_type(
mock_get_visible_genesets, score_type, client
):
"""Test get geneset data response."""
mock_get_visible_genesets.return_value = geneset_by_id_resp.get("geneset")

response = client.get("/api/genesets?" + score_type)
assert response.status_code == 422


@patch("geneweaver.api.services.geneset.get_visible_genesets")
def test_get_geneset_by_create_date(mock_get_visible_genesets, client):
"""Test get geneset data response."""
Expand All @@ -436,13 +464,6 @@ def test_get_geneset_by_update_date(mock_get_visible_genesets, client):
assert response.json() == geneset_by_id_resp.get("geneset")


@pytest.mark.parametrize("score_type", ["2342", "test"])
def test_invalid_score_type(score_type, client):
"""Test general get geneset data no parameters -- default limit."""
response = client.get("/api/genesets?score_type=" + score_type)
assert response.status_code == 422


@pytest.mark.parametrize("created_before", ["20-23-20", "08-01-2023", "80/01/2022"])
@pytest.mark.parametrize("created_after", ["20-23-20", "08-01-2023", "80/01/2022"])
def test_invalid_create_date_params(created_before, created_after, client):
Expand Down
29 changes: 28 additions & 1 deletion tests/services/test_genset.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def test_visible_geneset_all_expected_parameters(mock_db_geneset):
abbreviation="test",
publication_id=123,
pubmed_id="p123",
score_type=ScoreType("p-value"),
score_type={ScoreType("p-value"), ScoreType("q-value")},
lte_count=50,
gte_count=5,
gene_id_type=GeneIdentifier(5),
Expand Down Expand Up @@ -636,3 +636,30 @@ def test_delete_geneset_ontology_term_errors(mock_db_ontology, mock_db_geneset):
geneset.delete_geneset_ontology_term(
cursor=None, user=mock_user, geneset_id=1234, term_ref_id="D001921"
)


@patch("geneweaver.api.services.geneset.db_geneset")
@pytest.mark.parametrize(
"score_type",
[
None,
{ScoreType.P_VALUE},
{ScoreType.P_VALUE, ScoreType.Q_VALUE},
{ScoreType.P_VALUE, ScoreType.Q_VALUE, ScoreType.EFFECT},
{ScoreType.P_VALUE, ScoreType.Q_VALUE, ScoreType.EFFECT, ScoreType.CORRELATION},
{
ScoreType.P_VALUE,
ScoreType.Q_VALUE,
ScoreType.EFFECT,
ScoreType.CORRELATION,
ScoreType.BINARY,
},
],
)
def test_get_geneset_by_score_type(mock_db_geneset, score_type):
"""Test get geneset by score type."""
mock_db_geneset.get.return_value = geneset_list_resp

response = geneset.get_visible_genesets(None, mock_user, score_type=score_type)

assert response.get("data") == geneset_list_resp
Loading