Skip to content
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
23 changes: 16 additions & 7 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,11 +846,18 @@ 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":
if pval_name == "p_adjust_gene" and (abs_delta_psi := query.get("delta_psi")):
pval_struct = {
"$and": [
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