@Override public String getId() { return this.access.isOpenAccess() && this.match != null ? this.match.getId() : null; }
@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; }
while (iter.hasNext()) { Feature feature = iter.next(); if (getCategoriesFromOntology(feature.getId()).contains(category) || StringUtils.equals(feature.getId(), category)) { this.sectionFeatureTree.put(feature.getId(), section); sortedFeatures.add(feature); iter.remove(); this.sectionFeatureTree.put(feature.getId(), "No category");
private void readPhenotypes(Patient patient) { List<Map<String, String>> predefined = new LinkedList<>(); List<Map<String, String>> freeText = new LinkedList<>(); Set<? extends Feature> features = patient.getFeatures(); for (Feature feature : features) { Map<String, String> item = new HashMap<>(); item.put(NAME_FIELD, feature.getName()); item.put(OBSERVED_FIELD, feature.isPresent() ? OBSERVED : NOT_OBSERVED); String id = feature.getId(); if (StringUtils.isEmpty(id)) { freeText.add(item); } else { item.put(ID_FIELD, id); predefined.add(item); } } Collections.sort(predefined, PHENOTYPES_COMPARATOR); Collections.sort(freeText, PHENOTYPES_COMPARATOR); this.phenotypes = new HashMap<>(); this.phenotypes.put(PREDEFINED, predefined); this.phenotypes.put(FREE_TEXT, freeText); }
private JSONArray features(Patient patient) { JSONArray features = new JSONArray(); for (Feature patientFeature : patient.getFeatures()) { String featureId = patientFeature.getId(); if (featureId.isEmpty() || !this.hpoTerm.matcher(featureId).matches()) { this.logger.error("Patient feature parser: ignoring term with non-HPO id [{}]", featureId); continue; } JSONObject featureJson = new JSONObject(); featureJson.put(ApiConfiguration.JSON_FEATURE_ID, featureId); featureJson.put(ApiConfiguration.JSON_FEATURE_OBSERVED, observedStatusToJSONString(patientFeature)); Map<String, ? extends FeatureMetadatum> metadata = patientFeature.getMetadata(); FeatureMetadatum ageOfOnset = metadata.get(ApplicationConfiguration.FEATURE_METADATA_AGEOFONSET); if (ageOfOnset != null) { featureJson.put(ApiConfiguration.JSON_FEATURE_AGE_OF_ONSET, ageOfOnset.getId()); } features.put(featureJson); } return features; }
@Override public double getScore() { if (this.reference == null || this.match == null) { return Double.NaN; } double score = 0; if (StringUtils.equals(this.match.getId(), this.reference.getId())) { score = 1; } else { score = getRelativeScore(); } if (this.match.isPresent() != this.reference.isPresent()) { score = -score; } return adjustScoreWithMetadataScores(score); }
private JSONArray nonStandardFeaturesToJSON(PatientData<Feature> data, Collection<String> selectedFields) { JSONArray featuresJSON = new JSONArray(); if (data != null) { Iterator<Feature> iterator = data.iterator(); while (iterator.hasNext()) { Feature phenotype = iterator.next(); if (StringUtils.isNotBlank(phenotype.getId()) || !isFieldIncluded(selectedFields, phenotype.getType())) { continue; } JSONObject featureJSON = phenotype.toJSON(); if (featureJSON != null) { featuresJSON.put(featureJSON); } } } return featuresJSON; }
/** creates & returns a new JSON array of all patient features (as JSON objects). */ private JSONArray featuresToJSON(PatientData<Feature> data, Collection<String> selectedFields) { JSONArray featuresJSON = new JSONArray(); if (data != null) { Iterator<Feature> iterator = data.iterator(); while (iterator.hasNext()) { Feature phenotype = iterator.next(); if (StringUtils.isBlank(phenotype.getId()) || !isFieldIncluded(selectedFields, phenotype.getType())) { continue; } JSONObject featureJSON = phenotype.toJSON(); if (featureJSON != null) { featuresJSON.put(featureJSON); } } } return featuresJSON; }
private JSONArray nonStandardFeaturesToJSON(PatientData<Feature> data, Collection<String> selectedFields) { JSONArray featuresJSON = new JSONArray(); if (data != null) { Iterator<Feature> iterator = data.iterator(); while (iterator.hasNext()) { Feature phenotype = iterator.next(); if (StringUtils.isNotBlank(phenotype.getId()) || !isFieldIncluded(selectedFields, phenotype.getType())) { continue; } JSONObject featureJSON = phenotype.toJSON(); if (featureJSON != null) { featuresJSON.put(featureJSON); } } } return featuresJSON; }
/** * Compute the information content of a patient's positive or negative symptoms. * * @param p the patient profile to score * @param presentFeatures whether the score for positive ({@code true}) or negative ({@code false}) features is * computed * @return the score (information content) and the number of features */ private Pair<Double, Integer> process(Patient p, boolean presentFeatures) { double score = 0; int count = 0; for (Feature f : p.getFeatures()) { if (StringUtils.isNotEmpty(f.getId()) && f.isPresent() == presentFeatures) { score += informationContent(f); count++; } } return new ImmutablePair<Double, Integer>(score, count); }
/** * Compute the information content of a patient's positive or negative symptoms. * * @param p the patient profile to score * @param presentFeatures whether the score for positive ({@code true}) or negative ({@code false}) features is * computed * @return the score (information content) and the number of features */ private Pair<Double, Integer> process(Patient p, boolean presentFeatures) { double score = 0; int count = 0; for (Feature f : p.getFeatures()) { if (StringUtils.isNotEmpty(f.getId()) && f.isPresent() == presentFeatures) { score += informationContent(f); count++; } } return new ImmutablePair<Double, Integer>(score, count); }
/** * creates & returns a new JSON array of all patient features (as JSON objects). */ private JSONArray featuresToJSON(PatientData<Feature> data, Collection<String> selectedFields) { JSONArray featuresJSON = new JSONArray(); if (data != null) { Iterator<Feature> iterator = data.iterator(); while (iterator.hasNext()) { Feature phenotype = iterator.next(); if (StringUtils.isBlank(phenotype.getId()) || !isFieldIncluded(selectedFields, phenotype.getType())) { continue; } JSONObject featureJSON = phenotype.toJSON(); if (featureJSON != null) { featuresJSON.put(featureJSON); } } } return featuresJSON; }
/** * How much information is captured by a feature? In other words, how many diseases are selected by a feature out of * the total selectable diseases. If a feature doesn't select any diseases at all, the information content of its * nearest represented ancestor is considered, with a slight boost for even more specificity. * * @param f the target feature to measure * @return the information content captured by this term */ private double informationContent(Feature f) { String toSearch = f.getId(); double ic = informationContent(this.omim.count(Collections.singletonMap(SEARCH_FOR, toSearch))); int i = 0; while (ic == 0 && ++i < 5) { VocabularyTerm term = this.hpo.getTerm(toSearch); if (term == null) { break; } Set<VocabularyTerm> parents = term.getParents(); if (parents.isEmpty()) { break; } toSearch = parents.iterator().next().getId(); ic = informationContent(this.omim.count(Collections.singletonMap(SEARCH_FOR, toSearch))); } return ic * (1 + i / 5); }
/** * How much information is captured by a feature? In other words, how many diseases are selected by a feature out of * the total selectable diseases. If a feature doesn't select any diseases at all, the information content of its * nearest represented ancestor is considered, with a slight boost for even more specificity. * * @param f the target feature to measure * @return the information content captured by this term */ private double informationContent(Feature f) { String toSearch = f.getId(); double ic = informationContent(this.omim.count(Collections.singletonMap(SEARCH_FOR, toSearch))); int i = 0; while (ic == 0 && ++i < 5) { VocabularyTerm term = this.hpo.getTerm(toSearch); if (term == null) { break; } Set<VocabularyTerm> parents = term.getParents(); if (parents.isEmpty()) { break; } toSearch = parents.iterator().next().getId(); ic = informationContent(this.omim.count(Collections.singletonMap(SEARCH_FOR, toSearch))); } return ic * (1 + i / 5); }
String ancestorFieldName = "extended_" + presence + "phenotype"; String termId = phenotype.getId(); if (StringUtils.isNotBlank(termId)) { input.addField(fieldName, termId);