I am having trouble fixing a problem I have in snakemake. My samples are currently named something like "1-2-Brain_187_006_S77_L002_R1_001.fastq.gz". I want to eventually rename them to a shorter name like "1_2_Brain_S77_L002_R1" and then with the extension "_trim.fastq.gz" for my rule. I am trimming using bbduk. For my input I want to call my list of dictionaries, allSamples. Then I want to access values from each dictionary. Specifically, the "shortName1" and "shortName2" values. My problem is in my dry it shows the entire list as input for a single run. I'm not sure how to make it register that each element is it's own run. I am showing 3 file names as an example when I actually have 114. So, I would expect my dry run to have 114 counts for the trim job.
config.json
{
"allSamples" : ['1_2_Brain_S77_L002', '10_4_Kidney_S82_L002', '11_4_BB_S105_L002' ......],
"1_2_Brain_S77_L002":{
"sampleName1": "1-2-Brain_187_006_S77_L002_R1_001.fastq.gz",
"sampleName2": "1-2-Brain_187_006_S77_L002_R2_001.fastq.gz",
"shortName1": "1_2_Brain_S77_L002_R1",
"shortName2": "1_2_Brain_S77_L002_R2",
"stemName": "1_2_Brain_S77_L002"
}, ....
}
I'm taking my files located in rawReads/ and storing the new trimmed files in trimmedReads/ .
Snakefile
configfile: "refs/config.json"
# variables
sampleDict = config["allSamples"]
sampleNames1 = [config[i]["sampleName1"] for i in sampleDict]
sampleNames2 = [config[i]["sampleName2"] for i in sampleDict]
shortNames1 = [config[i]["shortName1"] for i in sampleDict]
shortNames2 = [config[i]["shortName2"] for i in sampleDict]
rule all:
input:
expand("trimmedReads/{trim1}_trim.fastq.gz", trim1 = shortNames1),
expand("trimmedReads/{trim2}_trim.fastq.gz", trim2 = shortNames2)
rule trim:
input:
R1 = expand("rawReads/{sample1}", sample1 = sampleNames1),
R2 = expand("rawReads/{sample2}", sample2 = sampleNames2)
output:
trim1 = expand("trimmedReads/{trim1}_trim.fastq.gz", trim1 = shortNames1),
trim2 = expand("trimmedReads/{trim2}_trim.fastq.gz", trim2 = shortNames2)
shell:
"""
bbduk.sh in1={input.R1} in2={input.R2} out1={output.trim1} out2={output.trim2} ref=ref/adapters.fa ktrim=r k=23 mink=11 hdist=1 tpe tbo
"""
When I do a dry run I get this.
Building DAG of jobs...
Job counts:
count jobs
1 all
1 trim
2
[Mon May 24 22:42:36 2021]
rule trim:
input: rawReads/1-2-Brain_187_006_S77_L002_R1_001.fastq.gz, rawReads/10-4-Kidney_127_066_S82_L002_R1_001.fastq.gz, rawReads/11-4_BB_041_152_S105_L002_R1_001.fastq.gz, ...
output: trimmedReads/1_2_Brain_S77_L002_R1_trim.fastq.gz, trimmedReads/10_4_Kidney_S82_L002_R1_trim.fastq.gz, trimmedReads/11_4_BB_S105_L002_R1_trim.fastq.gz, ...
jobid: 1
bbduk.sh in1=rawReads/1-2-Brain_187_006_S77_L002_R1_001.fastq.gz rawReads/10-4-Kidney_127_066_S82_L002_R1_001.fastq.gz rawReads/11-4_BB_041_152_S105_L002_R1_001.fastq.gz ... out1=trimmedReads/1_2_Brain_S77_L002_R1_trim.fastq.gz trimmedReads/10_4_Kidney_S82_L002_R1_trim.fastq.gz trimmedReads/11_4_BB_S105_L002_R1_trim.fastq.gz ... ref=ref/adapters.fa ktrim=r k=23 mink=11 hdist=1 tpe tbo
[Mon May 24 22:42:36 2021]
localrule all:
input: trimmedReads/1_2_Brain_S77_L002_R1_trim.fastq.gz, trimmedReads/10_4_Kidney_S82_L002_R1_trim.fastq.gz, trimmedReads/11_4_BB_S105_L002_R1_trim.fastq.gz, ...
jobid: 0
Job counts:
count jobs
1 all
1 trim
2
This was a dry-run (flag -n). The order of jobs does not reflect the order of execution.