Skip to content

Commit 9590a8c

Browse files
dpark01claude
andcommitted
Clean up sidecar index files (.tbi, .bai) in refine_assembly
Temp files created by samtools index (.bai) and tabix (.tbi) are not managed by the tempfname context manager since they are derived from the parent filename. Add explicit cleanup to prevent accumulation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent cde5cc6 commit 9590a8c

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/viral_ngs/assembly.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,9 @@ def refine_assembly(
752752
samtools.sort(downsampledUnsortedBam, downsampledBam, threads=threads)
753753
samtools.index(downsampledBam, threads=threads)
754754
fb.call(downsampledBam, deambigFasta, tmpVcf)
755+
# clean up samtools index sidecar
756+
if os.path.isfile(downsampledBam + '.bai'):
757+
os.unlink(downsampledBam + '.bai')
755758
else:
756759
fb.call(realignBam, deambigFasta, tmpVcf)
757760

@@ -778,6 +781,9 @@ def refine_assembly(
778781
if outVcf.endswith('.gz'):
779782
shutil.copyfile(tmpVcf + '.tbi', outVcf + '.tbi')
780783
shutil.copyfile(tmpFasta, outFasta)
784+
# clean up tabix index sidecar created by FreeBayes/tabix
785+
if os.path.isfile(tmpVcf + '.tbi'):
786+
os.unlink(tmpVcf + '.tbi')
781787

782788
# Index final output FASTA for Picard, Samtools, and Novoalign
783789
picard_index.execute(outFasta, overwrite=True)

0 commit comments

Comments
 (0)