forked from animint/animint2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-renderer3-roc.R
118 lines (109 loc) · 4.45 KB
/
test-renderer3-roc.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
acontext("TestROC")
data(TestROC, package="animint2")
##RColorBrewer::display.brewer.all()
## x <- RColorBrewer::brewer.pal(12, "Paired")
## cat(deparse(x))
algo.colors <-
c(hmcan="#A6CEE3",
hmcan.broad="#1F78B4",
PeakSegJoint="grey40",
macs="#FDBF6F",
macs.broad="#FF7F00")
path.before.params <- list(
title="Test ROC curves, predicted peaks and errors",
roc=a_plot()+
a_geom_path(a_aes(FPR, TPR, group=Model, key=Model, color=Model),
data=TestROC$roc)+
a_scale_color_manual(values=algo.colors, breaks=names(algo.colors))+
a_geom_point(a_aes(FPR, TPR, color=Model, key=paste(model, parameter),
size=parameter,
fill=parameter),
shape=21,
data=subset(TestROC$parameters, parameter=="learned"))+
a_geom_point(a_aes(FPR, TPR, color=Model, key=paste(model, parameter),
size=parameter,
fill=parameter),
shape=21,
data=subset(TestROC$parameters, parameter=="default"))+
a_geom_point(a_aes(FPR, TPR, color=Model,
key=ModelParam),
clickSelects="ModelParam",
size=4,
alpha=0.9,
data=subset(TestROC$roc, same.as.prev==FALSE))+
a_scale_fill_manual(values=c(default="black", learned="white"))+
a_scale_size_manual(values=c(default=7, learned=10))+
a_scale_shape_manual(values=c(default=20, learned=1))+
a_coord_equal()+
a_theme_grey()+
a_scale_x_continuous(paste(
"False positive rate in test labels",
"= Probability(peak | no peak)"),
breaks=seq(0, 1, by=0.2))+
a_scale_y_continuous(paste(
"True positive rate in test labels",
"= Probability(peak | peak)"),
breaks=seq(0, 1, by=0.2))+
a_theme(panel.margin=grid::unit(0, "lines")),
first=list(ModelParam="PeakSegJoint -0.8"))
test_that("path before params, 5 paths rendered", {
info <- animint2HTML(path.before.params)
entry.list <- info$plots$roc$legend$Model$entries
linetype.computed <- sapply(entry.list, "[[", "pathlinetype")
linetype.expected <- rep(1, 5)
expect_identical(linetype.computed, linetype.expected)
path.list <- getNodeSet(info$html, '//g[@class="a_geom1_path_roc"]//path')
expect_equal(length(path.list), 5)
stroke.vec <- getStyleValue(
info$html, '//td[@class="roc_legend"]//line', "stroke")
expect_color(stroke.vec, algo.colors)
})
path.after.params <- list(
title="Test ROC curves, predicted peaks and errors",
roc=a_plot()+
a_geom_point(a_aes(FPR, TPR, color=Model, key=paste(model, parameter),
size=parameter,
fill=parameter),
shape=21,
data=subset(TestROC$parameters, parameter=="learned"))+
a_geom_point(a_aes(FPR, TPR, color=Model, key=paste(model, parameter),
size=parameter,
fill=parameter),
shape=21,
data=subset(TestROC$parameters, parameter=="default"))+
a_scale_color_manual(values=algo.colors, breaks=names(algo.colors))+
a_geom_path(a_aes(FPR, TPR, group=Model, key=Model, color=Model),
data=TestROC$roc)+
a_geom_point(a_aes(FPR, TPR, color=Model,
key=ModelParam),
clickSelects="ModelParam",
size=4,
alpha=0.9,
data=subset(TestROC$roc, same.as.prev==FALSE))+
a_scale_fill_manual(values=c(default="black", learned="white"))+
a_scale_size_manual(values=c(default=7, learned=10))+
a_scale_shape_manual(values=c(default=20, learned=1))+
a_coord_equal()+
a_theme_grey()+
a_scale_x_continuous(paste(
"False positive rate in test labels",
"= Probability(peak | no peak)"),
breaks=seq(0, 1, by=0.2))+
a_scale_y_continuous(paste(
"True positive rate in test labels",
"= Probability(peak | peak)"),
breaks=seq(0, 1, by=0.2))+
a_theme(panel.margin=grid::unit(0, "lines")),
first=list(ModelParam="PeakSegJoint -0.8"))
test_that("path after params, 5 paths rendered", {
info <- animint2HTML(path.after.params)
entry.list <- info$plots$roc$legend$Model$entries
linetype.computed <- sapply(entry.list, "[[", "pathlinetype")
linetype.expected <- rep(1, 5)
expect_identical(linetype.computed, linetype.expected)
path.list <- getNodeSet(info$html, '//g[@class="a_geom3_path_roc"]//path')
expect_equal(length(path.list), 5)
stroke.vec <- getStyleValue(
info$html, '//td[@class="roc_legend"]//line', "stroke")
expect_color(stroke.vec, algo.colors)
})