-
Notifications
You must be signed in to change notification settings - Fork 5
/
monocle_lineage_trace.R
69 lines (48 loc) · 1.86 KB
/
monocle_lineage_trace.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
library(monocle) ## version 2.6
library(Seurat) ## version 2.3.0
output= "~/Documents/"
filename = "example"
## rename seurat object to seur_ob
seur_ob = seurat_object
seur_ob = UpdateSeuratObject(seur_ob)
## create CDS from seurat object data
# expression Matrix - select only cells of interest from seurat_ob@data
exprs <- [email protected]
cells <- colnames(seur_ob@data)
exprs_mat <- exprs[,match(cells, colnames(exprs))]
# check number of cells from both
print("raw data dim:")
print(dim(exprs))
print("filtered data dim:")
print(dim(exprs_mat))
## create phenodata from meta data (@data.info for seurat v1)
pheno.data = [email protected]
## create feature data
genes <- data.frame(gene_short_name = rownames(exprs))
rownames(genes) <- rownames(exprs)
# Make CellDataSet object
pd <- new("AnnotatedDataFrame", data=pheno.data)
fd <- new("AnnotatedDataFrame", data=genes)
HSMM_expr_matrix <- exprs_mat
cds <- newCellDataSet(as(HSMM_expr_matrix,"sparseMatrix"),
phenoData=pd,
featureData=fd,
lowerDetectionLimit=0.5,
expressionFamily=negbinomial.size())
HSMM <- estimateSizeFactors(cds)
HSMM <- estimateDispersions(HSMM)
## use seurat determined variable genes for ordering
seurat_var_genes = [email protected]
HSMM_seur_var = setOrderingFilter(HSMM, seurat_var_genes)
pdf(paste(output,filename,"_seur_var_genes.pdf",sep=""))
plot_ordering_genes(HSMM_seur_var)
dev.off()
## reduce dimensionality with DDRTree, regression on nUMI
HSMM_seur_var <- reduceDimension(HSMM_seur_var, reduction_method="DDRTree",max_components = 2,residualModelFormulaStr = "~nUMI")
## order cells
HSMM_seur_var <- orderCells(HSMM_seur_var)
## print trajectories
pdf(paste(output,filename,"_monocle_traj.pdf",sep=""))
plot_cell_trajectory(HSMM_seur_var, color_by = "Pseudotime",cell_size = 4,show_branch_points = T)
dev.off()
save(HSMM_seur_var, file=paste(output,filename,"_monocle.Rdata",sep=""))