Search in sources :

Example 26 with GeneProduct

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

the class BlatAssociationDaoImpl method find.

@Override
public Collection<BlatAssociation> find(Gene gene) {
    if (gene.getProducts().size() == 0) {
        throw new IllegalArgumentException("Gene has no products");
    }
    Collection<BlatAssociation> result = new HashSet<>();
    for (GeneProduct geneProduct : gene.getProducts()) {
        BusinessKey.checkValidKey(geneProduct);
        Criteria queryObject = super.getSessionFactory().getCurrentSession().createCriteria(BlatAssociation.class);
        Criteria innerQuery = queryObject.createCriteria("geneProduct");
        if (StringUtils.isNotBlank(geneProduct.getNcbiGi())) {
            innerQuery.add(Restrictions.eq("ncbiGi", geneProduct.getNcbiGi()));
        }
        if (StringUtils.isNotBlank(geneProduct.getName())) {
            innerQuery.add(Restrictions.eq("name", geneProduct.getName()));
        }
        // noinspection unchecked
        result.addAll(queryObject.list());
    }
    return result;
}
Also used : GeneProduct(ubic.gemma.model.genome.gene.GeneProduct) Criteria(org.hibernate.Criteria) BlatAssociation(ubic.gemma.model.genome.sequenceAnalysis.BlatAssociation) HashSet(java.util.HashSet)

Example 27 with GeneProduct

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

the class GeneProductDaoImpl method find.

@Override
public GeneProduct find(GeneProduct geneProduct) {
    try {
        Criteria queryObject = this.getSessionFactory().getCurrentSession().createCriteria(GeneProduct.class).setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
        BusinessKey.checkValidKey(geneProduct);
        BusinessKey.createQueryObject(queryObject, geneProduct);
        AbstractDao.log.debug(queryObject);
        // noinspection unchecked
        List<GeneProduct> results = queryObject.list();
        Object result = null;
        if (results.size() > 1) {
            /*
                 * At this point we can trust that the genes are from the same taxon. This kind of confusion should
                 * reduce with cruft-reduction.
                 */
            // we tend to want to keep the one with the lowest ID
            Collections.sort(results, GeneProductDaoImpl.c);
            Gene gene = geneProduct.getGene();
            if (gene != null) {
                GeneProduct keeper = null;
                int numFound = 0;
                for (Object object : results) {
                    GeneProduct candidateMatch = (GeneProduct) object;
                    Gene candidateGene = candidateMatch.getGene();
                    if (candidateGene.getOfficialSymbol().equals(gene.getOfficialSymbol()) && candidateGene.getTaxon().equals(gene.getTaxon())) {
                        keeper = candidateMatch;
                        numFound++;
                    }
                }
                if (numFound == 1) {
                    // not so bad, we figured out a match.
                    AbstractDao.log.warn("Multiple gene products match " + geneProduct + ", but only one for the right gene (" + gene + "), returning " + keeper);
                    this.debug(results);
                    return keeper;
                }
                if (numFound == 0) {
                    AbstractDao.log.error("Multiple gene products match " + geneProduct + ", but none with " + gene);
                    this.debug(results);
                    AbstractDao.log.error("Returning arbitrary match " + results.iterator().next());
                    return results.iterator().next();
                }
                if (numFound > 1) {
                    AbstractDao.log.error("Multiple gene products match " + geneProduct + ", and matches " + numFound + " genes");
                    this.debug(results);
                    AbstractDao.log.error("Returning arbitrary match " + results.iterator().next());
                    return results.iterator().next();
                }
            }
        } else if (results.size() == 1) {
            result = results.iterator().next();
        }
        if (result == null)
            return null;
        AbstractDao.log.debug("Found: " + result);
        return (GeneProduct) result;
    } catch (org.hibernate.HibernateException ex) {
        throw super.convertHibernateAccessException(ex);
    }
}
Also used : GeneProduct(ubic.gemma.model.genome.gene.GeneProduct) Gene(ubic.gemma.model.genome.Gene) GeneProductValueObject(ubic.gemma.model.genome.gene.GeneProductValueObject) Criteria(org.hibernate.Criteria)

Example 28 with GeneProduct

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

the class ArrayDesignProbeMapperServiceImpl method doLoad.

private void doLoad(final BlockingQueue<BACS> queue, AtomicBoolean generatorDone, AtomicBoolean loaderDone, boolean persist) {
    int loadedAssociationCount = 0;
    while (!(generatorDone.get() && queue.isEmpty())) {
        try {
            BACS bacs = queue.poll();
            if (bacs == null) {
                continue;
            }
            GeneProduct geneProduct = bacs.ba.getGeneProduct();
            if (geneProduct.getId() == null) {
                GeneProduct existing = geneProductService.find(geneProduct);
                if (existing == null) {
                    existing = this.checkForAlias(geneProduct);
                    if (existing == null) {
                        /*
                             * We have to be careful not to cruft up the gene table now that I so carefully cleaned it.
                             * But this is a problem if we aren't adding some other association to the gene at least.
                             * But generally the mRNAs that GP has that NCBI doesn't are "alternative" or "additional".
                             */
                        if (ArrayDesignProbeMapperServiceImpl.log.isDebugEnabled())
                            ArrayDesignProbeMapperServiceImpl.log.debug("New gene product from GoldenPath is not in Gemma: " + geneProduct + " skipping association to " + bacs.ba.getBioSequence() + " [skipping policy in place]");
                        continue;
                    }
                }
                bacs.ba.setGeneProduct(existing);
            }
            if (persist) {
                persisterHelper.persist(bacs.ba);
                if (++loadedAssociationCount % 1000 == 0) {
                    ArrayDesignProbeMapperServiceImpl.log.info("Persisted " + loadedAssociationCount + " blat associations. " + "Current queue has " + queue.size() + " items.");
                }
            } else {
                this.printResult(bacs.cs, bacs.ba);
            }
        } catch (Exception e) {
            ArrayDesignProbeMapperServiceImpl.log.error(e, e);
            loaderDone.set(true);
            throw new RuntimeException(e);
        }
    }
    ArrayDesignProbeMapperServiceImpl.log.info("Load thread done: loaded " + loadedAssociationCount + " blat associations. ");
    loaderDone.set(true);
}
Also used : GeneProduct(ubic.gemma.model.genome.gene.GeneProduct) IOException(java.io.IOException)

Example 29 with GeneProduct

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

the class BlatAssociationScorerTest method createGeneProduct.

private GeneProduct createGeneProduct() {
    GeneProduct geneProduct = GeneProduct.Factory.newInstance();
    Gene gene = Gene.Factory.newInstance();
    geneProduct.setGene(gene);
    geneProduct.setName("geneProduct");
    return geneProduct;
}
Also used : GeneProduct(ubic.gemma.model.genome.gene.GeneProduct) Gene(ubic.gemma.model.genome.Gene)

Example 30 with GeneProduct

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

the class BlatAssociationScorerTest method testScoreResults.

@Test
public void testScoreResults() {
    // there's only one gene product that is aligned to two different regions
    GeneProduct geneProduct = this.createGeneProduct();
    BlatResult blatResult_1 = this.createBlatResult("6_cox_hap2");
    BlatResult blatResult_2 = this.createBlatResult("6");
    // this has the highest score but located on a non-canonical chromosome
    // so this should be ignored
    BlatAssociation association_1 = BlatAssociation.Factory.newInstance();
    association_1.setGeneProduct(geneProduct);
    association_1.setBlatResult(blatResult_1);
    association_1.setScore(50.0);
    association_1.setOverlap(50);
    association_1.setBioSequence(BioSequence.Factory.newInstance());
    BlatAssociation association_2 = BlatAssociation.Factory.newInstance();
    association_2.setGeneProduct(geneProduct);
    association_2.setBlatResult(blatResult_2);
    association_2.setScore(30.0);
    association_2.setOverlap(30);
    association_2.setBioSequence(BioSequence.Factory.newInstance());
    Collection<BlatAssociation> blatAssociations = new ArrayList<>();
    blatAssociations.add(association_1);
    blatAssociations.add(association_2);
    ProbeMapperConfig config = new ProbeMapperConfig();
    config.setTrimNonCanonicalChromosomeHits(true);
    // BlatAssociation expected = association_2;
    BlatAssociation actual = BlatAssociationScorer.scoreResults(blatAssociations);
    assertFalse(ChromosomeUtil.isCanonical(blatResult_1.getTargetChromosome()));
    assertTrue(ChromosomeUtil.isCanonical(blatResult_2.getTargetChromosome()));
    assertEquals(940.0, association_1.getScore(), 0);
    assertEquals(564.0, association_2.getScore(), 0);
    assertEquals(1.0, actual.getSpecificity(), 0);
// assertEquals( expected, actual );
}
Also used : GeneProduct(ubic.gemma.model.genome.gene.GeneProduct) ArrayList(java.util.ArrayList) BlatAssociation(ubic.gemma.model.genome.sequenceAnalysis.BlatAssociation) BlatResult(ubic.gemma.model.genome.sequenceAnalysis.BlatResult) Test(org.junit.Test)

Aggregations

GeneProduct (ubic.gemma.model.genome.gene.GeneProduct)41 Gene (ubic.gemma.model.genome.Gene)20 HashSet (java.util.HashSet)16 BioSequence2GeneProduct (ubic.gemma.model.association.BioSequence2GeneProduct)12 DatabaseEntry (ubic.gemma.model.common.description.DatabaseEntry)8 BlatAssociation (ubic.gemma.model.genome.sequenceAnalysis.BlatAssociation)8 Test (org.junit.Test)6 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)5 BioSequence (ubic.gemma.model.genome.biosequence.BioSequence)5 AnnotationAssociation (ubic.gemma.model.genome.sequenceAnalysis.AnnotationAssociation)5 HashMap (java.util.HashMap)4 PhysicalLocation (ubic.gemma.model.genome.PhysicalLocation)4 Criteria (org.hibernate.Criteria)3 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 GeneProductValueObject (ubic.gemma.model.genome.gene.GeneProductValueObject)2 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1