25a1ed58b2f9fc2d9ad7fdbe9117f0b2f47253f3
fanhsu
  Tue Nov 9 16:38:23 2010 -0800
Update for RGD Genes, Redmine issue #29.
diff --git src/hg/hgGene/synonym.c src/hg/hgGene/synonym.c
index 1a05c3d..df00f6d 100644
--- src/hg/hgGene/synonym.c
+++ src/hg/hgGene/synonym.c
@@ -159,44 +159,142 @@
     /* since kg is not by location (even though we have a
      * curGeneStart/curGeneEnd), we need to use the location in the 
      * ccdsGeneMap */
     for (ccdsKg = ccdsKgs; ccdsKg != NULL; ccdsKg = ccdsKg->next)
         {
         if (ccdsKg != ccdsKgs)
             hPrintf(", ");
         hPrintf("<A href=\"../cgi-bin/hgc?%s&g=ccdsGene&i=%s&c=%s&o=%d&l=%d&r=%d&db=%s\">%s</A>",
                 cartSidUrlString(cart), ccdsKg->ccdsId, ccdsKg->chrom, ccdsKg->chromStart, ccdsKg->chromStart,
                 ccdsKg->chromEnd, database, ccdsKg->ccdsId);
         }
     hPrintf("<BR>\n");   
     }
 }
 
+char *addComma(char *inStr)
+{
+char *chp;
+chp = inStr;
+
+while (*chp != '\0')
+    {
+    if (*chp == '|')
+       *chp = ',';
+    chp++;
+    }
+return inStr;
+}
+
+static void rgdGene2SynonymPrint(struct section *section,
+        struct sqlConnection *conn, char *rgdGeneId)
+{
+char *geneSym = NULL, *geneName = NULL;
+char query[256], **row;
+struct sqlResult *sr;
+if (rgdGeneId != NULL)
+    {
+    safef(query, sizeof(query), 
+	    "select old_symbol, old_name from genes_rat where gene_rgd_id = '%s'", 
+	    rgdGeneId+4L);
+    sr = sqlGetResult(conn, query);
+    if ((row = sqlNextRow(sr)) != NULL)
+	{
+	if (row[0][0] != 0 && !sameString(row[0], "n/a"))
+	    {
+	    geneSym = cloneString(row[0]);
+	    hPrintf("<B>Symbol:</B> %s ", addComma(row[0]));
+	    //hPrintf("<BR>\n");
+	    }
+	if (row[1][0] != 0 && !sameString(row[0], "n/a"))
+	    {
+	    geneName = cloneString(row[1]);
+	    hPrintf("<BR><B>Name:</B> %s ", addComma(geneName));
+	    hPrintf("<BR>\n");
+	    }
+	}
+    sqlFreeResult(&sr);
+
+    safef(query, sizeof(query), 
+	    "select value from rgdGene2ToRefSeq where name= '%s'", rgdGeneId);
+    sr = sqlGetResult(conn, query);
+    if ((row = sqlNextRow(sr)) != NULL)
+	{
+        hPrintf("<B>RefSeq Accession: </B> <A HREF=\"");
+	printOurRefseqUrl(stdout, row[0]);
+	hPrintf("\">%s</A><BR>\n", row[0]);
+	}
+    sqlFreeResult(&sr);
+    
+    safef(query, sizeof(query), 
+	    "select value from rgdGene2ToUniProt where name= '%s'", rgdGeneId);
+    sr = sqlGetResult(conn, query);
+    if ((row = sqlNextRow(sr)) != NULL)
+    	{
+	char *spId, *spDisplayId, *oldDisplayId;
+	spId = row[0];
+	hPrintf("<B>Protein: </B>");
+        hPrintf("<A HREF=\"http://www.uniprot.org/uniprot/%s\" "
+	    "TARGET=_blank>%s</A>\n",
+	    spId, spId);
+    
+        /* show SWISS-PROT display ID if it is different than the accession ID */
+        /* but, if display name is like: Q03399 | Q03399_HUMAN, then don't show display name */
+        spDisplayId = spAnyAccToId(spConn, spId);
+        if (spDisplayId == NULL) 
+    	    {
+	    errAbort("<br>The corresponding protein %s of this gene is not found in our current UniProtKB DB.", spId);
+	    }   
+	
+        if (strstr(spDisplayId, spId) == NULL)
+	    {
+	    hPrintf(" (aka %s", spDisplayId);
+	    /* show once if the new and old displayId are the same */
+ 	    oldDisplayId = oldSpDisplayId(spDisplayId);
+	    if (oldDisplayId != NULL)
+ 	    	{
+            	if (!sameWord(spDisplayId, oldDisplayId)
+                    && !sameWord(spId, oldDisplayId))
+	    	    {
+	    	    hPrintf(" or %s", oldDisplayId);
+	    	    }  
+	        }	
+	    hPrintf(")<BR>\n");
+	    }  
+   	}
+    sqlFreeResult(&sr);
+    }
+}
 static void synonymPrint(struct section *section, 
 	struct sqlConnection *conn, char *id)
 /* Print out SwissProt comments - looking up typeId/commentVal. */
 {
 char *protAcc = getSwissProtAcc(conn, spConn, id);
 char *spDisplayId;
 char *refSeqAcc = "";
 char *mrnaAcc = "";
 char *oldDisplayId;
 char condStr[255];
 char *kgProteinID;
 char *parAcc; /* parent accession of a variant splice protein */
 char *chp;
 
+if (isRgdGene(conn))
+    {
+    rgdGene2SynonymPrint(section,conn, id);
+    return;
+    }
 if (sqlTablesExist(conn, "kgAlias"))
     printAlias(id, conn);
 if (sameWord(genome, "Zebrafish"))
     {
     char *xrefTable = "ensXRefZfish";
     char *geneIdCol = "ensGeneId";
     /* get Gene Symbol and RefSeq accession from Zebrafish-specific */
     /* cross-reference table */
     printGeneSymbol(id, xrefTable, geneIdCol, conn);
     refSeqAcc = getRefSeqAcc(id, xrefTable, geneIdCol, conn);
     hPrintf("<B>ENSEMBL ID:</B> %s", id);
     }
 else
     {
     char query[256];