-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateDerby.groovy
143 lines (125 loc) · 4.82 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
// Copyright (C) 2023 Egon Willighagen <[email protected]>
// MIT license
@Grab(group='org.bridgedb', module='org.bridgedb', version='3.0.19')
@Grab(group='org.bridgedb', module='org.bridgedb.bio', version='3.0.19')
@Grab(group='org.bridgedb', module='org.bridgedb.rdb', version='3.0.19')
@Grab(group='org.bridgedb', module='org.bridgedb.rdb.construct', version='3.0.19')
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.DataSourceTxt;
import org.bridgedb.rdb.construct.DBConnector;
import org.bridgedb.rdb.construct.DataDerby;
import org.bridgedb.rdb.construct.GdbConstruct;
import org.bridgedb.rdb.construct.GdbConstructImpl4;
commitInterval = 500
identifiersDone = new java.util.HashSet();
linksDone = new java.util.HashSet();
DataSourceTxt.init()
GdbConstruct database = GdbConstructImpl4.createInstance(
"nanomaterials", new DataDerby(), DBConnector.PROP_RECREATE
);
database.createGdbTables();
database.preInsert();
String dateStr = new SimpleDateFormat("yyyyMMdd").format(new Date());
database.setInfo("BUILDDATE", dateStr);
database.setInfo("DATASOURCENAME", "create-nanomaterial-mappings");
database.setInfo("DATASOURCEVERSION", dateStr);
database.setInfo("DATATYPE", "substance");
database.setInfo("SERIES", "nanomaterials");
database.setInfo("BRIDGEDBVERSION", "3.0.19");
wikidataDS = DataSource.getExistingBySystemCode("Wd")
ermDS = DataSource.getExistingBySystemCode("Nmerm")
nanomileDS = DataSource.getExistingBySystemCode("Nmnm")
jrcDS = DataSource.getExistingBySystemCode("Nmjrc")
def addXRef(GdbConstruct database, Xref ref, String node, DataSource source, Set identifiersDone, Set linkesDone, boolean isPrimary) {
id = node.trim()
if (id.length() > 0) {
// println "id($source): $id"
ref2 = new Xref(id, source, isPrimary);
if (!identifiersDone.contains(ref2.toString())) {
if (database.addGene(ref2) != 0) {
println "Error (addXRef.addGene): " + database.recentException().getMessage()
println " id($source): $id"
}
identifiersDone.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 addXRef(GdbConstruct database, Xref ref, String node, DataSource source, Set identifiersDone, Set linkesDone) {
addXRef(database, ref, node, source, identifiersDone, linkesDone, (boolean)true)
}
// NanoMILE
counter = 0
error = 0
new File("nanomile.csv").eachLine { line,number ->
if (line.trim().startsWith("#")) return; // skip comment lines
fields = line.split(",")
rootid = fields[0]
Xref ref = new Xref(rootid, nanomileDS);
if (!identifiersDone.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
identifiersDone.add(ref.toString())
}
// add external identifiers
ermID = fields[1].replaceAll("erm:","")
addXRef(database, ref, ermID, ermDS, identifiersDone, linksDone);
counter++
if (counter % commitInterval == 0) {
println "Info: errors: " + error + " (PubChem)"
database.commit()
}
}
// JRC
counter = 0
error = 0
new File("jrc.csv").eachLine { line,number ->
if (line.trim().startsWith("#")) return; // skip comment lines
fields = line.split(",")
rootid = fields[0]
Xref ref = new Xref(rootid, jrcDS);
if (!identifiersDone.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
identifiersDone.add(ref.toString())
}
// add external identifiers
wikidataID = fields[2]
if (wikidataID) {
addXRef(database, ref, wikidataID, wikidataDS, identifiersDone, linksDone);
}
if (fields.length>3) {
ermID = fields[3]
if (ermID) {
addXRef(database, ref, ermID, ermDS, identifiersDone, linksDone);
}
}
counter++
if (counter % commitInterval == 0) {
println "Info: errors: " + error + " (PubChem)"
database.commit()
}
}
database.commit();
database.finalize();