Skip to content

Commit

Permalink
sra: Move mktempd inside run()
Browse files Browse the repository at this point in the history
  • Loading branch information
arteymix committed Aug 19, 2024
1 parent 8823795 commit 7b782ff
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions bioluigi/tasks/sratoolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ def resources(self):

def __init__(self, *kwargs, **kwds):
super(FastqDump, self).__init__(*kwargs, **kwds)
base, tail = split(self.output_dir)
self.temp_output_dir = mkdtemp(prefix=tail + '-tmp', dir=base)

def program_args(self):
args = [cfg.fastqdump_bin,
Expand All @@ -89,13 +87,17 @@ def program_args(self):
if self.minimum_read_length > 0:
args.extend(['-M', self.minimum_read_length])

args.extend(['--outdir', self.temp_output_dir])
# temp_output_dir is only set within a run() execution, so this is a
# graceful fallback
args.extend(['--outdir', self.temp_output_dir if self.temp_output_dir else self.output_dir])

args.append(self.input_file)

return args

def run(self):
base, tail = split(self.output_dir)
self.temp_output_dir = mkdtemp(prefix=tail + '-tmp', dir=base)
try:
super(FastqDump, self).run()
# move every output to the final directory
Expand All @@ -106,6 +108,7 @@ def run(self):
os.replace(tmp_out_path, out.path)
finally:
shutil.rmtree(self.temp_output_dir)
self.temp_output_dir = None

def output(self):
sra_accession, _ = os.path.splitext(os.path.basename(self.input_file))
Expand Down

0 comments on commit 7b782ff

Please sign in to comment.