/** * Retrieve a term from its owner ontology. For this to work properly, the term identifier must contain a known * ontology prefix. * * @param termId the term identifier, in the format {@code <ontology prefix>:<term id>}, for example * {@code HP:0002066} * @return the requested term, or {@code null} if the term doesn't exist in the ontology, or no matching ontology is * available */ public OntologyTerm resolveTerm(String termId) { return this.manager.resolveTerm(termId); }
@Override public double getScore(Feature match, Feature reference) { if (match == null || reference == null) { return Double.NaN; } else if (StringUtils.equals(match.getId(), reference.getId())) { return 1; } OntologyTerm matchTerm = this.ontologyManager.resolveTerm(match.getId()); OntologyTerm referenceTerm = this.ontologyManager.resolveTerm(reference.getId()); if (matchTerm == null || referenceTerm == null) { return Double.NaN; } int distance = getDistance(matchTerm, referenceTerm); return distance <= 3 ? Math.pow(2.0, -distance) : 0; }
/** * Fills in an extended phenotype field using the base phenotype field. * * @param baseFieldName the name of the field holding the basic list of phenotypes * @param extendedFieldName the name of the target field that will hold the extended list of phenotypes * @param patientRecordObj the object to update */ private void updateField(String baseFieldName, String extendedFieldName, BaseObject patientRecordObj) { @SuppressWarnings("unchecked") List<String> phenotypes = patientRecordObj.getListValue(baseFieldName); Set<String> extendedPhenotypes = new TreeSet<String>(); Set<String> sortedPhenotypes = new TreeSet<String>(); for (String phenotype : phenotypes) { sortedPhenotypes.add(phenotype); OntologyTerm phenotypeTerm = this.ontologyManager.resolveTerm(phenotype); if (phenotypeTerm != null) { for (OntologyTerm term : phenotypeTerm.getAncestorsAndSelf()) { extendedPhenotypes.add(term.getId()); } } else { extendedPhenotypes.add(phenotype); } } patientRecordObj.setDBStringListValue(extendedFieldName, new ArrayList<String>(extendedPhenotypes)); patientRecordObj.setDBStringListValue(baseFieldName, new ArrayList<String>(sortedPhenotypes)); } }
@Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; BaseObject patientObject = doc.getXObject(Patient.CLASS_REFERENCE); if (patientObject != null && !StringUtils.equals("PatientTemplate", doc.getDocumentReference().getName())) { XWikiContext context = (XWikiContext) this.execution.getContext().getProperty("xwikicontext"); for (String field : this.fieldsToFix) { DBStringListProperty currentTermList = (DBStringListProperty) patientObject.getField(field); if (currentTermList == null) { continue; } List<String> terms = currentTermList.getList(); Set<String> correctSet = new LinkedHashSet<String>(); for (String term : terms) { OntologyTerm properTerm = this.ontologyManager.resolveTerm(term); if (properTerm != null) { correctSet.add(properTerm.getId()); } else { correctSet.add(term); } } List<String> correctList = new LinkedList<String>(); correctList.addAll(correctSet); patientObject.set(field, correctList, context); } } } }