From 2d5f022debc54c2119d3019acd1bf0fc1f32c1b6 Mon Sep 17 00:00:00 2001 From: Nicholas Youngblut Date: Sat, 19 Dec 2020 08:48:12 +0100 Subject: [PATCH 1/3] flexible find exe --- midas/utility.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/midas/utility.py b/midas/utility.py index ed8d628..03ddfee 100644 --- a/midas/utility.py +++ b/midas/utility.py @@ -5,6 +5,7 @@ # Freely distributed under the GNU General Public License (GPLv3) import io, os, stat, sys, resource, gzip, platform, bz2, Bio.SeqIO +from distutils.spawn import find_executable __version__ = '1.3.0' @@ -106,23 +107,23 @@ def init_worker(): pool.join() sys.exit("\nKeyboardInterrupt") +def find_exe(exe, path): + """ Finding executable """ + if find_executable(exe) is None: + exe = os.path.join(path, exe) + if not os.path.isfile(exe): + sys.exit("\nError: File not found: %s\n" % exe) + if find_executable(exe) is None: + sys.exit("\nError: Executable not found: %s\n" % exe) + return exe + def add_executables(args): """ Identify relative file and directory paths """ src_dir = os.path.dirname(os.path.abspath(__file__)) main_dir = os.path.dirname(src_dir) - args['stream_seqs'] = '/'.join([src_dir, 'run', 'stream_seqs.py']) - args['hs-blastn'] = '/'.join([main_dir, 'bin', platform.system(), 'hs-blastn']) - args['bowtie2-build'] = '/'.join([main_dir, 'bin', platform.system(), 'bowtie2-build']) - args['bowtie2'] = '/'.join([main_dir, 'bin', platform.system(), 'bowtie2']) - args['samtools'] = '/'.join([main_dir, 'bin', platform.system(), 'samtools']) - - for arg in ['hs-blastn', 'stream_seqs', 'bowtie2-build', 'bowtie2', 'samtools']: - if not os.path.isfile(args[arg]): - sys.exit("\nError: File not found: %s\n" % args[arg]) - - for arg in ['hs-blastn', 'bowtie2-build', 'bowtie2', 'samtools']: - if not os.access(args[arg], os.X_OK): - sys.exit("\nError: File not executable: %s\n" % args[arg]) + args['stream_seqs'] = find_exe('stream_seqs.py', os.path.join(src_dir, 'run')) + for exe in ['hs-blastn', 'bowtie2-build', 'bowtie2', 'samtools']: + args[exe] = find_exe(exe, os.path.join(main_dir, 'bin', platform.system())) import subprocess as sp From acbfeb74cbdeceaadde88893f50b49c1fa1aed40 Mon Sep 17 00:00:00 2001 From: Nicholas Youngblut Date: Sat, 19 Dec 2020 14:28:47 +0100 Subject: [PATCH 2/3] close log prior to passing args to species_pileup via utility.parallel --- midas/run/snps.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/midas/run/snps.py b/midas/run/snps.py index d439945..69c3c03 100644 --- a/midas/run/snps.py +++ b/midas/run/snps.py @@ -160,9 +160,8 @@ def keep_read(aln): else: aln_stats['mapped_reads'] += 1 return True - + def species_pileup(args, species_id, contigs): - # Set global variables for read filtering global global_args # need global for keep_read function global_args = args @@ -170,10 +169,10 @@ def species_pileup(args, species_id, contigs): # summary stats global aln_stats aln_stats = {'genome_length':0, - 'total_depth':0, - 'covered_bases':0, - 'aligned_reads':0, - 'mapped_reads':0} + 'total_depth':0, + 'covered_bases':0, + 'aligned_reads':0, + 'mapped_reads':0} # open outfiles out_path = '%s/snps/output/%s.snps.gz' % (args['outdir'], species_id) @@ -220,6 +219,7 @@ def pysam_pileup(args, species, contigs): start = time() print("\nCounting alleles") args['log'].write("\nCounting alleles\n") + args['log'].close() # run pileups per species in parallel argument_list = [] From 80b689df7e19f95bbc7af993bb3a0e765e9800e7 Mon Sep 17 00:00:00 2001 From: Nicholas Youngblut Date: Sat, 19 Dec 2020 20:23:30 +0100 Subject: [PATCH 3/3] fixed indentation error; added pop of log from args --- midas/run/snps.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/midas/run/snps.py b/midas/run/snps.py index 69c3c03..9d355d8 100644 --- a/midas/run/snps.py +++ b/midas/run/snps.py @@ -219,7 +219,8 @@ def pysam_pileup(args, species, contigs): start = time() print("\nCounting alleles") args['log'].write("\nCounting alleles\n") - args['log'].close() + args['log'].close() + args.pop('log', None) # run pileups per species in parallel argument_list = []