File: test_heatmap_w_pca.R

package info (click to toggle)
trinityrnaseq 2.15.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 468,004 kB
  • sloc: perl: 49,905; cpp: 17,993; java: 12,489; python: 3,282; sh: 1,989; ansic: 985; makefile: 717; xml: 62
file content (28 lines) | stat: -rw-r--r-- 688 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
source("../misc_rnaseq_funcs.R")
source("../heatmap.3.R")

data = mtcars;
data = log2(data*10+1)
scale(data,center=T,scale=T); # Z-scores


## Use principal components to partition the 'genes'
pc = princomp(data, cor=T)

pc4 = pc$scores[,1:4]
pc4_cols = matrix_to_color_assignments(pc4)
colnames(pc4_cols) = paste("PC", 1:4)

#heatmap.3(data, RowSideColors=pc4_cols)


## Highlight samples 
Pon = matrix(grepl("c", colnames(data)), nrow=1)
print(Pon)
PonMat = apply(Pon, 1:2, function(x) as.numeric(x))
PonMat = PonMat+1

PonMatCol = matrix_to_color_assignments(PonMat, col=c('white','black'))
rownames(PonMatCol) = "Pon"

heatmap.3(data, RowSideColors=pc4_cols, ColSideColors=PonMatCol)