Skip to content

Commit 098da57

Browse files
committed
Ruff linting/formatting
1 parent 2f318df commit 098da57

32 files changed

Lines changed: 1721 additions & 1172 deletions

colocus/api/apps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33

44
class WebConfig(AppConfig):
5-
default_auto_field = 'django.db.models.BigAutoField'
6-
name = 'colocus.api'
5+
default_auto_field = "django.db.models.BigAutoField"
6+
name = "colocus.api"

colocus/api/filters.py

Lines changed: 358 additions & 266 deletions
Large diffs are not rendered by default.

colocus/api/internal_views.py

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Views that power internal functionality: non-public API endpoints with additional information required for some pages
33
"""
4+
45
import os
56

67
from django import http
@@ -148,9 +149,8 @@
148149
def 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

241255
def 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")

colocus/api/parsers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def parse_plink(line: str):
2020
This parser assumes the following columns (plus any on the right after that):
2121
CHR_A BP_A SNP_A CHR_B BP_B SNP_B R2
2222
"""
23-
fields = line.strip().split('\t')
23+
fields = line.strip().split("\t")
2424
chr_a, bp_a, snp_a, chr_b, bp_b, snp_b, r2 = fields[0:7]
2525
bp_a = int(bp_a)
2626
bp_b = int(bp_b)

0 commit comments

Comments
 (0)