use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class DgaDatabaseImporter method findTermsWithParents.
// extra step to take out redundant terms, if a child term is more specific dont keep the parent, if 2 lines share
// same pubmed, gene and gene RIF take the most specific uri
// example: same pubed, same gene 1-leukemia 2-myeloid leukemia 3-acute myeloid leukemia, keep only 3-
private void findTermsWithParents() throws Exception {
try (BufferedReader dgaReader = new BufferedReader(new FileReader(dgaFile))) {
String line;
while ((line = dgaReader.readLine()) != null) {
// found a term
if (line.contains("DOID")) {
// this being of the url could change make sure its still correct if something doesn't work
String valueUri = "http://purl.obolibrary.org/obo/DOID_" + this.findStringBetweenSpecialCharacter(line);
String geneId = this.findStringBetweenSpecialCharacter(dgaReader.readLine(), "GeneID");
String pubMedID = this.findStringBetweenSpecialCharacter(dgaReader.readLine(), "PubMedID");
String geneRIF = this.findStringBetweenSpecialCharacter(dgaReader.readLine(), "GeneRIF");
OntologyTerm o = this.findOntologyTermExistAndNotObsolote(valueUri);
if (o != null) {
String key = geneId + pubMedID + geneRIF;
HashSet<OntologyTerm> valuesUri = new HashSet<>();
if (commonLines.get(key) != null) {
valuesUri = commonLines.get(key);
}
valuesUri.add(o);
commonLines.put(key, valuesUri);
}
}
}
dgaReader.close();
}
for (String key : commonLines.keySet()) {
AbstractCLI.log.info("Checking for lines that are ontology duplicated: " + key);
HashSet<OntologyTerm> ontologyTerms = commonLines.get(key);
HashSet<String> allUri = new HashSet<>();
for (OntologyTerm o : ontologyTerms) {
allUri.add(o.getUri());
}
for (OntologyTerm o : ontologyTerms) {
// get all kids terms
Collection<OntologyTerm> childrenOntology = o.getChildren(false);
for (OntologyTerm onChil : childrenOntology) {
// then this line is a parent dont keep it there is more specific child term
if (allUri.contains(onChil.getUri())) {
// result of this method, set of lines to exclude in the checkForDGAFile() step :
linesToExclude.add(key + o.getUri());
}
}
}
}
}
use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class EvidenceImporterCLI method experiementTags2Ontology.
private Set<CharacteristicValueObject> experiementTags2Ontology(Set<String> values, String category, String categoryUri, AbstractOntologyService ontologyUsed) {
Set<CharacteristicValueObject> experimentTags = new HashSet<>();
for (String term : values) {
String valueUri = "";
if (ontologyUsed != null) {
Collection<OntologyTerm> ontologyTerms = ontologyUsed.findTerm(term);
OntologyTerm ot = this.findExactTerm(ontologyTerms, term);
if (ot != null) {
valueUri = ot.getUri();
}
}
CharacteristicValueObject c = new CharacteristicValueObject(-1L, term, category, valueUri, categoryUri);
experimentTags.add(c);
}
return experimentTags;
}
use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class EvidenceImporterCLI method phenotype2Ontology.
// value or valueUri given changed to valueUri (even if valueUri is given in file we need to check)
private String phenotype2Ontology(String phenotypeToSearch) {
OntologyTerm ot;
// we got an uri, search by uri
if (phenotypeToSearch.contains("http://purl.")) {
AbstractCLI.log.info("Found an URI: " + phenotypeToSearch);
ot = this.diseaseOntologyService.getTerm(phenotypeToSearch);
if (ot == null) {
ot = this.humanPhenotypeOntologyService.getTerm(phenotypeToSearch);
}
if (ot == null) {
this.mammalianPhenotypeOntologyService.getTerm(phenotypeToSearch);
}
} else // value found
{
// search disease
Collection<OntologyTerm> ontologyTerms = this.diseaseOntologyService.findTerm(phenotypeToSearch);
ot = this.findExactTerm(ontologyTerms, phenotypeToSearch);
if (ot == null) {
// search hp
ontologyTerms = this.humanPhenotypeOntologyService.findTerm(phenotypeToSearch);
ot = this.findExactTerm(ontologyTerms, phenotypeToSearch);
}
if (ot == null) {
// search mammalian
ontologyTerms = this.mammalianPhenotypeOntologyService.findTerm(phenotypeToSearch);
this.findExactTerm(ontologyTerms, phenotypeToSearch);
}
}
return phenotypeToSearch;
}
use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class EvidenceImporterAbstractCLI method findExactTerm.
/**
* find the exact term of a search term in a Collection of Ontology terms
*
* @param ontologyTerms Collection of ontologyTerms
* @param search The value we are interested in finding
* @return OntologyTerm the exact match value found
*/
OntologyTerm findExactTerm(Collection<OntologyTerm> ontologyTerms, String search) {
// list of OntologyTerms found
Collection<OntologyTerm> ontologyKept = new HashSet<>();
OntologyTerm termFound = null;
for (OntologyTerm ot : ontologyTerms) {
if (ot.getLabel() != null) {
if (ot.getLabel().equalsIgnoreCase(search)) {
ontologyKept.add(ot);
termFound = ot;
}
}
}
// if we have more than 1 result, hardcode the one to choose
if (ontologyKept.size() > 1) {
if (search.equalsIgnoreCase("juvenile")) {
for (OntologyTerm ontologyTerm : ontologyKept) {
if (ontologyTerm.getUri().equalsIgnoreCase("http://purl.org/obo/owl/PATO#PATO_0001190")) {
return ontologyTerm;
}
}
} else if (search.equalsIgnoreCase("adult")) {
for (OntologyTerm ontologyTerm : ontologyKept) {
if (ontologyTerm.getUri().equalsIgnoreCase("http://ontology.neuinfo.org/NIF/BiomaterialEntities/NIF-Organism.owl#birnlex_681")) {
return ontologyTerm;
}
}
} else if (search.equalsIgnoreCase("newborn")) {
for (OntologyTerm ontologyTerm : ontologyKept) {
if (ontologyTerm.getUri().equalsIgnoreCase("http://ontology.neuinfo.org/NIF/BiomaterialEntities/NIF-Organism.owl#birnlex_699")) {
return ontologyTerm;
}
}
} else if (search.equalsIgnoreCase("prenatal")) {
for (OntologyTerm ontologyTerm : ontologyKept) {
if (ontologyTerm.getUri().equalsIgnoreCase("http://ontology.neuinfo.org/NIF/BiomaterialEntities/NIF-Organism.owl#birnlex_7014")) {
return ontologyTerm;
}
}
} else if (search.equalsIgnoreCase("infant")) {
for (OntologyTerm ontologyTerm : ontologyKept) {
if (ontologyTerm.getUri().equalsIgnoreCase("http://ontology.neuinfo.org/NIF/BiomaterialEntities/NIF-Organism.owl#birnlex_695")) {
return ontologyTerm;
}
}
} else if (search.equalsIgnoreCase("elderly")) {
for (OntologyTerm ontologyTerm : ontologyKept) {
if (ontologyTerm.getUri().equalsIgnoreCase("http://ontology.neuinfo.org/NIF/BiomaterialEntities/NIF-Organism.owl#birnlex_691")) {
return ontologyTerm;
}
}
}
}
if (ontologyKept.size() > 1) {
if (search.equalsIgnoreCase("apraxia")) {
for (OntologyTerm o : ontologyKept) {
if (o.getLabel().equalsIgnoreCase("apraxia") && o.getUri().equalsIgnoreCase("http://purl.obolibrary.org/obo/DOID_4019")) {
return o;
}
}
}
this.writeError("More than 1 term found for : " + search + " " + ontologyKept.size());
for (OntologyTerm o : ontologyKept) {
this.writeError(o.getLabel() + " " + o.getUri());
}
}
return termFound;
}
use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class ExternalDatabaseEvidenceImporterAbstractCLI method meshToDiseaseTerms.
private HashMap<String, Collection<OntologyTerm>> meshToDiseaseTerms(Collection<OntologyTerm> meshTerms) {
HashMap<String, Collection<OntologyTerm>> diseaseTerms = new HashMap<>();
for (OntologyTerm m : meshTerms) {
String meshId = this.changeToId(m.getUri());
Collection<OntologyTerm> onDisease = this.findOntologyTermsUriWithDiseaseId(meshId);
if (!onDisease.isEmpty()) {
diseaseTerms.put(meshId, onDisease);
}
}
return diseaseTerms;
}
Aggregations