-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.R
More file actions
20 lines (15 loc) · 784 Bytes
/
example.R
File metadata and controls
20 lines (15 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# good resource
# https://www.bioconductor.org/packages/release/bioc/vignettes/ChemmineR/inst/doc/ChemmineR.html
library(ChemmineR)
library(DBI)
db <- dbConnect(RPostgres::Postgres(), dbname="pgvector_example")
invisible(dbExecute(db, "CREATE EXTENSION IF NOT EXISTS vector"))
invisible(dbExecute(db, "DROP TABLE IF EXISTS molecules"))
invisible(dbExecute(db, "CREATE TABLE molecules (id text PRIMARY KEY, fingerprint bit(1024))"))
data(sdfsample)
fpset <- desc2fp(sdf2ap(sdfsample))
molecules <- data.frame(id=sdfid(sdfsample), fingerprint=as.character(fpset))
invisible(dbAppendTable(db, "molecules", molecules))
params <- list(molecules$fingerprint[[1]])
result <- dbGetQuery(db, "SELECT id FROM molecules ORDER BY fingerprint <%> $1 LIMIT 5", params=params)
print(result$id)