Snakemake Wildcard Issue: Trouble Passing Config Field to Rule Input
0
0
Entering edit mode
9 months ago
blackadder ▴ 30

Hello there!

I need your help with something...

I am trying to execute a rule in snakemake by passing a field from the config file to my rule input and, so far, i fail miserably.

My config file has the following:

input: "/hpc/data/raw/R0038/*.fq"

test: "R0038"

My Snakefile:

configfile: "config.yaml"

include: "rules/short_reads.smk"

path_short_reads=config["input"]
sample_id = config["test"]

short_reads=set()

for read in glob.glob(path_short_reads):
    short_reads.add(re.split("_R[0-9].fq", os.path.basename(read))[0])

rule all:
    input:
            expand("results/metaphlan/{sreads}/{sreads}.bowtie2.bz", sreads=short_reads),
            expand("results/metaphlan/{sreads}/{sreads}_profile.txt", sreads=short_reads),
            expand("results/metaphlan/{sreads}/{sreads}_profile_species.txt", sreads=short_reads)

My rule file:

rule metaphlan_short_paired_reads:
    """
    Profiling the composition of microbial communities from raw paired reads
    """
    input:
            read_1="/hpc/data/raw/{config[test]}/{sreads}_R1.fq",
            read_2="/hpc/data/raw/{config[test]}/{sreads}_R2.fq"
    output:
            bowtie2="results/metaphlan/{sreads}/{sreads}.bowtie2.bz",
            profile="results/metaphlan/{sreads}/{sreads}_profile.txt",
            final="results/metaphlan/{sreads}/{sreads}_profile_species.txt"
    params:
            type="fastq",
            db="/metaphlan/"
    shell:
            """
            metaphlan {input.read_1},{input.read_2} --bowtie2db {params.db} --bowtie2out {output.bowtie2} --unclassified_estimation --nproc 8 --input_type {params.ty>
            grep s__ {output.profile} | grep -v t__ | cut -f1,3 | sed "s/.*|//g" > {output.final}
            """

What i have tried so far without success in my input:

expand("/hpc/data/raw/{config[test]}/{sreads}_R{read}.fq", sreads=config[test], read=["1", "2"])

also

read_1="/hpc/data/raw/{config[test]}/{wildcards.sreads}_R1.fq",

read_2="/hpc/data/raw/{config[test]}/{wildcards.sreads}_R2.fq"

I also tried to pass it as python variable with sample_id

read_1="/hpc/data/raw/{sample_id}/{wildcards.sreads}_R1.fq",

read_2="/hpc/data/raw/{sample_id}/{wildcards.sreads}_R2.fq"

So far none of my attempts have worked! Any ideas on how to pass the sample filed in my config on my rule?

Thank you!

Python Snakemake • 401 views
ADD COMMENT
0
Entering edit mode

What happens if you specify read_1and read_2outside of a rule, for instance like this: READ_1="/hpc/data/raw/" + config[test] + "/{sreads}_R1.fq"

and then use in rule metaphlan_short_paired_reads this:

input:
    read_1 = READ_1,
    read_2 = READ_2
`
ADD REPLY
0
Entering edit mode

Hello,

It gives me the following error:

name 'READ_1' is not defined

But when i print (READ_1) i get :

/hpc/data/raw/R0038/{sreads}_R1.fq
ADD REPLY

Login before adding your answer.

Traffic: 1739 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6