Skip to content

Commit

Permalink
Merge pull request #14 from daisybio/dependency_migration
Browse files Browse the repository at this point in the history
Dependency migration
  • Loading branch information
nictru authored Nov 24, 2024
2 parents fea1808 + fd8d119 commit 6ebb8f4
Show file tree
Hide file tree
Showing 28 changed files with 589 additions and 378 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ RUN pip3 --no-cache-dir install -r requirements.txt
# the mariadb plugin directory seems to be misconfigured
# bei default. In order to work properly we manually adjust
# the path.
ENV MARIADB_PLUGIN_DIR /usr/lib/mariadb/plugin
ENV MARIADB_PLUGIN_DIR=/usr/lib/mariadb/plugin

# EXPOSE 5000
# CMD ["python3", "server.py"]

#run the command to start uWSGI
CMD ["uwsgi", "app.ini"]
CMD ["gunicorn", "-k", "uvicorn.workers.UvicornWorker", "-b", "0.0.0.0:5000", "-w", "4", "server:connex_app"]

81 changes: 15 additions & 66 deletions TestCases/test_ceRNAInteraction_findAll.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from config import *
import models, geneInteraction, unittest
import models, unittest
with app.app_context():
import geneInteraction
from flask import abort
import sqlalchemy as sa
from werkzeug.exceptions import HTTPException
Expand Down Expand Up @@ -41,9 +43,10 @@ def test_read_all_genes(disease_name=None, ensg_number=None, gene_symbol=None, g
queries_2 = []
# if specific disease_name is given:
if disease_name is not None:
run = models.SpongeRun.query.join(models.Dataset, models.Dataset.dataset_ID == models.SpongeRun.dataset_ID) \
.filter(models.Dataset.disease_name.like("%" + disease_name + "%")) \
.all()
with app.app_context():
run = models.SpongeRun.query.join(models.Dataset, models.Dataset.dataset_ID == models.SpongeRun.dataset_ID) \
.filter(models.Dataset.disease_name.like("%" + disease_name + "%")) \
.all()

if len(run) > 0:
run_IDs = [i.sponge_run_ID for i in run]
Expand Down Expand Up @@ -143,7 +146,7 @@ def test_read_all_genes(disease_name=None, ensg_number=None, gene_symbol=None, g
else:
# Serialize the data for the response depending on parameter all
schema = models.GeneInteractionDatasetShortSchema(many=True)
return schema.dump(interaction_result).data
return schema.dump(interaction_result)
else:
abort(404, "No information with given parameters found")

Expand All @@ -153,66 +156,51 @@ def test_read_all_genes(disease_name=None, ensg_number=None, gene_symbol=None, g

class TestDataset(unittest.TestCase):

def test_abort_error_disease(self):
def setUp(self):
app.config["TESTING"] = True
self.app = app.test_client()
self.app_context = app.app_context()
self.app_context.push()

def tearDown(self):
self.app_context.pop()

def test_abort_error_disease(self):
with self.assertRaises(HTTPException) as http_error:
# retrieve current API response to request
self.assertEqual(geneInteraction.read_all_genes(disease_name="foobar", pValue = None), 404)

def test_abort_error_limit(self):
app.config["TESTING"] = True
self.app = app.test_client()

with self.assertRaises(HTTPException) as http_error:
# retrieve current API response to request
self.assertEqual(geneInteraction.read_all_genes(disease_name="foobar", limit = 20000, pValue = None), 404)

def test_abort_error_ensg(self):
app.config["TESTING"] = True
self.app = app.test_client()

with self.assertRaises(HTTPException) as http_error:
# retrieve current API response to request
self.assertEqual(geneInteraction.read_all_genes(ensg_number=["ENSGfoobar"], pValue = None), 404)

def test_abort_error_gene_symbol(self):
app.config["TESTING"] = True
self.app = app.test_client()

with self.assertRaises(HTTPException) as http_error:
# retrieve current API response to request
self.assertEqual(geneInteraction.read_all_genes(gene_symbol=["foobar"], pValue = None), 404)

def test_abort_error_ensg_and_gene_symbol(self):
app.config["TESTING"] = True
self.app = app.test_client()

with self.assertRaises(HTTPException) as http_error:
# retrieve current API response to request
self.assertEqual(geneInteraction.read_all_genes(ensg_number=["ENSGfoobar"],gene_symbol=["foobar"], pValue = None), 404)

def test_abort_error_gene_type(self):
app.config["TESTING"] = True
self.app = app.test_client()

with self.assertRaises(HTTPException) as http_error:
# retrieve current API response to request
self.assertEqual(geneInteraction.read_all_genes(gene_type="foobar", pValue = None), 404)

def test_abort_error_no_data(self):
app.config["TESTING"] = True
self.app = app.test_client()

with self.assertRaises(HTTPException) as http_error:
# retrieve current API response to request
self.assertEqual(geneInteraction.read_all_genes(disease_name="bladder urothelial carcinoma", ensg_number=['ENSG00000023041'], pValue = None), 404)

def test_findAll_disease_and_ensg(self):
app.config["TESTING"] = True
self.app = app.test_client()

# retrieve correct database response to request
mock_response = test_read_all_genes(disease_name='bladder urothelial carcinoma', ensg_number=['ENSG00000172137','ENSG00000078237'], limit=50, pValue = None)

Expand All @@ -223,9 +211,6 @@ def test_findAll_disease_and_ensg(self):
self.assertEqual(mock_response, api_response)

def test_findAll_disease_and_gene_symbol(self):
app.config["TESTING"] = True
self.app = app.test_client()

# retrieve correct database response to request
mock_response = test_read_all_genes(disease_name='bladder urothelial carcinoma', gene_symbol=['CALB2','TIGAR'], limit=50, pValue = None)

Expand All @@ -236,9 +221,6 @@ def test_findAll_disease_and_gene_symbol(self):
self.assertEqual(mock_response, api_response)

def test_findAll_disease_and_ensg_pValue_smaller(self):
app.config["TESTING"] = True
self.app = app.test_client()

# retrieve correct database response to request
mock_response = test_read_all_genes(disease_name='bladder urothelial carcinoma',
ensg_number=['ENSG00000172137', 'ENSG00000078237'], limit=50, pValue=0.5, pValueDirection="<", sorting="pValue")
Expand All @@ -251,9 +233,6 @@ def test_findAll_disease_and_ensg_pValue_smaller(self):
self.assertEqual(mock_response, api_response)

def test_findAll_disease_and_ensg_pValue_greater(self):
app.config["TESTING"] = True
self.app = app.test_client()

# retrieve correct database response to request
mock_response = test_read_all_genes(disease_name='bladder urothelial carcinoma',
ensg_number=['ENSG00000172137', 'ENSG00000078237'], limit=50, pValue=0.5, pValueDirection=">", sorting="pValue")
Expand All @@ -266,9 +245,6 @@ def test_findAll_disease_and_ensg_pValue_greater(self):
self.assertEqual(mock_response, api_response)

def test_findAll_disease_and_gene_symbol_pValue_smaller(self):
app.config["TESTING"] = True
self.app = app.test_client()

# retrieve correct database response to request
mock_response = test_read_all_genes(disease_name='bladder urothelial carcinoma',
gene_symbol=['CALB2', 'TIGAR'], limit=50, pValue=0.5, pValueDirection="<", sorting="pValue")
Expand All @@ -281,9 +257,6 @@ def test_findAll_disease_and_gene_symbol_pValue_smaller(self):
self.assertEqual(mock_response, api_response)

def test_findAll_disease_and_gene_symbol_pValue_greater(self):
app.config["TESTING"] = True
self.app = app.test_client()

# retrieve correct database response to request
mock_response = test_read_all_genes(disease_name='bladder urothelial carcinoma',
gene_symbol=['CALB2', 'TIGAR'], limit=50, pValue=0.5, pValueDirection=">", sorting="pValue")
Expand All @@ -297,9 +270,6 @@ def test_findAll_disease_and_gene_symbol_pValue_greater(self):


def test_findAll_disease_and_ensg_correlation_smaller(self):
app.config["TESTING"] = True
self.app = app.test_client()

# retrieve correct database response to request
mock_response = test_read_all_genes(disease_name='bladder urothelial carcinoma',
ensg_number=['ENSG00000172137', 'ENSG00000078237'], limit=50, correlation=0.2, correlationDirection="<", sorting="correlation", pValue = None)
Expand All @@ -312,9 +282,6 @@ def test_findAll_disease_and_ensg_correlation_smaller(self):
self.assertEqual(mock_response, api_response)

def test_findAll_disease_and_ensg_correlation_greater(self):
app.config["TESTING"] = True
self.app = app.test_client()

# retrieve correct database response to request
mock_response = test_read_all_genes(disease_name='bladder urothelial carcinoma',
ensg_number=['ENSG00000172137', 'ENSG00000078237'], limit=50, correlation=0.1, correlationDirection=">", sorting="correlation", pValue = None)
Expand All @@ -327,9 +294,6 @@ def test_findAll_disease_and_ensg_correlation_greater(self):
self.assertEqual(mock_response, api_response)

def test_findAll_disease_and_gene_symbol_correlation_smaller(self):
app.config["TESTING"] = True
self.app = app.test_client()

# retrieve correct database response to request
mock_response = test_read_all_genes(disease_name='bladder urothelial carcinoma',
gene_symbol=['CALB2', 'TIGAR'], limit=50, correlation=0.2, correlationDirection="<", sorting="correlation",pValue = None)
Expand All @@ -342,9 +306,6 @@ def test_findAll_disease_and_gene_symbol_correlation_smaller(self):
self.assertEqual(mock_response, api_response)

def test_findAll_disease_and_gene_symbol_correlation_greater(self):
app.config["TESTING"] = True
self.app = app.test_client()

# retrieve correct database response to request
mock_response = test_read_all_genes(disease_name='bladder urothelial carcinoma',
gene_symbol=['CALB2', 'TIGAR'], limit=50, correlation=0.1, correlationDirection=">", sorting="correlation",pValue = None)
Expand All @@ -358,9 +319,6 @@ def test_findAll_disease_and_gene_symbol_correlation_greater(self):


def test_findAll_disease_and_ensg_mscor_smaller(self):
app.config["TESTING"] = True
self.app = app.test_client()

# retrieve correct database response to request
mock_response = test_read_all_genes(disease_name='bladder urothelial carcinoma',
ensg_number=['ENSG00000172137', 'ENSG00000078237'], limit=50, mscor=0.02, mscorDirection="<", sorting="mscor",pValue = None)
Expand All @@ -373,9 +331,6 @@ def test_findAll_disease_and_ensg_mscor_smaller(self):
self.assertEqual(mock_response, api_response)

def test_findAll_disease_and_ensg_mscor_greater(self):
app.config["TESTING"] = True
self.app = app.test_client()

# retrieve correct database response to request
mock_response = test_read_all_genes(disease_name='bladder urothelial carcinoma',
ensg_number=['ENSG00000172137', 'ENSG00000078237'], limit=50, mscor=0.01, mscorDirection=">", sorting="mscor", pValue = None)
Expand All @@ -388,9 +343,6 @@ def test_findAll_disease_and_ensg_mscor_greater(self):
self.assertEqual(mock_response, api_response)

def test_findAll_disease_and_gene_symbol_mscor_smaller(self):
app.config["TESTING"] = True
self.app = app.test_client()

# retrieve correct database response to request
mock_response = test_read_all_genes(disease_name='bladder urothelial carcinoma',
gene_symbol=['CALB2', 'TIGAR'], limit=50, mscor=0.02, mscorDirection="<", sorting="mscor", pValue = None)
Expand All @@ -403,9 +355,6 @@ def test_findAll_disease_and_gene_symbol_mscor_smaller(self):
self.assertEqual(mock_response, api_response)

def test_findAll_disease_and_gene_symbol_mscor_greater(self):
app.config["TESTING"] = True
self.app = app.test_client()

# retrieve correct database response to request
mock_response = test_read_all_genes(disease_name='bladder urothelial carcinoma',
gene_symbol=['CALB2', 'TIGAR'], limit=50, mscor=0.01, mscorDirection=">", sorting="mscor", pValue = None)
Expand Down
16 changes: 14 additions & 2 deletions TestCases/test_ceRNAInteraction_findSpecific.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from config import *
import models, geneInteraction, unittest
import models, unittest
with app.app_context():
import geneInteraction
from flask import abort
import sqlalchemy as sa
from werkzeug.exceptions import HTTPException
Expand Down Expand Up @@ -74,7 +76,7 @@ def test_read_specific_interaction(disease_name=None, ensg_number=None, gene_sym

if len(interaction_result) > 0:
# Serialize the data for the response depending on parameter all
return models.GeneInteractionDatasetShortSchema(many=True).dump(interaction_result).data
return models.GeneInteractionDatasetShortSchema(many=True).dump(interaction_result)
else:
abort(404, "No information with given parameters found")

Expand All @@ -84,6 +86,16 @@ def test_read_specific_interaction(disease_name=None, ensg_number=None, gene_sym
########################################################################################################################

class TestDataset(unittest.TestCase):

def setUp(self):
app.config["TESTING"] = True
self.app = app.test_client()
self.app_context = app.app_context()
self.app_context.push()

def tearDown(self):
self.app_context.pop()

def test_abort_error_disease(self):
app.config["TESTING"] = True
self.app = app.test_client()
Expand Down
23 changes: 19 additions & 4 deletions TestCases/test_findceRNA.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from config import *
import models, geneInteraction, unittest
import models, unittest
with app.app_context():
import geneInteraction
from flask import abort
from werkzeug.exceptions import HTTPException

def test_read_all_gene_network_analysis(disease_name=None, ensg_number=None, gene_symbol=None, gene_type=None,
minBetweenness=None, minNodeDegree=None, minEigenvector=None,
sorting=None, descending=True, limit=100, offset=0):
sorting=None, descending=True, limit=100, offset=0, db_version=2):
"""
This function responds to a request for /sponge/findceRNA
and returns all interactions the given identification (ensg_number or gene_symbol) in all available datasets is in involved and satisfies the given filters
Expand All @@ -21,6 +23,7 @@ def test_read_all_gene_network_analysis(disease_name=None, ensg_number=None, gen
:param limit: number of results that shouls be shown
:param offset: startpoint from where results should be shown
:return: all ceRNAInteractions in the dataset of interest that satisfy the given filters
:db_version: database version
"""

# test limit
Expand Down Expand Up @@ -76,6 +79,8 @@ def test_read_all_gene_network_analysis(disease_name=None, ensg_number=None, gen
queries.append(models.networkAnalysis.eigenvector > minEigenvector)
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)

# add all sorting if given:
sort = [models.networkAnalysis.sponge_run_ID]
Expand Down Expand Up @@ -105,7 +110,7 @@ def test_read_all_gene_network_analysis(disease_name=None, ensg_number=None, gen

if len(result) > 0:
schema = models.networkAnalysisSchema(many=True)
return schema.dump(result).data
return schema.dump(result)
else:
abort(404, "Not data found that satisfies the given filters")

Expand All @@ -114,6 +119,16 @@ def test_read_all_gene_network_analysis(disease_name=None, ensg_number=None, gen
########################################################################################################################

class TestDataset(unittest.TestCase):

def setUp(self):
app.config["TESTING"] = True
self.app = app.test_client()
self.app_context = app.app_context()
self.app_context.push()

def tearDown(self):
self.app_context.pop()

def test_abort_error_disease(self):
app.config["TESTING"] = True
self.app = app.test_client()
Expand Down Expand Up @@ -151,7 +166,7 @@ def test_findceRNA_disease_and_type(self):
self.app = app.test_client()

# retrieve correct database response to request
mock_response = test_read_all_gene_network_analysis(disease_name='bladder urothelial carcinoma', gene_type='protein_coding', limit=50)
mock_response = test_read_all_gene_network_analysis(disease_name='bladder urothelial carcinoma', gene_type='protein_coding', limit=50, db_version=1)

# retrieve current API response to request
api_response = geneInteraction.read_all_gene_network_analysis(disease_name='bladder urothelial carcinoma',
Expand Down
15 changes: 13 additions & 2 deletions TestCases/test_getDataset.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from config import *
import models, dataset, unittest
import models, unittest
with app.app_context():
import dataset
from flask import abort
from werkzeug.exceptions import HTTPException

Expand All @@ -25,7 +27,7 @@ def test_read(disease_name=None):
# Did we find a dataset?
if len(data) > 0:
# Serialize the data for the response
return models.DatasetSchema(many=True).dump(data).data
return models.DatasetSchema(many=True).dump(data)
else:
abort(404, 'No data found for name: {disease_name}'.format(disease_name=disease_name))

Expand All @@ -35,6 +37,15 @@ def test_read(disease_name=None):

class TestDataset(unittest.TestCase):

def setUp(self):
app.config["TESTING"] = True
self.app = app.test_client()
self.app_context = app.app_context()
self.app_context.push()

def tearDown(self):
self.app_context.pop()

def test_get_dataset_information_all(self):
app.config["TESTING"] = True
self.app = app.test_client()
Expand Down
Loading

0 comments on commit 6ebb8f4

Please sign in to comment.