简体   繁体   中英

snakemake Wildcards in input files cannot be determined from output files:

I use the snakemkae to create a pipeline to split bam by chr,but I met a problem, Wildcards in input files cannot be determined from output files: 'OutputDir' Can someone help me to figure it out?

if config['ref'] == 'hg38':
    ref_chr = []
    for i in range(1,23):
        ref_chr.append('chr'+str(i))
    ref_chr.extend(['chrX','chrY'])
    
elif config['ref'] == 'b37':
    ref_chr = []
    for i in range(1,23):
        ref_chr.append(str(i))
    ref_chr.extend(['X','Y'])
    
rule all:
    input:
        expand(f"{OutputDir}/split/{name}.{{chr}}.bam",chr=ref_chr)



rule minimap2:
    input:
        TargetFastq
    output:
        Sortbam = "{OutputDir}/{name}.sorted.bam",
        Sortbai = "{OutputDir}/{name}.sorted.bam.bai"
    resources:
        mem_mb = 40000
    threads: nt
    singularity:
       OntSoftware
    shell:
        """
        minimap2 -ax map-ont -d {ref_mmi} --MD -t {nt} {ref_fasta} {input} | samtools sort -O BAM -o {output.Sortbam}
        samtools index {output.Sortbam}
        """

rule split_bam:
    input:
        rules.minimap2.output.Sortbam
    output:
        splitBam = expand(f"{OutputDir}/split/{name}.{{chr}}.bam",chr=ref_chr),
        splitBamBai = expand(f"{OutputDir}/split/{name}.{{chr}}.bam.bai",chr=ref_chr)
    resources:
        mem_mb = 30000
    threads: nt
    singularity:
       OntSoftware
    shell:
        """
       samtools view -@ {nt} -b {input} {chr} > {output.splitBam}
       samtools index -@ {nt} {output.splitBam}
        """

I change the wilcards {outputdir},but is dose not help.

expand(f"{OutputDir}/split/{name}.{{chr}}.bam",chr=ref_chr),
splitBamBai = expand(f"{OutputDir}/split/{name}.{{chr}}.bam.bai",chr=ref_chr),

A couple of comments on this lines...:

  • You escape chr by using double braces, {{chr}} . This means you don't want chr to be expanded, which I doubt it is correct. I suspect you want something like:
expand("{{OutputDir}}/split/{{name}}.{chr}.bam",chr=ref_chr),
  • The rule minimpa2 does not contain {chr} wildcard, hence the error you get.

As an aside, when you create a bam file and its index in the same rule, you can get the time stamp of the index file to be older than the bam file itself. This later can generate spurious warning from samtools/bcftools. See https://github.com/snakemake/snakemake/issues/1378 (not sure if it's been fixed).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM