-
Notifications
You must be signed in to change notification settings - Fork 6
/
ch1scoring_fc.R
69 lines (59 loc) · 2.83 KB
/
ch1scoring_fc.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
# ------------------------------------------------------------------------------------
# Description: AZ-Sanger Challenge scoring functions
# Authors: Michael P Menden, Julio Saez-Rodriguez
# ------------------------------------------------------------------------------------
# Get observation format for Subchallenge 1
getObs_ch1 <- function(ls) {
return(data.frame(CELL_LINE=as.character(ls$CELL_LINE),
COMBINATION_ID=as.character(ls$COMBINATION_ID),
OBSERVATION=ls$SYNERGY_SCORE))
}
# Get the drug combinations score of Subchallenge 1
getDrugCombiScore_ch1 <- function(obs, pred, confidence=NA, topX=10) {
R <- c()
obs <- read.csv('<Leaderboard file here>',stringsAsFactors = F)
obs <- getObs_ch1(obs)
pred <- read.csv(pred,stringsAsFactors=F)
pred <- pred[match(paste(obs$CELL_LINE,obs$COMBINATION_ID),paste(pred$CELL_LINE,pred$COMBINATION_ID)),]
pred$COMBINATION_ID <- gsub(" ", "", pred$COMBINATION_ID)
for (i in as.character(unique(obs$COMBINATION_ID))) {
R <- c(R, cor(obs[obs$COMBINATION_ID == i, 'OBSERVATION'],
pred[pred$COMBINATION_ID == i, 'PREDICTION']))
}
#Make NA's in R = 0
R[is.na(R)] = 0
names(R) <- as.character(unique(obs$COMBINATION_ID))
if (all(is.na(confidence)))
return(c(mean=mean(R, na.rm=T),
ste=sd(R, na.rm=T) / sum(!is.na(R)),
n=sum(!is.na(R))))
idx <- sort(confidence$CONFIDENCE, decreasing = T,
index.return=T)$ix[1:round(topX * (length(R) / 100))]
return(c(mean=mean(R[idx], na.rm=T),
ste=sd(R[idx], na.rm=T) / sum(!is.na(R[idx])),
n=sum(!is.na(R[idx]))))
}
# ------------------------------------------------------------------------------------
# Get the global score of Subchallenge 1
# ------------------------------------------------------------------------------------
getGlobalScore_ch1 <- function(obs, pred) {
obs <- read.csv("<Leaderboard file here>", stringsAsFactors=F)
obs <- getObs_ch1(obs)
pred <- read.csv(pred,stringsAsFactors=F)
pred <- pred[match(paste(obs$CELL_LINE,obs$COMBINATION_ID),paste(pred$CELL_LINE,pred$COMBINATION_ID)),]
x = obs$OBSERVATION
y = pred$PREDICTION
agg <- aggregate(OBSERVATION ~ CELL_LINE, obs, median)
z0 <- agg$OBSERVATION[match(obs$CELL_LINE, agg$CELL_LINE)]
agg <- aggregate(OBSERVATION ~ COMBINATION_ID, obs, median)
z1 <- agg$OBSERVATION[match(obs$COMBINATION_ID, agg$COMBINATION_ID)]
parCor <- function(u,v,w) {
numerator = cor(u,v) - cor(u,w) * cor(w,v)
denumerator = sqrt(1-cor(u,w)^2) * sqrt(1-cor(w,v)^2)
return(numerator/denumerator)
}
numerator=parCor(x,y,z1) - parCor(x,z0,z1) * parCor(z0,y,z1)
denumerator= sqrt(1-parCor(x,z0,z1)^2) * sqrt(1-parCor(z0,y,z1)^2)
# partial out the mean of synergy across cell lines and combinationations
return(c(score=numerator/denumerator))
}