Search code examples
snakemake

Snakemake: Only input files can be specified as functions


Snakemake complains that "Only input files can be specified as functions" in the shell line.

def get_filename(wildcards):
    sampleid = wildcards.sample.split['-'][1]
    GeneFuse_vcf= f"{sampleid}.fusion.vcf"
    return GeneFuse_vcf

rule GeneFuse:
    input:
        bam_path = f"{outputdir}/"+"{sample}/13_genefusion"
    params:
        svabaflow = config["svabaflow"],
    output:
        GeneFuse_vcf = get_filename
    shell:
        "{params.svabaflow} {input} {wildcards.sample}"

In the rule GenefUSE, my {sample} format is ctn-305A26000547

and i want to tell snakemake that my outputfile(GeneFuse_vcf) is named 305A26000547.fusion.vcf Ofcourse,if the {sample} is ctn-367A23594285,the filename should be "367A23594285.fusion.vcf"

Any suggestion to fix it? Thanks.


Solution

  • Assuming you already have the list of SAMPLEIDS as you state in the comment, you can construct an rule all which calls rule GeneFuse like this:

    rule all:
        input:
            expand("{sample}.fusion.vcf", sampleid=SAMPLEIDS),
        default_target: True
    
    
    rule GeneFuse:
        input:
            bam_path=f"{outputdir}/" + "{sample}/13_genefusion",
        params:
            svabaflow=config["svabaflow"],
        output:
            GeneFuse_vcf="{sample}.fusion.vcf",
        shell:
            "{params.svabaflow} {input} {wildcards.sample}"