use of ubic.gemma.model.common.description.VocabCharacteristic 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.common.description.VocabCharacteristic in project Gemma by PavlidisLab.
the class GoMetric method getOntologyTerms.
/**
* @param gene gene
* @return direct GO annotation terms
*/
private Collection<OntologyTerm> getOntologyTerms(Gene gene) {
Collection<VocabCharacteristic> termsVoc = gene2GOAssociationService.findByGene(gene);
HashSet<OntologyTerm> termsGO = new HashSet<>();
for (VocabCharacteristic characteristic : termsVoc) {
OntologyTerm term = GeneOntologyServiceImpl.getTermForId(characteristic.getValue());
if ((term != null))
termsGO.add(term);
}
return termsGO;
}
use of ubic.gemma.model.common.description.VocabCharacteristic in project Gemma by PavlidisLab.
the class OntologyServiceImpl method gene2Characteristic.
/**
* Allow us to store gene information as a characteristic associated with our entities. This doesn't work so well
* for non-ncbi genes.
*/
private Characteristic gene2Characteristic(Gene g) {
VocabCharacteristic vc = VocabCharacteristic.Factory.newInstance();
vc.setCategory("gene");
vc.setCategoryUri("http://purl.org/commons/hcls/gene");
vc.setValue(g.getOfficialSymbol() + " [" + g.getTaxon().getCommonName() + "]" + " " + g.getOfficialName());
vc.setDescription(g.toString());
if (g.getNcbiGeneId() != null) {
vc.setValueUri("http://purl.org/commons/record/ncbi_gene/" + g.getNcbiGeneId());
}
return vc;
}
use of ubic.gemma.model.common.description.VocabCharacteristic in project Gemma by PavlidisLab.
the class DatabaseViewGeneratorImpl method generateDifferentialExpressionView.
private void generateDifferentialExpressionView(Integer limit, Collection<ExpressionExperiment> experiments) throws IOException {
DatabaseViewGeneratorImpl.log.info("Generating dataset diffex view");
/*
* Get handle to output file
*/
File file = this.getViewFile(DatabaseViewGeneratorImpl.DATASET_DIFFEX_VIEW_BASENAME);
DatabaseViewGeneratorImpl.log.info("Writing to " + file);
try (Writer writer = new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(file)))) {
/*
* For each gene that is differentially expressed, print out a line per contrast
*/
writer.write("GemmaDsId\tEEShortName\tGeneNCBIId\tGemmaGeneId\tFactor\tFactorURI\tBaseline\tContrasting\tDirection\n");
int i = 0;
for (ExpressionExperiment ee : experiments) {
ee = expressionExperimentService.thawLite(ee);
Collection<DifferentialExpressionAnalysis> results = differentialExpressionAnalysisService.getAnalyses(ee);
if (results == null || results.isEmpty()) {
DatabaseViewGeneratorImpl.log.warn("No differential expression results found for " + ee);
continue;
}
// noinspection StatementWithEmptyBody // FIXME. Should probably skip for this purpose.
if (results.size() > 1) {
}
DatabaseViewGeneratorImpl.log.info("Processing: " + ee.getShortName());
for (DifferentialExpressionAnalysis analysis : results) {
analysis = this.differentialExpressionAnalysisService.thawFully(analysis);
for (ExpressionAnalysisResultSet ears : analysis.getResultSets()) {
// ears = differentialExpressionResultService.thawRawAndProcessed( ears );
FactorValue baselineGroup = ears.getBaselineGroup();
if (baselineGroup == null) {
// log.warn( "No baseline defined for " + ee ); // interaction
continue;
}
if (ExperimentalDesignUtils.isBatch(baselineGroup.getExperimentalFactor())) {
continue;
}
String baselineDescription = ExperimentalDesignUtils.prettyString(baselineGroup);
// Get the factor category name
StringBuilder factorName = new StringBuilder();
StringBuilder factorURI = new StringBuilder();
for (ExperimentalFactor ef : ears.getExperimentalFactors()) {
factorName.append(ef.getName()).append(",");
if (ef.getCategory() instanceof VocabCharacteristic) {
factorURI.append(ef.getCategory().getCategoryUri()).append(",");
}
}
factorName = new StringBuilder(StringUtils.removeEnd(factorName.toString(), ","));
factorURI = new StringBuilder(StringUtils.removeEnd(factorURI.toString(), ","));
if (ears.getResults() == null || ears.getResults().isEmpty()) {
DatabaseViewGeneratorImpl.log.warn("No differential expression analysis results found for " + ee);
continue;
}
// Generate probe details
for (DifferentialExpressionAnalysisResult dear : ears.getResults()) {
if (dear == null) {
DatabaseViewGeneratorImpl.log.warn("Missing results for " + ee + " skipping to next. ");
continue;
}
if (dear.getCorrectedPvalue() == null || dear.getCorrectedPvalue() > DatabaseViewGeneratorImpl.THRESH_HOLD)
continue;
String formatted = this.formatDiffExResult(ee, dear, factorName.toString(), factorURI.toString(), baselineDescription);
if (StringUtils.isNotBlank(formatted))
writer.write(formatted);
}
// dear loop
}
// ears loop
}
if (limit != null && (limit > 0 && ++i > limit))
break;
}
// EE loop
}
}
use of ubic.gemma.model.common.description.VocabCharacteristic in project Gemma by PavlidisLab.
the class ExperimentalDesignImporterTest method assertFv.
static void assertFv(FactorValue fv) {
if (fv.getCharacteristics().size() > 0) {
VocabCharacteristic c = (VocabCharacteristic) fv.getCharacteristics().iterator().next();
assertNotNull(c.getValue());
assertNotNull(c.getCategoryUri());
} else {
assertNotNull(fv.getValue() + " should have a measurement or a characteristic", fv.getMeasurement());
}
}
Aggregations