Skip to content

Commit

Permalink
use contextmanager for tempdir
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkinsc committed Mar 20, 2024
1 parent e3c9f8b commit 98ac0f8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ jobs:
mkdir coverage
- name: test with docker
run: |
docker run -e _JAVA_OPTIONS -e PYTEST_ADDOPTS -v `pwd`/coverage:/coverage -v `pwd`/test:/opt/viral-ngs/source/test:rw --entrypoint /bin/bash $DOCKER_TAG -c 'set -e; cd /opt/viral-ngs/source; env; echo "LD_LIBRARY_PATH: $LD_LIBRARY_PATH"; export LD_LIBRARY_PATH="/opt/miniconda/envs/viral-ngs-env/lib:/usr/local/lib:${LD_LIBRARY_PATH}"; echo "$(nproc)"; python -c "import locale; print(locale.getpreferredencoding(False))"; pytest test/unit; cp .coverage /coverage'
docker run -e _JAVA_OPTIONS -e PYTEST_ADDOPTS -v `pwd`/coverage:/coverage -v `pwd`/test:/opt/viral-ngs/source/test:rw --entrypoint /bin/bash $DOCKER_TAG -c 'set -e; cd /opt/viral-ngs/source; env; echo "LD_LIBRARY_PATH: $LD_LIBRARY_PATH"; export LD_LIBRARY_PATH="/opt/miniconda/envs/viral-ngs-env/lib:/usr/local/lib:${LD_LIBRARY_PATH}"; echo "nproc: $(nproc)"; python -c "import locale; print(locale.getpreferredencoding(False))"; pytest test/unit; cp .coverage /coverage'
- name: run coveralls
run: |
mv coverage/.coverage .
Expand Down
36 changes: 18 additions & 18 deletions phylo/vphaser2.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,21 @@ def iterate(self, inBam, numThreads=None):
SNP_or_LP_Profile1, SNP_or_LP_Profile2, ...]
"""
#outdir = tempfile.mkdtemp('vphaser2')
outdir = util.file.tmp_dir(prefix='vphaser2')
try:
self.execute(inBam, outdir, numThreads)
finally:
# these V-Phaser droppings cause problems if they persist
bti = inBam + '.bti'
if os.path.isfile(bti):
os.unlink(bti)
chromNames = pysam.Samfile(inBam).references
for chromName in chromNames:
outfile = os.path.join(outdir, chromName + '.var.raw.txt')
if not os.path.exists(outfile):
continue
with open(outfile, 'rt') as inf:
for line in inf:
if not line.startswith('#'):
yield [chromName] + line.strip().split()
shutil.rmtree(outdir)
with util.file.tmp_dir(prefix='vphaser2') as outdir:
try:
self.execute(inBam, outdir, numThreads)
finally:
# these V-Phaser droppings cause problems if they persist
bti = inBam + '.bti'
if os.path.isfile(bti):
os.unlink(bti)
chromNames = pysam.Samfile(inBam).references
for chromName in chromNames:
outfile = os.path.join(outdir, chromName + '.var.raw.txt')
if not os.path.exists(outfile):
continue
with open(outfile, 'rt') as inf:
for line in inf:
if not line.startswith('#'):
yield [chromName] + line.strip().split()
#shutil.rmtree(outdir)

0 comments on commit 98ac0f8

Please sign in to comment.