Skip to content

Commit

Permalink
Merge pull request #48 from martinghunt/provide_getref_prefix_to_run
Browse files Browse the repository at this point in the history
Provide getref prefix to run
  • Loading branch information
martinghunt committed Apr 7, 2016
2 parents 8084de0 + 79b7f86 commit e81b118
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
6 changes: 3 additions & 3 deletions ariba/ref_genes_getter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')

Expand Down Expand Up @@ -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')

Expand Down
41 changes: 40 additions & 1 deletion ariba/tasks/run.py
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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')
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e81b118

Please sign in to comment.