0

I have made a heatmap based on following script.

#load the library
library(pheatmap)

#set label font
par(cex.lab=1.5) # is for y-axis
par(cex.axis=1.5) # is for x-axis

#Set the working directory
setwd("F:\\User\\OneDrive\\data\\final\\Rcode")


#hedge
#read the expression matrix
hedge <- read.table("hedge.txt",sep="\t",header = TRUE)

#Group the data in the frame
group_df = data.frame(Groups=rep(c("AP","CP","BP"),c(6,42,28)))

#Assign the col name to the matrix
rownames(group_df) = colnames(hedge)[2:ncol(hedge)]

#Assign the rownames
rownames(hedge) = hedge[,1]

#plot the heatmap with specific split
pheatmap(hedge[,-1],cluster_cols=FALSE,
         annotation_col=group_df, gaps_col = cumsum(c(6,42,28)))

I got following heatmap from the code:enter image description here

Now I want to extract and replot a subplot from the main heatmap using gene set of my interest (CD34, CD117, CD38, SHH, GLI1, GLI2, GLI3, BCL2, PTCH1, PTCH2, SMO). How can I do this?

2 Answers2

0

This should work:

pheatmap(hedge[which(hedge[,1]==c("CD34" , "CD117" , "CD38" , "SHH" ,
"GLI1" , "GLI2" , "GLI3" , "BCL2" , "PTCH1" , "PTCH2" , "SMO")),-1],
cluster_cols=FALSE, annotation_col=group_df, gaps_col =cumsum(c(6,42,28))) 

Here, you take the rows having those gene names in their first column and plot it.

EDIT: Removed first column.

phago29
  • 142
  • 1
  • 9
0

You can do something like this, define the genes of interest:

genes_of_interest = c("CD34","CD117","CD38","SHH",
"GLI1","GLI2","GLI3","BCL2","PTCH1","PTCH2","SMO")

If some of them are not in the matrix, do:

pheatmap(hedge[rownames(hedge) %in% genes_of_interest,-1],cluster_cols=FALSE,
         annotation_col=group_df, gaps_col = cumsum(c(6,42,28)))

If you are sure all of them are in there:

pheatmap(hedge[genes_of_interest,-1],cluster_cols=FALSE,
         annotation_col=group_df, gaps_col = cumsum(c(6,42,28)))

The rows will be clustered again so if you don't want that, you need to turn the cluster_rows to FALSE.

StupidWolf
  • 45,075
  • 17
  • 40
  • 72