Skip to content

Commit

Permalink
added psivec route
Browse files Browse the repository at this point in the history
  • Loading branch information
strasserle committed Dec 19, 2024
1 parent a6200ad commit 5f5c6a2
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 44 deletions.
48 changes: 48 additions & 0 deletions app/controllers/alternativeSplicing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from flask import abort
import app.models as models
from flask import Response
from app.config import db

def get_transcript_events(enst_number):
"""
Expand Down Expand Up @@ -91,3 +92,50 @@ def get_exons_for_position(start_pos: int, end_pos: int):
else:
abort(404, "No data found that satisfies the given filters")


def get_psi_values(transcript_ID: str = None, enst_number: str =None, psivec_ID: int = None, alternative_splicing_event_transcripts_ID: str = None, sample_ID: str = None, limit=100):
"""
This function response for the request: /alternativeSplicing/getPsiValue/
with the possibility to filter by psivec_ID, alternative
splicing event transcripts ID and sample ID
:param psivec_ID: ID of the psivec
:param alternative_splicing_event_transcripts_ID: ID of the alternative splicing event transcripts
:param sample_ID: ID of the sample
:return: psi value for the given parameters, ordered by psi value
"""
# Build the transcript query
transcript_query = db.select(models.Transcript.transcript_ID)
if transcript_ID:
transcript_query = transcript_query.where(models.Transcript.transcript_ID == transcript_ID)
if enst_number:
transcript_query = transcript_query.where(models.Transcript.enst_number == enst_number)

# Build the alternative splicing events query
as_query = db.select(models.AlternativeSplicingEventTranscripts.alternative_splicing_event_transcripts_ID).where(
models.AlternativeSplicingEventTranscripts.transcript_ID.in_(transcript_query)
)
if alternative_splicing_event_transcripts_ID:
as_query = as_query.where(
models.AlternativeSplicingEventTranscripts.alternative_splicing_event_transcripts_ID == alternative_splicing_event_transcripts_ID
)

# Build the psi values query
psi_query = db.select(models.PsiVec).where(
models.PsiVec.alternative_splicing_event_transcripts_ID.in_(as_query)
)
if psivec_ID:
psi_query = psi_query.where(models.PsiVec.psivec_ID == psivec_ID)
if sample_ID:
psi_query = psi_query.where(models.PsiVec.sample_ID == sample_ID)

# Apply limit and sort results
psi_query = psi_query.order_by(models.PsiVec.psi_value.desc()).limit(limit)

psi_values = db.session.execute(psi_query).scalars().all()

if psi_values:
schema = models.PsiVecSchema(many=True)
return schema.dump(psi_values)
else:
abort(404, "No data found that satisfies the given filters")

24 changes: 24 additions & 0 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,22 @@ class GseaRankingGenes(db.Model):
gene_ID = db.Column(db.Integer, db.ForeignKey('gene.gene_ID'))
gene_symbol = relationship("Gene", foreign_keys=[gene_ID])

class PsiVec(db.Model):
__tablename__ = 'psivec'
psivec_ID = db.Column(db.Integer, primary_key=True)

alternative_splicing_event_transcripts_ID = db.Column(db.Integer, db.ForeignKey('alternative_splicing_event_transcripts.alternative_splicing_event_transcripts_ID'), nullable=False)
alternative_splicing_event_transcripts = relationship("AlternativeSplicingEventTranscripts", foreign_keys=[alternative_splicing_event_transcripts_ID])

sample_ID = db.Column(db.String(32))
psi_value = db.Column(db.Float)



####################################
############# SCHEMAS ##############
####################################

class DatasetSchema(ma.SQLAlchemyAutoSchema):
class Meta:
model = Dataset
Expand Down Expand Up @@ -1158,3 +1174,11 @@ class Meta:

dataset_1 = ma.Nested(DatasetSchema)
dataset_2 = ma.Nested(DatasetSchema)

class PsiVecSchema(ma.SQLAlchemyAutoSchema):
class Meta:
model = PsiVec
sqla_session = db.session

alternative_splicing_event_transcripts = ma.Nested(AlternativeSplicingEventsTranscriptsSchema)

109 changes: 65 additions & 44 deletions swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,50 +74,6 @@ paths:
sponge_db_version:
type: integer
description: SPONGEdb version used
# /dataset:
# get:
# operationId: dataset.read
# tags:
# - Dataset
# summary: Get information about all cancer types/datasets or specific one.
# description: Get information about all available datasets to start browsing or search for a specific cancer type/dataset.
# parameters:
# - $ref: '#/components/parameters/VersionParam'
# - name: disease_name
# in: query
# description: Name of the specific cancer type/dataset. Fuzzy search is available (e.g. "kidney clear cell carcinoma" or just "kidney").
# required: false
# schema:
# type: string
# responses:
# "200":
# description: Successfully read information about all cancer types/datasets or specific one from database.
# content:
# application/json:
# schema:
# type: object
# properties:
# dataset_ID:
# type: integer
# description: Internal database ID of the cancer type/dataset.
# disease_name:
# type: string
# description: Name of the cancer type/dataset.
# data_origin:
# type: string
# description: Cancer type/dataset origin (database name, etc.).
# disease_type:
# type: string
# description: Type of the disease (e.g. cancer).
# download_url:
# type: string
# description: URL to cancer type/dataset annotation.
# disease_subtype:
# type: string
# description: Subtype of specific cancer type (NA if no relevant subtype is present)
# sponge_db_version:
# type: integer
# description: SPONGEdb version used
/dataset/spongeRunInformation:
get:
operationId: dataset.read_spongeRunInformation
Expand Down Expand Up @@ -3481,6 +3437,71 @@ paths:
ense_number:
type: string
description: Ense number of the exon.
/alternativeSplicing/getPsiValues:
get:
operationId: alternativeSplicing.get_psi_values
tags:
- AlternativeSplicing
summary: Retrieve all psi values for a specific event type of a transcript of interest.
description: Retrieve all psi values for a specific event type of a transcript of interest.
parameters:
- name: transcript_ID
in: query
description: Internal database ID of the transcript of interest.
required: false
schema:
type: integer
- name: enst_number
in: query
description: A enst number of a transcript of interest (e.g. ENST00000387314)
required: false
schema:
type: string
- name: psivec_ID
in: query
description: Internal database ID of the psi values of the transcript of interest.
required: false
schema:
type: integer
- name: alternative_splicing_event_transcripts_ID
in: query
description: Internal database ID of the alternative splicing event transcripts of the transcript of interest.
required: false
schema:
type: integer
- name: sample_ID
in: query
description: A sample ID to filter for
schema:
type: string
required: false
- name: limit
in: query
description: Limit the number of results. Defaults to 100.
schema:
type: integer
required: false
responses:
"200":
description: Retrieve all psi values for a specific event type of a transcript of interest.
content:
application/json:
schema:
type: array
items:
properties:
psivec_ID:
type: integer
description: Internal database ID of the psi values of the transcript of interest.
alternative_splicing_event_transcripts_ID:
type: integer
description: Internal database ID of the alternative splicing event transcripts of the transcript of interest.
sample_ID:
type: string
description: ID of the specific sample.
psi_value:
type: number
description: Psi value of the specific event type.
/spongEffects/getSpongEffectsRuns:
get:
operationId: spongEffects.get_spongeffects_runs
Expand Down

0 comments on commit 5f5c6a2

Please sign in to comment.