Skip to content

Commit c440edc

Browse files
committed
Allow gene name OR ensembl id at eqtl endpoint.
Use appropriate query depending on id given.
1 parent 126af5a commit c440edc

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

bravo_api/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.22.3
1+
2.22.4

bravo_api/blueprints/eqtl/eqtl.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ class Parser(FlaskParser):
2323
}
2424

2525
ensg_argmap = {
26-
'ensembl': fields.Str(required=True, validate=lambda x: len(x) > 12 and len(x) < 17,
26+
'ensembl': fields.Str(required=True,
27+
validate=lambda x: len(x) > 12 and len(x) < 17 and x.startswith("ENSG"),
2728
error_messages={
28-
'validator_failed': 'String length must be between 13 and 16.'})
29+
'validator_failed': 'Expecting string starting with ENSG and \
30+
length 13 to 16.'})
2931
}
3032

3133
eqtl_cpra_argmap = {
@@ -37,14 +39,20 @@ class Parser(FlaskParser):
3739
@bp.route('/eqtl/susie', methods=['GET'])
3840
@parser.use_args(eqtl_argmap, location='query')
3941
def get_susie(args: dict) -> Response:
40-
result = susie(args['gene'])
42+
if args['gene'].startswith("ENSG"):
43+
result = susie_ensembl(args['gene'])
44+
else:
45+
result = susie(args['gene'])
4146
return make_response(jsonify(result))
4247

4348

4449
@bp.route('/eqtl/cond', methods=['GET'])
4550
@parser.use_args(eqtl_argmap, location='query')
4651
def get_cond(args: dict) -> Response:
47-
result = cond(args['gene'])
52+
if args['gene'].startswith("ENSG"):
53+
result = cond_ensembl(args['gene'])
54+
else:
55+
result = cond(args['gene'])
4856
return make_response(jsonify(result))
4957

5058

@@ -151,11 +159,15 @@ def cond(gene_name: str) -> list:
151159
def susie_ensembl(ensembl_id: str) -> list:
152160
pipeline = [{'$match': {'phenotype_id': ensembl_id}}, {'$project': {'_id': False}}]
153161
cursor = current_app.mmongo.db.eqtl_susie.aggregate(pipeline)
154-
result = next(cursor, None)
155-
if result is None:
156-
return []
157-
else:
158-
return result
162+
answer = [item for item in cursor]
163+
return answer
164+
165+
166+
def cond_ensembl(ensembl_id: str) -> list:
167+
pipeline = [{'$match': {'phenotype_id': ensembl_id}}, {'$project': {'_id': False}}]
168+
cursor = current_app.mmongo.db.eqtl_cond.aggregate(pipeline)
169+
answer = [item for item in cursor]
170+
return answer
159171

160172

161173
def susie_count(ensembl_id: str) -> int:

0 commit comments

Comments
 (0)