def test_should_fail_if_invalid_output_file_format_provided(self): svc_driver = SVCDriver(self) svc_driver \ .with_ref_sequence("A") \ .with_read(".") \ .with_output_format('bah4.1') svc_driver.call(False).with_incorrect_output_format_error()
def test_should_fail_if_mem_limit_is_negative(self): svc_driver = SVCDriver(self) svc_driver \ .with_ref_sequence("A") \ .with_read(".") \ .with_mem_limit(-100) \ .with_output_vcf_filename(self.output_filename) svc_driver.call(False).with_mem_limit_range_error()
def test_should_fail_if_mem_limit_is_just_above_acceptable_range(self): svc_driver = SVCDriver(self) svc_driver \ .with_ref_sequence("A") \ .with_read(".") \ .with_mem_limit(1024 * 1024 + 1) \ .with_output_vcf_filename(self.output_filename) svc_driver.call(False).with_mem_limit_range_error()
def test_should_not_fail_due_to_existing_output_if_overwrite_specified( self): open(self.output_filename, "w").close() svc_driver = SVCDriver(self) svc_driver \ .with_ref_sequence("A") \ .with_read(".") \ .with_overwrite(True) \ .with_output_vcf_filename(self.output_filename) svc_driver.call(expected_success=True)
def test_get_unknown_quality_if_no_reads_span_region(self): chrom = "1" driver = SVCDriver(self) driver.with_ref_sequence( "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", chrom=chrom ).with_read( " ", ).with_output_ref_calls(True) driver.call().with_output_vcf().has_record(chrom, 0, "A", ref_alt).with_quality(None)
def test_should_run_if_interval_not_contained_in_reference(self): svc = SVCDriver(self) svc.with_ref_sequence( "ACGTACGTACGTACGTACGTACGT", chrom="1" ).with_read( "....G...................", chrom="1" ).with_bed_file( ['1\t24\t28'] ).with_region_padding(0) svc.call(True).with_output_vcf().record_count(0)
def test_should_have_standard_set_of_info_keys_for_variant(self): svc_driver = SVCDriver(self)\ .with_ref_sequence( "TAGAATTGTTTGAGCTCTTTGTATTTCCTGTTATTAATCCCTTGTCAGAAGGGTCGTTTG", )\ .with_read( "....................A.......................................", n_fwd=3, n_rev=0) svc_driver.call()\ .with_output_vcf()\ .record_count(1)\ .has_record_for_variant(Variant("1", 20, "G", "A"))\ .with_info()\ .has_keys("PP", "DP", "DPR", "DPF", "VC", "VCR", "VCF", "ABPV", "SBPV", "MQ", "QD", "BR")
def test_should_fail_if_output_already_exists_serial(self): open(self.output_filename, "w").close() svc_driver = SVCDriver(self) svc_driver \ .with_ref_sequence("A") \ .with_read(".") \ .with_overwrite(False) \ .with_output_vcf_filename(self.output_filename) assert (os.path.exists(self.output_filename)) svc_driver.call(expected_success=False).output_exists_error( self.output_filename)
def test_should_cope_with_region_padding_which_pads_to_negative_index_into_reference(self): svc = SVCDriver(self) svc.with_ref_sequence( "AAAGCGTACAACCGGGTTAGTCACAAACCCGTTACGTATGCCCCCCCCCCCATG", chrom='1' ).with_read( "......................................................", chrom='1', n_fwd=10, n_rev=10 ).with_read( " ...............................G.......... ", chrom='1', n_fwd=10, n_rev=10 ).with_read( " ..............................T........... ", chrom='1', n_fwd=6, n_rev=6) svc.with_region_string('1:20-41') svc.with_region_padding(20) svc.call(expected_success=True)
def test_raises_if_genotyping_file_doesnt_exist(self): missing_file = join( self.work_dir, "I_DONT_EXIST_NOT_JUST_IN_THE_PHILOSOPHICAL_SENSE.vcf.gz") driver = SVCDriver(self) driver.with_ref_sequence("ACGCCCCCTGCAAAAAAAAAA", ).with_read( "....G................", n_fwd=5, n_rev=5, ).with_genotype_alleles(missing_file).with_verbosity(0) driver.call(expected_success=False)\ .missing_genotype_file(missing_file)
def test_should_not_fail_due_to_existing_output_if_no_option_specified_in_parallel( self): open(self.output_filename, "w").close() svc_driver = SVCDriver(self) svc_driver \ .with_ref_sequence("A") \ .with_read(".") \ .with_number_of_jobs(2) \ .with_work_dir(self.we_call_work_dir) \ .with_output_vcf_filename(self.output_filename) assert (os.path.exists(self.output_filename)) svc_driver.call(expected_success=True)
def test_raises_if_genotyping_file_is_not_expected_format(self): gv_builder = VCFBuilder(join(self.work_dir, "genotype.vcf")) gv_builder.build() # note: not compressed or indexed driver = SVCDriver(self) driver.with_ref_sequence("ACGCCCCCTGCAAAAAAAAAA", ).with_read( "....G................", n_fwd=5, n_rev=5, ).with_genotype_alleles(gv_builder.filename).with_verbosity(0) driver.call(expected_success=False)\ .unexpected_genotype_file_format(gv_builder.filename)
def test_depth_computation_all_reads_spanning_reference_with_insertion( self): sample_name = "bah" chrom = "1" driver = SVCDriver(self) driver.with_ref_sequence( "AAAAAAAAAAAAAAAC*AAAAAAAAAAAAAAAAAAAAAAA", chrom=chrom).with_read( "................T.......................", n_rev=5, n_fwd=5, sample_name=sample_name).with_output_ref_calls( True).with_allow_MNP_calls(False) expect = driver.call() vcf_expect = expect.with_output_vcf() vcf_expect \ .has_record_for_variant(Variant(chrom, 0, "A", ref_alt))\ .with_sample(sample_name).has_read_depth(10).has_min_read_depth(10) vcf_expect \ .has_record_for_variant(Variant(chrom, 15, "C", "CT"))\ .with_sample(sample_name).has_read_depth(10) vcf_expect \ .has_record_for_variant(Variant(chrom, 16, "A", ref_alt))\ .with_sample(sample_name).has_read_depth(10).has_min_read_depth(10)
def test_phase_alignment_for_two_snps_in_different_clusters_on_different_strands( self): sample_name = "a_sample" chrom = "1" svc_driver = SVCDriver(self)\ .with_ref_sequence( "ACGCCCCCTGGGGGGGGGTGGGGGGGGGGGCAAAAAAAAAA", chrom=chrom) \ .with_read( ".......A.................................", n_fwd=10, n_rev=10, sample_name=sample_name) \ .with_read( ".............................A...........", n_fwd=10, n_rev=10, sample_name=sample_name) \ .with_output_phased_genotypes(True) \ .with_max_cluster_distance(10) \ vcf_expect = svc_driver.call()\ .with_output_vcf()\ .record_count(2) vcf_expect.has_record_for_variants(Variant(chrom, 7, "C", "A"))\ .with_sample(sample_name)\ .has_exact_phased_genotypes("1|0")\ .has_phase_set_id("7") vcf_expect.has_record_for_variants(Variant(chrom, 29, "G", "A"))\ .with_sample(sample_name)\ .has_exact_phased_genotypes("0|1")\ .has_phase_set_id("7")
def test_phase_not_aligns_for_hom_snp_in_first_cluster(self): sample_name = "a_sample" chrom = "1" svc_driver = SVCDriver(self)\ .with_ref_sequence( "ACGCCCCCTGGGGGGGGGTGGGGGGGGGGGCAAAAAAAAAA", chrom=chrom) \ .with_read( ".......A.....................A...........", n_fwd=10, n_rev=10, sample_name=sample_name) \ .with_read( ".......A.................................", n_fwd=10, n_rev=10, sample_name=sample_name) \ .with_output_phased_genotypes(True) \ .with_allow_MNP_calls(False) \ .with_max_cluster_distance(10) vcf_expect = svc_driver.call()\ .with_output_vcf()\ .record_count(2) vcf_expect.has_record_for_variants(Variant(chrom, 7, "C", "A"))\ .with_sample(sample_name)\ .has_exact_phased_genotypes("1|1")\ .has_phase_set_id("7") vcf_expect.has_record_for_variants(Variant(chrom, 29, "G", "A"))\ .with_sample(sample_name)\ .has_exact_phased_genotypes("1|0")\ .has_phase_set_id("28")
def test_should_handle_complex_variant_input(self): chrom = "22" variant = Variant(chrom, 10, "CAA", "CA") gv_builder = VCFBuilder(join(self.work_dir, "genotype.vcf")) gv_builder.with_record_from_variant(variant) gv_builder.build().index() driver = SVCDriver(self) dodgy_sample = "bobs_your_uncle" driver.with_ref_sequence( "ACGCCCCCTGCAAAAAAAAAA", chrom=chrom, pos_from=0).with_read( "...........C.........", n_fwd=5, n_rev=5, chrom=chrom, sample_name=dodgy_sample).with_genotype_alleles( gv_builder.compressed_filename) expect = driver.call() expect.with_log()\ .input_variant_trimmed_warning(variant, Variant(chrom, 11, "A", "")) expect.with_output_vcf()\ .record_count(1)
def test_doesnt_give_a_flying_damn_about_spurious_filters(self): chrom = "22" variant = Variant(chrom, 11, "A", "C") gv_builder = VCFBuilder(join(self.work_dir, "genotype.vcf")) gv_builder.with_record_from_variant(variant, filters={"#$.:@$%$%^&**()7!"}) gv_builder.build().index() driver = SVCDriver(self) dodgy_sample = "bobs_your_uncle" driver.with_ref_sequence( "ACGCCCCCTGCAAAAAAAAAA", chrom=chrom, pos_from=0).with_read( "...........C.........", n_fwd=5, n_rev=5, chrom=chrom, sample_name=dodgy_sample).with_genotype_alleles( gv_builder.compressed_filename) expect = driver.call(expected_success=True) expect.with_output_vcf()\ .has_record_for_variant(variant)\ .with_sample(dodgy_sample)\ .has_genotype("1/1")
def test_phase_alignment_for_het_variants_for_three_clusters_when_first_cluster_is_homozygous( self): sample_name = "sample1" chrom = "1" svc_driver = SVCDriver(self)\ .with_ref_sequence( "ACGCCCCCTGGGGGGGGGTGGGGGGGGGGGCAAAAAAAAAA", chrom=chrom) \ .with_read( "....A....................................", n_fwd=10, n_rev=10, sample_name=sample_name) \ .with_read( "....A.............C...............T......", n_fwd=10, n_rev=10, sample_name=sample_name) \ .with_output_phased_genotypes(True) \ .with_allow_MNP_calls(False) \ .with_max_cluster_distance(5) \ .with_min_cluster_distance(5) vcf_expect = svc_driver.call()\ .with_output_vcf()\ .record_count(3) vcf_expect.has_record_for_variants(Variant(chrom, 4, "C", "A"))\ .with_sample(sample_name)\ .has_exact_phased_genotypes("1|1")\ .has_phase_set_id("4") vcf_expect.has_record_for_variants(Variant(chrom, 18, "T", "C"))\ .with_sample(sample_name)\ .has_exact_phased_genotypes("1|0")\ .has_phase_set_id("13") vcf_expect.has_record_for_variants(Variant(chrom, 34, "A", "T"))\ .with_sample(sample_name)\ .has_exact_phased_genotypes("1|0")\ .has_phase_set_id("13")
def test_should_call_variants(self): chrom = 'chr1' sample_name = 'sample' svc = SVCDriver(self) \ .with_ploidy(3) svc.with_ref_sequence( "AAAGCGTACAACCGGGTTAGTC***AACCCGTTACGTATGCATG", chrom=chrom ).with_read( "......C.........G.....ATG.......***.........", n_rev=10, n_fwd=10, chrom=chrom, sample_name=sample_name ).with_read( "......C...............ATG.......***.........", n_rev=10, n_fwd=10, chrom=chrom, sample_name=sample_name ).with_read( "......................ATG.......***.........", n_rev=10, n_fwd=10, chrom=chrom, sample_name=sample_name) expect = svc.call() vcf = expect \ .with_output_vcf() \ .record_count(4) vcf.has_record_for_variant(Variant(chrom, 6, 'T', 'C')).with_sample(sample_name).has_genotype('0/1/1') vcf.has_record_for_variant(Variant(chrom, 16, 'T', 'G')).with_sample(sample_name).has_genotype('0/0/1') vcf.has_record_for_variant(Variant(chrom, 21, 'C', 'CATG')).with_sample(sample_name).has_genotype('1/1/1') vcf.has_record_for_variant(Variant(chrom, 28, 'TTAC', 'T')).with_sample(sample_name).has_genotype('1/1/1')
def test_bad_reads_filter_not_applied_if_one_sample_is_not_naughty(self): svc = SVCDriver(self) svc.with_var_filters("BR") svc.with_bad_reads_window_size(7) svc.with_min_bad_reads_score(13) svc.with_ref_sequence( # 1234567890123456789 "AAAGCGTACAACCGGGTTAGTCACAAACCCGTTACGTATGCATG").with_read( "................G...........................", " 3333333 3333333 ", sample_name="GOOD", n_rev=2, n_fwd=2).with_read( "................G...........................", " 0000000 0000000 ", sample_name="BAD", n_rev=10, n_fwd=10).with_read( "................G...........................", " 00000 0000 ", sample_name="UGLY", n_rev=10, n_fwd=10) expect = svc.call() vcf_expectation = expect.with_output_vcf() vcf_expectation.record_count(1) vcf_expectation \ .has_record_for_variant(Variant(DEFAULT_CHROM, 16, "T", "G")) \ .with_no_filters()
def test_bad_reads_filter_not_applied_when_median_read_is_good(self): svc = SVCDriver(self) \ .with_var_filters("BR") \ .with_bad_reads_window_size(7) \ .with_min_bad_reads_score(20) svc.with_ref_sequence( # 1234567890123456789 "AAAGCGTACAACCGGGTTAGTCACAAACCCGTTACGTATGCATG").with_read( "................G...........................", " 1 1 ", n_rev=10, n_fwd=10).with_read( "................G...........................", " 4444444 4444444 ", n_rev=11, n_fwd=10) expect = svc.call() vcf_expectation = expect.with_output_vcf() vcf_expectation.record_count(1) vcf_expectation \ .has_record_for_variant(Variant(DEFAULT_CHROM, 16, "T", "G")) \ .with_no_filters()
def test_should_not_apply_bad_reads_to_insertion_if_all_supporting_reads_have_high_base_qualities( self): svc = SVCDriver(self) \ .with_var_filters("BR") \ .with_bad_reads_window_size(3) \ .with_min_bad_reads_score(15) svc.with_ref_sequence( # 1234567890123 456789 "AAAGCGTACAACCG*GGTTAGTCACAAACCCGTTACGTATGCATG").with_read( "..............*..G...........................", " 1 ", n_rev=11, n_fwd=10) svc.with_read("..............T..............................", n_rev=10, n_fwd=10) expect = svc.call() vcf_expectation = expect.with_output_vcf() vcf_expectation.record_count(1) vcf_expectation \ .has_record_for_variant(Variant(DEFAULT_CHROM, 13, "G", "GT")) \ .with_no_filters()
def test_should_not_apply_filter_to_snp_if_all_supporting_reads_are_good( self): svc = SVCDriver(self) \ .with_var_filters("BR") \ .with_bad_reads_window_size(7) \ .with_min_bad_reads_score(15) svc.with_ref_sequence( # 1234567 890123456789 "AAAGCGTAA**CCGGGTTAGT**CAAACCCGTTACGTATGCATG").with_read( ".........**.....G....**.....................", n_rev=10, n_fwd=10).with_read( ".........GT..........TA.....................", " 00 00 ", n_rev=11, n_fwd=10) expect = svc.call() vcf_expectation = expect.with_output_vcf() vcf_expectation.record_count(3) vcf_expectation \ .has_record_for_variant(Variant(DEFAULT_CHROM, 14, "T", "G")) \ .with_no_filters()
def test_calls_correct_reference_when_one_sample_has_snp_and_tother_has_indel(self): chrom = "1" sample_1 = "sample_1" sample_2 = "sample_2" driver = SVCDriver(self) driver.with_ref_sequence( "AAAAAAAAAAACGCACG*CCCCATAAAAAAATTTTTTTTTTT", chrom=chrom ).with_read( " ..........T................ ", chrom=chrom, sample_name=sample_1 ).with_read( " ...............T........... ", chrom=chrom, sample_name=sample_1 ).with_read( " ...........T.*................ ", chrom=chrom, sample_name=sample_2 ).with_read( " ...........T.*..................... ", chrom=chrom, sample_name=sample_2 ).with_read( "...............T.*......... ", chrom=chrom, sample_name=sample_2 ).with_output_ref_calls(True) vcf_expect = driver.call().with_output_vcf() # Has only 4 records which are:- vcf_expect.has_reference_calls_for_region(chrom, 0, 15) vcf_expect.has_record(chrom, 15, "C", "T") vcf_expect.has_record(chrom, 16, "G", "GT") vcf_expect.has_reference_calls_for_region(chrom, 17, 41)
def test_min_depth_computation_with_mixed_depth_of_reads_when_no_chunking_occurs( self): sample_name = "bah" chrom = "1" driver = SVCDriver(self) driver.with_ref_sequence( "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", chrom=chrom).with_read( "........................................", n_rev=10, n_fwd=10, sample_name=sample_name).with_read( "................................... ", n_rev=2, n_fwd=2, sample_name=sample_name).with_read( " ................................... ", n_rev=1, n_fwd=1, sample_name=sample_name).with_output_ref_calls(True) expect = driver.call() expect\ .with_output_vcf()\ .has_record_for_variant(Variant(chrom, 0, "A", ref_alt))\ .with_sample(sample_name)\ .has_read_depth(round(20 + 4 * 35 / 40 + 2 * 35 / 40))\ .has_min_read_depth(20)
def test_calls_deletion_and_snp_at_same_location_in_repeat_region_with_few_reads_as_anchors( self): chrom = "1" sample = "sample" svc_driver = SVCDriver(self) svc_driver.with_ref_sequence( 'CGAGAGAGAGAGAGAGAGAGATAGAGAGAGAGAGAGAGAGTC', chrom=chrom).with_read( '....................**....................', n_rev=5, n_fwd=0, chrom=chrom, sample_name=sample).with_read( '.....................G....................', n_rev=5, n_fwd=0, chrom=chrom, sample_name=sample) expect = svc_driver.call() vcf_expect = expect.with_output_vcf() vcf_expect \ .has_record_for_variants( Variant(chrom, 21, "T", "G"), Variant(chrom, 19, "GAT", "G") ).with_sample(sample).has_phased_genotypes(".|1", "1|.")
def test_should_call_basic_snps(self): sample_name = "a_sample" chrom = "1" svc_driver = SVCDriver(self).with_ref_sequence( "GCCCCAGCCTCCCAAAGTGCATTGATTTTGTTGTTGTTGTGCTTATTTGCACTCCAGCCTGGCCTCTCCTTTCTTG", chrom=chrom ).with_read( "...............T.........A...............G..................................", n_fwd=10, n_rev=10, sample_name=sample_name ).with_read( ".........................A..........................A.......................", n_fwd=10, n_rev=10, sample_name=sample_name).with_normalize_variant_calls(True) expect = svc_driver.call() vcf_expect = expect.with_output_vcf() vcf_expect.record_count(4) vcf_expect.has_record(chrom, 15, "A", "T").with_sample(sample_name).has_genotype("1|0") vcf_expect.has_record(chrom, 25, "T", "A").with_sample(sample_name).has_genotype("1|1") vcf_expect.has_record(chrom, 41, "C", "G").with_sample(sample_name).has_genotype("1|0") vcf_expect.has_record(chrom, 52, "T", "A").with_sample(sample_name).has_genotype("0|1")
def test_doesnt_give_a_flying_damn_about_spurious_filter_header(self): chrom = "22" variant = Variant(chrom, 11, "A", "C") schema = Schema() complex_filter_name = '.+-*\\/~@?!%^&><=\"\'(){}[]_|' schema.set_filter(complex_filter_name, 'unusual characters') gv_builder = VCFBuilder(join(self.work_dir, "genotype.vcf"), schema=schema) gv_builder.with_record_from_variant(variant, filters={complex_filter_name}) gv_builder.build().index() driver = SVCDriver(self) dodgy_sample = "bobs_your_uncle" driver.with_ref_sequence( "ACGCCCCCTGCAAAAAAAAAA", chrom=chrom, pos_from=0).with_read( "...........C.........", n_fwd=5, n_rev=5, chrom=chrom, sample_name=dodgy_sample).with_genotype_alleles( gv_builder.compressed_filename) expect = driver.call(expected_success=True) expect .with_output_vcf()\ .has_record_for_variant(variant)\ .with_sample(dodgy_sample)\ .has_genotype("1/1")
def test_should_use_read_evidence_outside_region_to_not_call_snp(self): svc = SVCDriver(self) # If no region was specified then only the SNP with stronger evidence # would be outputted. svc.with_ref_sequence( "AAAGCGTACAACCGGGTTAGTCACAAACCCGTTACGTATGCCCCCCCCCCCATG", chrom='1').with_read( "......................................................", chrom='1', n_fwd=10, n_rev=10).with_read( " ...............................G.......... ", chrom='1', n_fwd=10, n_rev=10 ).with_read( " ..............................T........... ", chrom='1', n_fwd=6, n_rev=6) svc.with_region_string('1:0-41') expect = svc.call() expect.with_output_vcf().record_count(0)
def test_phasing_for_isolated_snp_on_one_sample_only(self): sample_1 = "sample_1" sample_2 = "sample_2" chrom = "1" svc_driver = SVCDriver(self)\ .with_ref_sequence( "ACGCCCCTGCAAAAAAAAAAT", chrom=chrom ).with_read( "........T............", n_fwd=10, n_rev=10, sample_name=sample_1 ).with_read( ".....................", n_fwd=10, n_rev=10, sample_name=sample_2 ) svc_driver.with_output_phased_genotypes(True) expect = svc_driver.call() vcf_expect = expect.with_output_vcf() vcf_expect.record_count(1) record_expect = vcf_expect.has_record_for_variant( Variant(chrom, 8, "G", "T")) sample_1_expect = record_expect.with_sample(sample_1) sample_1_expect.has_phased_genotype("1|1") sample_1_expect.has_phase_set_id(str(8)) sample_1_expect.has_phase_set_quality(MAX_PHRED) sample_2_expect = record_expect.with_sample(sample_2) sample_2_expect.has_phased_genotype("0|0") sample_2_expect.has_phase_set_id(str(8)) sample_2_expect.has_phase_set_quality(MAX_PHRED)