def get_shrimp_2_version(): try: text = subprocess.Popen(['gmapper-ls'], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[1] except OSError: raise Error("Couldn't run 'gmapper-ls'. SHRiMP 2 not installed?") for line in text.split('\n'): parts = line.strip().split() if len(parts) >= 2 and parts[0] == 'SHRiMP': return parts[1] raise Error("gmapper-ls didn't output a version number as expected")
def require_shrimp_2(): version = get_shrimp_2_version() version_parts = version.split('.') major = int(version_parts[0]) minor = int(version_parts[1]) if major < 2 or (major == 2 and minor < 1): raise Error("SHRiMP version 2.1 or higher required")
def require_sff2fastq(): try: text = subprocess.Popen(['sff2fastq'], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[1] except OSError: raise Error("Couldn't run 'sff2fastq'. Not installed?")
def require_shrimp_1(): try: text = subprocess.Popen(['rmapper-ls'], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[1] except OSError: raise Error("Couldn't run 'rmapper-ls'. SHRiMP 1 not installed?")
def get_numpy(): try: import numpy except ImportError: try: import numpypy as numpy except ImportError: raise Error('Neither numpy nor numpypy are available.') return numpy
def get_option_value(args, option, conversion_function, default, log=None, displayer='%s', description=''): """ Get a command line option """ args = args[:] value = default while True: try: location = args.index(option) except ValueError: #Not found break if location == len(args) - 1: raise Error('Option %s requires a paramter' % option) try: value = conversion_function(args[location + 1]) except Exception: raise Error('Option for %s not in expected format' % option) del args[location:location + 2] if log: if isinstance(displayer, str): display = displayer % value else: display = displayer(value) log.log('%18s %-8s - %s\n' % (option, display, word_wrap(description, 49).replace( '\n', '\n' + ' ' * 30))) return value, args
def require_sff2fastq(): if not can_execute('sff2fastq'): raise Error("Couldn't run 'sff2fastq'. Not installed?")
def require_samtools(): if not can_execute('samtools'): raise Error("Couldn't run 'samtools'. Not installed?")
def require_shrimp_1(): if not can_execute('rmapper-ls'): raise Error("Couldn't run 'rmapper-ls'. SHRiMP 1 not installed?")
def default_command(args): if args: raise Error('Don\'t know what to do with %s' % (' '.join(args)))
def expect_no_further_options(args): for arg in args: if arg.startswith('-'): raise Error('Unexpected flag "%s"' % arg)