Skip to content

Commit

Permalink
Fix tmpdir
Browse files Browse the repository at this point in the history
  • Loading branch information
ACEnglish committed Nov 28, 2024
1 parent b8c9056 commit 04d5feb
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions truvari/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ def performance_metrics(tpbase, tp, fn, fp):
f1 = 2 * (neum / denom) if denom != 0 else None
return precision, recall, f1


def compress_index_vcf(fn, fout=None, remove=True):
"""
Compress and index a vcf. If no fout is provided, write to fn + '.gz'
Expand All @@ -430,14 +429,14 @@ def compress_index_vcf(fn, fout=None, remove=True):
"""
if fout is None:
fout = fn + '.gz'
m_tmp = make_temp_filename(suffix='.vcf')
with open(m_tmp, 'w') as out_hdlr:
out_hdlr.write(bcftools.sort(fn, "--temp-dir", tempfile.gettempdir()))
pysam.tabix_compress(m_tmp, fout, force=True)
with tempfile.TemporaryDirectory() as tmpdirname:
m_tmp = make_temp_filename(tmpdir=tmpdirname, suffix='.vcf')
with open(m_tmp, 'w') as out_hdlr:
out_hdlr.write(bcftools.sort(fn, "--temp-dir", tmpdirname))
pysam.tabix_compress(m_tmp, fout, force=True)
pysam.tabix_index(fout, force=True, preset="vcf")
if remove:
os.remove(fn)
os.remove(m_tmp)


def check_vcf_index(vcf_path):
Expand Down

0 comments on commit 04d5feb

Please sign in to comment.