예제 #1
0
    def test_low_coverage(self):

        pc = ProbeCoverage(min_depth=100,
                           percent_coverage=16,
                           median_depth=16,
                           k_count=16,
                           klen=31)
        s = SequenceProbeCoverage(name="A123T",
                                  probe_coverage=pc,
                                  percent_coverage_threshold=80

                                  )
        call = self.pt_10.type(s)
        assert call.genotype == [0, 0]

        pc = ProbeCoverage(min_depth=100,
                           percent_coverage=80,
                           median_depth=16,
                           k_count=16,
                           klen=31)
        s = SequenceProbeCoverage(name="A123T",
                                  probe_coverage=pc,
                                  percent_coverage_threshold=80

                                  )
        call = self.pt_10.type(s)
        assert call.genotype == [1, 1]
예제 #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]
예제 #3
0
    def test_genotyping_gene_11(self):
        pt_no_contaim = PresenceTyper(expected_depths=[20])
        pt_contaim = PresenceTyper(
            expected_depths=[20],
            contamination_depths=[10])

        pc = ProbeCoverage(min_depth=10,
                           percent_coverage=100,
                           median_depth=10,
                           k_count=100,
                           klen=31)
        s = SequenceProbeCoverage(name="A123T",
                                  probe_coverage=pc,
                                  percent_coverage_threshold=80

                                  )
        call = pt_no_contaim.type(s)
        assert call.genotype == [1, 1]

        call = pt_contaim.type(s)
        assert call.genotype == [0, 0]

        pc = ProbeCoverage(min_depth=10,
                           percent_coverage=100,
                           median_depth=30,
                           k_count=30,
                           klen=31)
        s = SequenceProbeCoverage(name="A123T",
                                  probe_coverage=pc,
                                  percent_coverage_threshold=80

                                  )
        call = pt_no_contaim.type(s)
        assert call.genotype == [1, 1]

        call = pt_contaim.type(s)
        assert call.genotype == [1, 1]

        pc = ProbeCoverage(min_depth=10,
                           percent_coverage=100,
                           median_depth=20,
                           k_count=20,
                           klen=31)
        s = SequenceProbeCoverage(name="A123T",
                                  probe_coverage=pc,
                                  percent_coverage_threshold=80

                                  )
        call = pt_no_contaim.type(s)
        assert call.genotype == [1, 1]

        call = pt_contaim.type(s)
        assert call.genotype == [1, 1]
예제 #4
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]
예제 #5
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]
예제 #6
0
    def _parse_seq_panel(self, row):
        (
            allele,
            median_depth,
            min_depth,
            percent_coverage,
            k_count,
            klen,
        ) = self._parse_summary_covgs_row(row)
        probe_coverage = ProbeCoverage(
            percent_coverage=percent_coverage,
            median_depth=median_depth,
            min_depth=min_depth,
            k_count=k_count,
            klen=klen,
        )

        allele_name = allele.split("?")[0]
        params = get_params(allele)
        panel_type = params.get("panel_type", "presence")
        name = params.get("name")
        version = params.get("version", "1")
        if panel_type in ["variant", "presence"]:
            sequence_probe_coverage = SequenceProbeCoverage(
                name=name,
                probe_coverage=probe_coverage,
                version=version,
                length=params.get("length"),
            )
            try:
                self.covgs[panel_type][name][version] = sequence_probe_coverage
            except KeyError:
                self.covgs[panel_type][name] = {}
                self.covgs[panel_type][name][version] = sequence_probe_coverage

        else:
            # Species panels are treated differently
            l = int(params.get("length", -1))
            try:
                self.covgs[panel_type][name]["total_bases"] += l
                if percent_coverage > 75 and median_depth > 0:
                    self.covgs[panel_type][name]["percent_coverage"].append(
                        percent_coverage)
                    self.covgs[panel_type][name]["length"].append(l)
                    self.covgs[panel_type][name]["median"].append(median_depth)
            except KeyError:
                if panel_type not in self.covgs:
                    self.covgs[panel_type] = {}
                self.covgs[panel_type][name] = {}
                self.covgs[panel_type][name]["total_bases"] = l
                if percent_coverage > 75 and median_depth > 0:
                    self.covgs[panel_type][name]["percent_coverage"] = [
                        percent_coverage
                    ]
                    self.covgs[panel_type][name]["length"] = [l]
                    self.covgs[panel_type][name]["median"] = [median_depth]
                else:
                    self.covgs[panel_type][name]["percent_coverage"] = []
                    self.covgs[panel_type][name]["length"] = []
                    self.covgs[panel_type][name]["median"] = []
예제 #7
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]
예제 #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
예제 #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]
 def test_base_case_no_coverage(self):
     pc = ProbeCoverage(min_depth=0,
                        percent_coverage=0,
                        median_depth=0,
                        k_count=0)
     s1 = SequenceProbeCoverage(name="A123T", probe_coverage=pc)
     call = self.pt.type(s1)
     assert call.genotype == [0, 0]
예제 #11
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]
    def test_resistotype_gene_at_high_CN(self):

        pc = ProbeCoverage(min_depth=100,
                           percent_coverage=100,
                           median_depth=1000,
                           k_count=100)
        s = SequenceProbeCoverage(name="A123T",
                                  probe_coverage=pc,
                                  percent_coverage_threshold=80)
        call = self.pt.type(s)
        assert call.genotype == [1, 1]
    def test_genotyping_gene_01(self):

        pc = ProbeCoverage(min_depth=100,
                           percent_coverage=82,
                           median_depth=2,
                           k_count=82)
        s = SequenceProbeCoverage(name="A123T",
                                  probe_coverage=pc,
                                  percent_coverage_threshold=80)
        call = self.pt.type(s)
        assert call.genotype == [0, 1]
예제 #14
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
예제 #15
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]
예제 #16
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")
예제 #17
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]