Skip to content

Commit

Permalink
Add methods to fix mate info on non-primaries and templates
Browse files Browse the repository at this point in the history
  • Loading branch information
clintval committed Dec 27, 2024
1 parent 77fd97a commit f8c479d
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion tests/fgpyo/sam/test_sam.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,8 @@ def test_not_is_proper_pair_if_too_far_apart() -> None:
assert not is_proper_pair(r1, r2)


def test_isize() -> None:
def test_isize_when_r2_defined() -> None:
"""Tests that an insert size can be calculated when both input records are defined."""
builder = SamBuilder()
r1, r2 = builder.add_pair(chrom="chr1", start1=100, cigar1="115M", start2=250, cigar2="40M")
assert sam.isize(r1, r2) == 190
Expand All @@ -506,6 +507,40 @@ def test_isize() -> None:
assert sam.isize(r1, r2) == 0


def test_isize_when_r2_undefined() -> None:
"""Tests that an insert size can be calculated when R1 is provided only."""
builder = SamBuilder()
r1, r2 = builder.add_pair(chrom="chr1", start1=100, cigar1="115M", start2=250, cigar2="40M")
assert sam.isize(r1) == 190
assert sam.isize(r2) == -190

r1, r2 = builder.add_pair(chrom="chr1", start1=100, cigar1="115M")
assert sam.isize(r1) == 0
assert sam.isize(r2) == 0


def test_isize_when_r2_undefined_indels_in_r2_cigar() -> None:
"""Tests that an insert size can be derived without R2 by using R2's cigar."""
builder = SamBuilder()
r1, _ = builder.add_pair(
chrom="chr1",
start1=100,
cigar1="115M",
start2=250,
cigar2="10S5M1D1M1D2I2D30M", # only 40bp reference-consuming operators
)
assert sam.isize(r1) == 190


def test_isize_raises_when_r2_not_provided_and_no_mate_cigar_tag() -> None:
"""Tests that an insert size can be calculated when both input records are defined."""
builder = SamBuilder()
r1, _ = builder.add_pair(chrom="chr1", start1=100, cigar1="115M", start2=250, cigar2="40M")
r1.set_tag("MC", None)
with pytest.raises(ValueError, match="Cannot determine proper pair status without R2's cigar"):
sam.isize(r1)


def test_calc_edit_info_no_edits() -> None:
chrom = "ACGCTAGACTGCTAGCAGCATCTCATAGCACTTCGCGCTATAGCGATATAAATATCGCGATCTAGCG"
builder = SamBuilder(r1_len=30)
Expand Down

0 comments on commit f8c479d

Please sign in to comment.