4

我想要一个规则来执行正常和肿瘤之间的重新排列。主要问题是我不知道如何解决这个问题。是通配符还是扩展我的问题的答案?

这是我的样品清单:

conditions:
   pair1:
        tumor: "432"
        normal: "433"

所以规则需要是这样的

rule gatk_RealignerTargetCreator:
    input:
        expand("mapped_reads/merged_samples/{sample}.sorted.dup.reca.bam",sample=config['conditions']['pair1']['tumor']),
        "mapped_reads/merged_samples/{sample}.sorted.dup.reca.bam",sample=config['conditions']['pair1']['normal']),

    output:
        "mapped_reads/merged_samples/{pair1}.realign.intervals"

如何在条件下对所有键执行此操作?(我想有更多的一对)

我试过这段代码:

    input:
        lambda wildcards: config["conditions"][wildcards.condition],
        tumor= expand("mapped_reads/merged_samples/{tumor}.sorted.dup.reca.bam",tumor=config['conditions'][wildcards.condition]['tumor']),
        normal = expand("mapped_reads/merged_samples/{normal}.sorted.dup.reca.bam",normal=config['conditions'][wildcards.condition]['normal']),

    output:
        "mapped_reads/merged_samples/{tumor}/{tumor}_{normal}.realign.intervals"

名称“通配符”未定义

??

4

2 回答 2

6

wildcards不是在规则的输入中“直接”定义的。你需要使用一个函数来wildcards代替。我不确定我是否完全理解您想要做什么,但您可以尝试类似的方法。

def condition2tumorsamples(wildcards):
    return expand(
        "mapped_reads/merged_samples/{sample}.sorted.dup.reca.bam",
        sample=config['conditions'][wildcards.condition]['tumor'])

def condition2normalsamples(wildcards):
    return expand(
        "mapped_reads/merged_samples/{sample}.sorted.dup.reca.bam",
        sample=config['conditions'][wildcards.condition]['normal'])

rule gatk_RealignerTargetCreator:
    input:
        tumor = condition2tumorsamples,
        normal = condition2normalsamples,    
    output:
        "mapped_reads/merged_samples/{condition}.realign.intervals"
    # remainder of the rule here...
于 2017-08-09T09:35:44.507 回答
0

免责声明:您想从 YAML 文件中读取配对,但是,我建议您不要这样做。我不知道如何使用 YAML 格式优雅地做到这一点。我有一种特殊的方式来配对我的 SNP 和 INDEL 注释,但是,有很多样板代码只是这样它就可以从 YAML 中编写出来。这没关系,因为 YAML 变量可能永远不会被编辑,因此在这种情况下,维护一个迂腐格式化的字符串不再重要。

我认为您尝试的代码是正确的。我认为缺少的是在“全部规则”输入中“请求”正确配对的能力。我个人更喜欢使用Pandas来做到这一点。它列在Python Software Foundation的主页上,因此它是一个可靠的选择。

pandas 设置非常易于维护,它是单个文件选项卡或空格分隔。最终用户比格式化嵌套 YAML 文件更容易(如果通过 YAML 格式设置,我认为需要这样做)。这就是我在我的系统中的做法。它无限扩展。我承认访问 pandas 对象有点棘手,但我已经为您提供了代码。只知道第一层对象('sample[1][tumor]' 调用中的 [#]),我认为 [0] 只是正在读取的文件上的元数据。我还没有找到它的用途,否则就忽略它。

工作区的树形结构

(CentOS5-Compatible) [tboyarski@login3 Test]$ tree
.
|-- [tboyarsk       620 Aug  4 10:57]  Snakefile
|-- [tboyarsk        47 Aug  4 10:52]  config.yaml
|-- [tboyarsk       512 Aug  4 10:57]  output
|   |-- [tboyarsk         0 Aug  4 10:54]  ABC.bam
|   |-- [tboyarsk         0 Aug  4 10:53]  TimNorm.bam
|   |-- [tboyarsk         0 Aug  4 10:53]  TimTum.bam
|   `-- [tboyarsk         0 Aug  4 10:57]  XYZ.bam
`-- [tboyarsk        36 Aug  4 10:49]  sampleFILEpair.txt

sampleFILEpair.txt(证明样本名称可以不相关)

tumor normal
TimTum TimNorm
XYZ ABC

配置.yaml

pathDIR: output
sampleFILE: sampleFILEpair.txt

蛇文件

 from pandas import read_table

 configfile: "config.yaml"

 rule all:
     input:
         expand("{pathDIR}/{sample[1][tumor]}_{sample[1][normal]}.bam", pathDIR=config["pathDIR"], sample=read_table(config["sampleFILE"], " ").iterrows())


 rule gatk_RealignerTargetCreator:
     input:
         "{pathGRTC}/{normal}.bam",
         "{pathGRTC}/{tumor}.bam",
     output:
         "{pathGRTC}/{tumor}_{normal}.bam"
 #    wildcard_constraints:
 #        tumor = '[^_|-|\/][0-9a-zA-Z]*',
 #        normal = '[^_|-|\/][0-9a-zA-Z]*'
     run:
         call('touch ' + str(wildcard.tumor) + '_' + str(wildcard.normal) + '.bam', shell=True)

过去,随着通配符的合并,我发现它是循环依赖的来源,所以我在合并时也总是包含 wildcard_constraints(本质上这就是我们正在做的)。它们在这里实际上不是必需的。“规则全部”不包含通配符,它​​调用“gatk”,所以在这个确切的例子中没有歧义的余地,但如果这个规则与使用通配符的其他规则连接,通常它可以生成一些时髦的 DAG。

于 2017-08-04T18:12:53.103 回答