Skip to content

Commit

Permalink
Fixes related to problems with samtools & bowtie2
Browse files Browse the repository at this point in the history
-see issues #73, #72, #69, #68
-added new samtools and bowtie2 binaries which should work on more systems
-added checks for samtools and bowtie2 binaries; if binaries don't work instructions for replacing them are provided
  • Loading branch information
Stephen Nayfach committed Nov 26, 2017
1 parent 3ae6bb5 commit f6216e4
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
Binary file modified bin/Linux/bowtie2-align-l
Binary file not shown.
Binary file modified bin/Linux/bowtie2-align-s
Binary file not shown.
Binary file modified bin/Linux/bowtie2-build-l
Binary file not shown.
Binary file modified bin/Linux/bowtie2-build-s
Binary file not shown.
Binary file modified bin/Linux/samtools
Binary file not shown.
31 changes: 29 additions & 2 deletions midas/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Copyright (C) 2015 Stephen Nayfach
# Freely distributed under the GNU General Public License (GPLv3)

import io, os, stat, sys, resource, gzip, platform, subprocess, bz2, Bio.SeqIO
import io, os, stat, sys, resource, gzip, platform, bz2, Bio.SeqIO

__version__ = '1.3.0'

Expand Down Expand Up @@ -119,10 +119,36 @@ def add_executables(args):
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])

import subprocess as sp

process = sp.Popen("%s view" % args['samtools'], shell=True, stdout=sp.PIPE, stderr=sp.PIPE)
process.wait()
if process.returncode != 0:
err = "\nError: could not execute samtools binary: %s\n" % args['samtools']
err += "(exited with error code %s)\n" % process.returncode
err += "To solve this issue, follow these steps:\n"
err += " 1) Download samtools v1.4: https://github.com/samtools/samtools/releases/download/1.4/samtools-1.4.tar.bz2\n"
err += " 2) Unpack and compile the software on your system\n"
err += " 3) Copy the new samtools binary to: %s\n" % os.path.dirname(args['samtools'])
sys.exit(err)

process = sp.Popen("%s -h" % args['bowtie2'], shell=True, stdout=sp.PIPE, stderr=sp.PIPE)
process.wait()
if process.returncode != 0:
err = "\nError: could not execute bowtie2 binary: %s\n" % args['bowtie2']
err += "(exited with error code %s)\n" % process.returncode
err += "To solve this issue, follow these steps:\n"
err += " 1) Go to https://sourceforge.net/projects/bowtie-bio/files/bowtie2/2.3.2\n"
err += " 2) Download bowtie2-2.3.2-linux-x86_64.zip\n"
err += " 3) Unpack the software on your system\n"
err += " 4) Copy the new bowtie2 binaries to: %s\n" % os.path.dirname(args['bowtie2'])
sys.exit(err)

def auto_detect_file_type(inpath):
""" Detect file type [fasta or fastq] of <p_reads> """
infile = iopen(inpath)
Expand Down Expand Up @@ -207,8 +233,9 @@ def check_exit_code(process, command):

def check_bamfile(args, bampath):
""" Use samtools to check bamfile integrity """
import subprocess as sp
command = '%s view %s > /dev/null' % (args['samtools'], bampath)
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
process = sp.Popen(command, shell=True, stdout=sp.PIPE, stderr=sp.PIPE)
out, err = process.communicate()
if err.decode('ascii') != '': # need to use decode to convert to characters for python3
err_message = "\nWarning, bamfile may be corrupt: %s\nSamtools reported this error: %s\n" % (bampath, err.rstrip())
Expand Down

0 comments on commit f6216e4

Please sign in to comment.