I'm a newbie at snakemake. I'm trying to implement the GATK FastqToSam in a rule.
I have the following and it works if I hard code the samplename into the shell part but I was wanting to get the samplename from the config file. I tried using the params option like so:
configfile: "config.yaml"
fc = config["flowcell"]
index = config["index"]
samplename = config["sn"]
lane=["L01","L02","L03","L04"]
rule all:
input:
expand(["result/gatk4/{fc}_{lane}_{index}_fastqtosam.bam"], fc = fc, lane = lane, index = index)
rule fastqToSam:
input:
trimmed1 = "result/trimming/{fc}_{lane}_{index}_1_500k_trimmed.fq.gz",
trimmed2 = "result/trimming/{fc}_{lane}_{index}_2_500k_trimmed.fq.gz"
output:
output="result/gatk4/{fc}_{lane}_{index}_fastqtosam.bam"
log:
"result/logs/fastqtosam/{fc}_{lane}_{index}.out"
benchmark:
"result/benchmarks/{fc}_{lane}_{index}.out"
container:
config["containers"]["gatk4"]
params:
RG="{fc}_{lane}",
sn="{samplename}"
threads: 8
shell:
"""
gatk --java-options "-Xmx8G" FastqToSam
FASTQ={input.trimmed1}
FASTQ2={input.trimmed2}
OUTPUT={output.output}
QUALITY_FORMAT=Standard
READ_GROUP_NAME={params.RG}
SAMPLE_NAME={params.sn}
LIBRARY_NAME=PCRFree
PLATFORM=MGI
SEQUENCING_CENTER=CG 2>{log}
"""
But I get the error:
WildcardError in line ** of snakefile:
Wildcards in params cannot be determined from output files. Note that you have to use a function to deactivate automatic wildcard expansion in params strings, e.g., `lambda wildcards: '{test}'`. Also see https://snakemake.readthedocs.io/en/stable/snakefiles/rules.html#non-file-parameters-for-rules:
'samplename'
Is there a way of getting the samplename from the config file and using it in the shell part of the snakemake rule?
thanks hugo.avila I don't think I can accept your answer as it's a comment? Much appreciated!
Moved to answer. You can accept.
Your welcome ;)
No worries, sometimes the mods add comments as an accepted answer if they see that the problem was soved. I thought that maybe i have gotten you question wrong so i submitted my answer as a comment, my bad.