Ejemplo n.º 1
0
    def test_simple_case(self):
        reference_coverage = ProbeCoverage(min_depth=100,
                                           percent_coverage=80,
                                           median_depth=80,
                                           k_count=80,
                                           klen=31)
        alt1 = ProbeCoverage(min_depth=100,
                             percent_coverage=50,
                             median_depth=20,
                             k_count=20,
                             klen=31)
        alt2 = ProbeCoverage(min_depth=100,
                             percent_coverage=40,
                             median_depth=80,
                             k_count=30,
                             klen=31)
        alternate_coverages = [alt1, alt2]

        v1 = VariantProbeCoverage(var_name="A123T",
                                  reference_coverages=[reference_coverage],
                                  alternate_coverages=alternate_coverages)

        reference_coverage = ProbeCoverage(min_depth=100,
                                           percent_coverage=80,
                                           median_depth=80,
                                           k_count=20,
                                           klen=31)
        alt1 = ProbeCoverage(min_depth=100,
                             percent_coverage=50,
                             median_depth=20,
                             k_count=20,
                             klen=31)
        alt2 = ProbeCoverage(min_depth=100,
                             percent_coverage=100,
                             median_depth=80,
                             k_count=100,
                             klen=31)

        alternate_coverages = [alt1, alt2]

        v2 = VariantProbeCoverage(var_name="A123T",
                                  reference_coverages=[reference_coverage],
                                  alternate_coverages=alternate_coverages)

        call = self.vt_no_contaim.type([v1, v2])
        assert call['genotype'] == [1, 1]
Ejemplo n.º 2
0
    def _parse_variant_panel(self, row):
        allele, median_depth, min_depth, percent_coverage, k_count = self._parse_summary_covgs_row(
            row)
        params = get_params(allele)
        if 'var_name' in params:
            var_name = params.get('var_name')
        else:
            var_name = allele.split('?')[0].split('-')[1]

        num_alts = int(params.get("num_alts", 0))
        reference_coverages = [
            ProbeCoverage(percent_coverage=percent_coverage,
                          median_depth=median_depth,
                          min_depth=min_depth,
                          k_count=k_count)
        ]
        alt_or_ref = 'ref'
        alternate_coverages = []
        for i in range(num_alts - 1):
            row = next(self.reader)
            ref_allele, median_depth, min_depth, percent_coverage, k_count = self._parse_summary_covgs_row(
                row)
            if ref_allele.split('-')[0] != 'ref':
                logger.warning("Fewer ref alleles than alt alleles for %s" %
                               ref_allele)
                alternate_coverages.append(
                    ProbeCoverage(min_depth=min_depth,
                                  k_count=k_count,
                                  percent_coverage=percent_coverage,
                                  median_depth=median_depth))
                num_alts -= 1
                break

            assert ref_allele.split('-')[0] == 'ref'
            reference_coverages.append(
                ProbeCoverage(percent_coverage=percent_coverage,
                              median_depth=median_depth,
                              min_depth=min_depth,
                              k_count=k_count))
        for i in range(num_alts):
            row = next(self.reader)
            alt_allele, median_depth, min_depth, percent_coverage, k_count = self._parse_summary_covgs_row(
                row)
            assert alt_allele.split('-')[0] == 'alt'
            alternate_coverages.append(
                ProbeCoverage(min_depth=min_depth,
                              k_count=k_count,
                              percent_coverage=percent_coverage,
                              median_depth=median_depth))
        variant_probe_coverage = VariantProbeCoverage(
            reference_coverages=reference_coverages,
            alternate_coverages=alternate_coverages,
            var_name=var_name,
            params=params)
        try:
            self.variant_covgs[allele].append(variant_probe_coverage)
        except KeyError:
            self.variant_covgs[allele] = [variant_probe_coverage]
Ejemplo n.º 3
0
    def test_simple_case(self):
        reference_coverage = ProbeCoverage(min_depth=100,
                                           percent_coverage=70,
                                           median_depth=80,
                                           k_count=80)
        alt1 = ProbeCoverage(min_depth=100,
                             percent_coverage=70,
                             median_depth=20,
                             k_count=20)
        alt2 = ProbeCoverage(min_depth=100,
                             percent_coverage=100,
                             median_depth=80,
                             k_count=80)
        alternate_coverages = [alt1, alt2]
        v1 = VariantProbeCoverage(var_name="A123T",
                                  reference_coverages=[reference_coverage],
                                  alternate_coverages=alternate_coverages)
        assert v1._choose_best_alternate_coverage() == alt2

        call = self.vt_no_contaim.type(v1)
        assert call['genotype'] == [1, 1]
Ejemplo n.º 4
0
 def test_mixed_vars2(self):
     reference_coverage = ProbeCoverage(min_depth=11,
                                        percent_coverage=100,
                                        median_depth=42,
                                        k_count=42)
     alternate_coverages = [
         ProbeCoverage(min_depth=94,
                       percent_coverage=100,
                       median_depth=102,
                       k_count=94)
     ]
     v1 = VariantProbeCoverage(var_name="A123T",
                               reference_coverages=[reference_coverage],
                               alternate_coverages=alternate_coverages)
     call = self.vt.type(v1)
     assert call['genotype'] == [0, 1]
Ejemplo n.º 5
0
 def test_alt_vars(self):
     reference_coverage = ProbeCoverage(min_depth=100,
                                        percent_coverage=3,
                                        median_depth=100,
                                        k_count=3)
     alternate_coverages = [
         ProbeCoverage(min_depth=100,
                       percent_coverage=100,
                       median_depth=100,
                       k_count=100)
     ]
     v1 = VariantProbeCoverage(var_name="A123T",
                               reference_coverages=[reference_coverage],
                               alternate_coverages=alternate_coverages)
     call = self.vt.type([v1])
     assert call['genotype'] == [1, 1]
Ejemplo n.º 6
0
    def test_2(self):
        reference_coverage = ProbeCoverage(min_depth=131,
                                           percent_coverage=95.2381,
                                           median_depth=155,
                                           k_count=131)
        alt1 = ProbeCoverage(min_depth=1,
                             percent_coverage=100,
                             median_depth=1,
                             k_count=1)
        alternate_coverages = [alt1]
        v1 = VariantProbeCoverage(var_name="A123T",
                                  reference_coverages=[reference_coverage],
                                  alternate_coverages=alternate_coverages)

        call = self.vt_no_contaim.type(v1)
        assert call['genotype'] == [0, 0]
Ejemplo n.º 7
0
    def test_simple_case(self):
        reference_coverage = ProbeCoverage(min_depth=100,
                                           percent_coverage=100,
                                           median_depth=80,
                                           k_count=80)
        alternate_coverages = [
            ProbeCoverage(min_depth=100,
                          percent_coverage=100,
                          median_depth=20,
                          k_count=40)
        ]
        v1 = VariantProbeCoverage(var_name="A123T",
                                  reference_coverages=[reference_coverage],
                                  alternate_coverages=alternate_coverages)

        call = self.vt_no_contaim.type(v1)
        assert call['genotype'] == [0, 1]
Ejemplo n.º 8
0
    def test_3(self):
        reference_coverage = ProbeCoverage(min_depth=2,
                                           percent_coverage=59.52,
                                           median_depth=2,
                                           k_count=60)
        alt1 = ProbeCoverage(min_depth=1,
                             percent_coverage=83.33,
                             median_depth=1,
                             k_count=83)
        alternate_coverages = [alt1]
        v1 = VariantProbeCoverage(var_name="A123T",
                                  reference_coverages=[reference_coverage],
                                  alternate_coverages=alternate_coverages)

        call = self.vt2_no_contaim.type(v1)
        assert call['genotype'] == [1, 1]
        assert call["info"]["conf"] < 100
Ejemplo n.º 9
0
 def test_wt_vars(self):
     reference_coverage = ProbeCoverage(min_depth=100,
                                        percent_coverage=100,
                                        median_depth=100,
                                        k_count=100)
     alternate_coverages = [
         ProbeCoverage(min_depth=100,
                       percent_coverage=3,
                       median_depth=100,
                       k_count=3)
     ]
     v1 = VariantProbeCoverage(var_name="A123T",
                               reference_coverages=[reference_coverage],
                               alternate_coverages=alternate_coverages)
     call = self.vt.type([v1])
     assert call['genotype'] == [0, 0]
     assert call["info"].get('expected_depths') == [100]
Ejemplo n.º 10
0
 def _parse_variant_panel(self, row):
     (
         probe,
         median_depth,
         min_depth,
         percent_coverage,
         k_count,
         klen,
     ) = self._parse_summary_covgs_row(row)
     params = get_params(probe)
     probe_type = probe.split("-")[0]
     if "var_name" in params:
         var_name = (params.get("gene", "") + "_" + params.get("mut", "") +
                     "-" + params.get("var_name", ""))
     else:
         var_name = allele.split("?")[0].split("-")[1]
     if not var_name in self.variant_covgs:
         variant_probe_coverage = VariantProbeCoverage(
             reference_coverages=[],
             alternate_coverages=[],
             var_name=probe,
             params=params,
         )
         self.variant_covgs[var_name] = variant_probe_coverage
     probe_coverage = ProbeCoverage(
         min_depth=min_depth,
         k_count=k_count,
         percent_coverage=percent_coverage,
         median_depth=median_depth,
         klen=klen,
     )
     if probe_type == "ref":
         self.variant_covgs[var_name].reference_coverages.append(
             probe_coverage)
         self.variant_covgs[
             var_name].best_reference_coverage = self.variant_covgs[
                 var_name]._choose_best_reference_coverage()
     elif probe_type == "alt":
         self.variant_covgs[var_name].alternate_coverages.append(
             probe_coverage)
         self.variant_covgs[
             var_name].best_alternate_coverage = self.variant_covgs[
                 var_name]._choose_best_alternate_coverage()
     else:
         raise ValueError("probe_type must be ref or alt")
Ejemplo n.º 11
0
    def test_4(self):
        vt = VariantTyper(expected_depths=[6],
                          contamination_depths=[],
                          confidence_threshold=3)
        reference_coverage = ProbeCoverage(min_depth=1,
                                           percent_coverage=100,
                                           median_depth=2,
                                           k_count=2)
        alt1 = ProbeCoverage(min_depth=1,
                             percent_coverage=100,
                             median_depth=1,
                             k_count=1)
        alternate_coverages = [alt1]
        v1 = VariantProbeCoverage(var_name="A123T",
                                  reference_coverages=[reference_coverage],
                                  alternate_coverages=alternate_coverages)

        call = vt.type(v1)
        assert call['genotype'] == [0, 1]
        print(call["info"])
        assert call["info"]["conf"] < 100