Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide getref prefix to run #48

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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