-
Notifications
You must be signed in to change notification settings - Fork 2
/
createDerby.groovy
254 lines (217 loc) · 9.62 KB
/
createDerby.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
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
// export CLASSPATH=`ls -1 *.jar | tr '\n' ':'`
import java.text.SimpleDateFormat;
import java.util.Date;
import groovy.xml.XmlSlurper
import groovy.xml.slurpersupport.NodeChildren;
import org.bridgedb.IDMapperException;
import org.bridgedb.DataSource;
import org.bridgedb.Xref;
import org.bridgedb.bio.BioDataSource;
import org.bridgedb.rdb.construct.DBConnector;
import org.bridgedb.rdb.construct.DataDerby;
import org.bridgedb.rdb.construct.GdbConstruct;
import org.bridgedb.rdb.construct.GdbConstructImpl3;
commitInterval = 500
genesDone = new java.util.HashSet();
linksDone = new java.util.HashSet();
//unitReport = new File("creationNEW.xml")
// unitReport << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
//unitReport << "<testsuite tests=\"12\">\n"
GdbConstruct database = GdbConstructImpl3.createInstance(
"rhea_interactions", new DataDerby(), DBConnector.PROP_RECREATE
);
database.createGdbTables();
database.preInsert();
blacklist = new HashSet<String>();
//blacklist.add("C00350") //Example of blacklist item.
////Registering Datasources to create mappings
rheaDS = DataSource.register ("Rh", "Rhea").asDataSource()
enzymenom = DataSource.register ("E", "Enzyme Nomenclature").asDataSource()
keggreact = DataSource.register ("Rk", "KEGG Reaction").asDataSource()
reactomereact = DataSource.register ("Re", "Reactome").asDataSource()
metacycDS = DataSource.register ("Mc", "MetaCyc").asDataSource() //Not recognised as BioDataSource
ecocycDS = DataSource.register ("Eco", "EcoCyc").asDataSource() //Not recognised as BioDataSource
macieDS = DataSource.register ("Ma", "MACiE").asDataSource() //Not recognised as BioDataSource
//unipathDS = DataSource.register ("Up", "Unipathway").asDataSource() //Not recognised as BioDataSource, Not part of Rhea download (any more?)
String dateStr = new SimpleDateFormat("yyyyMMdd").format(new Date());
database.setInfo("BUILDDATE", dateStr);
database.setInfo("DATASOURCENAME", "EBI-RHEA");
database.setInfo("DATASOURCEVERSION", "115");
database.setInfo("DATATYPE", "standard-interaction");
database.setInfo("SERIES", "Interaction");
def addXRef(GdbConstruct database, Xref ref, String node, DataSource source, Set genesDone, Set linkesDone) {
id = node.trim()
if (id.length() > 0) {
// println "id($source): $id"
ref2 = new Xref(id, source);
if (!genesDone.contains(ref2.toString())) {
if (database.addGene(ref2) != 0) {
println "Error (addXRef.addGene): " + database.recentException().getMessage()
println " id($source): $id"
}
genesDone.add(ref2.toString())
}
if (!linksDone.contains(ref.toString()+ref2.toString())) {
if (database.addLink(ref, ref2) != 0) {
println "Error (addXRef.addLink): " + database.recentException().getMessage()
println " id(origin): " + ref.toString()
println " id($source): $id"
}
linksDone.add(ref.toString()+ref2.toString())
}
}
}
def addAttribute(GdbConstruct database, Xref ref, String key, String value) {
id = value.trim()
// println "attrib($key): $id"
if (id.length() > 255) {
println "Warn: attribute does not fit the Derby SQL schema: $id"
} else if (id.length() > 0) {
if (database.addAttribute(ref, key, value) != 0) {
println "Error (addAttrib): " + database.getException().getMessage()
}
}
}
//// load the Rhea content
// Split up data per column
counter = 0
error = 0
new File("data/mappingsrhea.tsv").eachLine { line,number ->
if (number == 1) return // skip the first line
fields = line.split(/\t/)
def rootid ;
def direction ;
def masterid ;
def databaseid ;
def databasename ;
if (fields.size() >= 5) {
(rootid, direction, masterid, databaseid, databasename) = line.split(/\t/)
}
//if (number == 3) println databasename ////Test if data is read correctly
//if (number == 4) println rootid ////Test if data is read correctly
//Rhea-EC
if(databasename == "EC" ) { //Only use the 4th column for EC mappings if it contains "EC".
Xref ref = new Xref(rootid, rheaDS);
if (!genesDone.contains(ref.toString())) {
addError = database.addGene(ref);
if (addError != 0) println "Error (addGene): " + database.recentException().getMessage()
error += addError
linkError = database.addLink(ref,ref);
if (linkError != 0) println "Error (addLinkItself): " + database.recentException().getMessage()
error += linkError
genesDone.add(ref.toString())
}
// add external identifiers
addXRef(database, ref, databaseid, enzymenom, genesDone, linksDone); //Updated database name (enzymenom)
counter++
if (counter % commitInterval == 0) {
println "Info: errors: " + error + " (EC Nomenclature)" //Updated database error output (EC Nomenclature)
database.commit()
}
}
//Rhea-KEGG
if(databasename == "KEGG_REACTION" ) { //Only use the 4th column for Kegg mappings if it contains "KEGG_REACTION".
Xref ref = new Xref(rootid, rheaDS);
if (!genesDone.contains(ref.toString())) {
addError = database.addGene(ref);
if (addError != 0) println "Error (addGene): " + database.recentException().getMessage()
error += addError
linkError = database.addLink(ref,ref);
if (linkError != 0) println "Error (addLinkItself): " + database.recentException().getMessage()
error += linkError
genesDone.add(ref.toString())
}
// add external identifiers
addXRef(database, ref, databaseid, keggreact, genesDone, linksDone); //Updated database name (keggreact)
counter++
if (counter % commitInterval == 0) {
println "Info: errors: " + error + " (KEGG Reactions)" //Updated database error output (KEGG Reactions)
database.commit()
}
}
//Rhea-MetaCyC
if(databasename == "METACYC" ) { //Only use the 4th column for MetaCyc mappings if it contains "METACYC".
Xref ref = new Xref(rootid, rheaDS);
if (!genesDone.contains(ref.toString())) {
addError = database.addGene(ref);
if (addError != 0) println "Error (addGene): " + database.recentException().getMessage()
error += addError
linkError = database.addLink(ref,ref);
if (linkError != 0) println "Error (addLinkItself): " + database.recentException().getMessage()
error += linkError
genesDone.add(ref.toString())
}
// add external identifiers
addXRef(database, ref, databaseid, metacycDS, genesDone, linksDone); //Updated database name (metacycDS)
counter++
if (counter % commitInterval == 0) {
println "Info: errors: " + error + " (MetaCyc)" //Updated database error output (MetaCyc)
database.commit()
}
}
//Rhea-EcoCyC
if(databasename == "ECOCYC" ) { //Only use the 4th column for EcoCyc mappings if it contains "ECOCYC".
Xref ref = new Xref(rootid, rheaDS);
if (!genesDone.contains(ref.toString())) {
addError = database.addGene(ref);
if (addError != 0) println "Error (addGene): " + database.recentException().getMessage()
error += addError
linkError = database.addLink(ref,ref);
if (linkError != 0) println "Error (addLinkItself): " + database.recentException().getMessage()
error += linkError
genesDone.add(ref.toString())
}
// add external identifiers
addXRef(database, ref, databaseid, ecocycDS, genesDone, linksDone); //Updated database name (ecocycDS)
counter++
if (counter % commitInterval == 0) {
println "Info: errors: " + error + " (EcoCyc)" //Updated database error output (EcoCyc)
database.commit()
}
}
//Rhea-MaCIE
if(databasename == "MACIE" ) { //Only use the 4th column for MaCIE mappings if it contains "MACIE".
Xref ref = new Xref(rootid, rheaDS);
if (!genesDone.contains(ref.toString())) {
addError = database.addGene(ref);
if (addError != 0) println "Error (addGene): " + database.recentException().getMessage()
error += addError
linkError = database.addLink(ref,ref);
if (linkError != 0) println "Error (addLinkItself): " + database.recentException().getMessage()
error += linkError
genesDone.add(ref.toString())
}
// add external identifiers
addXRef(database, ref, databaseid, macieDS, genesDone, linksDone); //Updated database name (macieDS)
counter++
if (counter % commitInterval == 0) {
println "Info: errors: " + error + " (MaCIE)" //Updated database error output (MaCIE)
database.commit()
}
}
//Rhea-Reactome
if(databasename == "REACTOME" ) { //Only use the 4th column for Reactome mappings if it contains "REACTOME".
Xref ref = new Xref(rootid, rheaDS);
if (!genesDone.contains(ref.toString())) {
addError = database.addGene(ref);
if (addError != 0) println "Error (addGene): " + database.recentException().getMessage()
error += addError
linkError = database.addLink(ref,ref);
if (linkError != 0) println "Error (addLinkItself): " + database.recentException().getMessage()
error += linkError
genesDone.add(ref.toString())
}
// add external identifiers
addXRef(database, ref, databaseid, reactomereact, genesDone, linksDone); //Updated database name (reactomereact)
counter++
if (counter % commitInterval == 0) {
println "Info: errors: " + error + " (Reactome Reactions)" //Updated database error output (Reactome interactions)
database.commit()
}
}
}
//unitReport << " <testcase classname=\"WikidataCreation\" name=\"CASNumbersFound\"/>\n" //No tests implemented (yet) for interaction IDs.
//unitReport << " <testcase classname=\"WikidataCreation\" name=\"NamesFound\"/>\n" ///These lines are merely here as examples
//unitReport << "</testsuite>\n"
database.commit();
database.finalize();