Skip to content

Commit

Permalink
Merge pull request #18 from daisybio/transcriptInteractions
Browse files Browse the repository at this point in the history
Transcript interactions
  • Loading branch information
strasserle authored Dec 5, 2024
2 parents 132b9c2 + 819277a commit f06db6f
Show file tree
Hide file tree
Showing 4 changed files with 1,470 additions and 41 deletions.
13 changes: 7 additions & 6 deletions geneInteraction.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sqlalchemy as sa
import os
from flask import abort
from sqlalchemy import desc
from sqlalchemy import desc, or_, and_
from sqlalchemy.sql import text
import models
from config import LATEST, db
Expand Down Expand Up @@ -50,7 +50,7 @@ def read_all_genes(disease_name=None, ensg_number=None, gene_symbol=None, gene_t

# if specific disease_name is given:
if disease_name is not None:
run = run.query.join(models.Dataset, models.Dataset.dataset_ID == models.SpongeRun.dataset_ID) \
run = run.join(models.Dataset, models.Dataset.dataset_ID == models.SpongeRun.dataset_ID) \
.filter(models.Dataset.disease_name.like("%" + disease_name + "%")) \

run = run.all()
Expand Down Expand Up @@ -130,6 +130,7 @@ def read_all_genes(disease_name=None, ensg_number=None, gene_symbol=None, gene_t
sort.append(models.GeneInteraction.correlation.asc())

# interaction_result = []

interaction_result = models.GeneInteraction.query \
.filter(*queries_1) \
.order_by(*sort) \
Expand Down Expand Up @@ -209,7 +210,7 @@ def read_specific_interaction(disease_name=None, ensg_number=None, gene_symbol=N

# if specific disease_name is given:
if disease_name is not None:
run = run.query.join(models.Dataset, models.Dataset.dataset_ID == models.SpongeRun.dataset_ID) \
run = run.join(models.Dataset, models.Dataset.dataset_ID == models.SpongeRun.dataset_ID) \
.filter(models.Dataset.disease_name.like("%" + disease_name + "%")) \
.filter(models.SpongeRun.sponge_db_version == sponge_db_version) \

Expand Down Expand Up @@ -274,7 +275,7 @@ def read_all_gene_network_analysis(disease_name=None, ensg_number=None, gene_sym

# if specific disease_name is given (should be because for this endpoint is it required):
if disease_name is not None:
run = run.query.join(models.Dataset, models.Dataset.dataset_ID == models.SpongeRun.dataset_ID) \
run = run.join(models.Dataset, models.Dataset.dataset_ID == models.SpongeRun.dataset_ID) \
.filter(models.Dataset.disease_name.like("%" + disease_name + "%")) \

run = run.all()
Expand Down Expand Up @@ -466,7 +467,7 @@ def read_all_to_one_mirna(disease_name=None, mimat_number=None, hs_number=None,

# if specific disease_name is given:
if disease_name is not None:
run = run.query.join(models.Dataset, models.Dataset.dataset_ID == models.SpongeRun.dataset_ID) \
run = run.join(models.Dataset, models.Dataset.dataset_ID == models.SpongeRun.dataset_ID) \
.filter(models.Dataset.disease_name.like("%" + disease_name + "%")) \

run = run.all()
Expand Down Expand Up @@ -571,7 +572,7 @@ def read_all_mirna(disease_name=None, mimat_number=None, hs_number=None, occuren

# if specific disease_name is given:
if disease_name is not None:
run = run.query.join(models.Dataset, models.Dataset.dataset_ID == models.SpongeRun.dataset_ID) \
run = run.join(models.Dataset, models.Dataset.dataset_ID == models.SpongeRun.dataset_ID) \
.filter(models.Dataset.disease_name.like("%" + disease_name + "%")) \

run = run.all()
Expand Down
60 changes: 54 additions & 6 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,21 @@ class networkAnalysis(db.Model):
betweenness = db.Column(db.Float)
node_degree = db.Column(db.Float)

# chris: Change
class networkAnalysisTranscript(db.Model):
__tablename__ = "network_analysis_transcript"
network_analysis_transcript_ID = db.Column(db.Integer, primary_key=True)

transcript_ID = db.Column(db.Integer, db.ForeignKey('transcript.transcript_ID'), nullable=False)
transcript= relationship("Transcript", foreign_keys=[transcript_ID])

sponge_run_ID = db.Column(db.Integer, db.ForeignKey('sponge_run.sponge_run_ID'), nullable=False)
sponge_run = relationship("SpongeRun", foreign_keys=[sponge_run_ID])

eigenvector = db.Column(db.Float)
betweenness = db.Column(db.Float)
node_degree = db.Column(db.Float)


class GeneExpressionValues(db.Model):
__tablename__ = "expression_data_gene"
Expand Down Expand Up @@ -298,8 +313,8 @@ class TranscriptElement(db.Model):
type = db.Column(db.String(32))
ense_number = db.Column(db.String(32))


class InteractionsTranscriptTranscript(db.Model):
# chris: Change
class TranscriptInteraction(db.Model):
__tablename__ = "interactions_transcripttranscript"
interactions_transcripttranscript_ID = db.Column(db.Integer, primary_key=True)

Expand Down Expand Up @@ -706,6 +721,17 @@ class Meta:
gene = ma.Nested(lambda: GeneSchema(only=("ensg_number", "gene_symbol")))
mirna = ma.Nested(lambda: miRNASchema(only=("mir_ID", "hs_nr")))

#chris: Change
class miRNAInteractionSchemaTranscript(ma.SQLAlchemyAutoSchema):
class Meta:
model = miRNAInteractionTranscript
sqla_session = db.session
fields = ["sponge_run", "transcript", "mirna", "coefficient"]

sponge_run = ma.Nested(lambda: SpongeRunForMirnaSchema(only=("sponge_run_ID", "dataset")))
gene = ma.Nested(lambda: TranscriptSchema(only=("enst_number", "gene")))
mirna = ma.Nested(lambda: miRNASchema(only=("mir_ID", "hs_nr")))

class networkAnalysisSchema(ma.SQLAlchemyAutoSchema):
class Meta:
model = networkAnalysis
Expand All @@ -715,6 +741,16 @@ class Meta:
sponge_run = ma.Nested(lambda: SpongeRunSchema(only=("sponge_run_ID", "dataset")))
gene = ma.Nested(lambda: GeneSchema(only=("ensg_number", "gene_symbol")))

# chris: Change
class networkAnalysisSchemaTranscript(ma.SQLAlchemyAutoSchema):
class Meta:
model = networkAnalysisTranscript
sqla_session = db.session
fields = ["betweenness", "eigenvector", "transcript", "node_degree", "sponge_run"]

sponge_run = ma.Nested(lambda: SpongeRunSchema(only=("sponge_run_ID", "dataset")))
transcript = ma.Nested(lambda: TranscriptSchema(only=("enst_number", "gene")))


class geneExpressionSchema(ma.SQLAlchemyAutoSchema):
class Meta:
Expand Down Expand Up @@ -744,6 +780,18 @@ class Meta:
sponge_run = ma.Nested(lambda: SpongeRunSchema(only=("sponge_run_ID", "dataset")))
mirna = ma.Nested(lambda: miRNASchema(only=("mir_ID", "hs_nr")))

# chris: Change
class occurencesMiRNASchemaTranscript(ma.SQLAlchemyAutoSchema):
class Meta:
model = OccurencesMiRNATranscript
sqla_session = db.session
fields = ["mirna", "occurences", "sponge_run"]

sponge_run = ma.Nested(lambda: SpongeRunSchema(only=("sponge_run_ID", "dataset")))
mirna = ma.Nested(lambda: miRNASchema(only=("mir_ID", "hs_nr")))



class PatientInformationSchema(ma.SQLAlchemyAutoSchema):
class Meta:
model = PatientInformation
Expand Down Expand Up @@ -854,7 +902,7 @@ class Meta:

class TranscriptInteractionLongSchema(ma.SQLAlchemyAutoSchema):
class Meta:
model = InteractionsTranscriptTranscript
model = TranscriptInteraction
sqla_session = db.session

sponge_run = ma.Nested(lambda: SpongeRunSchema(only=("sponge_run_ID", )))
Expand All @@ -863,7 +911,7 @@ class Meta:

class TranscriptInteractionShortSchema(ma.SQLAlchemyAutoSchema):
class Meta:
model = InteractionsTranscriptTranscript
model = TranscriptInteraction
sqla_session = db.session

sponge_run = ma.Nested(lambda: SpongeRunSchema(only=("sponge_run_ID", )))
Expand All @@ -873,7 +921,7 @@ class Meta:

class TranscriptInteractionDatasetLongSchema(ma.SQLAlchemyAutoSchema):
class Meta:
model = InteractionsTranscriptTranscript
model = TranscriptInteraction
sqla_session = db.session
fields = ["correlation", "mscor", "p_value", "sponge_run", "transcript1", "transcript2"]

Expand All @@ -883,7 +931,7 @@ class Meta:

class TranscriptInteractionDatasetShortSchema(ma.SQLAlchemyAutoSchema):
class Meta:
model = InteractionsTranscriptTranscript
model = TranscriptInteraction
sqla_session = db.session
fields = ["correlation", "mscor", "p_value", "sponge_run", "transcript1", "transcript2"]

Expand Down
Loading

0 comments on commit f06db6f

Please sign in to comment.