use of ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject in project Gemma by PavlidisLab.
the class OntologyServiceImpl method findExperimentsCharacteristicTags.
/**
* Using the ontology and values in the database, for a search searchQuery given by the client give an ordered list
* of possible choices
*/
@Override
public Collection<CharacteristicValueObject> findExperimentsCharacteristicTags(String searchQueryString, boolean useNeuroCartaOntology) {
String searchQuery = OntologySearch.stripInvalidCharacters(searchQueryString);
if (searchQuery.length() < 3) {
return new HashSet<>();
}
// this will do like %search%
Collection<CharacteristicValueObject> characteristicsFromDatabase = CharacteristicValueObject.characteristic2CharacteristicVO(this.characteristicService.findByValue("%" + searchQuery));
Map<String, CharacteristicValueObject> characteristicFromDatabaseWithValueUri = new HashMap<>();
Collection<CharacteristicValueObject> characteristicFromDatabaseFreeText = new HashSet<>();
for (CharacteristicValueObject characteristicInDatabase : characteristicsFromDatabase) {
// flag to let know that it was found in the database
characteristicInDatabase.setAlreadyPresentInDatabase(true);
if (characteristicInDatabase.getValueUri() != null && !characteristicInDatabase.getValueUri().equals("")) {
characteristicFromDatabaseWithValueUri.put(characteristicInDatabase.getValueUri(), characteristicInDatabase);
} else {
// free txt, no value uri
characteristicFromDatabaseFreeText.add(characteristicInDatabase);
}
}
// search the ontology for the given searchTerm, but if already found in the database dont add it again
Collection<CharacteristicValueObject> characteristicsFromOntology = this.findCharacteristicsFromOntology(searchQuery, useNeuroCartaOntology, characteristicFromDatabaseWithValueUri);
// order to show the the term: 1-exactMatch, 2-startWith, 3-substring and 4- no rule
// order to show values for each List : 1-From database with Uri, 2- from Ontology, 3- from from database with
// no Uri
Collection<CharacteristicValueObject> characteristicsWithExactMatch = new ArrayList<>();
Collection<CharacteristicValueObject> characteristicsStartWithQuery = new ArrayList<>();
Collection<CharacteristicValueObject> characteristicsSubstring = new ArrayList<>();
Collection<CharacteristicValueObject> characteristicsNoRuleFound = new ArrayList<>();
// from the database with a uri
this.putCharacteristicsIntoSpecificList(searchQuery, characteristicFromDatabaseWithValueUri.values(), characteristicsWithExactMatch, characteristicsStartWithQuery, characteristicsSubstring, characteristicsNoRuleFound);
// from the ontology
this.putCharacteristicsIntoSpecificList(searchQuery, characteristicsFromOntology, characteristicsWithExactMatch, characteristicsStartWithQuery, characteristicsSubstring, characteristicsNoRuleFound);
// from the database with no uri
this.putCharacteristicsIntoSpecificList(searchQuery, characteristicFromDatabaseFreeText, characteristicsWithExactMatch, characteristicsStartWithQuery, characteristicsSubstring, characteristicsNoRuleFound);
List<CharacteristicValueObject> allCharacteristicsFound = new ArrayList<>();
allCharacteristicsFound.addAll(characteristicsWithExactMatch);
allCharacteristicsFound.addAll(characteristicsStartWithQuery);
allCharacteristicsFound.addAll(characteristicsSubstring);
allCharacteristicsFound.addAll(characteristicsNoRuleFound);
// limit the size of the returned phenotypes to 100 terms
if (allCharacteristicsFound.size() > 100) {
return allCharacteristicsFound.subList(0, 100);
}
return allCharacteristicsFound;
}
use of ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject in project Gemma by PavlidisLab.
the class OntologyServiceTest method test.
@Test
public void test() {
os.getDiseaseOntologyService().loadTermsInNameSpace(this.getClass().getResourceAsStream("/data/loader/ontology/dotest.owl.xml"));
Collection<CharacteristicValueObject> name = os.findTermsInexact("diarrhea", null);
assertTrue(name.size() > 0);
OntologyTerm t1 = os.getTerm("http://purl.obolibrary.org/obo/DOID_0050001");
assertNotNull(t1);
// Actinomadura madurae infectious disease
assertTrue(os.isObsolete("http://purl.obolibrary.org/obo/DOID_0050001"));
// inflammatory diarrhea, not obsolete as of May 2012.
assertNotNull(os.getTerm("http://purl.obolibrary.org/obo/DOID_0050132"));
assertTrue(!os.isObsolete("http://purl.obolibrary.org/obo/DOID_0050132"));
}
use of ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject in project Gemma by PavlidisLab.
the class PhenotypeAssoOntologyHelperImpl method ontology2CharacteristicValueObject.
/**
* Ontology term to CharacteristicValueObject
*
* @return collection of the input, converted to 'shell' CharacteristicValueObjects (which have other slots we want
* to use)
*/
private Set<CharacteristicValueObject> ontology2CharacteristicValueObject(Collection<OntologyTerm> ontologyTerms) {
Set<CharacteristicValueObject> characteristicsVO = new HashSet<>();
for (OntologyTerm ontologyTerm : ontologyTerms) {
CharacteristicValueObject phenotype = new CharacteristicValueObject(-1L, ontologyTerm.getLabel().toLowerCase(), ontologyTerm.getUri());
characteristicsVO.add(phenotype);
}
return characteristicsVO;
}
use of ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject in project Gemma by PavlidisLab.
the class GeneralSearchControllerImpl method fillValueObjects.
@SuppressWarnings("unchecked")
private void fillValueObjects(Class<?> entityClass, List<SearchResult> results, SearchSettings settings) {
StopWatch timer = new StopWatch();
timer.start();
Collection<?> vos;
if (ExpressionExperiment.class.isAssignableFrom(entityClass)) {
vos = this.filterEE(expressionExperimentService.loadValueObjects(EntityUtils.getIds(results), false), settings);
if (!SecurityUtil.isUserAdmin()) {
auditableUtil.removeTroubledEes((Collection<ExpressionExperimentValueObject>) vos);
}
} else if (ArrayDesign.class.isAssignableFrom(entityClass)) {
vos = this.filterAD(arrayDesignService.loadValueObjectsByIds(EntityUtils.getIds(results)), settings);
if (!SecurityUtil.isUserAdmin()) {
auditableUtil.removeTroubledArrayDesigns((Collection<ArrayDesignValueObject>) vos);
}
} else if (CompositeSequence.class.isAssignableFrom(entityClass)) {
Collection<CompositeSequenceValueObject> css = new ArrayList<>();
for (SearchResult sr : results) {
CompositeSequenceValueObject csvo = compositeSequenceService.loadValueObject((CompositeSequence) sr.getResultObject());
css.add(csvo);
}
vos = css;
} else if (BibliographicReference.class.isAssignableFrom(entityClass)) {
Collection<BibliographicReference> bss = bibliographicReferenceService.load(EntityUtils.getIds(results));
bss = bibliographicReferenceService.thaw(bss);
vos = bibliographicReferenceService.loadValueObjects(bss);
} else if (Gene.class.isAssignableFrom(entityClass)) {
Collection<Gene> genes = geneService.load(EntityUtils.getIds(results));
genes = geneService.thawLite(genes);
vos = geneService.loadValueObjects(genes);
} else if (Characteristic.class.isAssignableFrom(entityClass)) {
Collection<CharacteristicValueObject> cvos = new ArrayList<>();
for (SearchResult sr : results) {
Characteristic ch = (Characteristic) sr.getResultObject();
cvos.add(new CharacteristicValueObject(ch));
}
vos = cvos;
} else if (CharacteristicValueObject.class.isAssignableFrom(entityClass)) {
Collection<CharacteristicValueObject> cvos = new ArrayList<>();
for (SearchResult sr : results) {
CharacteristicValueObject ch = (CharacteristicValueObject) sr.getResultObject();
cvos.add(ch);
}
vos = cvos;
} else if (BioSequenceValueObject.class.isAssignableFrom(entityClass)) {
return;
} else if (GeneSet.class.isAssignableFrom(entityClass)) {
vos = geneSetService.getValueObjects(EntityUtils.getIds(results));
} else if (ExpressionExperimentSet.class.isAssignableFrom(entityClass)) {
vos = experimentSetService.loadValueObjects(experimentSetService.load(EntityUtils.getIds(results)));
} else if (FactorValue.class.isAssignableFrom(entityClass)) {
Collection<FactorValueValueObject> fvo = new ArrayList<>();
for (SearchResult sr : results) {
fvo.add(new FactorValueValueObject((FactorValue) sr.getResultObject()));
}
vos = fvo;
} else {
throw new UnsupportedOperationException("Don't know how to make value objects for class=" + entityClass);
}
if (vos == null || vos.isEmpty()) {
// it causing front end errors, if vos is empty make sure to get rid of all search results
for (Iterator<SearchResult> it = results.iterator(); it.hasNext(); ) {
it.next();
it.remove();
}
return;
}
// retained objects...
Map<Long, Object> idMap = EntityUtils.getIdMap(vos);
for (Iterator<SearchResult> it = results.iterator(); it.hasNext(); ) {
SearchResult sr = it.next();
if (!idMap.containsKey(sr.getId())) {
it.remove();
continue;
}
sr.setResultObject(idMap.get(sr.getId()));
}
if (timer.getTime() > 1000) {
BaseFormController.log.info("Value object conversion after search: " + timer.getTime() + "ms");
}
}
use of ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject in project Gemma by PavlidisLab.
the class PhenotypeAssociationDaoImpl method findEvidenceCategoryTerms.
/**
* find category terms currently used in the database by evidence
*/
@Override
public Collection<CharacteristicValueObject> findEvidenceCategoryTerms() {
Collection<CharacteristicValueObject> mgedCategory = new TreeSet<>();
String queryString = "SELECT DISTINCT CATEGORY_URI, category FROM PHENOTYPE_ASSOCIATION " + "JOIN INVESTIGATION ON PHENOTYPE_ASSOCIATION.EXPERIMENT_FK = INVESTIGATION.ID " + "JOIN CHARACTERISTIC ON CHARACTERISTIC.INVESTIGATION_FK= INVESTIGATION.ID";
org.hibernate.SQLQuery queryObject = this.getSessionFactory().getCurrentSession().createSQLQuery(queryString);
ScrollableResults results = queryObject.scroll(ScrollMode.FORWARD_ONLY);
while (results.next()) {
CharacteristicValueObject characteristicValueObject = new CharacteristicValueObject(-1L);
characteristicValueObject.setCategoryUri((String) results.get(0));
characteristicValueObject.setCategory((String) results.get(1));
mgedCategory.add(characteristicValueObject);
}
results.close();
return mgedCategory;
}
Aggregations