Skip to content

Commit

Permalink
clean BND matching
Browse files Browse the repository at this point in the history
Only populate start/end distances when on the same chrom.
Cap score lower-bound at 0.
  • Loading branch information
ACEnglish committed Jan 6, 2025
1 parent a2620d0 commit 8f02ec9
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions truvari/matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,27 +299,35 @@ def bounds(pos):
ret.comp = comp

ret.matid = matid
ret.state = base.chrom == comp.chrom
ret.st_dist = base.pos - comp.pos
ret.state &= truvari.overlaps(*bounds(base.pos), *bounds(comp.pos))
b_bnd = bnd_direction_strand(base.alts[0])
c_bnd = bnd_direction_strand(comp.alts[0])
ret.state &= b_bnd == c_bnd
# Only put start distance same chrom pos2
if base.chrom == comp.chrom:
ret.st_dist = base.pos - comp.pos
ret.state &= truvari.overlaps(*bounds(base.pos), *bounds(comp.pos))
else:
ret.state = False
ret.score = 0
return ret

b_pos2 = bnd_position(base.alts[0])
c_pos2 = bnd_position(comp.alts[0])
ret.ed_dist = b_pos2[1] - c_pos2[1]
ret.state &= b_pos2[0] == c_pos2[0]
if b_pos2[0] == c_pos2[0]:
ret.ed_dist = b_pos2[1] - c_pos2[1]
ret.state &= truvari.overlaps(*bounds(b_pos2[1]), *bounds(c_pos2[1]))
else:
ret.state = False
ret.score = 0
return ret

ret.state &= truvari.overlaps(*bounds(b_pos2[1]), *bounds(c_pos2[1]))
ret.state &= ret.ed_dist < self.params.bnddist
b_bnd = bnd_direction_strand(base.alts[0])
c_bnd = bnd_direction_strand(comp.alts[0])
ret.state &= b_bnd == c_bnd

self.compare_gts(ret, base, comp)

# Score is percent of allowed distance needed to find this match
if self.params.bnddist > 0:
ret.score = (1 - ((abs(ret.st_dist) + abs(ret.ed_dist)) / 2)
/ self.params.bnddist) * 100
ret.score = max(0, (1 - ((abs(ret.st_dist) + abs(ret.ed_dist)) / 2)
/ self.params.bnddist) * 100)
else:
ret.score = int(ret.state) * 100

Expand Down

0 comments on commit 8f02ec9

Please sign in to comment.