Index: src/hg/hgc/lowelab.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/hgc/lowelab.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -b -B -U 4 -r1.37 -r1.38
--- src/hg/hgc/lowelab.c	24 Sep 2009 21:16:35 -0000	1.37
+++ src/hg/hgc/lowelab.c	14 Oct 2009 07:08:13 -0000	1.38
@@ -263,17 +263,31 @@
 struct genePred *gpList = NULL, *gp = NULL;
 char tableName[64];
 boolean hasBin;
 
+char pepTableName[64];
+char extraTableName[64];
+
+if (startsWith("annotRev", table))
+{
+    sprintf(pepTableName, "%s%s", table, pepTable);
+    sprintf(extraTableName, "%s%s", table, extraTable);
+}
+else
+{
+    strcpy(pepTableName, pepTable);
+    strcpy(extraTableName, extraTable);    
+}
+
 spConn = sqlConnect( pdb);
 genericHeader(tdb, item);
 wordCount = chopLine(dupe, words);
 if (wordCount > 1)
     num = atoi(words[1]);
 if (num < 3) num = 3;
-if (extraTable != NULL && hTableExists(database, extraTable))
+if (extraTableName != NULL && hTableExists(database, extraTableName))
     {
-    sprintf(query, "select * from %s where name = '%s'", extraTable, item);
+    sprintf(query, "select * from %s where name = '%s'", extraTableName, item);
     sr = sqlGetResult(conn, query);
     while ((row = sqlNextRow(sr)) != NULL)
     {
     minGeneInfoStaticLoad(row, &ginfo);
@@ -524,9 +538,9 @@
     if (sequence != NULL)
         printf("<B>GC content:</B> %0.2f%%<BR>\n", computeGCContent(sequence->dna, sequence->size));
 }
 
-geneShowPosAndLinks(item, item, tdb, pepTable, "htcTranslatedProtein",
+geneShowPosAndLinks(item, item, tdb, pepTableName, "htcTranslatedProtein",
             "htcGeneMrna", "htcGeneInGenome", "Predicted mRNA");
 
 genePredFreeList(&gpList);
 
@@ -1826,9 +1840,9 @@
     return blastpTrack;
 }
 
 
-void printQueryGeneInfo(struct sqlConnection *conn, struct bed *blastpTrack, char *queryName, unsigned int *querySeqLength)
+void printQueryGeneInfo(struct sqlConnection *conn, struct bed *blastpTrack, char *queryName, unsigned int *querySeqLength, char *queryTable)
 /* Get and print blastp query gene info */
 {
     char query[512];
     struct sqlResult *srRefSeq;
@@ -1837,21 +1851,20 @@
     char **buffer = NULL;
     char *targetGeneName[2];
     struct minGeneInfo* ginfo;
 
-    char refSeq[] = "refSeq";
     char blastpHits[] = "blastpHits";
 
     unsigned int queryStart = 0;
     unsigned int queryEnd = 0;
 
     parseDelimitedString(blastpTrack->name, ':', targetGeneName, 2);
 
-    if (hTableExists(database, refSeq) && hTableExists(database, blastpHits))
+    if (hTableExists(database, queryTable) && hTableExists(database, blastpHits))
     {
         /* Get query gene from refSeq */
         sprintf(query, "select count(*) from %s where chrom = '%s' and strand = '%s' and cdsStart <= %u and cdsEnd >= %u",
-                refSeq, blastpTrack->chrom, blastpTrack->strand, blastpTrack->chromStart, blastpTrack->chromEnd);
+                queryTable, blastpTrack->chrom, blastpTrack->strand, blastpTrack->chromStart, blastpTrack->chromEnd);
         srRefSeq = sqlGetResult(conn, query);
         if ((row = sqlNextRow(srRefSeq)) != NULL)
         {
             geneCount = atoi(row[0]);
@@ -1859,9 +1872,9 @@
 
         if (geneCount == 1)
             {
                 sprintf(query, "select name, cdsStart, cdsEnd from %s where chrom = '%s' and strand = '%s' and cdsStart <= %u and cdsEnd >= %u",
-                        refSeq, blastpTrack->chrom, blastpTrack->strand, blastpTrack->chromStart, blastpTrack->chromEnd);
+                        queryTable, blastpTrack->chrom, blastpTrack->strand, blastpTrack->chromStart, blastpTrack->chromEnd);
                 srRefSeq = sqlGetResult(conn, query);
                 if ((row = sqlNextRow(srRefSeq)) != NULL)
                 {
                     strcpy(queryName, row[0]);
@@ -1873,9 +1886,9 @@
             else
             {
                 /* Check blastpHits if more than 1 query gene is found within the region */
                 sprintf(query, "select a.name, a.cdsStart, a.cdsEnd from %s a, %s b where a.chrom = '%s' and a.strand = '%s' and a.cdsStart <= %u and a.cdsEnd >= %u and a.name = b.query and b.target like '%%%s'",
-                        refSeq, blastpHits,
+                        queryTable, blastpHits,
                         blastpTrack->chrom, blastpTrack->strand, blastpTrack->chromStart, blastpTrack->chromEnd, targetGeneName[0]);
                 srRefSeq = sqlGetResult(conn, query);
                 if ((row = sqlNextRow(srRefSeq)) != NULL)
                 {
@@ -1971,8 +1984,10 @@
     char query[512];
     struct sqlResult *sr;
     char **row;
     char refSeq[50];
+    char xraTable[50];
+    char product[255];
     struct blastTab *blastpHits;
     struct minGeneInfo *ginfo;
     char *blastpTarget[2];
     char *clades[2];
@@ -1981,8 +1996,9 @@
     char clade[50] = "";
     unsigned int hitStart = 0;
     unsigned int hitEnd = 0;
     char **buffer = NULL;
+    boolean findTable = FALSE;
 
     int tStart = cartInt(cart, "o");
     int tEnd = cartInt(cart, "t");
     char *tChrom = cartString(cart, "c");
@@ -2026,19 +2042,37 @@
         {
             cladePortionCount = parseDelimitedString(clade, '-', clades, 2);
 
             printf("<tr style=\"vertical-align: top;\">\n");
-
             printf("<td><a name=\"%s:%s:%u-%u\"><i>%s</i></td>\n", blastpTarget[1], tChrom, tStart, tEnd, genome);
+            
         if (cladePortionCount == 1)
             printf("<td>%s</td>\n", clades[0]);
         else if (cladePortionCount == 2)
             printf("<td>%s<br>%s</td>\n", clades[0], clades[1]);
 
             /* Get target gene position from refSeq */
             strcpy(refSeq, blastpTarget[0]);
-            strcat(refSeq, ".refSeq");
-            if (hDbExists(blastpTarget[0]) && hTableExists(blastpTarget[0], "refSeq"))
+            strcat(refSeq, ".");
+            if (hDbExists(blastpTarget[0]))
+            {
+                if (hTableExists(blastpTarget[0], "lookup"))
+                {
+                    sprintf(query, "select lookupValue from %s.lookup where lookupCode = 'annotRev'", blastpTarget[0]);
+                    sr = sqlGetResult(conn, query);
+                    if ((row = sqlNextRow(sr)) != NULL)
+                    {
+                        strcat(refSeq, row[0]);
+                        findTable = TRUE;
+                        sqlFreeResult(&sr);
+                    }
+                }
+                else if (hTableExists(blastpTarget[0], "refSeq"))
+                {
+                    strcat(refSeq, "refSeq");
+                    findTable = TRUE;
+                }
+                if (findTable)
             {
                 sprintf(query, "select chrom, cdsStart, cdsEnd from %s where name = '%s'",
                         refSeq, blastpTarget[1]);
                 sr = sqlGetResult(conn, query);
@@ -2054,17 +2088,46 @@
                 sqlFreeResult(&sr);
             }
             else
                 printf("<td>%s</td>\n", blastpTarget[1]);
+            }
+            else
+                printf("<td>%s</td>\n", blastpTarget[1]);
 
             /* Get target gene product annotation */
             if (hDbExists(blastpTarget[0]))
             {
+                if (hTableExists(blastpTarget[0], "lookup"))
+                {
+                    sprintf(query, "select lookupValue from %s.lookup where lookupCode = 'annotRevXra'", blastpTarget[0]);
+                    sr = sqlGetResult(conn, query);
+                    if ((row = sqlNextRow(sr)) != NULL)
+                    {
+                        strcpy(xraTable, row[0]);
+                        sqlFreeResult(&sr);
+                    }
+                    else
+                        strcpy(product, "N/A");
+                        
+                    sprintf(query, "select product from %s.%s where name = '%s'", blastpTarget[0], xraTable, blastpTarget[1]);
+                    sr = sqlGetResult(conn, query);
+                    if ((row = sqlNextRow(sr)) != NULL)
+                    {
+                        strcpy(product, row[0]);
+                        sqlFreeResult(&sr);
+                    }
+                    else
+                        strcpy(product, "N/A");
+                }
+                else
+                {
                 ginfo = getGbProtCodeInfo(conn, blastpTarget[0], blastpTarget[1]);
                 if (ginfo != NULL && ginfo->product != NULL && differentString(ginfo->product,"none"))
-                    printf("<td>%s</td>\n", ginfo->product);
+                        strcpy(product, ginfo->product);
                 else
-                    printf("<td>%s</td>\n", "N/A");
+                        strcpy(product, "N/A");
+                }
+                printf("<td>%s</td>\n", product);
                 }
             else
                 printf("<td>%s</td>\n", "N/A");
 
@@ -2094,17 +2157,34 @@
 void doBlastP(struct trackDb *tdb, char *targetName)
 /* Handle the BlastP Archaea and BlastP Bacteria tracks. */
 {
     char queryName[50];
+    char queryTable[50];
     unsigned int querySeqLength = 0;
     struct sqlConnection *conn = hAllocConn(database);
     struct bed *blastpTrack;
     struct blastTab *blastpHitsList;
+    char query[512];
+    struct sqlResult *sr;
+    char **row;
 
     cartWebStart(cart, database, "%s", "BlastP Alignment Hits");
 
     blastpTrack = getBlastpTrackRecord(conn, tdb, targetName);
-    printQueryGeneInfo(conn, blastpTrack, queryName, &querySeqLength);
+
+    if (hTableExists(database, "lookup"))
+    {
+        sprintf(query, "select lookupValue from lookup where lookupCode = 'annotRev'");
+        sr = sqlGetResult(conn, query);
+        if ((row = sqlNextRow(sr)) != NULL)
+        {
+            strcpy(queryTable, row[0]);
+            sqlFreeResult(&sr);
+        }
+    }
+    else
+        strcpy(queryTable, "refSeq");
+    printQueryGeneInfo(conn, blastpTrack, queryName, &querySeqLength, queryTable);
 
     blastpHitsList = loadBlastpHits(conn, queryName);
 
     printBlastpResult(conn, blastpHitsList, querySeqLength);
@@ -2964,8 +3044,12 @@
 else if (sameWord(track, "refSeq"))
     {
     doRefSeq(tdb, item,"gbProtCodePep","gbProtCodeXra");
     }
+else if (startsWith("annotRev", track))
+    {
+    doRefSeq(tdb, item,"Pep","Xra");
+    }
 else if (sameWord(track, "sargassoSea"))
     {
     doSargassoSea(tdb, item);
     }

