-
Notifications
You must be signed in to change notification settings - Fork 0
/
export_prediction_conditons.R
162 lines (103 loc) · 5.48 KB
/
export_prediction_conditons.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
152
153
154
155
156
157
158
159
# export files that shows conditions to be predicted.
library(tidyverse)
library(DBI)
library(RSQLite)
library(progress)
target_folder = "./challenge_data"
### Export single cell phospho data --------------------------------------------
con <- dbConnect(RSQLite::SQLite(), "./data/cleaned_single_cell_data/single_cell_dream_cls.sqlite")
median_data <- read_csv("./challenge_data/median_phospho/median_phospho_data.csv")
cell_lines <- dbListTables(con)
cell_lines = setdiff(cell_lines,"HCC70_2")
cell_line_sheet <- readxl::read_excel("./data/cell_line_distribution.xlsx",sheet = 1,range = "A1:I69")
bar = progress::progress_bar$new(format = " Processing [:bar] :percent eta: :eta",
total = length(cell_lines))
current_cell_line = cell_lines[[1]]
current_cell_line = cell_lines[[3]]
current_cell_line = cell_lines[[2]]
current_cell_line = cell_lines[[4]]
current_cell_line = cell_lines[[8]]
for(current_cell_line in cell_lines){
bar$tick()
print(paste("reading ",current_cell_line))
purpose = cell_line_sheet %>% filter(cell_line == current_cell_line)
purpose[1,as.logical(is.na(purpose[1,]))] = "" # set NA to empty, to be used in logical evaluation
# load cell_line
sc_data = dbReadTable(con, dbQuoteIdentifier(con,current_cell_line)) %>%
as_tibble()
stopifnot(length(unique(sc_data$cell_line))==1) # make sure there is exactly 1 cell-line there
# process according to the purpose of the cell-line.
public_data = sc_data
if(purpose$AIM_1_1 =="test"){
# 1. remove imTOR condition in the public_data from all cell-lines.
public_data <- public_data %>% filter(treatment!="imTOR")
prediction_templates = public_data %>% select(cell_line,treatment,time,cellID,fileID,c("p.ERK", "p.Akt.Ser473.","p.S6","p.HER2", "p.PLCg2")) %>%
mutate_at(c("p.ERK", "p.Akt.Ser473.","p.S6","p.HER2", "p.PLCg2"),~NA_real_)
# write out with 6 digit precision
write_csv(prediction_templates,
path = file.path(target_folder,'prediction_templates',paste0("AIM_11_",current_cell_line,".csv")))
}else if(purpose$AIM_1_2_1 == "test"){
# Predict cells in iPKC conditions
# 1. remove imTOR condition in the public_data from all cell-lines.
public_data <- public_data %>% filter(treatment!="imTOR")
reporters = setdiff(colnames(public_data),c("treatment","cell_line","time","cellID","fileID","p.HER2","p.PLCg2"))
# we find first the unique conditions
# then we expand each conditions with cellID: 1-10k
if(current_cell_line %in% c("MDAMB468","MCF12A","BT483")){
public_data = public_data %>% filter(treatment=="iEGFR")
}else if(current_cell_line %in% c("184B5","ZR751","HCC202")){
public_data = public_data %>% filter(treatment=="iMEK")
}else if(current_cell_line %in% c("UACC3199","SKBR3","MDAMB231")){
public_data = public_data %>% filter(treatment=="iPI3K")
}else if(current_cell_line %in% c("HCC1806","Hs578T","HCC1428")){
public_data = public_data %>% filter(treatment=="iPKC")
}
prediction_templates = public_data %>%
select(cell_line, treatment,time, -cellID,-fileID,reporters) %>%
group_by(cell_line,treatment,time) %>% mutate_at(reporters,~NA_real_) %>%unique() %>%
nest() %>% mutate(extended_data = map(data,function(data){
data.frame(cellID = 1:10000,data)
})) %>% unnest(extended_data)
# write out with 6 digit precision
write_csv(prediction_templates,
path = file.path(target_folder,'prediction_templates',paste0("AIM_121_", current_cell_line,".csv")))
}else if(purpose$AIM_1_2_2 == "test"){
reporters = setdiff(colnames(public_data),c("treatment","cell_line","time","cellID","fileID","p.HER2","p.PLCg2"))
# we find first the unique conditions
# then we expand each conditions with cellID: 1-10k
prediction_templates = public_data %>% filter(treatment=="imTOR") %>%
select(cell_line, treatment,time, -cellID,-fileID,reporters) %>%
group_by(cell_line,treatment,time) %>% mutate_at(reporters,~NA_real_) %>%unique() %>%
nest() %>% mutate(extended_data = map(data,function(data){
data.frame(cellID = 1:10000,data)
})) %>% unnest(extended_data)
# write out with 6 digit precision
write_csv(prediction_templates,
path = file.path(target_folder,'prediction_templates',paste0("AIM_122_", current_cell_line,".csv")))
}else if(purpose$AIM2 == "test"){
# nothing to do.
# this challenge is handled in export_dream_median_phospho.R
}
}
dbDisconnect(con)
##### Aggregate files ----------------------------------------------------------
# previously we exported the validation per cell-line, now we import them and aggregate.
# AIM 1.1
temp_files = list.files(file.path(target_folder,"prediction_templates"),pattern = "AIM_11_",full.names = T)
template_data = temp_files %>%
map(read_csv) %>% bind_rows()
# here we added the glob_cellID
write_csv(template_data,"./challenge_data/prediction_templates/AIM_11_template_data.csv")
file.remove(temp_files )
# AIM 1.2.1
temp_files = list.files(file.path(target_folder,"prediction_templates"),pattern = "AIM_121_",full.names = T)
template_data = temp_files %>%
map(read_csv) %>% bind_rows()
write_csv(template_data,"./challenge_data/prediction_templates/AIM_121_template_data.csv")
file.remove(temp_files )
# AIM 1.2.2
temp_files = list.files(file.path(target_folder,"prediction_templates"),pattern = "AIM_122_",full.names = T)
template_data = temp_files %>%
map(read_csv) %>% bind_rows()
write_csv(template_data,"./challenge_data/prediction_templates/AIM_122_template_data.csv")
file.remove(temp_files )