From c1c0ba45f3091a61f03115ea0f4c7e2ab5389e34 Mon Sep 17 00:00:00 2001 From: Martin Hunt Date: Thu, 7 Apr 2016 16:07:58 +0100 Subject: [PATCH 1/2] New option --ref_prefix --- ariba/tasks/run.py | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/ariba/tasks/run.py b/ariba/tasks/run.py index 9c488021..70639af6 100644 --- a/ariba/tasks/run.py +++ b/ariba/tasks/run.py @@ -1,8 +1,32 @@ import argparse +import os import sys import pyfastaq import ariba +def get_ref_files(options): + if options.ref_prefix is not None: + if options.verbose: + print('--ref_prefix used. Looking for reference input files starting with', options.ref_prefix, '...') + d = { + 'presabs': 'presence_absence.fa', + 'varonly': 'variants_only.fa', + 'noncoding': 'noncoding.fa', + 'metadata': 'metadata.tsv', + } + + for key in d: + filename = options.ref_prefix + '.' + d[key] + + if os.path.exists(filename): + if options.verbose: + print('Found: ', filename, '.\n ...treating it as if this was used: --', key, ' ', filename, sep='') + exec('options.' + key + ' = filename') + else: + if options.verbose: + print('Not found:', filename) + exec('options.' + key + ' = None') + def run(): parser = argparse.ArgumentParser( @@ -13,6 +37,7 @@ def run(): parser.add_argument('outdir', help='Output directory (must not already exist)') refdata_group = parser.add_argument_group('Reference data options') + refdata_group.add_argument('--ref_prefix', help='Prefix of input files (same as was used with getref), to save listing --preseabs,--varonly ...etc. Will look for files called ref_prefix. followed by: metadata.tsv,presence_absence.fa,noncoding.fa,presence_absence.fa. Using this will cause these to be ignored if used: --presabs,--varonly,--noncoding,--metadata') refdata_group.add_argument('--presabs', help='FASTA file of presence absence genes', metavar='FILENAME') refdata_group.add_argument('--varonly', help='FASTA file of variants only genes', metavar='FILENAME') refdata_group.add_argument('--noncoding', help='FASTA file of noncoding sequences', metavar='FILENAME') @@ -48,8 +73,22 @@ def run(): options = parser.parse_args() + + if options.verbose: + print('{:_^79}'.format(' Reference files '), flush=True) + get_ref_files(options) + if {None} == {options.presabs, options.varonly, options.noncoding}: - print('Error! Must use at least one of the options: --presabs --varonly --noncoding. Cannot continue', file=sys.stderr) + print('Error! Must use at least one of the options: --presabs --varonly --noncoding. Alternatively, use the option --ref_prefix. Cannot continue', file=sys.stderr) + sys.exit(1) + + if options.verbose: + print('\nUsing the following reference files:') + print('Presence/absence (--presabs):', options.presabs) + print('Variants only (--varonly):', options.varonly) + print('Non coding (--noncoding):', options.noncoding) + print('Metadata (--metadata):', options.metadata) + print() extern_progs = ariba.external_progs.ExternalProgs(verbose=options.verbose) pyfastaq.sequences.genetic_code = options.genetic_code From 79b7f86c3d1c82c991678b3bd9ccd1db99918a0d Mon Sep 17 00:00:00 2001 From: Martin Hunt Date: Thu, 7 Apr 2016 16:08:19 +0100 Subject: [PATCH 2/2] Use new --ref_prefix in example calls --- ariba/ref_genes_getter.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ariba/ref_genes_getter.py b/ariba/ref_genes_getter.py index 4fb56315..c81019f2 100644 --- a/ariba/ref_genes_getter.py +++ b/ariba/ref_genes_getter.py @@ -253,7 +253,7 @@ def _get_from_card(self, outprefix): print(' ', final_tsv) print('\nYou can use them with ARIBA like this:') - print('ariba run --presabs', presence_absence_fa, '--varonly', variants_only_fa, '--metadata', final_tsv, ' reads_1.fq reads_2.fq output_directory\n') + print('ariba run --ref_prefix', outprefix, ' reads_1.fq reads_2.fq output_directory\n') print('If you use this downloaded data, please cite:') print('"The Comprehensive Antibiotic Resistance Database", McArthur et al 2013, PMID: 23650175') @@ -294,7 +294,7 @@ def _get_from_resfinder(self, outprefix): shutil.rmtree(tmpdir) print('You can use it with ARIBA like this:') - print('ariba run --presabs', os.path.relpath(final_fasta), 'reads_1.fq reads_2.fq output_directory\n') + print('ariba run --ref_prefix', outprefix, 'reads_1.fq reads_2.fq output_directory\n') print('If you use this downloaded data, please cite:') print('"Identification of acquired antimicrobial resistance genes", Zankari et al 2012, PMID: 22782487\n') @@ -323,7 +323,7 @@ def _get_from_argannot(self, outprefix): print('Finished. Final genes file is called', final_fasta, end='\n\n') print('You can use it with ARIBA like this:') - print('ariba run --presabs', os.path.relpath(final_fasta), 'reads_1.fq reads_2.fq output_directory\n') + print('ariba run --ref_prefix', outprefix, 'reads_1.fq reads_2.fq output_directory\n') print('If you use this downloaded data, please cite:') print('"ARG-ANNOT, a new bioinformatic tool to discover antibiotic resistance genes in bacterial genomes",\nGupta et al 2014, PMID: 24145532\n')