diff --git a/klarigi/build.gradle b/klarigi/build.gradle index c5aa00d..4db5e10 100644 --- a/klarigi/build.gradle +++ b/klarigi/build.gradle @@ -88,4 +88,4 @@ jacocoTestReport { } } -version = '0.0.11' +version = '0.0.12-SNAPSHOT' diff --git a/klarigi/src/main/groovy/klarigi/App.groovy b/klarigi/src/main/groovy/klarigi/App.groovy index 2d67bed..9d8b47d 100644 --- a/klarigi/src/main/groovy/klarigi/App.groovy +++ b/klarigi/src/main/groovy/klarigi/App.groovy @@ -28,6 +28,7 @@ class App { _ longOpt: 'save-ic', 'Save the IC values to the given file', args:1 g longOpt: 'group', 'The group to explain.', args: 1 + gf longOpt: 'group-file', 'You can pass a file with a list of groups to: one per line. If you do this, the --group argument will be ignored.', args: 1 _ longOpt: 'max-ic', 'Max IC to use in stepdown algorithm. Default: 0.8', args: 1 _ longOpt: 'min-ic', 'Min IC to use in stepdown algorithm. Default: 0.4', args: 1 @@ -80,36 +81,44 @@ class App { def k = new Klarigi(o) if(!o['similarity-mode']) { - if(!o['group'] || (o['group'] && o['group'] == '*')) { - def allExplanations = k.explainAllClusters(o['output-scores'], o['power'], threads) - allExplanations.each { - k.output(it.cluster, it.results, o['output-type'], o['print-members'], o['output']) + def allExplanations + if(o['group-file']) { + def groups + try { + groups = new File(o['group-file']).text.split('\n') + } catch(e) { + println "Could not handle the --group-file: ${e.toString()}" + System.exit(1) } - if(o['output-exp-dataframe']) { - k.writeDataframe('train', allExplanations) - } - - if(o['reclassify']) { - k.reclassify(allExplanations, o['output-classification-scores']) - } - if(o['classify']) { - k.classify(o['classify'], allExplanations, o['output-classification-scores']) - - if(o['output-exp-dataframe']) { - k.writeDataframe('test', allExplanations) - } - } + allExplanations = k.explainClusters(groups, o['output-scores'], o['power'], threads) + } else if(o['group'] && o['group'] != '*') { + allExplanations = k.explainClusters([o['group']], o['output-scores'], o['power'], threads) } else { - def r = k.explainCluster(o['group'], o['power'], o['output-scores'], threads) - k.output(o['group'], r, o['output-type'], o['print-members'], o['output']) + allExplanations = k.explainAllClusters(o['output-scores'], o['power'], threads) + } - if(o['reclassify'] || o['output-exp-dataframe']) { - println "Must explain all groups for --reclassify or --output-exp-dataframe" + allExplanations.each { + k.output(it.cluster, it.results, o['output-type'], o['print-members'], o['output']) + } + + if(o['output-exp-dataframe']) { + k.writeDataframe('train', allExplanations) + } + + if(o['reclassify']) { + k.reclassify(allExplanations, o['output-classification-scores']) + } + if(o['classify']) { + k.classify(o['classify'], allExplanations, o['output-classification-scores']) + + if(o['output-exp-dataframe']) { + k.writeDataframe('test', allExplanations) } } + } else { - k.genSim(o['output']) + k.genSim(o['output'], o['group']) } } } diff --git a/klarigi/src/main/groovy/klarigi/InformationContent.groovy b/klarigi/src/main/groovy/klarigi/InformationContent.groovy index 91fec3e..bf818f4 100644 --- a/klarigi/src/main/groovy/klarigi/InformationContent.groovy +++ b/klarigi/src/main/groovy/klarigi/InformationContent.groovy @@ -106,12 +106,13 @@ public class InformationContent { } // this should really go to a diff class - def compareEntities(assoc) { + def compareEntities(assoc, groupings, group) { def smConfPairwise = new SMconf(SMConstants.FLAG_SIM_PAIRWISE_DAG_NODE_RESNIK_1995, icConf) def smConfGroupwise = new SMconf(SMConstants.FLAG_SIM_GROUPWISE_BMA, icConf) def results = [:] assoc.each { k1, v1 -> + if(group && !groupings[group].contains(k1)) { return; } if(!results.containsKey(k1)) { results[k1] = [:] } assoc.each { k2, v2 -> if(k1 == k2) { return; } @@ -134,7 +135,7 @@ public class InformationContent { results } - static def WriteSimilarity(results, groups, toFile) { + static def WriteSimilarity(results, toFile) { def out = [] results.each { k1, v1 -> diff --git a/klarigi/src/main/groovy/klarigi/Klarigi.groovy b/klarigi/src/main/groovy/klarigi/Klarigi.groovy index 6f0a01d..2afca67 100644 --- a/klarigi/src/main/groovy/klarigi/Klarigi.groovy +++ b/klarigi/src/main/groovy/klarigi/Klarigi.groovy @@ -179,6 +179,12 @@ public class Klarigi { } } + def explainClusters(groups, outputScores, powerMode, threads) { + data.groupings.findAll { g, v -> groups.contains(g) }.collect { g, v -> + [ cluster: g, results: explainCluster(g, powerMode, outputScores, threads) ] + } + } + def explainAllClusters(outputScores, powerMode, threads) { data.groupings.collect { g, v -> [ cluster: g, results: explainCluster(g, powerMode, outputScores, threads) ] @@ -210,12 +216,12 @@ public class Klarigi { } } - def genSim(toFile) { + def genSim(toFile, group) { if(!icFactory) { println "Error: IC class not loaded (--similarity and --ic are not compatible)" System.exit(1) } - def results = icFactory.compareEntities(data.associations) + def results = icFactory.compareEntities(data.associations, data.groupings, group) InformationContent.WriteSimilarity(results, toFile) }