Converting mouse Ensembl ID's to gene names in a data frame

I have recently produced an unsupervised hierarchical cluster heat map using 30 different RNA-seq samples. The x axis is labelled as the name of each sample, and the y axis displays the 100 most variable genes presented as mouse Ensembl ID's (e.g. ENSMUSG00000020573).

I was just wondering if there was a way for me to replace the Ensembl ID's with gene names (e.g. Pik3cg) before I input it into the pheatmap() function.

My input table is:

                        WT_Animal1      WT_Animal2     WT_Animal3
ENSMUSG00000094652      0.03463869       0.7333992     -0.29986091
ENSMUSG00000006356     -0.64264559      -0.5609578     -0.06037522
ENSMUSG00000019897      0.09159506      -0.1133322     -0.12974861
ENSMUSG00000027790     -0.25124228       1.2871582     -0.92491260
ENSMUSG00000054999     -0.58618795       1.2079283     -0.89929279
ENSMUSG00000072573      0.16812802       0.1058453     -0.16593449 

I changed the column names manually using colnames(mat) <- c() but I want to know how to change the row names (Ensembl ID's) using a different function so I can reproduce it in further plots.

I have tried to read up on using biomaRt and other packages but can't seem to work out a way to do it.

Any help would be much appreciated!

You can access row names this way

rownames(mtcars)
#>  [1] "Mazda RX4"           "Mazda RX4 Wag"       "Datsun 710"         
#>  [4] "Hornet 4 Drive"      "Hornet Sportabout"   "Valiant"            
#>  [7] "Duster 360"          "Merc 240D"           "Merc 230"           
#> [10] "Merc 280"            "Merc 280C"           "Merc 450SE"         
#> [13] "Merc 450SL"          "Merc 450SLC"         "Cadillac Fleetwood" 
#> [16] "Lincoln Continental" "Chrysler Imperial"   "Fiat 128"           
#> [19] "Honda Civic"         "Toyota Corolla"      "Toyota Corona"      
#> [22] "Dodge Challenger"    "AMC Javelin"         "Camaro Z28"         
#> [25] "Pontiac Firebird"    "Fiat X1-9"           "Porsche 914-2"      
#> [28] "Lotus Europa"        "Ford Pantera L"      "Ferrari Dino"       
#> [31] "Maserati Bora"       "Volvo 142E"

# you can change them
rownames(mtcars) <- toupper(rownames(mtcars))
rownames(mtcars)
#>  [1] "MAZDA RX4"           "MAZDA RX4 WAG"       "DATSUN 710"         
#>  [4] "HORNET 4 DRIVE"      "HORNET SPORTABOUT"   "VALIANT"            
#>  [7] "DUSTER 360"          "MERC 240D"           "MERC 230"           
#> [10] "MERC 280"            "MERC 280C"           "MERC 450SE"         
#> [13] "MERC 450SL"          "MERC 450SLC"         "CADILLAC FLEETWOOD" 
#> [16] "LINCOLN CONTINENTAL" "CHRYSLER IMPERIAL"   "FIAT 128"           
#> [19] "HONDA CIVIC"         "TOYOTA COROLLA"      "TOYOTA CORONA"      
#> [22] "DODGE CHALLENGER"    "AMC JAVELIN"         "CAMARO Z28"         
#> [25] "PONTIAC FIREBIRD"    "FIAT X1-9"           "PORSCHE 914-2"      
#> [28] "LOTUS EUROPA"        "FORD PANTERA L"      "FERRARI DINO"       
#> [31] "MASERATI BORA"       "VOLVO 142E"

I would advice to use a column in a data.frame for that, so that you can manipulate as any other column in your code See the new rowname column created

library(dplyr, warn.conflicts = F)
mtcars %>%
  tibble::rownames_to_column() %>%
  glimpse()
#> Rows: 32
#> Columns: 12
#> $ rowname <chr> "MAZDA RX4", "MAZDA RX4 WAG", "DATSUN 710", "HORNET 4 DRIVE...
#> $ mpg     <dbl> 21.0, 21.0, 22.8, 21.4, 18.7, 18.1, 14.3, 24.4, 22.8, 19.2,...
#> $ cyl     <dbl> 6, 6, 4, 6, 8, 6, 8, 4, 4, 6, 6, 8, 8, 8, 8, 8, 8, 4, 4, 4,...
#> $ disp    <dbl> 160.0, 160.0, 108.0, 258.0, 360.0, 225.0, 360.0, 146.7, 140...
#> $ hp      <dbl> 110, 110, 93, 110, 175, 105, 245, 62, 95, 123, 123, 180, 18...
#> $ drat    <dbl> 3.90, 3.90, 3.85, 3.08, 3.15, 2.76, 3.21, 3.69, 3.92, 3.92,...
#> $ wt      <dbl> 2.620, 2.875, 2.320, 3.215, 3.440, 3.460, 3.570, 3.190, 3.1...
#> $ qsec    <dbl> 16.46, 17.02, 18.61, 19.44, 17.02, 20.22, 15.84, 20.00, 22....
#> $ vs      <dbl> 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1,...
#> $ am      <dbl> 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,...
#> $ gear    <dbl> 4, 4, 4, 3, 3, 3, 3, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 4, 4, 4,...
#> $ carb    <dbl> 4, 4, 1, 1, 2, 1, 4, 2, 2, 4, 4, 3, 3, 3, 4, 4, 4, 1, 2, 1,...

Created on 2020-07-07 by the reprex package (v0.3.0)

Hope it helps

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.