use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class GeneSetSearchImpl method goTermToGeneSet.
/**
* Convert a GO term to a 'GeneSet', including genes from all child terms. Divide up by taxon.
*/
private GeneSet goTermToGeneSet(OntologyResource term, Taxon taxon, Integer maxGeneSetSize) {
assert taxon != null;
if (term == null)
return null;
if (term.getUri() == null)
return null;
Collection<OntologyResource> allMatches = new HashSet<>();
allMatches.add(term);
assert term instanceof OntologyTerm;
allMatches.addAll(this.geneOntologyService.getAllChildren((OntologyTerm) term));
GeneSetSearchImpl.log.info(term);
/*
* Gather up uris
*/
Collection<String> termsToFetch = new HashSet<>();
for (OntologyResource t : allMatches) {
String goId = this.uri2goid(t);
termsToFetch.add(goId);
}
Collection<Gene> genes = this.gene2GoService.findByGOTerms(termsToFetch, taxon);
if (genes.isEmpty() || (maxGeneSetSize != null && genes.size() > maxGeneSetSize)) {
return null;
}
GeneSet transientGeneSet = GeneSet.Factory.newInstance();
transientGeneSet.setName(this.uri2goid(term));
if (term.getLabel() == null) {
GeneSetSearchImpl.log.warn(" Label for term " + term.getUri() + " was null");
}
// noinspection StatementWithEmptyBody // FIXME this is an individual or a 'resource', not a 'class', but it's a real GO term. How to get the text.
if (term.getLabel() != null && term.getLabel().toUpperCase().startsWith("GO_")) {
}
transientGeneSet.setDescription(term.getLabel());
for (Gene gene : genes) {
GeneSetMember gmember = GeneSetMember.Factory.newInstance();
gmember.setGene(gene);
transientGeneSet.getMembers().add(gmember);
}
return transientGeneSet;
}
use of ubic.basecode.ontology.model.OntologyTerm 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.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class Gene2GOdescriptionEndpoint method invokeInternal.
/**
* Reads the given <code>requestElement</code>, and sends a the response back.
*
* @param requestElement the contents of the SOAP message as DOM elements
* @param document a DOM document to be used for constructing <code>Node</code>s
* @return the response element
*/
@Override
protected Element invokeInternal(Element requestElement, Document document) {
StopWatch watch = new StopWatch();
watch.start();
setLocalName(LOCAL_NAME);
Collection<String> geneInput = getArrayValues(requestElement, "gene_id");
// String geneString = geneInput.iterator().next();
log.info("XML input read: " + geneInput.size() + " gene ids ");
Element responseWrapper = document.createElementNS(NAMESPACE_URI, LOCAL_NAME);
Element responseElement = document.createElementNS(NAMESPACE_URI, LOCAL_NAME + RESPONSE);
responseWrapper.appendChild(responseElement);
Collection<Long> geneIds = parseLongCollection(geneInput);
Collection<Gene> geneCol = geneService.load(geneIds);
if (geneCol == null || geneCol.isEmpty()) {
String msg = "No gene with the given ids can be found.";
return buildBadResponse(document, msg);
}
for (Gene gene : geneCol) {
Collection<OntologyTerm> terms = geneOntologyService.getGOTerms(gene);
// get the labels for the gene and store them
if (terms != null) {
for (OntologyTerm ot : terms) {
// gene id output
Element e1 = document.createElement("gene_id");
e1.appendChild(document.createTextNode(gene.getId().toString()));
responseElement.appendChild(e1);
String goTerm = GeneOntologyServiceImpl.asRegularGoId(ot);
Element e2 = document.createElement("go_id");
e2.appendChild(document.createTextNode(goTerm));
responseElement.appendChild(e2);
Element e3 = document.createElement("go_description");
e3.appendChild(document.createTextNode(ot.getLabel()));
responseElement.appendChild(e3);
}
} else {
// gene id output
Element e1 = document.createElement("gene_id");
e1.appendChild(document.createTextNode(gene.getId().toString()));
responseElement.appendChild(e1);
Element e2 = document.createElement("go_id");
e2.appendChild(document.createTextNode("NaN"));
responseElement.appendChild(e2);
Element e3 = document.createElement("go_description");
e3.appendChild(document.createTextNode("NaN"));
responseElement.appendChild(e3);
}
}
watch.stop();
Long time = watch.getTime();
log.info("XML response for GO Term results built in " + time + "ms.");
return responseWrapper;
}
Aggregations