-
Notifications
You must be signed in to change notification settings - Fork 9
/
NOTES.R~no_promises
200 lines (122 loc) · 3.91 KB
/
NOTES.R~no_promises
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
#debug
library(CTSgetR)
CTSgetR::CTSgetR(id=c("C15973","C00026","C05381"), from=c("KEGG"), to = c("PubChem CID"))
nano #docker cred error
~/.docker/config.json # remove credsStore
want<-'sm'
possible_to<-unlist(valid_to())
possible_to[grepl(want,possible_to,ignore.case=TRUE)]
# CTSgetR::CTSgetR(id=c("C15973","C00026","C05381"), from=c("InChIKey"), to = c("PubChem CID"))
#inchi to smiles
webchem::get_csid #https://docs.ropensci.org/webchem/reference/get_csid.html
rcdkTools::inchi2smiles #https://rdrr.io/github/bachi55/rcdkTools/man/inchi2smiles.html - requires installing open babel
#TODO
# add local copy and build to dockerfile
#change rstudio server login from opencpu
#from WSL
cd /mnt/c/Users/think/Dropbox/Software/ARCHIVE/CTSgetR
#build base image from opencpu
#build
export rstudio_pass=dave_777 # rstudio server password for user opencpu
docker-compose -f docker-compose.yml build --force-rm
#start service
export ctsgetr_db_mount=/mnt/c/Users/think/Dropbox/Software/ARCHIVE/CTSgetR
docker-compose -f docker-compose.yml up -d
#interactive debug
docker exec -ti ctsgetr bash
#might need to own mounted sqlite
sudo chown www-data /root/ctsgetr/.
#configure app armor
#http://bbroeksema.github.io/2014/11/20/using-sqlite-with-opencpu.html
#how to update the db?
#could use s3 to copy?
https://cts.fiehnlab.ucdavis.edu/rest/convert/KEGG/InchiKey/C15973,C00026
# Calling the API from R -----------------------------------------------------------------
library(ocpuclient)
base_url<-'http://localhost:8084/ocpu/'
endpoint<-'library/CTSgetR/R/heartbeat'
url<-paste0(base_url,endpoint)
curl http://localhost/ocpu/library/CTSgetR/R/heartbeat
post_ocpu(url=url)
#debug
endpoint<-'library/CTSgetR/R/api_debug'
url<-paste0(base_url,endpoint)
post_ocpu(url=url)
#db
db_name<-'/root/ctsgetr/ctsgetr.sqlite'
# db_name<-'/ctsgetr/ctsgetr.sqlite'
# db_name<-'/ctsgetrdb/ctsgetr.sqlite'
endpoint<-'library/CTSgetR/R/db_stats'
url<-paste0(base_url,endpoint)
body<-list(data=FALSE, db_name=db_name)
post_ocpu(url=url,body=body)
#translate
endpoint<-'library/CTSgetR/R/CTSgetR'
url<-paste0(base_url,endpoint)
id <-
c("C15973",
"C00026")
from <- "KEGG"
to <- "PubChem CID"
body<-list(id=id,from=from,to=to,db_name=db_name)
post_ocpu(url=url,body=body)
do.call('CTSgetR',list(id=id,from=from,to=to))
#locking with a mounted db?
db_name<-'/ctsgetr/inst/ctsgetr.sqlite'
file.exists(db_name)
do.call('db_stats',list(db_name='/ctsgetrdb/ctsger.sqlite'))
db_stats(db_name=db_name1)
#tests
# endpoint<-'library/CTSgetR/R/api_echo'
endpoint<-'library/CTSgetR/R/CTSgetR'
url<-paste0(base_url,endpoint)
id <-
c(
"C15973",
"C00026"
)
from <- "KEGG"
to <- "PubChem CID"
#tests in R
body<-list(id=id,from=from,to=to)
body<-list(id=id,from=from,to=to,db_name='inst/ctsgetr.sqlite')
do.call('CTSgetR',body)
do.call('CTSgetR::db_stats',list())
#API
db_name<-'/ctsgetrdb/ctsgetr.sqlite'
db_fun<-function(){
Sys.getenv('ctsgetr_db')
}
body<-list(id=id,from=from,to=to)
#client db path
body<-list(id=id,from=from,to=to,db_name=db_name)
#server db
body<-list(id=id,from=from,to=to,db_name=db_fun())
endpoint<-'library/CTSgetR/R/CTSgetR'
url<-paste0(base_url,endpoint)
post_ocpu(url=url,body=body)
#OLDER
(x<-do.call('api_echo',list(toJSON(body))))
str(x)
fromJSON(x)
curl(val)
res<-POST(url,body=body,encode='json',verbose())
res_headers<-httr:::parse_http_headers(res$headers)[[1]]$headers
res_url<-res_headers$location
locs<-readLines(curl(res_url))
all_out<-lapply(locs,function(i){
url<-paste0(res_url,i)
readLines(curl(url))
})
names(all_out)<-locs
all_out
tmp<-paste0(res_url,'R/.val')
(results<-fromJSON(readLines(curl(tmp))))
tmp<-paste0(res_url,'R/console')
(results<-fromJSON(readLines(curl(tmp))))
results<-GET(res_url)
(out<-cat(rawToChar(results$content)))
#get location
rawToChar(headers(res))
# fromJSON(readLines(rawToChar(results$content)))
GET('http://localhost:4000/ocpu/tmp/x02060018908b3d/R/.val')