Search in sources :

Example 31 with OntologyTerm

use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.

the class ExperimentalDesignImporterImpl method termForCategoryLookup.

/**
 * Does a lookup for the Ontology term to match the category.
 *
 * @param category category
 * @return vocab characteristic
 */
private VocabCharacteristic termForCategoryLookup(String category, Collection<OntologyTerm> terms) {
    OntologyTerm t = null;
    String lookup = category.replaceAll("_", " ").toLowerCase();
    for (OntologyTerm to : terms) {
        if (to.getTerm().equals(category) || to.getTerm().equals(lookup)) {
            t = to;
            break;
        }
    }
    if (t == null) {
        throw new IllegalArgumentException("No term matches '" + category + "' - formalized to: " + lookup);
    }
    VocabCharacteristic vc = VocabCharacteristic.Factory.newInstance();
    vc.setCategoryUri(t.getUri());
    vc.setCategory(t.getTerm());
    vc.setValueUri(t.getUri());
    vc.setValue(t.getTerm());
    vc.setEvidenceCode(GOEvidenceCode.IC);
    return vc;
}
Also used : VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic) OntologyTerm(ubic.basecode.ontology.model.OntologyTerm)

Example 32 with OntologyTerm

use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.

the class ExternalDatabaseEvidenceImporterAbstractCLI method findOmimMeshInDiseaseOntology.

// step 1 using an OMIM or MESH to link to a disease id
private boolean findOmimMeshInDiseaseOntology(String meshOrOmimId, Gene gene, String pubmed, String evidenceCode, String description, String externalDatabase, String databaseLink, Collection<OntologyTerm> onParents) throws Exception {
    String mappingType;
    StringBuilder valuesUri = new StringBuilder();
    StringBuilder originalPhenotype = new StringBuilder(meshOrOmimId);
    String meshOrOmimIdValue = this.findDescriptionUsingTerm(meshOrOmimId);
    // use the ontology to find description
    if (meshOrOmimIdValue != null) {
        originalPhenotype.append(" (").append(meshOrOmimIdValue.toLowerCase()).append(")");
    }
    // using parents
    if (onParents != null) {
        mappingType = PhenotypeMappingType.INFERRED_XREF.toString();
        HashMap<String, Collection<OntologyTerm>> dieaseOn = this.meshToDiseaseTerms(onParents);
        originalPhenotype.append(" PARENT: (");
        for (String key : dieaseOn.keySet()) {
            originalPhenotype.append(key).append(",");
        }
        originalPhenotype = new StringBuilder(StringUtils.removeEnd(originalPhenotype.toString(), ",") + ")");
        for (Collection<OntologyTerm> colOn : dieaseOn.values()) {
            for (OntologyTerm o : colOn) {
                valuesUri.append(o.getUri()).append(";");
            }
        }
    } else {
        mappingType = PhenotypeMappingType.XREF.toString();
        Collection<OntologyTerm> ontologyTerms = this.findOntologyTermsUriWithDiseaseId(meshOrOmimId);
        for (OntologyTerm ontologyTerm : ontologyTerms) {
            valuesUri.append(ontologyTerm.getUri()).append(";");
        }
    }
    if (valuesUri.length() > 0) {
        outFinalResults.write(gene.getOfficialSymbol() + "\t" + gene.getNcbiGeneId() + "\t" + pubmed + "\t" + evidenceCode + "\t" + description + "\t" + externalDatabase + "\t" + databaseLink + "\t" + mappingType + "\t" + originalPhenotype + "\t" + valuesUri + "\n");
        return true;
    }
    return false;
}
Also used : OntologyTerm(ubic.basecode.ontology.model.OntologyTerm)

Example 33 with OntologyTerm

use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.

the class ExternalDatabaseEvidenceImporterAbstractCLI method findMapping.

void findMapping(String meshOrOmimId, Gene gene, String pubmed, String evidenceCode, String description, String annotatorKeyword, String externalDatabase, String databaseLink) throws Exception {
    if (gene == null) {
        throw new IllegalArgumentException("Called with a gene being null   on line pubmed; " + pubmed);
    }
    boolean mappingFound;
    // do without parents
    mappingFound = this.findMapping(meshOrOmimId, gene, pubmed, evidenceCode, description, annotatorKeyword, externalDatabase, databaseLink, null);
    if (!mappingFound && meshOrOmimId != null) {
        OntologyTerm on = this.medicOntologyService.getTerm(this.changeMedicToUri(meshOrOmimId));
        if (on != null) {
            Collection<OntologyTerm> onParents = on.getParents(true);
            // use omim/mesh parents
            this.findMapping(meshOrOmimId, gene, pubmed, evidenceCode, description, annotatorKeyword, externalDatabase, databaseLink, onParents);
        }
    }
}
Also used : OntologyTerm(ubic.basecode.ontology.model.OntologyTerm)

Example 34 with OntologyTerm

use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.

the class ExternalDatabaseEvidenceImporterAbstractCLI method parseManualMappingFile.

private void parseManualMappingFile() throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(RgdDatabaseImporter.class.getResourceAsStream(ExternalDatabaseEvidenceImporterAbstractCLI.MANUAL_MAPPING)));
    String line;
    // skip first line, the headers
    br.readLine();
    // reads the manual file and put the data in a structure
    while ((line = br.readLine()) != null) {
        HashSet<String> col = new HashSet<>();
        String[] tokens = line.split("\t");
        String termId = tokens[0].trim().toLowerCase();
        String valueUriStaticFile = tokens[1].trim();
        String valueStaticFile = tokens[2].trim();
        OntologyTerm ontologyTerm = this.findOntologyTermExistAndNotObsolote(valueUriStaticFile);
        if (ontologyTerm != null) {
            if (ontologyTerm.getLabel().equalsIgnoreCase(valueStaticFile)) {
                if (manualDescriptionToValuesUriMapping.get(termId) != null) {
                    col = manualDescriptionToValuesUriMapping.get(termId);
                }
                col.add(valueUriStaticFile);
                manualDescriptionToValuesUriMapping.put(termId, col);
                keyToDescription.put(termId, valueStaticFile);
            } else {
                this.writeError("MANUAL VALUEURI AND VALUE DOESNT MATCH IN FILE: line" + line + "\t What the value supposed to be:" + ontologyTerm.getLabel());
            }
        } else {
            this.writeError("MANUAL MAPPING FILE TERM OBSOLETE OR NOT EXISTANT: '" + valueUriStaticFile + "' " + " (" + valueStaticFile + ")");
        }
    }
}
Also used : OntologyTerm(ubic.basecode.ontology.model.OntologyTerm)

Example 35 with OntologyTerm

use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.

the class ExternalDatabaseEvidenceImporterAbstractCLI method findOntologyTermsUriWithDiseaseId.

private Collection<OntologyTerm> findOntologyTermsUriWithDiseaseId(String diseaseId) {
    Collection<OntologyTerm> terms = new HashSet<>();
    Collection<String> valuesUri = diseaseFileMappingFound.get(diseaseId);
    if (valuesUri != null && !valuesUri.isEmpty()) {
        for (String valueUri : valuesUri) {
            OntologyTerm on = this.findOntologyTermExistAndNotObsolote(valueUri);
            if (on != null) {
                terms.add(on);
            }
        }
    }
    return terms;
}
Also used : OntologyTerm(ubic.basecode.ontology.model.OntologyTerm)

Aggregations

OntologyTerm (ubic.basecode.ontology.model.OntologyTerm)73 Test (org.junit.Test)13 VocabCharacteristic (ubic.gemma.model.common.description.VocabCharacteristic)13 Gene (ubic.gemma.model.genome.Gene)11 OntologyResource (ubic.basecode.ontology.model.OntologyResource)8 HashSet (java.util.HashSet)6 StopWatch (org.apache.commons.lang3.time.StopWatch)6 CharacteristicValueObject (ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject)6 BufferedReader (java.io.BufferedReader)3 ConcurrentHashSet (org.compass.core.util.concurrent.ConcurrentHashSet)3 Element (org.w3c.dom.Element)3 OntologyIndividual (ubic.basecode.ontology.model.OntologyIndividual)3 EntityNotFoundException (ubic.gemma.core.association.phenotype.PhenotypeExceptions.EntityNotFoundException)3 Characteristic (ubic.gemma.model.common.description.Characteristic)3 GeneEvidenceValueObject (ubic.gemma.model.genome.gene.phenotype.valueObject.GeneEvidenceValueObject)3 Resource (com.hp.hpl.jena.rdf.model.Resource)2 FileReader (java.io.FileReader)2 SocketException (java.net.SocketException)2 Collection (java.util.Collection)2 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)2