forked from egonw/chembl.rdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactivities_qudt.groovy
131 lines (115 loc) · 4.45 KB
/
activities_qudt.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
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
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
import com.github.jqudt.Quantity
import com.github.jqudt.onto.UnitFactory
// 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 * FROM activities " + props.limit
unitMappings = [
nM:"http://www.openphacts.org/units/Nanomolar",
uM:"http://www.openphacts.org/units/Micromolar",
mM:"http://www.openphacts.org/units/Millimolar",
pM:"http://www.openphacts.org/units/Picomolar",
"%":"http://qudt.org/schema/qudt#floatPercentage",
"ug.mL-1":"http://www.openphacts.org/units/MicrogramPerMilliliter",
"ug/ml":"http://www.openphacts.org/units/MicrogramPerMilliliter",
"ug ml-1":"http://www.openphacts.org/units/MicrogramPerMilliliter",
"pg ml-1":"http://www.openphacts.org/units/PicogramPerMilliliter",
]
normalizationMappings = [
"IC50" : [
nM:"nM",
uM:"nM",
mM:"nM",
pM:"nM",
"ug.mL-1":"ug/ml",
"ug/ml":"ug/ml",
"ug ml-1":"ug/ml",
"pg ml-1":"ug/ml",
"%":"%"
],
"Potency" : [
M:"uM",
uM:"uM",
nM:"uM",
mM:"uM",
"%":"%"
]
]
ACT = props.rooturi + "activity/"
RES = props.rooturi + "resource/"
ONTO = "http://rdf.farmbio.uu.se/chembl/onto/#"
CITO = "http://purl.org/spar/cito/"
MOL = props.rooturi + "molecule/"
CHEMBL = props.rooturi + "chemblid/"
ASS = props.rooturi + "assay/"
OPS = "http://www.openphacts.org/chembl/onto/#"
unitFactory = UnitFactory.getInstance();
xsd = "http://www.w3.org/2001/XMLSchema#"
sql.eachRow(allMolregno) { row ->
def repos = new SailRepository(new MemoryStore())
repos.initialize()
con = repos.getConnection();
factory = repos.getValueFactory();
actURI = factory.createURI(ACT + "a" + row.activity_id)
if (row.standard_value != null) {
type = row.standard_type.trim()
// now do the units: check if we need to use QUDT and if we normalize
units = row.standard_units
if (units != null && unitMappings.containsKey(units)) {
qudtUnits = unitMappings.get(units)
// first output the value as QUDT
con.add(actURI,
factory.createURI(OPS + "standardValue"),
factory.createLiteral((float)row.standard_value)
)
con.add(actURI,
factory.createURI(OPS + "standardUnit"),
factory.createURI(qudtUnits)
)
// now see if I can normalize things
originalUnit = unitFactory.getUnit(qudtUnits)
if (originalUnit != null) {
if (originalUnit.abbreviation == null) originalUnit.abbreviation = units
quantity = new Quantity(row.standard_value, originalUnit);
if (normalizationMappings.containsKey(type)) {
// normalize the value, if we know how
if (normalizationMappings[type] != null && normalizationMappings[type][units] != null) {
normalizedUnit = unitFactory.getUnit(unitMappings[normalizationMappings[type][units]])
if (normalizedUnit != null & normalizedUnit != originalUnit) {
normalizedQuantity = quantity.convertTo(normalizedUnit)
con.add(actURI,
factory.createURI(OPS + "normalisedValue"),
factory.createLiteral((float)normalizedQuantity.value)
)
con.add(actURI,
factory.createURI(OPS + "normalisedUnit"),
factory.createURI(normalizedUnit.resource.toString())
)
} else {
// println "# WARN: normalized unit == null or equals the original: " + normalizedUnit
}
} else {
println "# WARN: wanting to normalize $type $units, but no normalization found: " + normalizationMappings[type]
}
} else {
// println "# WARN: no normalized unit defined for -> '$type'"
}
} else {
// println "# WARN: no originalUnit -> $originalUnit"
}
}
}
con.export(new NTriplesWriter(System.out))
con.close()
repos.shutDown()
}