1

我尝试使用蛇形制作地图并合并从许多车道获得的一些数据。我有一些问题。我想做的是:

*.gz> 432_L001.sam, 432_L002.sam > 432_L001.sorted.bam,432_L002.sorted.bam> 432.bam

因此,从单位的 fastq 开始,使用样本键的名称创建一个 unic bamfile。

配置.yaml

samples:
    "432": ["432_L001", "432_L002"]
    "433": ["433_LOO1","433_L002"]


units:

  "432_L001": [ "RAW/432_CGATGT_L001_R1_001.fastq.gz", "RAW/432_CGATGT_L001_R2_001.fastq.gz"]
  "432_L002": ["RAW/432_CGATGT_L002_R1_001.fastq.gz","RAW/432_CGATGT_L002_R2_001.fastq.gz"]
  "433_L001": ["RAW/433_CAGATC_L001_R1_001.fastq.gz","RAW/433_CAGATC_L001_R2_001.fastq.gz"]
  "433_L002": ["RAW/433_CAGATC_L002_R1_001.fastq.gz","RAW/433_CAGATC_L002_R2_001.fastq.gz"]

蛇制造

rule all:
    input: expand("mapped_reads/merged_samples/{A}.bam", A=config["samples"]),
           expand("mapped_reads/bam/{unit}_sorted.bam",unit=config['units'])


include_prefix="rules"


include:
    include_prefix + "/bwa_mem.rules"
include:
    include_prefix + "/samfiles.rules"
include:
    include_prefix + "/picard.rules"

规则

    from snakemake.exceptions import MissingInputException

    rule bwa_mem:
        input:
            lambda wildcards: config["units"][wildcards.unit]
        output:
            temp("mapped_reads/sam/{unit}.sam")
        params:
            #sample=lambda wildcards, UNIT_TO_SAMPLE[wildcards.unit]
            #sample=lambda wildcards: units[wildcards.unit],
            genome= config["reference"]['genome_fasta']
        log:
            "mapped_reads/log/{unit}_bwa_mem.log"
        benchmark:
            "benchmarks/bwa/mem/{unit}.txt"
        threads: 8
        shell:
            '/illumina/software/PROG2/bwa-0.7.15/bwa mem '\
                    '-t {threads} {params.genome} {input} 2> {log} > {output}'
rule picard_SortSam:
   input:
       "mapped_reads/sam/{unit}.sam"
   output:
       temp("mapped_reads/bam/{unit}_sorted.bam")
   benchmark:
       "benchmarks/picard/SortSam/{unit}.txt"
   shell:
       "picard  SortSam I={input} O={output} SO=coordinate"

rule samtools_merge_bam:
    """
    Merge bam files for multiple units into one for the given sample.
    If the sample has only one unit, files will be copied.
    """
    input:
        lambda wildcards: expand("mapped_reads/bam/{unit}_sorted.bam",unit=config["samples"][wildcards.sample])
    output:
        "mapped_reads/merged_samples/{sample}.bam"
    benchmark:
        "benchmarks/samtools/merge/{sample}.txt"
    run:
        if len(input) > 1:
            shell("samtools merge {output} {input}")
        else:
            shell("cp {input} {output} && touch -h {output}")

如果我使用此代码,我总是会出现此错误:

InputFunctionException in line 50 of /home/maurizio/Desktop/TEST_exome/rules/bwa_mem.rules:
KeyError: '433_LOO1'
Wildcards:
unit=433_LOO1

怎么可能解决?

这个通配符有什么问题..??:

lambda 通配符:expand("mapped_reads/bam/{unit}_sorted.bam",unit=config["samples"][wildcards.sample])

4

1 回答 1

1

您的配置中的“0”和“O”似乎混淆了:

samples: "432": ["432_L001", "432_L002"] "433": ["433_LOO1","433_L002"] --------------------------------------------- ^^

"433_L001": ["RAW/433_CAGATC_L001_R1_001.fastq.gz","RAW... ------------^^

于 2017-08-02T07:46:04.630 回答