Snakemake在两个不同的通配符子集上发布运行规则

时间:2019-08-05 16:03:50

标签: bioinformatics snakemake

我正在尝试编写一条蛇形规则,该规则将根据某些文件grouping与其他文件进行区别对待。我的文件列表已加载到sample.tsv文件中。

我认为这会相对容易一些,因为我相信在rule all中填充通配符会触发特定规则的执行,但事实并非如此。

这里是我正在研究的配对版本

示例文件列表。请注意,这里的chip类别对于定义我的组变得很重要

tissue replicate chip file
leaf rep2 input 00.data/chip_seq/input/leaf_input_rep2.fastq
leaf rep1 input 00.data/chip_seq/input/leaf_input_rep1.fastq
leaf rep2 H3K36me3 00.data/chip_seq/H3K36me3/leaf_H3K36me3_rep2.fastq
leaf rep1 H3K36me3 00.data/chip_seq/H3K36me3/leaf_H3K36me3_rep1.fastq
leaf rep1 H3K56ac 00.data/chip_seq/H3K56ac/leaf_H3K56ac_rep1.fastq                                                                                                        
leaf rep2 H3K56ac 00.data/chip_seq/H3K56ac/leaf_H3K56ac_rep2.fastq

然后在我的脚本中,将它们分为两个子类别

broad = ['H3K36me3']
narrow = ["H3K56ac"]
rule all:
    input:

#Align all reads
expand("02.unique_align/{tissue}_{chip}_{replicate}_unique_bowtie2_algn.bam", \
    ¦   ¦   ¦   tissue = samples['tissue'], replicate = samples['replicate'], \
    ¦   ¦   ¦   chip = samples['chip']),

#Should cause the expand on ONLY narrow groups, causing the below rule
# run_bcp_peak_caller_narrow to trigger 
expand("03.called_peaks/{tissue}_{replicate}_{chip}_peaks_region_narrow.bed",
    ¦   ¦   ¦   tissue = narrow_peaks['tissue'],
    ¦   ¦   ¦   replicate = narrow_peaks['replicate'],
    ¦   ¦   ¦   chip = narrow),

#Should cause the expand on ONLY narrow groups, causing the below rule
# run_bcp_peak_caller_broad to trigger

expand("03.called_peaks/{tissue}_{replicate}_{chip}_peaks_region_broad.bed",
    ¦   ¦   ¦   tissue = samples['tissue'],
    ¦   ¦   ¦   replicate = samples['replicate'],
    ¦   ¦   ¦   chip = broad)


## Two functions, one to get the input files, defined here as `get_input` the other to retrieve the chip files

def get_input(wildcards):
    z = glob.glob(os.path.join("02.unique_align/", (wildcards.tissue + "_" + \
    ¦   wildcards.replicate + "_" + "input_unique_bowtie2_algn.bam")))
    return z

def get_chip(wildcards):
    z = glob.glob(os.path.join("02.unique_align/", (wildcards.tissue + "_" + \
    ¦   ¦   ¦  wildcards.replicate + "_" + wildcards.chip + "_" + \
    ¦   ¦   ¦  "unique_bowtie2_algn.bam")))

    return z

rule run_bcp_peak_caller_broad:
    input:
    ¦   chip_input = get_input,
    ¦   chip_mod = get_chip
    params:
    ¦   "03.called_peaks/{tissue}_{replicate}_{chip}_peaks_broad"
    output:
    ¦   "03.called_peaks/{tissue}_{replicate}_{chip}_peaks_broad.bed"
    shell:"""
    peakranger bcp \
    --format bam \
    --verbose \
    --pval .001 \
    --data {input.chip_mod} \
    --control {input.chip_input} \
    --output {params}
    """

rule run_bcp_peak_caller_narrow:
    input:
        chip_input = get_input,
        chip_mod = get_chip
    params:
        "03.called_peaks/{tissue}_{replicate}_{chip}_peaks_narrow"
    output:
        "03.called_peaks/{tissue}_{replicate}_{chip}_peaks_narrow.bed"
    shell:"""
    peakranger \
    --format bam \
    --verbose \
    --pval .001 \
    --data {input.chip_mod} \
    --control {input.chip_input} \
    --output {params}
    """

错误如下:

MissingInputException in line 39 of /scratch/jpm73279/04.lncRNA/02.Analysis/24.regenerate_expression_peaks/Generate_peak_lists.snake:
Missing input files for rule all:
03.called_peaks/root_rep1_H3K4me1_peaks_region_broad.bed
03.called_peaks/root_rep2_H3K36me3_peaks_region_broad.bed
03.called_peaks/leaf_rep1_H3K4me1_peaks_region_broad.bed
03.called_peaks/root_rep1_H3K36me3_peaks_region_broad.bed
03.called_peaks/leaf_rep2_H3K36me3_peaks_region_broad.bed
03.called_peaks/root_rep2_H3K4me1_peaks_region_broad.bed

我的理解是snakemake会填充rule all部分中找到的文件组合,然后确定需要在上游运行哪些步骤。

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:1)

您的理解是正确的;当没有为snakemake指定任何输出时,它将找到第一个规则,并尝试生成其输出。

问题在于rule all指定了无法“制定”的规则。我将对错误进行并排比较:

rule all:
    03.called_peaks/root_rep1_H3K4me1_peaks_region_broad.bed

rule run_bcp_peak_caller_broad:
    output:
        "03.called_peaks/{tissue}_{replicate}_{chip}_peaks_broad.bed"

看到区别了吗?您说要生成的文件以peaks_region_broad.bed结尾,但是您的规则使输出以peaks_broad.bed结尾。

再次查看rule all,可能您想删除字符串的 _region 部分。