6a0e43196a3a99808b3c26252ce6ca30ee2c574f
max
  Wed May 31 13:43:38 2017 -0700
fixing bug when no links are left, refs #13634

diff --git src/hg/hgGeneGraph/hgGeneGraph src/hg/hgGeneGraph/hgGeneGraph
index 60c3626..b1745b7 100755
--- src/hg/hgGeneGraph/hgGeneGraph
+++ src/hg/hgGeneGraph/hgGeneGraph
@@ -534,30 +534,32 @@
     if len(links)==0:
         errAbort("Sorry, the gene %s is not a valid gene symbol or is not present in any gene interaction database." % cgi.escape(gene))
 
     links = filterLinks(links)
 
     lowLinks = defaultdict(set)
     graphLinks, lowLinks = splitHighLowLinks(links, gene, minSupp, lowLinks, geneCount)
 
     if addNeighbors:
         # create the links between all other genes, be less stringent about these
         otherGenes = set()
         for genes, pmids in graphLinks.iteritems():
             otherGenes.update(genes)
         if gene in otherGenes:
             otherGenes.remove(gene)
+
+        if len(otherGenes)!=0:
             # get links between all other genes but keep the limit on the graphed links
             otherLinks = queryLinks(conn, genes=otherGenes)
             otherLinks = filterLinks(otherLinks)
             otherLinks = reqMinSupp(otherLinks, 2, 999999999, gene) # we still require two text mining abstracts
             otherLinks, lowLinks = limitLinks(otherLinks, lowLinks, 35, gene)
             # add the high links back to the graph
             for pair, linkData in otherLinks.iteritems():
                 assert(pair not in graphLinks)
                 graphLinks[pair] = linkData
 
     return graphLinks, lowLinks
 
 #def queryLinkColors(conn, links):
     #" figure out if links have annotations in pathway commons "
     #colors = {}
@@ -1162,30 +1164,35 @@
     import json
 
     # the trash file name has the format hgGeneGraph_targetGene_<md5OfCGIParams>
     trashDir = join("..","trash","geneGraph")
     if not isdir(trashDir):
         os.mkdir(trashDir)
 
     stateStr = makeSelfUrl({})
     stateStr += alg
     stateHash =  saltedHash(stateStr, length=20)
     tmpName = join(trashDir, "%s_%s.dot" % (targetGene, stateHash))
 
     if format=="json":
         jsonStr = json.dumps(weightedLinks)
 
+    if len(weightedLinks)==0:
+        geneName = cgi.escape(cgiString("gene"))
+        selfLink = makeSelfLink("Remove all filters", {"supportLevel": None})
+        errAbort("Sorry, there are no direct interactions with %s that fulfill your "
+            "filter criteria. %s" % (geneName, selfLink))
     allGenes = set()
     sifLines = []
     for linkRow in weightedLinks:
         gene1, gene2 = linkRow[:2]
         allGenes.add(gene1)
         allGenes.add(gene2)
         if format=="sif":
             sifLines.append("%s pp %s" % (gene1, gene2))
 
     if format in ["sif", "json"]:
         printHttpHead(format)
         if format=="sif":
             print "\n".join(sifLines)
         else:
             print jsonStr