Snakemake通配符限制:如何按列表位置匹配样本对
解决Snakemake样本配对问题
原来的代码用expand时默认会生成两个列表的笛卡尔积(所有可能的组合),所以出现了4个文件。要实现同位置样本一一配对,只需要在expand里加上zip=True参数,让Snakemake按列表索引对应配对即可。
修改后的代码片段:
SAMPLE_IP = ['control_1_hif1a_hyp', 'control_2_hif1a_hyp'] SAMPLE_INPUT = ['control_1_input_hyp', 'control_2_input_hyp'] rule all: input: # 加入zip=True,让两个列表按位置一一配对 expand("bigwig/compare/{sample_ip}_vs_{sample_input}.bw", sample_ip=SAMPLE_IP, sample_input=SAMPLE_INPUT, zip=True), rule bigwig_sample_vs_input: input: ip="mapped/{sample_ip}_dedup.bam", inpt="mapped/{sample_input}_dedup.bam", output: "bigwig/compare/{sample_ip}_vs_{sample_input}.bw", ...
另一种写法:手动定义配对列表
如果觉得zip=True不够直观,也可以先把配对关系提前定义好,再传给expand:
# 提前生成(ip, input)的配对元组列表 SAMPLE_PAIRS = list(zip(SAMPLE_IP, SAMPLE_INPUT)) rule all: input: expand("bigwig/compare/{ip}_vs_{input}.bw", ip=[pair[0] for pair in SAMPLE_PAIRS], input=[pair[1] for pair in SAMPLE_PAIRS]),
两种方法都能实现只生成对应位置的配对文件,最终只会输出control_1_hif1a_hyp_vs_control_1_input_hyp.bw和control_2_hif1a_hyp_vs_control_2_input_hyp.bw这两个文件。
内容的提问来源于stack exchange,提问作者justinian482
相关产品推荐
相关产品推荐

