-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmonoclewithSeuratobject.R
76 lines (56 loc) · 2.43 KB
/
monoclewithSeuratobject.R
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
#monocle
library(monocle)
######load the seurat object first ######
seuratobject<-readRDS(YOURPATH/SEURATRDSfile)
data <- as(as.matrix(seuratobject@assays$RNA@data), 'sparseMatrix')
pd <- new('AnnotatedDataFrame', data = [email protected])
fData <- data.frame(gene_short_name = row.names(data), row.names = row.names(data))
fd <- new('AnnotatedDataFrame', data = fData)
FibroMono <- newCellDataSet(data,
phenoData = pd,
featureData = fd,expressionFamily = negbinomial.size())
####ESTIMATE DISPERSIONS AND SIZE FACTORS############
FibroMono <- estimateSizeFactors(FibroMono)
FibroMono <- estimateDispersions(FibroMono)
#######FILTER LOW QUALITY GENES/CELLS##########
FibroMono <- detectGenes(FibroMono, min_expr = 0.1)
print(head(fData(FibroMono)))
expressed_genes <- row.names(subset(fData(FibroMono),
num_cells_expressed >= 10))
######DEG TEST##########
diff_test_res <- differentialGeneTest(FibroMono[expressed_genes,],
fullModelFormulaStr = "~timegroup")
ordering_genes <- row.names (subset(diff_test_res, qval < 0.01))
FibroMono<- setOrderingFilter(FibroMono, ordering_genes)
FibroMono <- reduceDimension(FibroMono, max_components = 2,method = 'DDRTree')
FibroMono <- orderCells(FibroMono)
png(filename="Trajectory.png")
plot_ordering_genes(FibroMono)
dev.off()
png(filename="TrajectorybyGroup.png")
plot_cell_trajectory(FibroMono, color_by = "group")
dev.off()
###SIGNIFICANT GENES CHANGING WITH PSEUDOTIME##########
GM_state <- function(cds){
if (length(unique(pData(cds)$State)) > 1){
T0_counts <- table(pData(cds)$State, pData(cds)$Hours)[,"0"]
return(as.numeric(names(T0_counts)[which
(T0_counts == max(T0_counts))]))
} else {
return (1)
}
}
diff_test_res <- differentialGeneTest(FibroMono[marker_genes,],
fullModelFormulaStr = "~sm.ns(Pseudotime)")
sig_gene_names <- row.names(subset(diff_test_res, qval < 0.1))
FibroMono <- orderCells(FibroMono, root_state = GM_state(FibroMono))
###PLOT####
png(filename="TrajectorybyPSEUDOTIME.png")
plot_cell_trajectory(FibroMono, color_by = "Pseudotime")
dev.off()
png(filename="PSEUDOTIMEHEATMAP.png")
plot_pseudotime_heatmap(FibroMono_myo[sig_gene_names,],
num_clusters = 3,
cores = 1,
show_rownames = T)
dev.off()