Search in sources :

Example 1 with GeneEvidenceValueObject

use of ubic.gemma.model.genome.gene.phenotype.valueObject.GeneEvidenceValueObject in project Gemma by PavlidisLab.

the class PhenotypeAssociationDaoImpl method populateGenesWithPhenotypes.

/**
 * @param queryObject execute sqlQuery and populate phenotypesGenesAssociations is : phenotype --> genes
 * @return collection
 */
private Collection<GeneEvidenceValueObject> populateGenesWithPhenotypes(SQLQuery queryObject) {
    StopWatch sw = new StopWatch();
    sw.start();
    // we accumulate the phenotypes for a gene in one VO
    Map<Long, GeneEvidenceValueObject> genesWithPhenotypes = new HashMap<>();
    ScrollableResults results = queryObject.scroll(ScrollMode.FORWARD_ONLY);
    while (results.next()) {
        /* 0: gene id 1: ncbi id 2: name 3: symbol 4: taxon id 5: taxon name 6: characteristic value URI */
        Long geneId = ((BigInteger) results.get(0)).longValue();
        Integer nbciGeneId = (Integer) results.get(1);
        String officialName = (String) results.get(2);
        String officialSymbol = (String) results.get(3);
        Long taxonId = ((BigInteger) results.get(4)).longValue();
        String taxonCommonName = (String) results.get(5);
        String valueUri = (String) results.get(6);
        if (genesWithPhenotypes.get(geneId) != null) {
            genesWithPhenotypes.get(geneId).getPhenotypesValueUri().add(valueUri);
        } else {
            GeneEvidenceValueObject g = new GeneEvidenceValueObject(geneId);
            g.setNcbiId(nbciGeneId);
            g.setOfficialName(officialName);
            g.setOfficialSymbol(officialSymbol);
            g.setTaxonCommonName(taxonCommonName);
            g.setTaxonId(taxonId);
            g.getPhenotypesValueUri().add(valueUri);
            genesWithPhenotypes.put(geneId, g);
        }
    }
    results.close();
    if (sw.getTime() > 500) {
        PhenotypeAssociationDaoImpl.log.info("Get " + genesWithPhenotypes.size() + " genes with phenotypes: " + sw.getTime() + "ms");
    }
    return genesWithPhenotypes.values();
}
Also used : BigInteger(java.math.BigInteger) GeneEvidenceValueObject(ubic.gemma.model.genome.gene.phenotype.valueObject.GeneEvidenceValueObject) BigInteger(java.math.BigInteger) StopWatch(org.apache.commons.lang3.time.StopWatch)

Example 2 with GeneEvidenceValueObject

use of ubic.gemma.model.genome.gene.phenotype.valueObject.GeneEvidenceValueObject 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

StopWatch (org.apache.commons.lang3.time.StopWatch)2 GeneEvidenceValueObject (ubic.gemma.model.genome.gene.phenotype.valueObject.GeneEvidenceValueObject)2 BigInteger (java.math.BigInteger)1 Gene (ubic.gemma.model.genome.Gene)1 CharacteristicValueObject (ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject)1