-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDownsamplingBatchCorrection.R
More file actions
210 lines (162 loc) · 6.34 KB
/
DownsamplingBatchCorrection.R
File metadata and controls
210 lines (162 loc) · 6.34 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
library(here)
source("Combat_HKfunctions.R")
source("DownSampleFunctions.R")
source("LineageFunctions.R")
library(psych)
library(sva)
library(ggfortify)
library(e1071)
library(scales)
library(stringr)
library(splines2)
library(RColorBrewer)
library(colorspace)
library(preprocessCore)
library(aricode)
library(cluster)
library(doParallel)
registerDoParallel(cores=24)
seed <- 1809
set.seed(seed)
dir.Results<-"./Results"
dir.Input<-"/path/to/Figshare"
saveObj<-function(objTS,filePrefix=dir.Results){
save(objTS,file=paste0(filePrefix,'/',deparse(substitute(objTS)),".Rdata"))
}
cmp<-read.csv(paste0(dir.Input,"/model_list_latest.csv"),header=T,stringsAsFactors = F)
cmp$mn<-make.names(cmp$model_name)
cmpAnnot<-cmp
cmp2<-cmp
cmp2$model_id<-cmp2$BROAD_ID
cmpAnnot<-rbind(cmpAnnot,cmp2)
cmpAnnot<-cmpAnnot[!duplicated(cmpAnnot$model_id),]
rownames(cmpAnnot)<-cmpAnnot$model_id
B20Q2<-read.csv(paste0(dir.Input,"/Achilles_replicate_map.csv"),header=T,stringsAsFactors = F)
#this is fine with cmp incomplete as cmp does include Broad_ids for all crispr'd cell lines
OverlapData<-cmp[cmp$BROAD_ID%in%B20Q2$DepMap_ID,]
OverlapData<-OverlapData[OverlapData$BROAD_ID!="",]
OverlapData<-OverlapData[OverlapData$crispr_ko_data=="True",]
OverlapData$bmn<-make.names(OverlapData$BROAD_ID)
OverlapData$Bmn<-paste0(OverlapData$mn,"---Broad")
OverlapData$Smn<-paste0(OverlapData$mn,"---Sanger")
rmcl<-read.csv(file=paste0(dir.Results,'/Drop12NABroadCL.csv'),stringsAsFactors = FALSE)
OverlapData<-OverlapData[!OverlapData$BROAD_ID%in%rmcl[,1],]
###Load CRISPRcleanR and SQ processed data ###
load(file=paste0(dir.Results,"/SQsangerCCRoverlap.Rdata"))
load(file=paste0(dir.Results,"/SQbroadCCRoverlap.Rdata"))
OverlapData<-OverlapData[OverlapData$Smn%in%colnames(SangerScreenC),]
### Original overlap between CRISPRcleanR processed data ####
OrigCorrection<-combatadj(BroadScreenC,SangerScreenC)
mergedData<-OrigCorrection$mergedData
#load in the full dataset SQ processed with CCR:
load(file=paste0(dir.Results,"/SQsangerCCRall.Rdata"))
load(file=paste0(dir.Results,"/SQbroadCCRall.Rdata"))
#all data corrected:
CcrAllsq<-readRDS(file=paste0(dir.Results,"/CCR_SQ_Combat_All.Rds"))
DownSamples=seq(0.05,0.8,by=0.05)
corCCR1<-list()
eucCCR1<-list()
LineageCCR1<-list()
BatchCCR1<-list()
multiResultClass <- function(corR=NULL,euc=NULL,Lineage=NULL,Batch=NULL)
{
me <- list(
corR = corR,
euc = euc,
Lineage=Lineage,
Batch=Batch
)
## Set the name for the class
class(me) <- append(class(me),"multiResultClass")
return(me)
}
###Load CCR + JACKS processed data###
load(file=paste0(dir.Results,"/SQsangerJACKSoverlap.Rdata"))
load(file=paste0(dir.Results,"/SQbroadJACKSoverlap.Rdata"))
OrigCorrectionJacksD<-combatadj(BroadScreenJacks,SangerScreenJacks)
#all data:
load(file=paste0(dir.Results,"/SQsangerJACKSall.Rdata"))
load(file=paste0(dir.Results,"/SQbroadJACKSall.Rdata"))
CcrAllsqJ<-readRDS(file=paste0(dir.Results,"/CCR_SQ_Combat_All_JACKS.Rds"))
###Load CERES processed data ###
load(file=paste0(dir.Results,"/SQsangerCERESoverlap.Rdata"))
load(file=paste0(dir.Results,"/SQbroadCERESoverlap.Rdata"))
#change so that each correction is applied to all data and then there will also be no difference in numbers of correlations across the down samples
OrigCorrectionCERES<-combatadj(BroadScreenCeres,SangerScreenCeres)
#for CERES need different annotation file:
OverlapDataCeres<-OverlapData
OverlapDataCeres$Smn<-paste0(OverlapData$BROAD_ID,"---Sanger")
OverlapDataCeres$Bmn<-paste0(OverlapData$BROAD_ID,"---Broad")
OverlapDataCeres$model_id<-OverlapDataCeres$BROAD_ID
#All data SQ corrected and CERES processed
load(file=paste0(dir.Results,"/SQsangerCERESall.Rdata"))
load(file=paste0(dir.Results,"/SQbroadCERESall.Rdata"))
#result with all data:
CeresAllsq<-readRDS(file=paste0(dir.Results,"/CERES_SQ_Combat_All.Rds"))
DownSamplesL=c(0.3,0.6,0.9)
multiResultClass2 <- function(corR=NULL,euc=NULL,Batch=NULL)
{
me <- list(
corR = corR,
euc = euc,
Batch=Batch
)
## Set the name for the class
class(me) <- append(class(me),"multiResultClass")
return(me)
}
corCCR2<-list()
eucCCR2<-list()
OverlapDataSubtype<-OverlapData[OverlapData$tissue%in%c("Lung"),]
BatchCCR2<-foreach(i=1:length(DownSamplesL))%dopar%{
print(paste("CCR2",i))
result<-multiResultClass2()
CombatDS_CCR<-batch_downsample(mergedData,empBayes=TRUE,annotation=OverlapDataSubtype,numberSamples=50,DownRange=DownSamplesL[i],allBroad=BroadScreenA,allSanger=SangerScreenA,OrigCorrection=CcrAllsq,cmpAnnot)
result$corR<-CombatDS_CCR$corRes
result$euc<-CombatDS_CCR$eucRes
result$Batch<-CombatDS_CCR$clusterB
return(result)
}
corCCR2<-lapply(BatchCCR2,function(x) x$corR)
eucCCR2<-lapply(BatchCCR2,function(x) x$euc)
BatchCCR2<-lapply(BatchCCR2,function(x) x$Batch)
saveObj(corCCR2)
saveObj(eucCCR2)
saveObj(BatchCCR2)
corCCRJ2<-list()
eucCCRJ2<-list()
BatchCCRJ2<-list()
OverlapDataSubtype<-OverlapData[OverlapData$tissue%in%c("Lung"),]
BatchCCRJ2<-foreach(i=1:length(DownSamplesL))%dopar%{
print(paste("CCRJ2",i))
result<-multiResultClass2()
CombatDS_CCRJ<-batch_downsample(OrigCorrectionJacksD$mergedData,empBayes=TRUE,annotation=OverlapDataSubtype,numberSamples=50,DownRange=DownSamplesL[i],allBroad=JBroadScreenA,allSanger=JSangerScreenA,OrigCorrection=CcrAllsqJ,cmpAnnot)
result$corR<-CombatDS_CCRJ$corRes
result$euc<-CombatDS_CCRJ$eucRes
result$Batch<-CombatDS_CCRJ$clusterB
return(result)
}
corCCRJ2<-lapply(BatchCCRJ2,function(x) x$corR)
eucCCRJ2<-lapply(BatchCCRJ2,function(x) x$euc)
BatchCCRJ2<-lapply(BatchCCRJ2,function(x) x$Batch)
saveObj(corCCRJ2)
saveObj(eucCCRJ2)
saveObj(BatchCCRJ2)
corCERES2<-list()
eucCERES2<-list()
OverlapDataCeresSub<-OverlapDataCeres[OverlapDataCeres$tissue=="Lung",]
BatchCERES2<-foreach(i=1:length(DownSamplesL))%dopar%{
print(paste("CERES2",i))
result<-multiResultClass2()
CombatDS_CERES<-batch_downsample(OrigCorrectionCERES$mergedData,empBayes=TRUE,annotation=OverlapDataCeresSub,numberSamples=50,DownRange=DownSamplesL[i],allBroad=BroadScreenCeresA,allSanger=SangerScreenCeresA,OrigCorrection=CeresAllsq,cmpAnnot)
result$corR<-CombatDS_CERES$corRes
result$euc<-CombatDS_CERES$eucRes
result$Batch<-CombatDS_CERES$clusterB
return(result)
}
corCERES2<-lapply(BatchCERES2,function(x) x$corR)
eucCERES2<-lapply(BatchCERES2,function(x) x$euc)
BatchCERES2<-lapply(BatchCERES2,function(x) x$Batch)
saveObj(corCERES2)
saveObj(eucCERES2)
saveObj(BatchCERES2)