Skip to content

Commit

Permalink
v2.6
Browse files Browse the repository at this point in the history
Use different MLST species scheme map versions
Write to stderr number samples FAIL
  • Loading branch information
miguelpmachado authored Jun 21, 2017
1 parent 697c1d1 commit 7d0a8de
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 17 deletions.
14 changes: 8 additions & 6 deletions INNUca.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
INNUca.py - INNUENDO quality control of reads, de novo assembly and contigs quality assessment, and possible contamination search
<https://github.com/B-UMMI/INNUca>
Copyright (C) 2016 Miguel Machado <[email protected]>
Copyright (C) 2017 Miguel Machado <[email protected]>
Last modified: April 03, 2017
Last modified: June 21, 2017
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -70,7 +70,7 @@ def get_trueCoverage_config(skipTrueCoverage, trueConfigFile, speciesExpected, s


def main():
version = '2.5'
version = '2.6'
args = utils.parseArguments(version)

general_start_time = time.time()
Expand Down Expand Up @@ -163,9 +163,8 @@ def main():
scheme = 'unknown'
if not args.skipMLST and not args.skipSPAdes:
scheme = mlst.getScheme(args.speciesExpected)

# Get path to blastn
mlst.getBlastPath()
# Print path to blastn
mlst.getBlastPath()

# Get trueCoverage_ReMatCh settings
trueCoverage_config = get_trueCoverage_config(args.skipTrueCoverage, args.trueConfigFile.name if args.trueConfigFile is not None else None, args.speciesExpected, script_path)
Expand Down Expand Up @@ -260,6 +259,9 @@ def main():
# Check whether INNUca.py run at least one sample successfully
if number_samples_successfully == 0:
sys.exit('No samples run successfully!')
else:
if number_samples_pass < number_samples_successfully:
sys.stderr.write('{fail_samples} samples FAIL INNUca.py analysis'.format(fail_samples=(number_samples_successfully - number_samples_pass)))


def get_sample_args_fastq(fastq_files_list, outdir, pairEnd_filesSeparation_list):
Expand Down
54 changes: 43 additions & 11 deletions modules/mlst.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
import utils
import os
from functools import partial
import sys


mlst_timer = partial(utils.timer, name='MLST')


def getScheme(species):
command = ['which', 'mlst']
run_successfully, stdout, stderr = utils.runCommandPopenCommunicate(command, False, None, False)
mlst_folder = os.path.abspath(os.path.realpath(stdout.splitlines()[0]))
def get_species_scheme_map_version(mlst_folder):
species_scheme_map_version = 1

mlst_db_path = os.path.join(os.path.dirname(os.path.dirname(mlst_folder)), 'db', 'species_scheme_map.tab')
if not os.path.isfile(mlst_db_path):
mlst_db_path = os.path.join(os.path.dirname(os.path.dirname(mlst_folder)), 'db', 'scheme_species_map.tab')
if not os.path.isfile(mlst_db_path):
sys.exit('ERROR: species_scheme_map not found. Contact the developers. In the meantime try running INNUca with --skipMLST option')
else:
species_scheme_map_version = 2
return mlst_db_path, species_scheme_map_version


def set_species_scheme_map_variables(list_values, species_scheme_map_version):
if species_scheme_map_version == 1:
val_genus = list_values[0]
val_species = list_values[1]
val_scheme = list_values[2]
elif species_scheme_map_version == 2:
val_genus = list_values[1]
val_species = list_values[2]
val_scheme = list_values[0]
return val_genus, val_species, val_scheme

species = species.lower().split(' ')

def parse_species_scheme_map(species_splited, mlst_db_path, species_scheme_map_version):
scheme = 'unknown'

with open(mlst_db_path, 'rtU') as reader:
Expand All @@ -23,15 +43,27 @@ def getScheme(species):
if not line.startswith('#'):
line = line.lower().split('\t')
line = [line[i].split(' ')[0] for i in range(0, len(line))]
if line[0] == species[0]:
if line[1] == '':
genus_mlst_scheme = line[2]
elif line[1] == species[1]:
scheme = line[2]
val_genus, val_species, val_scheme = set_species_scheme_map_variables(line, species_scheme_map_version)
if val_genus == species_splited[0]:
if val_species == '':
genus_mlst_scheme = val_scheme
elif val_species == species_splited[1]:
scheme = val_scheme
if scheme == 'unknown' and genus_mlst_scheme is not None:
scheme = genus_mlst_scheme
return scheme


def getScheme(species):
command = ['which', 'mlst']
run_successfully, stdout, stderr = utils.runCommandPopenCommunicate(command, False, None, False)
mlst_folder = os.path.abspath(os.path.realpath(stdout.splitlines()[0]))

mlst_db_path, species_scheme_map_new = get_species_scheme_map_version(mlst_folder)

scheme = parse_species_scheme_map(species.lower().split(' '), mlst_db_path, species_scheme_map_new)

print '\n' + 'MLST scheme found for ' + ' '.join(species) + ': ' + scheme
print '\n' + 'MLST scheme found for {species}: {scheme}'.format(species=species, scheme=scheme)

return scheme

Expand Down

0 comments on commit 7d0a8de

Please sign in to comment.