use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class PhenotypeAssociationManagerServiceImpl method findPhenotypeCount.
/**
* @param taxon taxon
* @param ontologyTermsFound ontology terms found
* @param phenotypesFoundAndChildren phenotypes found and their children
* @return For a given Ontology Term, count the occurence of the term + children in the database
*/
private Collection<CharacteristicValueObject> findPhenotypeCount(Collection<OntologyTerm> ontologyTermsFound, Taxon taxon, Set<String> phenotypesFoundAndChildren) {
Collection<CharacteristicValueObject> phenotypesFound = new HashSet<>();
// Phenotype ---> Genes
Map<String, Set<Integer>> publicPhenotypesGenesAssociations = this.phenoAssocService.findPublicPhenotypesGenesAssociations(taxon, phenotypesFoundAndChildren, null, null, false, null, false);
// for each Ontoly Term find in the search
for (OntologyTerm ontologyTerm : ontologyTermsFound) {
Set<Integer> geneFoundForOntologyTerm = new HashSet<>();
if (publicPhenotypesGenesAssociations.get(ontologyTerm.getUri()) != null) {
geneFoundForOntologyTerm.addAll(publicPhenotypesGenesAssociations.get(ontologyTerm.getUri()));
}
// for all his children
for (OntologyTerm ontologyTermChildren : ontologyTerm.getChildren(false)) {
if (publicPhenotypesGenesAssociations.get(ontologyTermChildren.getUri()) != null) {
geneFoundForOntologyTerm.addAll(publicPhenotypesGenesAssociations.get(ontologyTermChildren.getUri()));
}
}
// count the number of distinct gene linked to this ontologyTerm ( or children) in the database
if (!geneFoundForOntologyTerm.isEmpty()) {
CharacteristicValueObject characteristicValueObject = new CharacteristicValueObject(-1L, ontologyTerm.getLabel().toLowerCase(), ontologyTerm.getUri());
characteristicValueObject.setPublicGeneCount(geneFoundForOntologyTerm.size());
characteristicValueObject.setTaxon(taxon.getCommonName());
phenotypesFound.add(characteristicValueObject);
}
}
return phenotypesFound;
}
use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class PhenotypeAssociationManagerServiceImpl method determineSameGeneAndPhenotypeAnnotated.
/**
* @param evidence evidence
* @param pubmed pub med
* @return Populates the ValidateEvidenceValueObject with the correct flags if necessary
*/
private ValidateEvidenceValueObject determineSameGeneAndPhenotypeAnnotated(EvidenceValueObject<PhenotypeAssociation> evidence, String pubmed) {
ValidateEvidenceValueObject validateEvidenceValueObject = null;
BibliographicReferenceValueObject bibliographicReferenceValueObject = this.findBibliographicReference(pubmed);
if (bibliographicReferenceValueObject == null) {
validateEvidenceValueObject = new ValidateEvidenceValueObject();
validateEvidenceValueObject.setPubmedIdInvalid(true);
} else {
// rule to determine if its an update
if (evidence.getId() != null) {
PhenotypeAssociation phenotypeAssociation = this.phenoAssocService.load(evidence.getId());
if (phenotypeAssociation == null) {
validateEvidenceValueObject = new ValidateEvidenceValueObject();
validateEvidenceValueObject.setEvidenceNotFound(true);
return validateEvidenceValueObject;
}
// check for the race condition
if (phenotypeAssociation.getLastUpdated().getTime() != evidence.getLastUpdated()) {
validateEvidenceValueObject = new ValidateEvidenceValueObject();
validateEvidenceValueObject.setLastUpdateDifferent(true);
return validateEvidenceValueObject;
}
}
for (BibliographicPhenotypesValueObject bibliographicPhenotypesValueObject : bibliographicReferenceValueObject.getBibliographicPhenotypes()) {
if (evidence.getId() != null) {
// dont compare evidence to itself since it already exists
if (evidence.getId().equals(bibliographicPhenotypesValueObject.getEvidenceId())) {
continue;
}
}
// look if the gene have already been annotated
if (evidence.getGeneNCBI().equals(bibliographicPhenotypesValueObject.getGeneNCBI())) {
if (validateEvidenceValueObject == null) {
validateEvidenceValueObject = new ValidateEvidenceValueObject();
}
validateEvidenceValueObject.setSameGeneAnnotated(true);
validateEvidenceValueObject.getProblematicEvidenceIds().add(bibliographicPhenotypesValueObject.getEvidenceId());
boolean containsExact = true;
for (CharacteristicValueObject phenotype : evidence.getPhenotypes()) {
if (!bibliographicPhenotypesValueObject.getPhenotypesValues().contains(phenotype)) {
containsExact = false;
}
}
if (containsExact) {
validateEvidenceValueObject.setSameGeneAndOnePhenotypeAnnotated(true);
validateEvidenceValueObject.getProblematicEvidenceIds().add(bibliographicPhenotypesValueObject.getEvidenceId());
}
if (evidence.getPhenotypes().size() == bibliographicPhenotypesValueObject.getPhenotypesValues().size() && evidence.getPhenotypes().containsAll(bibliographicPhenotypesValueObject.getPhenotypesValues())) {
validateEvidenceValueObject.setSameGeneAndPhenotypesAnnotated(true);
validateEvidenceValueObject.getProblematicEvidenceIds().add(bibliographicPhenotypesValueObject.getEvidenceId());
}
Set<String> parentOrChildTerm = new HashSet<>();
// the phenotype we want to add is not in that subset
for (CharacteristicValueObject phenotypeAlreadyPresent : bibliographicPhenotypesValueObject.getPhenotypesValues()) {
OntologyTerm ontologyTerm = this.ontologyService.getTerm(phenotypeAlreadyPresent.getValueUri());
for (OntologyTerm ot : ontologyTerm.getParents(true)) {
parentOrChildTerm.add(ot.getUri());
}
for (OntologyTerm ot : ontologyTerm.getChildren(false)) {
parentOrChildTerm.add(ot.getUri());
}
}
for (CharacteristicValueObject characteristicValueObject : evidence.getPhenotypes()) {
if (parentOrChildTerm.contains(characteristicValueObject.getValueUri())) {
validateEvidenceValueObject.setSameGeneAndPhenotypeChildOrParentAnnotated(true);
validateEvidenceValueObject.getProblematicEvidenceIds().add(bibliographicPhenotypesValueObject.getEvidenceId());
}
}
}
}
}
return validateEvidenceValueObject;
}
use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class PhenotypeAssociationManagerServiceImpl method findChildrenForEachPhenotype.
/**
* Map query phenotypes given to the set of possible children phenotypes in the database so for example if the user
* search for : cerebral palsy (parent phenotype), this will return all children associated with it that are also
* present in the database(all children of phenotype) : Map<String(parent phenotype), Set<String>(all children of
* phenotype)>
*
* @param usedPhenotypes the URIs of all phenotypes actually used in the database.
* @param phenotypesValuesUris URIs
* @return map of terms to their children. The term itself is included.
*/
private Map<String, Set<String>> findChildrenForEachPhenotype(Collection<String> phenotypesValuesUris, Collection<String> usedPhenotypes) {
// root corresponds to one value found in phenotypesValuesUri
// root ---> root+children phenotypes
Map<String, Set<String>> parentPheno = new HashMap<>();
// determine all children terms for each other phenotypes
for (String phenoRoot : phenotypesValuesUris) {
if (phenoRoot.isEmpty()) {
continue;
}
OntologyTerm ontologyTermFound;
try {
ontologyTermFound = this.ontologyHelper.findOntologyTermByUri(phenoRoot);
if (ontologyTermFound == null)
continue;
} catch (EntityNotFoundException e) {
if (!ontologyHelper.areOntologiesAllLoaded()) {
throw new RuntimeException(PhenotypeAssociationManagerServiceImpl.ERROR_MSG_ONTOLOGIES_NOT_LOADED + " ( " + e.getMessage() + " )");
} else {
throw e;
}
}
Collection<OntologyTerm> ontologyChildrenFound = ontologyTermFound.getChildren(false);
Set<String> parentChildren = new HashSet<>();
parentChildren.add(phenoRoot);
for (OntologyTerm ot : ontologyChildrenFound) {
if (usedPhenotypes.contains(ot.getUri())) {
parentChildren.add(ot.getUri());
}
}
parentPheno.put(phenoRoot, parentChildren);
}
return parentPheno;
}
use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class PhenotypeAssoOntologyHelperImpl method ontology2CharacteristicValueObject.
/**
* Ontology term to CharacteristicValueObject
*
* @return collection of the input, converted to 'shell' CharacteristicValueObjects (which have other slots we want
* to use)
*/
private Set<CharacteristicValueObject> ontology2CharacteristicValueObject(Collection<OntologyTerm> ontologyTerms) {
Set<CharacteristicValueObject> characteristicsVO = new HashSet<>();
for (OntologyTerm ontologyTerm : ontologyTerms) {
CharacteristicValueObject phenotype = new CharacteristicValueObject(-1L, ontologyTerm.getLabel().toLowerCase(), ontologyTerm.getUri());
characteristicsVO.add(phenotype);
}
return characteristicsVO;
}
use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class PhenotypeAssoOntologyHelperImpl method characteristicValueObject2Characteristic.
@Override
public VocabCharacteristic characteristicValueObject2Characteristic(CharacteristicValueObject characteristicValueObject) {
VocabCharacteristic characteristic = VocabCharacteristic.Factory.newInstance();
characteristic.setCategory(characteristicValueObject.getCategory());
characteristic.setCategoryUri(characteristicValueObject.getCategoryUri());
characteristic.setValue(characteristicValueObject.getValue());
if (characteristic.getValueUri() != null && !characteristic.getValueUri().equals("")) {
characteristic.setValueUri(characteristicValueObject.getValueUri());
} else {
// format the query for lucene to look for ontology terms with an exact match for the value
String value = "\"" + StringUtils.join(characteristicValueObject.getValue().trim().split(" "), " AND ") + "\"";
Collection<OntologyTerm> ontologyTerms = this.ontologyService.findTerms(value);
for (OntologyTerm ontologyTerm : ontologyTerms) {
if (ontologyTerm.getLabel().equalsIgnoreCase(characteristicValueObject.getValue())) {
characteristic.setValueUri(ontologyTerm.getUri());
break;
}
}
}
return characteristic;
}
Aggregations