Search in sources :

Example 61 with Taxon

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

the class TaxonDaoImpl method find.

@Override
public Taxon find(Taxon taxon) {
    BusinessKey.checkValidKey(taxon);
    Criteria queryObject = this.getSessionFactory().getCurrentSession().createCriteria(Taxon.class).setReadOnly(true);
    queryObject.setReadOnly(true);
    queryObject.setFlushMode(FlushMode.MANUAL);
    BusinessKey.addRestrictions(queryObject, taxon);
    List<?> results = queryObject.list();
    Object result = null;
    if (results != null) {
        if (results.size() > 1) {
            throw new org.springframework.dao.InvalidDataAccessResourceUsageException("More than one instance of '" + taxon.getClass().getName() + "' was found when executing query");
        } else if (results.size() == 1) {
            result = results.iterator().next();
        }
    }
    return (Taxon) result;
}
Also used : Taxon(ubic.gemma.model.genome.Taxon) TaxonValueObject(ubic.gemma.model.genome.TaxonValueObject) ExternalDatabaseValueObject(ubic.gemma.model.common.description.ExternalDatabaseValueObject)

Example 62 with Taxon

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

the class TaxonServiceImpl method getTaxaWithArrays.

/**
 * @return List of taxa with array designs in gemma
 */
@Override
@Transactional(readOnly = true)
public Collection<TaxonValueObject> getTaxaWithArrays() {
    Set<TaxonValueObject> taxaWithArrays = new TreeSet<>(TaxonServiceImpl.TAXON_VO_COMPARATOR);
    for (Taxon taxon : arrayDesignService.getPerTaxonCount().keySet()) {
        taxaWithArrays.add(TaxonValueObject.fromEntity(taxon));
    }
    AbstractService.log.debug("GenePicker::getTaxaWithArrays returned " + taxaWithArrays.size() + " results");
    return taxaWithArrays;
}
Also used : TaxonValueObject(ubic.gemma.model.genome.TaxonValueObject) Taxon(ubic.gemma.model.genome.Taxon) Transactional(org.springframework.transaction.annotation.Transactional)

Example 63 with Taxon

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

the class ArrayDesignDaoImpl method getPerTaxonCount.

@Override
public Map<Taxon, Long> getPerTaxonCount() {
    Map<Taxon, Long> result = new HashMap<>();
    final String csString = "select t, count(ad) from ArrayDesign ad inner join ad.primaryTaxon t group by t ";
    org.hibernate.Query csQueryObject = this.getSessionFactory().getCurrentSession().createQuery(csString);
    csQueryObject.setReadOnly(true);
    csQueryObject.setCacheable(true);
    List csList = csQueryObject.list();
    Taxon t;
    for (Object object : csList) {
        Object[] oa = (Object[]) object;
        t = (Taxon) oa[0];
        Long count = (Long) oa[1];
        result.put(t, count);
    }
    return result;
}
Also used : Taxon(ubic.gemma.model.genome.Taxon) ArrayDesignValueObject(ubic.gemma.model.expression.arrayDesign.ArrayDesignValueObject) org.hibernate(org.hibernate)

Example 64 with Taxon

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

the class ExpressionExperimentDaoImpl method getPerTaxonCount.

@Override
public Map<Taxon, Long> getPerTaxonCount() {
    Map<Taxon, Taxon> taxonParents = new HashMap<>();
    // noinspection unchecked
    List<Object[]> tp = this.getSessionFactory().getCurrentSession().createQuery("select t, p from Taxon t left outer join t.parentTaxon p").list();
    for (Object[] o : tp) {
        taxonParents.put((Taxon) o[0], (Taxon) o[1]);
    }
    Map<Taxon, Long> taxonCount = new LinkedHashMap<>();
    String queryString = "select t, count(distinct ee) from ExpressionExperiment " + "ee inner join ee.bioAssays as ba inner join ba.sampleUsed su " + "inner join su.sourceTaxon t group by t order by t.scientificName ";
    // it is important to cache this, as it gets called on the home page. Though it's actually fast.
    org.hibernate.Query queryObject = this.getSessionFactory().getCurrentSession().createQuery(queryString);
    queryObject.setCacheable(true);
    ScrollableResults list = queryObject.scroll();
    while (list.next()) {
        Taxon taxon = (Taxon) list.get(0);
        Taxon parent = taxonParents.get(taxon);
        Long count = list.getLong(1);
        if (parent != null) {
            if (!taxonCount.containsKey(parent)) {
                taxonCount.put(parent, 0L);
            }
            taxonCount.put(parent, taxonCount.get(parent) + count);
        } else {
            taxonCount.put(taxon, count);
        }
    }
    return taxonCount;
}
Also used : Taxon(ubic.gemma.model.genome.Taxon) org.hibernate(org.hibernate) ArrayDesignValueObject(ubic.gemma.model.expression.arrayDesign.ArrayDesignValueObject)

Example 65 with Taxon

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

the class GeneCoexpressionSearchServiceImpl method doCoexpressionSearch.

/**
 * @param genes          1 or more.
 * @param stringency;    this may be modified to control the number of results, unless "queryGenesOnly" is true.
 * @param maxResults     per gene, not including the query genes themselves. Ignored if this is 'queryGenesOnly'
 * @param queryGenesOnly will be ignored if number of genes is 1.
 * @return CoexpressionMetaValueObject, in which the results are already populated and sorted.
 */
private CoexpressionMetaValueObject doCoexpressionSearch(Collection<Long> inputEeIds, Collection<Long> genes, int stringency, final int maxResults, final boolean queryGenesOnly, final boolean quick) {
    if (genes.isEmpty()) {
        CoexpressionMetaValueObject r = new CoexpressionMetaValueObject();
        r.setErrorState("No genes selected");
        return r;
    }
    boolean actuallyUseQueryGeneOnly = queryGenesOnly && genes.size() > 1;
    Taxon taxon = this.geneService.load(genes.iterator().next()).getTaxon();
    List<ExpressionExperimentValueObject> eevos = this.getFilteredEEVos(inputEeIds, taxon);
    CoexpressionMetaValueObject result = this.initValueObject(genes, eevos);
    if (eevos.isEmpty()) {
        result = new CoexpressionMetaValueObject();
        result.setErrorState("No experiments selected");
        return result;
    }
    Collection<Long> eeIds = EntityUtils.getIds(eevos);
    Map<Long, List<CoexpressionValueObject>> allCoexpressions;
    if (genes.size() > GeneCoexpressionSearchServiceImpl.THRESHOLD_TRIGGER_QUERY_GENES_ONLY) {
        if (!actuallyUseQueryGeneOnly) {
            GeneCoexpressionSearchServiceImpl.log.info("Switching to 'query genes only'");
        }
        actuallyUseQueryGeneOnly = true;
    }
    if (stringency < 1)
        stringency = 1;
    if (!queryGenesOnly) {
        stringency = Math.max(stringency, this.chooseStringency(actuallyUseQueryGeneOnly, eeIds.size(), genes.size()));
        GeneCoexpressionSearchServiceImpl.log.info("Stringency set to " + stringency + " based on number of experiments (" + eeIds.size() + ") and genes (" + genes.size() + ") queried");
    } else {
        GeneCoexpressionSearchServiceImpl.log.info("Query gene only: stringency maintained at requested value=" + stringency);
    }
    assert stringency >= 1 || eeIds.size() == 1;
    // HACK drop the stringency until we get some results.
    int stepSize = 3;
    while (true) {
        if (actuallyUseQueryGeneOnly) {
            // note that maxResults is ignored.
            if (genes.size() < 2) {
                // should be impossible - could assert.
                throw new IllegalArgumentException("cannot do inter-gene coexpression search with only one gene");
            }
            allCoexpressions = coexpressionService.findInterCoexpressionRelationships(taxon, genes, eeIds, stringency, quick);
        } else {
            allCoexpressions = coexpressionService.findCoexpressionRelationships(taxon, genes, eeIds, stringency, maxResults, quick);
        }
        int minimum_stringency_for_requery = 2;
        if (allCoexpressions.isEmpty() && stringency > minimum_stringency_for_requery) {
            // step size completely made up.
            stringency -= stepSize;
            // keep stringency at least 2.
            stringency = Math.max(minimum_stringency_for_requery, stringency);
            GeneCoexpressionSearchServiceImpl.log.info("No results, re-querying with stringency=" + stringency);
        } else {
            // no results.
            break;
        }
    }
    GeneCoexpressionSearchServiceImpl.log.info("Final actual stringency used was " + stringency);
    result.setQueryStringency(stringency);
    result.setQueryGenesOnly(actuallyUseQueryGeneOnly);
    Set<Long> queryGeneIds = allCoexpressions.keySet();
    assert genes.containsAll(queryGeneIds);
    Map<Long, GeneValueObject> idMap = EntityUtils.getIdMap(geneService.loadValueObjectsByIds(queryGeneIds));
    int k = 0;
    for (Long queryGene : queryGeneIds) {
        Collection<CoexpressionValueObject> coexpressions = allCoexpressions.get(queryGene);
        List<CoexpressionValueObjectExt> results = this.addExtCoexpressionValueObjects(idMap.get(queryGene), coexpressions, actuallyUseQueryGeneOnly, genes);
        result.getResults().addAll(results);
        CoexpressionSummaryValueObject summary = new CoexpressionSummaryValueObject(queryGene);
        summary.setDatasetsAvailable(eevos.size());
        summary.setLinksFound(coexpressions.size());
        result.getSummaries().put(queryGene, summary);
        if (++k % 100 == 0) {
            GeneCoexpressionSearchServiceImpl.log.info("Processed results for " + k + " query genes ...");
        }
    }
    Collections.sort(result.getResults());
    // FIXME we might want to suppress this in some situations
    if (!queryGenesOnly) {
        result.trim();
    }
    this.populateNodeDegrees(result);
    return result;
}
Also used : Taxon(ubic.gemma.model.genome.Taxon) GeneValueObject(ubic.gemma.model.genome.gene.GeneValueObject) ExpressionExperimentValueObject(ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject) CoexpressionValueObject(ubic.gemma.persistence.service.association.coexpression.CoexpressionValueObject)

Aggregations

Taxon (ubic.gemma.model.genome.Taxon)161 Gene (ubic.gemma.model.genome.Gene)34 Test (org.junit.Test)31 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)29 HashSet (java.util.HashSet)23 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)23 InputStream (java.io.InputStream)17 Before (org.junit.Before)16 BioSequence (ubic.gemma.model.genome.biosequence.BioSequence)15 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)14 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)12 StopWatch (org.apache.commons.lang3.time.StopWatch)11 Transactional (org.springframework.transaction.annotation.Transactional)11 ArrayList (java.util.ArrayList)10 File (java.io.File)9 SimpleExpressionExperimentMetaData (ubic.gemma.core.loader.expression.simple.model.SimpleExpressionExperimentMetaData)9 Chromosome (ubic.gemma.model.genome.Chromosome)8 Collection (java.util.Collection)7 Element (org.w3c.dom.Element)7 PhysicalLocation (ubic.gemma.model.genome.PhysicalLocation)7