I'm trying to add amrfinder running within conda to a snakemake workflow, working on a slurm HPC.

The first time you run amrfinder, you have to run amrfinder -u to update/download the database of genes/proteins which it searches for. Since I'm using the --use-conda flag of snakemake, the first time I run the workflow, it creates a new env for the conda package, so this command has to be run before that copy of amrfinder will work.

My question is: how do I run amrfinder -u within snakemake? If I do it as part of the standard amrfinder command, it runs as many times as there are samples, and as all the jobs are looking at the same database, when it updates for one job, it breaks the other jobs.

I can't figure out how to run this command in a 'snakemake-y' way, as it has no input, it's just literally amrfinder -u.

Of course, I can make it work with a hack/workaround, but I'm interested in a snakemake way of doing it.

This is the main snakemake rule for running amr_finder_plus, the new rule, to run amrfinder -u needs to run before this

rule amr_finder_plus:
        assembly = 'my_assembly.fasta'
        amr_finder_plus_results = 'my_amr_finder_plus_results.tsv'
        'amrfinder -n {input.assembly} -O Salmonella --output {output.amr_finder_plus_results} --threads 4'

1 Answer 1


There are two approaches you can take:

  1. There's a --conda-create-envs-only option that you can use to exit after creating the envs. You should get information about where the envs are so you can run amrfinder -u.
  2. Add a new rule called "amr_setup" or something like that that runs:


amrfinder -u
touch amrfinder.setup

Then put amrfinder.setup into your snakemake workflow as an input file into the amr_finder_plus rule. Either of these will work


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.