use of ubic.gemma.model.genome.gene.GeneValueObject in project Gemma by PavlidisLab.
the class PhenotypeAssociationDaoImpl method findGenesForPhenotype.
@Override
public Map<GeneValueObject, OntologyTerm> findGenesForPhenotype(OntologyTerm term, Long taxon, boolean includeIEA) {
Collection<OntologyTerm> children = term.getChildren(false);
Map<String, OntologyTerm> uris = new HashMap<>();
uris.put(term.getUri(), term);
for (OntologyTerm c : children) {
uris.put(c.getUri(), c);
}
assert !uris.isEmpty();
Session sess = this.getSessionFactory().getCurrentSession();
String q = "select distinct ph.gene, p.valueUri, p.evidenceCode " + " from PhenotypeAssociation ph join ph.phenotypes p where p.valueUri in (:t)";
Query query = sess.createQuery(q);
Map<GeneValueObject, OntologyTerm> result = new HashMap<>();
query.setParameterList("t", uris.keySet());
List<?> list = query.list();
for (Object o : list) {
Object[] oa = (Object[]) o;
Gene g = (Gene) oa[0];
if (!taxon.equals(g.getTaxon().getId()))
continue;
String uri = (String) oa[1];
GOEvidenceCode ev = (GOEvidenceCode) oa[2];
if (!includeIEA && ev != null && ev.equals(GOEvidenceCode.IEA)) {
continue;
}
GeneValueObject gvo = new GeneValueObject(g);
OntologyTerm otForUri = uris.get(uri);
assert otForUri != null;
/*
* only clobber if this term is more specific
*/
if (result.containsKey(gvo) && otForUri.getParents(false).contains(otForUri)) {
continue;
}
result.put(gvo, otForUri);
}
return result;
}
use of ubic.gemma.model.genome.gene.GeneValueObject in project Gemma by PavlidisLab.
the class DEDVController method format4File.
/**
* Converts the given map into a tab delimited String
*/
private String format4File(Map<ExpressionExperimentValueObject, Map<Long, Collection<DoubleVectorValueObject>>> result) {
StringBuilder converted = new StringBuilder();
// Saves us from loading genes
Map<Long, GeneValueObject> genes = new HashMap<>();
// unnecessarily
converted.append("# Generated by Gemma\n# ").append(new Date()).append("\n");
converted.append(ExpressionDataFileService.DISCLAIMER + "#\n");
for (ExpressionExperimentValueObject ee : result.keySet()) {
boolean didHeaderForEe = false;
Collection<Long> geneIds = result.get(ee).keySet();
for (Long geneId : geneIds) {
GeneValueObject gene;
if (genes.containsKey(geneId)) {
gene = genes.get(geneId);
} else {
gene = geneService.loadValueObjectById(geneId);
genes.put(geneId, gene);
}
String geneName = gene.getOfficialSymbol();
Collection<DoubleVectorValueObject> vecs = result.get(ee).get(geneId);
for (DoubleVectorValueObject dedv : vecs) {
if (!didHeaderForEe) {
converted.append(makeHeader(dedv));
didHeaderForEe = true;
}
converted.append(geneName).append("\t").append(gene.getOfficialName()).append("\t");
converted.append(dedv.getDesignElement().getName()).append("\t");
if (dedv.getData() != null || dedv.getData().length != 0) {
for (double data : dedv.getData()) {
converted.append(String.format("%.3f", data)).append("\t");
}
// remove the trailing tab
converted.deleteCharAt(converted.length() - 1);
}
converted.append("\n");
}
}
converted.append("\n");
}
converted.append("\r\n");
return converted.toString();
}
use of ubic.gemma.model.genome.gene.GeneValueObject in project Gemma by PavlidisLab.
the class DEDVController method makeVisCollection.
/**
* Takes the DEDVs and put them in point objects and normalize the values. returns a map of eeid to visValueObject.
* Currently removes multiple hits for same gene. Tries to pick best DEDV.
*/
private VisualizationValueObject[] makeVisCollection(Collection<DoubleVectorValueObject> dedvs, Collection<Long> genes, Map<Long, Collection<Long>> validatedProbes, Map<Long, LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>>> layouts) {
Map<Long, List<DoubleVectorValueObject>> vvoMap = new HashMap<>();
// Organize by expression experiment
if (dedvs == null || dedvs.isEmpty())
return new VisualizationValueObject[1];
for (DoubleVectorValueObject dvvo : dedvs) {
// FIXME: we can probably use this information, and do away with carrying so much Layout information around?
// assert dvvo.isReorganized() && dvvo.getBioAssayDimension().isReordered(); // not always true!!
ExpressionExperimentValueObject ee = dvvo.getExpressionExperiment();
if (!vvoMap.containsKey(ee.getId())) {
vvoMap.put(ee.getId(), new ArrayList<DoubleVectorValueObject>());
}
vvoMap.get(ee.getId()).add(dvvo);
}
List<GeneValueObject> geneValueObjects;
if (genes == null || genes.isEmpty()) {
geneValueObjects = new ArrayList<>(getGeneValueObjectsUsed(dedvs).values());
} else {
geneValueObjects = getGeneValueObjectList(new ArrayList<>(genes));
}
StopWatch timer = new StopWatch();
timer.start();
VisualizationValueObject[] result = new VisualizationValueObject[vvoMap.keySet().size()];
// Create collection of visualizationValueObject for flotr on js side
int i = 0;
for (Long ee : vvoMap.keySet()) {
Collection<Long> validatedProbeList = null;
if (validatedProbes != null) {
validatedProbeList = validatedProbes.get(ee);
}
Collection<DoubleVectorValueObject> vectors = vvoMap.get(ee);
VisualizationValueObject vvo = new VisualizationValueObject(vectors, geneValueObjects, validatedProbeList);
if (vectors.size() > 0) {
getSampleNames(vectors, vvo, layouts);
if (vectors.size() > 0 && layouts != null && !layouts.isEmpty() && layouts.containsKey(ee)) {
// Set up the experimental designinfo so we can show it above the graph.
LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>> layout = layouts.get(ee);
this.prepareFactorsForFrontEndDisplay(vvo, layout);
}
}
/*
* Set up the experimental design info so we can show it above the graph.
*/
if (layouts != null && layouts.get(ee) != null) {
vvo.setUpFactorProfiles(layouts.get(ee));
}
result[i] = vvo;
i++;
}
long time = timer.getTime();
if (time > 1000) {
log.info("Created vis value objects in: " + time);
}
return result;
}
use of ubic.gemma.model.genome.gene.GeneValueObject in project Gemma by PavlidisLab.
the class GeneController method loadGeneDetails.
/**
* AJAX used for gene page
*/
public GeneValueObject loadGeneDetails(Long geneId) {
// return geneCoreService.loadGeneDetails( geneId );
GeneValueObject gvo = geneCoreService.loadGeneDetails(geneId);
Collection<EvidenceValueObject<? extends PhenotypeAssociation>> collEVO = phenotypeAssociationManagerService.findEvidenceByGeneId(geneId, new HashSet<String>(), new EvidenceFilter(gvo.getTaxonId(), false, null));
Iterator<EvidenceValueObject<? extends PhenotypeAssociation>> iter = collEVO.iterator();
Collection<CharacteristicValueObject> collFilteredDVO = new HashSet<>();
while (iter.hasNext()) {
EvidenceValueObject evo = iter.next();
if (!evo.isHomologueEvidence())
collFilteredDVO.addAll(evo.getPhenotypes());
}
gvo.setPhenotypes(collFilteredDVO);
gvo.setNumGoTerms(this.findGOTerms(geneId).size());
return gvo;
}
use of ubic.gemma.model.genome.gene.GeneValueObject in project Gemma by PavlidisLab.
the class GeneController method show.
@RequestMapping(value = { "/showGene.html", "/" }, method = RequestMethod.GET)
public ModelAndView show(HttpServletRequest request, HttpServletResponse response) {
String idString = request.getParameter("id");
String ncbiId = request.getParameter("ncbiid");
String geneName = request.getParameter("name");
String taxonName = request.getParameter("taxon");
String ensemblId = request.getParameter("ensemblId");
GeneValueObject geneVO = null;
try {
if (StringUtils.isNotBlank(idString)) {
Long id = Long.parseLong(idString);
geneVO = geneService.loadValueObjectById(id);
if (geneVO == null) {
addMessage(request, "object.notfound", new Object[] { "Gene " + id });
return new ModelAndView("index");
}
} else if (StringUtils.isNotBlank(ncbiId)) {
geneVO = geneService.findByNCBIIdValueObject(Integer.parseInt(ncbiId));
} else if (StringUtils.isNotBlank(ensemblId)) {
@SuppressWarnings("unchecked") Collection<Gene> foundGenes = Collections.singleton(geneService.findByEnsemblId(ensemblId));
if (foundGenes.size() == 1) {
Gene gene = foundGenes.iterator().next();
if (gene != null) {
geneVO = geneService.loadValueObjectById(gene.getId());
}
}
} else if (StringUtils.isNotBlank(geneName) && StringUtils.isNotBlank(taxonName)) {
Taxon taxon = taxonService.findByCommonName(taxonName);
if (taxon != null) {
Gene gene = geneService.findByOfficialSymbol(geneName, taxon);
if (gene != null) {
geneVO = geneService.loadValueObjectById(gene.getId());
}
}
}
} catch (NumberFormatException e) {
addMessage(request, "object.notfound", new Object[] { "Gene" });
return new ModelAndView("index");
}
if (geneVO == null) {
addMessage(request, "object.notfound", new Object[] { "Gene" });
return new ModelAndView("index");
}
Long id = geneVO.getId();
assert id != null;
ModelAndView mav = new ModelAndView("gene.detail");
mav.addObject("geneId", id);
mav.addObject("geneOfficialSymbol", geneVO.getOfficialSymbol());
mav.addObject("geneOfficialName", geneVO.getOfficialName());
mav.addObject("geneNcbiId", geneVO.getNcbiId());
mav.addObject("geneTaxonCommonName", geneVO.getTaxonCommonName());
mav.addObject("geneTaxonId", geneVO.getTaxonId());
return mav;
}
Aggregations