Issue with renaming genes in expression matrix for heatmap in R
0
0
Entering edit mode
3 days ago
Kelly • 0

I am trying to rename some genes in my expression matrix before plotting a heatmap using pheatmap in R. My original list of genes (genes_de_interesse) contains:

"ABCA11P", "TAP1", "TAP2", ...

I want to rename them as follows:

ABCA11P =ABCA11

TAP1 = ABCB2

TAP2 = ABCB3

So I applied the recode() function on the row names of the filtered expression matrix:

genes_de_interesse_renomeados <- recode(genes_de_interesse, "ABCA11P" = "ABCA11", "TAP1" = "ABCB2", "TAP2" = "ABCB3")

Then I filtered the expression matrix:

expr_matrix_filtered <- expr_matrix[rownames(expr_matrix) %in% genes_de_interesse_renomeados, ] %>% mutate(across(everything(), as.numeric))

And later selected columns for the heatmap using the renamed list:

heatmap_data <- final_data %>%
select(any_of(genes_de_interesse_renomeados)) %>% as.matrix()

Problem: If I use the original names (TAP1 and TAP2), the genes appear correctly in the heatmap. However, after renaming them to ABCB2 and ABCB3, they do not appear. Similarly, ABCA11 does not show up when replacing ABCA11P.

The renaming with recode() does not affect the subsetting step that uses genes_de_interesse. After filtering, the row names are still matched against the original names ("TAP1", "TAP2", "ABCA11P"), not the renamed ones ("ABCB2", "ABCB3", "ABCA11"). As a result, the heatmap never sees the renamed genes because they were not selected from the original matrix.

Question:

What is the correct way to rename genes in a matrix and make sure the renamed genes are included in the heatmap? Any help or example code would be greatly appreciated.

hetmap • 2.8k views
ADD COMMENT
0
Entering edit mode
dput(head(your_df))

Please do this, which would be helpful or just subset those problematic rows containing those genes, so that other people can troubleshoot and help

ADD REPLY
0
Entering edit mode

Are you sure that command with recode is working?

ADD REPLY
0
Entering edit mode

Maybe I'm missing something, it seems your recode function is switching values in a vector and then you later try to subset based on the new values, but never change the rownames themselves.

Perhaps something like this may work:

names_to_change <- c('ABCA11P', 'TAP1', 'TAP2')
new_names <-  c('ABCA11', 'ABCB2', 'ABCB3')

expr_mat_rename <- expr_matrix
rownames(expr_mat_rename[names_to_change,]) <- new_names 

Alternatively, you may use your recode command, but perhaps like this (although I haven't tried this way).

genes_de_interesse_renomeados <- recode(rownames(expr_matrix), "ABCA11P" = "ABCA11", "TAP1" = "ABCB2", "TAP2" = "ABCB3")
rownames(expr_matrix) <- genes_de_interesse_renomeados
ADD REPLY

Login before adding your answer.

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