将用户参数传递给 DESeq2 函数
pass user arg to DESeq2 function
我正在尝试使用从命令行输入的参数在 RScript 中 运行 DESeq
。我使用 optparse
来解析用户参数,并试图将设计参数传递给 DESeqDataSetFromMatrix()
函数。
我直接测试了该功能,它完美运行:
DESeq_tbl <- DESeqDataSetFromMatrix(countData=counts_tbl,
colData=coldata, design=~taxonomy)
但是,如果我尝试传递变量 opt$design
(这是一个字符串 = "~taxonomy"),我会收到以下错误:
DESeq_tbl <- DESeqDataSetFromMatrix(countData=counts_tbl,
colData=coldata, design=opt$design)
Error: $ operator is invalid for atomic vectors Execution halted
我试过 noquote()
,cat
/paste
的各种组合,并将整个命令创建为字符串以传递给 DESeqDataSetFromMatrix()
函数,但没有任何效果已经工作了。任何建议将不胜感激。
解决方案
感谢 Ben Bolker 在下面的回答,以下内容有效:
DESeq_tbl <- DESeqDataSetFromMatrix(countData=counts_tbl,
colData=coldata, design=as.formula(opt$design))
我认为你需要as.formula(opt$design)
。
x <- "~taxonomy"
f <- ~taxonomy
str(f)
## Class 'formula' language ~taxonomy
## ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
identical(f,as.formula(x)) ## TRUE
我正在尝试使用从命令行输入的参数在 RScript 中 运行 DESeq
。我使用 optparse
来解析用户参数,并试图将设计参数传递给 DESeqDataSetFromMatrix()
函数。
我直接测试了该功能,它完美运行:
DESeq_tbl <- DESeqDataSetFromMatrix(countData=counts_tbl,
colData=coldata, design=~taxonomy)
但是,如果我尝试传递变量 opt$design
(这是一个字符串 = "~taxonomy"),我会收到以下错误:
DESeq_tbl <- DESeqDataSetFromMatrix(countData=counts_tbl,
colData=coldata, design=opt$design)
Error: $ operator is invalid for atomic vectors Execution halted
我试过 noquote()
,cat
/paste
的各种组合,并将整个命令创建为字符串以传递给 DESeqDataSetFromMatrix()
函数,但没有任何效果已经工作了。任何建议将不胜感激。
解决方案
感谢 Ben Bolker 在下面的回答,以下内容有效:
DESeq_tbl <- DESeqDataSetFromMatrix(countData=counts_tbl,
colData=coldata, design=as.formula(opt$design))
我认为你需要as.formula(opt$design)
。
x <- "~taxonomy"
f <- ~taxonomy
str(f)
## Class 'formula' language ~taxonomy
## ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
identical(f,as.formula(x)) ## TRUE