71043966c4ee2a305169d935479676656434c6b7
fanhsu
  Tue Nov 9 14:58:10 2010 -0800
Update for RGD Genes, Redmine issue #29.
diff --git src/hg/hgGene/ctd.c src/hg/hgGene/ctd.c
index beb6c65..ed769be 100644
--- src/hg/hgGene/ctd.c
+++ src/hg/hgGene/ctd.c
@@ -6,37 +6,54 @@
 #include "dystring.h"
 #include "cheapcgi.h"
 #include "spDb.h"
 #include "hgGene.h"
 #include "hdb.h"
 #include "net.h"
 
 static char const rcsid[] = "$Id: ctd.c,v 1.9 2009/02/13 02:38:27 markd Exp $";
 
 static boolean ctdExists(struct section *section, 
 	struct sqlConnection *conn, char *geneId)
 /* Return TRUE if CTD database exists and it has an entry with the gene symbol */
 {
 char condStr[255];
 char *geneSymbol;
+if (isRgdGene(conn))
+    {
+    if (sqlTableExists(conn, "rgdGene2Xref") == FALSE) return FALSE;
+    }
+else
+    {
 if (sqlTableExists(conn, "kgXref") == FALSE) return FALSE;
+    }
 
 if (sqlTableExists(conn, "hgFixed.ctdSorted") == TRUE)
     {
-    safef(condStr, sizeof(condStr), "x.geneSymbol=c.GeneSymbol and kgId='%s' limit 1", geneId);
-    geneSymbol = sqlGetField(database, "kgXref x, hgFixed.ctdSorted c", 
+    if (isRgdGene(conn))
+	{
+    	safef(condStr, sizeof(condStr), 
+	"x.info=c.GeneSymbol and infoType = 'Name' and rgdGeneId='%s' limit 1", geneId);
+    	geneSymbol = sqlGetField(database, "rgdGene2Xref x, hgFixed.ctdSorted c", 
     			     "ChemicalId", condStr);
+	}
+    else
+        {
+    	safef(condStr, sizeof(condStr), "x.geneSymbol=c.GeneSymbol and kgId='%s' limit 1", geneId);
+        geneSymbol = sqlGetField(database, "kgXref x, hgFixed.ctdSorted c", "ChemicalId", condStr);
+	}
+
     if (geneSymbol != NULL) return(TRUE);
     }
 return(FALSE);
 }
 
 static void ctdPrint(struct section *section, 
 	struct sqlConnection *conn, char *geneId)
 /* Print out CTD section. */
 {
 char query[256];
 struct sqlResult *sr;
 char **row;
 char *chemId, *chemName;
 int chemCnt;
 int first = 1;
@@ -44,32 +61,42 @@
 struct dyString *currentCgiUrl;
 
 showCompleteCtdList = FALSE;
 if (cgiOptionalString("showAllCtdRef") != NULL)
     {
     if (sameWord(cgiOptionalString("showAllCtdRef"), "Y") ||
 	sameWord(cgiOptionalString("showAllCtdRef"), "y") )
 	{
 	showCompleteCtdList = TRUE;
 	}
     cartRemove(cart, "showAllCtdRef");
     }
 currentCgiUrl = cgiUrlString();
     
 /* List chemicals related to this gene */
+if (isRgdGene(conn))
+    {
 safef(query, sizeof(query),
-     "select ChemicalId, ChemicalName from kgXref x, hgFixed.ctdSorted c where x.geneSymbol=c.GeneSymbol and kgId='%s'", geneId);
+          "select ChemicalId, ChemicalName from rgdGene2Xref x, hgFixed.ctdSorted c where x.info=c.GeneSymbol and rgdGeneId='%s' and infoType='Name'", 
+	  geneId);
+    }
+else
+    {
+    safef(query, sizeof(query),
+          "select ChemicalId, ChemicalName from kgXref x, hgFixed.ctdSorted c where x.geneSymbol=c.GeneSymbol and kgId='%s'", 
+	  geneId);
+    }
 
 sr = sqlMustGetResult(conn, query);
 row = sqlNextRow(sr);
     
 chemCnt = 0;
 while (row != NULL) 
     {
     chemId   = cloneString(row[0]);
     chemName = cloneString(row[1]);
    
     if (first)
     	{
 	printf("<B>The following chemicals interact with this gene</B>\n");
 	printf("<UL>");
 	first = 0;