-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInferPhenos.groovy
156 lines (133 loc) · 5.19 KB
/
InferPhenos.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
@Grapes([
@Grab(group="org.semanticweb.elk", module="elk-owlapi", version="0.4.2"),
@Grab(group="net.sourceforge.owlapi", module="owlapi-api", version="4.1.0"),
@Grab(group="net.sourceforge.owlapi", module="owlapi-apibinding", version="4.1.0"),
@Grab(group="net.sourceforge.owlapi", module="owlapi-impl", version="4.1.0"),
@Grab(group="net.sourceforge.owlapi", module="owlapi-parsers", version="4.1.0"),
@Grab(group="org.codehaus.gpars", module="gpars", version="1.1.0"),
@GrabConfig(systemClassLoader=true)
])
import org.semanticweb.owlapi.model.parameters.*;
import org.semanticweb.elk.owlapi.ElkReasonerFactory;
import org.semanticweb.elk.owlapi.ElkReasonerConfiguration;
import org.semanticweb.elk.reasoner.config.*;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.reasoner.*;
import org.semanticweb.owlapi.reasoner.structural.StructuralReasoner
import org.semanticweb.owlapi.vocab.OWLRDFVocabulary;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.io.*;
import org.semanticweb.owlapi.owllink.*;
import org.semanticweb.owlapi.util.*;
import org.semanticweb.owlapi.search.*;
import org.semanticweb.owlapi.manchestersyntax.renderer.*;
import org.semanticweb.owlapi.reasoner.structural.*;
import groovyx.gpars.GParsPool;
OWLOntologyManager manager = OWLManager.createOWLOntologyManager()
OWLOntology ont = manager.loadOntologyFromOntologyDocument(
new File("data/go.owl"))
OWLDataFactory dataFactory = manager.getOWLDataFactory()
OWLDataFactory fac = manager.getOWLDataFactory()
ConsoleProgressMonitor progressMonitor = new ConsoleProgressMonitor()
OWLReasonerConfiguration config = new SimpleConfiguration(progressMonitor)
ElkReasonerFactory f1 = new ElkReasonerFactory()
OWLReasoner reasoner = f1.createReasoner(ont, config)
reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY)
def posReg = [:].withDefault {key -> return new HashSet<String>()}
def negReg = [:].withDefault {key -> return new HashSet<String>()}
// Positive Regulation
def pr = fac.getOWLObjectProperty(
IRI.create("http://purl.obolibrary.org/obo/RO_0002213"))
// Negative Regulation
def nr = fac.getOWLObjectProperty(
IRI.create("http://purl.obolibrary.org/obo/RO_0002212"))
def getLabel = { term_id ->
IRI iri = IRI.create("http://purl.obolibrary.org/obo/$term_id")
OWLClass cl = dataFactory.getOWLClass(iri)
for(OWLAnnotation a : EntitySearcher.getAnnotations(cl, ont, dataFactory.getRDFSLabel())) {
OWLAnnotationValue value = a.getValue();
if(value instanceof OWLLiteral) {
return ((OWLLiteral) value).getLiteral();
}
}
return "";
}
IRI iri = IRI.create("http://purl.obolibrary.org/obo/GO_0065007")
OWLClass reg = dataFactory.getOWLClass(iri)
GParsPool.withPool {
ont.getClassesInSignature(true).eachParallel { cl ->
def cls = cl.toString()
cls = cls.substring(32, cls.length() - 1)
def c = fac.getOWLObjectSomeValuesFrom(pr, cl)
c = fac.getOWLObjectIntersectionOf(reg, c)
reasoner.getEquivalentClasses(c).getEntities().each { sub ->
def s = sub.toString()
if (s.startsWith("<http://purl.obolibrary.org/obo/GO_")) {
s = s.substring(32, s.length() - 1)
posReg[s].add(cls)
}
}
c = fac.getOWLObjectSomeValuesFrom(nr, cl)
c = fac.getOWLObjectIntersectionOf(reg, c)
reasoner.getEquivalentClasses(c).getEntities().each { sub ->
def s = sub.toString()
if (s.startsWith("<http://purl.obolibrary.org/obo/GO_")) {
s = s.substring(32, s.length() - 1)
negReg[s].add(cls)
}
}
}
}
// def incPheno = [:].withDefault { new HashSet<String>() }
// def decPheno = [:].withDefault { new HashSet<String>() }
// def abnPheno = [:].withDefault { new HashSet<String>() }
// new File("data/pheno2go.txt").splitEachLine(" ") { items ->
// def pheno = items[0]
// def go = items[1]
// if (items[2] == "1") { // increase
// incPheno[go].add(pheno)
// } else if (items[2] == "-1") { // decrease
// decPheno[go].add(pheno)
// } else { // abnormal
// abnPheno[go].add(pheno)
// }
// }
// def out = new PrintWriter(new BufferedWriter(new FileWriter("data/rules.txt")))
// abnPheno.each {go, phenos ->
// phenos.each { pheno ->
// out.println("$go\t$pheno\tabnormal");
// }
// }
// posReg.each { go, gos ->
// gos.each { go_id ->
// decPheno[go_id].each { pheno ->
// out.println("$go\t$pheno\tdecrease");
// }
// incPheno[go_id].each { pheno ->
// out.println("$go\t$pheno\tincrease_inconsistent");
// }
// }
// }
// negReg.each { go, gos ->
// gos.each { go_id ->
// decPheno[go_id].each { pheno ->
// out.println("$go\t$pheno\tdecrease_inconsistent");
// }
// incPheno[go_id].each { pheno ->
// out.println("$go\t$pheno\tincrease");
// }
// }
// }
// out.close();
def out = new PrintWriter(new BufferedWriter(new FileWriter("data/regulations.txt")))
posReg.each { go, gos ->
gos.each { go_id ->
out.println("$go\t$go_id\tpos");
}
}
negReg.each { go, gos ->
gos.each { go_id ->
out.println("$go\t$go_id\tneg");
}
}
out.close();