Skip to content

Commit

Permalink
Facilitate ensembl id lookup for eqtl data.
Browse files Browse the repository at this point in the history
  Test api endpoints for bravue issue #32
  • Loading branch information
grosscol committed Jan 7, 2025
1 parent b85e431 commit a06fc46
Show file tree
Hide file tree
Showing 4 changed files with 924 additions and 0 deletions.
11 changes: 11 additions & 0 deletions bravo_api/blueprints/eqtl/eqtl.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def susie(gene_name: str) -> list:
cursor = current_app.mmongo.db.genes.aggregate(pipeline)
cursor.limit = 1
answer = next(cursor, None)

if answer is None:
return []
else:
Expand All @@ -100,6 +101,16 @@ def cond(gene_name: str) -> list:
return answer['eqtls']


def susie_ensembl(ensembl_id: str) -> list:
pipeline = [{'$match': {'phenotype_id': ensembl_id}}, {'$project': {'_id': False}}]
cursor = current_app.mmongo.db.eqtl_susie.aggregate(pipeline)
result = next(cursor, None)
if result is None:
return []
else:
return result


def susie_count(ensembl_id: str) -> int:
mongo_filter = {'phenotype_id': ensembl_id}
result = current_app.mmongo.db.eqtl_susie.count_documents(mongo_filter)
Expand Down
46 changes: 46 additions & 0 deletions tests/eqtl/test_eqtl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from bravo_api.blueprints.eqtl import eqtl
from flask import Flask

app = Flask('dummy')
app.register_blueprint(eqtl.bp)

# Test using fixture containing "ENSG00000239920" and "ENSG00000244734"
# Gene names CTD-2643I7.5 and HBB respetively
SUSIE_EXPECTED = {"ENSG00000239920": 22, "ENSG00000244734": 0}
COND_EXPECTED = {"ENSG00000239920": 5, "ENSG00000244734": 2}


def test_susie_count(mocker, mongodb):
# Mock PyMongo's database with pytest-mongo's fixtures
pymongo_mock = mocker.Mock()
pymongo_mock.db = mongodb
app.mmongo = pymongo_mock

# Mock the app's cache to return None (no caching)
cache_mock = mocker.Mock()
cache_mock.get = mocker.Mock(return_value=None)
app.cache = cache_mock

with app.test_client() as client:
for id in SUSIE_EXPECTED:
resp = client.get('/eqtl/susie_count', query_string={'ensembl': id})
assert(resp.content_type == 'application/json')
assert(resp.get_json() == SUSIE_EXPECTED[id])


def test_cond_count(mocker, mongodb):
# Mock PyMongo's database with pytest-mongo's fixtures
pymongo_mock = mocker.Mock()
pymongo_mock.db = mongodb
app.mmongo = pymongo_mock

# Mock the app's cache to return None (no caching)
cache_mock = mocker.Mock()
cache_mock.get = mocker.Mock(return_value=None)
app.cache = cache_mock

with app.test_client() as client:
for id in COND_EXPECTED:
resp = client.get('/eqtl/cond_count', query_string={'ensembl': id})
assert(resp.content_type == 'application/json')
assert(resp.get_json() == COND_EXPECTED[id])
Loading

0 comments on commit a06fc46

Please sign in to comment.