RStudio Pheatmap: sort DEG by logFC
1
0
Entering edit mode
4.4 years ago

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! :)

RNA-Seq R • 2.5k views
ADD COMMENT
0
Entering edit mode

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 DESeq2 for DEG, but it's not clear to me.

António

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

Hi,

Thank you very much, I just had to change a few things and it worked :)

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode
4.4 years ago
caggtaagtat ★ 1.9k

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 )
ADD COMMENT

Login before adding your answer.

Traffic: 1831 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