Hello,
I want to gather all DESeq functions in a custom function and then plan to connect with visualization part. Then will call this "DEG_analysis" function in apply function to do multiple runs in loop-like format.
This is an example of my colData design;
> colData[1:3,1:3]
X ABT737 Afatinib
1 BT-20 R R
2 CAL-120 S R
3 CAL-51 R R
> dim(colData)
[1] 17 53
I cannot make DESeqDataSetFromMatrix function to recognize "i" as a design to generate "dataset" for down-stream of DESeq2.My question is, how can I make interested column names ("i") to be recognized as a variable in design = ~i or something similar to this concept?
DEG_analysis <- function(i)
{
colData_tmp <- as.data.frame(colData %>% select("X", i))
colData_tmp[,2] <- as.factor(colData_tmp[,2])
dataset <- DESeqDataSetFromMatrix(countData = countData,colData = colData_tmp,design = ~paste0(i))
dds <- DESeq(dataset,minReplicatesForReplace = Inf)
vsd <- vst(dds,blind = F)
results_tmp <- results(dds, contrast=c(i, "R", "S"),cooksCutoff = T, independentFiltering=T, pAdjustMethod = "bonferroni", alpha = 0.05)
results_tmp <- results_tmp[order(results_tmp$padj),]
....
}
Currently, I am taking this error message:
Error in DESeqDataSet(se, design = design, ignoreRank) :
all variables in design formula must be columns in colData
Hey Michael, thanks for your reply.
Yes, I want to convert the variable of "i" which is adequate of "condition" in classic design examples to formula for many iterations. For the first iteration
i = "Afatinib"
;I have read
?formula
and tried various variety ofdesign = formula("~i")
,design = formula(~i)
,design = formula(call("~", i))
but couldn't make it to work likedesign = formula(~Afatinib)
This is a bit out of scope for the support site (how to use Bioconductor software), and I'm pretty swamped these days, it's more of an R programming question. If you continue to get stuck you might try reaching out to someone with R experience at your institute.
But just note, formula takes a string with a tilde and a variable name, you have a variable name, but it needs a tilde in front...
formula(paste("~", variable))
Thank you so much for kindly extending the scope of the forum to help me to overcome this issue on my code. Now each step is smoothly running thanks to
formula(paste("~", i))
suggestion of yours.Have a nice day Michael Sincerely, -R