Answers.Body: <p>There are two approaches you can take:</p>
  
  <ol>
  <li>There's a <code>--conda-create-envs-only</code> option that you can use to exit after creating the envs. You should get information about where the envs are so you can run <code>amrfinder -u</code>.</li>
  <li>Add a new rule called "amr_setup" or something like that that runs:</li>
  </ol>
  
  <p>. </p>
  
  <pre><code>amrfinder -u
  touch amrfinder.setup
  </code></pre>
  
  <p>Then put <code>amrfinder.setup</code> into your snakemake workflow as an input file into the amr_finder_plus rule. Either of these will work</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-21T06:51:36.260Z
Answers.LastActivityDate: 2020-04-21T09:50:39.957Z
Answers.LastEditDate: 2020-04-21T09:50:39.957Z
Answers.UserDisplayName: Devon Ryan
Body: <p>I'm trying to add <a href="https://github.com/ncbi/amr" rel="nofollow noreferrer">amrfinder</a> running within conda to a snakemake workflow, working on a slurm HPC.</p>
  
  <p>The first time you run <code>amrfinder</code>, you have to run <code>amrfinder -u</code> to update/download the database of genes/proteins which it searches for. Since I'm using the <code>--use-conda</code> flag of <code>snakemake</code>, the first time I run the workflow, it creates a new env for the <code>conda</code> package, so this command has to be run before that copy of <code>amrfinder</code> will work.</p>
  
  <p>My question is: how do I run <code>amrfinder -u</code> within <code>snakemake</code>? If I do it as part of the standard <code>amrfinder</code> 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.</p>
  
  <p>I can't figure out how to run this command in a 'snakemake-y' way, as it has no input, it's just literally <code>amrfinder -u</code>.</p>
  
  <p>Of course, I can make it work with a hack/workaround, but I'm interested in a snakemake way of doing it.</p>
  
  <p>This is the main snakemake rule for running amr_finder_plus, the new rule, to run <code>amrfinder -u</code> needs to run before this</p>
  
  <pre><code>rule amr_finder_plus:
      input:
          assembly = 'my_assembly.fasta'
      output:
          amr_finder_plus_results = 'my_amr_finder_plus_results.tsv'
      conda:
          '../../envs/amrfinderplus.yaml'
      shell:
          'amrfinder -n {input.assembly} -O Salmonella --output {output.amr_finder_plus_results} --threads 4'
  </code></pre>
  
Tags: <snakemake><conda><hpc>
Title: How to run a one-time 'setup' step for amrfinder in snakemake using conda
ThreadText: # How to run a one-time 'setup' step for amrfinder in snakemake using conda
  
  (Asked by: username_0 on 2020-04-21)
  
  I'm trying to add [amrfinder](https://github.com/ncbi/amr) 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:
      input:
          assembly = 'my_assembly.fasta'
      output:
          amr_finder_plus_results = 'my_amr_finder_plus_results.tsv'
      conda:
          '../../envs/amrfinderplus.yaml'
      shell:
          'amrfinder -n {input.assembly} -O Salmonella --output {output.amr_finder_plus_results} --threads 4'
  
  ```
  
  **Tags:** snakemake, conda, hpc
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-04-21. Score: 1 | Accepted answer
  
  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
  
  
  ---
  
  