Skip to content

Commit

Permalink
support for output file; support for resnik-ic, small fixes to output…
Browse files Browse the repository at this point in the history
… and error reporting.
  • Loading branch information
reality committed Jun 9, 2021
1 parent 63742e8 commit 38ac83f
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 20 deletions.
2 changes: 1 addition & 1 deletion klarigi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ jacocoTestReport {
}
}

version = '0.0.4'
version = '0.0.5'
11 changes: 9 additions & 2 deletions klarigi/src/main/groovy/klarigi/App.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class App {
d longOpt: 'data', 'The data describing entities and associations. See documentation for format.', args: 1
o longOpt: 'ontology', 'The ontology to use for explanations (should be the same as the ontology used to describe patients).', args: 1

ri longOpt: 'resnik-ic', 'Use Resnik annotation frequency for information content calculation', type: Boolean
ic longOpt: 'ic', 'List of classes and associated information content values.', args: 1
_ longOpt: 'save-ic', 'Save the IC values to the given file', args:1

Expand All @@ -36,6 +37,9 @@ class App {

_ longOpt: 'output-scores', 'Output the results of the scorer. This can be useful for debugging, or identifying coefficient settings.', type: Boolean

_ longOpt: 'latex', 'Output the results in LaTeX table format', type: Boolean
_ longOpt: 'output', 'File to output results to. If not given, will print to stdout', args: 1

_ longOpt: 'verbose', 'Verbose output, mostly progress', type: Boolean, args: 0
}

Expand All @@ -53,9 +57,12 @@ class App {

def k = new Klarigi(o)
if(!o['group'] || (o['group'] && o['group'] == '*')) {
k.explainAllClusters(o['output-scores'])
k.explainAllClusters(o['output-scores']).each {
k.output(it.cluster, it.results, o['latex'], o['output'])
}
} else {
k.explainCluster(o['group'], o['output-scores'])
def r = k.explainCluster(o['group'], o['output-scores'])
k.output(o['group'], r, o['latex'], o['output'])
}
}
}
15 changes: 14 additions & 1 deletion klarigi/src/main/groovy/klarigi/InformationContent.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public class InformationContent {
private factory

InformationContent(ontologyPath) {
this(ontologyPath, false, false)
}

InformationContent(ontologyPath, dataPath, annotIC) {
factory = URIFactoryMemory.getSingleton()

/*def graphURI = factory.getURI('http://purl.obolibrary.org/obo/HP_')
Expand All @@ -65,12 +69,21 @@ public class InformationContent {

def gConf = new GraphConf()
gConf.addGDataConf(dataConf)

def icMeasure = DEFAULT_IC
if(annotIC) {
gConf.addGDataConf(new GDataConf(GFormat.TSV_ANNOT, dataPath));
}
//gConf.addGAction(actionRerootConf)

GraphLoaderGeneric.load(gConf, graph)
def roots = new ValidatorDAG().getTaxonomicRoots(graph)

icConf = new IC_Conf_Topo(DEFAULT_IC)
if(annotIC) {
icConf = new IC_Conf_Corpus(SMConstants.FLAG_IC_ANNOT_RESNIK_1995_NORMALIZED)
}

engine = new SM_Engine(graph)
}

Expand All @@ -80,7 +93,7 @@ public class InformationContent {
try {
def cTerm = factory.getURI(c)
res[c] = engine.getIC(icConf, cTerm)
} catch(e) { e.printStackTrace() }
} catch(e) { println 'Warning: ' + e.getMessage() }
}
res
}
Expand Down
27 changes: 19 additions & 8 deletions klarigi/src/main/groovy/klarigi/Klarigi.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ public class Klarigi {
Klarigi(o) {
loadData(o['data'])
loadOntology(o['ontology'])
loadIc(o['ic'], o['ontology'], o['save-ic'])
loadIc(o['ic'], o['ontology'], o['data'], o['resnik-ic'], o['save-ic'])
coefficients = Coefficients.Generate(o)
verbose = o['verbose']

if(o['output']) { // blank the output file, since we will subsequently append to it. all the output stuff could probs be better abstracted.
new File(o['output']).text = ''
}
}

def loadData(dataFile) {
Expand All @@ -63,7 +67,7 @@ public class Klarigi {
}
}

def loadIc(icFile, ontologyFile, saveIc) {
def loadIc(icFile, ontologyFile, annotFile, resnikIc, saveIc) {
if(icFile) {
try {
new File(icFile).splitEachLine('\t') {
Expand All @@ -74,7 +78,7 @@ public class Klarigi {
}
} else {
try {
def icFactory = new InformationContent(ontologyFile)
def icFactory = new InformationContent(ontologyFile, annotFile, resnikIc)
def allClasses = ontoHelper.reasoner.getSubClasses(ontoHelper.dataFactory.getOWLThing(), false).collect { it.getRepresentativeElement().getIRI().toString() }.unique(false)
allClasses = allClasses.findAll { it != 'http://www.w3.org/2002/07/owl#Nothing' } // heh
data.ic = icFactory.getInformationContent(allClasses)
Expand Down Expand Up @@ -145,14 +149,21 @@ public class Klarigi {
}
}


def res = StepDown.Run(coefficients, cid, candidates, data)
StepDown.Print(cid, res, ontoHelper.labels)
StepDown.Run(coefficients, cid, candidates, data)
}

def explainAllClusters(outputScores) {
data.groupings.each { g, v ->
explainCluster(g, outputScores)
data.groupings.collect { g, v ->
[ cluster: g, results: explainCluster(g, outputScores) ]
}
}

def output(cid, results, latex, toFile) {
def cSize = data.groupings[cid].size()
if(latex) {
StepDown.PrintLaTeX(cid, results, ontoHelper.labels, cSize, toFile)
} else {
StepDown.Print(cid, results, ontoHelper.labels, cSize, toFile)
}
}

Expand Down
39 changes: 31 additions & 8 deletions klarigi/src/main/groovy/klarigi/StepDown.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,38 @@ public class StepDown {
return stepDown(candidates, c.MAX_IC, c.MAX_EXCLUSION, c.MAX_INCLUSION, c.MAX_TOTAL_INCLUSION)
}

static def Print(cid, res, labels) {
println "----------------"
println "Group: $cid"
println "Overall inclusion: ${res[1]}%"
println "Explanatory classes:"
static def Print(cid, res, labels, s, toFile) {
def out = []
out << "----------------"
out << "Group: $cid ($s members)"
out << "Overall inclusion: ${res[1]}%"
out << "Explanatory classes:"
res[0].each { z ->
println " IRI: ${labels[z.iri]} (${z.iri}), Inclusivity: ${z.nInclusion}, Exclusivity: ${z.nExclusion}, IC: ${z.nIc}"
out << " IRI: ${labels[z.iri]} (${z.iri}), Inclusivity: ${z.nInclusion}, Exclusivity: ${z.nExclusion}, IC: ${z.nIc}"
}
out << "----------------"
out << ""
out = out.join('\n')

if(toFile) {
new File(toFile).text += '\n' + out
} else {
println out
}
}

static def PrintLaTeX(cid, res, labels, s, toFile) {
def out = []
out << "{\\bf Group: $cid ($s members), overall inclusivity: ${res[1].toDouble().round(2)})} & {\\bf Exclusion} & {\\bf Inclusion} & {\\bf IC} \\\\"
res[0].sort { -it.nIc }.each {
out << "${labels[it.iri]} (HP:${it.iri.tokenize('_')[1]}) & ${it.nExclusion.toDouble().round(2)} & ${it.nInclusion.toDouble().round(2)} & ${it.ic.toDouble().round(2)} \\\\"
}
out = out.join('\n')

if(toFile) {
new File(toFile).text += '\n' + out
} else {
println out
}
println "----------------"
println ""
}
}

0 comments on commit 38ac83f

Please sign in to comment.