Skip to content

Commit

Permalink
Merge pull request #459 from monarch-initiative/release-2.0.5
Browse files Browse the repository at this point in the history
Release 2.0.5
  • Loading branch information
ielis authored Dec 27, 2023
2 parents 4299533 + 6a72b60 commit 9c848f7
Show file tree
Hide file tree
Showing 24 changed files with 797 additions and 228 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ Changelog
latest
------

-----
2.0.5
-----

- extend `OntologyGraph` with convenience methods
- audit calculation of Resnik similarity scores
- use Jackson annotations to describe serialization of `GeneIdentifier`

-----
2.0.4
-----
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ associate phenotype annotation files.

- **Language/Platform:** Java >=11
- **License:** BSD 3-Clause Clear
- **Version:** 2.0.4
- **Version:** 2.0.5
- **Authors:**
- Sebastian Bauer
- Peter N. Robinson
Expand All @@ -39,7 +39,7 @@ We recommend indicating the phenol version in the `properties` section of the po
```
<properties>
(...)
<phenol.version>2.0.4</phenol.version>
<phenol.version>2.0.5</phenol.version>
</properties>
```

Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# The short X.Y version.
version = '2.0'
# The full version, including alpha/beta/rc tags.
release = '2.0.4'
release = '2.0.5'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
2 changes: 1 addition & 1 deletion phenol-analysis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.monarchinitiative.phenol</groupId>
<artifactId>phenol</artifactId>
<version>2.0.4</version>
<version>2.0.5</version>
</parent>

<artifactId>phenol-analysis</artifactId>
Expand Down
24 changes: 23 additions & 1 deletion phenol-annotations/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.monarchinitiative.phenol</groupId>
<artifactId>phenol</artifactId>
<version>2.0.4</version>
<version>2.0.5</version>
</parent>

<artifactId>phenol-annotations</artifactId>
Expand All @@ -18,12 +18,34 @@
<artifactId>phenol-core</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.monarchinitiative.phenol</groupId>
<artifactId>phenol-io</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>--add-reads org.monarchinitiative.phenol.annotations=com.fasterxml.jackson.databind</argLine>
</configuration>
</plugin>
</plugins>
</build>

</project>
1 change: 1 addition & 0 deletions phenol-annotations/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

requires java.xml;
requires org.slf4j;
requires com.fasterxml.jackson.annotation;

/* Exports */
exports org.monarchinitiative.phenol.annotations.analysis;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.monarchinitiative.phenol.annotations.formats;

import com.fasterxml.jackson.annotation.JsonGetter;
import org.monarchinitiative.phenol.ontology.data.Identified;
import org.monarchinitiative.phenol.ontology.data.TermId;

Expand All @@ -22,13 +23,15 @@ private GeneIdentifier(TermId tid, String geneSymbol) {

/** A CURIE for the gene, such as NCBIGene:3949 */
@Override
@JsonGetter
public TermId id() {
return id;
}

/**
* @return the symbol for the gene, e.g., LDLR
*/
@JsonGetter
public String symbol() {
return symbol;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.monarchinitiative.phenol.annotations.formats;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import org.monarchinitiative.phenol.ontology.data.TermId;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

public class GeneIdentifierTest {

private final ObjectMapper objectMapper = new ObjectMapper();

@Test
public void serializeToJson() throws Exception {
GeneIdentifier gi = GeneIdentifier.of(TermId.of("NCBIGene:6834"), "SURF1");

String actual = objectMapper.writeValueAsString(gi);

assertThat(actual, equalTo("{\"id\":\"NCBIGene:6834\",\"symbol\":\"SURF1\"}"));
}
}
2 changes: 1 addition & 1 deletion phenol-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.monarchinitiative.phenol</groupId>
<artifactId>phenol</artifactId>
<version>2.0.4</version>
<version>2.0.5</version>
</parent>

<artifactId>phenol-cli</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@CommandLine.Command(name = "phenol demo",
mixinStandardHelpOptions = true,
version = "2.0.4",
version = "2.0.5",
description = "phenol demo programs")
public class Main implements Callable<Integer> {
private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import org.monarchinitiative.phenol.annotations.io.hpo.HpoDiseaseLoaderOptions;
import org.monarchinitiative.phenol.annotations.io.hpo.HpoDiseaseLoaders;
import org.monarchinitiative.phenol.cli.demo.MicaCalculator;
import org.monarchinitiative.phenol.io.OntologyLoader;
import org.monarchinitiative.phenol.ontology.data.Ontology;
import org.monarchinitiative.phenol.io.MinimalOntologyLoader;
import org.monarchinitiative.phenol.ontology.data.MinimalOntology;
import org.monarchinitiative.phenol.ontology.data.TermId;
import org.monarchinitiative.phenol.ontology.similarity.HpoResnikSimilarity;
import org.monarchinitiative.phenol.ontology.similarity.HpoResnikSimilarityPrecompute;
import org.monarchinitiative.phenol.ontology.similarity.TermPair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -59,7 +59,7 @@ public class PrecomputeResnikMapCommand implements Callable<Integer> {
@Override
public Integer call() throws Exception {
LOGGER.info("Loading HPO from {}", hpoPath.toAbsolutePath());
Ontology hpo = OntologyLoader.loadOntology(hpoPath.toFile());
MinimalOntology hpo = MinimalOntologyLoader.loadOntology(hpoPath.toFile());

LOGGER.info("Loading HPO annotations from {}", hpoaPath.toAbsolutePath());
HpoDiseaseLoader loader = HpoDiseaseLoaders.defaultLoader(hpo, HpoDiseaseLoaderOptions.defaultOptions());
Expand All @@ -81,14 +81,13 @@ public Integer call() throws Exception {
return 0;
}

private Map<TermId, Double> calculateTermToIc(Ontology hpo, HpoDiseases diseases) {
private Map<TermId, Double> calculateTermToIc(MinimalOntology hpo, HpoDiseases diseases) {
MicaCalculator micaCalculator = new MicaCalculator(hpo, assumeAnnotated);
return micaCalculator.calculateMica(diseases).termToIc();
}

private static Map<TermPair, Double> assignMicaToTermPairs(Ontology hpo, Map<TermId, Double> termToIc) {
HpoResnikSimilarity similarity = new HpoResnikSimilarity(hpo, termToIc);
return similarity.getTermPairResnikSimilarityMap();
private static Map<TermPair, Double> assignMicaToTermPairs(MinimalOntology hpo, Map<TermId, Double> termToIc) {
return HpoResnikSimilarityPrecompute.precomputeSimilaritiesForTermPairs(hpo, termToIc);
}

private void writeTermPairMap(Map<TermPair, Double> termPairResnikSimilarityMap,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,35 @@
import org.monarchinitiative.phenol.annotations.formats.hpo.AnnotatedItem;
import org.monarchinitiative.phenol.annotations.formats.hpo.AnnotatedItemContainer;
import org.monarchinitiative.phenol.ontology.data.Identified;
import org.monarchinitiative.phenol.ontology.data.Ontology;
import org.monarchinitiative.phenol.ontology.data.MinimalOntology;
import org.monarchinitiative.phenol.ontology.data.TermId;
import org.monarchinitiative.phenol.ontology.data.TermIds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.Duration;
import java.time.Instant;
import java.util.*;
import java.util.stream.Collectors;

/**
* Class for calculating information content of the <em>most informative common ancestor</em> (MICA)
* for {@link Ontology} concepts using a corpus of annotated.
* Calculate information content of the <em>most informative common ancestor</em> (IC<sub>MICA</sub>) for the concepts
* in given {@link MinimalOntology} using a corpus of annotated items.
* <p>
* For instance, calculate IC<sub>MICA</sub> of HPO terms that annotate Mendelian diseases.
* <p>
* The IC<sub>MICA</sub> values are in <em>nats</em>.
*/
public class MicaCalculator {

private static final Logger LOGGER = LoggerFactory.getLogger(MicaCalculator.class);

private final Ontology hpo;
private final MinimalOntology hpo;
/**
* {@code true} if the count of annotations that are not used to annotate at least one corpus item should be set to 1
* to prevent ic being {@link Double#POSITIVE_INFINITY}.
*/
private final boolean assumeAnnotated;

public MicaCalculator(Ontology hpo) {
this(hpo, false);
}

public MicaCalculator(Ontology hpo, boolean assumeAnnotated) {
public MicaCalculator(MinimalOntology hpo, boolean assumeAnnotated) {
this.assumeAnnotated = assumeAnnotated;
this.hpo = Objects.requireNonNull(hpo);
}
Expand All @@ -40,24 +42,25 @@ public MicaData calculateMica(AnnotatedItemContainer<? extends AnnotatedItem> it
Map<TermId, Integer> phenotypeIdToDiseaseIds = new HashMap<>();
Map<TermId, Collection<TermId>> diseaseIdToTermIds = new HashMap<>();

Set<TermId> termsAndAncestorsBuilder = new HashSet<>();
for (AnnotatedItem item: itemContainer) {
List<TermId> annotationTermIds = item.annotations().stream()
.map(Identified::id)
.collect(Collectors.toList());
// add term ancestors
Set<TermId> inclAncestorTermIds = TermIds.augmentWithAncestors(hpo, annotationTermIds, true);
for (Identified annotation : item.annotations()) {
hpo.graph().extendWithAncestors(annotation.id(), true, termsAndAncestorsBuilder);
}

for (TermId tid : inclAncestorTermIds) {
for (TermId tid : termsAndAncestorsBuilder) {
// We can't do this within the hot loop above because there is no guarantee of uniqueness of the ancestors.
phenotypeIdToDiseaseIds.compute(tid, (key, val) -> val == null ? 0 : val + 1);
diseaseIdToTermIds.computeIfAbsent(item.id(), key -> new HashSet<>()).add(tid); // Note that this MUST be a Set
}
termsAndAncestorsBuilder.clear();
}

Map<TermId, Double> termToIc = new HashMap<>();
int totalPopulationHpoTerms = phenotypeIdToDiseaseIds.get(HpoSubOntologyRootTermIds.PHENOTYPIC_ABNORMALITY);
double totalPopulationHpoTerms = phenotypeIdToDiseaseIds.get(HpoSubOntologyRootTermIds.PHENOTYPIC_ABNORMALITY);
for (Map.Entry<TermId, Integer> e : phenotypeIdToDiseaseIds.entrySet()) {
int annotatedCount = assumeAnnotated ? Math.max(e.getValue(), 1) : e.getValue();
double ic = -1 * Math.log((double)annotatedCount/totalPopulationHpoTerms);
double ic = Math.log(totalPopulationHpoTerms / annotatedCount);
termToIc.put(e.getKey(), ic);
}

Expand Down
2 changes: 1 addition & 1 deletion phenol-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.monarchinitiative.phenol</groupId>
<artifactId>phenol</artifactId>
<version>2.0.4</version>
<version>2.0.5</version>
</parent>

<artifactId>phenol-core</artifactId>
Expand Down
Loading

0 comments on commit 9c848f7

Please sign in to comment.