Skip to content

Commit 5705c49

Browse files
author
Chiara Rasi
committed
Fix conflicts
1 parent 79a1b35 commit 5705c49

File tree

4 files changed

+348
-180
lines changed

4 files changed

+348
-180
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ About changelog [here](https://keepachangelog.com/en/1.0.0/)
1111
- Export genotype with gene variantS search (#6088)
1212
- igv.js version to 3.7.3 (#6096)
1313
- Rework rank model file loading, allowing full URI (#6090)
14-
- Refactored `scout delete` commands and relative tests into separate modules (#6102)
14+
- Refactored scout delete commands and relative tests into separate modules (#6102)
15+
- Refactor, speedup and add a progress bar to `scout delete variants` cmd (#6094)
16+
- `scout delete variants` command now accepts an optional `--out-file` where to print a detailed report of the deletion process (#6094)
1517
### Fixed
1618
- Comments' text wrapping in ACMG classifications exported as PDF (#6086)
1719
- Individual breakpoint gDNA IGV links should not trigger split locus view (#6103)

scout/adapter/mongo/query.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
import re
33
from datetime import datetime, timedelta
4-
from typing import List, Optional, Union
4+
from typing import List, Optional, Set, Union
55

66
from scout.constants import (
77
CLINSIG_MAP,
@@ -52,31 +52,29 @@ def build_case_query(
5252
def delete_variants_query(
5353
self,
5454
case_id: str,
55-
variants_to_keep: List[str] = [],
55+
variants_to_keep: Set[str] | None = None,
5656
min_rank_threshold: Optional[int] = None,
57-
keep_ctg: List[str] = [],
57+
remove_ctg: List[str] | None = None,
5858
) -> dict:
59-
"""Build a query to delete variants from a case (variant collection).
59+
"""Build a query to delete variants from a case.
6060
6161
Removes variants with rank lower than `min_rank_threshold`.
62-
Retains variants in categories `keep_ctg` by excluding them from deletion - eg `["cancer", "cancer_sv"]`.
62+
Retains variants in categories `keep_ctg` and specific variant IDs in
63+
`variants_to_keep` by excluding them from deletion.
6364
"""
64-
variants_query = {}
65-
case_subquery = {"case_id": case_id}
66-
67-
# Create query to delete all variants that shouldn't be kept or with rank higher than min_rank_threshold
68-
if variants_to_keep or min_rank_threshold or keep_ctg:
69-
variants_query["$and"] = [case_subquery]
70-
if variants_to_keep:
71-
variants_query["$and"].append({"_id": {"$nin": variants_to_keep}})
72-
if keep_ctg:
73-
variants_query["$and"].append({"category": {"$nin": keep_ctg}})
74-
if min_rank_threshold:
75-
variants_query["$and"].append({"rank_score": {"$lt": min_rank_threshold}})
76-
else:
77-
variants_query = case_subquery
78-
79-
return variants_query
65+
66+
query: dict = {"case_id": case_id}
67+
68+
if variants_to_keep:
69+
query["_id"] = {"$nin": variants_to_keep}
70+
71+
if remove_ctg:
72+
query["category"] = {"$in": remove_ctg}
73+
74+
if min_rank_threshold is not None:
75+
query["rank_score"] = {"$lt": min_rank_threshold}
76+
77+
return query
8078

8179
def build_variant_query(
8280
self,

0 commit comments

Comments
 (0)