use of ubic.gemma.model.genome.gene.GeneProduct in project Gemma by PavlidisLab.
the class ExternalFileGeneLoaderServiceImpl method createGeneProduct.
/**
* When loading genes with a file each gene will have just 1 gene product. The gene product is a filler taking its
* details from the gene.
*
* @param gene The gene associated to this gene product
* @return Collection of gene products in this case just 1.
*/
private GeneProduct createGeneProduct(Gene gene) {
GeneProduct geneProduct = GeneProduct.Factory.newInstance();
geneProduct.setType(GeneProductType.RNA);
geneProduct.setGene(gene);
geneProduct.setName(gene.getName());
geneProduct.setDescription("Gene product placeholder");
return geneProduct;
}
use of ubic.gemma.model.genome.gene.GeneProduct in project Gemma by PavlidisLab.
the class ExternalFileGeneLoaderServiceImpl method createGene.
/**
* Creates a gene, where gene name and official gene symbol is set to gene symbol(from file) and official name is
* set to geneName(from file). The gene description is set to a message indicating that the gene was imported from
* an external file and the associated uniprot id.
* If the gene already exists, then it is not modified, unless it lacks a gene product. In that case we add one and
* return it.
*
* @param fields A string array containing gene symbol, gene name and uniprot id.
* @param taxon Taxon relating to gene
* @return Gene with associated gene product for loading into Gemma. Null if no gene was loaded (exists, or invalid
* fields) or modified.
*/
private Gene createGene(String[] fields, Taxon taxon) {
assert fields.length > 1;
String geneSymbol = fields[0];
String geneName = fields[1];
String uniProt = "";
if (fields.length > 2)
uniProt = fields[2];
Gene gene;
// need at least the gene symbol and gene name
if (StringUtils.isBlank(geneSymbol) || StringUtils.isBlank(geneName)) {
log.warn("Line did not contain valid gene information; GeneSymbol=" + geneSymbol + "GeneName=" + geneName + " UniProt=" + uniProt);
return null;
}
if (log.isDebugEnabled())
log.debug("Creating gene " + geneSymbol);
gene = geneService.findByOfficialSymbol(geneSymbol, taxon);
if (gene != null) {
Collection<GeneProductValueObject> existingProducts = geneService.getProducts(gene.getId());
if (existingProducts.isEmpty()) {
log.warn("Gene " + gene + " exists, but has no products; adding one");
gene = geneService.thaw(gene);
GeneProduct newgp = createGeneProduct(gene);
newgp = geneProductService.create(newgp);
gene.getProducts().add(newgp);
geneService.update(gene);
return gene;
}
log.info(gene + " already exists and is valid, will not update");
// no need to create it, though we ignore the name.
return null;
}
gene = Gene.Factory.newInstance();
gene.setName(geneSymbol);
gene.setOfficialSymbol(geneSymbol);
gene.setOfficialName(StringUtils.lowerCase(geneName));
gene.setDescription("Imported from external annotation file");
gene.setTaxon(taxon);
gene.getProducts().add(createGeneProduct(gene));
gene = (Gene) persisterHelper.persistOrUpdate(gene);
return gene;
}
use of ubic.gemma.model.genome.gene.GeneProduct in project Gemma by PavlidisLab.
the class CompositeSequenceDaoImpl method thaw.
@Override
public void thaw(final Collection<CompositeSequence> compositeSequences) {
HibernateTemplate templ = this.getHibernateTemplate();
templ.executeWithNativeSession(new org.springframework.orm.hibernate3.HibernateCallback<Object>() {
@Override
public Object doInHibernate(org.hibernate.Session session) throws org.hibernate.HibernateException {
int i = 0;
int numToDo = compositeSequences.size();
for (CompositeSequence cs : compositeSequences) {
session.buildLockRequest(LockOptions.NONE).lock(cs);
Hibernate.initialize(cs.getArrayDesign());
BioSequence bs = cs.getBiologicalCharacteristic();
if (bs == null) {
continue;
}
session.buildLockRequest(LockOptions.NONE).lock(bs);
Hibernate.initialize(bs);
Hibernate.initialize(bs.getTaxon());
DatabaseEntry dbEntry = bs.getSequenceDatabaseEntry();
if (dbEntry != null) {
Hibernate.initialize(dbEntry);
Hibernate.initialize(dbEntry.getExternalDatabase());
session.evict(dbEntry);
session.evict(dbEntry.getExternalDatabase());
}
if (bs.getBioSequence2GeneProduct() == null) {
continue;
}
for (BioSequence2GeneProduct bs2gp : bs.getBioSequence2GeneProduct()) {
if (bs2gp == null) {
continue;
}
GeneProduct geneProduct = bs2gp.getGeneProduct();
if (geneProduct != null && geneProduct.getGene() != null) {
Gene g = geneProduct.getGene();
g.getAliases().size();
session.evict(g);
session.evict(geneProduct);
}
}
if (++i % 2000 == 0) {
AbstractDao.log.info("Progress: " + i + "/" + numToDo + "...");
try {
Thread.sleep(10);
} catch (InterruptedException e) {
//
}
}
session.evict(bs);
}
session.clear();
return null;
}
});
}
use of ubic.gemma.model.genome.gene.GeneProduct in project Gemma by PavlidisLab.
the class GeneProductServiceImpl method remove.
@Override
@Transactional
public void remove(Collection<GeneProduct> toRemove) {
Collection<BlatAssociation> associations = this.blatAssociationDao.find(toRemove);
if (!associations.isEmpty()) {
AbstractService.log.info("Removing " + associations.size() + " blat associations involving up to " + toRemove.size() + " products.");
this.blatAssociationDao.remove(associations);
}
Collection<AnnotationAssociation> annotationAssociations = this.annotationAssociationDao.find(toRemove);
if (!annotationAssociations.isEmpty()) {
AbstractService.log.info("Removing " + annotationAssociations.size() + " annotationAssociations involving up to " + toRemove.size() + " products.");
this.annotationAssociationDao.remove(annotationAssociations);
}
// remove associations to database entries that are still associated with sequences.
for (GeneProduct gp : toRemove) {
gp = this.thaw(gp);
Collection<DatabaseEntry> accessions = gp.getAccessions();
Collection<DatabaseEntry> toRelease = new HashSet<>();
for (DatabaseEntry de : accessions) {
if (this.bioSequenceDao.findByAccession(de) != null) {
toRelease.add(de);
}
}
gp.getAccessions().removeAll(toRelease);
this.geneProductDao.remove(gp);
}
}
use of ubic.gemma.model.genome.gene.GeneProduct in project Gemma by PavlidisLab.
the class GenomePersister method persistGeneProduct.
private GeneProduct persistGeneProduct(GeneProduct geneProduct) {
if (geneProduct == null)
return null;
if (!this.isTransient(geneProduct))
return geneProduct;
GeneProduct existing = geneProductDao.find(geneProduct);
if (existing != null) {
if (AbstractPersister.log.isDebugEnabled())
AbstractPersister.log.debug(geneProduct + " exists, will not update");
return existing;
}
if (AbstractPersister.log.isDebugEnabled())
AbstractPersister.log.debug("*** New: " + geneProduct + " *** ");
this.fillInGeneProductAssociations(geneProduct);
if (this.isTransient(geneProduct.getGene())) {
// this results in the persistence of the gene products, but only if the gene is transient.
geneProduct.setGene(this.persistGene(geneProduct.getGene()));
} else {
geneProduct = geneProductDao.create(geneProduct);
}
if (geneProduct.getId() == null) {
return geneProductDao.create(geneProduct);
}
return geneProduct;
}
Aggregations