-
Notifications
You must be signed in to change notification settings - Fork 0
/
ISSCR_2019_methods.R
139 lines (104 loc) · 3.88 KB
/
ISSCR_2019_methods.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
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
# package loading, installation----
library(devtools)
devtools::install_github("dynverse/dyno", force=TRUE, ref = 'master')
devtools::install_github("dynverse/dynmethods", force=TRUE, ref = 'master')
devtools::install_github("dynverse/dynplot", force=TRUE, ref = 'master')
devtools::install_github("dynverse/dynutils", force=TRUE, ref = 'master')
devtools::install_github("dynverse/dynwrap", force=TRUE, ref = 'master')
devtools::install_github("dynverse/dynguidelines", force=TRUE, ref = 'master')
devtools::install_github("dynverse/dynfeature", force=TRUE, ref = 'master')
library(dyno)
library(tidyverse)
library(data.table)
options(rgl.useNULL=TRUE)
.rs.restartR()
library("plot3Drgl")
# load raw data ----
load("/Volumes/ncatssctl/NGS_related/ddSeq/Analysis_across_runs/R_scripts/Seurat/Aggr6.Seurat.Object.RData")
# set up task ----
mycolanno <- data.table::fread('/Volumes/ncatssctl/NGS_related/ddSeq/Analysis_across_runs/R_scripts/ddseq-mycolanno.csv')
mycolanno <- subset(mycolanno, mycolanno$Barcode %in% names(as.data.frame(as.matrix(aggr6@data))))
names(mycolanno) <- c('cell_ids', 'cell_info')
grouping <- as.data.frame(mycolanno)
row.names(grouping) <- mycolanno$cell_ids
grouping <- subset(grouping, select=c('cell_info'))
head(grouping)
grouping <- as.vector(grouping)
grouping <- setNames(as.character(grouping$cell_info), row.names(grouping))
subsample.genes <- [email protected]
subsample.genes <- unique(c(subsample.genes, 'ESRG', 'TPBG', 'PAX6', 'DUSP6', 'NANOG', 'POU5F1', 'PRTG'))
aggr6.subset.raw <- as.matrix([email protected])[subsample.genes,]
aggr6.subset.data <- as.matrix(aggr6@data)[subsample.genes,]
task <- wrap_expression(
counts = t(aggr6.subset.raw),
expression= t(aggr6.subset.data),
cell_info = mycolanno
)
# run TI methods -----
model.projectedslingshot <- infer_trajectory(task, 'projected_slingshot')
model.celltree <- infer_trajectory(task, 'celltree_maptpx')
model.scorpius <- infer_trajectory(task, 'scorpius')
model.tscan <- infer_trajectory(task, 'tscan') # works but it labels day 2 as endpoint NPC
model.paga <- infer_trajectory(task, 'paga', verbose=T)
model.embeddr <- infer_trajectory(task, 'embeddr') # ok, it is linear
# plot from each method----
model <- model.embeddr
model <- model.projectedslingshot
model <- model.tscan
model <- model %>% add_root_using_expression(c("DUSP6"), task$expression)
model <- label_milestones_markers(
model,
markers = list(
Neuroprogenitor = c("PAX6", "PRTG", "TPBG"),
Pluripotent=c('DUSP6','NANOG', 'ESRG')
),
task$expression
)
task$grouping <- grouping
model$grouping <- grouping
model <- model %>% add_dimred(dyndimred::dimred_mds, expression_source = task$expression)
plot_dimred(
model,
expression_source = task$expression,
grouping = grouping,
groups=grouping,
color_cells="auto"
)
dynplot::plot_topology(model)
plot_dendro(
model,
expression_source = task$expression,
grouping = grouping,
groups=grouping,
color_cells="auto"
)
plot_dimred(
model,
expression_source = task$expression,
grouping = grouping,
color_cells="milestone"
)
plot_dimred(
model,
expression_source = task$expression,
grouping = grouping,
color_cells="pseudotime"
)
plot_heatmap(
model,
expression_source = task$expression,
grouping = task$grouping,
features_oi = 50
)
# writing out pseudotime values for GSEA use----
pseudotime <- as.data.frame(model$pseudotime)
pseudotime <- as.data.frame(t(pseudotime))
fwrite(pseudotime, '/Volumes/ncatssctl/NGS_related/ddSeq/Analysis_across_runs/GSEA/Aggr6.Embeddr.phenotype.pseudotime.cls', row.names = F, col.names = F, sep='\t', quote=F)
#
all(row.names(task$counts) == row.names(model$pseudotime))
all(row.names(as.matrix([email protected])) == row.names(model$pseudotime))
task$counts[1:5,1:5]
as.matrix([email protected])[1:5,1:5]
# make combined table for bootstrapping pseudotimes -----
# weight pseudotime from each method----
# input to randomforest regression -----