Exemplo n.º 1
0
    def test_reads_below_k31_makes_empty_vcf(self):
        nonvars = [Variant("Chr1", (20, 20), self.ref[0].seq[20])]
        reads: Reads = simulate_reads(self.ref,
                                      nonvars,
                                      read_len=15,
                                      fold_cov=1)
        reads.write(self.paths.reads_out)

        with mock.patch("cortex.calls._make_empty_vcf") as mock_empty_vcf:
            cortex_run(
                self.paths.ref_out,
                [self.paths.reads_out],
                self.paths.out_vcf,
                mem_height=2,
                tmp_directory=self.paths._tmp_dir,
                sample_name="mysample",
            )
            mock_empty_vcf.assert_called_once_with(self.paths.out_vcf,
                                                   "mysample")

        # Check the vcf gets actually made
        self.setUp()
        reads.write(self.paths.reads_out)
        cortex_run(
            self.paths.ref_out,
            [self.paths.reads_out],
            self.paths.out_vcf,
            mem_height=2,
            tmp_directory=self.paths._tmp_dir,
            cleanup=False,
        )
        self.assertTrue(self.paths.out_vcf.exists())
Exemplo n.º 2
0
    def test_simulate_reads_with_variant(self):
        variants = [Variant("r1", (9, 10), "AAT")]
        with mock.patch("random.randint") as randint:
            randint.return_value = 8

            reads = simulate_reads(self.refs, variants, 7, fold_cov=3)
            self.assertTrue(all([read.seq == "CAATGGA" for read in reads]))
Exemplo n.º 3
0
    def test_simulate_reads_no_variant(self):
        nonvars = [Variant("r1", (9, 9), self.refs[0].seq[9])]

        with mock.patch("random.randint") as randint:
            randint.return_value = 8

            reads = simulate_reads(self.refs, nonvars, 7, fold_cov=3)
            expected_seq = str(self.refs[0].seq[8:8 + 7])
            self.assertTrue(all([read.seq == expected_seq for read in reads]))
Exemplo n.º 4
0
    def test_not_enough_memory_fails(self):
        refs = simulate_refs(["id1"], [10000])
        reads = simulate_reads(refs, variants=list(), read_len=10)

        with tmpInputFiles() as paths:
            refs.write(paths.ref_out)
            reads.write(paths.reads_out)

            with self.assertRaises(RuntimeError):
                cortex_run(
                    paths.ref_out,
                    [paths.reads_out],
                    paths.out_vcf,
                    tmp_directory=paths._tmp_dir,
                    mem_height=1,
                )
Exemplo n.º 5
0
    def test_reads_with_no_var_makes_empty_vcf(self):
        nonvars = [Variant("Chr1", (50, 50), self.ref[0].seq[50])]
        reads: Reads = simulate_reads(self.ref,
                                      nonvars,
                                      read_len=40,
                                      fold_cov=30)
        reads.write(self.paths.reads_out)

        with mock.patch("cortex.calls._make_empty_vcf") as mock_empty_vcf:
            cortex_run(
                self.paths.ref_out,
                [self.paths.reads_out],
                self.paths.out_vcf,
                mem_height=2,
                tmp_directory=self.paths._tmp_dir,
            )
            mock_empty_vcf.assert_called_once()
Exemplo n.º 6
0
    def test_reads_with_one_snp_non_empty_vcf(self):
        snp_pos = 50
        ref_base = self.ref[0].seq[snp_pos]
        non_ref_choices = set(dna_choices).difference(set(ref_base))
        assert len(non_ref_choices) == len(dna_choices) - 1
        alt_base = random.choice(list(non_ref_choices))
        vars = [Variant("Chr1", (snp_pos, snp_pos), alt_base)]
        reads: Reads = simulate_reads(self.ref, vars, read_len=40, fold_cov=30)
        reads.write(self.paths.reads_out)

        cortex_run(
            self.paths.ref_out,
            [self.paths.reads_out],
            self.paths.out_vcf,
            mem_height=2,
            tmp_directory=self.paths.reads_out.parent,
            cleanup=False,
        )
        with self.paths.out_vcf.open() as vcf_out:
            all_lines = vcf_out.readlines()
            all_lines = [line for line in all_lines if line[0] != "#"]
        self.assertTrue(len(all_lines) > 0)
Exemplo n.º 7
0
 def test_read_on_ref_end_passes(self):
     variants = [
         Variant("r1", (3, 3), "T"),
         Variant("r1", (1, 1), "T"),
     ]
     simulate_reads(self.refs, variants, 1)
Exemplo n.º 8
0
 def test_read_len_beyond_ref_end_fails(self):
     variants = [Variant("r1", (3, 3), "T")]
     with self.assertRaises(ValueError):
         simulate_reads(self.refs, variants, 2)