在snakemake规则中创建conda环境

问题描述 投票:0回答:1

我想为一个工具创建一个conda环境,激活它并在snakemake规则中使用该工具。我已指出如下:

蛇形规则:

rule fastqc:
    input:
        #fastq=expand("fastq_dir/{sample}_R{pair}_001.fastq.gz", sample=config["samples"], pair=config["fastq_pairs"])
        fastq_path = lambda wildcards: get_full_path(wildcards.sample)
    output:
        #html=expand("fastqc_dir/{sample}_R{pair}_001_fastqc.html", sample=config["samples"], pair=config["fastq_pairs"]),
        #zip=expand("fastqc_dir/{sample}_R{pair}_001_fastqc.zip", sample=config["samples"], pair=config["fastq_pairs"])
        os.path.join("{output_dir}", "{sample}_fastqc.html")
    params:
        outdir="{output_dir}",
        sample_adapter=os.path.join("../data/adapters", "{sample}.txt")
    log:
        log_file=os.path.join("{output_dir}", "local_log", \
        "run_FastQC_{sample}.log")
    resources:
        threads = 4,
        mem_mb = 24000,
        runtime = "2h"
    benchmark:
        os.path.join("{output_dir}", "cluster_log", "run_FastQC_{sample}.benchmark.log")
    conda:
        "envs/fastqc.yaml"
    shell:
        """
        conda activate fastqc
        fastqc {input} \
        threads {resources.threads} \
        --outdir {params.outdir} \
        --kmers 7 \
        --adapters {params.sample_adapter} \
        &> {log.log_file} 
        """

配置文件是:

name: fastqc
channels:
- conda-forge
- bioconda
dependencies:
- fastqc=0.12.1-0
prefix: ./.conda_myproject/envs

当我运行 Snakemake 时,我的作业失败并出现以下错误:

EnvironmentNameNotFound: Could not find conda environment: fastqc

确实,当我查看环境是否在指定位置创建时,我没有看到 fastqc 环境。相反,我看到一个名为:

的环境
f2b1d4b45d38fce47f79239411ceb3a4_

在我的工作目录中

.snakemake/conda/

我已经尝试过很多次了,但都失败了。我将 conda 环境安装在项目目录而不是我的主目录中。我想知道你是否能帮我解决这个问题。谢谢!

conda snakemake
1个回答
0
投票

在运行命令之前不需要激活环境,请参阅教程中的示例,所以这应该可以工作:

rule fastqc:
    input:
        #fastq=expand("fastq_dir/{sample}_R{pair}_001.fastq.gz", sample=config["samples"], pair=config["fastq_pairs"])
        fastq_path = lambda wildcards: get_full_path(wildcards.sample)
    output:
        #html=expand("fastqc_dir/{sample}_R{pair}_001_fastqc.html", sample=config["samples"], pair=config["fastq_pairs"]),
        #zip=expand("fastqc_dir/{sample}_R{pair}_001_fastqc.zip", sample=config["samples"], pair=config["fastq_pairs"])
        os.path.join("{output_dir}", "{sample}_fastqc.html")
    params:
        outdir="{output_dir}",
        sample_adapter=os.path.join("../data/adapters", "{sample}.txt")
    log:
        log_file=os.path.join("{output_dir}", "local_log", \
        "run_FastQC_{sample}.log")
    resources:
        threads = 4,
        mem_mb = 24000,
        runtime = "2h"
    benchmark:
        os.path.join("{output_dir}", "cluster_log", "run_FastQC_{sample}.benchmark.log")
    conda:
        "envs/fastqc.yaml"
    shell:
        """
        fastqc {input} \
        threads {resources.threads} \
        --outdir {params.outdir} \
        --kmers 7 \
        --adapters {params.sample_adapter} \
        &> {log.log_file} 
        """
© www.soinside.com 2019 - 2024. All rights reserved.