Search in sources :

Example 31 with VocabCharacteristic

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

the class CharacteristicUpdateTaskImpl method convertAvo2Characteristic.

private VocabCharacteristic convertAvo2Characteristic(AnnotationValueObject avo) {
    VocabCharacteristic vc = VocabCharacteristic.Factory.newInstance();
    vc.setId(avo.getId());
    vc.setCategory(avo.getClassName());
    vc.setCategoryUri(avo.getClassUri());
    vc.setValue(avo.getTermName());
    vc.setValueUri(avo.getTermUri());
    if (StringUtils.isNotBlank(avo.getEvidenceCode()))
        vc.setEvidenceCode(GOEvidenceCode.fromString(avo.getEvidenceCode()));
    return vc;
}
Also used : VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic)

Example 32 with VocabCharacteristic

use of ubic.gemma.model.common.description.VocabCharacteristic 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 33 with VocabCharacteristic

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

the class ExperimentalDesignImporterImpl method addFactorValuesToExperimentalFactor.

/**
 * Method that adds factor values to a given experimental factor
 *
 * @param experimentalFactor The experimental factor to add the factor values to
 * @param factorSampleValues A map of factor value names keyed on experimental factor name
 * @param factorType         Whether the factor is continuous or categorical
 */
private void addFactorValuesToExperimentalFactor(ExperimentalFactor experimentalFactor, Map<String, Set<String>> factorSampleValues, String factorType) {
    ExperimentalDesignImporterImpl.log.debug("Addding factors values to experimental factor: " + experimentalFactor.getName());
    VocabCharacteristic category = (VocabCharacteristic) experimentalFactor.getCategory();
    Set<String> values = factorSampleValues.get(experimentalFactor.getName());
    for (String value : values) {
        FactorValue factorValue = FactorValue.Factory.newInstance();
        factorValue.setValue(value);
        if (factorType.equalsIgnoreCase("CATEGORICAL")) {
            ExperimentalDesignImporterImpl.log.debug("Factor is categorical");
            VocabCharacteristic newVc = VocabCharacteristic.Factory.newInstance();
            String category2 = category.getCategory();
            assert category2 != null;
            newVc.setCategory(category2);
            newVc.setCategoryUri(category.getCategoryUri());
            newVc.setValue(value);
            newVc.setEvidenceCode(GOEvidenceCode.IC);
            factorValue.getCharacteristics().add(newVc);
        } else {
            ExperimentalDesignImporterImpl.log.debug("Factor is continous");
            this.addMeasurementToFactorValueOfTypeContinous(factorValue);
        }
        // set bidirectional relationship
        experimentalFactor.getFactorValues().add(factorValue);
        factorValue.setExperimentalFactor(experimentalFactor);
        ExperimentalDesignImporterImpl.log.debug("Added factor value " + factorValue + " to experimental factor " + experimentalFactor);
    }
}
Also used : VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic)

Example 34 with VocabCharacteristic

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

the class ExperimentalDesignImporterImpl method addExperimentalFactorsToExperimentalDesign.

/**
 * This method reads the file line e.g. $Run time : Category=environmental_history Type=categorical and creates
 * experimental factors from it and adds them to the experimental design.
 * NOTE that this doesn't have the ability to add values to existing factors, which might be desirable.
 *
 * @param experimentalDesign          Experimental design for this expression experiment
 * @param experimentalFactorFileLines List of strings representing lines from input file containing experimental
 *                                    factors
 * @param headerFields                Sample header line split on tab.
 * @param factorValueLines            Lines containing biomaterial names and their factor values
 */
private void addExperimentalFactorsToExperimentalDesign(ExperimentalDesign experimentalDesign, List<String> experimentalFactorFileLines, String[] headerFields, List<String> factorValueLines) {
    int maxWait = 0;
    if (efoService.isEnabled()) {
        while (!efoService.isOntologyLoaded()) {
            try {
                Thread.sleep(10000);
                if (maxWait++ > 10) {
                    ExperimentalDesignImporterImpl.log.error("EFO is not loaded and gave up waiting");
                    break;
                // this is okay, we can get by using OntologyTermSimple.
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    Collection<OntologyTerm> terms = ontologyService.getCategoryTerms();
    if (experimentalDesign.getExperimentalFactors() == null) {
        experimentalDesign.setExperimentalFactors(new HashSet<ExperimentalFactor>());
    }
    Map<String, Set<String>> mapFactorSampleValues = this.getMapFactorSampleValues(headerFields, factorValueLines);
    for (String experimentalFactorFileLine : experimentalFactorFileLines) {
        // $Run time : Category=EnvironmentalHistory Type=categorical
        String[] experimentalFactorfields = experimentalFactorFileLine.split(":");
        String factorValue = (StringUtils.strip(experimentalFactorfields[0].replaceFirst(Pattern.quote(ExperimentalDesignImporterImpl.EXPERIMENTAL_FACTOR_DESCRIPTION_LINE_INDICATOR) + "\\s*", ""))).trim();
        String categoryAndType = StringUtils.strip(experimentalFactorfields[1]);
        String[] categoryAndTypeFields = StringUtils.split(categoryAndType);
        // e.g. Category=EnvironmentalHistory
        String category = categoryAndTypeFields[0];
        // e.g. EnvironmentalHistory
        String categoryValue = StringUtils.split(category, "=")[1];
        ExperimentalFactor experimentalFactorFromFile = ExperimentalFactor.Factory.newInstance();
        experimentalFactorFromFile.setExperimentalDesign(experimentalDesign);
        VocabCharacteristic vc = this.termForCategoryLookup(categoryValue, terms);
        // e.g. Category=EnvironmentalHistory
        String categoryTypeValue = categoryAndTypeFields[1];
        String factorType = StringUtils.split(categoryTypeValue, "=")[1];
        // vc.setCategory( categoryType );
        experimentalFactorFromFile.setCategory(vc);
        experimentalFactorFromFile.setName(factorValue);
        experimentalFactorFromFile.setDescription(factorValue);
        experimentalFactorFromFile.setType(factorType.equalsIgnoreCase("CATEGORICAL") ? FactorType.CATEGORICAL : FactorType.CONTINUOUS);
        this.addFactorValuesToExperimentalFactor(experimentalFactorFromFile, mapFactorSampleValues, factorType);
        if (!this.checkForDuplicateExperimentalFactorOnExperimentalDesign(experimentalDesign, experimentalFactorFromFile)) {
            experimentalDesign.getExperimentalFactors().add(experimentalFactorFromFile);
            ExperimentalDesignImporterImpl.log.info("Added " + experimentalFactorFromFile);
        }
    }
}
Also used : VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic) OntologyTerm(ubic.basecode.ontology.model.OntologyTerm)

Example 35 with VocabCharacteristic

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

the class OntologyServiceImpl method termsToCharacteristics.

/**
 * Convert raw ontology resources into VocabCharacteristics.
 */
@Override
public Collection<VocabCharacteristic> termsToCharacteristics(final Collection<? extends OntologyResource> terms) {
    Collection<VocabCharacteristic> results = new HashSet<>();
    if ((terms == null) || (terms.isEmpty()))
        return results;
    for (OntologyResource res : terms) {
        if (res == null)
            continue;
        VocabCharacteristic vc = VocabCharacteristic.Factory.newInstance();
        if (res instanceof OntologyTerm) {
            OntologyTerm term = (OntologyTerm) res;
            vc.setValue(term.getTerm());
            vc.setValueUri(term.getUri());
            vc.setDescription(term.getComment());
        } else if (res instanceof OntologyIndividual) {
            OntologyIndividual indi = (OntologyIndividual) res;
            vc.setValue(indi.getLabel());
            vc.setValueUri(indi.getUri());
            vc.setDescription("Individual");
        } else {
            OntologyServiceImpl.log.warn("What is it? " + res);
            continue;
        }
        if (vc.getValue() == null)
            continue;
        results.add(vc);
    }
    OntologyServiceImpl.log.debug("returning " + results.size() + " terms after filter");
    return results;
}
Also used : VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic) OntologyIndividual(ubic.basecode.ontology.model.OntologyIndividual) OntologyTerm(ubic.basecode.ontology.model.OntologyTerm) OntologyResource(ubic.basecode.ontology.model.OntologyResource) ConcurrentHashSet(org.compass.core.util.concurrent.ConcurrentHashSet)

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