1
$\begingroup$

I have created a DESeq object (dds) and now I want to access the results and apply the lfc shrinkage on them.

res <- results(dds, alpha=0.05)
resultsNames(dds) 
[1] "Intercept"                                                  "Cell_type_Interstitial_macrophages_vs_Alveolar_macrophages"
[3] "Cell_type_T_cells_vs_Alveolar_macrophages"

Here we see all the coefficients I got from the results function. Now I try to use the lfcShrink() function on the second coefficient:

res_im_vs_am <- lfcShrink(dds, coef=2, res=res, type="apeglm")
Error in lfcShrink(dds, coef = 2, res = res, type = "apeglm") : 
  'coef' should specify same coefficient as in results 'res'

it doesn't work, so I try with the name directly copy-pasted from the above code:

res_im_vs_am <- lfcShrink(dds, coef = "Cell_type_Interstitial_macrophages_vs_Alveolar_macrophages", res=res, type="apeglm")
Error in lfcShrink(dds, coef = "Cell_type_Interstitial_macrophages_vs_Alveolar_macrophages",  : 
  'coef' should specify same coefficient as in results 'res'    

Same error. According to the ?lfcShrink for coef: the name or number of the coefficient (LFC) to shrink, consult resultsNames(dds) after running DESeq(dds).

So I do not understand why it is not working. Anyone can help?

$\endgroup$
0
1
$\begingroup$

We use an example dataset:

library(DESeq2)
mat = matrix(rnbinom(9000,mu=100,size=1),ncol=9)
rownames(mat) = paste0("gene",1:1000)
grps = rep(c("A","B","C"),each=3)

dds = DESeqDataSetFromMatrix(mat,data.frame(grps),~grps)
dds = DESeq(dds)

resultsNames(dds) 
[1] "Intercept"   "grps_B_vs_A" "grps_C_vs_A"

When you call results, by default it takes the last coefficient, in this example is C vs A:

res <- results(dds, alpha=0.05)

log2 fold change (MLE): grps C vs A 
Wald test p-value: grps C vs A 
DataFrame with 6 rows and 6 columns
              baseMean     log2FoldChange             lfcSE               stat
             <numeric>          <numeric>         <numeric>          <numeric>
gene1 74.3974631643997 -0.439258650876538  1.22842645044656 -0.357578307367818
gene2 99.4576039995999    1.2903547180366  1.12500005531808   1.14698191518912
gene3 87.1593850381565  -3.11763876685787  1.19848628038255  -2.60131368868297
gene4   51.47821785473  -2.16622171024749 0.953571440023498  -2.27169315200349
gene5 62.4630151830988   1.05879388186169  1.31999477669387  0.802119751195993
gene6 111.967714581788  -1.23916751032406  1.17612862134365  -1.05359863524824

If you want to look at the second comparison:

res <- results(dds, alpha=0.05,name="grps_B_vs_A")
res_lfc <- lfcShrink(dds, coef=2, res=res, type="apeglm")

log2 fold change (MAP): grps B vs A 
Wald test p-value: grps B vs A 
DataFrame with 6 rows and 5 columns
              baseMean      log2FoldChange             lfcSE            pvalue
             <numeric>           <numeric>         <numeric>         <numeric>
gene1 74.3974631643997 0.00143892076074213 0.275057978370776 0.987946388824352
gene2 99.4576039995999  -0.031292774512063 0.276439771853046 0.632995722892249
gene3 87.1593850381565 0.00806769808245902 0.274672487627629                NA
gene4   51.47821785473 -0.0394804572502463 0.274244572145665 0.609999235800452
gene5 62.4630151830988   0.065875708916621 0.288411208595865 0.234448669110134
gene6 111.967714581788 -0.0871847461207727 0.295733383995144 0.153081913500716

or simply:

res_lfc <- lfcShrink(dds, coef=2, type="apeglm")
$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy