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;
}
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);
}
}
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);
}
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;
}
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 );
}
Aggregations