use of ubic.gemma.model.association.coexpression.GeneCoexpressionNodeDegreeValueObject in project Gemma by PavlidisLab.
the class LinkAnalysisServiceTest method checkResults.
private int checkResults(Collection<BioAssaySet> ees, int expectedMinimumMaxSupport) {
boolean foundOne = false;
int maxSupport = 0;
Taxon mouse = taxonService.findByCommonName("mouse");
Collection<Gene> genesWithLinks = new ArrayList<>();
int totalLinks = 0;
// numdatasetstesting will not be set so we won't bother checking.
assertTrue(!geneCoexpressionService.getCoexpression(ee, true).isEmpty());
Collection<CoexpressionValueObject> eeResults = geneCoexpressionService.getCoexpression(ee, false);
assertTrue(!eeResults.isEmpty());
for (CoexpressionValueObject coex : eeResults) {
this.checkResult(coex);
}
Map<Long, GeneCoexpressionNodeDegreeValueObject> nodeDegrees = geneCoexpressionService.getNodeDegrees(EntityUtils.getIds(geneService.loadAll()));
assertTrue(!nodeDegrees.isEmpty());
// experiment-major query
Map<Long, List<CoexpressionValueObject>> allLinks = geneCoexpressionService.findCoexpressionRelationships(mouse, new HashSet<Long>(), EntityUtils.getIds(ees), ees.size(), 10, false);
assertTrue(!allLinks.isEmpty());
for (Long g : allLinks.keySet()) {
for (CoexpressionValueObject coex : allLinks.get(g)) {
this.checkResult(coex);
}
}
for (Gene gene : geneService.loadAll(mouse)) {
Collection<CoexpressionValueObject> links = geneCoexpressionService.findCoexpressionRelationships(gene, EntityUtils.getIds(ees), 1, 0, false);
if (links == null || links.isEmpty()) {
continue;
}
assertEquals(geneCoexpressionService.findCoexpressionRelationships(gene, Collections.singleton(ee.getId()), 0, false).size(), geneCoexpressionService.countLinks(ee, gene).intValue());
GeneCoexpressionNodeDegreeValueObject nodeDegree = geneCoexpressionService.getNodeDegree(gene);
if (links.size() != nodeDegree.getLinksWithMinimumSupport(1)) {
log.info(nodeDegree);
assertEquals("Node degree check failed for gene " + gene, links.size(), nodeDegree.getLinksWithMinimumSupport(1).intValue());
}
assertTrue(nodeDegree.getLinksWithMinimumSupport(1) >= nodeDegree.getLinksWithMinimumSupport(2));
totalLinks += links.size();
log.debug(links.size() + " hits for " + gene);
for (CoexpressionValueObject coex : links) {
this.checkResult(coex);
if (coex.getNumDatasetsSupporting() > maxSupport) {
maxSupport = coex.getNumDatasetsSupporting();
}
}
foundOne = true;
if (genesWithLinks.size() == 5) {
// without specifying stringency
Map<Long, List<CoexpressionValueObject>> multiGeneResults = geneCoexpressionService.findCoexpressionRelationships(mouse, EntityUtils.getIds(genesWithLinks), EntityUtils.getIds(ees), 100, false);
if (multiGeneResults.isEmpty()) {
// noinspection ConstantConditions // these strange structures are to help with debugger.
assertTrue(!multiGeneResults.isEmpty());
}
for (Long id : multiGeneResults.keySet()) {
for (CoexpressionValueObject coex : multiGeneResults.get(id)) {
this.checkResult(coex);
}
}
// with stringency specified, quick.
Map<Long, List<CoexpressionValueObject>> multiGeneResults2 = geneCoexpressionService.findCoexpressionRelationships(mouse, EntityUtils.getIds(genesWithLinks), EntityUtils.getIds(ees), ees.size(), 100, true);
if (multiGeneResults.size() != multiGeneResults2.size()) {
assertEquals(multiGeneResults.size(), multiGeneResults2.size());
}
for (Long id : multiGeneResults2.keySet()) {
for (CoexpressionValueObject coex : multiGeneResults2.get(id)) {
this.checkResult(coex);
}
}
}
genesWithLinks.add(gene);
}
assertTrue(foundOne);
Map<Long, List<CoexpressionValueObject>> mygeneresults = geneCoexpressionService.findInterCoexpressionRelationships(mouse, EntityUtils.getIds(genesWithLinks), EntityUtils.getIds(ees), 1, false);
if (mygeneresults.isEmpty()) {
// noinspection ConstantConditions // these strange structures are to help with debugger.
assertTrue(!mygeneresults.isEmpty());
}
for (Long id : mygeneresults.keySet()) {
for (CoexpressionValueObject coex : mygeneresults.get(id)) {
this.checkResult(coex);
}
}
assertTrue(maxSupport >= expectedMinimumMaxSupport);
return totalLinks;
}
use of ubic.gemma.model.association.coexpression.GeneCoexpressionNodeDegreeValueObject in project Gemma by PavlidisLab.
the class CoexpressionNodeDegreeValueObjectTest method testa.
@Test
public void testa() {
Gene g = Gene.Factory.newInstance();
g.setId(1L);
g.setOfficialName("foo");
GeneCoexpressionNodeDegree nd = GeneCoexpressionNodeDegree.Factory.newInstance(g);
GeneCoexpressionNodeDegreeValueObject t = new GeneCoexpressionNodeDegreeValueObject(nd);
t.increment(1, true);
t.increment(2, true);
assertEquals(2, t.getLinksWithMinimumSupport(1, true).intValue());
assertEquals(1, t.getLinksWithExactSupport(1, true).intValue());
t.increment(1, true);
t.increment(2, true);
assertEquals(4, t.getLinksWithMinimumSupport(1, true).intValue());
assertEquals(2, t.getLinksWithMinimumSupport(2, true).intValue());
assertEquals(2, t.getLinksWithExactSupport(1, true).intValue());
assertEquals(3, t.asIntArrayPos().length);
assertEquals(0, t.asIntArrayPos()[0]);
assertEquals(2, t.asIntArrayPos()[1]);
assertEquals(2, t.asIntArrayPos()[2]);
}
use of ubic.gemma.model.association.coexpression.GeneCoexpressionNodeDegreeValueObject in project Gemma by PavlidisLab.
the class GeneServiceImpl method loadFullyPopulatedValueObject.
@Override
@Transactional(readOnly = true)
public GeneValueObject loadFullyPopulatedValueObject(Long id) {
Gene gene = this.geneDao.load(id);
if (gene == null) {
return null;
}
gene = this.geneDao.thaw(gene);
GeneValueObject gvo = GeneValueObject.convert2ValueObject(gene);
Collection<GeneAlias> aliasObjects = gene.getAliases();
Collection<String> aliasStrings = new ArrayList<>();
for (GeneAlias ga : aliasObjects) {
aliasStrings.add(ga.getAlias());
}
gvo.setAliases(aliasStrings);
if (gene.getMultifunctionality() != null) {
gvo.setMultifunctionalityRank(gene.getMultifunctionality().getRank());
}
Long compositeSequenceCount = this.getCompositeSequenceCountById(id);
gvo.setCompositeSequenceCount(compositeSequenceCount.intValue());
Integer platformCount = this.geneDao.getPlatformCountById(id);
gvo.setPlatformCount(platformCount);
Collection<GeneSet> geneSets = this.geneSetSearch.findByGene(gene);
Collection<GeneSetValueObject> gsVos = new ArrayList<>();
// noinspection CollectionAddAllCanBeReplacedWithConstructor // Constructor can't handle subclasses
gsVos.addAll(geneSetValueObjectHelper.convertToLightValueObjects(geneSets, false));
gvo.setGeneSets(gsVos);
Collection<Gene> geneHomologues = this.homologeneService.getHomologues(gene);
geneHomologues = this.thawLite(geneHomologues);
Collection<GeneValueObject> homologues = this.loadValueObjects(geneHomologues);
gvo.setHomologues(homologues);
Collection<PhenotypeAssociation> pas = gene.getPhenotypeAssociations();
Collection<CharacteristicValueObject> cVos = new HashSet<>();
for (PhenotypeAssociation pa : pas) {
cVos.addAll(CharacteristicValueObject.characteristic2CharacteristicVO(pa.getPhenotypes()));
}
gvo.setPhenotypes(cVos);
if (gvo.getNcbiId() != null) {
SearchSettingsImpl s = new SearchSettingsImpl();
s.setTermUri("http://purl.org/commons/record/ncbi_gene/" + gvo.getNcbiId());
s.noSearches();
s.setSearchExperiments(true);
Map<Class<?>, List<SearchResult>> r = searchService.search(s);
if (r.containsKey(ExpressionExperiment.class)) {
List<SearchResult> hits = r.get(ExpressionExperiment.class);
gvo.setAssociatedExperimentCount(hits.size());
}
}
GeneCoexpressionNodeDegreeValueObject nodeDegree = coexpressionService.getNodeDegree(gene);
if (nodeDegree != null) {
gvo.setNodeDegreesPos(nodeDegree.asIntArrayPos());
gvo.setNodeDegreesNeg(nodeDegree.asIntArrayNeg());
gvo.setNodeDegreePosRanks(nodeDegree.asDoubleArrayPosRanks());
gvo.setNodeDegreeNegRanks(nodeDegree.asDoubleArrayNegRanks());
}
return gvo;
}
use of ubic.gemma.model.association.coexpression.GeneCoexpressionNodeDegreeValueObject in project Gemma by PavlidisLab.
the class GeneCoexpressionSearchServiceImpl method populateNodeDegrees.
/**
* Populate node degree. Note that this ignores the datasets that were used in the query - the statistics are for
* 'all' data sets.
*/
private void populateNodeDegrees(CoexpressionMetaValueObject result) {
StopWatch timer = new StopWatch();
timer.start();
Collection<Long> allUsedGenes = new HashSet<>();
for (CoexpressionValueObjectExt coexp : result.getResults()) {
allUsedGenes.add(coexp.getQueryGene().getId());
allUsedGenes.add(coexp.getFoundGene().getId());
}
Map<Long, GeneCoexpressionNodeDegreeValueObject> nodeDegrees = new HashMap<>();
if (allUsedGenes.size() > 0) {
nodeDegrees = coexpressionService.getNodeDegrees(allUsedGenes);
}
for (CoexpressionValueObjectExt coexp : result.getResults()) {
// if node degree info is out of date.
if (!nodeDegrees.containsKey(coexp.getQueryGene().getId()) || !nodeDegrees.containsKey(coexp.getFoundGene().getId())) {
continue;
}
GeneCoexpressionNodeDegreeValueObject queryGeneNodeDegree = nodeDegrees.get(coexp.getQueryGene().getId());
GeneCoexpressionNodeDegreeValueObject foundGeneNodeDegree = nodeDegrees.get(coexp.getFoundGene().getId());
boolean pos = coexp.getNegSupp() == 0;
coexp.setQueryGeneNodeDegree(queryGeneNodeDegree.getLinksWithMinimumSupport(coexp.getSupport(), pos));
coexp.setFoundGeneNodeDegree(foundGeneNodeDegree.getLinksWithMinimumSupport(coexp.getSupport(), pos));
coexp.setQueryGeneNodeDegreeRank(queryGeneNodeDegree.getRankAtMinimumSupport(coexp.getSupport(), pos));
coexp.setFoundGeneNodeDegreeRank(foundGeneNodeDegree.getRankAtMinimumSupport(coexp.getSupport(), pos));
}
assert result.getSummaries() != null;
for (Long g : nodeDegrees.keySet()) {
if (!result.getSummaries().containsKey(g))
continue;
result.getSummaries().get(g).setCoexpNodeDegree(nodeDegrees.get(g));
}
if (timer.getTime() > 100) {
GeneCoexpressionSearchServiceImpl.log.info("Populate node degree for " + result.getResults().size() + ": " + timer.getTime() + "ms");
}
}
use of ubic.gemma.model.association.coexpression.GeneCoexpressionNodeDegreeValueObject in project Gemma by PavlidisLab.
the class CoexpressionDaoImpl method updateNodeDegree.
@Override
@Transactional
public GeneCoexpressionNodeDegreeValueObject updateNodeDegree(Gene g, GeneCoexpressionNodeDegree nd) {
Session sess = this.getSessionFactory().getCurrentSession();
List<CoexpressionValueObject> hits = this.getCoexpression(g);
/*
* We have to reset the support.
*/
GeneCoexpressionNodeDegreeValueObject gcndvo = new GeneCoexpressionNodeDegreeValueObject(nd);
gcndvo.clear();
assert gcndvo.getMaxSupportNeg() == 0;
for (CoexpressionValueObject hit : hits) {
if (hit.isPositiveCorrelation()) {
gcndvo.increment(hit.getNumDatasetsSupporting(), true);
} else {
gcndvo.increment(hit.getNumDatasetsSupporting(), false);
}
}
assert gcndvo.total() == hits.size();
GeneCoexpressionNodeDegree entity = gcndvo.toEntity();
nd.setLinkCountsPositive(entity.getLinkCountsPositive());
nd.setLinkCountsNegative(entity.getLinkCountsNegative());
if (CoexpressionDaoImpl.log.isDebugEnabled())
CoexpressionDaoImpl.log.debug("gene=" + g.getId() + " pos=" + StringUtils.join(ArrayUtils.toObject(nd.getLinkCountsPositive()), " ") + " neg=" + StringUtils.join(ArrayUtils.toObject(nd.getLinkCountsNegative()), " "));
sess.update(nd);
// might not be necessary, but presumption is data is stale now...
this.gene2GeneCoexpressionCache.remove(g.getId());
this.geneTestedInCache.remove(g.getId());
return gcndvo;
}
Aggregations