Custom Functional for automated DESeq2 running
2
0
Entering edit mode
rekren ▴ 20
@rekren-23392
Last seen 3.8 years 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)
      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
deseq2 • 1.2k views
ADD COMMENT
2
Entering edit mode
@mikelove
Last seen 16 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")

ADD COMMENT
0
Entering edit mode

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

ADD REPLY
2
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))

ADD REPLY
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

ADD REPLY
0
Entering edit mode
swbarnes2 ★ 1.3k
@swbarnes2-14086
Last seen 8 hours 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.

ADD COMMENT

Login before adding your answer.

Traffic: 1098 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6