Search in sources :

Example 1 with BioMaterial

use of ubic.gemma.model.expression.biomaterial.BioMaterial in project Gemma by PavlidisLab.

the class CuratableValueObjectTest method setUp.

@Before
public void setUp() throws Exception {
    arrayDesign = ArrayDesign.Factory.newInstance();
    arrayDesign.setName("testing audit " + RandomStringUtils.randomAlphanumeric(32));
    arrayDesign.setShortName(RandomStringUtils.randomAlphanumeric(8));
    arrayDesign.setPrimaryTaxon(this.getTaxon("human"));
    arrayDesign = (ArrayDesign) this.persisterHelper.persist(arrayDesign);
    assertTrue(arrayDesign.getAuditTrail() != null);
    Taxon taxon = Taxon.Factory.newInstance("text taxon scientific name " + RandomStringUtils.randomAlphanumeric(8), RandomStringUtils.randomAlphanumeric(8), "ttxn", 0, false, true);
    this.persisterHelper.persist(taxon);
    BioMaterial bm = BioMaterial.Factory.newInstance();
    bm.setName(RandomStringUtils.randomAlphanumeric(8));
    bm.setSourceTaxon(taxon);
    this.persisterHelper.persist(bm);
    BioAssay bioAssay = BioAssay.Factory.newInstance();
    bioAssay.setArrayDesignUsed(arrayDesign);
    bioAssay.setSampleUsed(bm);
    this.persisterHelper.persist(bioAssay);
    ExperimentalDesign ed = ExperimentalDesign.Factory.newInstance();
    ed.setName(RandomStringUtils.randomAlphanumeric(8));
    expressionExperiment = super.getTestPersistentBasicExpressionExperiment();
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) ExperimentalDesign(ubic.gemma.model.expression.experiment.ExperimentalDesign) Taxon(ubic.gemma.model.genome.Taxon) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay) Before(org.junit.Before)

Example 2 with BioMaterial

use of ubic.gemma.model.expression.biomaterial.BioMaterial 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 BioMaterial

use of ubic.gemma.model.expression.biomaterial.BioMaterial 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 BioMaterial

use of ubic.gemma.model.expression.biomaterial.BioMaterial in project Gemma by PavlidisLab.

the class PersistentDummyObjectHelper method getBioAssays.

private List<BioAssay> getBioAssays(Collection<BioMaterial> bioMaterials, ArrayDesign ad) {
    List<BioAssay> baCol = new ArrayList<>();
    for (BioMaterial bm : bioMaterials) {
        BioAssay ba = this.getTestNonPersistentBioAssay(ad, bm);
        bm.getBioAssaysUsedIn().add(ba);
        baCol.add(ba);
    }
    return baCol;
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Example 5 with BioMaterial

use of ubic.gemma.model.expression.biomaterial.BioMaterial in project Gemma by PavlidisLab.

the class PersistentDummyObjectHelper method getTestExpressionExperimentWithAllDependencies.

public ExpressionExperiment getTestExpressionExperimentWithAllDependencies(ExpressionExperiment prototype) {
    ExpressionExperiment ee = ExpressionExperiment.Factory.newInstance();
    ee.setShortName(RandomStringUtils.randomNumeric(PersistentDummyObjectHelper.RANDOM_STRING_LENGTH));
    ee.setName("Expression Experiment " + RandomStringUtils.randomNumeric(PersistentDummyObjectHelper.RANDOM_STRING_LENGTH));
    ee.setDescription("A test expression experiment");
    ee.setSource("https://www.ncbi.nlm.nih.gov/geo/");
    DatabaseEntry de1 = this.getTestPersistentDatabaseEntry(PersistentDummyObjectHelper.geo);
    ee.setAccession(de1);
    LocalFile file = LocalFile.Factory.newInstance();
    try {
        file.setLocalURL(new URL("file:///just/a/placeholder/" + ee.getShortName()));
    } catch (MalformedURLException e) {
        log.error("Malformed URL");
    }
    ee.setRawDataFile(file);
    Collection<FactorValue> allFactorValues = new HashSet<>();
    ExperimentalDesign ed = this.getExperimentalDesign(allFactorValues);
    Collection<BioMaterial> bioMaterials = this.getBioMaterials(allFactorValues);
    ee.setExperimentalDesign(ed);
    ee.setOwner(this.getTestPersistentContact());
    List<ArrayDesign> arrayDesignsUsed = new ArrayList<>(eeService.getArrayDesignsUsed(prototype));
    Collection<BioAssay> bioAssays = new HashSet<>();
    Collection<QuantitationType> quantitationTypes = this.addQuantitationTypes(new HashSet<QuantitationType>());
    eeService.thaw(prototype);
    Collection<RawExpressionDataVector> vectors = new HashSet<>();
    for (ArrayDesign ad : arrayDesignsUsed) {
        List<BioAssay> bas = this.getBioAssays(bioMaterials, ad);
        bioAssays.addAll(bas);
        ad = this.adService.thaw(ad);
        vectors.addAll(this.getDesignElementDataVectors(ee, quantitationTypes, bas, ad));
    }
    ee.setBioAssays(bioAssays);
    assert quantitationTypes.size() > 0;
    ee.setQuantitationTypes(quantitationTypes);
    ee.setRawExpressionDataVectors(vectors);
    ArrayDesignsForExperimentCache c = persisterHelper.prepare(ee);
    ee = persisterHelper.persist(ee, c);
    return ee;
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) MalformedURLException(java.net.MalformedURLException) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) ArrayDesignsForExperimentCache(ubic.gemma.persistence.util.ArrayDesignsForExperimentCache) URL(java.net.URL) RawExpressionDataVector(ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Aggregations

BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)132 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)67 FactorValue (ubic.gemma.model.expression.experiment.FactorValue)27 ExperimentalFactor (ubic.gemma.model.expression.experiment.ExperimentalFactor)22 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)19 BioAssayDimension (ubic.gemma.model.expression.bioAssayData.BioAssayDimension)15 HashSet (java.util.HashSet)13 Test (org.junit.Test)13 ExpressionDataDoubleMatrix (ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix)12 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)12 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)10 InputStream (java.io.InputStream)7 DenseDoubleMatrix (ubic.basecode.dataStructure.matrix.DenseDoubleMatrix)7 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)7 QuantitationType (ubic.gemma.model.common.quantitationtype.QuantitationType)7 Characteristic (ubic.gemma.model.common.description.Characteristic)6 RawExpressionDataVector (ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector)6 DoubleArrayList (cern.colt.list.DoubleArrayList)5 DoubleMatrix1D (cern.colt.matrix.DoubleMatrix1D)5 ArrayList (java.util.ArrayList)5