def test_softclip_end_of_alignment_by_query_masks_qualities_when_softclipping() -> None: for new_qual in None, 2: rec = r(10, "50M", "+") clipping.softclip_end_of_alignment_by_query(rec, 10, clipped_base_quality=new_qual) quals = rec.query_qualities for i in range(40, 50): assert quals[i] == (30 if new_qual is None else new_qual)
def test_softclip_end_of_alignment_by_query_makes_read_unmapped_when_clipping_all_bases() -> None: rec = r(10, "50M") assert not rec.is_unmapped info = clipping.softclip_end_of_alignment_by_query(rec, 50) assert info.query_bases_clipped == 50 assert info.ref_bases_clipped == 50 assert rec.is_unmapped
def test_softclip_end_of_alignment_by_query_preserves_deletions_post_clipping_region() -> None: for strand in "+", "-": rec = r(10, "25M4D25M", strand) info = clipping.softclip_end_of_alignment_by_query(rec, 10) assert info.query_bases_clipped == 10 assert info.ref_bases_clipped == 10 assert rec.reference_start == 10 assert rec.cigarstring == "25M4D15M10S"
def test_softclip_end_of_alignment_by_query_removes_deletion_following_clipping() -> None: for strand in "+", "-": rec = r(10, "40M4D10M", strand) info = clipping.softclip_end_of_alignment_by_query(rec, 10) assert info.query_bases_clipped == 10 assert info.ref_bases_clipped == 14 assert rec.reference_start == 10 assert rec.cigarstring == "40M10S"
def test_softclip_end_of_alignment_by_query_consumes_rest_of_insertion() -> None: for strand in "+", "-": rec = r(10, "38M4I8M", strand) info = clipping.softclip_end_of_alignment_by_query(rec, 10) assert info.query_bases_clipped == 12 assert info.ref_bases_clipped == 8 assert rec.reference_start == 10 assert rec.cigarstring == "38M12S"
def test_softclip_end_of_alignment_by_query_with_complicated_cigar() -> None: for strand in "+", "-": rec = r(10, "10M5I5M10I16M4S2H", strand) info = clipping.softclip_end_of_alignment_by_query(rec, 10) assert info.query_bases_clipped == 10 assert info.ref_bases_clipped == 10 assert rec.reference_start == 10 assert rec.cigarstring == "10M5I5M10I6M14S2H"
def test_softclip_end_of_alignment_by_query_preserves_hard_clipping() -> None: for strand in "+", "-": rec = r(10, "40M10H", strand) info = clipping.softclip_end_of_alignment_by_query(rec, 10) assert info.query_bases_clipped == 10 assert info.ref_bases_clipped == 10 assert rec.reference_start == 10 assert rec.cigarstring == "30M10S10H"
def test_softclip_end_of_alignment_by_query_clips_10_aligned_and_deleted_bases() -> None: for strand in "+", "-": rec = r(10, "44M2D6M", strand) info = clipping.softclip_end_of_alignment_by_query(rec, 10) assert info.query_bases_clipped == 10 assert info.ref_bases_clipped == 12 assert rec.reference_start == 10 assert rec.cigarstring == "40M10S"
def test_softclip_end_of_alignment_by_query_clips_last10_bases_of_fully_aligned_read() -> None: for strand in "+", "-": rec = r(10, "50M", strand) info = clipping.softclip_end_of_alignment_by_query(rec, 10) assert info.query_bases_clipped == 10 assert info.ref_bases_clipped == 10 assert rec.reference_start == 10 assert rec.cigarstring == "40M10S"
def test_softclip_end_of_alignment_by_query_unmapped_reads_ok() -> None: rec = r(start=None, cigar=None) info = clipping.softclip_end_of_alignment_by_query(rec, 10) assert info.query_bases_clipped == 0 assert info.ref_bases_clipped == 0