Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ About changelog [here](https://keepachangelog.com/en/1.0.0/)
- Export genotype with gene variantS search (#6088)
- igv.js version to 3.7.3 (#6096)
- Rework rank model file loading, allowing full URI (#6090)
- Refactored `scout delete` commands and relative tests into separate modules (#6102)
- Refactored scout delete commands and relative tests into separate modules (#6102)
- 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)
- Remove specifically research variants with the `scout delete variants` command (#6094)

## [4.108.2]
### Fixed
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