|
1 | 1 | import logging |
2 | 2 | import re |
3 | 3 | from datetime import datetime, timedelta |
4 | | -from typing import List, Optional, Union |
| 4 | +from typing import List, Optional, Set, Union |
5 | 5 |
|
6 | 6 | from scout.constants import ( |
7 | 7 | CLINSIG_MAP, |
@@ -52,31 +52,29 @@ def build_case_query( |
52 | 52 | def delete_variants_query( |
53 | 53 | self, |
54 | 54 | case_id: str, |
55 | | - variants_to_keep: List[str] = [], |
| 55 | + variants_to_keep: Set[str] | None = None, |
56 | 56 | min_rank_threshold: Optional[int] = None, |
57 | | - keep_ctg: List[str] = [], |
| 57 | + remove_ctg: List[str] | None = None, |
58 | 58 | ) -> dict: |
59 | | - """Build a query to delete variants from a case (variant collection). |
| 59 | + """Build a query to delete variants from a case. |
60 | 60 |
|
61 | 61 | 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. |
63 | 64 | """ |
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 |
80 | 78 |
|
81 | 79 | def build_variant_query( |
82 | 80 | self, |
|
0 commit comments