Skip to content

Commit b214f19

Browse files
committed
Set h4/r2 to NULL for orphans
Also allow single signals with NULLs for those values to still come through regardless of filter value
1 parent 1f9b2a7 commit b214f19

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

colocus/api/filters.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ def parse_region(region):
2626
return match.groups()
2727

2828

29+
class NumberFilterWithNulls(NumberFilter):
30+
"""NumberFilter that includes NULL values when filtering."""
31+
32+
def filter(self, qs, value):
33+
if value is None:
34+
return qs
35+
36+
lookup = f"{self.field_name}__{self.lookup_expr}"
37+
return qs.filter(
38+
Q(**{lookup: value}) | Q(**{f"{self.field_name}__isnull": True})
39+
)
40+
41+
2942
class NullsLastOrderingFilter(OrderingFilter):
3043
"""OrderingFilter that always puts NULL values last."""
3144

@@ -432,10 +445,10 @@ def filter_signal2_trait(self, queryset, name, value):
432445
label="Minimum -log10 p-value for signal 2",
433446
)
434447

435-
min_h4 = NumberFilter(
448+
min_h4 = NumberFilterWithNulls(
436449
field_name="coloc_h4", lookup_expr="gte", label="Minimum PP(H4)"
437450
)
438-
min_r2 = NumberFilter(
451+
min_r2 = NumberFilterWithNulls(
439452
field_name="r2",
440453
lookup_expr="gte",
441454
label="Minimum r2 between the two signals' lead variants",

colocus/core/migrations/0006_colocresult_with_orphans.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ class Migration(migrations.Migration):
4242
SELECT
4343
fs.uuid as uuid,
4444
NULL::jsonb as cross_signal,
45-
0.0::float8 as coloc_h3,
46-
0.0::float8 as coloc_h4,
47-
0.0::float8 as r2,
48-
0::integer as n_coloc_between_traits,
45+
NULL::float8 as coloc_h3,
46+
NULL::float8 as coloc_h4,
47+
NULL::float8 as r2,
48+
NULL::integer as n_coloc_between_traits,
4949
ma.data_submission_id as data_submission_id,
5050
fs.id as signal1_id,
5151
NULL::integer as signal2_id

0 commit comments

Comments
 (0)