Search in sources :

Example 51 with OntologyTerm

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

the class ExternalDatabaseEvidenceImporterAbstractCLI method findUsingManualMappingFile.

// step 2 manual mapping file
private boolean findUsingManualMappingFile(String meshOrOmimId, String annotatorKeyword, Gene gene, String pubmed, String evidenceCode, String description, String externalDatabase, String databaseLink, Collection<OntologyTerm> onParents) throws Exception {
    String mappingType;
    StringBuilder originalPhenotype;
    Collection<String> phenotypesUri = new HashSet<>();
    if (onParents != null) {
        mappingType = PhenotypeMappingType.INFERRED_CURATED.toString();
        originalPhenotype = new StringBuilder(meshOrOmimId + this.findExtraInfoMeshDescription(meshOrOmimId) + " PARENT: (");
        for (OntologyTerm o : onParents) {
            String meshId = this.changeToId(o.getUri());
            Collection<String> uri = this.findManualMappingTermValueUri(meshId);
            if (uri != null && !uri.isEmpty()) {
                phenotypesUri.addAll(uri);
                originalPhenotype.append(meshId).append(",");
            }
        }
        originalPhenotype = new StringBuilder(StringUtils.removeEnd(originalPhenotype.toString(), ",") + ")");
    } else {
        mappingType = PhenotypeMappingType.CURATED.toString();
        if (meshOrOmimId != null) {
            originalPhenotype = new StringBuilder(meshOrOmimId);
        } else {
            originalPhenotype = new StringBuilder(annotatorKeyword);
        }
        phenotypesUri = this.findManualMappingTermValueUri(originalPhenotype.toString());
        originalPhenotype.append(this.findExtraInfoMeshDescription(originalPhenotype.toString()));
    }
    if (phenotypesUri != null && !phenotypesUri.isEmpty()) {
        outFinalResults.write(gene.getOfficialSymbol() + "\t" + gene.getNcbiGeneId() + "\t" + pubmed + "\t" + evidenceCode + "\t" + description + "\t" + externalDatabase + "\t" + databaseLink + "\t" + mappingType + "\t" + originalPhenotype + "\t" + StringUtils.join(phenotypesUri, ";") + "\n");
        return true;
    }
    return false;
}
Also used : OntologyTerm(ubic.basecode.ontology.model.OntologyTerm)

Example 52 with OntologyTerm

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

the class ExternalDatabaseEvidenceImporterAbstractCLI method findDescriptionUsingTerm.

private String findDescriptionUsingTerm(String meshOrOmimId) throws Exception {
    OntologyTerm ontologyTerm = this.medicOntologyService.getTerm(this.changeMedicToUri(meshOrOmimId));
    if (ontologyTerm != null) {
        return ontologyTerm.getLabel();
    }
    String conceptId = meshOrOmimId.substring(meshOrOmimId.indexOf(":") + 1, meshOrOmimId.length());
    // root term in medic
    if (conceptId.equalsIgnoreCase("C")) {
        return null;
    }
    // look in cache
    if (omimIDToLabel.containsKey(conceptId)) {
        return omimIDToLabel.get(conceptId);
    }
    String label;
    if (meshOrOmimId.contains("OMIM:")) {
        label = AnnotatorClient.findLabelUsingIdentifier(1348L, conceptId);
    } else if (meshOrOmimId.contains("MESH:")) {
        label = AnnotatorClient.findLabelUsingIdentifier(3019L, conceptId);
    } else {
        throw new Exception("diseaseId not OMIM or MESH: " + meshOrOmimId);
    }
    omimIDToLabel.put(conceptId, label);
    return label;
}
Also used : OntologyTerm(ubic.basecode.ontology.model.OntologyTerm) SocketException(java.net.SocketException)

Example 53 with OntologyTerm

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

the class ExternalDatabaseEvidenceImporterAbstractCLI method findWithAnnotator.

// step 3
private boolean findWithAnnotator(String meshOrOmimId, String keywordSearchAnnotator, String externalDatabase, boolean modifySearch, Collection<OntologyTerm> onParents, String child) throws Exception {
    String usedChild = "";
    if (child == null) {
        usedChild = null;
    }
    if (onParents != null) {
        for (OntologyTerm o : onParents) {
            boolean found = this.findWithAnnotator(o.getLabel(), keywordSearchAnnotator, externalDatabase, modifySearch, null, meshOrOmimId);
            if (found) {
                return true;
            }
        }
        return false;
    }
    String searchTerm = keywordSearchAnnotator.toLowerCase();
    Collection<AnnotatorResponse> annotatorResponses = null;
    String key = meshOrOmimId;
    // we are not dealing with an omim identifier, gwas using this case for example
    if (key == null) {
        key = keywordSearchAnnotator;
    }
    if (modifySearch) {
        searchTerm = ExternalDatabaseEvidenceImporterAbstractCLI.removeSpecificKeywords(keywordSearchAnnotator.toLowerCase());
    }
    if (!descriptionToIgnore.contains(searchTerm)) {
        // we already know the answer for this term
        if (cacheAnswerFromAnnotator.containsKey(searchTerm)) {
            return false;
        }
        // search with the annotator and filter result to take out obsolete terms given
        try {
            annotatorResponses = this.removeNotExistAndObsolete(AnnotatorClient.findTerm(searchTerm));
        } catch (SocketException e1) {
            Thread.sleep(10000);
            try {
                annotatorResponses = this.removeNotExistAndObsolete(AnnotatorClient.findTerm(searchTerm));
            } catch (SocketException e2) {
                Thread.sleep(10000);
                try {
                    annotatorResponses = this.removeNotExistAndObsolete(AnnotatorClient.findTerm(searchTerm));
                } catch (SocketException e3) {
                    AbstractCLI.log.error("connection problem");
                    return false;
                }
            }
        }
        cacheAnswerFromAnnotator.put(searchTerm, annotatorResponses);
        if (annotatorResponses != null && !annotatorResponses.isEmpty()) {
            AnnotatorResponse annotatorResponse = annotatorResponses.iterator().next();
            String condition = annotatorResponse.findCondition(modifySearch);
            if (condition != null) {
                OntologyTerm on = this.findOntologyTermExistAndNotObsolote(annotatorResponse.getValueUri());
                if (on != null) {
                    searchTerm = AnnotatorClient.removeSpecialCharacters(searchTerm).replaceAll("\\+", " ");
                    if (modifySearch) {
                        searchTerm = searchTerm + "   (" + keywordSearchAnnotator + ")";
                    }
                    String lineToWrite = key + "\t" + on.getUri() + "\t" + on.getLabel() + "\t" + searchTerm + "\t" + usedChild + "\t" + condition + "\t" + externalDatabase + "\n";
                    outMappingFoundBuffer.add(lineToWrite);
                    return true;
                }
            }
        }
    }
    logRequestAnnotator.write(AnnotatorClient.removeSpecialCharacters(searchTerm).replaceAll("\\+", " ") + "   (" + keywordSearchAnnotator + ")\t");
    if (annotatorResponses != null && !annotatorResponses.isEmpty()) {
        for (AnnotatorResponse ar : annotatorResponses) {
            logRequestAnnotator.write(ar.getTxtMatched() + ";   ");
        }
    }
    logRequestAnnotator.write("\n");
    logRequestAnnotator.flush();
    return false;
}
Also used : SocketException(java.net.SocketException) OntologyTerm(ubic.basecode.ontology.model.OntologyTerm) AnnotatorResponse(ubic.basecode.ontology.ncbo.AnnotatorResponse)

Example 54 with OntologyTerm

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

the class ExperimentalDesignImporterImpl method addExperimentalFactorsToExperimentalDesign.

/**
 * This method reads the file line e.g. $Run time : Category=environmental_history Type=categorical and creates
 * experimental factors from it and adds them to the experimental design.
 * NOTE that this doesn't have the ability to add values to existing factors, which might be desirable.
 *
 * @param experimentalDesign          Experimental design for this expression experiment
 * @param experimentalFactorFileLines List of strings representing lines from input file containing experimental
 *                                    factors
 * @param headerFields                Sample header line split on tab.
 * @param factorValueLines            Lines containing biomaterial names and their factor values
 */
private void addExperimentalFactorsToExperimentalDesign(ExperimentalDesign experimentalDesign, List<String> experimentalFactorFileLines, String[] headerFields, List<String> factorValueLines) {
    int maxWait = 0;
    if (efoService.isEnabled()) {
        while (!efoService.isOntologyLoaded()) {
            try {
                Thread.sleep(10000);
                if (maxWait++ > 10) {
                    ExperimentalDesignImporterImpl.log.error("EFO is not loaded and gave up waiting");
                    break;
                // this is okay, we can get by using OntologyTermSimple.
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    Collection<OntologyTerm> terms = ontologyService.getCategoryTerms();
    if (experimentalDesign.getExperimentalFactors() == null) {
        experimentalDesign.setExperimentalFactors(new HashSet<ExperimentalFactor>());
    }
    Map<String, Set<String>> mapFactorSampleValues = this.getMapFactorSampleValues(headerFields, factorValueLines);
    for (String experimentalFactorFileLine : experimentalFactorFileLines) {
        // $Run time : Category=EnvironmentalHistory Type=categorical
        String[] experimentalFactorfields = experimentalFactorFileLine.split(":");
        String factorValue = (StringUtils.strip(experimentalFactorfields[0].replaceFirst(Pattern.quote(ExperimentalDesignImporterImpl.EXPERIMENTAL_FACTOR_DESCRIPTION_LINE_INDICATOR) + "\\s*", ""))).trim();
        String categoryAndType = StringUtils.strip(experimentalFactorfields[1]);
        String[] categoryAndTypeFields = StringUtils.split(categoryAndType);
        // e.g. Category=EnvironmentalHistory
        String category = categoryAndTypeFields[0];
        // e.g. EnvironmentalHistory
        String categoryValue = StringUtils.split(category, "=")[1];
        ExperimentalFactor experimentalFactorFromFile = ExperimentalFactor.Factory.newInstance();
        experimentalFactorFromFile.setExperimentalDesign(experimentalDesign);
        VocabCharacteristic vc = this.termForCategoryLookup(categoryValue, terms);
        // e.g. Category=EnvironmentalHistory
        String categoryTypeValue = categoryAndTypeFields[1];
        String factorType = StringUtils.split(categoryTypeValue, "=")[1];
        // vc.setCategory( categoryType );
        experimentalFactorFromFile.setCategory(vc);
        experimentalFactorFromFile.setName(factorValue);
        experimentalFactorFromFile.setDescription(factorValue);
        experimentalFactorFromFile.setType(factorType.equalsIgnoreCase("CATEGORICAL") ? FactorType.CATEGORICAL : FactorType.CONTINUOUS);
        this.addFactorValuesToExperimentalFactor(experimentalFactorFromFile, mapFactorSampleValues, factorType);
        if (!this.checkForDuplicateExperimentalFactorOnExperimentalDesign(experimentalDesign, experimentalFactorFromFile)) {
            experimentalDesign.getExperimentalFactors().add(experimentalFactorFromFile);
            ExperimentalDesignImporterImpl.log.info("Added " + experimentalFactorFromFile);
        }
    }
}
Also used : VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic) OntologyTerm(ubic.basecode.ontology.model.OntologyTerm)

Example 55 with OntologyTerm

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

the class GoMetric method checkParents.

/**
 * @param GOProbMap go prob map
 * @param ontoC     onto C
 * @param ontoM     onto M
 * @return the lowest probability value of the shared term among both collections of parent terms
 */
private Double checkParents(OntologyTerm ontoM, OntologyTerm ontoC, Map<String, Double> GOProbMap) {
    Collection<OntologyTerm> parentM = geneOntologyService.getAllParents(ontoM, partOf);
    parentM.add(ontoM);
    Collection<OntologyTerm> parentC = geneOntologyService.getAllParents(ontoC, partOf);
    parentC.add(ontoC);
    double pMin = 1;
    for (OntologyTerm termM : parentM) {
        if (this.isRoot(termM))
            continue;
        for (OntologyTerm termC : parentC) {
            if (this.isRoot(termC))
                continue;
            if ((termM.getUri().equalsIgnoreCase(termC.getUri())) && (GOProbMap.get(termM.getUri()) != null)) {
                double value = GOProbMap.get(termM.getUri());
                if (value < pMin) {
                    pMin = value;
                    break;
                }
            }
        }
    }
    return pMin;
}
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