5c2c8cf11fb23c78904551c13aad3265cd70b9d1
fanhsu
  Fri Sep 16 15:20:53 2011 -0700
Broke a complex query for omimGene2 into a combination of 2-step queries.
diff --git src/hg/hgc/hgc.c src/hg/hgc/hgc.c
index e4c8eb2..21e9228 100644
--- src/hg/hgc/hgc.c
+++ src/hg/hgc/hgc.c
@@ -9703,50 +9703,65 @@
 		else
 		    {
 		    // show phenotype class if available, even phenotypeId is not available
 		    if (!sameWord(phenotypeClass, "-1")) printf(" (%s)", phenotypeClass);
 		    }
 
 		}
 	    printf("<BR>\n");
 	    }
 	if (disorderShown) printf("</UL>\n");
     	sqlFreeResult(&sr);
 	}
 
     // show RefSeq Gene link(s)
     safef(query, sizeof(query),
-          "select distinct r.name from refLink l, omim2gene g, refGene r where l.omimId=%s and g.geneId=l.locusLinkId and g.entryType='gene' and chrom='%s' and txStart = %s and txEnd= %s",
+          "select distinct locusLinkId from refLink l, omim2gene g, refGene r where l.omimId=%s and g.geneId=l.locusLinkId and g.entryType='gene' and chrom='%s' and txStart = %s and txEnd= %s",
 	  itemName, chrom, chromStart, chromEnd);
     sr = sqlMustGetResult(conn, query);
     if (sr != NULL)
 	{
+    	char *geneId;
+    	row = sqlNextRow(sr);
+    	geneId = strdup(row[0]);
+    	sqlFreeResult(&sr);
+
+    	safef(query, sizeof(query),
+              "select distinct l.mrnaAcc from refLink l where locusLinkId = '%s' order by mrnaAcc asc", geneId);
+    	sr = sqlMustGetResult(conn, query);
+    	if (sr != NULL)
+	    {
 	int printedCnt;
 	printedCnt = 0;
 	while ((row = sqlNextRow(sr)) != NULL)
 	    {
 	    if (printedCnt < 1)
 		printf("<B>RefSeq Gene(s): </B>");
 	    else
 		printf(", ");
     	    printf("<A HREF=\"%s%s&o=%s&t=%s\">", "../cgi-bin/hgc?g=refGene&i=", row[0], chromStart, chromEnd);
     	    printf("%s</A></B>", row[0]);
 	    printedCnt++;
 	    }
         if (printedCnt >= 1) printf("<BR>\n");
 	}
+        }
+    else
+    	{
+	// skip if no RefSeq found
     sqlFreeResult(&sr);
+    	}
 
     // show Related UCSC Gene links
     safef(query, sizeof(query),
           "select distinct kgId from kgXref x, refLink l, omim2gene g where x.refseq = mrnaAcc and l.omimId=%s and g.omimId=l.omimId and g.entryType='gene'",
 	  itemName);
     sr = sqlMustGetResult(conn, query);
     if (sr != NULL)
 	{
 	int printedCnt;
 	printedCnt = 0;
 	while ((row = sqlNextRow(sr)) != NULL)
 	    {
 	    if (printedCnt < 1)
 		printf("<B>Related UCSC Gene(s): </B>");
 	    else