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

#140. Develop "study" endpoint #148

Open
wants to merge 5 commits into
base: release/2023-05
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion api/db/dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from itertools import chain
from typing import get_args, get_origin

from config import CONFIG
from config import CONFIG, cache_if_enabled
from db.suggestion_handler import suggestion_request_builder
from entities import entities
from models.gene import (
Expand Down
2 changes: 1 addition & 1 deletion api/endpoints/gene.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pandas as pd
from typing import List

from config import Language
from config import Language, cache_if_enabled
from db.dao import GeneDAO, GeneSuggestionDAO, TaxonDAO

from fastapi import APIRouter, Depends, HTTPException, Query
Expand Down
92 changes: 84 additions & 8 deletions api/endpoints/research.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,46 @@
IncreaseLifespanSearchInput,
IncreaseLifespanSearchOutput,
OtherEvidenceResearchedOutput,
StudySearchByExperimentInput
)

router = APIRouter()


@router.get('/research/lifespan-change', response_model=IncreaseLifespanSearchOutput)

@router.get('/lifespan-change', response_model=IncreaseLifespanSearchOutput)
@cache_if_enabled

async def increase_lifespan_search(
input: IncreaseLifespanSearchInput = Depends(IncreaseLifespanSearchInput),
) -> List:
return ResearchesDAO().increase_lifespan_search(input)


@router.get('/research/age-related-changes', response_model=AgeRelatedChangeOfGeneResearchOutput)
@router.get('/age-related-changes', response_model=AgeRelatedChangeOfGeneResearchOutput)
@cache_if_enabled

async def age_related_changes_search(input: GeneSearchInput = Depends(GeneSearchInput)) -> List:
return ResearchesDAO().age_related_changes(input)


@router.get(
'/research/gene-activity-change-impact', response_model=GeneActivityChangeImpactResearchedOutput
'/gene-activity-change-impact', response_model=GeneActivityChangeImpactResearchedOutput
)
@cache_if_enabled
async def gene_activity_change_impact(input: GeneSearchInput = Depends(GeneSearchInput)) -> List:
return ResearchesDAO().gene_activity_change_impact(input)


@router.get('/research/gene-regulation', response_model=GeneRegulationResearchedOutput)

@router.get('/gene-regulation', response_model=GeneRegulationResearchedOutput)
@cache_if_enabled

async def gene_regulation(input: GeneSearchInput = Depends(GeneSearchInput)) -> List:
return ResearchesDAO().gene_regulation(input)


@router.get(
'/research/association-with-accelerated-aging',
'/association-with-accelerated-aging',
response_model=AssociationWithAcceleratedAgingResearchedOutput,
)
@cache_if_enabled
Expand All @@ -58,14 +63,85 @@ async def association_with_accelerated_aging(


@router.get(
'/research/associations-with-lifespan', response_model=AssociationsWithLifespanResearchedOutput
'/associations-with-lifespan', response_model=AssociationsWithLifespanResearchedOutput
)
@cache_if_enabled
async def associations_with_lifespan(input: GeneSearchInput = Depends(GeneSearchInput)) -> List:
return ResearchesDAO().associations_with_lifespan(input)


@router.get('/research/other-evidence', response_model=OtherEvidenceResearchedOutput)
@router.get('/other-evidence', response_model=OtherEvidenceResearchedOutput)
@cache_if_enabled

async def other_evidence(input: GeneSearchInput = Depends(GeneSearchInput)) -> List:
return ResearchesDAO().other_evidence(input)


@router.get('/lifespan-change/{id}', response_model=IncreaseLifespanSearchOutput)
async def increase_lifespan_search_by_experiment(
input: StudySearchByExperimentInput = Depends(StudySearchByExperimentInput),
) -> List:
"Filtered by general_lifespan_experiment.id"
input._filters['id'] = input._filters['general_lifespan_experiment_id']
return ResearchesDAO().increase_lifespan_search(input)


@router.get('/age-related-changes/{id}', response_model=AgeRelatedChangeOfGeneResearchOutput)
async def age_related_changes_search_by_experiment(
input: StudySearchByExperimentInput = Depends(StudySearchByExperimentInput)
) -> List:
"Filtered by age_related_change.id"
input._filters['id'] = input._filters['age_related_change_id']
return ResearchesDAO().age_related_changes(input)


@router.get(
'/gene-activity-change-impact/{id}', response_model=GeneActivityChangeImpactResearchedOutput
)
async def gene_activity_change_impact_by_experiment(
input: StudySearchByExperimentInput = Depends(StudySearchByExperimentInput)
) -> List:
"Filtered by gene_intervention_to_vital_process.id"
input._filters['id'] = input._filters['gene_intervention_to_vital_process_id']
return ResearchesDAO().gene_activity_change_impact(input)


@router.get('/gene-regulation/{id}', response_model=GeneRegulationResearchedOutput)
async def gene_regulation(
input: StudySearchByExperimentInput = Depends(StudySearchByExperimentInput)
) -> List:
"Filtered by protein_activity.id"
input._filters['id'] = input._filters['protein_activity_id']
return ResearchesDAO().gene_regulation(input)


@router.get(
'/association-with-accelerated-aging/{id}',
response_model=AssociationWithAcceleratedAgingResearchedOutput,
)
async def association_with_accelerated_aging(
input: StudySearchByExperimentInput = Depends(StudySearchByExperimentInput)
) -> List:
"Filtered by progeria_syndrome.id"
input._filters['id'] = input._filters['progeria_syndrome_id']
return ResearchesDAO().association_with_accelerated_aging(input)


@router.get(
'/associations-with-lifespan/{id}', response_model=AssociationsWithLifespanResearchedOutput
)
async def associations_with_lifespan(
input: StudySearchByExperimentInput = Depends(StudySearchByExperimentInput)
) -> List:
"Filtered by longevity_effect.id"
input._filters['id'] = input._filters['longevity_effect_id']
return ResearchesDAO().associations_with_lifespan(input)


@router.get('/other-evidence/{id}', response_model=OtherEvidenceResearchedOutput)
async def other_evidence(
input: StudySearchByExperimentInput = Depends(StudySearchByExperimentInput)
) -> List:
"Filtered by longevity_effect.id"
input._filters['id'] = input._filters['gene_to_additional_evidence_id']
return ResearchesDAO().other_evidence(input)
3 changes: 2 additions & 1 deletion api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def assembling_endpoints(app: FastAPI):
)
app.include_router(
research.router,
tags=["research"],
prefix='/study',
tags=["study"],
)


Expand Down
15 changes: 15 additions & 0 deletions api/models/researches.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,21 @@ class IncreaseLifespanSearchInput(PaginationInput, LanguageInput, SortInput):
}


class StudySearchByExperimentInput(LanguageInput, PaginationInput):
id: int
isHidden: str = 1
_filters = {
'id': None,
'general_lifespan_experiment_id':[lambda value: 'general_lifespan_experiment.id=%s', lambda value: [value]],
'age_related_change_id':[lambda value: 'age_related_change.id=%s', lambda value: [value]],
'gene_intervention_to_vital_process_id':[lambda value: 'gene_intervention_to_vital_process.id=%s', lambda value: [value]],
'protein_activity_id':[lambda value: 'protein_activity.id=%s', lambda value: [value]],
'progeria_syndrome_id':[lambda value: 'progeria_syndrome.id=%s', lambda value: [value]],
'longevity_effect_id':[lambda value: 'longevity_effect.id=%s', lambda value: [value]],
'gene_to_additional_evidence_id':[lambda value: 'gene_to_additional_evidence.id=%s', lambda value: [value]],
}


class IncreaseLifespanSearched(IncreaseLifespan):
geneId: int
geneNcbiId: int | None
Expand Down