use of ubic.gemma.model.common.description.DatabaseEntry in project Gemma by PavlidisLab.
the class ExpressionExperimentBibRefFinder method locatePrimaryReference.
public BibliographicReference locatePrimaryReference(ExpressionExperiment ee) {
if (ee.getPrimaryPublication() != null)
return ee.getPrimaryPublication();
DatabaseEntry accession = ee.getAccession();
ExternalDatabase ed = accession.getExternalDatabase();
if (!ed.getName().equals("GEO")) {
ExpressionExperimentBibRefFinder.log.warn("Don't know how to get references for non-GEO data sets");
return null;
}
String geoId = accession.getAccession();
int pubMedId = this.locatePubMedId(geoId);
if (pubMedId < 0)
return null;
PubMedXMLFetcher fetcher = new PubMedXMLFetcher();
return fetcher.retrieveByHTTP(pubMedId);
}
use of ubic.gemma.model.common.description.DatabaseEntry in project Gemma by PavlidisLab.
the class LoadEvidenceForClassifier method findMeshTerms.
// return mesh term of a pubmed format : meshTerm1;meshTerm2;meshTerms3.... etc
private String findMeshTerms(String pubmed) {
StringBuilder result = new StringBuilder();
DatabaseEntry de = DatabaseEntry.Factory.newInstance();
de.setAccession(pubmed);
BibliographicReference bi = BibliographicReference.Factory.newInstance();
bi.setPubAccession(de);
System.out.println(pubmed);
BibliographicReference b = this.bibliographicReferenceService.find(bi);
for (MedicalSubjectHeading m : b.getMeshTerms()) {
result.append(m.getTerm()).append(";");
}
return result.toString();
}
use of ubic.gemma.model.common.description.DatabaseEntry in project Gemma by PavlidisLab.
the class ArrayDesignPersister method persistNewArrayDesign.
/**
* Persist an entirely new array design, including composite sequences and any associated new sequences.
*/
private ArrayDesign persistNewArrayDesign(ArrayDesign arrayDesign) {
if (arrayDesign == null)
return null;
AbstractPersister.log.info("Persisting new platform " + arrayDesign.getName());
try {
this.getSessionFactory().getCurrentSession().setFlushMode(FlushMode.COMMIT);
if (arrayDesign.getDesignProvider() != null)
arrayDesign.setDesignProvider(this.persistContact(arrayDesign.getDesignProvider()));
if (arrayDesign.getLocalFiles() != null) {
for (LocalFile file : arrayDesign.getLocalFiles()) {
this.persistLocalFile(file);
}
}
if (arrayDesign.getPrimaryTaxon() == null) {
throw new IllegalArgumentException("Primary taxon cannot be null");
}
arrayDesign.setPrimaryTaxon((Taxon) this.persist(arrayDesign.getPrimaryTaxon()));
for (DatabaseEntry externalRef : arrayDesign.getExternalReferences()) {
externalRef.setExternalDatabase(this.persistExternalDatabase(externalRef.getExternalDatabase()));
}
AbstractPersister.log.info("Persisting " + arrayDesign);
if (arrayDesign.getAuditTrail() != null && this.isTransient(arrayDesign.getAuditTrail()))
arrayDesign.getAuditTrail().setId(null);
Collection<CompositeSequence> scs = new ArrayList<>(arrayDesign.getCompositeSequences());
arrayDesign.getCompositeSequences().clear();
arrayDesign = arrayDesignDao.create(arrayDesign);
arrayDesign.getCompositeSequences().addAll(scs);
arrayDesign = this.persistArrayDesignCompositeSequenceAssociations(arrayDesign);
arrayDesignDao.update(arrayDesign);
} finally {
this.getSessionFactory().getCurrentSession().setFlushMode(FlushMode.AUTO);
}
return arrayDesign;
}
use of ubic.gemma.model.common.description.DatabaseEntry in project Gemma by PavlidisLab.
the class GenomePersister method persistGene.
private Gene persistGene(Gene gene, boolean checkFirst) {
if (gene == null)
return null;
if (!this.isTransient(gene))
return gene;
if (checkFirst) {
Gene existingGene = geneDao.find(gene);
if (existingGene != null) {
if (AbstractPersister.log.isDebugEnabled())
AbstractPersister.log.debug("Gene exists, will not update");
return existingGene;
}
}
if (gene.getAccessions().size() > 0) {
for (DatabaseEntry de : gene.getAccessions()) {
this.fillInDatabaseEntry(de);
}
}
Collection<GeneProduct> tempGeneProduct = gene.getProducts();
gene.setProducts(null);
gene.setTaxon(this.persistTaxon(gene.getTaxon()));
this.fillChromosomeLocationAssociations(gene.getPhysicalLocation(), gene.getTaxon());
if (AbstractPersister.log.isInfoEnabled())
AbstractPersister.log.info("New gene: " + gene);
gene = geneDao.create(gene);
Collection<GeneProduct> geneProductsForNewGene = new HashSet<>();
for (GeneProduct product : tempGeneProduct) {
GeneProduct existingProduct = geneProductDao.find(product);
if (existingProduct != null) {
/*
* A geneProduct is being moved to a gene that didn't exist in the system already
*/
Gene previousGeneForProduct = existingProduct.getGene();
previousGeneForProduct.getProducts().remove(existingProduct);
// we aren't going to make it, this isn't really necessary.
product.setGene(null);
existingProduct.setGene(gene);
geneProductsForNewGene.add(existingProduct);
AbstractPersister.log.warn("While creating new gene: Gene product: [New=" + product + "] is already associated with a gene [Old=" + existingProduct + "], will move to associate with new gene: " + gene);
} else {
product.setGene(gene);
geneProductsForNewGene.add(product);
}
}
// attach the products.
gene.setProducts(geneProductsForNewGene);
for (GeneProduct gp : gene.getProducts()) {
this.fillInGeneProductAssociations(gp);
}
try {
// we do a separate create because the cascade doesn't trigger auditing correctly - otherwise the
// products are not persistent until the session is flushed, later. There might be a better way around this,
// but so far as I know this is the only place this happens.
// noinspection unchecked
gene.setProducts(geneProductDao.create(gene.getProducts()));
geneDao.update(gene);
return gene;
} catch (Exception e) {
AbstractPersister.log.error("**** Error while creating gene: " + gene + "; products:");
for (GeneProduct gp : gene.getProducts()) {
System.err.println(gp);
}
throw new RuntimeException(e);
}
}
use of ubic.gemma.model.common.description.DatabaseEntry in project Gemma by PavlidisLab.
the class GenomePersister method removeGeneProducts.
private void removeGeneProducts(Collection<GeneProduct> toRemove) {
Collection<BlatAssociation> associations = this.blatAssociationDao.find(toRemove);
if (!associations.isEmpty()) {
AbstractPersister.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()) {
AbstractPersister.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) {
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);
}
}
Aggregations