Skip to content

Commit

Permalink
code clean
Browse files Browse the repository at this point in the history
might be a little faster to not call entry_boundaries multiple times
  • Loading branch information
ACEnglish committed Jan 7, 2024
1 parent 731095b commit 81a7d3e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions truvari/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
:meth:`chunker`
:meth:`cmd_exe`
:meth:`consolidate_phab_vcfs`
:meth:`coord_distance`
:meth:`count_entries`
:meth:`file_zipper`
:meth:`help_unknown_cmd`
Expand Down Expand Up @@ -101,6 +102,7 @@
)

from truvari.comparisons import (
coord_distance,
create_pos_haplotype,
entry_boundaries,
entry_distance,
Expand Down
7 changes: 6 additions & 1 deletion truvari/comparisons.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,13 @@ def entry_distance(entryA, entryB):
"""
astart, aend = entry_boundaries(entryA)
bstart, bend = entry_boundaries(entryB)
return astart - bstart, aend - bend
return coord_distance(astart, aend, bstart, bend)

def coord_distance(astart, aend, bstart, bend):
"""
Return start and end distances
"""
return astart - bstart, aend - bend

def entry_gt_comp(entryA, entryB, sampleA=None, sampleB=None):
"""
Expand Down
4 changes: 2 additions & 2 deletions truvari/matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,14 @@ def build_match(self, base, comp, matid=None, skip_gt=False, short_circuit=False
ret.comp_gt_count = sum(1 for _ in ret.comp_gt if _ == 1)
ret.gt_match = abs(ret.base_gt_count - ret.comp_gt_count)

ret.ovlpct = truvari.entry_reciprocal_overlap(base, comp)
ret.ovlpct = truvari.reciprocal_overlap(bstart, bend, cstart, cend)
if ret.ovlpct < self.params.pctovl:
logging.debug("%s and %s overlap percent is too low (%.3f)",
str(base), str(comp), ret.ovlpct)
ret.state = False
if short_circuit:
return ret

ret.st_dist, ret.ed_dist = truvari.entry_distance(base, comp)
if self.params.pctseq > 0:
ret.seqsim = truvari.entry_seq_similarity(
base, comp, self.reference, self.params.minhaplen)
Expand All @@ -244,6 +243,7 @@ def build_match(self, base, comp, matid=None, skip_gt=False, short_circuit=False
else:
ret.seqsim = 0

ret.st_dist, ret.ed_dist = truvari.coord_distance(bstart, bend, cstart, cend)
ret.calc_score()

return ret
Expand Down

0 comments on commit 81a7d3e

Please sign in to comment.