# cell type specific genes - heatmap using rank based approach

I was wondering if some one can help me with pseudo r code for my approach here based on this paper to plot a heatmap

# Figure 3

Figure description The top 40 enriched genes percelltypeare shown in a heat map.Onlyhighlyexpressed genes with FPKM ⬎20 areincludedin this analysis. Fold enrichment iscalculatedasFPKM of one cell type divided by the average FPKM of all other cell types. The majority of these genes showed specific expression by only one cell type, with the exception that some are expressed during more than one maturation stage in the oligodendrocyte lineage.

Similar description in their methods: Differential expression was calculated as the FPKM of a given cell type divided by the average FPKM of all other cell types. Genes were ranked by their fold enrichment in each cell type, and top enriched genes for each cell type were identified

In my case I have 9 cell types(columns) and ~24000 genes(rows) from mouse and the values are TPMs.

I know to order celltype only based on one column like this

expr.order = expr[order(expr[,1],decreasing =T),]


Which clearly not the right way and would need some help with code in r

• It’s unclear from your text what you actually want to do: there’s no question. For ordering the expression values based on one column you already found the solution. If that’s not what you mean you need to be more specific. Sep 20 '17 at 15:54
• I do not know how to achieve this Genes were ranked by their fold enrichment in each cell type which I guess means rank individual column independently not sure how to do this Sep 20 '17 at 16:37
• You can't rank individual columns independently (of the same data), but you can order them by several factors.
– llrs
Sep 21 '17 at 11:23
• Well in that case you first need to compute fold changes using one of the existing differential expression packages, e.g. DESeq2 or edgeR. Sep 21 '17 at 12:03
• BTW, what else have you tried with R? Did you compute the fold change and found the top 40 as described in the image?
– llrs
Sep 24 '17 at 20:52

> expr <- matrix(runif(9*24000), nrow=24000, ncol=9)

Then you can build a biclustered heatmap with expr[top_genes_all_celltypes,], for example, using heatmap2.