Snakemake:在声明中使用另一个扩展变量的值

问题描述 投票:1回答:1

有没有办法在扩展函数中使用另一个扩展变量的值?例如,如果我有以下config.yaml

patients:
  patientA:
    - "sampleA_A"
    - "sampleA_B"
    - "sampleA_C"
  patientB:
    - "sampleB_A"
    - "sampleB_B"
    - "sampleB_C"

而这个Snakefile

configfile: "config.yaml"
patient_samples = expand("{patient}_{sample}.txt", patient = "patientA", sample = config["patients"]["patientA"])
print(patient_samples)

这会产生:

['patientA_sampleA_A.txt', 'patientA_sampleA_B.txt', 'patientA_sampleA_C.txt']

但是,如果我想迭代患者并使其与样本匹配,我希望能够使用扩展患者变量的值来检索患者的样本:

configfile: "config.yaml"
PATIENTS = ["patientA", "patientB"]
patient_samples = expand("{patient}_{sample}.txt", patient = PATIENTS, sample = config["patients"][patient])
print(patient_samples)

但这不起作用,因为它产生以下错误:

NameError in line 4 of /Users/fongchan/Downloads/Snakefile:
name 'patient' is not defined
  File "/Users/fongchan/Downloads/Snakefile", line 4, in <module>

有没有办法引用扩展patient值,以便可以在config变量中使用它来获取相应的样本?

提前谢谢了,

snakemake
1个回答
0
投票

如果你完全放弃expand功能并自己构建patient_samples列表,也许会更容易。例如。就像是:

patient_samples= []
for patient in config["patients"]:
    for sample in config["patients"][patient]:
        patient_samples.append("{patient}_{sample}.txt".format(patient= patient, sample= sample))
© www.soinside.com 2019 - 2024. All rights reserved.