You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 03:51:06