My dataset: 3 different cell types, with 3 replicates each
Celltype is the factor and "Alveolarmacrophages" "Interstitialmacrophages" "Tcells" are the factor levels.
I created the DESeq object:
>dds <- DESeqDataSetFromMatrix(countData = only_counts,
colData = sample_info,
design= ~ Cell_type)
and calculated the results from the comparison of one factor level against the others:
>res <- results(dds, alpha=0.05)
So the DESeqResults object has three elements:
> resultsNames(dds)
[1] "Intercept" "Cell_type_Interstitial_macrophages_vs_Alveolar_macrophages"
[3] "Cell_type_T_cells_vs_Alveolar_macrophages"
Now I want to access ONE of these elements for further analysis. When I type 'res' I only see one of them
> res
log2 fold change (MLE): Cell type T cells vs Alveolar macrophages
Wald test p-value: Cell type T cells vs Alveolar macrophages
DataFrame with 1978 rows and 6 columns
So I would also like to access the other one, "Cell_type_Interstitial_macrophages_vs_Alveolar_macrophages"
. I have tried:
> res["Cell_type_Interstitial_macrophages_vs_Alveolar_macrophages"]
Error: subscript contains invalid names
>res[[2]] #super large vector
> res_am <- results(dds, coef=2)
Error in results(dds, coef = 2) : unused argument (coef = 2). #I find this error weird since the same is used in the DESeq vignette in the LFC example
When I do
>res_im_vs_am <- results(dds, name="Cell_type_Interstitial_macrophages_vs_Alveolar_macrophages")
this is not really accessing the element from 'res', it´s recalculating the results, all the information that I included when I did res<-results(dds,alpha=0.05)
is lost; e.g. that alpha=0.05, or any other customization I could have added.
Is there any way to directly access the elements that resultsNames(dds) shows?
Right now I only have 3 levels, but later I will add others, so it doesn't make sense to do contrast by contrast.
Is there any way to do all the possible comparisons in a single line of code and store the resulting data frames in e.g. a list?
Thanks! the last answer simplifies my question, if it's not possible then all the comparisons must be written by hand, or do this step in galaxy.
I have been doing this manually and in the end I encountered a problem, which refers to the first part of your answer. If results() does not modify dds, why resultsNames() is applied on dds and only the first results() that you used is considered? To explain myself better:
I started the results function with the first, default, level:
Then I started storing the different pairwise comparisons, after running results() every time and, additionally, doing a lfc shrinkage:
Comparisons that were included in the first results(dds):
The comparison missing:
But here I could not apply the shrinkage because this last comparison was not included in results(dds), even though I specified another results table...so isn't it in this case results() information stored in dds?
I tried to "add" the last comparison to dds by running results() without assigning it to anything, but resultsNames() did not change.
By the way, you can properly format your code by putting triple backticks around code blocks and single backticks around in-line code (e.g. objects).
Single backticks:
x
, ory
.Re: your last question, this is answered in the vignette section about lfcShrink. The apeglm shrinkage only works on comparisons that are directly in resultsNames, not on more complicated contrasts. You can either follow the workaround described in the vignette for apeglm, or you can use
type="ashr"
which can work with contrasts."why resultsNames() is applied on dds and only the first results() that you used is considered"
I don't understand the question exactly. I think you should maybe just avoid calling
results()
without specifyingname
orcontrast
, as this seems to be a point of confusion. Imagine that it's not possible to callresults()
without also adding the argumentname
orcontrast
.Thanks a lot! I just wanted to use '"apeglm"' because it's the one that it was used in a course about DESEq, so I thought it was the best. But now I will use '"ashr"' for all.