forked from bio-ontology-research-group/phenogocon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PropPhenos.groovy
70 lines (62 loc) · 2.71 KB
/
PropPhenos.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
@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 getChildren = { term_id ->
IRI iri = IRI.create("http://purl.obolibrary.org/obo/$term_id")
OWLClass cl = dataFactory.getOWLClass(iri)
def res = reasoner.getSubClasses(cl, false).getFlattened()
return res
}
def getName = { cl ->
def iri = cl.toString()
def name = iri
if (iri.startsWith("<http://purl.obolibrary.org/obo/")) {
name = iri.substring(32, iri.length() - 1)
} else if (iri.startsWith("<http://aber-owl.net/")) {
name = iri.substring(21, iri.length() - 1)
}
return name
}
def out = new PrintWriter(new BufferedWriter(new FileWriter("data/rules_prop.txt")))
new File("data/rules.txt").splitEachLine("\t") { items ->
def go_id = items[0]
def pred = items[1] + "\t" + items[2];
out.println("$go_id\t$pred");
getChildren(go_id).each { term_id ->
term_id = getName(term_id)
out.println("$term_id\t$pred")
}
}
out.close();