use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class SearchServiceImpl method getDirectChildTerms.
/**
* Returns children one step down.
*
* @param term starting point
*/
@SuppressWarnings("unchecked")
private Collection<OntologyTerm> getDirectChildTerms(OntologyTerm term) {
String uri = term.getUri();
/*
* getChildren can be very slow for 'high-level' classes like "neoplasm", so we use a cache.
*/
Collection<OntologyTerm> children = null;
if (StringUtils.isBlank(uri)) {
// shouldn't happen, but just in case
if (SearchServiceImpl.log.isDebugEnabled())
SearchServiceImpl.log.debug("Blank uri for " + term);
}
Element cachedChildren = this.childTermCache.get(uri);
if (cachedChildren == null) {
try {
children = term.getChildren(true);
childTermCache.put(new Element(uri, children));
} catch (com.hp.hpl.jena.ontology.ConversionException ce) {
SearchServiceImpl.log.warn("getting children for term: " + term + " caused com.hp.hpl.jena.ontology.ConversionException. " + ce.getMessage());
}
} else {
children = (Collection<OntologyTerm>) cachedChildren.getObjectValue();
}
return children;
}
use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class GoMetric method computePercentOverlap.
/**
* @param gene1 gene 1
* @param gene2 gene 2
* @param includePartOf include part of
* @return percent of overlapping terms wrt to the gene with the lower number of GO terms
*/
private Double computePercentOverlap(Gene gene1, Gene gene2, boolean includePartOf) {
if (!geneOntologyService.isReady())
GoMetric.log.error("computeSimpleOverlap called before geneOntologyService is ready!!!");
Double avgScore = 0.0;
Collection<OntologyTerm> masterGO = geneOntologyService.getGOTerms(gene1, includePartOf, null);
Collection<OntologyTerm> coExpGO = geneOntologyService.getGOTerms(gene2, includePartOf, null);
Collection<OntologyTerm> overlappingTerms = new HashSet<>();
for (OntologyTerm o : masterGO) {
if (coExpGO.contains(o) && !this.isRoot(o))
overlappingTerms.add(o);
}
if (masterGO.size() < coExpGO.size()) {
avgScore = (double) overlappingTerms.size() / masterGO.size();
}
if (coExpGO.size() < masterGO.size()) {
avgScore = (double) overlappingTerms.size() / coExpGO.size();
}
if (coExpGO.size() == masterGO.size()) {
avgScore = (double) overlappingTerms.size() / coExpGO.size();
}
return avgScore;
}
use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class GoMetric method computeMaxSimilarity.
/**
* @param metric metric
* @param GOProbMap go prob map
* @param queryGene query gene
* @param targetGene target gene
* @return the MAX overlap score between two genes
*/
public Double computeMaxSimilarity(Gene queryGene, Gene targetGene, Map<String, Double> GOProbMap, Metric metric) {
Collection<OntologyTerm> masterGO = this.getOntologyTerms(queryGene);
if ((masterGO == null) || masterGO.isEmpty())
return 0.0;
Collection<OntologyTerm> coExpGO = this.getOntologyTerms(targetGene);
if ((coExpGO == null) || coExpGO.isEmpty())
return 0.0;
double checkScore = 0.0;
for (OntologyTerm ontoM : masterGO) {
if (this.isRoot(ontoM))
continue;
if (!GOProbMap.containsKey(ontoM.getUri()))
continue;
double probM = GOProbMap.get(ontoM.getUri());
for (OntologyTerm ontoC : coExpGO) {
if (this.isRoot(ontoC))
continue;
if (!GOProbMap.containsKey(ontoC.getUri()))
continue;
Double probC = GOProbMap.get(ontoC.getUri());
Double pMin;
Double score;
if (ontoM.getUri().equalsIgnoreCase(ontoC.getUri()))
pMin = GOProbMap.get(ontoM.getUri());
else
pMin = this.checkParents(ontoM, ontoC, GOProbMap);
if (pMin < 1) {
score = this.getMetric(metric, pMin, probM, probC);
if (score > checkScore)
checkScore = score;
}
}
}
GoMetric.log.info("score for " + queryGene + " and " + targetGene + " is " + checkScore);
return checkScore;
}
use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class GoMetric method computeSimpleOverlap.
/**
* @param gene1 gene 1
* @param gene2 gene 2
* @param includePartOf include part of
* @return number of overlapping terms
*/
private Double computeSimpleOverlap(Gene gene1, Gene gene2, boolean includePartOf) {
if (!geneOntologyService.isReady())
GoMetric.log.error("computeSimpleOverlap called before geneOntologyService is ready!!!");
Collection<OntologyTerm> masterGO = geneOntologyService.getGOTerms(gene1, includePartOf, null);
Collection<OntologyTerm> coExpGO = geneOntologyService.getGOTerms(gene2, includePartOf, null);
Collection<OntologyTerm> overlappingTerms = new HashSet<>();
for (OntologyTerm o : masterGO) {
if (coExpGO.contains(o) && !this.isRoot(o))
overlappingTerms.add(o);
}
return (double) overlappingTerms.size();
}
use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class GoMetric method computeSimilarity.
/**
* @param metric metric
* @param GOProbMap go prob map
* @param queryGene query gene
* @param targetGene target gene
* @return the overlap score between two genes
*/
public Double computeSimilarity(Gene queryGene, Gene targetGene, Map<String, Double> GOProbMap, Metric metric) {
if (metric.equals(GoMetric.Metric.simple)) {
return this.computeSimpleOverlap(queryGene, targetGene, partOf);
}
if (metric.equals(GoMetric.Metric.percent)) {
return this.computePercentOverlap(queryGene, targetGene, partOf);
}
Collection<OntologyTerm> masterGO = this.getOntologyTerms(queryGene);
if ((masterGO == null) || masterGO.isEmpty())
return 0.0;
Collection<OntologyTerm> coExpGO = this.getOntologyTerms(targetGene);
if ((coExpGO == null) || coExpGO.isEmpty())
return 0.0;
double total = 0;
int count = 0;
for (OntologyTerm ontoM : masterGO) {
if (this.isRoot(ontoM))
continue;
if (!GOProbMap.containsKey(ontoM.getUri()))
continue;
double probM = GOProbMap.get(ontoM.getUri());
for (OntologyTerm ontoC : coExpGO) {
if (this.isRoot(ontoC))
continue;
if (!GOProbMap.containsKey(ontoC.getUri()))
continue;
Double probC = GOProbMap.get(ontoC.getUri());
Double pMin;
Double score;
if (ontoM.getUri().equalsIgnoreCase(ontoC.getUri()))
pMin = GOProbMap.get(ontoM.getUri());
else
pMin = this.checkParents(ontoM, ontoC, GOProbMap);
if (pMin < 1) {
score = this.getMetric(metric, pMin, probM, probC);
total += score;
count++;
}
}
}
if (total > 0) {
double avgScore = total / count;
GoMetric.log.info("score for " + queryGene + " and " + targetGene + " is " + avgScore);
return avgScore;
}
GoMetric.log.info("NO score for " + queryGene + " and " + targetGene);
return 0.0;
}
Aggregations