Esempio n. 1
0
 def test_call(self):
     """The 'call' command."""
     # Methods: clonal, threshold
     tr_cns = cnvlib.read("formats/tr95t.cns")
     tr_thresh = commands.do_call(tr_cns,
                                  "threshold",
                                  is_reference_male=True,
                                  is_sample_female=True)
     self.assertEqual(len(tr_cns), len(tr_thresh))
     tr_clonal = commands.do_call(tr_cns,
                                  "clonal",
                                  purity=.65,
                                  is_reference_male=True,
                                  is_sample_female=True)
     self.assertEqual(len(tr_cns), len(tr_clonal))
     cl_cns = cnvlib.read("formats/cl_seq.cns")
     cl_thresh = commands.do_call(cl_cns,
                                  "threshold",
                                  thresholds=np.log2(
                                      (np.arange(12) + .5) / 6.),
                                  is_reference_male=True,
                                  is_sample_female=True)
     self.assertEqual(len(cl_cns), len(cl_thresh))
     cl_clonal = commands.do_call(cl_cns,
                                  "clonal",
                                  ploidy=6,
                                  purity=.99,
                                  is_reference_male=True,
                                  is_sample_female=True)
     self.assertEqual(len(cl_cns), len(cl_clonal))
Esempio n. 2
0
    def test_call_sex(self):
        """Test each 'call' method on allosomes."""
        for (
                fname,
                sample_is_f,
                ref_is_m,
                chr1_expect,
                chrx_expect,
                chry_expect,
                chr1_cn,
                chrx_cn,
                chry_cn,
        ) in (
            ("formats/f-on-f.cns", True, False, 0, 0, None, 2, 2, None),
            ("formats/f-on-m.cns", True, True, 0.585, 1, None, 3, 2, None),
            ("formats/m-on-f.cns", False, False, 0, -1, 0, 2, 1, 1),
            ("formats/m-on-m.cns", False, True, 0, 0, 0, 2, 1, 1),
        ):
            cns = cnvlib.read(fname)
            chr1_idx = (cns.chromosome == 'chr1')
            chrx_idx = (cns.chromosome == 'chrX')
            chry_idx = (cns.chromosome == 'chrY')

            def test_chrom_means(segments):
                self.assertEqual(chr1_cn, segments['cn'][chr1_idx].mean())
                self.assertAlmostEqual(chr1_expect,
                                       segments['log2'][chr1_idx].mean(), 0)
                self.assertEqual(chrx_cn, segments['cn'][chrx_idx].mean())
                self.assertAlmostEqual(chrx_expect,
                                       segments['log2'][chrx_idx].mean(), 0)
                if not sample_is_f:
                    self.assertEqual(chry_cn, segments['cn'][chry_idx].mean())
                    self.assertAlmostEqual(chry_expect,
                                           segments['log2'][chry_idx].mean(),
                                           0)

            # Call threshold
            cns_thresh = commands.do_call(cns,
                                          None,
                                          "threshold",
                                          is_reference_male=ref_is_m,
                                          is_sample_female=sample_is_f)
            test_chrom_means(cns_thresh)
            # Call clonal pure
            cns_clone = commands.do_call(cns,
                                         None,
                                         "clonal",
                                         is_reference_male=ref_is_m,
                                         is_sample_female=sample_is_f)
            test_chrom_means(cns_clone)
            # Call clonal barely-mixed
            cns_p99 = commands.do_call(cns,
                                       None,
                                       "clonal",
                                       purity=0.99,
                                       is_reference_male=ref_is_m,
                                       is_sample_female=sample_is_f)
            test_chrom_means(cns_p99)
Esempio n. 3
0
 def test_call(self):
     # Methods: clonal, threshold
     tr_cns = cnvlib.read("formats/tr95t.cns")
     tr_thresh = commands.do_call(tr_cns, "threshold",
                         is_reference_male=True, is_sample_female=True)
     self.assertEqual(len(tr_cns), len(tr_thresh))
     tr_clonal = commands.do_call(tr_cns, "clonal",
                         purity=.65,
                         is_reference_male=True, is_sample_female=True)
     self.assertEqual(len(tr_cns), len(tr_clonal))
     cl_cns = cnvlib.read("formats/cl_seq.cns")
     cl_thresh = commands.do_call(cl_cns, "threshold",
                         thresholds=np.log2((np.arange(12) + .5) / 6.),
                         is_reference_male=True, is_sample_female=True)
     self.assertEqual(len(cl_cns), len(cl_thresh))
     cl_clonal = commands.do_call(cl_cns, "clonal",
                         ploidy=6, purity=.99,
                         is_reference_male=True, is_sample_female=True)
     self.assertEqual(len(cl_cns), len(cl_clonal))
Esempio n. 4
0
    def test_call_sex(self):
        """Test each 'call' method on allosomes."""
        for (fname, sample_is_f, ref_is_m,
             chr1_expect, chrx_expect, chry_expect,
             chr1_cn, chrx_cn, chry_cn,
            ) in (
                ("formats/f-on-f.cns", True, False, 0, 0, None, 2, 2, None),
                ("formats/f-on-m.cns", True, True, 0.585, 1, None, 3, 2, None),
                ("formats/m-on-f.cns", False, False, 0, -1, 0, 2, 1, 1),
                ("formats/m-on-m.cns", False, True, 0, 0, 0, 2, 1, 1),
            ):
            cns = cnvlib.read(fname)
            chr1_idx = (cns.chromosome == 'chr1')
            chrx_idx = (cns.chromosome == 'chrX')
            chry_idx = (cns.chromosome == 'chrY')
            def test_chrom_means(segments):
                self.assertEqual(chr1_cn, segments['cn'][chr1_idx].mean())
                self.assertAlmostEqual(chr1_expect,
                                       segments['log2'][chr1_idx].mean(), 0)
                self.assertEqual(chrx_cn, segments['cn'][chrx_idx].mean())
                self.assertAlmostEqual(chrx_expect,
                                       segments['log2'][chrx_idx].mean(), 0)
                if not sample_is_f:
                    self.assertEqual(chry_cn, segments['cn'][chry_idx].mean())
                    self.assertAlmostEqual(chry_expect,
                                           segments['log2'][chry_idx].mean(), 0)

            # Call threshold
            cns_thresh = commands.do_call(cns, None, "threshold",
                                 is_reference_male=ref_is_m,
                                 is_sample_female=sample_is_f)
            test_chrom_means(cns_thresh)
            # Call clonal pure
            cns_clone = commands.do_call(cns, None, "clonal",
                                is_reference_male=ref_is_m,
                                is_sample_female=sample_is_f)
            test_chrom_means(cns_clone)
            # Call clonal barely-mixed
            cns_p99 = commands.do_call(cns, None, "clonal", purity=0.99,
                              is_reference_male=ref_is_m,
                              is_sample_female=sample_is_f)
            test_chrom_means(cns_p99)
Esempio n. 5
0
 def test_call_filter(self):
     segments = cnvlib.read("formats/tr95t.segmetrics.cns")
     variants = tabio.read("formats/na12878_na12882_mix.vcf", "vcf")
     # Each filter individually, then all filters together
     for filters in (['ampdel'], ['cn'], ['ci'], ['sem'],
                     ['sem', 'cn', 'ampdel'],
                     ['ci', 'cn', 'ampdel']):
         result = commands.do_call(segments, variants, method="threshold",
                                   purity=.9, is_reference_male=True,
                                   is_sample_female=True, filters=filters)
         self.assertLessEqual(len(result), len(segments))
         self.assertLessEqual(len(segments.chromosome.unique()), len(result))
         for colname in 'baf', 'cn', 'cn1', 'cn2':
             self.assertIn(colname, result)
Esempio n. 6
0
 def test_call_filter(self):
     segments = cnvlib.read("formats/tr95t.segmetrics.cns")
     variants = tabio.read("formats/na12878_na12882_mix.vcf", "vcf")
     # Each filter individually, then all filters together
     for filters in (['ampdel'], ['cn'], ['ci'], ['sem'],
                     ['sem', 'cn', 'ampdel'],
                     ['ci', 'cn']):
         result = commands.do_call(segments, variants, method="threshold",
                                   purity=.9, is_reference_male=True,
                                   is_sample_female=True, filters=filters)
         self.assertLessEqual(len(result), len(segments))
         if 'ampdel' not in filters:
             # At least 1 segment per chromosome remains
             self.assertLessEqual(len(segments.chromosome.unique()),
                                  len(result))
         for colname in 'baf', 'cn', 'cn1', 'cn2':
             self.assertIn(colname, result)