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

dataset_ID param #19

Merged
merged 12 commits into from
Dec 10, 2024
2 changes: 1 addition & 1 deletion TestCases/test_findceRNA.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_read_all_gene_network_analysis(disease_name=None, ensg_number=None, gen
if gene_type is not None:
queries.append(models.Gene.gene_type == gene_type)
if db_version is not None:
queries.append(models.Dataset.version == db_version)
queries.append(models.Dataset.sponge_db_version == db_version)

# add all sorting if given:
sort = [models.networkAnalysis.sponge_run_ID]
Expand Down
2 changes: 1 addition & 1 deletion TestCases/test_getGeneExpression.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_get_gene_expr(disease_name=None, ensg_number=None, gene_symbol=None, db
if disease_name is not None:
dataset = models.Dataset.query \
.filter(models.Dataset.disease_name.like("%" + disease_name + "%")) \
.filter(models.Dataset.version == db_version) \
.filter(models.Dataset.sponge_db_version == db_version) \
.all()

if len(dataset) > 0:
Expand Down
2 changes: 1 addition & 1 deletion TestCases/test_miRNAInteraction_getOccurences.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_read_all_mirna(disease_name=None, mimat_number=None, hs_number=None, oc

# database version
if db_version is not None:
queries.append(models.Dataset.version == db_version)
queries.append(models.Dataset.sponge_db_version == db_version)

if occurences is not None:
queries.append(models.OccurencesMiRNA.occurences > occurences)
Expand Down
4 changes: 2 additions & 2 deletions alternativeSplicing.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def get_event_positions(enst_number, event_type):

def get_exons_for_position(start_pos: int, end_pos: int):
"""
This function response for the request: /sponge//alternativeSplicing/getExonsForPosition/
This function response for the request: /alternativeSplicing/getExonsForPosition/
with genomic start and end positions
:param start_pos: genomic start position
:param end_pos: genomic end position
Expand All @@ -86,7 +86,7 @@ def get_exons_for_position(start_pos: int, end_pos: int):
.filter(models.TranscriptElement.transcript_element_positions_ID.in_(transcript_element_positions_ids)) \
.all()
if len(result) > 0:
schema = models.networkAnalysisSchema(many=True)
schema = models.TranscriptElementSchema(many=True)
return schema.dump(result)
else:
abort(404, "No data found that satisfies the given filters")
Expand Down
33 changes: 18 additions & 15 deletions comparison.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
from flask import abort
import models
from config import LATEST
from config import LATEST, db

def get_comparison(disease_name=None, disease_subtype=None, sponge_db_version: int = LATEST):
def get_comparison(dataset_ID: str = None, disease_name: str = None, disease_subtype=None, sponge_db_version: int = LATEST):
"""
:param dataset_ID: ID of the dataset to find
:param disease_name: disease name of one part of the comparison (e.g. Sarcoma)
:param disease_subtype: subtype of the same part of the comparison, overtype if none is provided (e.g. LMS)
:param sponge_db_version: version of the database
:return: all comparisons which contain the given disease name and subtype combination
"""

# if specific disease_name is given:
dataset = models.Dataset.query.filter(models.Dataset.sponge_db_version == sponge_db_version)
# get dataset table
query = db.select(models.Dataset)

# do filtering
if dataset_ID is not None:
query = query.where(models.Dataset.dataset_ID == dataset_ID)
if disease_name is not None:
dataset = dataset.filter(models.Dataset.disease_name.like("%" + disease_name + "%"))

if disease_subtype is None:
dataset = dataset.filter(models.Dataset.disease_subtype.is_(None))
else:
dataset = dataset.filter(models.Dataset.disease_subtype.like("%" + disease_subtype + "%"))
query = query.where(models.Dataset.disease_name.like("%" + disease_name + "%"))
if disease_subtype is None:
query = query.where(models.Dataset.disease_subtype.is_(None))
else:
query = query.where(models.Dataset.disease_subtype.like("%" + disease_subtype + "%"))

dataset = dataset.all()
data = db.session.execute(query).scalars().all()

dataset = [x.dataset_ID for x in dataset]
dataset = [i.dataset_ID for i in data]

if len(dataset) == 0:
abort(404, "No dataset with given disease_name found")

result = models.Comparison.query \
.filter(models.Comparison.dataset_ID_1.in_(dataset) | models.Comparison.dataset_ID_2.in_(dataset)) \
.all()
comparison_query = db.select(models.Comparison).where(models.Comparison.dataset_ID_1.in_(dataset) | models.Comparison.dataset_ID_2.in_(dataset))

result = db.session.execute(comparison_query).scalars().all()

if len(result) > 0:
return models.ComparisonSchema(many=True).dump(result)
Expand Down
126 changes: 75 additions & 51 deletions dataset.py
Original file line number Diff line number Diff line change
@@ -1,79 +1,103 @@
from flask import abort
import models
from config import LATEST
from config import LATEST, db


def get_datasets(data_origin=None, sponge_db_version: int = LATEST):
def _dataset_query(query = None, sponge_db_version = LATEST, **kwargs):

if query is None:
query = db.select(models.Dataset)
for key, value in kwargs.items():
if type(value) == str:
query = query.where(getattr(models.Dataset, key).like("%" + value + "%"))
elif type(value) == int:
query = query.where(getattr(models.Dataset, key) == value)
elif type(value) == list:
query = query.where(getattr(models.Dataset, key).in_(value))
elif value is None:
if key == 'disease_subtype':
query = query.where(models.Dataset.disease_subtype.is_(None))
else:
continue
else:
abort(404, "Unknown input type")

query = query.where(models.Dataset.sponge_db_version == sponge_db_version)
data = db.session.execute(query).scalars().all()

if len(data) == 0:
abort(404, "No dataset found for given inputs")

return data


def get_datasets(dataset_ID: int = None, disease_name: str = None, data_origin=None, sponge_db_version: int = LATEST):
"""
This function responds to a request for /sponge/datasets?data_origin={data_origin}&version={version}
with one matching entry to the specified data_origin
This function responds to a request for /sponge/datasets?data_origin={data_origin}&sponge_db_version={version}
with one matching entry to the specified data_origin

:param data_origin: name of the data source
:param sponge_db_version: version of the database
:return: all datasets that match the source (e.g. TCGA)
:param dataset_id: ID of the dataset to find
:param disease_name: name of the dataset to find
:param data_origin: name of the data source
:param sponge_db_version: version of the database
:return: all datasets that match the source (e.g. TCGA)
"""
if data_origin is None:
# Create the list of people from our data
data = models.Dataset.query \
.all()
else:
# Get the dataset requested
data = models.Dataset.query \
.filter(models.Dataset.data_origin.like("%" + data_origin + "%")) \
.filter(models.Dataset.sponge_db_version == sponge_db_version) \
.all()
# Query dataset table
query = db.select(models.Dataset)

data = _dataset_query(query, sponge_db_version, dataset_ID=dataset_ID, disease_name=disease_name, data_origin=data_origin)

# Did we find a source?
if len(data) > 0:
# Serialize the data for the response
return models.DatasetSchema(many=True).dump(data)
else:
abort(404, 'No data found for name: {data_origin}'.format(data_origin=data_origin))
abort(404, 'No data found for \
name: {data_origin}'.format(data_origin=data_origin))

def read(disease_name=None, sponge_db_version: int = LATEST):
"""
This function responds to a request for /sponge/dataset/?disease_name={disease_name}&version={version}
with one matching entry to the specified disease_name

:param disease_name: name of the dataset to find (if not given, all available datasets will be shown)
:param sponge_db_version: version of the database
:return: dataset matching ID
"""

if disease_name is None:
# Create the list of people from our data
data = models.Dataset.query \
.all()
else:
# Get the dataset requested
data = models.Dataset.query \
.filter(models.Dataset.disease_name.like("%" + disease_name + "%")) \
.filter(models.Dataset.sponge_db_version == sponge_db_version) \
.all()
# def read(disease_name=None, sponge_db_version: int = LATEST):
# """
# This function responds to a request for /sponge/dataset/?disease_name={disease_name}&version={version}
# with one matching entry to the specified disease_name

# Did we find a dataset?
if len(data) > 0:
# Serialize the data for the response
return models.DatasetSchema(many=True).dump(data)
else:
abort(404, 'No data found for name: {disease_name}'.format(disease_name=disease_name))
# :param disease_name: name of the dataset to find (if not given, all available datasets will be shown)
# :param sponge_db_version: version of the database
# :return: dataset matching ID
# """

# if disease_name is None:
# # Create the list of people from our data
# query = models.Dataset.query
# else:
# # Get the dataset requested
# query = models.Dataset.query \
# .filter(models.Dataset.disease_name.like("%" + disease_name + "%"))

# # filter for db version
# data = query.filter(models.Dataset.sponge_db_version == sponge_db_version) \
# .all()

# # Did we find a dataset?
# if len(data) > 0:
# # Serialize the data for the response
# return models.DatasetSchema(many=True).dump(data)
# else:
# abort(404, 'No data found for name: {disease_name}'.format(disease_name=disease_name))


def read_spongeRunInformation(disease_name=None, sponge_db_version: int = LATEST):
def read_spongeRunInformation(dataset_ID: int = None, disease_name: str = None, sponge_db_version: int = LATEST):
"""
This function responds to a request for /sponge/spongeRunInformation/?disease_name={disease_name}&version={version}
This function responds to a request for /sponge/dataset/spongeRunInformation/?disease_name={disease_name}&sponge_db_version={sponge_db_version}
with a matching entry to the specifed diesease_name

:param disease_name: name of the dataset to find (if not given, all available datasets will be shown)
:param sponge_db_version: sponge_db_version of the database
:return: all available runs + information for disease of interest
"""

data = models.SpongeRun.query \
.join(models.Dataset, models.SpongeRun.dataset_ID == models.Dataset.dataset_ID) \
.filter(models.Dataset.disease_name.like("%" + disease_name + "%")) \
.filter(models.Dataset.sponge_db_version == sponge_db_version) \
.all()
query = db.select(models.SpongeRun).join(models.Dataset, models.SpongeRun.dataset_ID == models.Dataset.dataset_ID)

data = _dataset_query(query, sponge_db_version, dataset_ID=dataset_ID, disease_name=disease_name)

if len(data) > 0:
# Serialize the data for the response
Expand Down
46 changes: 31 additions & 15 deletions expressionValues.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from flask import abort
import models
from config import LATEST
from config import LATEST, db

def get_gene_expr(disease_name=None, ensg_number=None, gene_symbol=None, sponge_db_version: int = LATEST):
def get_gene_expr(dataset_ID: int = None, disease_name=None, ensg_number=None, gene_symbol=None, sponge_db_version: int = LATEST):
"""
Handles API call /exprValue/getceRNA to get gene expression values
:param dataset_ID: dataset_ID of interest
:param disease_name: disease_name of interest
:param ensg_number: esng number of the gene of interest
:param gene_symbol: gene symbol of the gene of interest
Expand Down Expand Up @@ -45,6 +47,10 @@ def get_gene_expr(disease_name=None, ensg_number=None, gene_symbol=None, sponge_
if disease_name is not None:
dataset_query = dataset_query \
.filter(models.Dataset.disease_name.like("%" + disease_name + "%"))

if dataset_ID is not None:
dataset_query = dataset_query \
.filter(models.Dataset.dataset_ID == dataset_ID)

dataset = dataset_query.all()

Expand All @@ -64,13 +70,14 @@ def get_gene_expr(disease_name=None, ensg_number=None, gene_symbol=None, sponge_
abort(404, "No data found.")


def get_transcript_expression(disease_name: str, enst_number: str = None, ensg_number: str = None, gene_symbol: str = None, version: int = LATEST):
def get_transcript_expression(dataset_ID: int = None, disease_name: str = None, enst_number: str = None, ensg_number: str = None, gene_symbol: str = None, sponge_db_version: int = LATEST):
"""
Handles API call to return transcript expressions
Handles API call /exprValue/getTranscriptExpr to return transcript expressions
:param dataset_ID: dataset_ID of interest
:param disease_name: Name of the disease
:param enst_number: Ensembl transcript ID(s)
:param ensg_number: Ensembl gene ID(s)
:param gene_symbol: gene symbol(s)
:param enst_number: Ensembl transcript ID
:param ensg_number: Ensembl gene ID
:param gene_symbol: gene symbol
:param sponge_db_version: version of the database
:return: expression values for given search parameters
"""
Expand All @@ -79,18 +86,18 @@ def get_transcript_expression(disease_name: str, enst_number: str = None, ensg_n
elif enst_number is not None:
# query by enst_numbers only
transcript = models.Transcript.query \
.filter(models.Transcript.enst_number.in_(enst_number)) \
.filter(models.Transcript.enst_number == enst_number) \
.all()
elif ensg_number is not None or enst_number is not None:
elif ensg_number is not None or gene_symbol is not None:
if ensg_number is not None:
# query all transcripts with matching ensg_number
gene = models.Gene.query \
.filter(models.Gene.ensg_number.in_(ensg_number)) \
.filter(models.Gene.ensg_number == ensg_number) \
.all()
else:
# query all transcripts with matching gene symbol
gene = models.Gene.query \
.filter(models.Gene.gene_symbol.in_(gene_symbol)) \
.filter(models.Gene.gene_symbol == gene_symbol) \
.all()
if len(gene) > 0:
gene_IDs = [i.gene_ID for i in gene]
Expand All @@ -115,6 +122,10 @@ def get_transcript_expression(disease_name: str, enst_number: str = None, ensg_n
dataset_query = dataset_query \
.filter(models.Dataset.disease_name.like("%" + disease_name + "%"))

if dataset_ID is not None:
dataset_query = dataset_query \
.filter(models.Dataset.dataset_ID == dataset_ID)

dataset = dataset_query.all()

if len(dataset) > 0:
Expand All @@ -124,18 +135,19 @@ def get_transcript_expression(disease_name: str, enst_number: str = None, ensg_n
abort(404, f"No dataset with given disease_name for the database version {sponge_db_version} found")

# apply all filters
result = models.ExpressionDataTranscript.query \
.filter(*filters) \
.all()
query = db.select(models.ExpressionDataTranscript).filter(*filters)
result = db.session.execute(query).scalars().all()

if len(result) > 0:
return models.ExpressionDataTranscriptSchema(many=True).dump(result)
else:
abort(404, "No transcript expression data found for the given filters.")


def get_mirna_expr(disease_name=None, mimat_number=None, hs_number=None, sponge_db_version: int = LATEST):
def get_mirna_expr(dataset_ID: int = None, disease_name=None, mimat_number=None, hs_number=None, sponge_db_version: int = LATEST):
"""
Handles API call /exprValue/getmiRNA to get miRNA expression values
:param dataset_ID: dataset_ID of interest
:param disease_name: disease_name of interest
:param mimat_number: comma-separated list of mimat_id(s) of miRNA of interest
:param: hs_nr: comma-separated list of hs_number(s) of miRNA of interest
Expand Down Expand Up @@ -177,6 +189,10 @@ def get_mirna_expr(disease_name=None, mimat_number=None, hs_number=None, sponge_
if disease_name is not None:
dataset_query = models.Dataset.query \
.filter(models.Dataset.disease_name.like("%" + disease_name + "%"))

if dataset_ID is not None:
dataset_query = dataset_query \
.filter(models.Dataset.dataset_ID == dataset_ID)

dataset = dataset_query.all()

Expand Down
Loading
Loading