Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pass user arg to DESeq2 function

I'm trying to run DESeq in an RScript using parameters input from the command line. I used optparse to parse user arguments and am trying to pass the design argument into the DESeqDataSetFromMatrix() function.

I tested the function directly and it works perfectly:

DESeq_tbl <- DESeqDataSetFromMatrix(countData=counts_tbl,
colData=coldata, design=~taxonomy)

However, if I try to pass the variable opt$design (which is a character string = "~taxonomy"), I get the following error:

DESeq_tbl <- DESeqDataSetFromMatrix(countData=counts_tbl,
colData=coldata, design=opt$design)

Error: $ operator is invalid for atomic vectors Execution halted

I've tried noquote(), various combinations of cat/paste and creating the entire command as a string to pass to the DESeqDataSetFromMatrix() function, but nothing has worked. Any advice would be greatly appreciated.

the solution

Thanks to Ben Bolker's answer below, the following worked:

DESeq_tbl <- DESeqDataSetFromMatrix(countData=counts_tbl,
colData=coldata, design=as.formula(opt$design))
like image 368
SummerEla Avatar asked Mar 05 '26 10:03

SummerEla


1 Answers

I think you need 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
like image 83
Ben Bolker Avatar answered Mar 08 '26 02:03

Ben Bolker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!