forked from DREAM-Toronto/Drug-Combination-Prediction-2015
-
Notifications
You must be signed in to change notification settings - Fork 0
/
readDrugJSON.R
63 lines (54 loc) · 1.91 KB
/
readDrugJSON.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
setwd("~/Desktop/JSON_Practice")
if (! require(jsonlite, quietly=TRUE)) {
# for plotting dose-response surfaces
install.packages("jsonlite",
repos="http://cran.us.r-project.org")
library(jsonlite)
}
readDrugJSON <- function(fn){
if (! require(jsonlite, quietly=TRUE)) {
# for plotting dose-response surfaces
install.packages("jsonlite",
repos="http://cran.us.r-project.org")
library(jsonlite)
}
x <- fromJSON(fn,FALSE)
chemPhyProperties <- x$Record$Section[[4]]
computedProperties <- chemPhyProperties$Section[[1]]
# experimentalProperties <- chemPhyProperties$Section[[2]]
computedPropertyObj <- list();
for(i in 1:length(computedProperties$Section)){
curProperty <- computedProperties$Section[[i]]$Information[[1]]
newPropertyObj <- {}
curPropertyName <-curProperty[2][[1]]
# newPropertyObj$Name <- curPropertyName
newPropertyObj$Value <- curProperty[3][[1]]
if(length(curProperty)>3){
newPropertyObj$Unit <- curProperty[4][[1]]
}
# computedPropertyObj[[i]] <- newPropertyObj
computedPropertyObj[[curPropertyName]] <- newPropertyObj
}
return(computedPropertyObj)
}
a <- readDrugJSON("CID_9444.json")
# x <- fromJSON("CID_9444.json",FALSE)
#
# chemPhyProperties <- x$Record$Section[[4]]
# computedProperties <- chemPhyProperties$Section[[1]]
# # experimentalProperties <- chemPhyProperties$Section[[2]]
#
# computedPropertyObj <- list();
#
# for(i in 1:length(computedProperties$Section)){
# curProperty <- computedProperties$Section[[i]]$Information[[1]]
# newPropertyObj <- {}
# curPropertyName <-curProperty[2][[1]]
# # newPropertyObj$Name <- curPropertyName
# newPropertyObj$Value <- curProperty[3][[1]]
# if(length(curProperty)>3){
# newPropertyObj$Unit <- curProperty[4][[1]]
# }
# # computedPropertyObj[[i]] <- newPropertyObj
# computedPropertyObj[[curPropertyName]] <- newPropertyObj
# }