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;
}
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, " ");
}
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;
}
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;
}
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;
}
Aggregations