Snakemake: MissingInputException in rule - Missing input files for rule sam_to_bam:

224 Views Asked by At

I started to learn Snakemake and here is my first code:

SAM_DIR = "/mnt/c/Code/sam_tiny"
BAM_DIR = "/mnt/c/Code/bam"

SAM_FILES = glob_wildcards(os.path.join(SAM_DIR, "{sample}.sam"))
SAMPLES = [wildcards[0] for wildcards in SAM_FILES]

rule all:
    input:
        expand(os.path.join(STATS_DIR, "{sample}.txt"), sample=SAM_FILES)

rule sam_to_bam:
    input:
        os.path.join(SAM_DIR, "{sample}.sam")
    output:
        os.path.join(BAM_DIR, "{sample}.bam")
    shell:
        "samtools view -b {input.sam} > {output.bam}"

and, of course, it was not without error.

On running it gives the following error:

MissingInputException in rule sam_to_bam in file /mnt/c/Code/Snakefile.smk, line 16:
Missing input files for rule sam_to_bam:
    output: /mnt/c/Code/bam/['ERR024604_tiny', 'ERR024605_tiny', 'ERR024606_tiny', 'ERR024607_tiny', 'ERR024608_tiny', 'ERR024609_tiny'].bam
    wildcards: sample=['ERR024604_tiny', 'ERR024605_tiny', 'ERR024606_tiny', 'ERR024607_tiny', 'ERR024608_tiny', 'ERR024609_tiny']
    affected files:
        /mnt/c/Code/sam_tiny/['ERR024604_tiny', 'ERR024605_tiny', 'ERR024606_tiny', 'ERR024607_tiny', 'ERR024608_tiny', 'ERR024609_tiny'].sam

I have already checked several times the correct path to the SAM files, the correctness of the files themselves, etc., but I can not understand what the problem is. This might be the easiest problem, but since I just started learning this, I need some support. Thanks!

1

There are 1 best solutions below

0
Giang Le On

Here are the input files:

.
├── Snakefile
└── sam_tiny
    ├── ERR024604_tiny.sam
    ├── ERR024605_tiny.sam
    ├── ERR024606_tiny.sam
    ├── ERR024607_tiny.sam
    ├── ERR024608_tiny.sam
    └── ERR024609_tiny.sam

For glob_wildcards you can add a comma to get the correct sample name.

In rule all, you need to change txt to bam match with what you are creating in rule sam_to_bam:

SAM_DIR = "sam_tiny"
BAM_DIR = "bam_folder"

SAM_FILES, = glob_wildcards(os.path.join(SAM_DIR, "{sample}.sam"))

rule all:
    input:
        expand(os.path.join(BAM_DIR, "{sample}.bam"), sample=SAM_FILES)

rule sam_to_bam:
    input:
        os.path.join(SAM_DIR, "{sample}.sam")
    output:
        os.path.join(BAM_DIR, "{sample}.bam")
    shell:
        """
        echo {input} > {output}
        """