Skip to content

Commit

Permalink
fix tmpdir being set from base command
Browse files Browse the repository at this point in the history
  • Loading branch information
AroneyS committed Apr 18, 2024
1 parent bf90668 commit 16f5b57
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 16 deletions.
6 changes: 1 addition & 5 deletions aviary/aviary.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import logging
import os
from datetime import datetime
import tempfile

# Debug
debug={1:logging.CRITICAL,
Expand Down Expand Up @@ -198,7 +197,7 @@ def main():
help='Path to the location that will be treated used for temporary files. If none is specified, the TMPDIR \n'
'environment variable will be used. Can be configured within the `configure` subcommand',
dest='tmpdir',
default=tempfile.gettempdir(),
default=None,
)

base_group.add_argument(
Expand Down Expand Up @@ -1290,9 +1289,6 @@ def manage_env_vars(args):
if args.conda_prefix is None:
args.conda_prefix = Config.get_software_db_path('CONDA_ENV_PATH', '--conda-prefix')

if args.tmpdir is None:
args.tmpdir = Config.get_software_db_path('TMPDIR', '--tmpdir')

try:
if args.gtdb_path is None:
args.gtdb_path = Config.get_software_db_path('GTDBTK_DATA_PATH', '--gtdb-path')
Expand Down
2 changes: 1 addition & 1 deletion aviary/modules/annotation/annotation.smk
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ rule eggnog:
params:
mag_extension = config['mag_extension'],
eggnog_db = config['eggnog_folder'],
tmpdir = config["tmpdir"]
tmpdir = config["tmpdir"] if config["tmpdir"] else "$TMPDIR",
output:
done = 'data/eggnog/done'
threads:
Expand Down
6 changes: 3 additions & 3 deletions aviary/modules/assembly/assembly.smk
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ rule spades_assembly:
max_memory = config["max_memory"],
long_read_type = config["long_read_type"],
kmer_sizes = " ".join(config["kmer_sizes"]),
tmpdir = config["tmpdir"]
tmpdir = config["tmpdir"] if config["tmpdir"] else "$TMPDIR"
conda:
"envs/spades.yaml"
benchmark:
Expand Down Expand Up @@ -458,14 +458,14 @@ rule spades_assembly_coverage:
log:
"logs/spades_assembly_coverage.log"
params:
tmpdir = config["tmpdir"]
tmpdir = f"TMPDIR={config["tmpdir"]}" if config["tmpdir"] else ""
conda:
"../../envs/coverm.yaml"
benchmark:
"benchmarks/spades_assembly_coverage.benchmark.txt"
shell:
"""
TMPDIR={params.tmpdir} coverm contig -m metabat -t {threads} -r {input.fasta} --interleaved {input.fastq} --bam-file-cache-directory data/cached_bams/ > {output.assembly_cov} 2> {log};
{params.tmpdir} coverm contig -m metabat -t {threads} -r {input.fasta} --interleaved {input.fastq} --bam-file-cache-directory data/cached_bams/ > {output.assembly_cov} 2> {log};
mv data/cached_bams/*.bam {output.bam} && samtools index -@ {threads} {output.bam} 2>> {log}
"""

Expand Down
13 changes: 11 additions & 2 deletions aviary/modules/assembly/scripts/assemble_short_reads.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ def assemble_short_reads(
:return:
'''

if not tmp_dir:
try:
tmp_dir = os.environ["TMPDIR"]
except KeyError:
tmp_dir_arg = ""

if tmp_dir:
tmp_dir_arg = f"--tmp-dir {tmp_dir}"

# deal with read sets i.e. are we coassembling? Which assembler are we using?
# Non co-assembled reads are handled the same for each assembler
if read_set1 != 'none':
Expand Down Expand Up @@ -86,7 +95,7 @@ def assemble_short_reads(
# Run chosen assembler
if use_megahit:
max_memory_in_bytes = max_memory * 1024*1024*1024
command = f"megahit {read_string} -t {threads} -m {max_memory_in_bytes} -o data/megahit_assembly --tmp-dir {tmp_dir}"
command = f"megahit {read_string} -t {threads} -m {max_memory_in_bytes} -o data/megahit_assembly {tmp_dir_arg}"

with open(log, 'a') as logf:
logf.write(f"Queueing command {command}\n")
Expand All @@ -97,7 +106,7 @@ def assemble_short_reads(
else:
kmers = " ".join(kmer_sizes)
command = f"spades.py --memory {max_memory} --meta -t {threads} " \
f"-o data/short_read_assembly {read_string} -k {kmers} --tmp-dir {tmp_dir}"
f"-o data/short_read_assembly {read_string} -k {kmers} {tmp_dir_arg}"
with open(log, 'a') as logf:
logf.write(f"Queueing command {command}\n")
subprocess.run(command.split(), stdout=logf, stderr=subprocess.STDOUT)
Expand Down
3 changes: 2 additions & 1 deletion aviary/modules/binning/scripts/get_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ def get_coverage(
threads: int,
log: str,
):
os.environ["TMPDIR"] = tmpdir
if tmpdir: os.environ["TMPDIR"] = tmpdir

if long_reads != "none" and not os.path.exists("data/long_cov.tsv"):
if long_read_type in ["ont", "ont_hq"]:
coverm_cmd = f"coverm contig -t {threads} -r {input_fasta} --single {' '.join(long_reads)} -p minimap2-ont -m length trimmed_mean variance --bam-file-cache-directory data/binning_bams/ --discard-unmapped --min-read-percent-identity 0.85 --output-file data/long_cov.tsv".split()
Expand Down
5 changes: 3 additions & 2 deletions aviary/modules/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def __init__(self,


self.conda_prefix = args.conda_prefix
self.tmpdir = os.path.abspath(args.tmpdir)
self.tmpdir = os.path.abspath(args.tmpdir) if args.tmpdir else None
self.resources = args.resources
self.output = os.path.abspath(args.output)
self.threads = args.max_threads
Expand Down Expand Up @@ -444,7 +444,8 @@ def run_workflow(self, cores=16, profile=None, cluster_retries=None,
self._validate_config()

cores = max(int(self.threads), cores)
os.environ["TMPDIR"] = self.tmpdir
if self.tmpdir is not None:
os.environ["TMPDIR"] = self.tmpdir
for workflow in self.workflows:
cmd = (
"snakemake --snakefile {snakefile} --directory {working_dir} "
Expand Down
1 change: 0 additions & 1 deletion aviary/modules/strain_analysis/strain_analysis.smk
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ rule lorikeet:
params:
mag_extension = config['mag_extension'],
parallel_genomes = 8,
tmpdir = config['tmpdir']
resources:
mem_mb=int(config["max_memory"])*512
threads:
Expand Down
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ ani: none
precluster_ani: none
precluster_method: none
pggb_params: none
tmpdir: /tmp
tmpdir: none

0 comments on commit 16f5b57

Please sign in to comment.