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 325 api genset endpoint update #89

Merged
merged 3 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
642 changes: 352 additions & 290 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.0a2"
version = "0.8.0a3"
description = "The Geneweaver API"
authors = [
"Alexander Berger <alexander.berger@jax.org>",
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.0a15"
geneweaver-db = "0.5.0a16"
psycopg-pool = "^3.1.7"
requests = "^2.32.3"
python-jose = {extras = ["cryptography"], version = "^3.3.0"}
Expand Down
37 changes: 34 additions & 3 deletions src/geneweaver/api/controller/genesets.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Endpoints related to genesets."""

import json
import time
from datetime import date, datetime
from tempfile import TemporaryDirectory
from typing import Optional, Set

Expand All @@ -13,7 +13,7 @@
from geneweaver.api.services import geneset as genset_service
from geneweaver.api.services import publications as publication_service
from geneweaver.core.enum import GeneIdentifier, GenesetTier, Species
from geneweaver.core.schema.score import GenesetScoreType
from geneweaver.core.schema.score import GenesetScoreType, ScoreType
from typing_extensions import Annotated

from . import message as api_message
Expand Down Expand Up @@ -69,6 +69,29 @@ def get_visible_genesets(
with_publication_info: Annotated[
bool, Query(description=api_message.ONLY_MY_GS)
] = True,
score_type: Optional[ScoreType] = None,
size_less_than: Annotated[
Optional[int],
Query(
format="int64",
minimum=0,
maxiumum=9223372036854775807,
description=api_message.GENESET_SIZE,
),
] = None,
size_greater_than: Annotated[
Optional[int],
Query(
format="int64",
minimum=0,
maxiumum=9223372036854775807,
description=api_message.GENESET_SIZE,
),
] = None,
created_after: Annotated[date, Query(description=api_message.CREATE_DATE)] = None,
created_before: Annotated[date, Query(description=api_message.CREATE_DATE)] = None,
updated_after: Annotated[date, Query(description=api_message.UPDATE_DATE)] = None,
updated_before: Annotated[date, Query(description=api_message.UPDATE_DATE)] = None,
limit: Annotated[
Optional[int],
Query(
Expand Down Expand Up @@ -104,6 +127,13 @@ def get_visible_genesets(
with_publication_info=with_publication_info,
ontology_term=ontology_term,
only_my_genesets=only_my_genesets,
score_type=score_type,
lte_count=size_less_than,
gte_count=size_greater_than,
created_after=created_after,
created_before=created_before,
updated_after=updated_after,
updated_before=updated_before,
limit=limit,
offset=offset,
)
Expand Down Expand Up @@ -190,7 +220,8 @@ def get_export_geneset_by_id_type(
gene_id_type: Optional[GeneIdentifier] = None,
) -> StreamingResponse:
"""Export geneset into JSON file. Search by ID and optional gene identifier type."""
timestr = time.strftime("%Y%m%d-%H%M%S")
current_datetime = datetime.now()
timestr = current_datetime.strftime("%Y%m%d-%H%M%S")

# Validate gene identifier type
if gene_id_type:
Expand Down
3 changes: 3 additions & 0 deletions src/geneweaver/api/controller/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@
)
CHECK_DB_HEALTH = "Check DB health flag"
ONTOLOGY_ID = "Ontology term reference ID"
CREATE_DATE = "Create date limit (before or after). E.g. 2024-08-01"
UPDATE_DATE = "Update date limit (before or after). E.g. 2023-07-01"
GENESET_SIZE = "Geneset size (Genes count)"
26 changes: 24 additions & 2 deletions src/geneweaver/api/services/geneset.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""Service functions for dealing with genesets."""

from datetime import date
from typing import Iterable, Optional, Set

from fastapi.logger import logger
from geneweaver.api.controller import message
from geneweaver.api.core.exceptions import UnauthorizedException
from geneweaver.api.schemas.auth import AppRoles, User
from geneweaver.core.enum import GeneIdentifier, GenesetTier, Species
from geneweaver.core.schema.score import GenesetScoreType
from geneweaver.core.schema.score import GenesetScoreType, ScoreType
from geneweaver.db import gene as db_gene
from geneweaver.db import geneset as db_geneset
from geneweaver.db import geneset_value as db_geneset_value
Expand Down Expand Up @@ -90,9 +91,16 @@ def get_visible_genesets(
gene_id_type: Optional[GeneIdentifier] = None,
search_text: Optional[str] = None,
ontology_term: Optional[str] = None,
with_publication_info: bool = True,
score_type: Optional[ScoreType] = None,
lte_count: Optional[int] = None,
gte_count: Optional[int] = None,
created_after: Optional[date] = None,
created_before: Optional[date] = None,
updated_after: Optional[date] = None,
updated_before: Optional[date] = None,
limit: Optional[int] = None,
offset: Optional[int] = None,
with_publication_info: bool = True,
) -> dict:
"""Get genesets from the database.

Expand All @@ -110,6 +118,13 @@ 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 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.
:param updated_after: Show only results updated after this date.
:param created_before: Show only results created before this date.
:param created_after: Show only results updated before this date.
:param limit: Limit the number of results.
:param offset: Offset the results.
:param with_publication_info: Include publication info in the return.
Expand All @@ -134,6 +149,13 @@ def get_visible_genesets(
search_text=search_text,
with_publication_info=with_publication_info,
ontology_term=ontology_term,
score_type=score_type,
lte_count=lte_count,
gte_count=gte_count,
created_after=created_after,
created_before=created_before,
updated_after=updated_after,
updated_before=updated_before,
limit=limit,
offset=offset,
)
Expand Down
10 changes: 9 additions & 1 deletion tests/services/test_genset.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Tests for geneset Service."""

import datetime
from unittest.mock import patch

import pytest
Expand All @@ -8,7 +9,7 @@
from geneweaver.api.schemas.auth import AppRoles, User
from geneweaver.api.services import geneset
from geneweaver.core.enum import GeneIdentifier, GenesetTier, Species
from geneweaver.core.schema.score import GenesetScoreType
from geneweaver.core.schema.score import GenesetScoreType, ScoreType

from tests.data import test_geneset_data

Expand Down Expand Up @@ -258,7 +259,14 @@ def test_visible_geneset_all_expected_parameters(mock_db_geneset):
abbreviation="test",
publication_id=123,
pubmed_id="p123",
score_type=ScoreType("p-value"),
lte_count=50,
gte_count=5,
gene_id_type=GeneIdentifier(5),
created_before=datetime.datetime(2024, 7, 31),
created_after=datetime.datetime(2008, 7, 31),
updated_before=datetime.datetime(2024, 7, 31),
updated_after=datetime.datetime(2023, 7, 31),
limit=10,
offset=0,
with_publication_info=True,
Expand Down
Loading