Search in sources :

Example 16 with Gene

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

the class LinkAnalysisServiceTest method checkResults.

private int checkResults(Collection<BioAssaySet> ees, int expectedMinimumMaxSupport) {
    boolean foundOne = false;
    int maxSupport = 0;
    Taxon mouse = taxonService.findByCommonName("mouse");
    Collection<Gene> genesWithLinks = new ArrayList<>();
    int totalLinks = 0;
    // numdatasetstesting will not be set so we won't bother checking.
    assertTrue(!geneCoexpressionService.getCoexpression(ee, true).isEmpty());
    Collection<CoexpressionValueObject> eeResults = geneCoexpressionService.getCoexpression(ee, false);
    assertTrue(!eeResults.isEmpty());
    for (CoexpressionValueObject coex : eeResults) {
        this.checkResult(coex);
    }
    Map<Long, GeneCoexpressionNodeDegreeValueObject> nodeDegrees = geneCoexpressionService.getNodeDegrees(EntityUtils.getIds(geneService.loadAll()));
    assertTrue(!nodeDegrees.isEmpty());
    // experiment-major query
    Map<Long, List<CoexpressionValueObject>> allLinks = geneCoexpressionService.findCoexpressionRelationships(mouse, new HashSet<Long>(), EntityUtils.getIds(ees), ees.size(), 10, false);
    assertTrue(!allLinks.isEmpty());
    for (Long g : allLinks.keySet()) {
        for (CoexpressionValueObject coex : allLinks.get(g)) {
            this.checkResult(coex);
        }
    }
    for (Gene gene : geneService.loadAll(mouse)) {
        Collection<CoexpressionValueObject> links = geneCoexpressionService.findCoexpressionRelationships(gene, EntityUtils.getIds(ees), 1, 0, false);
        if (links == null || links.isEmpty()) {
            continue;
        }
        assertEquals(geneCoexpressionService.findCoexpressionRelationships(gene, Collections.singleton(ee.getId()), 0, false).size(), geneCoexpressionService.countLinks(ee, gene).intValue());
        GeneCoexpressionNodeDegreeValueObject nodeDegree = geneCoexpressionService.getNodeDegree(gene);
        if (links.size() != nodeDegree.getLinksWithMinimumSupport(1)) {
            log.info(nodeDegree);
            assertEquals("Node degree check failed for gene " + gene, links.size(), nodeDegree.getLinksWithMinimumSupport(1).intValue());
        }
        assertTrue(nodeDegree.getLinksWithMinimumSupport(1) >= nodeDegree.getLinksWithMinimumSupport(2));
        totalLinks += links.size();
        log.debug(links.size() + " hits for " + gene);
        for (CoexpressionValueObject coex : links) {
            this.checkResult(coex);
            if (coex.getNumDatasetsSupporting() > maxSupport) {
                maxSupport = coex.getNumDatasetsSupporting();
            }
        }
        foundOne = true;
        if (genesWithLinks.size() == 5) {
            // without specifying stringency
            Map<Long, List<CoexpressionValueObject>> multiGeneResults = geneCoexpressionService.findCoexpressionRelationships(mouse, EntityUtils.getIds(genesWithLinks), EntityUtils.getIds(ees), 100, false);
            if (multiGeneResults.isEmpty()) {
                // noinspection ConstantConditions // these strange structures are to help with debugger.
                assertTrue(!multiGeneResults.isEmpty());
            }
            for (Long id : multiGeneResults.keySet()) {
                for (CoexpressionValueObject coex : multiGeneResults.get(id)) {
                    this.checkResult(coex);
                }
            }
            // with stringency specified, quick.
            Map<Long, List<CoexpressionValueObject>> multiGeneResults2 = geneCoexpressionService.findCoexpressionRelationships(mouse, EntityUtils.getIds(genesWithLinks), EntityUtils.getIds(ees), ees.size(), 100, true);
            if (multiGeneResults.size() != multiGeneResults2.size()) {
                assertEquals(multiGeneResults.size(), multiGeneResults2.size());
            }
            for (Long id : multiGeneResults2.keySet()) {
                for (CoexpressionValueObject coex : multiGeneResults2.get(id)) {
                    this.checkResult(coex);
                }
            }
        }
        genesWithLinks.add(gene);
    }
    assertTrue(foundOne);
    Map<Long, List<CoexpressionValueObject>> mygeneresults = geneCoexpressionService.findInterCoexpressionRelationships(mouse, EntityUtils.getIds(genesWithLinks), EntityUtils.getIds(ees), 1, false);
    if (mygeneresults.isEmpty()) {
        // noinspection ConstantConditions // these strange structures are to help with debugger.
        assertTrue(!mygeneresults.isEmpty());
    }
    for (Long id : mygeneresults.keySet()) {
        for (CoexpressionValueObject coex : mygeneresults.get(id)) {
            this.checkResult(coex);
        }
    }
    assertTrue(maxSupport >= expectedMinimumMaxSupport);
    return totalLinks;
}
Also used : Taxon(ubic.gemma.model.genome.Taxon) Gene(ubic.gemma.model.genome.Gene) GeneCoexpressionNodeDegreeValueObject(ubic.gemma.model.association.coexpression.GeneCoexpressionNodeDegreeValueObject) CoexpressionValueObject(ubic.gemma.persistence.service.association.coexpression.CoexpressionValueObject)

Example 17 with Gene

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

the class DiffExMetaAnalyzerServiceTest method extraTests1.

private void extraTests1(ExpressionExperiment ds1) {
    Collection<Gene> geneCollection = geneService.findByOfficialSymbol("ACTA2");
    assertTrue(!geneCollection.isEmpty());
    Gene g = geneCollection.iterator().next();
    assertNotNull(g);
    long count = geneService.getCompositeSequenceCountById(g.getId());
    assertTrue(count != 0);
    Collection<CompositeSequence> compSequences = geneService.getCompositeSequencesById(g.getId());
    assertTrue(compSequences.size() != 0);
    Collection<CompositeSequence> collection = compositeSequenceService.findByGene(g);
    assertEquals(1, collection.size());
    ArrayDesign ad = experimentService.getArrayDesignsUsed(ds1).iterator().next();
    collection = compositeSequenceService.findByGene(g, ad);
    assertEquals(1, collection.size());
    Collection<CompositeSequence> css = compositeSequenceService.findByName("200974_at");
    assertTrue(!css.isEmpty());
    CompositeSequence cs = css.iterator().next();
    Collection<Gene> genes = compositeSequenceService.getGenes(cs);
    assertEquals(1, genes.size());
    assertEquals(g, genes.iterator().next());
    tableMaintenanceUtil.disableEmail();
    tableMaintenanceUtil.updateGene2CsEntries();
    Map<CompositeSequence, Collection<Gene>> gm = compositeSequenceService.getGenes(css);
    assertEquals(1, gm.size());
    assertEquals(g, gm.values().iterator().next().iterator().next());
}
Also used : Gene(ubic.gemma.model.genome.Gene) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence)

Example 18 with Gene

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

the class DiffExMetaAnalyzerServiceTest method cleanup.

private void cleanup() {
    for (GeneDifferentialExpressionMetaAnalysisSummaryValueObject vo : geneDiffExMetaAnalysisHelperService.loadAllMetaAnalyses()) {
        analysisService.delete(vo.getId());
    }
    this.deleteSet("GSE2018");
    this.deleteSet("GSE2111");
    this.deleteSet("GSE6344");
    ArrayDesign gpl96 = arrayDesignService.findByShortName("GPL96");
    ArrayDesign gpl97 = arrayDesignService.findByShortName("GPL97");
    if (gpl96 != null) {
        for (ExpressionExperiment ee : arrayDesignService.getExpressionExperiments(gpl96)) {
            experimentService.remove(ee);
        }
        arrayDesignService.remove(gpl96);
    }
    if (gpl97 != null) {
        for (ExpressionExperiment ee : arrayDesignService.getExpressionExperiments(gpl97)) {
            experimentService.remove(ee);
        }
        arrayDesignService.remove(gpl97);
    }
    Collection<Gene> genes = geneService.loadAll();
    for (Gene gene : genes) {
        try {
            geneService.remove(gene);
        } catch (Exception e) {
            log.warn("Failed to remove gene " + gene);
        }
    }
}
Also used : Gene(ubic.gemma.model.genome.Gene) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) AlreadyExistsInSystemException(ubic.gemma.core.loader.util.AlreadyExistsInSystemException)

Example 19 with Gene

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

the class SupportDetailsTest method test.

@Test
public void test() {
    Gene g1 = Gene.Factory.newInstance();
    g1.setId(3L);
    Gene g2 = Gene.Factory.newInstance();
    g2.setId(4L);
    SupportDetails sd1 = new MouseCoexpressionSupportDetailsImpl(g1, g2, true);
    SupportDetails sd2 = new MouseCoexpressionSupportDetailsImpl(g1, g2, true);
    sd1.addEntity(1L);
    sd2.addEntity(2L);
    sd2.removeEntity(2L);
    sd2.addEntity(1L);
    sd1.addEntity(10L);
    sd2.addEntity(10L);
    assertEquals(2, sd2.getNumIds());
}
Also used : Gene(ubic.gemma.model.genome.Gene) Test(org.junit.Test)

Example 20 with Gene

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

the class CoexpressionNodeDegreeValueObjectTest method testa.

@Test
public void testa() {
    Gene g = Gene.Factory.newInstance();
    g.setId(1L);
    g.setOfficialName("foo");
    GeneCoexpressionNodeDegree nd = GeneCoexpressionNodeDegree.Factory.newInstance(g);
    GeneCoexpressionNodeDegreeValueObject t = new GeneCoexpressionNodeDegreeValueObject(nd);
    t.increment(1, true);
    t.increment(2, true);
    assertEquals(2, t.getLinksWithMinimumSupport(1, true).intValue());
    assertEquals(1, t.getLinksWithExactSupport(1, true).intValue());
    t.increment(1, true);
    t.increment(2, true);
    assertEquals(4, t.getLinksWithMinimumSupport(1, true).intValue());
    assertEquals(2, t.getLinksWithMinimumSupport(2, true).intValue());
    assertEquals(2, t.getLinksWithExactSupport(1, true).intValue());
    assertEquals(3, t.asIntArrayPos().length);
    assertEquals(0, t.asIntArrayPos()[0]);
    assertEquals(2, t.asIntArrayPos()[1]);
    assertEquals(2, t.asIntArrayPos()[2]);
}
Also used : Gene(ubic.gemma.model.genome.Gene) GeneCoexpressionNodeDegreeValueObject(ubic.gemma.model.association.coexpression.GeneCoexpressionNodeDegreeValueObject) GeneCoexpressionNodeDegree(ubic.gemma.model.association.coexpression.GeneCoexpressionNodeDegree) Test(org.junit.Test)

Aggregations

Gene (ubic.gemma.model.genome.Gene)186 Taxon (ubic.gemma.model.genome.Taxon)34 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)32 StopWatch (org.apache.commons.lang3.time.StopWatch)31 Test (org.junit.Test)24 HashSet (java.util.HashSet)23 GeneProduct (ubic.gemma.model.genome.gene.GeneProduct)20 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)18 Element (org.w3c.dom.Element)16 ArrayList (java.util.ArrayList)13 Transactional (org.springframework.transaction.annotation.Transactional)12 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)12 Collection (java.util.Collection)11 OntologyTerm (ubic.basecode.ontology.model.OntologyTerm)11 CharacteristicValueObject (ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject)10 HashMap (java.util.HashMap)8 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)8 BioSequence2GeneProduct (ubic.gemma.model.association.BioSequence2GeneProduct)7 PhysicalLocation (ubic.gemma.model.genome.PhysicalLocation)7 BioSequence (ubic.gemma.model.genome.biosequence.BioSequence)7