Search in sources :

Example 16 with DatabaseEntry

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);
}
Also used : ExternalDatabase(ubic.gemma.model.common.description.ExternalDatabase) DatabaseEntry(ubic.gemma.model.common.description.DatabaseEntry)

Example 17 with DatabaseEntry

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();
}
Also used : DatabaseEntry(ubic.gemma.model.common.description.DatabaseEntry) MedicalSubjectHeading(ubic.gemma.model.common.description.MedicalSubjectHeading) BibliographicReference(ubic.gemma.model.common.description.BibliographicReference)

Example 18 with DatabaseEntry

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;
}
Also used : LocalFile(ubic.gemma.model.common.description.LocalFile) ArrayList(java.util.ArrayList) DatabaseEntry(ubic.gemma.model.common.description.DatabaseEntry) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence)

Example 19 with DatabaseEntry

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);
    }
}
Also used : BioSequence2GeneProduct(ubic.gemma.model.association.BioSequence2GeneProduct) GeneProduct(ubic.gemma.model.genome.gene.GeneProduct) DatabaseEntry(ubic.gemma.model.common.description.DatabaseEntry) HashSet(java.util.HashSet)

Example 20 with DatabaseEntry

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);
    }
}
Also used : BioSequence2GeneProduct(ubic.gemma.model.association.BioSequence2GeneProduct) GeneProduct(ubic.gemma.model.genome.gene.GeneProduct) AnnotationAssociation(ubic.gemma.model.genome.sequenceAnalysis.AnnotationAssociation) DatabaseEntry(ubic.gemma.model.common.description.DatabaseEntry) BlatAssociation(ubic.gemma.model.genome.sequenceAnalysis.BlatAssociation) HashSet(java.util.HashSet)

Aggregations

DatabaseEntry (ubic.gemma.model.common.description.DatabaseEntry)37 ExternalDatabase (ubic.gemma.model.common.description.ExternalDatabase)11 GeneProduct (ubic.gemma.model.genome.gene.GeneProduct)8 HashSet (java.util.HashSet)6 Test (org.junit.Test)6 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)6 Gene (ubic.gemma.model.genome.Gene)6 BioSequence (ubic.gemma.model.genome.biosequence.BioSequence)6 Taxon (ubic.gemma.model.genome.Taxon)5 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)4 BioSequence2GeneProduct (ubic.gemma.model.association.BioSequence2GeneProduct)4 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)4 HashMap (java.util.HashMap)3 BibliographicReference (ubic.gemma.model.common.description.BibliographicReference)3 AnnotationAssociation (ubic.gemma.model.genome.sequenceAnalysis.AnnotationAssociation)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Before (org.junit.Before)2 AlreadyExistsInSystemException (ubic.gemma.core.loader.util.AlreadyExistsInSystemException)2 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)2