Skip to content
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ About changelog [here](https://keepachangelog.com/en/1.0.0/)
- Tests for cli command to update VCF files not running (#5888)
- Gene in panels search results broken layout - overflow when a panel has many panel versions containing the gene (#5899)
- ACMG evaluation PDF export, both style and colors (#5879)
- Include outliers with missing p-value fields in filtering logic (#5903)

## [4.106]
### Added
Expand Down
21 changes: 15 additions & 6 deletions scout/adapter/mongo/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,6 @@ def secondary_query(self, query: dict) -> list:

if query.get("padjust") or query.get("p_adjust_gene"):
mongo_secondary_query.append(_get_outlier_query(query))
LOG.info(
f"using padjust for filtering - query was {query}, secondary filter is {mongo_secondary_query}"
)

for criterion in SECONDARY_CRITERIA:
if not query.get(criterion):
Expand Down Expand Up @@ -849,9 +846,16 @@ def _get_outlier_query(query: dict) -> dict:

outlier_padjust_query = {"$or": []}

mutual_exclusion = {
"padjust": "p_adjust_gene",
"p_adjust_gene": "padjust",
}

for pval_name in {"padjust", "p_adjust_gene"}:
if pval := query.get(pval_name):
pval_struct = {pval_name: {"$lt": pval}}
provided_pval = query.get(pval_name)

if provided_pval is not None:
pval_struct = {pval_name: {"$lt": provided_pval}}

if (abs_delta_psi := query.get("delta_psi")) and pval_name == "p_adjust_gene":
pval_struct = {
Expand All @@ -866,7 +870,12 @@ def _get_outlier_query(query: dict) -> dict:
]
}

outlier_padjust_query["$or"].append(pval_struct)
outlier_padjust_query["$or"].append(
{"$and": [pval_struct, {mutual_exclusion[pval_name]: {"$exists": False}}]}
Copy link
Member Author

@northwestwitch northwestwitch Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enforce mutual exclusivity of the values: whenever a key/value is provided -> the other should't be existing, but if a key/value is not provided then the field might be missing - see line 878. Something like this @dnil? This is complicated 🤯

)

else:
outlier_padjust_query["$or"].append({pval_name: {"$exists": False}})

return outlier_padjust_query

Expand Down
Loading