Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flexible find exe #113

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions midas/run/snps.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,19 @@ 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

# 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)
Expand Down Expand Up @@ -220,6 +219,8 @@ def pysam_pileup(args, species, contigs):
start = time()
print("\nCounting alleles")
args['log'].write("\nCounting alleles\n")
args['log'].close()
args.pop('log', None)

# run pileups per species in parallel
argument_list = []
Expand Down
27 changes: 14 additions & 13 deletions midas/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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

Expand Down