Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into cv_fix_mates_secondar…
Browse files Browse the repository at this point in the history
…y_supplementary
  • Loading branch information
clintval committed Dec 28, 2024
2 parents 8baaa48 + bd38898 commit 206cec5
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions fgpyo/sam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ def from_recs( # noqa: C901 # `from_recs` is too complex (11 > 10)

if rec2 is None:
if not rec1.has_tag("MC"):
raise ValueError('Cannot determine proper pair status without a mate cigar ("MC")!')
raise ValueError('Cannot determine pair orientation without a mate cigar ("MC")!')
rec2_cigar = Cigar.from_cigarstring(str(rec1.get_tag("MC")))
rec2_reference_end = rec1.next_reference_start + rec2_cigar.length_on_target()
else:
Expand Down Expand Up @@ -966,16 +966,16 @@ def set_mate_info_on_supplementary(supp: AlignedSegment, mate_primary: AlignedSe
def set_pair_info(r1: AlignedSegment, r2: AlignedSegment, proper_pair: bool = True) -> None:
"""Resets mate pair information between reads in a pair.
Requires that both r1 and r2 are mapped. Can be handed reads that already have pairing flags
setup or independent R1 and R2 records that are currently flagged as SE reads.
Can be handed reads that already have pairing flags setup or independent R1 and R2 records that
are currently flagged as SE reads.
Args:
r1: Read 1 (first read in the template).
r2: Read 2 with the same query name as r1 (second read in the template).
proper_pair: whether the pair is proper or not.
"""
if r1.query_name != r2.query_name:
raise ValueError("Cannot pair reads with different query names!")
raise ValueError("Cannot set pair info on reads with different query names!")

for r in [r1, r2]:
r.is_paired = True
Expand All @@ -984,6 +984,7 @@ def set_pair_info(r1: AlignedSegment, r2: AlignedSegment, proper_pair: bool = Tr
r1.is_read2 = False
r2.is_read2 = True
r2.is_read1 = False

set_mate_info(r1=r1, r2=r2, is_proper_pair=lambda a, b: proper_pair)


Expand Down

0 comments on commit 206cec5

Please sign in to comment.