RStudio Pheatmap: sort DEG by logFC
Hi Guys,
I'm very new to R and bioinformatics and I hope my question isnt that stupid... I'm trying to make a Heatmap with 200 DEGs from an RNA_Seq_Dataset. In my script (which I got from another PhD candidate) I've got the following code:
topVarianceGenes <- head(order(rowVars(assay(rld)), decreasing=T),200)
matrix <- assay(rld)[topVarianceGenes,]
matrix <- matrix - rowMeans(matrix)
annotation_data <- as.data.frame(colData(rld))
pheatmap(matrix, scale = 'row',
show_rownames = T,
color = bluered(100),
fontsize = 8,
annotation_col = annotation_data[1],
cluster_cols = F) `
It works quite well, but I'm told to use the Top Genes sort by logFC and I don't find anything using google or the search function in thi forum.
Thanks to anyone who could help! :)
• 3,182 views
•
link
1 answer
Hi,
I also think, you use DESeq2. So if thats true, you could do something like this:
For the L2FC you need the call the result function first. With the abs function, you calculate the L2FC without + or -. So you then can sort by highest absolute L2FC value.
res_data <- results(ds_txi,contrast=c("treatment","Drug","Control"))
res_data$abs_L2FC <- abs(res_data$L2FC)
mat <- assay(rld)[head(order(res_data$abs_L2FC, decreasing=T),200), ]
mat <- mat - rowMeans(mat)
df <- as.data.frame(colData(vsd)[, c("treatment")])
rownames(df) <- colnames(mat)
pheatmap(mat, annotation_col = df, cluster_rows = F , show_colnames = F )
• 0 views
•
link
Log in to answer this question.
Hi,
Can you post the code that you've used before and print the first few lines of your data?
For instance I don't know how it looks your data, so I don't know that column names, and so on. I believe that you've used
DESeq2for DEG, but it's not clear to me.António
From the code, it seems earlier dev used DESeq2 analysis. Please follow the manual of DEseq2 here: http://bioconductor.org/packages/devel/bioc/vignettes/DESeq2/inst/doc/DESeq2.html#heatmap-of-the-count-matrix
Hi,
Thank you very much, I just had to change a few things and it worked :)
Please make a note of things you changed and perhaps post that as a new answer. This comment does not help future visitors. If @caggtaagtat's answer helped you solve the problem please upvote/accept that answer.