-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEvaluate.groovy
150 lines (133 loc) · 5.1 KB
/
Evaluate.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
@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 go = manager.loadOntologyFromOntologyDocument(
// new File("data/go.owl"))
// OWLOntology phenomenet = manager.loadOntologyFromOntologyDocument(
// new File("data/a.owl"))
// OWLDataFactory fac = manager.getOWLDataFactory()
// ConsoleProgressMonitor progressMonitor = new ConsoleProgressMonitor()
// OWLReasonerConfiguration config = new SimpleConfiguration(progressMonitor)
// OWLDataFactory dataFactory = manager.getOWLDataFactory()
// ElkReasonerFactory reasonerFactory = new ElkReasonerFactory()
// OWLReasoner goReasoner = reasonerFactory.createReasoner(go, config)
// OWLReasoner phenomeReasoner = reasonerFactory.createReasoner(
// phenomenet, config)
// def shortFormProvider = new SimpleShortFormProvider()
// def getAnchestors = { reasoner, term_id ->
// IRI iri = IRI.create("http://purl.obolibrary.org/obo/$term_id")
// OWLClass cl = dataFactory.getOWLClass(iri)
// def res = reasoner.getSuperClasses(cl, false).getFlattened()
// return res
// }
// def getChildren = { reasoner, 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 ->
// return shortFormProvider.getShortForm(cl)
// }
// def mp2hp = [:]
// phenomenet.getClassesInSignature().each {
// cl ->
// def name = getName(cl);
// if (name.startsWith("MP_")) {
// def eClasses = phenomeReasoner.getEquivalentClasses(cl).getEntities()
// eClasses.each {
// ecl ->
// eName = getName(ecl)
// if (eName.startsWith('HP_')) {
// mp2hp[name] = eName;
// }
// }
// }
// }
annotations = [:].withDefault { new HashSet<String>() }
predictions = [:].withDefault { [:].withDefault { new HashSet<String>() } }
def qual = [:].withDefault { [:] }
new File("data/predictions_filtered.txt").splitEachLine("\t") { items ->
def pheno = items[2].replaceAll(":", "_")
def children = new HashSet<String>()
children.add(pheno)
// getChildren(phenomeReasoner, pheno).each { cl ->
// def name = getName(cl)
// if (name.startsWith("MP") || name.startsWith("HP")) {
// children.add(name)
// }
// }
gene = items[0]
annot = items[1]
predictions[gene][annot].addAll(children)
qual[annot][pheno] = items[3]
}
new File("data/MGI_GenePheno.rpt").splitEachLine("\t") { items ->
pheno = items[4].replaceAll(":", "_")
anchestors = new HashSet<String>()
anchestors.add(pheno)
// getAnchestors(phenomeReasoner, pheno).each { cl ->
// def name = getName(cl)
// if (name.startsWith("MP") || name.startsWith("HP")) {
// anchestors.add(name)
// }
// }
mgis = items[6].split(",")
mgis.each { mgi ->
if (mgi in predictions) {
predictions[mgi].each { go_id, phenos ->
if (anchestors.intersect(phenos).size() > 0) {
def ql = qual[go_id][pheno]
println("$mgi\t$go_id\t$pheno\t$ql");
}
}
}
annotations[mgi].addAll(anchestors)
}
}
new File("data/genes_to_phenotype.txt").eachLine { line ->
if (line.startsWith("#")) return;
def items = line.split("\t")
def gene = items[1]
def hp = items[3].replaceAll(":", "_")
anchestors = new HashSet<String>()
anchestors.add(hp)
// getAnchestors(phenomeReasoner, hp).each { cl ->
// def name = getName(cl)
// if (name.startsWith("MP") || name.startsWith("HP")) {
// anchestors.add(name)
// }
// }
if (gene in predictions) {
predictions[gene].each { go_id, phenos ->
if (anchestors.intersect(phenos).size() > 0) {
def ql = qual[go_id][hp]
println("$gene\t$go_id\t$hp\t$ql");
}
}
}
annotations[gene].addAll(anchestors)
}