RBCeq2 2.3.4__tar.gz → 2.3.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. {rbceq2-2.3.4/src/rbceq2.egg-info → rbceq2-2.3.6}/PKG-INFO +2 -2
  2. {rbceq2-2.3.4 → rbceq2-2.3.6}/README.md +1 -1
  3. {rbceq2-2.3.4 → rbceq2-2.3.6}/pyproject.toml +1 -1
  4. {rbceq2-2.3.4 → rbceq2-2.3.6}/src/rbceq2/IO/vcf.py +19 -9
  5. {rbceq2-2.3.4 → rbceq2-2.3.6}/src/rbceq2/core_logic/constants.py +2 -2
  6. {rbceq2-2.3.4 → rbceq2-2.3.6}/src/rbceq2/core_logic/data_procesing.py +59 -18
  7. {rbceq2-2.3.4 → rbceq2-2.3.6}/src/rbceq2/db/db.py +1 -1
  8. {rbceq2-2.3.4 → rbceq2-2.3.6}/src/rbceq2/filters/geno.py +7 -4
  9. {rbceq2-2.3.4 → rbceq2-2.3.6}/src/rbceq2/filters/phased.py +193 -22
  10. {rbceq2-2.3.4 → rbceq2-2.3.6}/src/rbceq2/main.py +34 -24
  11. {rbceq2-2.3.4 → rbceq2-2.3.6}/src/rbceq2/phenotype/antigens.py +1 -53
  12. {rbceq2-2.3.4 → rbceq2-2.3.6}/src/rbceq2/phenotype/choose_pheno.py +52 -33
  13. {rbceq2-2.3.4 → rbceq2-2.3.6}/src/rbceq2/resources/db.tsv +98 -98
  14. {rbceq2-2.3.4 → rbceq2-2.3.6/src/rbceq2.egg-info}/PKG-INFO +2 -2
  15. {rbceq2-2.3.4 → rbceq2-2.3.6}/tests/test_data_processing.py +2 -292
  16. {rbceq2-2.3.4 → rbceq2-2.3.6}/tests/test_geno_filters.py +11 -27
  17. {rbceq2-2.3.4 → rbceq2-2.3.6}/LICENSE +0 -0
  18. {rbceq2-2.3.4 → rbceq2-2.3.6}/MANIFEST.in +0 -0
  19. {rbceq2-2.3.4 → rbceq2-2.3.6}/setup.cfg +0 -0
  20. {rbceq2-2.3.4 → rbceq2-2.3.6}/src/rbceq2/IO/PDF_reports.py +0 -0
  21. {rbceq2-2.3.4 → rbceq2-2.3.6}/src/rbceq2/IO/__init__.py +0 -0
  22. {rbceq2-2.3.4 → rbceq2-2.3.6}/src/rbceq2/IO/record_data.py +0 -0
  23. {rbceq2-2.3.4 → rbceq2-2.3.6}/src/rbceq2/IO/validation.py +0 -0
  24. {rbceq2-2.3.4 → rbceq2-2.3.6}/src/rbceq2/__init__.py +0 -0
  25. {rbceq2-2.3.4 → rbceq2-2.3.6}/src/rbceq2/core_logic/__init__.py +0 -0
  26. {rbceq2-2.3.4 → rbceq2-2.3.6}/src/rbceq2/core_logic/alleles.py +0 -0
  27. {rbceq2-2.3.4 → rbceq2-2.3.6}/src/rbceq2/core_logic/co_existing.py +0 -0
  28. {rbceq2-2.3.4 → rbceq2-2.3.6}/src/rbceq2/core_logic/utils.py +0 -0
  29. {rbceq2-2.3.4 → rbceq2-2.3.6}/src/rbceq2/db/__init__.py +0 -0
  30. {rbceq2-2.3.4 → rbceq2-2.3.6}/src/rbceq2/filters/__init__.py +0 -0
  31. {rbceq2-2.3.4 → rbceq2-2.3.6}/src/rbceq2/filters/knops.py +0 -0
  32. {rbceq2-2.3.4 → rbceq2-2.3.6}/src/rbceq2/filters/shared_filter_functionality.py +0 -0
  33. {rbceq2-2.3.4 → rbceq2-2.3.6}/src/rbceq2/phenotype/__init__.py +0 -0
  34. {rbceq2-2.3.4 → rbceq2-2.3.6}/src/rbceq2.egg-info/SOURCES.txt +0 -0
  35. {rbceq2-2.3.4 → rbceq2-2.3.6}/src/rbceq2.egg-info/dependency_links.txt +0 -0
  36. {rbceq2-2.3.4 → rbceq2-2.3.6}/src/rbceq2.egg-info/entry_points.txt +0 -0
  37. {rbceq2-2.3.4 → rbceq2-2.3.6}/src/rbceq2.egg-info/requires.txt +0 -0
  38. {rbceq2-2.3.4 → rbceq2-2.3.6}/src/rbceq2.egg-info/top_level.txt +0 -0
  39. {rbceq2-2.3.4 → rbceq2-2.3.6}/tests/test_IO.py +0 -0
  40. {rbceq2-2.3.4 → rbceq2-2.3.6}/tests/test_VCF.py +0 -0
  41. {rbceq2-2.3.4 → rbceq2-2.3.6}/tests/test_alleles.py +0 -0
  42. {rbceq2-2.3.4 → rbceq2-2.3.6}/tests/test_ants.py +0 -0
  43. {rbceq2-2.3.4 → rbceq2-2.3.6}/tests/test_choose_pheno.py +0 -0
  44. {rbceq2-2.3.4 → rbceq2-2.3.6}/tests/test_co_filters.py +0 -0
  45. {rbceq2-2.3.4 → rbceq2-2.3.6}/tests/test_coexisting.py +0 -0
  46. {rbceq2-2.3.4 → rbceq2-2.3.6}/tests/test_db.py +0 -0
  47. {rbceq2-2.3.4 → rbceq2-2.3.6}/tests/test_filters_phase.py +0 -0
  48. {rbceq2-2.3.4 → rbceq2-2.3.6}/tests/test_main.py +0 -0
  49. {rbceq2-2.3.4 → rbceq2-2.3.6}/tests/test_pdf.py +0 -0
  50. {rbceq2-2.3.4 → rbceq2-2.3.6}/tests/test_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rbceq2
3
- Version: 2.3.4
3
+ Version: 2.3.6
4
4
  Summary: Call ISBT alleles from VCF/s
5
5
  Author-email: Liam McIntyre <limcintyre@redcrossblood.org.au>
6
6
  License: Copyright 2025 Australian Red Cross Lifeblood
@@ -45,7 +45,7 @@ Dynamic: license-file
45
45
  > [!WARNING]
46
46
  > NOT FOR CLINICAL USE
47
47
 
48
- ## Version v2.3.4
48
+ ## Version v2.3.6
49
49
 
50
50
  RBCeq2 reads in genomic variant data in the form of variant call files (VCF) and outputs blood group (BG) genotype and phenotype inference.
51
51
 
@@ -12,7 +12,7 @@
12
12
  > [!WARNING]
13
13
  > NOT FOR CLINICAL USE
14
14
 
15
- ## Version v2.3.4
15
+ ## Version v2.3.6
16
16
 
17
17
  RBCeq2 reads in genomic variant data in the form of variant call files (VCF) and outputs blood group (BG) genotype and phenotype inference.
18
18
 
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
6
6
 
7
7
  [project]
8
8
  name = "rbceq2"
9
- version = "2.3.4"
9
+ version = "2.3.6"
10
10
  description = "Call ISBT alleles from VCF/s"
11
11
  readme = "README.md"
12
12
  license = { file = "LICENSE" }
@@ -212,7 +212,7 @@ class VCF:
212
212
  ref = self.df.loc[self.df.loci == lane_loci, "REF"].values[0]
213
213
  alt = self.df.loc[self.df.loci == lane_loci, "ALT"].values[0]
214
214
  lane = LANE[f"chr{chrom}"][pos]
215
- if f"{ref}_{alt}" == lane or lane == 'no_ALT':
215
+ if f"{ref}_{alt}" == lane or lane == "no_ALT":
216
216
  self.df.loc[self.df.loci == lane_loci, "variant"] = (
217
217
  self.df.loc[
218
218
  self.df.loci == lane_loci, "variant"
@@ -260,9 +260,6 @@ class VCF:
260
260
  vcf_variants[variant] = mapped_metrics
261
261
  else:
262
262
  vcf_variants[variant] = mapped_metrics
263
- # if not all_ints_zero_or_one(mapped_metrics["GT"]):
264
- # #ic(11111111111,mapped_metrics["GT"], vcf_variants)
265
- # #raise ValueError('multi allele loci are not supported, please use bcftools norm -m -both on your VCF/s!')
266
263
 
267
264
  return vcf_variants
268
265
 
@@ -474,6 +471,7 @@ def read_vcf(file_path: str) -> pl.DataFrame:
474
471
  Returns:
475
472
  pl.DataFrame: DataFrame containing the VCF data.
476
473
  """
474
+
477
475
  header = None
478
476
  # Use gzip.open if file is gzipped, else standard open.
479
477
  open_func = gzip.open if str(file_path).endswith(".gz") else open
@@ -495,14 +493,26 @@ def read_vcf(file_path: str) -> pl.DataFrame:
495
493
  data = f.read()
496
494
 
497
495
  csv_content = header_line + data
498
- df = pl.read_csv(
499
- io.StringIO(csv_content),
500
- separator="\t",
501
- schema_overrides=dict.fromkeys(["CHROM", "POS", "QUAL"], str),
502
- )
496
+ try:
497
+ df = pl.read_csv(
498
+ io.StringIO(csv_content),
499
+ separator="\t",
500
+ schema_overrides=dict.fromkeys(["CHROM", "POS", "QUAL"], str),
501
+ )
502
+ except pl.exceptions.ComputeError:
503
+ logger.warning(
504
+ f"VCF {file_path} is not formatted correctly. Attempting to read in an error prone way!"
505
+ )
506
+ df = pl.read_csv(
507
+ io.StringIO(csv_content),
508
+ separator="\t",
509
+ schema_overrides=dict.fromkeys(["CHROM", "POS", "QUAL"], str),
510
+ truncate_ragged_lines=True,
511
+ )
503
512
  if df.is_empty():
504
513
  raise VcfNoDataError(filename=file_path)
505
514
  df = df.with_columns(df["CHROM"].str.replace("chr", "", literal=True))
515
+
506
516
  return df
507
517
 
508
518
 
@@ -1,8 +1,8 @@
1
1
  from enum import Enum, auto
2
2
 
3
3
  # Define version
4
- VERSION = "2.3.4"
5
- DB_VERSION = "2.3.3"
4
+ VERSION = "2.3.6"
5
+ DB_VERSION = "2.3.4"
6
6
 
7
7
 
8
8
  COMMON_COLS = ["CHROM", "POS", "ID", "REF", "ALT", "QUAL", "FILTER", "INFO", "FORMAT"]
@@ -17,6 +17,7 @@ from rbceq2.core_logic.utils import (
17
17
  )
18
18
  from rbceq2.db.db import Db
19
19
  from rbceq2.IO.vcf import VCF
20
+ import pandas as pd
20
21
 
21
22
 
22
23
  def raw_results(db: Db, vcf: VCF, exclude: list[str]) -> dict[str, list[Allele]]:
@@ -358,19 +359,10 @@ def ABO_phasing(
358
359
  if not variant.startswith(("9:133257521", "9:136132908")):
359
360
  phase = bg.variant_pool_phase[variant]
360
361
  aboO_phases.add(phase)
361
- # aboO_phases2 = set([]) I'm opting out of this path but if it ever gets revisited
362
- # do it at DB level #TODO look for vars that have only ever been observed in cis with
363
- # ABO*O, or never been observed with it and take phasing info from there. Best
364
- # to actually phase indels though
365
- # for variant in other.difference(aboO):
366
- # if not variant.startswith(("9:133257521", "9:136132908")):
367
- # phase = bg.variant_pool_phase[variant]
368
- # aboO_phases2.add(phase)
369
- # ic(aboO_phases,aboO_phases2,aboO, other, aboO.difference(other), other.difference(aboO))
362
+
370
363
  if len(aboO_phases) == 0:
371
364
  return bg # can't rescue ABO
372
365
  if len(aboO_phases) > 1:
373
- # ic(aboO_phases,aboO, other, aboO.difference(other), other.difference(aboO))
374
366
  return bg # can't rescue ABO
375
367
  abo_phase = aboO_phases.pop()
376
368
  not_abo_phase = "1|0" if abo_phase == "0|1" else "0|1"
@@ -594,7 +586,7 @@ def remove_alleles_with_low_read_depth(
594
586
  """
595
587
 
596
588
  filtered_out, passed_filtering = filter_vcf_metrics(
597
- bg.alleles[AlleleState.RAW], variant_metrics, "DP", min_read_depth, microarray
589
+ bg.alleles[AlleleState.FILT], variant_metrics, "DP", min_read_depth, microarray
598
590
  )
599
591
  if filtered_out:
600
592
  vars_affected = ",".join(filtered_out.keys())
@@ -605,6 +597,56 @@ def remove_alleles_with_low_read_depth(
605
597
  return bg
606
598
 
607
599
 
600
+ @apply_to_dict_values
601
+ def only_keep_alleles_if_FILTER_PASS(
602
+ bg: BloodGroup, df: pd.DataFrame, no_filter: bool
603
+ ) -> BloodGroup:
604
+ """
605
+ Remove alleles from a BloodGroup object that have defining variants with read depth
606
+ below a specified minimum threshold.
607
+
608
+ Args:
609
+ bg (BloodGroup): The BloodGroup object containing alleles to filter.
610
+ variant_metrics (dict[str, dict[str, int]]): A dictionary containing variant
611
+ metrics with read depth information.
612
+ min_read_depth (int): The minimum read depth threshold.
613
+
614
+ Returns:
615
+ BloodGroup: The BloodGroup object with alleles filtered based on read depth.
616
+ """
617
+ if no_filter:
618
+ bg.alleles[AlleleState.FILT] = bg.alleles[AlleleState.RAW]
619
+ return bg
620
+ passed_filtering = []
621
+ for allele in bg.alleles[AlleleState.RAW]:
622
+ keeper = True
623
+ for variant in allele.defining_variants:
624
+ if "_ref" in variant:
625
+ continue
626
+ try:
627
+ filter_value = df.query("variant.str.contains(@variant)")[
628
+ "FILTER"
629
+ ].iloc[0]
630
+ except IndexError:
631
+ message = f"FILTER parsing failed. Sample: {bg.sample}, BG: {bg.type}, variant/s: {variant}"
632
+ logger.error(message)
633
+ raise
634
+ if filter_value != "PASS":
635
+ keeper = False
636
+ break
637
+ if keeper:
638
+ passed_filtering.append(allele)
639
+
640
+ bg.filtered_out["FILTER_not_PASS"] = [
641
+ allele
642
+ for allele in bg.alleles[AlleleState.RAW]
643
+ if allele not in passed_filtering
644
+ ]
645
+ bg.alleles[AlleleState.FILT] = passed_filtering
646
+
647
+ return bg
648
+
649
+
608
650
  @apply_to_dict_values
609
651
  def remove_alleles_with_low_base_quality(
610
652
  bg: BloodGroup,
@@ -820,7 +862,10 @@ class SomeHomMultiVariantStrategy:
820
862
  ) -> list[Pair]:
821
863
  homs = get_fully_homozygous_alleles(self.ranked_chunks, bg.variant_pool_numeric)
822
864
  if len(homs) > 2 and len(homs[0]) == 0 and len(homs[1]) == 0:
823
- raise ValueError("No homs in the first two rank tiers.")
865
+ flat = [item for sublist in self.ranked_chunks for item in sublist]
866
+ return combine_all(
867
+ flat, bg.variant_pool_numeric
868
+ ) # pass to filters (low_weight_hom)
824
869
 
825
870
  first_chunk = self.ranked_chunks[0]
826
871
  if len(first_chunk) == 1 and len(self.ranked_chunks) == 1:
@@ -843,13 +888,9 @@ class NoHomMultiVariantStrategy:
843
888
  def process(
844
889
  self, bg: BloodGroup, reference_alleles: dict[str, Allele]
845
890
  ) -> list[Pair]:
846
- ref_allele = reference_alleles[
847
- bg.type
848
- ] # TODO - this is putting refs back in that have already been discarded as impossible
849
-
891
+ ref_allele = reference_alleles[bg.type]
850
892
  ref_options = self.non_ref_options + [ref_allele]
851
- # if bg.type == 'ABCC4':
852
- # ic(self.non_ref_options, ref_options, bg.variant_pool_phase, bg.variant_pool_phase_set)
893
+
853
894
  return combine_all(ref_options, bg.variant_pool_numeric)
854
895
 
855
896
 
@@ -257,7 +257,7 @@ def _is_null_genotype(genotype: str) -> bool:
257
257
  True if the genotype is identified as null, False otherwise.
258
258
  """
259
259
  geno_upper = genotype.upper()
260
- return "N." in geno_upper or geno_upper.endswith('N')
260
+ return "N." in geno_upper or geno_upper.endswith('N') or geno_upper == "KEL*02M.05"
261
261
 
262
262
  def prepare_db() -> pd.DataFrame:
263
263
  """Read and prepare the database from a TSV file, applying necessary transformations.
@@ -17,7 +17,7 @@ from rbceq2.filters.shared_filter_functionality import (
17
17
  all_hom,
18
18
  check_var,
19
19
  )
20
- from icecream import ic
20
+
21
21
 
22
22
  def split_pair_by_ref(pair: Pair) -> tuple[Allele, Allele]:
23
23
  """Split a pair of alleles into reference and non-reference.
@@ -118,7 +118,6 @@ def filter_pairs_on_antithetical_zygosity(
118
118
  return None
119
119
 
120
120
  to_remove = []
121
-
122
121
  if bg.type in antitheticals:
123
122
  anti1, anti2 = find_anti_variant_pair(antitheticals[bg.type])
124
123
  var_pool_no_chrom = {k.split(":")[1]: v for k, v in bg.variant_pool.items()}
@@ -126,6 +125,9 @@ def filter_pairs_on_antithetical_zygosity(
126
125
  return bg
127
126
  if var_pool_no_chrom.get(anti2) == Zygosity.HOM:
128
127
  return bg
128
+ if anti1 not in var_pool_no_chrom or anti2 not in var_pool_no_chrom:
129
+ # if Lane var doesn't get PASS FILTER
130
+ return bg
129
131
  if (
130
132
  var_pool_no_chrom.get(anti1) is None
131
133
  and var_pool_no_chrom.get(anti2) is None
@@ -376,7 +378,8 @@ def ABO_cant_pair_with_ref_cuz_261delG_HET(bg: BloodGroup) -> BloodGroup:
376
378
  BloodGroup: The updated BloodGroup after filtering out allele pairs where a
377
379
  reference allele is improperly paired.
378
380
  """
379
-
381
+ if bg.type != "ABO":
382
+ return bg
380
383
  to_remove = []
381
384
  for pair in bg.alleles[AlleleState.NORMAL]:
382
385
  if pair.contains_reference and not pair.all_reference:
@@ -389,7 +392,7 @@ def ABO_cant_pair_with_ref_cuz_261delG_HET(bg: BloodGroup) -> BloodGroup:
389
392
  check_available_variants, 0, tmp_pool2, operator.gt
390
393
  )
391
394
  if all(check_vars_other_strand(allele)):
392
- # ie, can they exist given other strand
395
+ # ie, can they exist given other chrom
393
396
  continue
394
397
  to_remove.append(pair)
395
398
 
@@ -1,6 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from functools import partial
4
+ from collections.abc import Callable
4
5
  from rbceq2.core_logic.alleles import BloodGroup, Pair
5
6
  from rbceq2.core_logic.constants import AlleleState
6
7
  from rbceq2.core_logic.utils import (
@@ -13,7 +14,6 @@ from rbceq2.filters.shared_filter_functionality import (
13
14
  identify_unphased,
14
15
  proceed,
15
16
  )
16
-
17
17
  from rbceq2.core_logic.alleles import Allele
18
18
 
19
19
 
@@ -681,33 +681,204 @@ def rm_ref_if_2x_HET_phased(bg: BloodGroup, phased: bool) -> BloodGroup:
681
681
  same_phase_set = partial(check_phase, bg.variant_pool_phase_set)
682
682
  same_phase = partial(check_phase, bg.variant_pool_phase)
683
683
  for pair in bg.alleles[AlleleState.NORMAL]:
684
- # if bg.type == 'ABCC4':
685
- # ic(pair)
686
684
  if pair.allele1.reference or pair.allele2.reference:
687
685
  to_remove.append(pair)
688
686
  continue
689
- if (same_phase_set(pair.allele1, ".") and same_phase(pair.allele2, "1/1")) and (
690
- same_phase_set(pair.allele2, ".") and same_phase(pair.allele2, "1/1")
691
- ):
692
- phase1 = set(
693
- [
694
- phase
695
- for variant, phase in bg.variant_pool_phase.items()
696
- if variant in pair.allele1.defining_variants
697
- ]
698
- )
699
- phase2 = set(
700
- [
701
- phase
702
- for variant, phase in bg.variant_pool_phase.items()
703
- if variant in pair.allele2.defining_variants
704
- ]
705
- )
687
+ if possible_to_use_phase(same_phase_set, same_phase, pair):
688
+ phase1 = allele_phase(bg.variant_pool_phase, pair.allele1)
689
+ phase2 = allele_phase(bg.variant_pool_phase, pair.allele2)
706
690
  assert phase1 != phase2
707
691
  phased_ref_free_pair_exists = True
708
692
  if to_remove and phased_ref_free_pair_exists:
709
- # if bg.type == 'ABCC4':
710
- # ic(3333333,to_remove)
711
693
  bg.remove_pairs(to_remove, "rm_ref_if_2x_HET_phased")
712
694
 
713
695
  return bg
696
+
697
+
698
+ def allele_phase(variant_pool, allele):
699
+ return set(
700
+ [
701
+ phase
702
+ for variant, phase in variant_pool.items()
703
+ if variant in allele.defining_variants
704
+ ]
705
+ )
706
+
707
+
708
+ def possible_to_use_phase(same_phase_set: Callable, same_phase: Callable, pair: Pair):
709
+ return (same_phase_set(pair.allele1, ".") and same_phase(pair.allele2, "1/1")) and (
710
+ same_phase_set(pair.allele2, ".") and same_phase(pair.allele2, "1/1")
711
+ )
712
+
713
+
714
+ @apply_to_dict_values
715
+ def low_weight_hom(bg: BloodGroup, phased: bool) -> BloodGroup:
716
+ """
717
+ Case where there's a hom but it isn't in the top 2 ranked chunk,
718
+ so SomeHomMultiVariantStrategy has to let it pass to here. in this
719
+ example the 2 highest weights are in in opposite phase.
720
+ no example where they're in phase, yet
721
+
722
+ 2025-09-17 08:08:58.947 | DEBUG | Sample: HG03437.vcf BG Name: FUT2
723
+
724
+ #Results:
725
+ Genotypes count: 4
726
+ Genotypes:
727
+ FUT2*01N.02/FUT2*01N.04 #only this is possible as in opposite phase
728
+ #and are the 2 biggest weights
729
+ FUT2*01N.02/FUT2*01N.14
730
+ FUT2*01N.02/FUT2*01N.16
731
+
732
+ Phenotypes (numeric):
733
+ Phenotypes (alphanumeric): Se-
734
+
735
+ #Data:
736
+ Vars:
737
+ 19:48703417_G_A : Heterozygous
738
+ 19:48703560_C_T : Heterozygous
739
+ 19:48703939_C_T : Heterozygous
740
+ 19:48703728_G_A : Homozygous
741
+ Vars_phase:
742
+ 19:48703417_G_A : 0|1
743
+ 19:48703560_C_T : 1|0
744
+ 19:48703939_C_T : 1|0
745
+ 19:48703728_G_A : 1/1
746
+ Vars_phase_set:
747
+ 19:48703417_G_A : 48646783
748
+ 19:48703560_C_T : 48646783
749
+ 19:48703939_C_T : 48646783
750
+ 19:48703728_G_A : .
751
+ Raw:
752
+ Allele
753
+ genotype: FUT2*01N.02
754
+ defining_variants:
755
+ 19:48703417_G_A
756
+ weight_geno: 1
757
+ phenotype: . or Se-
758
+ reference: False
759
+
760
+ Allele
761
+ genotype: FUT2*01N.04
762
+ defining_variants:
763
+ 19:48703560_C_T
764
+ weight_geno: 2
765
+ phenotype: . or Se-
766
+ reference: False
767
+
768
+ Allele
769
+ genotype: FUT2*01N.14
770
+ defining_variants:
771
+ 19:48703939_C_T
772
+ weight_geno: 8
773
+ phenotype: . or Se-
774
+ reference: False
775
+
776
+ Allele
777
+ genotype: FUT2*01N.16
778
+ defining_variants:
779
+ 19:48703728_G_A
780
+ weight_geno: 8
781
+ phenotype: . or Se-
782
+ reference: False
783
+ """
784
+
785
+ if not phased:
786
+ return bg
787
+ same_phase_set = partial(check_phase, bg.variant_pool_phase_set)
788
+ same_phase = partial(check_phase, bg.variant_pool_phase)
789
+ # store as list of tuples: (weight, pair)
790
+ pairs: list[tuple[float, Pair]] = []
791
+ for pair in bg.alleles[AlleleState.NORMAL]:
792
+ if possible_to_use_phase(same_phase_set, same_phase, pair):
793
+ phase1 = allele_phase(bg.variant_pool_phase, pair.allele1)
794
+ phase2 = allele_phase(bg.variant_pool_phase, pair.allele2)
795
+ assert phase1 != phase2
796
+ pairs.append((pair.allele1.weight_geno + pair.allele2.weight_geno, pair))
797
+ if not pairs:
798
+ return bg
799
+ if len(pairs) == 1:
800
+ return bg
801
+ weights = set([pair_tup[0] for pair_tup in pairs])
802
+ if len(weights) == 1:
803
+ return bg
804
+ # select the lowest-weighted pair
805
+ best_weight, best_pair = min(pairs, key=lambda x: x[0])
806
+
807
+ to_remove = [pair for pair in bg.alleles[AlleleState.NORMAL] if pair != best_pair]
808
+ if to_remove:
809
+ bg.remove_pairs(to_remove, "low_weight_hom")
810
+
811
+ return bg
812
+
813
+
814
+ @apply_to_dict_values
815
+ def no_defining_variant(bg: BloodGroup, phased: bool) -> BloodGroup:
816
+ """
817
+ need to rm ref as 1:25390874_ref not possible
818
+ as 1:25390874_C_G: Homozygous
819
+
820
+ bg.variant_pool_phase: {'1:25390874_C_G': '1/1',
821
+ '1:25408711_G_A': '0|1',
822
+ '1:25408711_ref': '1|0',
823
+ '1:25408815_T_C': '0|1',
824
+ '1:25408817_T_C': '0|1',
825
+ '1:25408840_G_T': '0|1',
826
+ '1:25408868_G_A': '0|1',
827
+ '1:25420739_G_C': '1|0',
828
+ '1:25420739_ref': '0|1'}
829
+ bg.variant_pool: {'1:25390874_C_G': 'Homozygous',
830
+ '1:25408711_G_A': 'Heterozygous',
831
+ '1:25408711_ref': 'Heterozygous',
832
+ '1:25408815_T_C': 'Heterozygous',
833
+ '1:25408817_T_C': 'Heterozygous',
834
+ '1:25408840_G_T': 'Heterozygous',
835
+ '1:25408868_G_A': 'Heterozygous',
836
+ '1:25420739_G_C': 'Heterozygous',
837
+ '1:25420739_ref': 'Heterozygous'}
838
+ ic| allele: Allele
839
+ genotype: RHCE*04
840
+ defining_variants:
841
+ 1:25390874_C_G
842
+ 1:25408815_T_C
843
+ 1:25408868_G_A
844
+ 1:25408711_G_A
845
+ 1:25420739_ref
846
+ 1:25408840_G_T
847
+ 1:25408817_T_C
848
+ weight_geno: 1000
849
+ phenotype: RH:2,3,-4,-5,22 or C+,E+,c-,e-,CE+
850
+ reference: False
851
+ ic| allele: Allele
852
+ genotype: RHCE*01
853
+ defining_variants:
854
+ 1:25420739_G_C
855
+ 1:25408711_ref
856
+ 1:25390874_ref
857
+ weight_geno: 1000
858
+ phenotype: RH:-2,-3,4,5,6 or C-,E-,c+,e+,f+
859
+ reference: True
860
+ """
861
+
862
+ if not phased:
863
+ return bg
864
+ to_remove = []
865
+
866
+ for pair in bg.alleles[AlleleState.NORMAL]:
867
+ for allele in pair.alleles:
868
+ if not allele.reference:
869
+ continue
870
+ if all(variant.endswith(".") for variant in allele.defining_variants):
871
+ continue
872
+ for variant in allele.defining_variants:
873
+ if variant == "9:133257521_T_TC" or variant == "136132908_T_TC":
874
+ continue
875
+ if variant not in bg.variant_pool:
876
+ # ic(variant)
877
+ to_remove.append(pair)
878
+ break
879
+ if to_remove:
880
+ # ic(1,bg.sample, bg.type,to_remove, bg.alleles[AlleleState.NORMAL], bg.variant_pool)
881
+ bg.remove_pairs(to_remove, "no_defining_variant")
882
+ # ic(2,to_remove, bg.alleles[AlleleState.NORMAL], bg.variant_pool)
883
+
884
+ return bg
@@ -19,7 +19,7 @@ import rbceq2.filters.geno as filt
19
19
  import rbceq2.filters.phased as filt_phase
20
20
  import rbceq2.filters.knops as filt_co
21
21
  import rbceq2.phenotype.choose_pheno as ph
22
- from rbceq2.core_logic.constants import PhenoType,DB_VERSION, VERSION
22
+ from rbceq2.core_logic.constants import PhenoType, DB_VERSION, VERSION
23
23
  from rbceq2.core_logic.utils import compose, get_allele_relationships
24
24
  from rbceq2.db.db import Db, prepare_db, DbDataConsistencyChecker
25
25
  from rbceq2.IO.PDF_reports import generate_all_reports
@@ -60,7 +60,6 @@ def parse_args(args: list[str]) -> argparse.Namespace:
60
60
  )
61
61
  version_str = f"%(prog)s {VERSION} (DB: {DB_VERSION})"
62
62
 
63
-
64
63
  parser.add_argument(
65
64
  "-v",
66
65
  "--version",
@@ -81,13 +80,10 @@ def parse_args(args: list[str]) -> argparse.Namespace:
81
80
  "--out", type=lambda p: Path(p).absolute(), help="Prefix for output files"
82
81
  )
83
82
  parser.add_argument(
84
- "--depth", type=int, help="Minimum number of reads for a variant", default=10
85
- )
86
- parser.add_argument(
87
- "--quality",
88
- type=int,
89
- help="Minimum average genotype quality for a variant",
90
- default=10,
83
+ "--no_filter",
84
+ action="store_true",
85
+ help="Use all variants, not just those where FILTER = PASS in the VCF",
86
+ default=False,
91
87
  )
92
88
  parser.add_argument(
93
89
  "--processes",
@@ -111,12 +107,12 @@ def parse_args(args: list[str]) -> argparse.Namespace:
111
107
  help="Use phase information",
112
108
  default=False,
113
109
  )
114
- parser.add_argument(
115
- "--microarray",
116
- action="store_true",
117
- help="Input is from a microarray.",
118
- default=False,
119
- )
110
+ # parser.add_argument(
111
+ # "--microarray",
112
+ # action="store_true",
113
+ # help="Input is from a microarray.",
114
+ # default=False,
115
+ # )
120
116
  parser.add_argument(
121
117
  "--debug",
122
118
  action="store_true",
@@ -153,7 +149,7 @@ def parse_args(args: list[str]) -> argparse.Namespace:
153
149
 
154
150
  def main():
155
151
  ic("Running RBCeq2...")
156
-
152
+
157
153
  start = pd.Timestamp.now()
158
154
  args = parse_args(sys.argv[1:])
159
155
  exclude = ["C4A", "C4B", "ATP11C", "CD99", "RHD", "RHCE"]
@@ -264,17 +260,20 @@ def find_hits(
264
260
  res = dp.make_blood_groups(res, vcf.sample)
265
261
 
266
262
  pipe: list[Callable] = [
263
+ partial(
264
+ dp.only_keep_alleles_if_FILTER_PASS, df=vcf.df, no_filter=args.no_filter
265
+ ),
267
266
  partial(
268
267
  dp.remove_alleles_with_low_read_depth,
269
268
  variant_metrics=vcf.variants,
270
- min_read_depth=args.depth,
271
- microarray=args.microarray,
269
+ min_read_depth=1,
270
+ microarray=False,
272
271
  ),
273
272
  partial(
274
273
  dp.remove_alleles_with_low_base_quality,
275
274
  variant_metrics=vcf.variants,
276
- min_base_quality=args.quality,
277
- microarray=args.microarray,
275
+ min_base_quality=1,
276
+ microarray=False,
278
277
  ),
279
278
  partial(dp.make_variant_pool, vcf=vcf),
280
279
  partial(
@@ -298,6 +297,10 @@ def find_hits(
298
297
  phased=args.phased,
299
298
  reference_alleles=db.reference_alleles,
300
299
  ),
300
+ partial(
301
+ filt_phase.no_defining_variant,
302
+ phased=args.phased,
303
+ ),
301
304
  co.homs,
302
305
  co.max_rank,
303
306
  partial(co.prep_co_putative_combos, allele_relationships=allele_relationships),
@@ -327,15 +330,22 @@ def find_hits(
327
330
  filt.filter_pairs_by_context,
328
331
  filt.impossible_alleles,
329
332
  partial(filt_phase.impossible_alleles_phased, phased=args.phased),
330
- partial(filt_phase.filter_if_all_HET_vars_on_same_side_and_phased, phased=args.phased),
331
- partial(filt_phase.filter_on_in_relationship_if_HET_vars_on_dif_side_and_phased, phased=args.phased),
333
+ partial(
334
+ filt_phase.filter_if_all_HET_vars_on_same_side_and_phased,
335
+ phased=args.phased,
336
+ ),
337
+ partial(
338
+ filt_phase.filter_on_in_relationship_if_HET_vars_on_dif_side_and_phased,
339
+ phased=args.phased,
340
+ ),
332
341
  partial(filt_phase.rm_ref_if_2x_HET_phased, phased=args.phased),
342
+ partial(filt_phase.low_weight_hom, phased=args.phased),
333
343
  filt_co.ensure_co_existing_HET_SNP_used,
334
344
  filt_co.filter_co_existing_pairs,
335
345
  filt_co.filter_co_existing_in_other_allele,
336
346
  filt_co.filter_co_existing_with_normal, # has to be after normal filters!!!!!!!
337
347
  filt_co.filter_co_existing_subsets,
338
- #partial(filt_co.filter_impossible_coexisting_alleles_phased, phased=args.phased),
348
+ # partial(filt_co.filter_impossible_coexisting_alleles_phased, phased=args.phased),
339
349
  dp.get_genotypes,
340
350
  dp.add_CD_to_XG,
341
351
  ]
@@ -344,7 +354,7 @@ def find_hits(
344
354
 
345
355
  res = dp.add_refs(db, res, excluded)
346
356
 
347
- #merge FUT 1 and 2
357
+ # merge FUT 1 and 2
348
358
  fut2s = res["FUT2"].genotypes.copy()
349
359
  fut1s = res["FUT1"].genotypes.copy()
350
360
  for allele_pair in fut2s: