-
Notifications
You must be signed in to change notification settings - Fork 3
/
compounds_labels.groovy
53 lines (43 loc) · 1.84 KB
/
compounds_labels.groovy
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
import groovy.sql.Sql
import org.openrdf.repository.Repository
import org.openrdf.repository.sail.SailRepository
import org.openrdf.sail.memory.MemoryStore
import org.openrdf.model.vocabulary.RDFS
import org.openrdf.model.vocabulary.RDF
import org.openrdf.rio.ntriples.NTriplesWriter
// export CLASSPATH=$(JARS=(*.jar); IFS=:; echo "${JARS[*]}")
def props = new Properties()
new File("vars.properties").withInputStream { stream -> props.load(stream) }
if (props.mysqliini) new File(props.mysqliini).withInputStream { stream -> props.load(stream) }
def url = "jdbc:mysql://localhost/" + props.dbprefix + props.version
def sql = Sql.newInstance(url, props["mysqli.default_user"], props["mysqli.default_pw"], "com.mysql.jdbc.Driver")
allMolregno = "SELECT DISTINCT molregno, chembl_id FROM molecule_dictionary " + props.limit
CHEMBL = props.rooturi + "chemblid/";
xsdStringURI = "http://www.w3.org/2001/XMLSchema#string"
sql.eachRow(allMolregno) { row ->
def repos = new SailRepository(new MemoryStore())
repos.initialize()
con = repos.getConnection();
factory = repos.getValueFactory();
molURI = factory.createURI(CHEMBL + row.chembl_id)
// the names
allNames = "SELECT DISTINCT compound_name FROM compound_records WHERE molregno = " + row.molregno
sql.eachRow(allNames) { nameRow ->
if (nameRow['compound_name'] != null) {
con.add(molURI, RDFS.LABEL,
factory.createLiteral(nameRow['compound_name'], factory.createURI(xsdStringURI))
)
}
}
// the synonyms
allNames = "SELECT DISTINCT synonyms FROM molecule_synonyms WHERE molregno = " + row.molregno
sql.eachRow(allNames) { nameRow ->
if (nameRow['synonyms'] != null) {
con.add(molURI, RDFS.LABEL,
factory.createLiteral(nameRow['synonyms'], factory.createURI(xsdStringURI))
)
}
}
con.export(new NTriplesWriter(System.out))
con.close()
}