Search in sources :

Example 11 with CharacteristicValueObject

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;
}
Also used : CharacteristicValueObject(ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject) Gene(ubic.gemma.model.genome.Gene) SearchSettingsImpl(ubic.gemma.model.common.search.SearchSettingsImpl) PhenotypeAssociation(ubic.gemma.model.association.phenotype.PhenotypeAssociation) SearchResult(ubic.gemma.core.search.SearchResult) GeneCoexpressionNodeDegreeValueObject(ubic.gemma.model.association.coexpression.GeneCoexpressionNodeDegreeValueObject) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with CharacteristicValueObject

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() );
}
Also used : CharacteristicValueObject(ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject) ArrayList(java.util.ArrayList) BaseSpringContextTest(ubic.gemma.core.testing.BaseSpringContextTest) Test(org.junit.Test)

Example 13 with CharacteristicValueObject

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)));
        }
    }
}
Also used : Gene(ubic.gemma.model.genome.Gene) CharacteristicValueObject(ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject) SearchSettings(ubic.gemma.model.common.search.SearchSettings) SearchResult(ubic.gemma.core.search.SearchResult)

Example 14 with CharacteristicValueObject

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;
}
Also used : CharacteristicValueObject(ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject) StopWatch(org.apache.commons.lang3.time.StopWatch) ConcurrentHashSet(org.compass.core.util.concurrent.ConcurrentHashSet)

Example 15 with CharacteristicValueObject

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;
}
Also used : Gene(ubic.gemma.model.genome.Gene) CharacteristicValueObject(ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject) GeneEvidenceValueObject(ubic.gemma.model.genome.gene.phenotype.valueObject.GeneEvidenceValueObject) StopWatch(org.apache.commons.lang3.time.StopWatch)

Aggregations

CharacteristicValueObject (ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject)17 StopWatch (org.apache.commons.lang3.time.StopWatch)6 ConcurrentHashSet (org.compass.core.util.concurrent.ConcurrentHashSet)5 Gene (ubic.gemma.model.genome.Gene)5 OntologyTerm (ubic.basecode.ontology.model.OntologyTerm)3 SearchResult (ubic.gemma.core.search.SearchResult)3 Characteristic (ubic.gemma.model.common.description.Characteristic)3 Test (org.junit.Test)2 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)2 ExpressionExperimentSet (ubic.gemma.model.analysis.expression.ExpressionExperimentSet)2 PhenotypeAssociation (ubic.gemma.model.association.phenotype.PhenotypeAssociation)2 VocabCharacteristic (ubic.gemma.model.common.description.VocabCharacteristic)2 SearchSettingsValueObject (ubic.gemma.model.common.search.SearchSettingsValueObject)2 GeneValueObject (ubic.gemma.model.genome.gene.GeneValueObject)2 GeneEvidenceValueObject (ubic.gemma.model.genome.gene.phenotype.valueObject.GeneEvidenceValueObject)2 BioSequenceValueObject (ubic.gemma.model.genome.sequenceAnalysis.BioSequenceValueObject)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1