Search in sources :

Example 1 with FactorValue

use of ubic.gemma.model.expression.experiment.FactorValue in project Gemma by PavlidisLab.

the class FactorProfile method checkIfFactorIsContinuous.

/**
 * @param ef experimental factor
 */
private void checkIfFactorIsContinuous(ExperimentalFactor ef) {
    if (ef.getType() != null) {
        this.isContinuous = ef.getType().equals(FactorType.CONTINUOUS);
    } else {
        for (FactorValue fv : ef.getFactorValues()) {
            if (fv.getMeasurement() != null) {
                try {
                    Double.parseDouble(fv.getMeasurement().getValue());
                    this.isContinuous = true;
                } catch (NumberFormatException e) {
                    this.isContinuous = false;
                    break;
                }
            }
        }
    }
}
Also used : FactorValue(ubic.gemma.model.expression.experiment.FactorValue)

Example 2 with FactorValue

use of ubic.gemma.model.expression.experiment.FactorValue in project Gemma by PavlidisLab.

the class SearchServiceImpl method filterCharacteristicOwnersByClass.

private Collection<SearchResult> filterCharacteristicOwnersByClass(Collection<Class<?>> classes, Map<Characteristic, Object> characteristic2entity) {
    Collection<BioMaterial> biomaterials = new HashSet<>();
    Collection<FactorValue> factorValues = new HashSet<>();
    Collection<SearchResult> results = new HashSet<>();
    for (Characteristic c : characteristic2entity.keySet()) {
        Object o = characteristic2entity.get(c);
        for (Class<?> clazz : classes) {
            if (clazz.isAssignableFrom(o.getClass())) {
                String matchedText = c.getValue();
                if (o instanceof BioMaterial) {
                    biomaterials.add((BioMaterial) o);
                } else if (o instanceof FactorValue) {
                    factorValues.add((FactorValue) o);
                } else {
                    if (c instanceof VocabCharacteristic && c.getValueUri() != null) {
                        matchedText = "Ontology term: <a href=\"" + Settings.getRootContext() + "/searcher.html?query=" + c.getValueUri() + "\">" + matchedText + "</a>";
                    }
                    results.add(new SearchResult(o, 1.0, matchedText));
                }
            }
        }
    }
    this.addEEeByFactorvalues(results, factorValues);
    if (biomaterials.size() > 0) {
        Collection<ExpressionExperiment> ees = expressionExperimentService.findByBioMaterials(biomaterials);
        for (ExpressionExperiment ee : ees) {
            results.add(new SearchResult(ee, SearchServiceImpl.INDIRECT_DB_HIT_PENALTY, "BioMaterial characteristic"));
        }
    }
    return results;
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) FactorValue(ubic.gemma.model.expression.experiment.FactorValue) 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) BibliographicReferenceValueObject(ubic.gemma.model.common.description.BibliographicReferenceValueObject) SearchSettingsValueObject(ubic.gemma.model.common.search.SearchSettingsValueObject) BioSequenceValueObject(ubic.gemma.model.genome.sequenceAnalysis.BioSequenceValueObject) GeneEvidenceValueObject(ubic.gemma.model.genome.gene.phenotype.valueObject.GeneEvidenceValueObject) CharacteristicValueObject(ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject)

Example 3 with FactorValue

use of ubic.gemma.model.expression.experiment.FactorValue in project Gemma by PavlidisLab.

the class SearchServiceImpl method characteristicExpressionExperimentSearch.

private Collection<SearchResult> characteristicExpressionExperimentSearch(final SearchSettings settings) {
    Collection<SearchResult> results = new HashSet<>();
    // this is a collection because of the API
    Collection<Class<?>> classToSearch = new ArrayList<>(1);
    // for characteristicService; could add
    // findByUri(Class<?>...)
    // order matters.
    Queue<Class<?>> orderedClassesToSearch = new LinkedList<>();
    orderedClassesToSearch.add(ExpressionExperiment.class);
    orderedClassesToSearch.add(FactorValue.class);
    orderedClassesToSearch.add(BioMaterial.class);
    orderedClassesToSearch.add(Treatment.class);
    Collection<SearchResult> characterSearchResults = new HashSet<>();
    while (characterSearchResults.size() < SearchServiceImpl.SUFFICIENT_EXPERIMENT_RESULTS_FROM_CHARACTERISTICS && !orderedClassesToSearch.isEmpty()) {
        classToSearch.clear();
        classToSearch.add(orderedClassesToSearch.poll());
        // We handle the OR clauses here.
        String[] subclauses = settings.getQuery().split(" OR ");
        for (String subclause : subclauses) {
            /*
                 * Note that the AND is applied only within one entity type. The fix would be to apply AND at this
                 * level.
                 */
            Collection<SearchResult> classResults = this.characteristicSearchWithChildren(classToSearch, subclause);
            if (!classResults.isEmpty()) {
                String msg = "Found " + classResults.size() + " " + classToSearch.iterator().next().getSimpleName() + " results from characteristic search.";
                if (characterSearchResults.size() >= SearchServiceImpl.SUFFICIENT_EXPERIMENT_RESULTS_FROM_CHARACTERISTICS) {
                    msg += " Total found > " + SearchServiceImpl.SUFFICIENT_EXPERIMENT_RESULTS_FROM_CHARACTERISTICS + ", will not search for more entities.";
                }
                SearchServiceImpl.log.info(msg);
            }
            characterSearchResults.addAll(classResults);
        }
    }
    StopWatch watch = new StopWatch();
    watch.start();
    // filter and get parents...
    int numEEs = 0;
    Collection<BioMaterial> biomaterials = new HashSet<>();
    Collection<FactorValue> factorValues = new HashSet<>();
    Collection<Treatment> treatments = new HashSet<>();
    for (SearchResult sr : characterSearchResults) {
        Class<?> resultClass = sr.getResultClass();
        // highlightedText.put( sr.getResultObject(), sr.getHighlightedText() );
        if (ExpressionExperiment.class.isAssignableFrom(resultClass)) {
            sr.setHighlightedText(sr.getHighlightedText() + " (characteristic)");
            results.add(sr);
            numEEs++;
        } else if (BioMaterial.class.isAssignableFrom(resultClass)) {
            biomaterials.add((BioMaterial) sr.getResultObject());
        } else if (FactorValue.class.isAssignableFrom(resultClass)) {
            factorValues.add((FactorValue) sr.getResultObject());
        } else if (Treatment.class.isAssignableFrom(resultClass)) {
            treatments.add((Treatment) sr.getResultObject());
        }
    }
    /*
         * Much faster to batch it...but we loose track of which search result came from which, so we put generic
         * highlighted text.
         */
    if (biomaterials.size() > 0) {
        Collection<ExpressionExperiment> ees = expressionExperimentService.findByBioMaterials(biomaterials);
        for (ExpressionExperiment ee : ees) {
            results.add(new SearchResult(ee, SearchServiceImpl.INDIRECT_DB_HIT_PENALTY, "BioMaterial characteristic"));
        }
    }
    this.addEEeByFactorvalues(results, factorValues);
    if (treatments.size() > 0) {
        SearchServiceImpl.log.info("Not processing treatments, but hits were found");
    }
    if (SearchServiceImpl.log.isDebugEnabled()) {
        SearchServiceImpl.log.debug("ExpressionExperiment search: " + settings + " -> " + results.size() + " characteristic hits");
    }
    if (watch.getTime() > 1000) {
        SearchServiceImpl.log.info("Retrieving " + results.size() + " experiments from " + characterSearchResults.size() + " retrieved characteristics took " + watch.getTime() + " ms");
        SearchServiceImpl.log.info("Breakdown: " + numEEs + " via direct association with EE; " + biomaterials.size() + " via association with Biomaterial; " + factorValues.size() + " via experimental design");
    }
    return results;
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) FactorValue(ubic.gemma.model.expression.experiment.FactorValue) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) StopWatch(org.apache.commons.lang3.time.StopWatch) Treatment(ubic.gemma.model.expression.biomaterial.Treatment)

Example 4 with FactorValue

use of ubic.gemma.model.expression.experiment.FactorValue in project Gemma by PavlidisLab.

the class AncovaTest method testAncovaTriLevel.

/*
     * Two fixed-level parameters, one of which has three levels
     */
@Test
public void testAncovaTriLevel() {
    this.configureMocks();
    /*
         * Add a factor with three levels (same one used in onewayanovaanalyzertest)
         */
    ExperimentalFactor experimentalFactorC = ExperimentalFactor.Factory.newInstance();
    experimentalFactorC.setName("threeLevFactor");
    experimentalFactorC.setId(5003L);
    experimentalFactorC.setType(FactorType.CATEGORICAL);
    expressionExperiment.getExperimentalDesign().getExperimentalFactors().add(experimentalFactorC);
    FactorValue fcbase = null;
    for (int i = 1; i <= 3; i++) {
        FactorValue factorValueC = FactorValue.Factory.newInstance();
        factorValueC.setId(2000L + i);
        if (i == 3) {
            factorValueC.setValue("control_group");
            fcbase = factorValueC;
        } else {
            factorValueC.setValue(i + "_group");
        }
        factorValueC.setExperimentalFactor(experimentalFactorC);
        experimentalFactorC.getFactorValues().add(factorValueC);
    }
    List<FactorValue> facV = new ArrayList<>(experimentalFactorC.getFactorValues());
    for (int i = 0; i < 8; i++) {
        super.biomaterials.get(i).getFactorValues().add(facV.get(i % 3));
    }
    List<ExperimentalFactor> factors = new ArrayList<>();
    factors.add(experimentalFactorA_Area);
    factors.add(experimentalFactorC);
    DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
    config.setFactorsToInclude(factors);
    Collection<DifferentialExpressionAnalysis> expressionAnalyses = analyzer.run(expressionExperiment, config);
    DifferentialExpressionAnalysis expressionAnalysis = expressionAnalyses.iterator().next();
    assertNotNull(expressionAnalysis);
    Collection<ExpressionAnalysisResultSet> resultSets = expressionAnalysis.getResultSets();
    assertEquals(2, resultSets.size());
    boolean found14 = false;
    boolean found198 = false;
    boolean found3 = false;
    boolean found4 = false;
    for (ExpressionAnalysisResultSet resultSet : resultSets) {
        assertEquals(1, resultSet.getExperimentalFactors().size());
        log.info(resultSet.getBaselineGroup());
        assertTrue(resultSet.getBaselineGroup().equals(factorValueA2) || resultSet.getBaselineGroup().equals(fcbase));
        ExperimentalFactor f = resultSet.getExperimentalFactors().iterator().next();
        for (DifferentialExpressionAnalysisResult r : resultSet.getResults()) {
            CompositeSequence probe = r.getProbe();
            Double pvalue = r.getPvalue();
            if (f.equals(super.experimentalFactorA_Area)) {
                if (probe.getName().equals("probe_98")) {
                    assertEquals(0.8060, pvalue, 0.001);
                    found198 = true;
                }
            } else if (probe.getName().equals("probe_10")) {
                assertEquals(0.9088, pvalue, 0.001);
                found3 = true;
            }
            Collection<ContrastResult> contrasts = r.getContrasts();
            Double stat;
            if (contrasts.isEmpty()) {
                continue;
            }
            stat = contrasts.iterator().next().getTstat();
            assertNotNull(probe);
            if (stat == null)
                continue;
            if (f.equals(super.experimentalFactorA_Area)) {
                if (probe.getName().equals("probe_10")) {
                    assertEquals(9.215e-09, pvalue, 1e-11);
                    assertEquals(-152.812, stat, 0.001);
                } else if (probe.getName().equals("probe_4")) {
                    assertEquals(0.006278, pvalue, 0.0001);
                    assertEquals(-95.118, stat, 0.001);
                    found14 = true;
                }
            } else {
                if (contrasts.size() == 2) {
                    found4 = true;
                }
                if (probe.getName().equals("probe_98")) {
                    assertEquals(0.2171, pvalue, 0.001);
                }
            }
        }
    }
    assertTrue("Didn't find results", found14 && found198 && found3);
    assertTrue("Didn't find the right number of contrasts", found4);
}
Also used : FactorValue(ubic.gemma.model.expression.experiment.FactorValue) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) ArrayList(java.util.ArrayList) DifferentialExpressionAnalysis(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis) DifferentialExpressionAnalysisResult(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysisResult) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) ExpressionAnalysisResultSet(ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet) ContrastResult(ubic.gemma.model.analysis.expression.diff.ContrastResult) Test(org.junit.Test)

Example 5 with FactorValue

use of ubic.gemma.model.expression.experiment.FactorValue in project Gemma by PavlidisLab.

the class AncovaTest method setupFactorValues.

private void setupFactorValues(ExperimentalFactor experimentalFactorC) {
    for (int i = 1; i <= 8; i++) {
        FactorValue factorValueC = FactorValue.Factory.newInstance();
        factorValueC.setId(2000L + i);
        factorValueC.setMeasurement(Measurement.Factory.newInstance(MeasurementType.ABSOLUTE, "" + i, PrimitiveType.DOUBLE));
        factorValueC.setExperimentalFactor(experimentalFactorC);
        assert !biomaterials.get(i - 1).getFactorValues().contains(factorValueC);
        super.biomaterials.get(i - 1).getFactorValues().add(factorValueC);
        experimentalFactorC.getFactorValues().add(factorValueC);
    }
}
Also used : FactorValue(ubic.gemma.model.expression.experiment.FactorValue)

Aggregations

FactorValue (ubic.gemma.model.expression.experiment.FactorValue)55 ExperimentalFactor (ubic.gemma.model.expression.experiment.ExperimentalFactor)30 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)27 Test (org.junit.Test)12 VocabCharacteristic (ubic.gemma.model.common.description.VocabCharacteristic)8 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)8 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)8 HashSet (java.util.HashSet)7 Characteristic (ubic.gemma.model.common.description.Characteristic)6 DifferentialExpressionAnalysis (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis)5 ArrayList (java.util.ArrayList)4 AbstractGeoServiceTest (ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest)4 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)4 FactorValueValueObject (ubic.gemma.model.expression.experiment.FactorValueValueObject)4 StopWatch (org.apache.commons.lang3.time.StopWatch)3 DifferentialExpressionAnalysisResult (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysisResult)3 ExpressionAnalysisResultSet (ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet)3 AnnotationValueObject (ubic.gemma.model.common.description.AnnotationValueObject)3 Measurement (ubic.gemma.model.common.measurement.Measurement)3 BioAssaySet (ubic.gemma.model.expression.experiment.BioAssaySet)3