5472f71152a9d892fc7d7081fad7e7c797d3258a
max
  Fri Jun 27 07:28:30 2025 -0700
requiring valid user cookie to use hgGeneGraph, refs #35391

diff --git src/hg/hgGeneGraph/hgGeneGraph src/hg/hgGeneGraph/hgGeneGraph
index b90474abd9f..f7a1ad401c0 100755
--- src/hg/hgGeneGraph/hgGeneGraph
+++ src/hg/hgGeneGraph/hgGeneGraph
@@ -81,30 +81,33 @@
 # Cutoff on minResCount:
 # maximum number of pairs a study can have to be considered "low-throughput"
 # only interactions with at least one low-throughput study are colord in dark
 # In essence, this gets rid of curated papers that describe huge complexes
 LTCUTOFF=10
 
 # color for edges with only text-mining data ("text")
 TEXTCOLOR="#BBBBBB"
 # color for edges with low-throughput data (=pwy or (ppi and LTCUTOFF))
 LTCOLOR="#000099"
 # color for edges with high-throughput data (=ppi)
 HTCOLOR="#8080CC"
 # transparency for the gene graph edges
 TRANSPARENCY="C0"
 
+# do not show more than X snippets
+MAXSNIPPETS=100
+
 # url of the user's manual
 MANUALURL="../goldenPath/help/hgGeneGraph.html"
 
 # database where the tables are stored
 GGDB="hgFixed"
 
 # ==== GLOBALS =====
 
 # CGI parameters as a FieldStorage object
 # args = None
 
 # external DB information
 dbData = {
 "kegg" : ("KEGG", "http://www.kegg.jp/kegg-bin/show_pathway?%s"),
 "wikipathways" : ("WikiPathways", "http://www.wikipathways.org/index.php/Pathway:%s"),
@@ -1650,31 +1653,31 @@
     #centralDb = cfgOption("central.db")
     #blackList = set()
     #rows = sqlQuery(conn, "SELECT causeGene, themeGene, pmid from %s.ggFeedback" % centralDb)
     #for row in rows:
         #blackList.add( (row.causeGene, row.themeGene, str(row.pmid)) )
     #return blackList
 
 def queryEventText(conn, gene1, gene2):
     " return rows from the ggEventText table "
     gene1, gene2 = sorted([gene1, gene2])
     q = "SELECT ggEventText.*, "\
         "ggDoc.authors, ggDoc.title, ggDoc.journal, ggDoc.year, ggDoc.context, ggDoc.resCount " \
         "FROM ggLinkEvent, ggEventText " \
         "JOIN ggDoc ON (ggDoc.docId=ggEventText.docId) " \
         "WHERE gene1='%s' and gene2='%s' AND ggEventText.eventId=ggLinkEvent.eventId " \
-        "ORDER BY ggDoc.docId" % (gene1,gene2)
+        "ORDER BY ggDoc.docId REVERSE LIMIT %d" % (gene1,gene2,MAXSNIPPETS)
     rows =  sqlQuery(conn, q)
     return rows
 
 def htmlInteraction(gene1, gene2):
     " return html: two genes separated by an arrow from g1 to g2, with links to hgGeneGraph "
     return '<a href="hgGeneGraph?gene=%s">%s</a> &#8594; <a href="hgGeneGraph?gene=%s">%s</a>' % (gene1, gene1, gene2, gene2)
 
 def prettyDocLinks(conn, pmids):
     " given a list of pmids, return a list of nice links to articles on our own site "
     quoteList = ['"%s"' % pmid for pmid in pmids]
     idStr = "(%s)" % (",".join(quoteList))
     # XX remove distinct if not needed anymore
     query = "SELECT authors, title, journal, year, docId, resCount FROM ggDoc WHERE docId IN %s" % idStr
     rows = sqlQuery(conn, query)
 
@@ -1702,30 +1705,33 @@
     text = "%s %s, %s %s" % (fAu, suffix, row.journal, row.year)
 
     mouseOver = None
     title = row.title
     if title!="":
         mouseOver = title.replace('"', "")
     return docLink(row.docId, text=text, mouseOver=mouseOver)+note
 
 def showSnipsLink(conn, gene1, gene2):
     " show snippets for a gene pair "
     rows = queryEventText(conn, gene1, gene2)
 
     if len(rows)!=0:
         print('<h3>Text-mined interactions from <A HREF="http://literome.azurewebsites.net/Network?gene1=%s&gene2=%s">Literome</A></h3>' % (gene1, gene2))
 
+    if len(rows)==MAXSNIPPETS:
+        print("Only %d snippets are shown below. Use our public MariaDB server to access the others or contact us.<br>" % MAXSNIPPETS)
+
     byDoc = defaultdict(list)
     for row in rows:
         byDoc[row.docId].append(row)
 
     for docId, rows in byDoc.items():
         print(prettyDocLink(rows[0], showStar=False))
 
         disSuffix = ""
         context = rows[0].context
         if context!="":
             contexts = context.split("|")
             if len(contexts)>1:
                 suffix = "..."
             else:
                 suffix = ""
@@ -2019,31 +2025,31 @@
         exit(0)
         
     link = getCgiVar("link")
     if link!=None:
         showLink(link)
         exit(0)
 
     page = getCgiVar("page")
     if page=="stats":
         showStats()
         exit(0)
 
     showGraphBrowser()
 
 def main():
-    cgiSetup(bottleneckFraction=2, useBytes=2)
+    cgiSetup(bottleneckFraction=2)
 
     format = getCgiVar("format")
     if format in ["pdf", "svg", "sif", "json"]:
         conn = sqlConnect(GGDB)
         gene, alg, addNeighbors, sortByCount, geneCount = parseGraphArgs()
         graphLinks, lowLinks = buildGraph(conn, gene, geneCount, MINSUPP, addNeighbors)
         weightedLinks, minAbsCount = flattenLink(graphLinks)
         printGraph(conn, weightedLinks, alg, addNeighbors, gene, format)
         sys.exit(0)
 
 
     # Apache doesn't set LANG, so the default encoding of stdout is ASCII: Change it to utf8
     import codecs
     sys.stdout = open(1, 'w', encoding='utf-8', closefd=False)