c3ad8f42fcb9df72943c002404152f77c5802a98 max Thu Jun 1 09:57:29 2017 -0700 fixing incorrect db counts on the low level menu, refs #13634 diff --git src/hg/hgGeneGraph/hgGeneGraph src/hg/hgGeneGraph/hgGeneGraph index f153ff6..5d74863 100755 --- src/hg/hgGeneGraph/hgGeneGraph +++ src/hg/hgGeneGraph/hgGeneGraph @@ -489,31 +489,37 @@ assert (gene!=None or genes!=None) query = "SELECT gene1, gene2, linkTypes, docCount, minResCount, dbList, snippet FROM ggLink " if gene!=None: query += "WHERE gene1='%s' OR gene2='%s'" % (gene, gene) else: geneList = ["'"+g+"'" for g in genes] listStr = '(%s)' % ",".join(geneList) query += "WHERE gene1 IN %s AND gene2 IN %s" % (listStr, listStr) rows = sqlQuery(conn, query) links = {} for row in rows: pair = (row.gene1, row.gene2) - links[pair] = (int(row.docCount), row.dbList.split("|"), \ + + if row.dbList=="": + dbList = [] + else: + dbList = row.dbList.split("|") + + links[pair] = (int(row.docCount), dbList, \ row.linkTypes.split(","), int(row.minResCount), row.snippet) return links def filterLinks(links): " remove links depending on the CGI param 'supportLevel'. Can show all, only with PPI/pathway or only with pathway " showTags = getFilterStatus() if len(showTags)==3: # no filtering return links # filter links filtLinks = {} for pair, pairData in links.iteritems(): docCount, dbList, tagSet = pairData[:3] if len(showTags.intersection(tagSet))!=0: @@ -811,33 +817,33 @@ # "INS" is not in kgXref??? rows = sqlQuery(conn, 'select chrom, txStart, txEnd from refGene where name2="%s" limit 1;' % gene) if len(rows)==0: return "", "", "" return rows[0] def flattenLink(links): """ given a dict with a directed graph geneA, geneB -> linkData return a undirected graph in the form of a list (geneA, geneB), totalCount, docCount, tags """ counts = [] minAbsCount = 99999999 for genes, linkData in links.iteritems(): - docCount, dbCount, tagSet, minResCount, snippet = linkData + docCount, dbList, tagSet, minResCount, snippet = linkData geneScore = scorePair(docCount, tagSet) - counts.append( (genes[0], genes[1], geneScore, docCount, dbCount, tagSet, minResCount, snippet) ) + counts.append( (genes[0], genes[1], geneScore, docCount, dbList, tagSet, minResCount, snippet) ) if docCount!=0: minAbsCount = min(minAbsCount, docCount) return counts, minAbsCount def countTargetLinks(links, targetGene): """ given a dict with (gene1, gene2) => docCount, dbCount, tags create a list of (gene, count) for all genes connected to target gene """ # count the in+outgoing links for each gene in 'links', the DB evidence # and the union of the tags allGenes = set() txtCounts = defaultdict(int) pairDbs = defaultdict(set) tags = defaultdict(set) @@ -848,31 +854,33 @@ if g1==targetGene: gene = g2 elif g2==targetGene: gene = g1 else: continue allGenes.add(gene) pairDbs[gene].update(dbs) txtCounts[gene] += docCount tags[gene].update(tagSet) # create a list (gene, txtCount, dbCount) linkList = [] for g in allGenes: - linkList.append( (g, txtCounts.get(g, 0), len(pairDbs.get(g, [])), tags.get(g, [])) ) + dbs = pairDbs.get(g, []) + dbCount = len(dbs) + linkList.append( (g, txtCounts.get(g, 0), dbCount, tags.get(g, [])) ) return linkList def makeUniDir(links): " for bidirectional links: keep only strongest direction and return new links dict " newLinks = defaultdict(set) for pair, pmids in links.iteritems(): if not pair in newLinks: cause, theme = pair revPair = (theme, cause) score = len(pmids) revPmids = links.get( revPair, set()) revScore = len(revPmids) allPmids = pmids.union(revPmids) if score > revScore: