-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path200627_lvl4_umap.R
151 lines (132 loc) · 5.1 KB
/
200627_lvl4_umap.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
library(cmapR)
library(umap)
setwd("~/Dropbox/GDB/CMapCorr/")
if (exists("lvl4_data")) {
} else if (file.exists("~/Dropbox/GDB_archive/CMapCorr_files/lvl4_inputs.RData")) {
load("~/Dropbox/GDB_archive/CMapCorr_files/lvl4_inputs.RData")
} else {
source("lvl4_inputs.R")
}
# Not including controls in UMAP data because they're meaningless
# UMAP ----
if (file.exists("~/Dropbox/GDB/CMapCorr_files/200630_lvl4_umap.RData")) {
load("~/Dropbox/GDB/CMapCorr_files/200630_lvl4_umap.RData")
} else {
temp_param <- umap.defaults
temp_param$n_neighbors <- 30
temp_param$metric <- "cosine"
temp_param$min_dist <- 0.2
temp_param$n_epochs <- 500
lvl4_umap <- umap(t(lvl4_data@mat),config=temp_param)
save(lvl4_umap,file="~/Dropbox/GDB/CMapCorr_files/200630_lvl4_umap.RData")
}
if (file.exists("~/Dropbox/GDB/CMapCorr_files/200630_lvl4_umap_lig16.RData")) {
load("~/Dropbox/GDB/CMapCorr_files/200630_lvl4_umap_lig16.RData")
} else {
temp_param <- umap.defaults
temp_param$n_neighbors <- 30
temp_param$metric <- "cosine"
temp_param$min_dist <- 0.2
temp_param$n_epochs <- 500
lvl4_umap_lig16 <- umap(t(lvl4_data@mat[,lvl4_data@cdesc$pert_iname %in% lig16]),config=temp_param)
save(lvl4_umap_lig16,file="~/Dropbox/GDB/CMapCorr_files/200630_lvl4_umap_lig16.RData")
}
# UMAP by CT ----
if (file.exists("~/Dropbox/GDB/CMapCorr_files/200630_lvl4_ctUMAP.RData")) {
load("~/Dropbox/GDB/CMapCorr_files/200630_lvl4_ctUMAP.RData")
} else {
temp_param <- umap.defaults
temp_param$n_neighbors <- 30
temp_param$metric <- "cosine"
temp_param$min_dist <- 0.2
temp_param$n_epochs <- 500
lvl4_ctUMAP <- list()
for (CT in ct14) {
message(paste0(which(CT == ct14),"/",length(ct14)))
temp_tx <- rownames(lvl4_data@cdesc[lvl4_data@cdesc$cell_id == CT &
lvl4_data@cdesc$pert_iname %in% lig16,])
if (temp_tx < 1000) {
temp_param$n_neighbors <- 5
} else {
temp_param$n_neighbors <- 30
}
lvl4_ctUMAP[[CT]] <- umap(t(lvl4_data@mat[,temp_tx]),config=temp_param)
}
save(lvl4_ctUMAP,file="~/Dropbox/GDB/CMapCorr_files/200630_lvl4_ctUMAP.RData")
}
# UMAP per LIG ----
if (file.exists("~/Dropbox/GDB/CMapCorr_files/200630_lvl4_ligUMAP.RData")) {
load("~/Dropbox/GDB/CMapCorr_files/200630_lvl4_ligUMAP.RData")
} else {
lvl4_ligUMAP <- list()
temp_param <- umap.defaults
temp_param$n_neighbors <- 30
temp_param$metric <- "cosine"
temp_param$min_dist <- 0.2
temp_param$n_epochs <- 500
for (LIG in lig16) {
message(paste0(which(LIG == lig16),"/",length(lig16)))
temp_tx <- rownames(lvl4_data@cdesc[lvl4_data@cdesc$pert_iname == LIG,])
lvl4_ligUMAP[[LIG]] <- umap(t(lvl4_data@mat[,temp_tx]),config=temp_param)
}
save(lvl4_ligUMAP,file="~/Dropbox/GDB/CMapCorr_files/200630_lvl4_ligUMAP.RData")
}
# WITH ALL GENES ----
rm(list=ls())
if (exists("lvl4_data_all")) {
} else if (file.exists("~/Dropbox/GDB_archive/CMapCorr_files/lvl4_inputs_allgenes.RData")) {
load("~/Dropbox/GDB_archive/CMapCorr_files/lvl4_inputs_allgenes.RData")
} else {
source("lvl4_inputs_allgenes.R")
}
if (file.exists("~/Dropbox/GDB/CMapCorr_files/200721_lvl4all_umap_lig16.RData")) {
load("~/Dropbox/GDB/CMapCorr_files/200721_lvl4all_umap_lig16.RData")
} else {
temp_param <- umap.defaults
temp_param$n_neighbors <- 30
temp_param$metric <- "cosine"
temp_param$min_dist <- 0.2
temp_param$n_epochs <- 500
lvl4all_umap_lig16 <- umap(t(lvl4_data_all@mat[,lvl4_data_all@cdesc$pert_iname %in% lig16]),config=temp_param)
save(lvl4all_umap_lig16,file="~/Dropbox/GDB/CMapCorr_files/200721_lvl4all_umap_lig16.RData")
}
# UMAP by CT ----
if (file.exists("~/Dropbox/GDB/CMapCorr_files/200721_lvl4all_ctUMAP.RData")) {
load("~/Dropbox/GDB/CMapCorr_files/200721_lvl4all_ctUMAP.RData")
} else {
temp_param <- umap.defaults
temp_param$n_neighbors <- 30
temp_param$metric <- "cosine"
temp_param$min_dist <- 0.2
temp_param$n_epochs <- 500
lvl4_ctUMAP <- list()
for (CT in ct14) {
message(paste0(which(CT == ct14),"/",length(ct14)))
temp_tx <- rownames(lvl4_data_all@cdesc[lvl4_data_all@cdesc$cell_id == CT &
lvl4_data_all@cdesc$pert_iname %in% lig16,])
if (temp_tx < 1000) {
temp_param$n_neighbors <- 5
} else {
temp_param$n_neighbors <- 30
}
lvl4_ctUMAP[[CT]] <- umap(t(lvl4_data_all@mat[,temp_tx]),config=temp_param)
}
save(lvl4_ctUMAP,file="~/Dropbox/GDB/CMapCorr_files/200721_lvl4all_ctUMAP.RData")
}
# UMAP per LIG ----
if (file.exists("~/Dropbox/GDB/CMapCorr_files/200721_lvl4all_ligUMAP.RData")) {
load("~/Dropbox/GDB/CMapCorr_files/200721_lvl4all_ligUMAP.RData")
} else {
lvl4_ligUMAP <- list()
temp_param <- umap.defaults
temp_param$n_neighbors <- 30
temp_param$metric <- "cosine"
temp_param$min_dist <- 0.2
temp_param$n_epochs <- 500
for (LIG in lig16) {
message(paste0(which(LIG == lig16),"/",length(lig16)))
temp_tx <- rownames(lvl4_data_all@cdesc[lvl4_data_all@cdesc$pert_iname == LIG,])
lvl4_ligUMAP[[LIG]] <- umap(t(lvl4_data_all@mat[,temp_tx]),config=temp_param)
}
save(lvl4_ligUMAP,file="~/Dropbox/GDB/CMapCorr_files/200721_lvl4all_ligUMAP.RData")
}