- Snakemake :交换变量

我有一些基于MINIT的ONT测序运行,我想使用snakemake作为工作流管理器来通过分析来获取这些fastq文件,但是有时需要将{barcode }交换为{sample }。


BARCODE=['barcode01', 'barcode02', 'barcode03', 'barcode04']


SAMPLE=['sample01', 'sample02', 'sample03', 'sample04']



rule all:


 input:


 directory(expand("Sequencing_reads/demultiplexed/{barcode}", barcode=BARCODE)), #guppy_barcoder


 expand("Sequencing_reads/gathered/{sample}_ONT.fastq", sample=SAMPLE), #getting all of the fastq files with the same barcode assigned to the correct sample



rule demultiplex:


 input:


 glob.glob("Sequencing_reads/fastq_pass/*fastq")


 output:


 directory(expand("Sequencing_reads/demultiplexed/{barcode}", barcode=BARCODE))


 shell:


"guppy_barcoder --input_path Sequencing_reads/fastq_pass --save_path Sequencing_reads/demultiplexed -r"



rule gather:


 input:


 rules.demultiplex.output


 output:


"Sequencing_reads/gathered/{sample}_ONT.fastq"


 shell:


"cat Sequencing_reads/demultiplexed/{wildcards.barcode}/*fastq > {output.fastq}"




这给了我一个错误:

RuleException in line 32 of /home/eriny/sandbox/ONT_unicycler_pipeline/ONT_pipeline.smk: 'Wildcards' object has no attribute 'barcode'


cat Sequencing_reads/demultiplexed/barcode01/*fastq > Sequencing_reads/gathered/sample01_ONT.fastq



我希望找到一个1:1方法来将一个变量名映射到另一个变量。

时间:

例如:


BARCODE=['barcode01', 'barcode02', 'barcode03', 'barcode04']


SAMPLE=['sample01', 'sample02', 'sample03', 'sample04']



sam2bar= dict(zip(SAMPLE, BARCODE))



rule all:


 input:


 expand("Sequencing_reads/gathered/{sample}_ONT.fastq", sample=SAMPLE), #getting all of the fastq files with the same barcode assigned to the correct sample



rule demultiplex:


 input:


 glob.glob("Sequencing_reads/fastq_pass/*fastq"),


 output:


 done= touch('demux.done'), # This signals that guppy has completed


 shell:


"guppy_barcoder --input_path Sequencing_reads/fastq_pass --save_path Sequencing_reads/demultiplexed -r"



rule gather:


 input:


 done= 'demux.done',


 fastq= lambda wc: glob.glob("Sequencing_reads/demultiplexed/%s/*fastq" % sam2bar[wc.sample])


 output:


 fastq="Sequencing_reads/gathered/{sample}_ONT.fastq"


 shell:


"cat {input.fastq} > {output.fastq}"



...