Skip to content

Commit

Permalink
Update prymer/offtarget/bwa.py
Browse files Browse the repository at this point in the history
Co-authored-by: Tim Fennell <[email protected]>
  • Loading branch information
msto and tfenne committed Oct 17, 2024
1 parent 8455a49 commit efe55fb
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions prymer/offtarget/bwa.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,14 +374,17 @@ def _to_result(self, query: Query, rec: pysam.AlignedSegment) -> BwaResult:
)

num_hits: int = int(rec.get_tag("HN")) if rec.has_tag("HN") else 0
hits: list[BwaHit] = self.to_hits(rec=rec) if 0 < num_hits < self.max_hits else []

# `to_hits()` removes artifactual hits which span the boundary between concatenated
# reference sequences. If we are reporting a list of hits, the number of hits should match
# the size of this list. Otherwise, we either have zero hits, or more than the maximum
# number of hits. In both of the latter cases, we have to rely on the count reported in the
# `HN` tag.
num_hits = len(hits) if hits else num_hits
hits: list[BwaHit]
if 0 < num_hits < self.max_hits:
hits = self.to_hits(rec=rec)
num_hits = len(hits)
else:
hits = []

return BwaResult(query=query, hit_count=num_hits, hits=hits)

Expand Down

0 comments on commit efe55fb

Please sign in to comment.