25a1ed58b2f9fc2d9ad7fdbe9117f0b2f47253f3
fanhsu
  Tue Nov 9 16:38:23 2010 -0800
Update for RGD Genes, Redmine issue #29.
diff --git src/hg/hgGene/pathways.c src/hg/hgGene/pathways.c
index 1a6fd7e..b0a9e4a 100644
--- src/hg/hgGene/pathways.c
+++ src/hg/hgGene/pathways.c
@@ -23,55 +23,76 @@
     	struct sqlConnection *conn, char *geneId);
     /* Count number of items referring to this gene. */
 
     void (*printLinks)(struct pathwayLink *pl, 
     	struct sqlConnection *conn, char *geneId);
     /* Print out links. */
     };
 
 static void keggLink(struct pathwayLink *pl, struct sqlConnection *conn, 
 	char *geneId)
 /* Print out kegg database link. */
 {
 char query[512], **row;
 struct sqlResult *sr;
 
+if (isRgdGene(conn))
+{
+safef(query, sizeof(query), 
+	"select k.locusID, k.mapID, keggMapDesc.description"
+	" from rgdGene2KeggPathway k, keggMapDesc, rgdGene2 x"
+	" where k.rgdId=x.name "
+	" and x.name='%s'"
+	" and k.mapID = keggMapDesc.mapID"
+	, geneId);
+}
+else
+{
 safef(query, sizeof(query), 
 	"select k.locusID, k.mapID, keggMapDesc.description"
 	" from keggPathway k, keggMapDesc, kgXref x"
 	" where k.kgID=x.kgId "
 	" and x.kgID='%s'"
 	" and k.mapID = keggMapDesc.mapID"
 	, geneId);
+}
 
 sr = sqlGetResult(conn, query);
 while ((row = sqlNextRow(sr)) != NULL)
     {
     hPrintf("<A HREF=\"http://www.genome.ad.jp/dbget-bin/show_pathway?%s+%s\" TARGET=_blank>",
     	row[1], row[0]);
     hPrintf("%s</A> - %s<BR>", row[1], row[2]);
     }
 sqlFreeResult(&sr);
 }
 
 static int keggCount(struct pathwayLink *pl, struct sqlConnection *conn,
 	char *geneId)
 /* Count up number of hits. */
 {
 char query[256];
+if (!isRgdGene(conn))
+    {
 safef(query, sizeof(query), 
 	"select count(*) from keggPathway k, kgXref x where k.kgID=x.kgId and x.kgId='%s'", geneId);
+    }
+else
+    {
+    safef(query, sizeof(query), 
+	"select count(*) from rgdGene2KeggPathway k, rgdGene2 x where k.rgdId=x.name and x.name='%s'", geneId);
+    }
 return sqlQuickNum(conn, query);
 }
 
 static void bioCycLink(struct pathwayLink *pl, struct sqlConnection *conn, 
 	char *geneId)
 /* Print out bioCyc database link. */
 {
 char query[512], **row;
 struct sqlResult *sr;
 char *oldMapId = cloneString("");
 
 safef(query, sizeof(query),
 	"select bioCycPathway.mapId,description"
 	" from bioCycPathway,bioCycMapDesc"
 	" where bioCycPathway.kgId='%s'"
@@ -113,34 +134,49 @@
 
 static void reactomeLink(struct pathwayLink *pl, struct sqlConnection *conn, 
 	char *geneId)
 {
 char condStr[255];
 char *spID, *chp;
 
 struct sqlConnection *conn2;
 char query2[256];
 struct sqlResult *sr2;
 char **row2;
 char *eventDesc;
 char *eventID;
 
 /* check the existence of kgXref table first */
+if (isRgdGene(conn))
+    {
+    if (!sqlTableExists(conn, "rgdGene2Xref")) return;
+    }
+else
+    {
 if (!sqlTableExists(conn, "kgXref")) return;
-
+    }
+if (isRgdGene(conn))
+    {
+    safef(condStr, sizeof(condStr), "name='%s'", geneId);
+    spID = sqlGetField(database, "rgdGene2ToUniProt", "value", condStr);
+    }
+else
+    {
 safef(condStr, sizeof(condStr), "kgID='%s'", geneId);
 spID = sqlGetField(database, "kgXref", "spID", condStr);
+    }
+
 if (spID != NULL)
     {
     /* convert splice variant UniProt ID to its main root ID */
     chp = strstr(spID, "-");
     if (chp != NULL) *chp = '\0';
     
     hPrintf(
     "<BR>Protein %s (<A href=\"http://www.reactome.org/cgi-bin/link?SOURCE=UniProt&ID=%s\" TARGET=_blank>Reactome details)</A> participates in the following event(s):<BR><BR>" 
     , spID, spID);
 
     conn2= hAllocConn(database);
     safef(query2,sizeof(query2), 
     	  "select eventID, eventDesc from proteome.spReactomeEvent where spID='%s'", spID);
     sr2 = sqlMustGetResult(conn2, query2);
     row2 = sqlNextRow(sr2);
@@ -235,46 +271,70 @@
 char query[256];
 safef(query, sizeof(query),
       "select count(*) from rgdGenePathway where geneId ='%s'", geneId);
 return sqlQuickNum(conn, query);
 }
 
 static int reactomeCount(struct pathwayLink *pl, struct sqlConnection *conn, 
 	char *geneId)
 /* Count up number of hits. */
 {
 int ret = 0;
 char query[256];
 char *spID, *chp;
 char condStr[256];
 char *origSpID;
-
 /* check the existence of kgXref table first */
+if (!isRgdGene(conn))
+    {
 if (!sqlTableExists(conn, "kgXref")) return(0);
+    }
+else
+    {
+    if (!sqlTableExists(conn, "rgdGene2Xref")) return(0);
+    }
 
+if (isRgdGene(conn))
+    {
+    safef(condStr, sizeof(condStr), "name='%s'", geneId);
+    spID = sqlGetField(database, "rgdGene2ToUniProt", "value", condStr);
+    }
+else
+    {
 safef(condStr, sizeof(condStr), "kgID='%s'", geneId);
 spID = sqlGetField(database, "kgXref", "spID", condStr);
+    }
+
 if (spID != NULL)
     {
     origSpID = cloneString(spID);
     /* convert splice variant UniProt ID to its main root ID */
     chp = strstr(spID, "-");
     if (chp != NULL) *chp = '\0';
 
+    if (!isRgdGene(conn))
+        {
     safef(query, sizeof(query), 
 	  "select count(*) from %s.spReactomeEvent, %s.spVariant, %s.kgXref where kgID='%s' and kgXref.spID=variant and variant = '%s' and spReactomeEvent.spID=parent", 
 	  PROTEOME_DB_NAME, PROTEOME_DB_NAME, database, geneId, origSpID);
+	}
+    else
+    	{
+        safef(query, sizeof(query), 
+	  "select count(*) from %s.spReactomeEvent, %s.spVariant, %s.rgdGene2ToUniProt where name='%s' and value=variant and variant = '%s' and spReactomeEvent.spID=parent", 
+	  PROTEOME_DB_NAME, PROTEOME_DB_NAME, database, geneId, origSpID);
+	}
 
     ret = sqlQuickNum(conn, query);
     }
 return ret;
 }
 
 struct pathwayLink pathwayLinks[] =
 {
    { "kegg", "KEGG", "KEGG - Kyoto Encyclopedia of Genes and Genomes", 
    	"keggPathway keggMapDesc", 
 	keggCount, keggLink},
    { "bioCyc", "BioCyc", "BioCyc Knowledge Library",
         "bioCycPathway bioCycMapDesc", 
 	bioCycCount, bioCycLink},
    { "bioCarta", "BioCarta", "BioCarta from NCI Cancer Genome Anatomy Project",