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();
}
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;
}
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;
}
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;
}
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;
}
Aggregations