use of ubic.gemma.model.common.description.VocabCharacteristic in project Gemma by PavlidisLab.
the class OntologyServiceImpl method convert.
/**
* Given a collection of ontology terms converts them to a collection of VocabCharacteristics
*/
private Collection<VocabCharacteristic> convert(final Collection<OntologyResource> resources) {
Collection<VocabCharacteristic> converted = new HashSet<>();
if ((resources == null) || (resources.isEmpty()))
return converted;
for (OntologyResource res : resources) {
VocabCharacteristic vc = VocabCharacteristic.Factory.newInstance();
// If there is no URI we don't want to send it back (ie useless)
if ((res.getUri() == null) || StringUtils.isEmpty(res.getUri()))
continue;
if (res instanceof OntologyTerm) {
OntologyTerm term = (OntologyTerm) res;
vc.setValue(term.getTerm());
vc.setValueUri(term.getUri());
vc.setDescription(term.getComment());
}
if (res instanceof OntologyIndividual) {
OntologyIndividual indi = (OntologyIndividual) res;
vc.setValue(indi.getLabel());
vc.setValueUri(indi.getUri());
vc.setDescription("Individual");
}
converted.add(vc);
}
return converted;
}
use of ubic.gemma.model.common.description.VocabCharacteristic in project Gemma by PavlidisLab.
the class GeneOntologyServiceImpl method getGOTerms.
@Override
public Collection<OntologyTerm> getGOTerms(Gene gene, boolean includePartOf, GOAspect goAspect) {
Collection<OntologyTerm> cachedTerms = goTerms.get(gene);
if (GeneOntologyServiceImpl.log.isTraceEnabled() && cachedTerms != null) {
this.logIds("found cached GO terms for " + gene.getOfficialSymbol(), goTerms.get(gene));
}
if (cachedTerms == null) {
Collection<OntologyTerm> allGOTermSet = new HashSet<>();
Collection<VocabCharacteristic> annotations = gene2GOAssociationService.findByGene(gene);
for (VocabCharacteristic c : annotations) {
if (!GeneOntologyServiceImpl.uri2Term.containsKey(c.getValueUri())) {
GeneOntologyServiceImpl.log.warn("Term " + c.getValueUri() + " not found in term list cant add to results");
continue;
}
allGOTermSet.add(GeneOntologyServiceImpl.uri2Term.get(c.getValueUri()));
}
allGOTermSet.addAll(this.getAllParents(allGOTermSet, includePartOf));
cachedTerms = Collections.unmodifiableCollection(allGOTermSet);
if (GeneOntologyServiceImpl.log.isTraceEnabled())
this.logIds("caching GO terms for " + gene.getOfficialSymbol(), allGOTermSet);
goTerms.put(gene, cachedTerms);
}
if (goAspect != null) {
Collection<OntologyTerm> finalTerms = new HashSet<>();
for (OntologyTerm ontologyTerm : cachedTerms) {
GOAspect term = this.getTermAspect(ontologyTerm);
if (term != null && term.equals(goAspect)) {
finalTerms.add(ontologyTerm);
}
}
return finalTerms;
}
return cachedTerms;
}
use of ubic.gemma.model.common.description.VocabCharacteristic in project Gemma by PavlidisLab.
the class GeneDifferentialExpressionServiceImpl method configExperimentalFactorValueObject.
@Override
public ExperimentalFactorValueObject configExperimentalFactorValueObject(ExperimentalFactor ef) {
ExperimentalFactorValueObject efvo = new ExperimentalFactorValueObject(ef.getId());
efvo.setName(ef.getName());
efvo.setDescription(ef.getDescription());
Characteristic category = ef.getCategory();
if (category != null) {
efvo.setCategory(category.getCategory());
if (category instanceof VocabCharacteristic) {
efvo.setCategoryUri(category.getCategoryUri());
}
}
Collection<FactorValue> fvs = ef.getFactorValues();
StringBuilder factorValuesAsString = new StringBuilder(StringUtils.EMPTY);
for (FactorValue fv : fvs) {
String fvName = fv.toString();
if (StringUtils.isNotBlank(fvName)) {
factorValuesAsString.append(fvName).append(GeneDifferentialExpressionServiceImpl.FV_SEP);
}
}
/* clean up the start and end of the string */
factorValuesAsString = new StringBuilder(StringUtils.remove(factorValuesAsString.toString(), ef.getName() + ":"));
factorValuesAsString = new StringBuilder(StringUtils.removeEnd(factorValuesAsString.toString(), GeneDifferentialExpressionServiceImpl.FV_SEP));
/*
* Preformat the factor name; due to Ext PropertyGrid limitations we can't do this on the client.
*/
efvo.setName(ef.getName() + " (" + StringUtils.abbreviate(factorValuesAsString.toString(), 50) + ")");
efvo.setFactorValues(factorValuesAsString.toString());
return efvo;
}
use of ubic.gemma.model.common.description.VocabCharacteristic in project Gemma by PavlidisLab.
the class PhenotypeAssoOntologyHelperImpl method valueUri2Characteristic.
@Override
public Characteristic valueUri2Characteristic(String valueUri) {
try {
OntologyTerm o = findOntologyTermByUri(valueUri);
if (o == null)
return null;
VocabCharacteristic myPhenotype = VocabCharacteristic.Factory.newInstance();
myPhenotype.setValueUri(o.getUri());
myPhenotype.setValue(o.getLabel());
myPhenotype.setCategory(PhenotypeAssociationConstants.PHENOTYPE);
myPhenotype.setCategoryUri(PhenotypeAssociationConstants.PHENOTYPE_CATEGORY_URI);
return myPhenotype;
} catch (EntityNotFoundException e) {
e.printStackTrace();
return null;
}
}
use of ubic.gemma.model.common.description.VocabCharacteristic in project Gemma by PavlidisLab.
the class GeneSetServiceTest method testFindByGoId.
@Test
public void testFindByGoId() {
VocabCharacteristic oe = VocabCharacteristic.Factory.newInstance();
oe.setValueUri(GeneOntologyService.BASE_GO_URI + GeneSetServiceTest.GOTERM_INDB);
oe.setValue(GeneSetServiceTest.GOTERM_INDB);
Gene2GOAssociation g2Go1 = Gene2GOAssociation.Factory.newInstance(g, oe, GOEvidenceCode.EXP);
gene2GoService.create(g2Go1);
oe = VocabCharacteristic.Factory.newInstance();
oe.setValueUri(GeneOntologyService.BASE_GO_URI + GeneSetServiceTest.GOTERM_INDB);
oe.setValue(GeneSetServiceTest.GOTERM_INDB);
Gene2GOAssociation g2Go2 = Gene2GOAssociation.Factory.newInstance(g3, oe, GOEvidenceCode.EXP);
gene2GoService.create(g2Go2);
GeneSet gset = this.geneSetSearch.findByGoId(GeneSetServiceTest.GOTERM_QUERY, g3.getTaxon());
assertEquals(2, gset.getMembers().size());
}
Aggregations