@@ -23,9 +23,11 @@ class Parser(FlaskParser):
23
23
}
24
24
25
25
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" ),
27
28
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.' })
29
31
}
30
32
31
33
eqtl_cpra_argmap = {
@@ -37,14 +39,20 @@ class Parser(FlaskParser):
37
39
@bp .route ('/eqtl/susie' , methods = ['GET' ])
38
40
@parser .use_args (eqtl_argmap , location = 'query' )
39
41
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' ])
41
46
return make_response (jsonify (result ))
42
47
43
48
44
49
@bp .route ('/eqtl/cond' , methods = ['GET' ])
45
50
@parser .use_args (eqtl_argmap , location = 'query' )
46
51
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' ])
48
56
return make_response (jsonify (result ))
49
57
50
58
@@ -151,11 +159,15 @@ def cond(gene_name: str) -> list:
151
159
def susie_ensembl (ensembl_id : str ) -> list :
152
160
pipeline = [{'$match' : {'phenotype_id' : ensembl_id }}, {'$project' : {'_id' : False }}]
153
161
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
159
171
160
172
161
173
def susie_count (ensembl_id : str ) -> int :
0 commit comments