use of ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject in project Gemma by PavlidisLab.
the class GeneServiceImpl method loadFullyPopulatedValueObject.
@Override
@Transactional(readOnly = true)
public GeneValueObject loadFullyPopulatedValueObject(Long id) {
Gene gene = this.geneDao.load(id);
if (gene == null) {
return null;
}
gene = this.geneDao.thaw(gene);
GeneValueObject gvo = GeneValueObject.convert2ValueObject(gene);
Collection<GeneAlias> aliasObjects = gene.getAliases();
Collection<String> aliasStrings = new ArrayList<>();
for (GeneAlias ga : aliasObjects) {
aliasStrings.add(ga.getAlias());
}
gvo.setAliases(aliasStrings);
if (gene.getMultifunctionality() != null) {
gvo.setMultifunctionalityRank(gene.getMultifunctionality().getRank());
}
Long compositeSequenceCount = this.getCompositeSequenceCountById(id);
gvo.setCompositeSequenceCount(compositeSequenceCount.intValue());
Integer platformCount = this.geneDao.getPlatformCountById(id);
gvo.setPlatformCount(platformCount);
Collection<GeneSet> geneSets = this.geneSetSearch.findByGene(gene);
Collection<GeneSetValueObject> gsVos = new ArrayList<>();
// noinspection CollectionAddAllCanBeReplacedWithConstructor // Constructor can't handle subclasses
gsVos.addAll(geneSetValueObjectHelper.convertToLightValueObjects(geneSets, false));
gvo.setGeneSets(gsVos);
Collection<Gene> geneHomologues = this.homologeneService.getHomologues(gene);
geneHomologues = this.thawLite(geneHomologues);
Collection<GeneValueObject> homologues = this.loadValueObjects(geneHomologues);
gvo.setHomologues(homologues);
Collection<PhenotypeAssociation> pas = gene.getPhenotypeAssociations();
Collection<CharacteristicValueObject> cVos = new HashSet<>();
for (PhenotypeAssociation pa : pas) {
cVos.addAll(CharacteristicValueObject.characteristic2CharacteristicVO(pa.getPhenotypes()));
}
gvo.setPhenotypes(cVos);
if (gvo.getNcbiId() != null) {
SearchSettingsImpl s = new SearchSettingsImpl();
s.setTermUri("http://purl.org/commons/record/ncbi_gene/" + gvo.getNcbiId());
s.noSearches();
s.setSearchExperiments(true);
Map<Class<?>, List<SearchResult>> r = searchService.search(s);
if (r.containsKey(ExpressionExperiment.class)) {
List<SearchResult> hits = r.get(ExpressionExperiment.class);
gvo.setAssociatedExperimentCount(hits.size());
}
}
GeneCoexpressionNodeDegreeValueObject nodeDegree = coexpressionService.getNodeDegree(gene);
if (nodeDegree != null) {
gvo.setNodeDegreesPos(nodeDegree.asIntArrayPos());
gvo.setNodeDegreesNeg(nodeDegree.asIntArrayNeg());
gvo.setNodeDegreePosRanks(nodeDegree.asDoubleArrayPosRanks());
gvo.setNodeDegreeNegRanks(nodeDegree.asDoubleArrayNegRanks());
}
return gvo;
}
use of ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject in project Gemma by PavlidisLab.
the class CharacteristicSortTest method testSortCharacteristics.
@Test
public final void testSortCharacteristics() {
// does not use spring context
List<CharacteristicValueObject> cl = new ArrayList<>();
cl.add(new CharacteristicValueObject(Characteristic.Factory.newInstance("g", "gggg", null, "gggg_", "g", null, null)));
cl.add(new CharacteristicValueObject(Characteristic.Factory.newInstance("xused", "x", null, "xused", "x", null, null)));
// will be first
CharacteristicValueObject a = new CharacteristicValueObject(Characteristic.Factory.newInstance("a", "a", null, "aused", "a", null, null));
a.setNumTimesUsed(3);
a.setAlreadyPresentInDatabase(true);
cl.add(a);
CharacteristicValueObject vo = new CharacteristicValueObject(VocabCharacteristic.Factory.newInstance("b", "bbbb", null, "bbbbb", "http://bbbb", "b", null, null));
vo.setNumTimesUsed(5);
vo.setAlreadyPresentInDatabase(true);
cl.add(vo);
cl.add(new CharacteristicValueObject(VocabCharacteristic.Factory.newInstance("a", "aaaa", null, "aaaa_", "http://aaaa_", "a", null, null)));
cl.add(new CharacteristicValueObject(VocabCharacteristic.Factory.newInstance("d", "dddd", null, "dddd_", "http://dddd_", "d", null, null)));
cl.add(new CharacteristicValueObject(VocabCharacteristic.Factory.newInstance("af", "aaaf", null, "aaaff", "http://aaaff", "af", null, null)));
ontologyService.sort(cl);
assertEquals("bbbbb", cl.get(0).getValue());
// assertEquals( "x", cl.get( 2 ).getValue() );
// assertEquals( "aaaa", cl.get( 3 ).getValue() );
// assertEquals( "aaaf", cl.get( 4 ).getValue() );
//
// assertEquals( "d", cl.get( 5 ).getValue() );
// assertEquals( "gggg", cl.get( 6 ).getValue() );
}
use of ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject in project Gemma by PavlidisLab.
the class OntologyServiceImpl method searchForGenes.
/**
* Look for genes, but only for certain category Uris (genotype, etc.)
*
* @param taxon okay if null, but then all matches returned.
* @param searchResults added to this
*/
private void searchForGenes(String queryString, Taxon taxon, Collection<CharacteristicValueObject> searchResults) {
SearchSettings ss = SearchSettings.Factory.newInstance();
ss.setQuery(queryString);
ss.noSearches();
ss.setTaxon(taxon);
ss.setSearchGenes(true);
Map<Class<?>, List<SearchResult>> geneResults = this.searchService.search(ss, true, false);
if (geneResults.containsKey(Gene.class)) {
for (SearchResult sr : geneResults.get(Gene.class)) {
Gene g = (Gene) sr.getResultObject();
if (OntologyServiceImpl.log.isDebugEnabled())
OntologyServiceImpl.log.debug("Search for " + queryString + " returned: " + g);
searchResults.add(new CharacteristicValueObject(this.gene2Characteristic(g)));
}
}
}
use of ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject in project Gemma by PavlidisLab.
the class OntologyServiceImpl method findTermsInexact.
@Override
public Collection<CharacteristicValueObject> findTermsInexact(String givenQueryString, Taxon taxon) {
if (StringUtils.isBlank(givenQueryString))
return null;
StopWatch watch = new StopWatch();
watch.start();
String queryString = OntologySearch.stripInvalidCharacters(givenQueryString);
if (StringUtils.isBlank(queryString)) {
OntologyServiceImpl.log.warn("The query was not valid (ended up being empty): " + givenQueryString);
return new HashSet<>();
}
if (OntologyServiceImpl.log.isDebugEnabled()) {
OntologyServiceImpl.log.debug("starting findExactTerm for " + queryString + ". Timing information begins from here");
}
Collection<? extends OntologyResource> results;
Collection<CharacteristicValueObject> searchResults = new HashSet<>();
Map<String, CharacteristicValueObject> previouslyUsedInSystem = new HashMap<>();
this.countOccurrences(queryString, previouslyUsedInSystem);
this.searchForGenes(queryString, taxon, searchResults);
for (AbstractOntologyService service : this.ontologyServices) {
if (!service.isOntologyLoaded())
continue;
results = service.findResources(queryString);
if (results.isEmpty())
continue;
if (OntologyServiceImpl.log.isDebugEnabled())
OntologyServiceImpl.log.debug("found " + results.size() + " from " + service.getClass().getSimpleName() + " in " + watch.getTime() + " ms");
searchResults.addAll(CharacteristicValueObject.characteristic2CharacteristicVO(this.termsToCharacteristics(results)));
if (searchResults.size() > OntologyServiceImpl.MAX_TERMS_TO_FETCH) {
break;
}
}
this.countOccurrences(searchResults, previouslyUsedInSystem);
// get GO terms, if we don't already have a lot of possibilities. (might have to adjust this)
if (searchResults.size() < OntologyServiceImpl.MAX_TERMS_TO_FETCH && geneOntologyService.isReady()) {
searchResults.addAll(CharacteristicValueObject.characteristic2CharacteristicVO(this.termsToCharacteristics(geneOntologyService.findTerm(queryString))));
}
// Sort the results rather elaborately.
Collection<CharacteristicValueObject> sortedResults = this.sort(previouslyUsedInSystem, searchResults, queryString);
if (watch.getTime() > 1000) {
OntologyServiceImpl.log.info("Ontology term query for: " + givenQueryString + ": " + watch.getTime() + "ms");
}
return sortedResults;
}
use of ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject in project Gemma by PavlidisLab.
the class SearchServiceImpl method geneSearch.
/**
* Combines compass style search, the db style search, and the compositeSequence search and returns 1 combined list
* with no duplicates.
*
* @param returnOnDbHit if true and if there is a match for a gene from the database, return immediately - much
* faster
*/
private Collection<SearchResult> geneSearch(final SearchSettings settings, boolean returnOnDbHit) {
StopWatch watch = this.startTiming();
String searchString = settings.getQuery();
Collection<SearchResult> geneDbList = this.databaseGeneSearch(settings);
if (returnOnDbHit && geneDbList.size() > 0) {
return geneDbList;
}
Set<SearchResult> combinedGeneList = new HashSet<>(geneDbList);
Collection<SearchResult> geneCompassList = this.compassGeneSearch(settings);
combinedGeneList.addAll(geneCompassList);
if (combinedGeneList.isEmpty()) {
Collection<SearchResult> geneCsList = this.databaseCompositeSequenceSearch(settings);
for (SearchResult res : geneCsList) {
if (res.getResultClass().isAssignableFrom(Gene.class))
combinedGeneList.add(res);
}
}
/*
* Possibly search for genes linked via a phenotype, but only if we don't have anything here.
*
*/
if (combinedGeneList.isEmpty()) {
Collection<CharacteristicValueObject> phenotypeTermHits = this.phenotypeAssociationManagerService.searchInDatabaseForPhenotype(settings.getQuery());
for (CharacteristicValueObject phenotype : phenotypeTermHits) {
Set<String> phenotypeUris = new HashSet<>();
phenotypeUris.add(phenotype.getValueUri());
// DATABASE HIT!
Collection<GeneEvidenceValueObject> phenotypeGenes = phenotypeAssociationManagerService.findCandidateGenes(phenotypeUris, settings.getTaxon());
if (!phenotypeGenes.isEmpty()) {
SearchServiceImpl.log.info(phenotypeGenes.size() + " genes associated with " + phenotype + " (via query='" + settings.getQuery() + "')");
for (GeneEvidenceValueObject gvo : phenotypeGenes) {
Gene g = Gene.Factory.newInstance();
g.setId(gvo.getId());
g.setTaxon(settings.getTaxon());
SearchResult sr = new SearchResult(g);
sr.setHighlightedText(phenotype.getValue() + " (" + phenotype.getValueUri() + ")");
// if ( gvo.getScore() != null ) {
// TODO If we get evidence quality, use that in the score.
// }
// maybe lower, if we do this search when combinedGeneList is nonempty.
sr.setScore(1.0);
combinedGeneList.add(sr);
}
if (combinedGeneList.size() > 100) /* some limit */
{
break;
}
}
}
}
if (watch.getTime() > 1000)
SearchServiceImpl.log.info("Gene search for " + searchString + " took " + watch.getTime() + " ms; " + combinedGeneList.size() + " results.");
return combinedGeneList;
}
Aggregations