creating conda environment from snakemake rule
0
0
Entering edit mode
17 months ago
Jordi ▴ 60

I am trying to activate a conda environment from snakemake to use a different environment for a rule in the workflow. I created a .yml file to specify dependencies.

This is the snakemake rule I defined:

rule Merge_VCFs:
    input:
        f1='file1',
                f2='file2'
    output:
                vcf="output_file"
    conda:
               "bcftools_env.yml"
    shell:
        """
        bcftools merge -m none -F x {input.f1} {input.f2} > {output.vcf}
                """

When I try to run this, however, I get the following error:

Workflow.conda() missing 1 required positional argument: 'conda_env'

I looked for information on this argument in the documentation, but I could not figure out what is missing and where I need to specify it. I ran rules using other .yml previously without encountering this error.

Does anybody have any idea what this is?

These are the run parameters used:

snakemake -s "Snakefile" \
        --cores 10 \
        --resources mem_gb=40 \
        --use-conda \
        --conda-prefix '/home/USER/anaconda3'

This is the content of the .yml file I am trying to use to set up the environment:

name: bcftools_env
channels:
  - conda-forge
  - bioconda
  - defaults
dependencies:
  - _libgcc_mutex=0.1=conda_forge
  - _openmp_mutex=4.5=2_gnu
  - bcftools=1.17=h3cc50cf_1
  - bzip2=1.0.8=h7f98852_4
  - c-ares=1.19.1=hd590300_0
  - ca-certificates=2023.5.7=hbcca054_0
  - gsl=2.7=he838d99_0
  - htslib=1.17=h81da01d_2
  - keyutils=1.6.1=h166bdaf_0
  - krb5=1.20.1=h81ceb04_0
  - libblas=3.9.0=17_linux64_openblas
  - libcblas=3.9.0=17_linux64_openblas
  - libcurl=8.1.2=h409715c_0
  - libdeflate=1.18=h0b41bf4_0
  - libedit=3.1.20191231=he28a2e2_2
  - libev=4.33=h516909a_1
  - libgcc-ng=13.1.0=he5830b7_0
  - libgfortran-ng=13.1.0=h69a702a_0
  - libgfortran5=13.1.0=h15d22d2_0
  - libgomp=13.1.0=he5830b7_0
  - libnghttp2=1.52.0=h61bc06f_0
  - libnsl=2.0.0=h7f98852_0
  - libopenblas=0.3.23=pthreads_h80387f5_0
  - libssh2=1.11.0=h0841786_0
  - libstdcxx-ng=13.1.0=hfd8a6a1_0
  - libzlib=1.2.13=hd590300_5
  - ncurses=6.4=hcb278e6_0
  - openssl=3.1.1=hd590300_1
  - perl=5.32.1=2_h7f98852_perl5
  - xz=5.2.6=h166bdaf_0
  - zlib=1.2.13=hd590300_5
  - zstd=1.5.2=h3eb15da_6
prefix: /home/USER/anaconda3/envs/bcftools_env
snakemake conda • 1.3k views
ADD COMMENT
0
Entering edit mode

Have you added --use-conda flag when running snakemake?

ADD REPLY
0
Entering edit mode

Yes, I did. I just edited the post accordingly

ADD REPLY
0
Entering edit mode

Should you have envs/bcftools_env.yml next to your conda directive? Or envs at the end of the path after the --conda-prefix flag?

ADD REPLY
0
Entering edit mode

I'm not sure the --conda-prefix is necessary. I ran your code without it, after setting up the conda env, and it ran fine. Had to fix a few typos in the Snakefile though.

ADD REPLY
0
Entering edit mode

I will try this out soon. It is weird, however, that I ran other rules with similar setups without any problem. Yes, for some reason the spacing in the Snakefile is messed up in my post. The original file is correct, though.

ADD REPLY
0
Entering edit mode

It's not just the spacing, you have a comma missing after f1='file1'. Sometimes when erroneous formatting like this is present snakamake throws ambiguous errors.

ADD REPLY

Login before adding your answer.

Traffic: 2575 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6