Skip to content

Commit

Permalink
Merge pull request #413 from monarch-initiative/getDomainItemsAnnotat…
Browse files Browse the repository at this point in the history
…edByOntologyTerm

extended interface of AssociationContainer by new method
  • Loading branch information
pnrobinson authored Aug 8, 2022
2 parents 7849db6 + a01cce0 commit 7282e3e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public interface AssociationContainer<T> {
Map<T, DirectAndIndirectTermAnnotations> getAssociationMap(Set<TermId> annotatedItemTermIds);

Set<T> getAllAnnotatedGenes();

/**
* @param tid The {@link TermId} of an ontology term (e.g. Gene Ontology) used to annotated domain items
* @return A set of domain items (e.g., genes) annotated by the ontology term
*/
Set<T> getDomainItemsAnnotatedByOntologyTerm(TermId tid);
/**
* @return total number of GO (or HP, MP, etc) terms that are annotating the items in this container.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.monarchinitiative.phenol.analysis;

import org.monarchinitiative.phenol.analysis.util.Util;
import org.monarchinitiative.phenol.annotations.formats.go.GoGaf22Annotation;
import org.monarchinitiative.phenol.annotations.io.go.GoGeneAnnotationParser;
import org.monarchinitiative.phenol.ontology.algo.OntologyAlgorithm;
Expand Down Expand Up @@ -86,6 +87,11 @@ public Set<TermId> getAllAnnotatedGenes() {
return this.gene2associationMap.keySet();
}

@Override
public Set<TermId> getDomainItemsAnnotatedByOntologyTerm(TermId tid) {
return Util.getDomainItemsAnnotatedByOntologyTerm(tid, ontology, gene2associationMap);
}

/**
* @return number of genes (or items) represented in this association container.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.monarchinitiative.phenol.analysis;


import org.monarchinitiative.phenol.analysis.util.Util;
import org.monarchinitiative.phenol.annotations.io.go.GoGeneAnnotationParser;
import org.monarchinitiative.phenol.base.PhenolException;
import org.monarchinitiative.phenol.ontology.algo.OntologyAlgorithm;
Expand Down Expand Up @@ -112,6 +113,11 @@ public Set<TermId> getAllAnnotatedGenes() {
return this.gene2associationMap.keySet();
}

@Override
public Set<TermId> getDomainItemsAnnotatedByOntologyTerm(TermId tid) {
return Util.getDomainItemsAnnotatedByOntologyTerm(tid, ontology, gene2associationMap);
}

/**
* @return number of genes (or items) represented in this association container.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.monarchinitiative.phenol.analysis.util;

import org.monarchinitiative.phenol.analysis.ItemAnnotations;
import org.monarchinitiative.phenol.ontology.algo.OntologyAlgorithm;
import org.monarchinitiative.phenol.ontology.data.Ontology;
import org.monarchinitiative.phenol.ontology.data.TermId;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class Util {

public static Set<TermId> getDomainItemsAnnotatedByOntologyTerm(TermId termId,
Ontology ontology,
Map<TermId, ? extends ItemAnnotations<TermId>> gene2associationMap) {
Set<TermId> domainItemSet = new HashSet<>();
// the following includes termId in the descendent set
Set<TermId> descendentSet = OntologyAlgorithm.getDescendents(ontology, termId);

for (Map.Entry<TermId, ? extends ItemAnnotations<TermId>> entry : gene2associationMap.entrySet()) {
TermId gene = entry.getKey();
for (TermId ontologyTermId : entry.getValue().getAnnotatingTermIds()) {
if (descendentSet.contains(ontologyTermId) || ontologyTermId.equals(termId)) {
domainItemSet.add(gene);
}
}
}

return domainItemSet;
}

}

0 comments on commit 7282e3e

Please sign in to comment.