2b9a3a726493d66c526e3d8256178ff3e12c7e3c max Fri Apr 28 16:48:03 2017 -0700 renaming pylib to pyLib after Angie's suggestion (thanks) and adding a better error message when graphviz was not found. refs #13634 diff --git src/hg/hgGeneGraph/hgGeneGraph src/hg/hgGeneGraph/hgGeneGraph index 023818d..8b39204 100755 --- src/hg/hgGeneGraph/hgGeneGraph +++ src/hg/hgGeneGraph/hgGeneGraph @@ -24,34 +24,39 @@ # - os.system is not a security risk here, no variables go into the cmd line # - mysql statements are not escaped, instead all CGI vars are checked for non-alpha letters # hgFixed tables required for this script: ggLink (main table with gene-gene links), # ggLinkEvent (details about link), ggEventDb (details about links from databases), # ggEventText (details about links from text mining), ggDoc (details about documents for ggEventText) # ggGeneName (symbols), ggGeneClass (HPRD/Panther class) # these are default python modules on python 2.7, no errors expected here import sys, cgi, os, string, urllib, operator, hashlib from sys import exit from collections import defaultdict, namedtuple from os.path import * # import the UCSC-specific library -sys.path.append("pylib") +sys.path.append("pyLib") +try: from hgLib import cgiArgs, cgiSetup, cgiString, printContentType, printMenuBar, \ sqlConnect, sqlQuery, errAbort, cfgOption, runCmd, cgiGetAll, printHgcHeader, \ printHgcSection, webStartGbNoBanner, htmlPageEnd, hConnectCentral, sqlTableExists +except: + print("Content-type: text/html\n") + print("Cannot find the directory cgi-bin/pyLib in Apache. This is an installation error.") + print("All all parts of cgi-bin installed? Did you do 'make' in kent/src/hg/pyLib?") # not using feedback button for now. Fan would have liked it, but not sure how we can write # to any form of database. #skimpyGimpyLoaded=False #try: #from skimpyGimpy import skimpyAPI #skimpyGimpyLoaded=True #except: #pass # the list of allowed chars in cgi args: digits, letters and dashes legalChars = set(string.digits) legalChars.update(set(string.letters)) legalChars.update("_-./: ") @@ -565,41 +570,71 @@ thick = 1 return thick def minResToThick(count): " convert minResCount to line thickness, for description of minResCount see start of file " if count > 100: thick = 1 elif count > 50: thick = 2 elif count > 10: thick = 3.5 else: thick = 2 return thick +def which(binPath): + " find full path of binary " + import distutils.spawn + return distutils.spawn.find_executable(binPath) + def runDot(fname, alg, format="png"): " run dot and return tuple outFname, outMapFname " outFname = splitext(fname)[0]+"."+format outMap = splitext(fname)[0]+".map" binPath = cfgOption("graphvizPath", "dot") - #cmd = "%s -Gdpi=96 -Gsize=12,5 -Gratio=fill -K%s %s -T%s -o %s" % (binPath, alg, fname, format, outFname) + + if which(binPath) is None: + print("Could not find the command %s<p>" % binPath) + print("This usually means that on this UCSC Genome Browser, GraphViz is not installed.") + print("To install GraphViz, ask the Administrator of this server to run one of the following commands:<br>") + print("<tt>sudo apt-get install graphviz</tt><br>") + print("<tt>sudo wget http://www.graphviz.org/graphviz-rhel.repo -o /etc/yum/repos.d/graphviz.rhel.repo; sudo yum install graphviz*</tt><br>") + print("<p>") + print("Alternatively, you can compile GraphViz from source and specify the full path to 'dot' with the option 'graphvizPath' in cgi-bin/hg.conf.") + exit(0) + cmd = [binPath, "-Gdpi=96", "-Gsize=12,5", "-Gratio=fill", "-K"+alg, "-T"+format, fname, "-o",outFname] # create a html map for png format if format=="png": cmd.extend(["-Tcmapx", "-o", outMap]) - runCmd(cmd) + ret = runCmd(cmd, mustRun=False) + + if ret!=0: + print("Could not run the command '%s'. <br>" % "".join(cmd)) + print("This means that on this UCSC Genome Browser Installation too old.") + print("To update GraphViz to a more recent version, ask the Administrator of this ") + print("server to try running one of these commands:<br>") + print("<tt>sudo apt-get install graphviz</tt><br>") + print("<tt>sudo wget http://www.graphviz.org/graphviz-rhel.repo -o ") + print("/etc/yum/repos.d/graphviz.rhel.repo;") + print("sudo yum install graphviz*</tt><br>") + print("<p>") + print("If this does not work, you may have to compile GraphViz from source and") + print("specify the 'dot' binary with the option graphvizPath cgi-bin/hg.conf.") + exit(0) + return outFname, outMap def dictToDot(d): """ reformat a dictionary to a string like [key1="value1"; key2="value2"] """ if len(d)==0: return "" strList = [] for key, val in d.iteritems(): strList.append('%s="%s"' % (key, val.replace('"', ''))) return "[%s]" % (";".join(strList)) def writeDot(allGenes, links, fname, targetGene, geneDescs, annotLabel, geneAnnots, linkSnips): """ write a description of the graph to fname in dot format. targetGene is highlighted, geneDescs are on mouseovers, geneAnnots are used to color the genes.