Beispiel #1
0
    def test_should_have_near_zero_RR_genotype_likelihood_for_hom_alt_call(
            self):
        chr1 = 'chr1'
        sample_bank = SampleBank("TTTTTAAAAAAAAAAAAAAAAAAAA", chrom=chr1)

        sequence_bank_1 = sample_bank.add_sample_name('sample_1')
        sequence_bank_1.add_sequence(".........................",
                                     n_fwd=20,
                                     n_rev=20)

        sequence_bank_2 = sample_bank.add_sample_name('sample_2')
        sequence_bank_2.add_sequence("............C............",
                                     n_fwd=20,
                                     n_rev=20)

        vc_wrapper_builder = VariantCallerBuilderFromSampleBank(
            sample_bank, self.work_dir)
        variant_output = vc_wrapper_builder.build().run().output_vcf

        vcf_expectation = VCFExpectation(self, variant_output)
        record_expectation = vcf_expectation.has_record_for_variant(
            Variant(chr1, 12, "A", "C"))
        sample_expectation = record_expectation.with_sample("sample_1")

        sample_expectation.has_genotype("0|0").has_RR_genotype_likelihood(0.0)
Beispiel #2
0
    def test_should_add_sequences_with_same_reference(self):
        sample_bank = SampleBank("AAATTTTGGGGG")
        sample_bank.add_sample_name("SAMPLE1")
        sample_bank.add_sample_name("SAMPLE2")

        self.assertEqual(sample_bank["SAMPLE1"].reference.ref_seq,
                         sample_bank["SAMPLE2"].reference.ref_seq)
Beispiel #3
0
    def __run_small_variant_caller(self, refcalls, format):
        sample_bank = SampleBank("T")
        sample_bank.add_sample_name("TEST").add_sequence(".")

        variant_caller_builder = VariantCallerBuilderFromSampleBank(
            sample_bank, self.work_dir)
        variant_caller_builder.configuration = {}  # clear config.
        variant_caller = variant_caller_builder.build()
        variant_caller.add_additional_command('outputRefCalls', refcalls)
        variant_caller.add_additional_command('outputFormat',
                                              "VCF{}".format(format))
        variant_caller.run()

        with VCFReaderContextManager(variant_caller.output_vcf) as vcf_file:
            actual_schema = vcf_file.read_header()

        reference = os.path.splitext(
            os.path.basename(variant_caller_builder.wecall_input_data.
                             reference_filename))[0]
        expected_schema = wecall_schema(
            file_date=datetime.datetime.today().strftime('%F'),
            reference=reference,
            contigs={
                sample_bank.reference.chrom: {
                    "length": sample_bank.reference.length_minus_deletions()
                }
            },
            add_ref_calls=refcalls,
            format=format)

        return expected_schema, actual_schema
Beispiel #4
0
    def test_should_raise_when_adding_existing_sample(self):
        sample_bank = SampleBank("AAA")
        sample_name = "SAMPLE1"
        sample_bank.add_sample_name(sample_name)

        self.assertRaisesRegex(
            weCallException,
            "Sample SAMPLE1 already exists in the SampleBank.",
            sample_bank.add_sample_with_seqs_and_quals, sample_name, [])
Beispiel #5
0
    def test_should_add_sequence_with_quality(self):
        sample_bank = SampleBank("AAA")
        sample_name = "SAMPLE1"
        sample_bank.add_sample_name(sample_name)
        sample_bank[sample_name].add_sequence("...", quality_string="007")
        read_lists = [
            builder.build_reads(0, {}) for builder in sample_bank["SAMPLE1"]
        ]
        reads = [read for read_list in read_lists for read in read_list]

        # ascii: "0": "!", "1": "+", "2": "5", "3": "?", "4": "I", "5": "S",
        # "6": "]", "7": "g", "8": "q", "9": "{"
        self.assertEqual(reads[0].qual, "!!g")
Beispiel #6
0
    def test_should_return_all_variants(self):
        sample_bank = SampleBank("AAATTTTGGGAG")
        sample_bank.add_sample_name("SAMPLE1")
        sample_bank.add_sample_name("SAMPLE2")

        sample_bank["SAMPLE1"].add_sequence(".....G......")
        sample_bank["SAMPLE2"].add_sequence("..........*.")

        exp_variant1 = Variant(sample_bank.reference.chrom, 5, "T", "G")
        exp_variant2 = Variant(sample_bank.reference.chrom, 9, "GA", "G")
        self.assertEqual(sample_bank["SAMPLE1"].variants, {exp_variant1})
        self.assertEqual(sample_bank["SAMPLE2"].variants, {exp_variant2})
        self.assertEqual(sample_bank.variants, {exp_variant1, exp_variant2})
Beispiel #7
0
    def test_should_place_variants_at_custom_position(self):
        sample_bank = SampleBank("AAATTTTGGGAG", 100)
        sample_bank.add_sample_name("SAMPLE1")
        sample_bank.add_sample_name("SAMPLE2")

        sample_bank["SAMPLE1"].add_sequence(".....G......")
        sample_bank["SAMPLE2"].add_sequence("..........*.")

        exp_variant1 = Variant(sample_bank.reference.chrom, 105, "T", "G")
        exp_variant2 = Variant(sample_bank.reference.chrom, 109, "GA", "G")
        self.assertEqual(sample_bank["SAMPLE1"].variants, {exp_variant1})
        self.assertEqual(sample_bank["SAMPLE2"].variants, {exp_variant2})
        self.assertEqual(sample_bank.variants, {exp_variant1, exp_variant2})
Beispiel #8
0
    def test_can_build_correct_ref_and_bam_file(self):
        bank = SampleBank("ATCCT*ATAATAAATAAATAAT")
        sample_name = "TEST_SAMPLE"
        bank.add_sample_name(sample_name)
        bank[sample_name].add_sequence("....CT.........T......")

        builder = WecallInputDataBuilder(self.work_dir).with_sample_bank(bank)

        input_files = builder.build()

        bam_file = pysam.Samfile(input_files.bam_filenames[0], "rb")
        for read in bam_file.fetch():
            self.assertEqual(read.pos, 0)
            self.assertEqual(read.seq, "ATCCCTATAATAAATTAATAAT")
            self.assertEqual(read.cigarstring, "5M1I16M")

        fasta_file = pysam.Fastafile(input_files.reference_filename)
        self.assertEqual(fasta_file.get_reference_length(bank.reference.chrom),
                         21)
        self.assertEqual(fasta_file.fetch(bank.reference.chrom, 0, 21),
                         "ATCCTATAATAAATAAATAAT")
Beispiel #9
0
    def test_should_be_able_to_build_bam_and_ref_data_with_multiple_chromosomes(
            self):
        bank_1 = SampleBank("A" * 10, 0, chrom='10')
        bank_1.add_sample_name("sample").add_sequence("." * 10)

        bank_2 = SampleBank("T" * 9, 0, chrom='20')
        bank_2.add_sample_name("sample").add_sequence("." * 9)

        builder = WecallInputDataBuilder(
            self.work_dir).with_sample_bank(bank_1).with_sample_bank(bank_2)

        input_files = builder.build()
        bam_file = pysam.Samfile(input_files.bam_filenames[0], "rb")

        for read in bam_file.fetch(reference='20'):
            self.assertEqual(read.pos, 0)
            self.assertEqual(read.seq, "T" * 9)
            self.assertEqual(read.cigarstring, "9M")

        for read in bam_file.fetch(reference='10'):
            self.assertEqual(read.pos, 0)
            self.assertEqual(read.seq, "A" * 10)
            self.assertEqual(read.cigarstring, "10M")
            print((dir(read)))
Beispiel #10
0
    def test_can_build_multiple_bam_files(self):
        bank = SampleBank("ATCCT*ATAATAAATAAATAAT")
        sample_name1 = "TEST_SAMPLE1"
        bank.add_sample_name(sample_name1)
        bank[sample_name1].add_sequence("....CT.........T......")

        sample_name2 = "TEST_SAMPLE2"
        bank.add_sample_name(sample_name2)
        bank[sample_name2].add_sequence(".....*.G..........*...")

        builder = WecallInputDataBuilder(self.work_dir).with_sample_bank(bank)
        input_bams = builder.build().bam_filenames

        bam_file1 = pysam.Samfile(input_bams[0], "rb")
        for read in bam_file1.fetch():
            self.assertEqual(read.pos, 0)
            self.assertEqual(read.seq, "ATCCCTATAATAAATTAATAAT")
            self.assertEqual(read.cigarstring, "5M1I16M")

        bam_file2 = pysam.Samfile(input_bams[1], "rb")
        for read in bam_file2.fetch():
            self.assertEqual(read.pos, 0)
            self.assertEqual(read.seq, "ATCCTAGAATAAATAAAAAT")
            self.assertEqual(read.cigarstring, "17M1D3M")