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;
}
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;
}
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;
}
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);
}
}
}
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;
}
Aggregations