1 回答
TA贡献1786条经验 获得超12个赞
glob_wildcards我将使用一个简单的 python 字典来定义附加到 fastq 文件的示例名称,而不是使用:
import os
import re
d = dict()
fastqPath = "."
for fastqF in [f for f in os.listdir(fastqPath) if(re.match(r"^[\w-]+_R1_001\.fastq\.gz", f))]:
s = re.search(r"(^[\w-]+)_(S\d+)_R1_(001.fastq.gz)", fastqF)
samplename = s.group(1)
fastqFfile = os.path.join(fastqPath, fastqF)
fastqRfile = os.path.join(fastqPath, s.group(1) + "_" + s.group(2) + "_R2_" + s.group(3))
if(os.path.isfile(fastqRfile)):
d[samplename] = {"read1":os.path.abspath(fastqFfile),"read2":os.path.abspath(fastqRfile)}
fastq 输入文件非常易于使用:
rule all:
input:
expand("output/trimmed/{sample}_R1_trim_PE.fastq",sample=d)
rule trim:
input:
R1 = lambda wildcards: d[wildcards.sample]["read1"],
R2 = lambda wildcards: d[wildcards.sample]["read2"]
output:
R1_Pair="output/trimmed/{sample}_R1_trim_PE.fastq",
R1_Sing="output/trimmed/{sample}_R1_trim_SE.fastq",
R2_Pair="output/trimmed/{sample}_R2_trim_PE.fastq",
R2_Sing="output/trimmed/{sample}_R2_trim_SE.fastq"
resources:
cpus=8
log:
"../logs/trim_{sample}.log"
conda:
"envs/trim.yaml"
shell:
"""
trimmomatic PE -trimlog {log} -threads {resources.cpus} {input.R1} {input.R2} {output.R1_Pair} {output.R1_Sing} {output.R2_Pair} {output.R2_Sing} HEADCROP:10 I>
"""
注意:我删除了params您的规则中未使用的部分trim。
添加回答
举报