-
Notifications
You must be signed in to change notification settings - Fork 0
/
random_analysis.R
95 lines (77 loc) · 2.79 KB
/
random_analysis.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
randomize.column <- function ( interactions, col ) {
attach(interactions, warn.conflicts = F)
as.list(as.character( sample( unique(col ) ) ) ) -> random.mapping
names(random.mapping) <- as.character(unique(col))
list2env(random.mapping) -> random.mapping
lapply(as.character(col),
function(x) {
random.mapping[[x]]
}
) %>% unlist-> random.column
detach()
return(random.column)
}
random.by.analysis <- function( sub.table,
rand.col, list1,
norm.col, list2,
total.runs=1000) {
norm.col <- enquo(norm.col)
mclapply( 1:total.runs, function(x) {
sub.table$rand <- randomize.column(sub.table, rand.col)
rColRanks <-
general.ranker(sub.table,
!!norm.col, list2,
rand, list1
)
extract.checked(rColRanks) %>%
select(-checked, -norm.not.checked, -not.checked) %>%
spread(bywhat, norm.checked, fill = 0)
} ) %>% bind_rows
}
random.mc.analysis <- function( sub.table,
rand.col, list1,
norm.col, list2,
total.runs=1000) {
norm.col <- enquo(norm.col)
mclapply( 1:total.runs, function(x) {
sub.table$rand <- randomize.column(sub.table, rand.col)
general.ranker(sub.table,
rand, list1,
!!norm.col, list2
) -> rColRanks
extract.checked(rColRanks) %>%
select(-checked, -norm.not.checked, -not.checked) %>%
spread(bywhat, norm.checked, fill = 0)
} ) %>% bind_rows
}
random.analysis <- function(ts, rand.runs = 1000) {
hack <-
tibble(MESH = ts$diseases[1],
mcol = ts$drug.ids, score = 0) %>%
rbind(tibble(MESH = ts$diseases,
mcol = ts$drug.ids[1], score = 0))
sub.table <-
ts$interactions %>%
select(MESH, mcol, score) %>%
rbind(hack)
ts$random.analysis$rmcol.by.mesh <-
random.by.analysis(sub.table,
mcol, ts$drug.ids,
MESH, ts$diseases,
total.runs = rand.runs)
ts$random.analysis$rmcol.by.drug <-
random.mc.analysis(sub.table,
mcol, ts$drug.ids,
MESH, ts$diseases,
total.runs = rand.runs)
ts$random.analysis$rmesh.by.drug <-
random.by.analysis(sub.table,
MESH, ts$diseases,
mcol, ts$drug.ids,
total.runs = rand.runs)
ts$random.analysis$rmesh.by.mesh <-
random.mc.analysis(sub.table,
MESH, ts$diseases,
mcol, ts$drug.ids,
total.runs = rand.runs)
}