def exec_spades(self, dna_source, reads_data, phred_type, kmer_sizes, skip_error_correction):
    mem = ((psutil.virtual_memory().available / self.GB) - self.MEMORY_OFFSET_GB)
    if (mem < self.MIN_MEMORY_GB):
        raise ValueError(((((('Only ' + str(psutil.virtual_memory().available)) + ' bytes of memory are available. The SPAdes wrapper will') + ' not run without at least ') + str((self.MIN_MEMORY_GB + self.MEMORY_OFFSET_GB))) + ' gigabytes available'))
    if (dna_source == self.PARAM_IN_METAGENOME):
        max_mem = self.MAX_MEMORY_GB_META_SPADES
        max_threads = self.MAX_THREADS_META
    else:
        max_mem = self.MAX_MEMORY_GB_SPADES
        max_threads = self.MAX_THREADS
    threads = min(max_threads, (psutil.cpu_count() * self.THREADS_PER_CORE))
    if (mem > max_mem):
        mem = max_mem
    outdir = os.path.join(self.scratch, 'spades_output_dir')
    if (not os.path.exists(outdir)):
        os.makedirs(outdir)
    tmpdir = os.path.join(self.scratch, 'spades_tmp_dir')
    if (not os.path.exists(tmpdir)):
        os.makedirs(tmpdir)
    cmd = ['spades.py', '--threads', str(threads), '--memory', str(mem), '-o', outdir, '--tmp-dir', tmpdir]
    print(('THE DNA SOURCE IS : ' + str(dna_source)))
    if (dna_source == self.PARAM_IN_SINGLE_CELL):
        cmd += ['--sc']
    if (dna_source == self.PARAM_IN_PLASMID):
        cmd += ['--plasmid']
        if (len(reads_data) > 1):
            raise ValueError(((('Plasmid assembly requires that one ' + 'and only one library as input. ') + str(len(reads_data))) + ' libraries detected.'))
    if (dna_source == self.PARAM_IN_METAGENOME):
        cmd += ['--meta']
        if ((len(reads_data) > 1) or (reads_data[0]['type'] != 'paired')):
            error_msg = ('Metagenome assembly requires that one and ' + 'only one paired end library as input.')
            if (len(reads_data) > 1):
                error_msg += ((' ' + str(len(reads_data))) + ' libraries detected.')
            raise ValueError(error_msg)
    else:
        cmd += ['--careful']
    cmd += ['--phred-offset', phred_type]
    if (kmer_sizes is not None):
        cmd += [('-k ' + kmer_sizes)]
    if (skip_error_correction == 1):
        cmd += ['--only-assembler']
    (spades_yaml_path, iontorrent_present) = self.generate_spades_yaml(reads_data)
    if (iontorrent_present == 1):
        cmd += ['--iontorrent']
    cmd += ['--dataset', spades_yaml_path]
    self.log('Running SPAdes command line:')
    print(('SPADES CMD:' + str(cmd)))
    self.log(cmd)
    if self.DISABLE_SPADES_OUTPUT:
        with open(os.devnull, 'w') as null:
            p = subprocess.Popen(cmd, cwd=self.scratch, shell=False, stdout=null)
    else:
        p = subprocess.Popen(cmd, cwd=self.scratch, shell=False)
    retcode = p.wait()
    self.log(('Return code: ' + str(retcode)))
    if (p.returncode != 0):
        raise ValueError((('Error running SPAdes, return code: ' + str(retcode)) + '\n'))
    return outdir
def exec_spades(self, dna_source, reads_data, phred_type, kmer_sizes, skip_error_correction):
    mem = ((psutil.virtual_memory().available / self.GB) - self.MEMORY_OFFSET_GB)
    if (mem < self.MIN_MEMORY_GB):
        raise ValueError(((((('Only ' + str(psutil.virtual_memory().available)) + ' bytes of memory are available. The SPAdes wrapper will') + ' not run without at least ') + str((self.MIN_MEMORY_GB + self.MEMORY_OFFSET_GB))) + ' gigabytes available'))
    if (dna_source == self.PARAM_IN_METAGENOME):
        max_mem = self.MAX_MEMORY_GB_META_SPADES
        max_threads = self.MAX_THREADS_META
    else:
        max_mem = self.MAX_MEMORY_GB_SPADES
        max_threads = self.MAX_THREADS
    threads = min(max_threads, (psutil.cpu_count() * self.THREADS_PER_CORE))
    if (mem > max_mem):
        mem = max_mem
    outdir = os.path.join(self.scratch, 'spades_output_dir')
    if (not os.path.exists(outdir)):
        os.makedirs(outdir)
    tmpdir = os.path.join(self.scratch, 'spades_tmp_dir')
    if (not os.path.exists(tmpdir)):
        os.makedirs(tmpdir)
    cmd = ['spades.py', '--threads', str(threads), '--memory', str(mem), '-o', outdir, '--tmp-dir', tmpdir]
    print(('THE DNA SOURCE IS : ' + str(dna_source)))
    if (dna_source == self.PARAM_IN_SINGLE_CELL):
        cmd += ['--sc']
    if (dna_source == self.PARAM_IN_PLASMID):
        cmd += ['--plasmid']
        if (len(reads_data) > 1):
            raise ValueError(((('Plasmid assembly requires that one ' + 'and only one library as input. ') + str(len(reads_data))) + ' libraries detected.'))
    if (dna_source == self.PARAM_IN_METAGENOME):
        cmd += ['--meta']
        if ((len(reads_data) > 1) or (reads_data[0]['type'] != 'paired')):
            error_msg = ('Metagenome assembly requires that one and ' + 'only one paired end library as input.')
            if (len(reads_data) > 1):
                error_msg += ((' ' + str(len(reads_data))) + ' libraries detected.')
            raise ValueError(error_msg)
    else:
        cmd += ['--careful']
    cmd += ['--phred-offset', phred_type]
    if (kmer_sizes is not None):
        cmd += [('-k ' + kmer_sizes)]
    if (skip_error_correction == 1):
        cmd += ['--only-assembler']
    (spades_yaml_path, iontorrent_present) = self.generate_spades_yaml(reads_data)
    if (iontorrent_present == 1):
        cmd += ['--iontorrent']
    cmd += ['--dataset', spades_yaml_path]
    self.log('Running SPAdes command line:')
    print(('SPADES CMD:' + str(cmd)))
    self.log(cmd)
    if self.DISABLE_SPADES_OUTPUT:
        with open(os.devnull, 'w') as null:
            p = subprocess.Popen(cmd, cwd=self.scratch, shell=False, stdout=null)
    else:
        p = subprocess.Popen(cmd, cwd=self.scratch, shell=False)
    retcode = p.wait()
    self.log(('Return code: ' + str(retcode)))
    if (p.returncode != 0):
        raise ValueError((('Error running SPAdes, return code: ' + str(retcode)) + '\n'))
    return outdir