Search in sources :

Example 1 with Gene2GOAssociation

use of ubic.gemma.model.association.Gene2GOAssociation in project Gemma by PavlidisLab.

the class GeneMultifunctionalityPopulationServiceTest method setUp.

@Before
public void setUp() throws Exception {
    if (goService.isRunning()) {
        goService.shutDown();
    }
    gene2GoService.removeAll();
    goService.loadTermsInNameSpace(new GZIPInputStream(this.getClass().getResourceAsStream("/data/loader/ontology/molecular-function.test.owl.gz")));
    testTaxon = taxonService.findOrCreate(Taxon.Factory.newInstance("foobly" + RandomStringUtils.randomAlphabetic(2), "doobly" + RandomStringUtils.randomAlphabetic(2), "bar" + RandomStringUtils.randomAlphabetic(2), RandomUtils.nextInt(5000), true, true));
    /*
         * Create genes
         */
    for (int i = 0; i < 120; i++) {
        Gene gene = this.getTestPersistentGene(testTaxon);
        // Some genes get no terms.
        if (i >= 100)
            continue;
        /*
             * Add up to 5 GO terms. Parents mean more will be added.
             */
        for (int j = 0; j <= Math.floor(i / 20); j++) {
            VocabCharacteristic oe = VocabCharacteristic.Factory.newInstance();
            oe.setValueUri(GeneOntologyService.BASE_GO_URI + goTerms[j]);
            oe.setValue(goTerms[j]);
            Gene2GOAssociation g2Go1 = Gene2GOAssociation.Factory.newInstance(gene, oe, GOEvidenceCode.EXP);
            gene2GoService.create(g2Go1);
        }
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) Gene(ubic.gemma.model.genome.Gene) VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic) Gene2GOAssociation(ubic.gemma.model.association.Gene2GOAssociation) Before(org.junit.Before)

Example 2 with Gene2GOAssociation

use of ubic.gemma.model.association.Gene2GOAssociation in project Gemma by PavlidisLab.

the class NCBIGene2GOAssociationLoader method load.

public void load(final InputStream inputStream) {
    final BlockingQueue<Gene2GOAssociation> queue = new ArrayBlockingQueue<>(NCBIGene2GOAssociationLoader.QUEUE_SIZE);
    final SecurityContext context = SecurityContextHolder.getContext();
    final Authentication authentication = context.getAuthentication();
    Thread loadThread = new Thread(new Runnable() {

        @Override
        public void run() {
            NCBIGene2GOAssociationLoader.log.info("Starting loading");
            SecurityContextHolder.setContext(context);
            NCBIGene2GOAssociationLoader.this.load(queue);
        }
    });
    loadThread.start();
    Thread parseThread = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                // NCBIGene2GOAssociationParser parser = new NCBIGene2GOAssociationParser();
                SecurityContextHolder.getContext().setAuthentication(authentication);
                parser.parse(inputStream, queue);
                NCBIGene2GOAssociationLoader.this.setCount(parser.getCount());
            } catch (IOException e) {
                NCBIGene2GOAssociationLoader.log.error(e, e);
                throw new RuntimeException(e);
            }
            NCBIGene2GOAssociationLoader.log.info("Done parsing");
            producerDone.set(true);
        }
    });
    parseThread.start();
    while (!this.isProducerDone() || !this.isConsumerDone()) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
Also used : ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext) Gene2GOAssociation(ubic.gemma.model.association.Gene2GOAssociation) IOException(java.io.IOException)

Example 3 with Gene2GOAssociation

use of ubic.gemma.model.association.Gene2GOAssociation in project Gemma by PavlidisLab.

the class NCBIGene2GOAssociationParser method mapFromGene2GO.

/**
 * Note that "-" means a missing value, which in practice only occurs in the "qualifier" and "pubmed" columns.
 *
 * @param line line
 * @return Object
 */
// Possible external use
@SuppressWarnings({ "unused", "WeakerAccess" })
public Gene2GOAssociation mapFromGene2GO(String line) {
    String[] values = StringUtils.splitPreserveAllTokens(line, "\t");
    if (line.startsWith(NCBIGene2GOAssociationParser.COMMENT_INDICATOR))
        return null;
    if (values.length < 8)
        return null;
    Integer taxonId;
    try {
        taxonId = Integer.parseInt(values[TAX_ID]);
    } catch (NumberFormatException e) {
        throw new RuntimeException(e);
    }
    if (!taxaNcbiIds.containsKey(taxonId)) {
        return null;
    }
    Gene gene = Gene.Factory.newInstance();
    gene.setNcbiGeneId(Integer.parseInt(values[GENE_ID]));
    gene.setTaxon(taxaNcbiIds.get(taxonId));
    VocabCharacteristic oe = VocabCharacteristic.Factory.newInstance();
    String value = values[GO_ID].replace(":", "_");
    oe.setValueUri(GeneOntologyService.BASE_GO_URI + value);
    oe.setValue(value);
    // g2GOAss.setSource( ncbiGeneDb );
    GOEvidenceCode evcode = null;
    String evidenceCode = values[EVIDENCE_CODE];
    if (!(StringUtils.isBlank(evidenceCode) || evidenceCode.equals("-"))) {
        if (NCBIGene2GOAssociationParser.ignoredEvidenceCodes.contains(evidenceCode)) {
            return null;
        }
        evcode = GOEvidenceCode.fromString(evidenceCode);
    }
    Gene2GOAssociation g2GOAss = Gene2GOAssociation.Factory.newInstance(gene, oe, evcode);
    try {
        queue.put(g2GOAss);
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
    return g2GOAss;
}
Also used : Gene(ubic.gemma.model.genome.Gene) GOEvidenceCode(ubic.gemma.model.association.GOEvidenceCode) VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic) Gene2GOAssociation(ubic.gemma.model.association.Gene2GOAssociation)

Example 4 with Gene2GOAssociation

use of ubic.gemma.model.association.Gene2GOAssociation in project Gemma by PavlidisLab.

the class NCBIGene2GOAssociationLoader method load.

private void load(BlockingQueue<Gene2GOAssociation> queue) {
    NCBIGene2GOAssociationLoader.log.debug("Entering 'load' ");
    long millis = System.currentTimeMillis();
    int cpt = 0;
    double secspt = 0.0;
    Collection<Gene2GOAssociation> itemsToPersist = new ArrayList<>();
    try {
        while (!(producerDone.get() && queue.isEmpty())) {
            Gene2GOAssociation associations = queue.poll();
            if (associations == null) {
                continue;
            }
            itemsToPersist.add(associations);
            if (++count % NCBIGene2GOAssociationLoader.BATCH_SIZE == 0) {
                persisterHelper.persist(itemsToPersist);
                itemsToPersist.clear();
            }
            // just some timing information.
            if (count % 1000 == 0) {
                cpt++;
                double secsperthousand = (System.currentTimeMillis() - millis) / 1000.0;
                secspt += secsperthousand;
                double meanspt = secspt / cpt;
                String progString = "Processed and loaded " + count + " (" + secsperthousand + " seconds elapsed, average per thousand=" + String.format("%.2f", meanspt) + ")";
                NCBIGene2GOAssociationLoader.log.info(progString);
                millis = System.currentTimeMillis();
            }
        }
    } catch (Exception e) {
        consumerDone.set(true);
        NCBIGene2GOAssociationLoader.log.fatal(e, e);
        throw new RuntimeException(e);
    }
    // finish up.
    persisterHelper.persist(itemsToPersist);
    NCBIGene2GOAssociationLoader.log.info("Finished, loaded total of " + count + " GO associations");
    consumerDone.set(true);
}
Also used : ArrayList(java.util.ArrayList) Gene2GOAssociation(ubic.gemma.model.association.Gene2GOAssociation) IOException(java.io.IOException)

Example 5 with Gene2GOAssociation

use of ubic.gemma.model.association.Gene2GOAssociation in project Gemma by PavlidisLab.

the class GeneServiceImpl method findGOTerms.

@Override
@Transactional(readOnly = true)
public Collection<AnnotationValueObject> findGOTerms(Long geneId) {
    if (geneId == null)
        throw new IllegalArgumentException("Null id for gene");
    Collection<AnnotationValueObject> ontologies = new HashSet<>();
    Gene g = this.load(geneId);
    if (g == null) {
        throw new IllegalArgumentException("No such gene could be loaded with id=" + geneId);
    }
    Collection<Gene2GOAssociation> associations = gene2GOAssociationService.findAssociationByGene(g);
    for (Gene2GOAssociation assoc : associations) {
        if (assoc.getOntologyEntry() == null)
            continue;
        AnnotationValueObject annotationValueObject = new AnnotationValueObject();
        annotationValueObject.setId(assoc.getOntologyEntry().getId());
        annotationValueObject.setTermName(geneOntologyService.getTermName(assoc.getOntologyEntry().getValue()));
        annotationValueObject.setTermUri(assoc.getOntologyEntry().getValue());
        annotationValueObject.setEvidenceCode(assoc.getEvidenceCode().getValue());
        annotationValueObject.setDescription(assoc.getOntologyEntry().getDescription());
        annotationValueObject.setClassUri(assoc.getOntologyEntry().getCategoryUri());
        annotationValueObject.setClassName(assoc.getOntologyEntry().getCategory());
        ontologies.add(annotationValueObject);
    }
    return annotationAssociationService.removeRootTerms(ontologies);
}
Also used : Gene(ubic.gemma.model.genome.Gene) AnnotationValueObject(ubic.gemma.model.common.description.AnnotationValueObject) Gene2GOAssociation(ubic.gemma.model.association.Gene2GOAssociation) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Gene2GOAssociation (ubic.gemma.model.association.Gene2GOAssociation)7 VocabCharacteristic (ubic.gemma.model.common.description.VocabCharacteristic)3 Gene (ubic.gemma.model.genome.Gene)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 Criteria (org.hibernate.Criteria)1 Before (org.junit.Before)1 Test (org.junit.Test)1 Authentication (org.springframework.security.core.Authentication)1 SecurityContext (org.springframework.security.core.context.SecurityContext)1 Transactional (org.springframework.transaction.annotation.Transactional)1 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)1 GOEvidenceCode (ubic.gemma.model.association.GOEvidenceCode)1 AnnotationValueObject (ubic.gemma.model.common.description.AnnotationValueObject)1