11"""
22Views that power internal functionality: non-public API endpoints with additional information required for some pages
33"""
4+
45import os
56
67from django import http
148149def search_page_metadata (request , * args , ** kwargs ):
149150 # Apply analysis_uuid filter if provided, else use all objects
150151 qs_analysis = models .MarginalAnalysis .objects .select_related (
151- "trait" ,
152- "trait__phenotype" ,
153- "study" )
152+ "trait" , "trait__phenotype" , "study"
153+ )
154154
155155 """Return metadata required to power the "available categories" menus in the "search" page UI"""
156156 count_signal_pairs = models .ColocResult .objects .count ()
@@ -161,7 +161,13 @@ def search_page_metadata(request, *args, **kwargs):
161161 phenotypes = set ()
162162 studies = set ()
163163
164- analysis_fields = ["analysis_type" , "tissue" , "cell_type" , "trait__phenotype__name" , "study__uuid" ]
164+ analysis_fields = [
165+ "analysis_type" ,
166+ "tissue" ,
167+ "cell_type" ,
168+ "trait__phenotype__name" ,
169+ "study__uuid" ,
170+ ]
165171 for obj in qs_analysis .values (* analysis_fields ):
166172 analysis_types .add (obj .get ("analysis_type" ))
167173 tissues .add (obj .get ("tissue" ))
@@ -182,10 +188,10 @@ def search_page_metadata(request, *args, **kwargs):
182188 # This uses .values() to avoid pulling in a lot of unnecessary data and avoids issues with prefetching and
183189 # customizing the serializer for this one case
184190 fields = [
185- ' signal1__analysis__trait__gene__ens_id' ,
186- ' signal1__analysis__trait__gene__symbol' ,
187- ' signal2__analysis__trait__gene__ens_id' ,
188- ' signal2__analysis__trait__gene__symbol' ,
191+ " signal1__analysis__trait__gene__ens_id" ,
192+ " signal1__analysis__trait__gene__symbol" ,
193+ " signal2__analysis__trait__gene__ens_id" ,
194+ " signal2__analysis__trait__gene__symbol" ,
189195 ]
190196 coloc_results = models .ColocResult .objects .values (* fields )
191197 genes = set ()
@@ -199,13 +205,13 @@ def search_page_metadata(request, *args, **kwargs):
199205 genes .add (symb )
200206
201207 result = {
202- ' count_pairs' : count_signal_pairs ,
203- ' tissues' : tissues ,
204- ' cell_types' : cell_types ,
205- ' analysis_types' : analysis_types ,
206- ' phenotypes' : phenotypes ,
207- ' studies' : studies ,
208- ' genes' : list (genes )
208+ " count_pairs" : count_signal_pairs ,
209+ " tissues" : tissues ,
210+ " cell_types" : cell_types ,
211+ " analysis_types" : analysis_types ,
212+ " phenotypes" : phenotypes ,
213+ " studies" : studies ,
214+ " genes" : list (genes ),
209215 }
210216
211217 # For debugging: Return data as HTML
@@ -229,13 +235,21 @@ def analysis_manhattan(request, *args, **kwargs):
229235 try :
230236 model = models .MarginalAnalysis .objects .get (** filter_args )
231237 except models .MarginalAnalysis .DoesNotExist :
232- return http .HttpResponseNotFound ("No record was found for the specified study + trait" )
238+ return http .HttpResponseNotFound (
239+ "No record was found for the specified study + trait"
240+ )
233241
234242 filename = model .manhattan_bins
235- if not model .analysis_type == constants .GWAS or not model .manhattan_bins or not os .path .exists (filename ):
236- return http .HttpResponseBadRequest ("No manhattan data is available for the specified trait" )
243+ if (
244+ not model .analysis_type == constants .GWAS
245+ or not model .manhattan_bins
246+ or not os .path .exists (filename )
247+ ):
248+ return http .HttpResponseBadRequest (
249+ "No manhattan data is available for the specified trait"
250+ )
237251
238- return http .FileResponse (open (filename , 'rb' ), content_type = ' application/json' )
252+ return http .FileResponse (open (filename , "rb" ), content_type = " application/json" )
239253
240254
241255def analysis_qq (request , uuid ):
@@ -248,10 +262,18 @@ def analysis_qq(request, uuid):
248262 try :
249263 model = models .MarginalAnalysis .objects .get (uuid = uuid )
250264 except models .MarginalAnalysis .DoesNotExist :
251- return http .HttpResponseNotFound ("No record was found for the specified study + trait" )
265+ return http .HttpResponseNotFound (
266+ "No record was found for the specified study + trait"
267+ )
252268
253269 filename = model .qq_bins
254- if not model .analysis_type == constants .GWAS or not model .qq_bins or not os .path .exists (filename ):
255- return http .HttpResponseBadRequest ("No QQ data is available for the specified trait" )
270+ if (
271+ not model .analysis_type == constants .GWAS
272+ or not model .qq_bins
273+ or not os .path .exists (filename )
274+ ):
275+ return http .HttpResponseBadRequest (
276+ "No QQ data is available for the specified trait"
277+ )
256278
257- return http .FileResponse (open (filename , 'rb' ), content_type = ' application/json' )
279+ return http .FileResponse (open (filename , "rb" ), content_type = " application/json" )
0 commit comments