Custom Functional for automated DESeq2 running
2
0
Entering edit mode
rekren ▴ 10
@rekren-23392
Last seen 13 months ago

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)
....
}


Currently, I am taking this error message:

Error in DESeqDataSet(se, design = design, ignoreRank) :
all variables in design formula must be columns in colData

deseq2 • 168 views
1
Entering edit mode
@mikelove
Last seen 20 hours ago
United States

If I'm reading correctly, you want to convert a string to a formula to pass as an argument to design? See ?formula. E.g. formula("~x")

0
Entering edit mode

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 of design = formula("~i"), design = formula(~i) , design = formula(call("~", i)) but couldn't make it to work like design = formula(~Afatinib)

1
Entering edit mode

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))

0
Entering edit mode

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

0
Entering edit mode
swbarnes2 ▴ 800
@swbarnes2-14086
Last seen 1 day ago
San Diego

What you are asking is probably too much to cram into one function.

Start with one function into which you give an object, a design, and a list of (contrast, factor1, factor2, comparisonName) for all the comparisons you want. This way, you only do DESeq one for multiple comparisons, and you can do more complicated designs than just the column header.

Once you have that, you can work on automating the process that generates that input.