Search in sources :

Example 66 with Taxon

use of ubic.gemma.model.genome.Taxon in project Gemma by PavlidisLab.

the class AbstractCLIContextCLI method setTaxonByName.

protected Taxon setTaxonByName(TaxonService taxonService) {
    String taxonName = this.getOptionValue('t');
    ubic.gemma.model.genome.Taxon taxon = taxonService.findByCommonName(taxonName);
    if (taxon == null) {
        AbstractCLI.log.error("ERROR: Cannot find taxon " + taxonName);
    }
    return taxon;
}
Also used : Taxon(ubic.gemma.model.genome.Taxon)

Example 67 with Taxon

use of ubic.gemma.model.genome.Taxon in project Gemma by PavlidisLab.

the class AffyPowerToolsProbesetSummarize method getCommand.

/**
 * For exon arrays. Like
 * <pre>
 * apt-probeset-summarize -a rma -p HuEx-1_0-st-v2.r2.pgf -c HuEx-1_0-st-v2.r2.clf -m
 * HuEx-1_0-st-v2.r2.dt1.hg18.core.mps -qc-probesets HuEx-1_0-st-v2.r2.qcc -o GSE13344.genelevel.data
 * /bigscratch/GSE13344/*.CEL
 * </pre>
 * http://media.affymetrix.com/support/developer/powertools/changelog/apt-probeset-summarize.html
 * http://bib.oxfordjournals.org/content/early/2011/04/15/bib.bbq086.full
 *
 * @param ad         ad
 * @param celfiles   celfiles
 * @param outputPath directory
 * @return string
 */
private String getCommand(ArrayDesign ad, List<String> celfiles, String outputPath) {
    /*
         * Get the pgf, clf, mps file for this platform. qc probesets: optional.
         */
    String toolPath = Settings.getString("affy.power.tools.exec");
    String refPath = Settings.getString("affy.power.tools.ref.path");
    this.checkFileReadable(toolPath);
    if (!new File(refPath).isDirectory()) {
        throw new IllegalStateException(refPath + " is not a valid directory");
    }
    Taxon primaryTaxon = ad.getPrimaryTaxon();
    String base;
    String genome;
    switch(primaryTaxon.getCommonName()) {
        case "human":
            base = AffyPowerToolsProbesetSummarize.h;
            genome = AffyPowerToolsProbesetSummarize.hg;
            break;
        case "mouse":
            base = AffyPowerToolsProbesetSummarize.m;
            genome = AffyPowerToolsProbesetSummarize.mm;
            break;
        case "rat":
            base = AffyPowerToolsProbesetSummarize.r;
            genome = AffyPowerToolsProbesetSummarize.rn;
            break;
        default:
            throw new IllegalArgumentException("Cannot use " + primaryTaxon);
    }
    String pgf = refPath + File.separator + base + ".pgf";
    String clf = refPath + File.separator + base + ".clf";
    String mps = refPath + File.separator + base + ".dt1." + genome + ".core.mps";
    String qcc = refPath + File.separator + base + ".qcc";
    this.checkFileReadable(pgf);
    this.checkFileReadable(clf);
    this.checkFileReadable(mps);
    this.checkFileReadable(qcc);
    return toolPath + " -a " + AffyPowerToolsProbesetSummarize.METHOD + " -p " + pgf + " -c " + clf + " -m " + mps + " -o " + outputPath + " --qc-probesets " + qcc + " " + StringUtils.join(celfiles, " ");
}
Also used : Taxon(ubic.gemma.model.genome.Taxon) LocalFile(ubic.gemma.model.common.description.LocalFile)

Example 68 with Taxon

use of ubic.gemma.model.genome.Taxon in project Gemma by PavlidisLab.

the class GeneSearchServiceImpl method searchMultipleGenesGetMap.

@Override
public Map<String, GeneValueObject> searchMultipleGenesGetMap(Collection<String> query, Long taxonId) {
    Taxon taxon = taxonService.load(taxonId);
    if (taxon == null)
        throw new IllegalArgumentException("No such taxon with id=" + taxonId);
    // this deals with the simple cases. For remainder we look a little harder
    Map<String, GeneValueObject> queryToGenes = geneService.findByOfficialSymbols(query, taxonId);
    for (String line : query) {
        line = StringUtils.strip(line);
        if (StringUtils.isBlank(line)) {
            continue;
        }
        String queryAsKey = line.toLowerCase();
        if (queryToGenes.containsKey(queryAsKey)) {
            // already found.
            continue;
        }
        if (queryToGenes.size() >= GeneSearchServiceImpl.MAX_GENES_PER_QUERY) {
            GeneSearchServiceImpl.log.warn("Too many genes, stopping (limit=" + GeneSearchServiceImpl.MAX_GENES_PER_QUERY + ')');
            break;
        }
        // searching one gene at a time is a bit slow; we do a quick search for symbols.
        SearchSettings settings = SearchSettingsImpl.geneSearch(line, taxon);
        List<SearchResult> geneSearchResults = searchService.speedSearch(settings).get(Gene.class);
        if (geneSearchResults == null || geneSearchResults.isEmpty()) {
            // an empty set is an indication of no results.
            queryToGenes.put(queryAsKey, null);
        } else if (geneSearchResults.size() == 1) {
            // Just one result so add it
            Gene g = (Gene) geneSearchResults.iterator().next().getResultObject();
            queryToGenes.put(queryAsKey, new GeneValueObject(g));
        } else {
            // like grin1, grin2, grin3, grin (given the search term was grin)
            for (SearchResult sr : geneSearchResults) {
                Gene srGene = (Gene) sr.getResultObject();
                if (srGene.getTaxon().equals(taxon) && srGene.getOfficialSymbol().equalsIgnoreCase(line)) {
                    queryToGenes.put(queryAsKey, new GeneValueObject(srGene));
                    // found so done
                    break;
                }
            }
        }
    }
    return queryToGenes;
}
Also used : Gene(ubic.gemma.model.genome.Gene) Taxon(ubic.gemma.model.genome.Taxon) SearchSettings(ubic.gemma.model.common.search.SearchSettings) SearchResult(ubic.gemma.core.search.SearchResult)

Example 69 with Taxon

use of ubic.gemma.model.genome.Taxon in project Gemma by PavlidisLab.

the class GeneSearchServiceImpl method searchGenesAndGeneGroups.

@Override
public Collection<SearchResultDisplayObject> searchGenesAndGeneGroups(String query, Long taxonId) {
    Taxon taxon = null;
    String taxonName = "";
    if (taxonId != null) {
        taxon = taxonService.load(taxonId);
        if (taxon == null) {
            GeneSearchServiceImpl.log.warn("No such taxon with id=" + taxonId);
        } else {
            taxonName = taxon.getCommonName();
        }
    }
    List<SearchResultDisplayObject> displayResults = new ArrayList<>();
    // session-bound sets
    if (StringUtils.isBlank(query)) {
        return this.searchGenesAndGeneGroupsBlankQuery(taxonId);
    }
    Integer maxGeneralSearchResults = 500;
    /*
         * GET GENES AND GENE SETS
         */
    // SearchSettings settings = SearchSettings.geneSearch( query, taxon );
    SearchSettings settings = SearchSettings.Factory.newInstance();
    settings.setQuery(query);
    settings.noSearches();
    // add searching for genes
    settings.setSearchGenes(true);
    // add searching for geneSets
    settings.setSearchGeneSets(true);
    settings.setMaxResults(maxGeneralSearchResults);
    if (taxon != null)
        // this doesn't work yet
        settings.setTaxon(taxon);
    GeneSearchServiceImpl.log.debug("getting results from searchService for " + query);
    Map<Class<?>, List<SearchResult>> results = searchService.speedSearch(settings);
    List<SearchResult> geneSetSearchResults = new ArrayList<>();
    List<SearchResult> geneSearchResults = new ArrayList<>();
    boolean exactGeneSymbolMatch = false;
    if (!results.isEmpty()) {
        if (results.get(GeneSet.class) != null) {
            geneSetSearchResults.addAll(results.get(GeneSet.class));
        }
        if (results.get(Gene.class) != null) {
            geneSearchResults.addAll(results.get(Gene.class));
        }
        // Check to see if we have an exact match, if so, return earlier abstaining from doing other searches
        for (SearchResult geneResult : results.get(Gene.class)) {
            Gene g = (Gene) geneResult.getResultObject();
            // aliases too?
            if (g != null && g.getOfficialSymbol() != null && g.getOfficialSymbol().startsWith(query.trim())) {
                exactGeneSymbolMatch = true;
                break;
            }
        }
    }
    Collection<SearchResultDisplayObject> genes = new ArrayList<>();
    Collection<SearchResultDisplayObject> geneSets;
    Map<Long, Boolean> isSetOwnedByUser = new HashMap<>();
    if (taxon != null) {
        // filter search results by taxon
        List<SearchResult> taxonCheckedGenes = this.retainGenesOfThisTaxon(taxonId, geneSearchResults);
        // convert result object to a value object to a SearchResultDisplayObject
        for (SearchResult sr : taxonCheckedGenes) {
            genes.add(new SearchResultDisplayObject(sr));
        }
        List<SearchResult> taxonCheckedSets = this.retainGeneSetsOfThisTaxon(taxonId, geneSetSearchResults, isSetOwnedByUser);
        // convert result object to a value object
        for (SearchResult sr : taxonCheckedSets) {
            GeneSet g = (GeneSet) sr.getResultObject();
            DatabaseBackedGeneSetValueObject gsVo = geneSetValueObjectHelper.convertToValueObject(g);
            sr.setResultObject(gsVo);
        }
        geneSets = SearchResultDisplayObject.convertSearchResults2SearchResultDisplayObjects(taxonCheckedSets);
        for (SearchResultDisplayObject srDo : geneSets) {
            // geneSets were filtered by taxon above:
            // if taxonId for geneSet != taxonId param, then gene set was already removed
            srDo.setTaxonId(taxonId);
            srDo.setTaxonName(taxonName);
        }
    } else {
        for (SearchResult sr : geneSearchResults) {
            genes.add(new SearchResultDisplayObject(sr));
        }
        geneSets = new ArrayList<>();
        SearchResultDisplayObject srDo;
        for (SearchResult sr : geneSetSearchResults) {
            GeneSet gs = (GeneSet) sr.getResultObject();
            isSetOwnedByUser.put(gs.getId(), securityService.isOwnedByCurrentUser(gs));
            taxon = geneSetService.getTaxon((GeneSet) sr.getResultObject());
            GeneSetValueObject gsVo = geneSetValueObjectHelper.convertToValueObject(gs);
            srDo = new SearchResultDisplayObject(gsVo);
            srDo.setTaxonId(taxon.getId());
            srDo.setTaxonName(taxon.getCommonName());
            geneSets.add(srDo);
        }
        taxon = null;
    }
    // if a geneSet is owned by the user, mark it as such (used for giving it a special background colour in
    // search results)
    this.setUserOwnedForGeneSets(geneSets, isSetOwnedByUser);
    if (exactGeneSymbolMatch) {
        // get summary results
        GeneSearchServiceImpl.log.info("getting Summary results for " + query);
        List<SearchResultDisplayObject> summaries = this.addEntryForAllResults(query, genes, geneSets, new ArrayList<SearchResultDisplayObject>(), new ArrayList<SearchResultDisplayObject>());
        displayResults.addAll(summaries);
        displayResults.addAll(genes);
        displayResults.addAll(geneSets);
        return displayResults;
    }
    List<SearchResultDisplayObject> srDos;
    // get GO group results
    GeneSearchServiceImpl.log.debug("Getting GO group results for " + query);
    srDos = this.getGOGroupResults(query, taxon);
    List<SearchResultDisplayObject> phenotypeSrDos = new ArrayList<>();
    if (!query.toUpperCase().startsWith("GO")) {
        GeneSearchServiceImpl.log.info("getting Phenotype Association results for " + query);
        phenotypeSrDos = this.getPhenotypeAssociationSearchResults(query, taxon);
    }
    // }
    // get summary results
    GeneSearchServiceImpl.log.debug("Getting Summary results for " + query);
    List<SearchResultDisplayObject> summaryEntries = this.addEntryForAllResults(query, genes, geneSets, srDos, phenotypeSrDos);
    // add all results, keeping order of result types
    displayResults.addAll(summaryEntries);
    displayResults.addAll(geneSets);
    displayResults.addAll(srDos);
    displayResults.addAll(phenotypeSrDos);
    displayResults.addAll(genes);
    if (displayResults.isEmpty()) {
        GeneSearchServiceImpl.log.info("No results for search: " + query + " taxon=" + ((taxon == null) ? null : taxon.getCommonName()));
        return new HashSet<>();
    }
    GeneSearchServiceImpl.log.info("Results for search: " + query + ", size=" + displayResults.size());
    return displayResults;
}
Also used : Gene(ubic.gemma.model.genome.Gene) SearchSettings(ubic.gemma.model.common.search.SearchSettings) Taxon(ubic.gemma.model.genome.Taxon) SearchResult(ubic.gemma.core.search.SearchResult) SearchResultDisplayObject(ubic.gemma.core.search.SearchResultDisplayObject)

Example 70 with Taxon

use of ubic.gemma.model.genome.Taxon in project Gemma by PavlidisLab.

the class GeneSearchServiceImpl method searchGenesAndGeneGroupsBlankQuery.

/**
 * if query is blank, return list of public sets, user-owned sets (if logged in) and user's recent session-bound
 * sets called by ubic.gemma.web.controller.genome.gene.GenePickerController.searchGenesAndGeneGroups(String, Long)
 *
 * @param taxonId taxon id
 * @return Collection<SearchResultDisplayObject>
 */
private Collection<SearchResultDisplayObject> searchGenesAndGeneGroupsBlankQuery(Long taxonId) {
    Taxon taxon = null;
    if (taxonId != null) {
        taxon = taxonService.load(taxonId);
        if (taxon == null) {
            GeneSearchServiceImpl.log.warn("No such taxon with id=" + taxonId);
        }
    }
    // if query is blank, return list of auto generated sets, user-owned sets (if logged in) and user's recent
    // session-bound sets
    // right now, no public gene sets are useful so we don't want to prompt them
    StopWatch watch = new StopWatch();
    watch.start();
    // get all public sets
    // filtered by security.
    Collection<GeneSet> sets = new ArrayList<>();
    if (!SecurityUtil.isUserLoggedIn()) {
        try {
            sets = geneSetService.loadAll(taxon);
            if (watch.getTime() > 100)
                GeneSearchServiceImpl.log.info(sets.size() + " sets loaded for taxon =" + taxon + " took: " + watch.getTime() + "ms");
        } catch (AccessDeniedException e) {
        // okay, they just aren't allowed to see those.
        }
    } else if (SecurityUtil.isUserLoggedIn()) {
        /*
             * actually, loadMyGeneSets and loadAll point to the same method (they just use different spring security
             * filters)
             */
        sets = (taxon != null) ? geneSetService.loadMyGeneSets(taxon) : geneSetService.loadMyGeneSets();
        if (watch.getTime() > 100)
            GeneSearchServiceImpl.log.info("Loading the user's gene sets took: " + watch.getTime() + "ms");
    }
    if (sets.isEmpty()) {
        return new ArrayList<>();
    }
    // separate these out because they go at the top of the list
    List<SearchResultDisplayObject> displayResultsPrivate = new ArrayList<>();
    List<SearchResultDisplayObject> displayResultsPublic = new ArrayList<>();
    SearchResultDisplayObject newSrDo;
    List<DatabaseBackedGeneSetValueObject> valueObjects = geneSetValueObjectHelper.convertToValueObjects(sets, false);
    if (watch.getTime() > 500)
        GeneSearchServiceImpl.log.info("Database stage done: " + watch.getTime() + "ms");
    for (DatabaseBackedGeneSetValueObject set : valueObjects) {
        newSrDo = new SearchResultDisplayObject(set);
        newSrDo.setTaxonId(((GeneSetValueObject) newSrDo.getResultValueObject()).getTaxonId());
        newSrDo.setTaxonName(((GeneSetValueObject) newSrDo.getResultValueObject()).getTaxonName());
        newSrDo.setUserOwned(!set.getIsPublic());
        ((GeneSetValueObject) newSrDo.getResultValueObject()).setIsPublic(!newSrDo.isUserOwned());
        if (newSrDo.isUserOwned()) {
            displayResultsPrivate.add(newSrDo);
        } else {
            displayResultsPublic.add(newSrDo);
        }
    }
    // keep sets in proper order (user's groups first, then public ones)
    Collections.sort(displayResultsPrivate);
    Collections.sort(displayResultsPublic);
    List<SearchResultDisplayObject> displayResults = new ArrayList<>();
    displayResults.addAll(displayResultsPrivate);
    displayResults.addAll(displayResultsPublic);
    GeneSearchServiceImpl.log.info("Results for blank query: " + displayResults.size() + " items, " + watch.getTime() + "ms");
    return displayResults;
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) Taxon(ubic.gemma.model.genome.Taxon) SearchResultDisplayObject(ubic.gemma.core.search.SearchResultDisplayObject) StopWatch(org.apache.commons.lang3.time.StopWatch)

Aggregations

Taxon (ubic.gemma.model.genome.Taxon)161 Gene (ubic.gemma.model.genome.Gene)34 Test (org.junit.Test)31 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)29 HashSet (java.util.HashSet)23 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)23 InputStream (java.io.InputStream)17 Before (org.junit.Before)16 BioSequence (ubic.gemma.model.genome.biosequence.BioSequence)15 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)14 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)12 StopWatch (org.apache.commons.lang3.time.StopWatch)11 Transactional (org.springframework.transaction.annotation.Transactional)11 ArrayList (java.util.ArrayList)10 File (java.io.File)9 SimpleExpressionExperimentMetaData (ubic.gemma.core.loader.expression.simple.model.SimpleExpressionExperimentMetaData)9 Chromosome (ubic.gemma.model.genome.Chromosome)8 Collection (java.util.Collection)7 Element (org.w3c.dom.Element)7 PhysicalLocation (ubic.gemma.model.genome.PhysicalLocation)7