Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5705c49
Fix conflicts
Mar 9, 2026
802a4b0
Wop
Mar 9, 2026
78e9c94
Fix tests
Mar 9, 2026
81fee6c
Speedup dry run by skipping counting the affected variants
Mar 9, 2026
6f8e732
Improve changelog
Mar 9, 2026
c8d8f07
Merge branch 'main' into speedup_remove_variants
dnil Mar 11, 2026
7e3facd
Merge branch 'main' into speedup_remove_variants
northwestwitch Mar 11, 2026
2acd96a
Merge branch 'main' into speedup_remove_variants
dnil Mar 12, 2026
f802423
Merge branch 'main' into speedup_remove_variants
northwestwitch Mar 12, 2026
d8c1ae1
Apply suggestions from code review
northwestwitch Mar 12, 2026
ffbf140
Apply suggestion from @dnil
northwestwitch Mar 12, 2026
b58df78
Fix code style issues with Black
lint-action Mar 12, 2026
ad3ab27
Fix changelog
Mar 12, 2026
abbf51c
convert cursor to list
Mar 12, 2026
cc179bf
Print total removed vars only if not dry run
Mar 12, 2026
04d489a
Merge branch 'main' into speedup_remove_variants
northwestwitch Mar 13, 2026
dbadb4b
Merge branch 'main' into speedup_remove_variants
dnil Mar 13, 2026
16f045b
Merge branch 'main' into speedup_remove_variants
northwestwitch Mar 13, 2026
23fc082
Merge branch 'main' into speedup_remove_variants
northwestwitch Mar 13, 2026
9e0547b
Merge branch 'main' into speedup_remove_variants
northwestwitch Mar 16, 2026
e38bac4
Merge branch 'main' into speedup_remove_variants
northwestwitch Mar 17, 2026
d348692
Merge branch 'main' into speedup_remove_variants
dnil Mar 17, 2026
4035bce
Merge branch 'main' into speedup_remove_variants
northwestwitch Mar 20, 2026
82260b0
Merge branch 'main' into speedup_remove_variants
northwestwitch Mar 20, 2026
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ About changelog [here](https://keepachangelog.com/en/1.0.0/)
- On managed variants page, print maintainers names instead of emails/ids (#6121)
- Enable ClinVar test API URL by default on Scout demo config settings (#6129)
- ClinVar settings (API and list of users allowed to send API submissions) are no longer shown only to admin users (#6134)
- Refactor, speedup (dry-run only) and add a progress bar to `scout delete variants` cmd (#6094)
- `scout delete variants` command now accepts an optional `--out-file` where to print a detailed report of the deletion process (#6094)
### Fixed
- Comments' text wrapping in ACMG classifications exported as PDF (#6086)
- Individual breakpoint gDNA IGV links should not trigger split locus view (#6103)
Expand Down
41 changes: 20 additions & 21 deletions scout/adapter/mongo/query.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import re
from datetime import datetime, timedelta
from typing import List, Optional, Union
from typing import List, Optional, Set, Union

from scout.constants import (
CLINSIG_MAP,
Expand Down Expand Up @@ -52,31 +52,30 @@ def build_case_query(
def delete_variants_query(
self,
case_id: str,
variants_to_keep: List[str] = [],
variants_to_keep: Set[str] | None = None,
min_rank_threshold: Optional[int] = None,
keep_ctg: List[str] = [],
remove_ctg: List[str] | None = None,
) -> dict:
"""Build a query to delete variants from a case (variant collection).
"""Build a query to delete variants from a case.

Removes variants with rank lower than `min_rank_threshold`.
Retains variants in categories `keep_ctg` by excluding them from deletion - eg `["cancer", "cancer_sv"]`.
Retains variants in categories `keep_ctg` and specific variant IDs in
`variants_to_keep` by excluding them from deletion.
"""
variants_query = {}
case_subquery = {"case_id": case_id}

# Create query to delete all variants that shouldn't be kept or with rank higher than min_rank_threshold
if variants_to_keep or min_rank_threshold or keep_ctg:
variants_query["$and"] = [case_subquery]
if variants_to_keep:
variants_query["$and"].append({"_id": {"$nin": variants_to_keep}})
if keep_ctg:
variants_query["$and"].append({"category": {"$nin": keep_ctg}})
if min_rank_threshold:
variants_query["$and"].append({"rank_score": {"$lt": min_rank_threshold}})
else:
variants_query = case_subquery

return variants_query

query: dict = {
"case_id": case_id,
"$or": [
{"rank_score": {"$lt": min_rank_threshold}},
{"rank_score": {"$exists": False}},
],
}
if remove_ctg:
query["category"] = {"$in": remove_ctg}
Copy link
Member

Choose a reason for hiding this comment

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

Hm, we never split the CTGs right? So these would still have those whatever_research on them? But it would never propagate to a { category: 'whatever', variant_type: "research" }

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah right, now that you tell me I remember. I'll fix, or perhaps I'll just leave it as it was

Copy link
Member Author

Choose a reason for hiding this comment

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

Reverted now! Very good point!

if variants_to_keep:
query["_id"] = {"$nin": variants_to_keep}

return query

def build_variant_query(
self,
Expand Down
Loading
Loading