Search in sources :

Example 1 with GeneSetMember

use of ubic.gemma.model.genome.gene.GeneSetMember in project Gemma by PavlidisLab.

the class GeneSetSearchImpl method goTermToGeneSets.

private Collection<GeneSet> goTermToGeneSets(OntologyTerm term, Integer maxGeneSetSize) {
    if (term == null)
        return null;
    if (term.getUri() == null)
        return null;
    Collection<OntologyResource> allMatches = new HashSet<>();
    allMatches.add(term);
    allMatches.addAll(this.geneOntologyService.getAllChildren(term));
    GeneSetSearchImpl.log.info(term);
    /*
         * Gather up uris
         */
    Collection<String> termsToFetch = new HashSet<>();
    for (OntologyResource t : allMatches) {
        String goId = this.uri2goid(t);
        termsToFetch.add(goId);
    }
    Map<Taxon, Collection<Gene>> genesByTaxon = this.gene2GoService.findByGOTermsPerTaxon(termsToFetch);
    Collection<GeneSet> results = new HashSet<>();
    for (Taxon t : genesByTaxon.keySet()) {
        Collection<Gene> genes = genesByTaxon.get(t);
        if (genes.isEmpty() || (maxGeneSetSize != null && genes.size() > maxGeneSetSize)) {
            continue;
        }
        GeneSet transientGeneSet = GeneSet.Factory.newInstance();
        transientGeneSet.setName(this.uri2goid(term));
        transientGeneSet.setDescription(term.getLabel());
        for (Gene gene : genes) {
            GeneSetMember gmember = GeneSetMember.Factory.newInstance();
            gmember.setGene(gene);
            transientGeneSet.getMembers().add(gmember);
        }
        results.add(transientGeneSet);
    }
    return results;
}
Also used : Taxon(ubic.gemma.model.genome.Taxon) GeneSetMember(ubic.gemma.model.genome.gene.GeneSetMember) Gene(ubic.gemma.model.genome.Gene) Collection(java.util.Collection) GeneSet(ubic.gemma.model.genome.gene.GeneSet) OntologyResource(ubic.basecode.ontology.model.OntologyResource) HashSet(java.util.HashSet)

Example 2 with GeneSetMember

use of ubic.gemma.model.genome.gene.GeneSetMember in project Gemma by PavlidisLab.

the class GeneSetValueObjectHelperImpl method fillSessionBoundValueObject.

private void fillSessionBoundValueObject(SessionBoundGeneSetValueObject sbgsvo, GeneSet gs) {
    sbgsvo.setName(gs.getName());
    sbgsvo.setDescription(gs.getDescription());
    // GO group gene sets don't have ids
    if (gs.getId() == null) {
        sbgsvo.setSize(gs.getMembers() != null ? gs.getMembers().size() : 0);
    } else {
        // this case may never happen as this is only called from convertToGoValueObject() leaving here in case
        // this method is ever called from somewhere else
        sbgsvo.setSize(this.geneSetService.getSize(new GeneSetValueObject(gs.getId())));
    }
    Collection<Long> gids = new HashSet<>();
    for (GeneSetMember gm : gs.getMembers()) {
        gids.add(gm.getGene().getId());
    }
    sbgsvo.setGeneIds(gids);
    Taxon tax = this.geneSetService.getTaxon(gs);
    if (tax != null) {
        while (tax.getParentTaxon() != null) {
            tax = tax.getParentTaxon();
        }
        sbgsvo.setTaxonId(tax.getId());
        sbgsvo.setTaxonName(tax.getCommonName());
    }
    sbgsvo.setId(new Long(-1));
    sbgsvo.setModified(false);
}
Also used : Taxon(ubic.gemma.model.genome.Taxon) GeneSetMember(ubic.gemma.model.genome.gene.GeneSetMember) GeneSetValueObject(ubic.gemma.model.genome.gene.GeneSetValueObject) DatabaseBackedGeneSetValueObject(ubic.gemma.model.genome.gene.DatabaseBackedGeneSetValueObject)

Example 3 with GeneSetMember

use of ubic.gemma.model.genome.gene.GeneSetMember in project Gemma by PavlidisLab.

the class GeneSetSearchImpl method goTermToGeneSet.

/**
 * Convert a GO term to a 'GeneSet', including genes from all child terms. Divide up by taxon.
 */
private GeneSet goTermToGeneSet(OntologyResource term, Taxon taxon, Integer maxGeneSetSize) {
    assert taxon != null;
    if (term == null)
        return null;
    if (term.getUri() == null)
        return null;
    Collection<OntologyResource> allMatches = new HashSet<>();
    allMatches.add(term);
    assert term instanceof OntologyTerm;
    allMatches.addAll(this.geneOntologyService.getAllChildren((OntologyTerm) term));
    GeneSetSearchImpl.log.info(term);
    /*
         * Gather up uris
         */
    Collection<String> termsToFetch = new HashSet<>();
    for (OntologyResource t : allMatches) {
        String goId = this.uri2goid(t);
        termsToFetch.add(goId);
    }
    Collection<Gene> genes = this.gene2GoService.findByGOTerms(termsToFetch, taxon);
    if (genes.isEmpty() || (maxGeneSetSize != null && genes.size() > maxGeneSetSize)) {
        return null;
    }
    GeneSet transientGeneSet = GeneSet.Factory.newInstance();
    transientGeneSet.setName(this.uri2goid(term));
    if (term.getLabel() == null) {
        GeneSetSearchImpl.log.warn(" Label for term " + term.getUri() + " was null");
    }
    // noinspection StatementWithEmptyBody // FIXME this is an individual or a 'resource', not a 'class', but it's a real GO term. How to get the text.
    if (term.getLabel() != null && term.getLabel().toUpperCase().startsWith("GO_")) {
    }
    transientGeneSet.setDescription(term.getLabel());
    for (Gene gene : genes) {
        GeneSetMember gmember = GeneSetMember.Factory.newInstance();
        gmember.setGene(gene);
        transientGeneSet.getMembers().add(gmember);
    }
    return transientGeneSet;
}
Also used : Gene(ubic.gemma.model.genome.Gene) OntologyTerm(ubic.basecode.ontology.model.OntologyTerm) GeneSetMember(ubic.gemma.model.genome.gene.GeneSetMember) GeneSet(ubic.gemma.model.genome.gene.GeneSet) OntologyResource(ubic.basecode.ontology.model.OntologyResource) HashSet(java.util.HashSet)

Aggregations

GeneSetMember (ubic.gemma.model.genome.gene.GeneSetMember)3 HashSet (java.util.HashSet)2 OntologyResource (ubic.basecode.ontology.model.OntologyResource)2 Gene (ubic.gemma.model.genome.Gene)2 Taxon (ubic.gemma.model.genome.Taxon)2 GeneSet (ubic.gemma.model.genome.gene.GeneSet)2 Collection (java.util.Collection)1 OntologyTerm (ubic.basecode.ontology.model.OntologyTerm)1 DatabaseBackedGeneSetValueObject (ubic.gemma.model.genome.gene.DatabaseBackedGeneSetValueObject)1 GeneSetValueObject (ubic.gemma.model.genome.gene.GeneSetValueObject)1