-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy path.Rhistory
512 lines (512 loc) · 28.4 KB
/
.Rhistory
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
m.set <- read.table(file, header = TRUE, sep = '\t', stringsAsFactors = FALSE)
marker.sets[[m]] <- m.set$Input
}
## create dummy regulon
#' Creates a dummy regulon from a given gene list.
#'
#' @param gene.list List of genes.
#' @return List with two elements; likelihood and tfmode
MakeReg <- function(gene.list) {
likelihood <- rep(1, length(gene.list))
tf.mode <- rep(1, length(gene.list)); names(tf.mode) <- gene.list
d.reg <- list('tfmode' = tf.mode, 'likelihood' = likelihood)
return(d.reg)
}
raw.mat <- readRDS('C://Users/lvlah/linux/ac_lab/data/pda_olive/mouse-pda_raw.rds')
cpm.mat <- readRDS('C://Users/lvlah/linux/ac_lab/data/pda_olive/mouse-pda_cpm.rds')
rank.mat <- readRDS('C://Users/lvlah/linux/ac_lab/data/pda_olive/mouse-pda_rank.rds')
marker.reg <- list()
for (m in names(marker.sets)) {
m.set <- marker.sets[[m]]
m.set <- lapply(m.set, function(x) { paste(substr(x, 1, 1), tolower(substr(x, 2, nchar(x))), sep = '') })
m.set <- intersect(m.set, rownames(rank.mat))
marker.reg[[as.character(m)]] <- MakeReg(m.set)
}
class(marker.reg) <- "regulon"
## GSEA using marker sets
marker.vip <- viper(rank.mat, marker.reg, method = 'none', minsize = 1)
marker.vip
dim(marker.vip)
library(pheatmap)
library(RColorBrewer)
head(rownames(cpm.mat))
'Cxcr7' %in% rownames(cpm.mat)
'Cxcr7' %in% rownames(raw.mat)
raw.mat <- as.matrix(readMM('C://Users/lvlah/linux/ac_lab/data/pda_olive/count_data/matrix.mtx'))
genes <- read.table('C://Users/lvlah/linux/ac_lab/data/pda_olive/count_data/features.tsv', sep = '\t')
barcodes <- read.table('C://Users/lvlah/linux/ac_lab/data/pda_olive/count_data/barcodes.tsv', sep = '\t')
colnames(raw.mat) <- barcodes[,1]
rownames(raw.mat) <- genes[,1]
'ENSMUSG00000044337' %in% rownames(raw.mat)
filt.mat <- QCTransform(raw.mat)
cpm.mat <- CPMTransform(filt.mat)
'ENSMUSG00000044337' %in% rownames(cpm.mat)
pheatmap(marker.vip, main = 'Mouse GSEA Clust', width = 6, height = 8, scale = 'row',
cluster_rows = FALSE, cluster_cols = TRUE, show_rownames = TRUE, show_colnames = FALSE,
color = colorRampPalette(colors = c('blue', 'white', 'red'))(100), fontsize_row = 4,
annotation_col = data.frame('Cxcr7' = cpm.mat['ENSMUSG00000044337',]))
pheatmap(marker.vip, main = 'Mouse GSEA Clust', width = 6, height = 8, scale = 'row',
cluster_rows = FALSE, cluster_cols = TRUE, show_rownames = TRUE, show_colnames = FALSE,
color = colorRampPalette(colors = c('blue', 'white', 'red'))(100), fontsize_row = 8,
annotation_col = data.frame('Cxcr7' = cpm.mat['ENSMUSG00000044337',]))
View(cpm.mat)
head(sort(cpm.mat['ENSMUSG00000044337',]))
head(sort(cpm.mat['ENSMUSG00000044337',], decreasing = TRUE))
pheatmap(marker.vip, main = 'Mouse GSEA Clust', width = 6, height = 8, scale = 'row',
cluster_rows = FALSE, cluster_cols = TRUE, show_rownames = TRUE, show_colnames = FALSE,
color = colorRampPalette(colors = c('blue', 'white', 'red'))(100), fontsize_row = 8,
annotation_col = data.frame('Cxcr7' = raw.mat['ENSMUSG00000044337', colnames(marker.vip)]))
library(cluster)
## clustering
gsea.clust <- pam(t(marker.vip), k = 5)
gsea.clust$clustering
pheatmap(marker.vip[, names(sort(gsea.clust$clustering)) ], main = 'Mouse GSEA Clust', width = 6, height = 8, scale = 'row',
cluster_rows = FALSE, cluster_cols = FALSE, show_rownames = FALSE, show_colnames = FALSE,
color = colorRampPalette(colors = c('blue', 'white', 'red'))(100), fontsize_row = 8,
annotation_col = annot.df)
annot.df <- data.frame('clust' = gsea.clust$clustering, 'Cxcr7' = cpm.mat['ENSMUSG00000044337', ])
pheatmap(marker.vip[, names(sort(gsea.clust$clustering)) ], main = 'Mouse GSEA Clust', width = 6, height = 8, scale = 'row',
cluster_rows = FALSE, cluster_cols = FALSE, show_rownames = FALSE, show_colnames = FALSE,
color = colorRampPalette(colors = c('blue', 'white', 'red'))(100), fontsize_row = 8,
annotation_col = annot.df)
annot.df <- data.frame('clust' = gsea.clust$clustering, 'Cxcr7' = cpm.mat['ENSMUSG00000044337', names(gsea.clust$clustering)])
pheatmap(marker.vip[, names(sort(gsea.clust$clustering)) ], main = 'Mouse GSEA Clust', width = 6, height = 8, scale = 'row',
cluster_rows = FALSE, cluster_cols = FALSE, show_rownames = FALSE, show_colnames = FALSE,
color = colorRampPalette(colors = c('blue', 'white', 'red'))(100), fontsize_row = 8,
annotation_col = annot.df)
annot.df <- data.frame('clust' = as.factor(gsea.clust$clustering), 'Cxcr7' = cpm.mat['ENSMUSG00000044337', names(gsea.clust$clustering)])
pheatmap(marker.vip[, names(sort(gsea.clust$clustering)) ], main = 'Mouse GSEA Clust', width = 6, height = 8, scale = 'row',
cluster_rows = FALSE, cluster_cols = FALSE, show_rownames = FALSE, show_colnames = FALSE,
color = colorRampPalette(colors = c('blue', 'white', 'red'))(100), fontsize_row = 8,
annotation_col = annot.df)
pheatmap(marker.vip[, names(sort(gsea.clust$clustering)) ], main = 'Mouse GSEA Clust', width = 6, height = 8, scale = 'row',
cluster_rows = FALSE, cluster_cols = FALSE, show_rownames = TRUE, show_colnames = FALSE,
color = colorRampPalette(colors = c('blue', 'white', 'red'))(100), fontsize_row = 8,
annotation_col = annot.df)
## get average expression for each clsuter
for (i in 1:5) {
clust.cells <- which(gsea.clust$clustering == i)
mean.exp <- mean(cpm.mat['ENSMUSG00000044337', clust.cells])
print(mean.exp)
}
### HUMAN ###
raw.human.mat <- readRDS('C://Users/lvlah/linux/ac_lab/data/pda_olive/ht99_geneExp.rds')
## convert to gene symbol
raw.human.mat <- Ensemble2GeneName(raw.human.mat)
cpm.human.mat <- CPMTransform(raw.human.mat)
rank.human.mat <- RankTransform(cpm.human.mat)
saveRDS(cpm.human.mat, 'C://Users/lvlah/linux/ac_lab/data/pda_olive/ht99_cpm.rds')
saveRDS(rank.human.mat, 'C://Users/lvlah/linux/ac_lab/data/pda_olive/ht99_rank.rds')
## create human marker set
marker.human.reg <- list()
for (m in names(marker.sets)) {
m.set <- marker.sets[[m]]
m.set <- lapply(m.set, function(x) { paste(substr(x, 1, 1), tolower(substr(x, 2, nchar(x))), sep = '') })
m.set <- intersect(m.set, rownames(rank.human.mat))
marker.human.reg[[as.character(m)]] <- MakeReg(m.set)
}
class(marker.human.reg) <- "regulon"
## GSEA using marker set
marker.human.vip <- viper(rank.mat, marker.reg, method = 'none')
## GSEA using marker set
marker.human.vip <- viper(rank.mat, marker.reg, method = 'none', minsize = 1)
head(rownames(cpm.human.mat))
'CXCR7' %in% rownames(cpm.human.mat)
'ACKR3' %in% rownames(cpm.human.mat)
gsea.clust.human <- pam(t(marker.human.vip), k = 5)
## pheatmap
annot.df <- data.frame('clust' = as.factor(gsea.clust.human$clustering), 'Cxcr7' = cpm.human.mat['ACKR3', names(gsea.clust.human$clustering)])
pheatmap(marker.vip[, names(sort(gsea.clust$clustering)) ], main = 'Mouse GSEA Clust', width = 6, height = 8, scale = 'row',
cluster_rows = FALSE, cluster_cols = FALSE, show_rownames = TRUE, show_colnames = FALSE,
color = colorRampPalette(colors = c('blue', 'white', 'red'))(100), fontsize_row = 8,
annotation_col = annot.df)
## pheatmap
annot.df <- data.frame('clust' = as.factor(gsea.clust.human$clustering), 'Cxcr7' = cpm.human.mat['ACKR3', names(gsea.clust.human$clustering)])
pheatmap(marker.human.vip[, names(sort(gsea.clust.human$clustering)) ], main = 'Human GSEA Clust', width = 6, height = 8, scale = 'row',
cluster_rows = FALSE, cluster_cols = FALSE, show_rownames = TRUE, show_colnames = FALSE,
color = colorRampPalette(colors = c('blue', 'white', 'red'))(100), fontsize_row = 8,
annotation_col = annot.df)
## pheatmap
annot.df <- data.frame('clust' = as.factor(gsea.clust.human$clustering), 'Cxcr7' = cpm.human.mat['ACKR3', names(gsea.clust.human$clustering)])
## pheatmap
annot.df <- data.frame('clust' = as.factor(gsea.clust.human$clustering), 'Cxcr7' = cpm.human.mat['ACKR3', ])
dim(marker.human.vip)
dim(cpm.human.mat)
## create human marker set
marker.human.reg <- list()
for (m in names(marker.sets)) {
m.set <- marker.sets[[m]]
m.set <- intersect(m.set, rownames(rank.human.mat))
marker.human.reg[[as.character(m)]] <- MakeReg(m.set)
}
class(marker.human.reg) <- "regulon"
marker.human.vip <- viper(rank.human.mat, marker.reg, method = 'none', minsize = 1)
m.set
marker.human.vip <- viper(rank.human.mat, marker.human.reg, method = 'none', minsize = 1)
## clustering
gsea.clust.human <- pam(t(marker.human.vip), k = 5)
## pheatmap
annot.df <- data.frame('clust' = as.factor(gsea.clust.human$clustering), 'Cxcr7' = cpm.human.mat['ACKR3', ])
pheatmap(marker.human.vip[, names(sort(gsea.clust.human$clustering)) ], main = 'Human GSEA Clust', width = 6, height = 8, scale = 'row',
cluster_rows = FALSE, cluster_cols = FALSE, show_rownames = TRUE, show_colnames = FALSE,
color = colorRampPalette(colors = c('blue', 'white', 'red'))(100), fontsize_row = 8,
annotation_col = annot.df)
## get average expression for each clsuter
for (i in 1:5) {
clust.cells <- which(gsea.clust$clustering == i)
mean.exp <- mean(cpm.mat['ENSMUSG00000044337', clust.cells])
print(mean.exp)
}
## get average expression for each clsuter
for (i in 1:5) {
clust.cells <- which(gsea.clust.human$clustering == i)
mean.exp <- mean(cpm.human.mat['ENSMUSG00000044337', clust.cells])
print(mean.exp)
}
## get average expression for each clsuter
for (i in 1:5) {
clust.cells <- which(gsea.clust.human$clustering == i)
mean.exp <- mean(cpm.human.mat['ACKR3', clust.cells])
print(mean.exp)
}
### MOUSE ###
raw.mat <- readRDS('C://Users/lvlah/linux/ac_lab/data/pda_olive/mouse-pda_raw.rds')
cpm.mat <- readRDS('C://Users/lvlah/linux/ac_lab/data/pda_olive/mouse-pda_cpm.rds')
rank.mat <- readRDS('C://Users/lvlah/linux/ac_lab/data/pda_olive/mouse-pda_rank.rds')
'Rdc1' %in% rownames(cpm.mat)
'Cxcr7' %in% rownames(cpm.mat)
head(rownames(cpm.mat))
'Cxcr7' %in% rownames(raw.mat)
'Rdc1' %in% rownames(raw.mat)
'Ackr3' %in% rownames(raw.mat)
'Ackr3' %in% rownames(cpm.mat)
?viperSignature
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/process-utils.R')
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/cluster-functions.R')
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/viper-utils.R')
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/process-utils.R')
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/cluster-functions.R')
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/viper-utils.R')
## PIPELINE r2
r2.pAct <- readRDS('C://Users/lvlah/linux/ac_lab/data/pda_olive/mps_r2-pAct.rds')
r2.cbcMRs <- CBCMRs(r2.pAct) # identify the most representative proteins
r2.pAct.cbc <- r2.pAct[ r2.cbcMRs ,] # filter the protein activity matrix
r2.louvain <- LouvainClust(r2.pAct.cbc) # perform clustering analysis
r2.cbcUMAP <- CustomUMAP(r2.pAct.cbc)
ClusterScatter(r2.cbcUMAP, r2.louvain, 'Viper Clustering (Louvain)')
m.set
marker.sets
markers <- c('Ackr3', marker.sets$endothelial)
markers
markers <- c('Ackr3', lapply(marker.sets$endothelial, function(x) { paste(substr(x, 1, 1), tolower(substr(x, 2, nchar(x))), sep = '') })
)
markers
markers <- c('Ackr3', unlist( lapply(marker.sets$endothelial, function(x)
{ paste(substr(x, 1, 1), tolower(substr(x, 2, nchar(x))), sep = '') })))
markers
MarkerGrid(r2.cbcUMAP, r2.louvain, r2.pAct, markers, 'Endothelial Marker Activity')
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/process-utils.R')
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/cluster-functions.R')
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/viper-utils.R')
MarkerGrid(r2.cbcUMAP, r2.louvain, r2.pAct, markers, 'Endothelial Marker Activity')
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/process-utils.R')
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/cluster-functions.R')
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/viper-utils.R')
MarkerGrid(r2.cbcUMAP, r2.louvain, r2.pAct, markers, 'Endothelial Marker Activity')
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/process-utils.R')
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/cluster-functions.R')
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/viper-utils.R')
MarkerGrid(r2.cbcUMAP, r2.louvain, r2.pAct, markers, 'Endothelial Marker Activity')
dev.off()
MarkerGrid(r2.cbcUMAP, r2.louvain, r2.pAct, markers, 'Endothelial Marker Activity')
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/cluster-functions.R'\
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/cluster-functions.R'
)
MarkerGrid(r2.cbcUMAP, r2.louvain, r2.pAct, markers, 'Endothelial Marker Activity')
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/cluster-functions.R')
MarkerGrid(r2.cbcUMAP, r2.louvain, r2.pAct, markers, 'Endothelial Marker Activity')
length(markers)
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/cluster-functions.R')
length(markers)
MarkerGrid(r2.cbcUMAP, r2.louvain, r2.pAct, markers, 'Endothelial Marker Activity')
markers <- c('Ackr3', unlist( lapply(marker.sets$epithelial, function(x)
{ paste(substr(x, 1, 1), tolower(substr(x, 2, nchar(x))), sep = '') })))
MarkerGrid(r2.cbcUMAP, r2.louvain, r2.pAct, markers, 'Epithelial Marker Activity')
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/cluster-functions.R')
markers <- c('Ackr3', unlist( lapply(marker.sets$endothelial, function(x)
{ paste(substr(x, 1, 1), tolower(substr(x, 2, nchar(x))), sep = '') })))
MarkerGrid(r2.cbcUMAP, r2.louvain, r2.pAct, markers, 'Endothelial Marker Activity')
markers <- c('Ackr3', unlist( lapply(marker.sets$epithelial, function(x)
{ paste(substr(x, 1, 1), tolower(substr(x, 2, nchar(x))), sep = '') })))
MarkerGrid(r2.cbcUMAP, r2.louvain, r2.pAct, markers, 'Epithelial Marker Activity')
markers <- c('Ackr3', unlist( lapply(marker.sets$fibroblast, function(x)
{ paste(substr(x, 1, 1), tolower(substr(x, 2, nchar(x))), sep = '') })))
MarkerGrid(r2.cbcUMAP, r2.louvain, r2.pAct, markers, 'Fibroblast Marker Activity')
markers <- c('Ackr3', unlist( lapply(marker.sets$immune, function(x)
{ paste(substr(x, 1, 1), tolower(substr(x, 2, nchar(x))), sep = '') })))
MarkerGrid(r2.cbcUMAP, r2.louvain, r2.pAct, markers, 'Immune Marker Activity')
markers <- c('Ackr3', unlist( lapply(marker.sets$pericytes, function(x)
{ paste(substr(x, 1, 1), tolower(substr(x, 2, nchar(x))), sep = '') })))
MarkerGrid(r2.cbcUMAP, r2.louvain, r2.pAct, markers, 'Pericyte Marker Activity')
setwd('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/')
r1.pAct <- readRDS('tutorial/pbmc_r1-pAct.rds')
r2.pAct <- readRDS('tutorial/pbmc_r2-pAct.rds')
r2.MRs <- readRDS('tutorial/pbmc_r2-MRs.rds')
source('functions/process-utils.R')
source('functions/cluster-functions.R')
source('functions/viper-utils.R')
library(ggplot2)
library(ggpubr)
library(viper)
library(pheatmap)
library(RColorBrewer)
library(MUDAN)
library(umap)
raw.mat <- readRDS('tutorial/pbmc.rds')
mt.genes <- read.table('mt-genes.csv', header = TRUE, sep = ',', stringsAsFactors = FALSE)
mt.genes <- read.table('mt-genes.csv', header = TRUE, sep = ',', stringsAsFactors = FALSE)
mt.genes
mt.genes <- read.table('mt-genes.csv', header = TRUE, sep = ',', stringsAsFactors = FALSE)
hum.mt <- mt.genes$hum.ensg
QCPlots(raw.mat, hum.mt)
mt.genes <- read.table('mt-genes.csv', header = TRUE, sep = ',', stringsAsFactors = FALSE)
hum.mt <- mt.genes$hum.ensg
QCPlots(raw.mat, hum.mt)
source('functions/process-utils.R')
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/process-utils.R')
mt.genes <- read.table('mt-genes.csv', header = TRUE, sep = ',', stringsAsFactors = FALSE)
hum.mt <- mt.genes$hum.ensg
QCPlots(raw.mat, hum.mt)
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/process-utils.R')
mt.genes <- read.table('mt-genes.csv', header = TRUE, sep = ',', stringsAsFactors = FALSE)
hum.mt <- mt.genes$hum.ensg
QCPlots(raw.mat, hum.mt)
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/process-utils.R')
mt.genes <- read.table('mt-genes.csv', header = TRUE, sep = ',', stringsAsFactors = FALSE)
hum.mt <- mt.genes$hum.ensg
QCPlots(raw.mat, hum.mt)
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/process-utils.R')
mt.genes <- read.table('mt-genes.csv', header = TRUE, sep = ',', stringsAsFactors = FALSE)
hum.mt <- mt.genes$hum.ensg
QCPlots(raw.mat, hum.mt)
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/process-utils.R')
mt.genes <- read.table('mt-genes.csv', header = TRUE, sep = ',', stringsAsFactors = FALSE)
hum.mt <- mt.genes$hum.ensg
QCPlots(raw.mat, hum.mt)
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/process-utils.R')
mt.genes <- read.table('mt-genes.csv', header = TRUE, sep = ',', stringsAsFactors = FALSE)
hum.mt <- mt.genes$hum.ensg
QCPlots(raw.mat, hum.mt)
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/process-utils.R')
mt.genes <- read.table('mt-genes.csv', header = TRUE, sep = ',', stringsAsFactors = FALSE)
hum.mt <- mt.genes$hum.ensg
QCPlots(raw.mat, hum.mt)
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/process-utils.R')
mt.genes <- read.table('mt-genes.csv', header = TRUE, sep = ',', stringsAsFactors = FALSE)
hum.mt <- mt.genes$hum.ensg
QCPlots(raw.mat, hum.mt)
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/process-utils.R')
source('functions/process-utils.R')
source('functions/cluster-functions.R')
source('functions/viper-utils.R')
library(ggplot2)
library(ggpubr)
library(viper)
library(pheatmap)
library(RColorBrewer)
library(MUDAN)
library(umap)
raw.mat <- readRDS('tutorial/pbmc.rds')
mt.genes <- read.table('mt-genes.csv', header = TRUE, sep = ',', stringsAsFactors = FALSE)
hum.mt <- mt.genes$hum.ensg
QCPlots(raw.mat, hum.mt)
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/process-utils.R')
mt.genes <- read.table('mt-genes.csv', header = TRUE, sep = ',', stringsAsFactors = FALSE)
hum.mt <- mt.genes$hum.ensg
QCPlots(raw.mat, hum.mt)
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/process-utils.R')
mt.genes <- read.table('mt-genes.csv', header = TRUE, sep = ',', stringsAsFactors = FALSE)
hum.mt <- mt.genes$hum.ensg
QCPlots(raw.mat, hum.mt)
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/process-utils.R')
mt.genes <- read.table('mt-genes.csv', header = TRUE, sep = ',', stringsAsFactors = FALSE)
hum.mt <- mt.genes$hum.ensg
QCPlots(raw.mat, hum.mt)
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/process-utils.R')
mt.genes <- read.table('mt-genes.csv', header = TRUE, sep = ',', stringsAsFactors = FALSE)
hum.mt <- mt.genes$hum.ensg
QCPlots(raw.mat, hum.mt)
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/process-utils.R')
mt.genes <- read.table('mt-genes.csv', header = TRUE, sep = ',', stringsAsFactors = FALSE)
hum.mt <- mt.genes$hum.ensg
QCPlots(raw.mat, hum.mt)
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/process-utils.R')
mt.genes <- read.table('mt-genes.csv', header = TRUE, sep = ',', stringsAsFactors = FALSE)
hum.mt <- mt.genes$hum.ensg
QCPlots(raw.mat, hum.mt)
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/process-utils.R')
mt.genes <- read.table('mt-genes.csv', header = TRUE, sep = ',', stringsAsFactors = FALSE)
hum.mt <- mt.genes$hum.ensg
QCPlots(raw.mat, hum.mt)
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/process-utils.R')
mt.genes <- read.table('mt-genes.csv', header = TRUE, sep = ',', stringsAsFactors = FALSE)
hum.mt <- mt.genes$hum.ensg
QCPlots(raw.mat, hum.mt)
mt.genes <- read.table('mt-genes.csv', header = TRUE, sep = ',', stringsAsFactors = FALSE)
hum.mt <- mt.genes$hum.ensg
QCPlots(raw.mat, hum.mt)
mt.genes <- read.table('mt-genes.csv', header = TRUE, sep = ',', stringsAsFactors = FALSE)
hum.mt <- mt.genes$hum.ensg
QCPlots(raw.mat, hum.mt)
QCPlots(raw.mat, hum.mt)
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/process-utils.R')
mt.genes <- read.table('mt-genes.csv', header = TRUE, sep = ',', stringsAsFactors = FALSE)
hum.mt <- mt.genes$hum.ensg
QCPlots(raw.mat, hum.mt)
mt.genes <- read.table('mt-genes.csv', header = TRUE, sep = ',', stringsAsFactors = FALSE)
hum.mt <- mt.genes$hum.ensg
QCPlots(raw.mat, hum.mt)
mt.mat <- MTFilter(raw.mat, hum.mt)
filt.mat <- QCTransform(mt.mat)
cpm.mat <- CPMTransform(filt.mat)
rank.mat <- RankTransform(cpm.mat)
r1.net <- readRDS('tutorial/pbmc_r1-net-pruned.rds')
r1.pAct <- viper(rank.mat, r1.net, method = 'none')
r1.viperDist <- as.dist(viperSimilarity(r1.pAct))
r1.clusts <- PamKRange(r1.viperDist, kmin = 2, kmax = 10)
r1.clustSil <- SilScoreEval(r1.clusts, r1.viperDist)
plot.dat <- data.frame('k' = 2:10, 'Silhouette.Scores' = r1.clustSil)
ggplot(plot.dat, aes(x = k, y = Silhouette.Scores)) + geom_point() + geom_line() +
ggtitle('1.1 Clustering Silhouette Scores') + theme_bw()
# load in networks
c1.net <- readRDS('tutorial/pbmc-r2-c1_pruned.rds')
c2.net <- readRDS('tutorial/pbmc-r2-c2_pruned.rds')
c3.net <- readRDS('tutorial/pbmc-r2-c3_pruned.rds')
# infer protein activity
r2.pAct <- viper(rank.mat, list('c1' = c1.net, 'c2' = c2.net, 'c3' = c3.net), method = 'none')
r2.cbcMRs <- CBCMRs(r2.pAct) # identify the most representative proteins
r2.pAct.cbc <- r2.pAct[ r2.cbcMRs ,] # filter the protein activity matrix
r2.louvain <- LouvainClust(r2.pAct.cbc) # perform clustering analysis
r2.cbcUMAP <- CustomUMAP(r2.pAct.cbc)
ClusterScatter(r2.cbcUMAP, r2.louvain, 'Viper Clustering (Louvain)')
r2.pAct.ensg <- r2.pAct
r2.pAct <- Ensemble2GeneName(r2.pAct)
r2.MRs <- BTTestMRs(r2.pAct, r2.louvain)
ClusterHeatmap(r2.pAct[ MR_UnWrap(r2.MRs, top = 10) , ], clust = r2.louvain, plotTitle = 'Louvain Clustering: Differentially Activated Proteins')
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/cluster-functions.R')
ClusterHeatmap(r2.pAct[ MR_UnWrap(r2.MRs, top = 10) , ], clust = r2.louvain, plotTitle = 'Louvain Clustering: Differentially Activated Proteins')
?brewer.pal
ClusterHeatmap(r2.pAct[ MR_UnWrap(r2.MRs, top = 10) , ], clust = r2.louvain, plotTitle = 'Louvain Clustering: Differentially Activated Proteins')
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/cluster-functions.R')
ClusterHeatmap(r2.pAct[ MR_UnWrap(r2.MRs, top = 10) , ], clust = r2.louvain, plotTitle = 'Louvain Clustering: Differentially Activated Proteins')
ClusterHeatmap(r2.pAct[ MR_UnWrap(r2.MRs, top = 10) , ], clust = r2.louvain, plotTitle = 'Louvain Clustering: Differentially Activated Proteins')
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/cluster-functions.R')
ClusterHeatmap(r2.pAct[ MR_UnWrap(r2.MRs, top = 10) , ], clust = r2.louvain, plotTitle = 'Louvain Clustering: Differentially Activated Proteins')
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/cluster-functions.R')
ClusterHeatmap(r2.pAct[ MR_UnWrap(r2.MRs, top = 10) , ], clust = r2.louvain, plotTitle = 'Louvain Clustering: Differentially Activated Proteins')
seq(1,10, 0.5)
seq(min(r2.pAct), max(r2.pAct), (max(r2.pAct) - min(r2.pAct)) / 10)
length(seq(min(r2.pAct), max(r2.pAct), (max(r2.pAct) - min(r2.pAct)) / 10))
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/cluster-functions.R')
ClusterHeatmap(r2.pAct[ MR_UnWrap(r2.MRs, top = 10) , ], clust = r2.louvain, plotTitle = 'Louvain Clustering: Differentially Activated Proteins')
r2.MRs
?pt
anv.mrs <- AnovaMRs(r2.pAct, r2.louvain)
anv.mrs
s.mrs <- GetMRs(r2.pAct, r2.louvain, method = 'Stouffer')
ClusterHeatmap(r2.pAct[ MR_UnWrap(s.mrs, top = 10) ,], clust = r2.louvain)
s.mrs
?sort
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/cluster-functions.R')
s.mrs <- StoufferMRs(r2.pAct, r2.louvain)
s.mrs
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/cluster-functions.R')
s.mrs
s.mrs <- StoufferMRs(r2.pAct, r2.louvain)
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/viper-utils.R')
s.mrs <- StoufferMRs(r2.pAct, r2.louvain)
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/viper-utils.R')
s.mrs <- StoufferMRs(r2.pAct, r2.louvain)
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/viper-utils.R')
s.mrs <- StoufferMRs(r2.pAct, r2.louvain)
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/viper-utils.R')
s.mrs <- StoufferMRs(r2.pAct, r2.louvain)
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/viper-utils.R')
s.mrs <- StoufferMRs(r2.pAct, r2.louvain)
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/viper-utils.R')
s.mrs <- StoufferMRs(r2.pAct, r2.louvain)
r2.louvain
names(which(r2.louvain == 1))
names(which(r2.louvain == '1'))
which(r2.louvain == 1)
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/viper-utils.R')
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/viper-utils.R')
s.mrs <- StoufferMRs(r2.pAct, r2.louvain)
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/viper-utils.R')
s.mrs <- StoufferMRs(r2.pAct, r2.louvain)
ClusterHeatmap(r2.pAct[ MR_UnWrap(s.mrs, top = 10),], clust = r2.louvain)
ClusterHeatmap(r2.pAct[ MR_UnWrap(s.mrs, top = 10),], clust = r2.louvain, plotTitle = 'your mom')
ClusterHeatmap(r2.pAct[ MR_UnWrap(s.mrs, top = 10),], clust = r2.louvain, plotTitle = 'your mom', quantile = FALSE)
?quantile
ClusterHeatmap(r2.pAct[ MR_UnWrap(r2.MRs, top = 10) , ], clust = r2.louvain, plotTitle = 'Louvain Clustering: Differentially Activated Proteins')
ClusterHeatmap(r2.pAct[ MR_UnWrap(r2.MRs, top = 10) , ], clust = r2.louvain, plotTitle = 'Louvain Clustering: Differentially Activated Proteins')
ClusterHeatmap(r2.pAct[ MR_UnWrap(r2.MRs, top = 10) , ], clust = r2.louvain, plotTitle = 'Louvain Clustering: Differentially Activated Proteins')
MR_UnWrap(r2.MRs, top = 10)
r2.MRs$`1`
MR_UnWrap(r2.MRs, top = 10)
head(r2.MRs$`1`)
dat.mat <- r2.pAct[ MR_UnWrap(r2.MRs, top = 10) , ]
clust <- r2.louvain
sorted.cells <- sort(clust)
pheatmap.mat <- dat.mat[, names(sorted.cells)]
num.breaks <- 25
if (quantile) {
mat.breaks <- QuantileBreaks(pheatmap.mat, num.breaks)
} else {
mat.breaks <- seq(min(dat.mat), max(dat.mat), (max(dat.mat) - min(dat.mat)) / num.breaks)
}
annot_color <- ClusterColors(length(unique(clust))); names(annot_color) <- sort(unique(clust))
mat.breaks <- QuantileBreaks(pheatmap.mat, num.breaks)
pheatmap(pheatmap.mat, annotation_col = data.frame('Cluster' = as.factor(clust)),
annotation_colors = list('Cluster' = annot_color),
main = 'fuck', width = 6, height = 8, scale = 'row', fontsize_row = 4,
cluster_rows = FALSE, cluster_cols = FALSE, show_rownames = TRUE, show_colnames = FALSE,
color = colorRampPalette(rev(brewer.pal(11, 'RdBu')))(num.breaks), breaks = mat.breaks)
hist(dat.mat)
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/viper-utils.R')
ClusterHeatmap(r2.pAct[ MR_UnWrap(r2.MRs, top = 10) , ], clust = r2.louvain, plotTitle = 'Louvain Clustering: Differentially Activated Proteins')
ClusterHeatmap(r2.pAct[ MR_UnWrap(r2.MRs, top = 10) , ], clust = r2.louvain, plotTitle = 'Louvain Clustering: Differentially Activated Proteins')
r2.MRs.new <- r2.MRs
setwd('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/')
r1.pAct <- readRDS('tutorial/pbmc_r1-pAct.rds')
r2.pAct <- readRDS('tutorial/pbmc_r2-pAct.rds')
r2.MRs <- readRDS('tutorial/pbmc_r2-MRs.rds')
r2.pAct <- Ensemble2GeneName(r2.pAct)
ClusterHeatmap(r2.pAct[ MR_UnWrap(r2.MRs, top = 10) , ], clust = r2.louvain, plotTitle = 'Louvain Clustering: Differentially Activated Proteins')
r2.MRs
ClusterHeatmap(r2.pAct[ MR_UnWrap(r2.MRs.new, top = 10) , ], clust = r2.louvain, plotTitle = 'Louvain Clustering: Differentially Activated Proteins')
MR_UnWrap(r2.MRs.new, top = 10)
MR_UnWrap(r2.MRs, top = 10)
head(r2.MRs$`1`)
head(r2.MRs.new$`1`)
tail(r2.MRs.new$`1`, 5)
head(r2.MRs$`1`, 10)
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/viper-utils.R')
r2.MRs.new2 <- BTTestMRs(r2.pAct, r2.louvain, bootstrap.num = 10)
source('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/functions/viper-utils.R')
r2.MRs.new2 <- BTTestMRs(r2.pAct, r2.louvain, bootstrap.num = 10)
MR_UnWrap(r2.MRs.new2, top = 10)
head(r2.MRs.new$`1`)
head(r2.MRs.new2$`1`)
head(r2.MRs$`1`)
ClusterHeatmap(r2.pAct[ MR_UnWrap(r2.MRs.new2, top = 10) , ], clust = r2.louvain, plotTitle = 'Louvain Clustering: Differentially Activated Proteins')
ClusterHeatmap(r2.pAct[ MR_UnWrap(r2.MRs.new2, top = 10) , ], clust = r2.louvain, plotTitle = 'Louvain Clustering: Differentially Activated Proteins')
r2.MRs <- BTTestMRs(r2.pAct, r2.louvain)
ClusterHeatmap(r2.pAct[ MR_UnWrap(r2.MRs, top = 10) , ], clust = r2.louvain, plotTitle = 'Louvain Clustering: Differentially Activated Proteins')
markers <- c('CCR7', 'CD8A', 'MS4A1', 'PPBP', 'MS4A7', 'IL7R', 'CD14', 'FCER1A', 'FCGR3A')
MarkerGrid(r2.cbcUMAP, r2.louvain, r2.pAct, markers, 'PBMC Marker Activity')
library(rmarkdown)
setwd('C://Users/lvlah/linux/ac_lab/single-cell-pipeline/')
render('PISCES_walkthrough.Rmd', output_format = 'html')
render('PISCES_walkthrough.Rmd', output_format = 'html_document')
saveRDS(r2.MRs, file = 'tutorial/pbmc_r2-MRs.rds')