Search in sources :

Example 21 with VocabCharacteristic

use of ubic.gemma.model.common.description.VocabCharacteristic in project Gemma by PavlidisLab.

the class BatchInfoPopulationHelperServiceImpl method getBatchFactorCategory.

private VocabCharacteristic getBatchFactorCategory() {
    VocabCharacteristic c = VocabCharacteristic.Factory.newInstance();
    c.setCategory(ExperimentalDesignUtils.BATCH_FACTOR_CATEGORY_NAME);
    c.setValue(ExperimentalDesignUtils.BATCH_FACTOR_CATEGORY_NAME);
    c.setValueUri(ExperimentalDesignUtils.BATCH_FACTOR_CATEGORY_URI);
    c.setCategoryUri(ExperimentalDesignUtils.BATCH_FACTOR_CATEGORY_URI);
    c.setEvidenceCode(GOEvidenceCode.IIA);
    return c;
}
Also used : VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic)

Example 22 with VocabCharacteristic

use of ubic.gemma.model.common.description.VocabCharacteristic in project Gemma by PavlidisLab.

the class BatchInfoPopulationServiceImpl method isBatchFactor.

/**
 * @param ef ef
 * @return true if the factor seems to be a 'batch' factor.
 */
public static boolean isBatchFactor(ExperimentalFactor ef) {
    Characteristic c = ef.getCategory();
    boolean isBatchFactor = false;
    boolean looksLikeBatch = ef.getName().equals(ExperimentalDesignUtils.BATCH_FACTOR_NAME);
    if (c != null && c instanceof VocabCharacteristic) {
        VocabCharacteristic v = (VocabCharacteristic) c;
        if (v.getCategory() != null && v.getCategory().equals(ExperimentalDesignUtils.BATCH_FACTOR_CATEGORY_NAME)) {
            isBatchFactor = true;
        }
    } else if (looksLikeBatch) {
        isBatchFactor = true;
    }
    return isBatchFactor;
}
Also used : Characteristic(ubic.gemma.model.common.description.Characteristic) VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic) VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic)

Example 23 with VocabCharacteristic

use of ubic.gemma.model.common.description.VocabCharacteristic in project Gemma by PavlidisLab.

the class DatabaseViewGeneratorImpl method generateDatasetTissueView.

private void generateDatasetTissueView(Integer limit, Collection<ExpressionExperiment> experiments) throws IOException {
    DatabaseViewGeneratorImpl.log.info("Generating dataset tissue view");
    /*
         * Get handle to output file
         */
    File file = this.getViewFile(DatabaseViewGeneratorImpl.DATASET_TISSUE_VIEW_BASENAME);
    DatabaseViewGeneratorImpl.log.info("Writing to " + file);
    try (Writer writer = new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(file)))) {
        /*
             * For all of their annotations... if it's a tissue, print out a line
             */
        writer.write("GemmaDsId\tTerm\tTermURI\n");
        int i = 0;
        for (ExpressionExperiment ee : experiments) {
            ee = expressionExperimentService.thawLite(ee);
            DatabaseViewGeneratorImpl.log.info("Processing: " + ee.getShortName());
            Long gemmaId = ee.getId();
            for (Characteristic c : ee.getCharacteristics()) {
                if (StringUtils.isBlank(c.getValue())) {
                    continue;
                }
                if (c.getCategory().equals("OrganismPart")) {
                    // or tissue? check URI
                    String uri = "";
                    if (c instanceof VocabCharacteristic) {
                        VocabCharacteristic vocabCharacteristic = (VocabCharacteristic) c;
                        if (StringUtils.isNotBlank(vocabCharacteristic.getValueUri()))
                            uri = vocabCharacteristic.getValueUri();
                    }
                    writer.write(String.format("%d\t%s\t%s\n", gemmaId, c.getValue(), uri));
                }
            }
            if (limit != null && (limit > 0 && ++i > limit))
                break;
        }
    }
}
Also used : GZIPOutputStream(java.util.zip.GZIPOutputStream) Characteristic(ubic.gemma.model.common.description.Characteristic) VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic) VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment)

Example 24 with VocabCharacteristic

use of ubic.gemma.model.common.description.VocabCharacteristic in project Gemma by PavlidisLab.

the class ArrayDesignAnnotationServiceImpl method getGoTerms.

/**
 * @param ty Configures which GO terms to return: With all parents, biological process only, or direct annotations
 *           only.
 * @return the goTerms for a given gene, as configured
 */
private Collection<OntologyTerm> getGoTerms(Collection<VocabCharacteristic> ontologyTerms, OutputType ty) {
    Collection<OntologyTerm> results = new HashSet<>();
    if (ontologyTerms == null || ontologyTerms.size() == 0)
        return results;
    for (VocabCharacteristic vc : ontologyTerms) {
        results.add(GeneOntologyServiceImpl.getTermForId(vc.getValue()));
    }
    if (ty.equals(OutputType.SHORT))
        return results;
    if (ty.equals(OutputType.LONG)) {
        Collection<OntologyTerm> oes = goService.getAllParents(results);
        results.addAll(oes);
    } else if (ty.equals(OutputType.BIOPROCESS)) {
        Collection<OntologyTerm> toRemove = new HashSet<>();
        for (OntologyTerm ont : results) {
            if ((ont == null)) {
                // / shouldn't happen!
                continue;
            }
            if (!goService.isBiologicalProcess(ont)) {
                toRemove.add(ont);
            }
        }
        for (OntologyTerm toRemoveOnto : toRemove) {
            results.remove(toRemoveOnto);
        }
    }
    return results;
}
Also used : VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic) OntologyTerm(ubic.basecode.ontology.model.OntologyTerm)

Example 25 with VocabCharacteristic

use of ubic.gemma.model.common.description.VocabCharacteristic in project Gemma by PavlidisLab.

the class GeneMultifunctionalityPopulationServiceImpl method fetchGoAnnotations.

private Map<Gene, Collection<String>> fetchGoAnnotations(Collection<Gene> genes) {
    if (!goService.isRunning()) {
        goService.init(true);
    }
    while (!goService.isReady()) {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
        // 
        }
        GeneMultifunctionalityPopulationServiceImpl.log.info("Waiting for GO to load");
    }
    /*
         * Build the GO 'matrix'.
         */
    int count = 0;
    Map<Gene, Collection<String>> gomap = new HashMap<>();
    for (Gene gene : genes) {
        Collection<VocabCharacteristic> annots = gene2GOService.findByGene(gene);
        Collection<String> termsForGene = new HashSet<>();
        // noinspection StatementWithEmptyBody // TODO we just count it as a gene with lowest multifunctionality
        if (annots.isEmpty()) {
        // continue;
        }
        for (VocabCharacteristic t : annots) {
            if (ontologyService.isObsolete(t.getValueUri())) {
                GeneMultifunctionalityPopulationServiceImpl.log.warn("Obsolete term annotated to " + gene + " : " + t);
                continue;
            }
            termsForGene.add(t.getValue());
            Collection<OntologyTerm> parents = goService.getAllParents(GeneOntologyServiceImpl.getTermForURI(t.getValueUri()));
            for (OntologyTerm p : parents) {
                termsForGene.add(p.getTerm());
            }
        }
        // noinspection StatementWithEmptyBody // TODO we just count it as a gene with lowest multifunctionality
        if (termsForGene.isEmpty()) {
        // continue;
        }
        gomap.put(gene, termsForGene);
        if (++count % 1000 == 0) {
            GeneMultifunctionalityPopulationServiceImpl.log.info("Fetched GO annotations for: " + count + "/" + genes.size() + " genes");
        }
    }
    return gomap;
}
Also used : HashMap(java.util.HashMap) VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic) OntologyTerm(ubic.basecode.ontology.model.OntologyTerm) Gene(ubic.gemma.model.genome.Gene) Collection(java.util.Collection) HashSet(java.util.HashSet)

Aggregations

VocabCharacteristic (ubic.gemma.model.common.description.VocabCharacteristic)44 Characteristic (ubic.gemma.model.common.description.Characteristic)15 OntologyTerm (ubic.basecode.ontology.model.OntologyTerm)10 FactorValue (ubic.gemma.model.expression.experiment.FactorValue)7 Test (org.junit.Test)6 AnnotationValueObject (ubic.gemma.model.common.description.AnnotationValueObject)4 Gene (ubic.gemma.model.genome.Gene)4 HashSet (java.util.HashSet)3 Gene2GOAssociation (ubic.gemma.model.association.Gene2GOAssociation)3 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)3 GZIPOutputStream (java.util.zip.GZIPOutputStream)2 StopWatch (org.apache.commons.lang3.time.StopWatch)2 ConcurrentHashSet (org.compass.core.util.concurrent.ConcurrentHashSet)2 OntologyIndividual (ubic.basecode.ontology.model.OntologyIndividual)2 OntologyResource (ubic.basecode.ontology.model.OntologyResource)2 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)2 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)2 CharacteristicValueObject (ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject)2 AclObjectIdentity (gemma.gsec.acl.domain.AclObjectIdentity)1 InputStream (java.io.InputStream)1