-
Notifications
You must be signed in to change notification settings - Fork 5
/
monocle_seurat_input_v1.R
66 lines (45 loc) · 1.85 KB
/
monocle_seurat_input_v1.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
### monocle for timecourse data
### use seurat normalized and transformed data as input into monocle generated in prepare_for_monocle_v1.R
library(Seurat)
library(monocle)
filename = "path_to_seurat_object.Rdata"
output = "~/Documents/"
load(filename)
####### Expression matrix #########
# rename seurat object
obj <-my.pancreas
#expression matrix - use scaled data, which is regressed, normalized
exprs <- [email protected]
## use variable genes determined by seurat##
var_genes <- [email protected]
############# PhenoData ################
## AnnotatedDataFrame object, where rows are cells, and columns are cell attributes
pheno.data <- [email protected]
######### FeatureData #################
# AnnotatedDataFrame object, where rows are features (e.g. genes), and columns are gene attributes, such as biotype, gc content, etc
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 <- as.matrix(exprs)
## use gaussianff family since inputting normalized, transformed values
HSMM <- newCellDataSet(
HSMM_expr_matrix,
phenoData=pd,
featureData=fd,
# lowerDetectionLimit=0.5,
expressionFamily=gaussianff())
ordering_genes <- var_genes
HSMM <- setOrderingFilter(HSMM, ordering_genes)
print(dim(exprs(HSMM)))
## reduce dimension - do not normalize or include pseudo count. do use monocle scaling
HSMM <- reduceDimension(HSMM,norm_method="none", reduction_method="DDRTree",max_components=2,scaling=TRUE,verbose=TRUE,pseudo_expr=0)
## order cells
HSMM <- orderCells(HSMM)
pdf(output_trajectory)
plot_cell_trajectory(HSMM, color_by="Labels")
dev.off()
save(HSMM, file=output)