Introduction


In this tutorial we provide a basic overview of Spectre's heatmap functions, to create expression heatmaps, and z-score/fold-change heatmaps.

1. Expression heatmap

2. Z-score or fold-change heatmap

For showing the average expression of each selected marker on each population for a given dataset.


For showing relative change (increase or decrease) from the mean/median of each column for a given dataset. Each column shows a summarised feature of the data, including the expression of marker on labelled populations.



1. Expression heatmaps



library('Spectre')
package.load()

cell.dat <- Spectre::demo.clustered 
cell.dat
                 FileName      NK11        CD3     CD45       Ly6G    CD11b      B220      CD8a       Ly6C       CD4  NK11_asinh    CD3_asinh CD45_asinh  Ly6G_asinh	...
     1:   CNS_Mock_01.csv   42.3719  40.098700  6885.08  -344.7830 14787.30  -40.2399   83.7175   958.7000  711.0720  0.04235923  0.040087962   2.627736 -0.33829345	...
     2:   CNS_Mock_01.csv   42.9586 119.014000  1780.29  -429.6650  5665.73   86.6673   34.7219   448.2590  307.2720  0.04294540  0.118734817   1.340828 -0.41743573	...
     3:   CNS_Mock_01.csv   59.2366 206.238000 10248.30 -1603.8400 19894.30  427.8310  285.8800  1008.8300  707.0940  0.05920201  0.204803270   3.022631 -1.25101677	...
     4:   CNS_Mock_01.csv  364.9480  -0.233878  3740.04  -815.9800  9509.43  182.4200  333.6050   440.0710  249.7840  0.35729716 -0.000233878   2.029655 -0.74509796	...
     5:   CNS_Mock_01.csv  440.2470  40.035200  9191.38    40.5055  5745.82 -211.6940  149.2200    87.4815  867.5700  0.42713953  0.040024513   2.914359  0.04049443	...
    ---                                                                                                                                                             
169000: CNS_WNV_D7_06.csv  910.8890  72.856100 31466.20  -316.5570 28467.80   -7.7972 -271.8040 12023.7000 1103.0500  0.81693878  0.072791800   4.142314 -0.31149515	...
169001: CNS_WNV_D7_06.csv  -10.2642  64.188700 45188.00  -540.5140 22734.00  202.4110 -936.4920  4188.3300  315.9400 -0.01026402  0.064144703   4.504101 -0.51715205	...
169002: CNS_WNV_D7_06.csv -184.2910  -9.445650 11842.60   -97.9383 17237.00  123.4760 -219.9320  8923.4000 -453.4640 -0.18326344 -0.009445510   3.166628 -0.09778240	...
169003: CNS_WNV_D7_06.csv  248.3860 229.986000 32288.20  -681.1630 19255.80 -656.0540 -201.5880 10365.7000   61.6765  0.24590035  0.228005328   4.168089 -0.63716643	...
169004: CNS_WNV_D7_06.csv  738.9810  95.470300 46185.10 -1004.6000 22957.80 -661.6280   72.3356  9704.4700  -31.8532  0.68430866  0.095325863   4.525922 -0.88462254	...
as.matrix(names(cell.dat))
      [,1]                 
 [1,] "FileName"           
 [2,] "NK11"               
 [3,] "CD3"                
 [4,] "CD45"               
 [5,] "Ly6G"               
 [6,] "CD11b"              
 [7,] "B220"               
 [8,] "CD8a"               
 [9,] "Ly6C"               
[10,] "CD4"                
[11,] "NK11_asinh"         
[12,] "CD3_asinh"          
[13,] "CD45_asinh"         
[14,] "Ly6G_asinh"         
[15,] "CD11b_asinh"        
[16,] "B220_asinh"         
[17,] "CD8a_asinh"         
[18,] "Ly6C_asinh"         
[19,] "CD4_asinh"          
[20,] "Sample"             
[21,] "Group"              
[22,] "Batch"              
[23,] "FlowSOM_cluster"    
[24,] "FlowSOM_metacluster"
[25,] "Population"         
[26,] "UMAP_X"             
[27,] "UMAP_Y"     
cellular.cols <- names(cell.dat)[c(11:19)]
cellular.cols
      [,1]         
 [1,] "NK11_asinh" 
 [2,] "CD3_asinh"  
 [3,] "CD45_asinh" 
 [4,] "Ly6G_asinh" 
 [5,] "CD11b_asinh"
 [6,] "B220_asinh" 
 [7,] "CD8a_asinh" 
 [8,] "Ly6C_asinh" 
 [9,] "CD4_asinh"  
exp <- do.aggregate(dat = cell.dat, use.cols = cellular.cols, by = 'Population')
exp
          Population  NK11_asinh   CD3_asinh CD45_asinh Ly6G_asinh CD11b_asinh B220_asinh  CD8a_asinh Ly6C_asinh   CD4_asinh
1:         Microglia  0.06236472  0.08602177   2.166889 -0.3855973    3.057697  0.1821609  0.08896056  0.5460709  0.54132958
2:          NK cells  1.46300084 -0.01751250   4.630241 -1.3037979    1.922951  1.0739984 -0.25100596  0.6064406  0.03004418
3:       Neutrophils  0.03727157  0.07222479   4.308696  3.0539339    4.619174  0.3441983  0.03039162  2.6481672  0.61570367
4:       CD4 T cells -0.33980759  2.15264283   5.143285 -1.7226959    1.408319 -0.3640679 -0.45432434  1.9315509  3.49054693
5: Infil Macrophages  0.22941383  0.14636386   4.518994 -1.1993391    3.922148  0.1186618 -0.22026899  3.5722527  0.66496177
6:       CD8 T cells -0.21850316  1.53463965   4.909689 -1.7374355    1.396367  0.1280498  1.16367454  2.2156928 -0.17229134 
getwd()
make.pheatmap(dat = exp, sample.col = 'Population', plot.cols = cellular.cols)



2. Z-score or fold-change heatmaps



library('Spectre')
package.load()

sum.dat <- Spectre::demo.sum
sum.dat
        Sample Group Batch Cells per sample -- CD4 T cells Cells per sample -- CD8 T cells Cells per sample -- Infil Macrophages	...
 1: 01_Mock_01  Mock     A                        734.6282                       2696.9910                              2143.504	...
 2: 02_Mock_02  Mock     B                        506.0006                       1037.9500                              2536.490	...
 3: 03_Mock_03  Mock     B                        540.5026                       1003.7905                              2470.869	...
 4: 04_Mock_04  Mock     A                        252.2882                        404.8345                              1965.501	...
 5: 05_Mock_05  Mock     A                        201.5021                        549.5512                              2198.205	...
 6: 06_Mock_06  Mock     B                        531.5886                       1308.5259                              4722.961	...
 7:  07_WNV_01   WNV     A                      54094.7075                      50529.2479                            605738.162	...
 8:  08_WNV_02   WNV     B                      20636.9741                      23901.9282                            674243.824	...
 9:  09_WNV_03   WNV     A                      26314.1446                      34814.6759                            678792.425	...
10:  10_WNV_04   WNV     A                      26910.2796                      32397.4082                            652559.687	...
11:  11_WNV_05   WNV     B                      31520.7836                      36292.8545                            644041.191	...
12:  12_WNV_06   WNV     A                      34251.3184                      37500.6658                            645714.590	...
as.matrix(names(sum.dat))
      [,1]                                              
 [1,] "Sample"                                          
 [2,] "Group"                                           
 [3,] "Batch"                                           
 [4,] "Cells per sample -- CD4 T cells"                 
 [5,] "Cells per sample -- CD8 T cells"                 
 [6,] "Cells per sample -- Infil Macrophages"           
 [7,] "Cells per sample -- Microglia"                   
 [8,] "Cells per sample -- Neutrophils"                 
 [9,] "Cells per sample -- NK cells"                    
[10,] "Percent Ly6C_asinh positive -- CD4 T cells"      
[11,] "Percent Ly6C_asinh positive -- CD8 T cells"      
[12,] "Percent Ly6C_asinh positive -- Infil Macrophages"
[13,] "Percent Ly6C_asinh positive -- Microglia"        
[14,] "Percent Ly6C_asinh positive -- Neutrophils"      
[15,] "Percent Ly6C_asinh positive -- NK cells" 
to.plot <- names(sum.dat)[c(4:15)]
as.matrix(to.plot)
      [,1]                                              
 [1,] "Cells per sample -- CD4 T cells"                 
 [2,] "Cells per sample -- CD8 T cells"                 
 [3,] "Cells per sample -- Infil Macrophages"           
 [4,] "Cells per sample -- Microglia"                   
 [5,] "Cells per sample -- Neutrophils"                 
 [6,] "Cells per sample -- NK cells"                    
 [7,] "Percent Ly6C_asinh positive -- CD4 T cells"      
 [8,] "Percent Ly6C_asinh positive -- CD8 T cells"      
 [9,] "Percent Ly6C_asinh positive -- Infil Macrophages"
[10,] "Percent Ly6C_asinh positive -- Microglia"        
[11,] "Percent Ly6C_asinh positive -- Neutrophils"      
[12,] "Percent Ly6C_asinh positive -- NK cells"  
sum.dat.z <- do.zscore(dat = sum.dat, use.cols = to.plot, replace = TRUE)
sum.dat.z
        Sample Group Batch Cells per sample -- CD4 T cells Cells per sample -- CD8 T cells Cells per sample -- Infil Macrophages Cells per sample -- Microglia	...
 1: 01_Mock_01  Mock     A                      -0.8505409                      -0.8308476                            -0.9576835                    -0.8963994	...
 2: 02_Mock_02  Mock     B                      -0.8629743                      -0.9178710                            -0.9565229                    -0.8768447	...
 3: 03_Mock_03  Mock     B                      -0.8610980                      -0.9196628                            -0.9567167                    -0.8832496	...
 4: 04_Mock_04  Mock     A                      -0.8767718                      -0.9510804                            -0.9582092                    -0.7237695	...
 5: 05_Mock_05  Mock     A                      -0.8795337                      -0.9434894                            -0.9575220                    -0.8121820	...
 6: 06_Mock_06  Mock     B                      -0.8615827                      -0.9036782                            -0.9500658                    -1.3124378	...
 7:  07_WNV_01   WNV     A                       2.0513215                       1.6781460                             0.8248683                     0.9445190	...
 8:  08_WNV_02   WNV     B                       0.2318014                       0.2814364                             1.0271811                     1.1174911	...
 9:  09_WNV_03   WNV     A                       0.5405409                       0.8538537                             1.0406141                     0.8099797	...
10:  10_WNV_04   WNV     A                       0.5729603                       0.7270584                             0.9631429                     0.4584563	...
11:  11_WNV_05   WNV     B                       0.8236918                       0.9313901                             0.9379859                     0.6569472	...
12:  12_WNV_06   WNV     A                       0.9721855                       0.9947447                             0.9429278                     1.5174898	...
getwd()
make.pheatmap(dat = sum.dat.z, sample.col = 'Sample', plot.cols = to.plot, is.fold = TRUE)



  • No labels