繁体   English   中英

如何在snakemake中调用列表样式参数

[英]How to call a list style parameter in snakemake

我写了一些R脚本,我想使用snakemake将它们集成到分析管道中。 除了R脚本之一,我几乎完成了该管道。 在此R脚本中,参数之一是列表,如下所示:

group=list(A=c("a","b","c"),B=c("d","e"),C=c("f","g","h"))

我不知道如何在snakemake调用这种参数。

我编写的R脚本和snakemake脚本如下:

R脚本:

library(optparse)
library(ggtree)
library(ggplot2)
library(colorspace)

# help doc  

option_list=list(
    make_option("--input",type="character",help="<file> input file"),
    make_option("--output",type="character",help="<file> output file"),
    make_option("--families",type="character",help="<list> a list containing classified families"),
    make_option("--wide",type="numeric",help="<num> width of figure"),
    make_option("--high",type="numeric",help="<num> height of figure"),
    make_option("--labsize",type="numeric",help="<num> size of tip lable")
)

opt_parser=OptionParser(usage="\n\nName: cluster_vil.r",
                        description="\nDescription: This script is to virualize the result of cluster analysis.
                        \nContact: huisu<hsu@kangpusen.com>
                        \nDate: 9.5.2019",
                        option_list=option_list,
                        epilogue="Example: Rscript cluster_vil.r --input  mega_IBSout_male.nwk
                               --output NJ_IBS_male.ggtree.pdf
                               --families list(Family_A=c('3005','3021','3009','3119'),Family_B=c('W','4023'),Family_C=c('810','3003'),Family_D=c('4019','1001','4015','4021'),Family_E=c('4017','3115'))
                               --wide 18
                               --high 8
                               --labsize 7"
)

opt=parse_args(opt_parser)

input=opt$input
output=opt$output
families=opt$families
wide=opt$wide
high=opt$high
labsize=opt$labsize

# start plot

nwk=read.tree(input)

tree=groupOTU(nwk, families)

pdf(file=output,width=wide,height=high) # 18,8 for male samples; 12,18 for all samples

ggtree(tree,aes(color=group),branch.length='none') + geom_tiplab(size=labsize) +
    theme(legend.position=("left"),legend.text=element_text(size=12),legend.title=element_text(size=18),
          legend.key.width=unit(0.5,"inches"),legend.key.height=unit(0.3,"inches")) + 
    scale_color_manual(values=c("black", rainbow_hcl(length(families)))) +
    theme(plot.margin=unit(rep(2,4),'cm'))

dev.off()

做蛇

rule cluster_virual:
    input:
        nwk="mega_IBS.nwk",
    output:
        all="mega_IBS.pdf",
    params:
        fam=collections.OrderedDict([('Family_A',['3005','3021','3009','3119']),
                                     ('Family_B',['W','4023']),
                                     ('Family_C',['810','3003']),
                                     ('Family_D',["4019","1001","4015","4021"]),
                                     ('Family_E',["4017","3115"])])
    message:
        "====cluster analysis virualization===="
    shell:
        "Rscript Rfunction/cluster_vil.r " 
        "--input {input.nwk} "
        "--output {output.all} "
        "--families {params.fam} "
        "--wide 12 "
        "--high 18 "
        "--labsize 3"

所以,我想知道如何正确地在snakemake中调用write参数fam

我认为在python / snakemake中,您可以使用OrderedDict来表示R列表。 所以:

params:
    fam=list(A=c('a','b','c'),B=c('d','e'),C=c('f','g','h'))

将会:

params:
    fam= collections.OrderedDict([('A', ['a', 'b', 'c']), 
                                  ('B', ['d', 'e', 'f']),
                                  ('C', ['h', 'g'])])

当然,将import collections添加到snakemake文件的顶部(或想要导入集合模块的任何位置)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM