use of ubic.gemma.model.expression.biomaterial.Treatment 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.Treatment in project Gemma by PavlidisLab.
the class AuditAdviceTest method checkEEAuditTrails.
private void checkEEAuditTrails(ExpressionExperiment ee, Collection<Long> trailIds, Collection<Long> eventIds) {
this.checkAuditTrail(ee, trailIds, eventIds);
for (BioAssay ba : ee.getBioAssays()) {
this.checkAuditTrail(ba, trailIds, eventIds);
BioMaterial bm = ba.getSampleUsed();
this.checkAuditTrail(bm, trailIds, eventIds);
for (Characteristic c : bm.getCharacteristics()) {
this.checkAuditTrail(c, trailIds, eventIds);
}
for (Treatment t : bm.getTreatments()) {
this.checkAuditTrail(t, trailIds, eventIds);
this.checkAuditTrail(t.getAction(), trailIds, eventIds);
// for ( CompoundMeasurement cm : t.getCompoundMeasurements() ) {
// checkAuditTrail( cm.getCompound().getCompoundIndices(), trailIds, eventIds );
// }
}
}
Collection<ExperimentalFactor> experimentalFactors = ee.getExperimentalDesign().getExperimentalFactors();
assertTrue(experimentalFactors.size() > 0);
for (ExperimentalFactor ef : experimentalFactors) {
this.checkAuditTrail(ef, trailIds, eventIds);
for (FactorValue fv : ef.getFactorValues()) {
for (Characteristic c : fv.getCharacteristics()) {
this.checkAuditTrail(c, trailIds, eventIds);
}
}
}
}
use of ubic.gemma.model.expression.biomaterial.Treatment in project Gemma by PavlidisLab.
the class GeoConverterImpl method convertChannel.
/**
* GEO does not keep track of 'biomaterials' that make up different channels. Therefore the two channels effectively
* make up a single biomaterial, as far as we're concerned. We're losing information here.
*
* @param sample sample
* @param channel channel
* @param bioMaterial BA
*/
private void convertChannel(GeoSample sample, GeoChannel channel, BioMaterial bioMaterial) {
if (bioMaterial == null)
return;
GeoConverterImpl.log.debug("Sample: " + sample.getGeoAccession() + " - Converting channel " + channel.getSourceName());
bioMaterial.setDescription((bioMaterial.getDescription() == null ? "" : bioMaterial.getDescription() + ";") + "Channel " + channel.getChannelNumber());
if (!StringUtils.isBlank(channel.getGrowthProtocol())) {
Treatment treatment = Treatment.Factory.newInstance();
treatment.setName(sample.getGeoAccession() + " channel " + channel.getChannelNumber() + " treatment");
treatment.setDescription(channel.getGrowthProtocol());
bioMaterial.getTreatments().add(treatment);
}
if (!StringUtils.isBlank(channel.getTreatmentProtocol())) {
Treatment treatment = Treatment.Factory.newInstance();
treatment.setName(sample.getGeoAccession() + " channel " + channel.getChannelNumber() + " growth");
treatment.setDescription(channel.getTreatmentProtocol());
bioMaterial.getTreatments().add(treatment);
}
if (!StringUtils.isBlank(channel.getExtractProtocol())) {
Treatment treatment = Treatment.Factory.newInstance();
treatment.setName(sample.getGeoAccession() + " channel " + channel.getChannelNumber() + " extraction");
treatment.setDescription(channel.getExtractProtocol());
bioMaterial.getTreatments().add(treatment);
}
if (!StringUtils.isBlank(channel.getLabelProtocol())) {
Treatment treatment = Treatment.Factory.newInstance();
treatment.setName(sample.getGeoAccession() + " channel " + channel.getChannelNumber() + " labeling");
treatment.setDescription(channel.getLabelProtocol());
bioMaterial.getTreatments().add(treatment);
}
for (String characteristic : channel.getCharacteristics()) {
characteristic = this.trimString(characteristic);
/*
* Sometimes values are like Age:8 weeks, so we can try to convert them.
*/
String[] fields = characteristic.split(":");
String defaultDescription = "GEO Sample characteristic";
if (fields.length == 2) {
String category = fields[0].trim();
String value = fields[1].trim();
try {
Characteristic gemmaChar = Characteristic.Factory.newInstance();
this.convertVariableType(gemmaChar, GeoVariable.convertStringToType(category));
if (gemmaChar.getCategory() == null) {
continue;
}
gemmaChar.setDescription(defaultDescription);
gemmaChar.setValue(value);
gemmaChar.setEvidenceCode(GOEvidenceCode.IIA);
bioMaterial.getCharacteristics().add(gemmaChar);
} catch (Exception e) {
// conversion didn't work, fall back.
this.doFallback(bioMaterial, characteristic, defaultDescription);
}
} else {
// no colon, just use raw (same as fallback above)
this.doFallback(bioMaterial, characteristic, defaultDescription);
}
}
if (StringUtils.isNotBlank(channel.getSourceName())) {
Characteristic sourceChar = Characteristic.Factory.newInstance();
sourceChar.setDescription("GEO Sample source");
String characteristic = this.trimString(channel.getSourceName());
sourceChar.setCategory("BioSource");
sourceChar.setCategoryUri("http://www.ebi.ac.uk/efo/EFO_0000635");
sourceChar.setValue(characteristic);
sourceChar.setEvidenceCode(GOEvidenceCode.IIA);
bioMaterial.getCharacteristics().add(sourceChar);
}
if (StringUtils.isNotBlank(channel.getOrganism())) {
// if we have a case where the two channels have different taxon throw an exception.
String currentChannelTaxon = channel.getOrganism();
if (bioMaterial.getSourceTaxon() != null) {
String previousChannelTaxon = bioMaterial.getSourceTaxon().getScientificName();
if (previousChannelTaxon != null && !(previousChannelTaxon.equals(currentChannelTaxon))) {
throw new IllegalArgumentException("Channel 1 taxon is " + bioMaterial.getSourceTaxon().getScientificName() + " Channel 2 taxon is " + currentChannelTaxon + " Check that is expected for sample " + sample.getGeoAccession());
}
} else {
// get it from the channel.
Taxon taxon = Taxon.Factory.newInstance();
taxon.setIsSpecies(true);
taxon.setScientificName(channel.getOrganism());
// plausible default, doesn't matter.
taxon.setIsGenesUsable(true);
bioMaterial.setSourceTaxon(taxon);
}
}
if (channel.getMolecule() != null) {
// this we can convert automatically pretty easily.
Characteristic c = channel.getMoleculeAsCharacteristic();
bioMaterial.getCharacteristics().add(c);
}
if (StringUtils.isNotBlank(channel.getLabel())) {
String characteristic = this.trimString(channel.getLabel());
// This is typically something like "biotin-labeled nucleotides", which we can convert later.
Characteristic labelChar = Characteristic.Factory.newInstance();
labelChar.setDescription("GEO Sample label");
labelChar.setCategory("LabelCompound");
labelChar.setCategoryUri("http://www.ebi.ac.uk/efo/EFO_0000562");
labelChar.setValue(characteristic);
labelChar.setEvidenceCode(GOEvidenceCode.IIA);
bioMaterial.getCharacteristics().add(labelChar);
}
}
use of ubic.gemma.model.expression.biomaterial.Treatment in project Gemma by PavlidisLab.
the class ExpressionPersister method persistBioMaterial.
private BioMaterial persistBioMaterial(BioMaterial entity) {
if (entity == null)
return null;
AbstractPersister.log.debug("Persisting " + entity);
if (!this.isTransient(entity))
return entity;
assert entity.getSourceTaxon() != null;
AbstractPersister.log.debug("Persisting " + entity);
this.fillInDatabaseEntry(entity.getExternalAccession());
AbstractPersister.log.debug("db entry done");
entity.setSourceTaxon(this.persistTaxon(entity.getSourceTaxon()));
AbstractPersister.log.debug("taxon done");
for (Treatment treatment : entity.getTreatments()) {
Characteristic action = treatment.getAction();
AbstractPersister.log.debug(treatment + " action: " + action);
AbstractPersister.log.debug("treatment done");
}
AbstractPersister.log.debug("start save");
BioMaterial bm = bioMaterialDao.findOrCreate(entity);
AbstractPersister.log.debug("save biomaterial done");
return bm;
}
Aggregations