Hi all,
I'm quite new to using DESeq2 and was hoping for some guidance. I appreciate my question might be very basic - apologies for this.
I have an experimental set of six groups (24 samples in total, n = 4) and am looking at creating different comparisons. I've read the DESeq2 vignette and have made my contrast like so:
dds <- DESeqDataSetFromTximport(Txi_gene, colData=sample_file, design=~group)
dds <- DESeq(dds)
dds$group <- factor(paste0(dds$condition, dds$time))
design(dds) <- ~ group
res1 <- results(dds, contrast=c("group","A_day14","B_day14"))
res2 <- results(dds, contrast=c("group","A_day14","A_day0"))
*etc.*
This all seems to be looking as expected. My next question is about visualizing the differentially expressed genes: if I'm looking at comparison A vs B, how can I extract just those DEGs rather than the genes in general?
This is my code chunk so far:
normalized_counts <- counts(dds, normalized=TRUE)
normalized_counts <- normalized_counts %>%
data.frame(check.names=FALSE) %>%
rownames_to_column(var="gene") %>%
as_tibble()
top50_sigRes1_genes <- res1_lfcshrink_tb %>%
arrange(padj) %>%
pull(gene) %>%
head(n=50)
top50_sigRes1_norm <- normalized_counts %>%
dplyr::filter(gene %in% top50_sigRes1_genes)
gathered_top50_sigRes1 <- top50_sigRes1_norm %>%
gather(colnames(top50_sigRes1_norm)[2:25], key = "samplename", value = "normalized_counts")
My hunch is that I need to change the [2:25] to reflect only the columns I'm interested in per comparison? So if I look at A vs B, I only select those columns and disregard C, D, etc. However, when I try that I get the error ! incorrect number of dimensions
.
So for visualization:
gathered_top50_sigRes1_joined <- inner_join(meta_data, gathered_top50_sigRes1)
ggplot(gathered_top50_sigRes1_joined) +
geom_point(aes(x = gene, y = normalized_counts, color = group)) +
scale_y_log10() +
xlab("Genes") +
ylab("log10 Normalized Counts") +
ggtitle("Top 50 Significant DE Genes - A day 14 vs B day 14") +
theme_bw() +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
theme(plot.title = element_text(hjust = 0.5))
This gives me a nice plot, but all my samples are included in it so it's not specific to the comparison I'm looking at.
I hope my question makes sense and thank you in advance for taking the time to help me!
Can you share the line of code that fails for this?
Hi Friederike, thanks for your reply! Please see the code:
So here I've indicated columns 3,5,7,11 because those are the samples I'm interested in. This gives me the following error:
This is what my
top50_sigRes1_norm
looks like:colnames(top50_sigRes1_norm)[2:3,5,7,11]
needs to becolnames(top50_sigRes1_norm)[c(2:3,5,7,11)]
Thanks Frederieke. It seems to be the right direction, however, now my
gathered_top50_sigRes1
output includes everything except those columns I specified?Edit: in the downstream code this seems to have achieved exactly what I wanted! Thank you!