how to specify a specific conda environment in a specific rule with snakemake?
2
1
Entering edit mode
2.1 years ago

Hi!

I met a question about snakemake when I try to specify a conda env within a specific rule, but not influence other rules which should be run in default conda env.

configfile:
    "config.json"

SAMPLES, = glob_wildcards(config['data']+"/{id}_L001_R1_001.fastq.gz")

rule align_sort:
    input:
        config['data']+"/{sample}_L001_R1_001.fastq.gz",
        config['data']+"/{sample}_L001_R2_001.fastq.gz"
    output:
        temp("{sample}.mapped.bam")
    params:
        rg = "@RG\tID:{sample}\tPL:ILLUMINA\tSM:{sample}",
        ref = config['genome']
    shell:
        "bwa mem -R '{params.rg}' -M {params.ref} {input} | samtools sort -o {output} -"

rule removeClipping:
    input:
        "{sample}.mapped.bam"
    output:
        temp("{sample}.clipped.bam")
    conda:
        "bio2"
    shell:
        "bamutils removeclipping {input} {output}"
......

In my snakemake file, I have only one rule named removeClipping which has to be run in another conda environment named bio2.

But the remaining rule should be run in the default conda environment.

So I do not sure about the conda: setting in snakemake. Is this means that only this specific rule will be run in bio env, and the remaining rule will still be run in the default env?

Is anyone clear on this issue and would like help me figure this out? Many thanks!

linux snakemake conda • 1.7k views
ADD COMMENT
1
Entering edit mode
2.1 years ago
Eric Lim ★ 2.2k

You specify the tool and version you want to use in a yaml. For example, in bio2.yaml,

name: bio2
channels: 
  - bioconda
  - conda-forge
dependencies:
  - tool=version

Then you define the yaml in your rule. For example,

conda:
    "bio2.yaml"

Then you run snakemake with the --use-conda flag.

Hope this helps.

ADD COMMENT
0
Entering edit mode

Thank you for responding so quickly!!

This helps me a lot.

ADD REPLY
1
Entering edit mode
2.1 years ago

Given the Snakefile you posted, you are asking whether rule removeClipping will run in conda env bio2 while the other rules will run in the default environment, right? If so, the answer is yes. Remember to add --use-conda to the snakemake command line (it's easy to forget!)

ADD COMMENT
0
Entering edit mode

Yes! That's what I mean. Thanks a lot!

ADD REPLY

Login before adding your answer.

Traffic: 1820 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