27263de199a7c1410afad10fcfc6bdee0dedfb2f
braney
  Tue Feb 26 09:21:56 2013 -0800
some assembly hub fixes (non-chrom sequence dump, don't open db when not needed) #8072
diff --git src/hg/hgTracks/hgTracks.c src/hg/hgTracks/hgTracks.c
index a2201c3..72c26c5 100644
--- src/hg/hgTracks/hgTracks.c
+++ src/hg/hgTracks/hgTracks.c
@@ -46,30 +46,31 @@
 #include "cytoBand.h"
 #include "ensFace.h"
 #include "liftOver.h"
 #include "pcrResult.h"
 #include "jsHelper.h"
 #include "mafTrack.h"
 #include "hgConfig.h"
 #include "encode.h"
 #include "agpFrag.h"
 #include "imageV2.h"
 #include "suggest.h"
 #include "search.h"
 #include "errCatch.h"
 #include "iupac.h"
 #include "botDelay.h"
+#include "chromInfo.h"
 
 /* Other than submit and Submit all these vars should start with hgt.
  * to avoid weeding things out of other program's namespaces.
  * Because the browser is a central program, most of it's cart
  * variables are not hgt. qualified.  It's a good idea if other
  * program's unique variables be qualified with a prefix though. */
 char *excludeVars[] = { "submit", "Submit", "dirty", "hgt.reset",
             "hgt.in1", "hgt.in2", "hgt.in3", "hgt.inBase",
             "hgt.out1", "hgt.out2", "hgt.out3",
             "hgt.left1", "hgt.left2", "hgt.left3",
             "hgt.right1", "hgt.right2", "hgt.right3",
             "hgt.dinkLL", "hgt.dinkLR", "hgt.dinkRL", "hgt.dinkRR",
             "hgt.tui", "hgt.hideAll", "hgt.visAllFromCt",
 	    "hgt.psOutput", "hideControls", "hgt.toggleRevCmplDisp",
 	    "hgt.collapseGroups", "hgt.expandGroups", "hgt.suggest",
@@ -5370,33 +5371,120 @@
     printf("<A HREF=\"%s?%s=%u&position=%s\">%s</A>",
            hgTracksName(), cartSessionVarName(), cartSessionId(cart),
            chromPtr->name, chromPtr->name);
     cgiTableFieldEnd();
     cgiTableFieldStartAlignRight();
     printLongWithCommas(stdout, size);
     puts("&nbsp;&nbsp;");
     cgiTableFieldEnd();
     cgiTableRowEnd();
     total += size;
     }
 chromInfoTotalRow(slCount(chromList), total);
 slFreeList(&chromList);
 }
 
+static int  chromInfoCmpSize(const void *va, const void *vb)
+/* Compare to sort based on chrom size */
+{
+const struct chromInfo *a = *((struct chromInfo **)va);
+const struct chromInfo *b = *((struct chromInfo **)vb);
+
+return b->size - a->size;
+}
+
+void chromInfoRowsNonChromTrackHub(int limit)
+/* Make table rows of non-chromosomal chromInfo name & size */
+/* leaks chromInfo list */
+{
+struct chromInfo *chromInfo = trackHubAllChromInfo(database);
+slSort(&chromInfo, chromInfoCmpSize);
+int seqCount = slCount(chromInfo);
+long long total = 0;
+char msg1[512], msg2[512];
+boolean truncating;
+int count = limit;
+
+truncating = (limit > 0) && (seqCount > limit);
+
+for(;count-- && (chromInfo != NULL); chromInfo = chromInfo->next)
+    {
+    unsigned size = chromInfo->size;
+    cgiSimpleTableRowStart();
+    cgiSimpleTableFieldStart();
+    printf("<A HREF=\"%s?%s=%u&position=%s\">%s</A>",
+           hgTracksName(), cartSessionVarName(), cartSessionId(cart),
+           chromInfo->chrom,chromInfo->chrom);
+    cgiTableFieldEnd();
+    cgiTableFieldStartAlignRight();
+    printLongWithCommas(stdout, size);
+    puts("&nbsp;&nbsp;");
+    cgiTableFieldEnd();
+    cgiTableRowEnd();
+    total += size;
+    }
+if (!truncating)
+    {
+    chromInfoTotalRow(seqCount, total);
+    }
+else
+    {
+    safef(msg1, sizeof(msg1), "Limit reached");
+    safef(msg2, sizeof(msg2), "%d rows displayed", limit);
+    cgiSimpleTableRowStart();
+    cgiSimpleTableFieldStart();
+    puts(msg1);
+    cgiTableFieldEnd();
+    cgiSimpleTableFieldStart();
+    puts(msg2);
+    cgiTableFieldEnd();
+    for(;limit-- && (chromInfo != NULL); chromInfo = chromInfo->next)
+	total += chromInfo->size;
+
+    unsigned scafCount = seqCount;
+    unsigned totalSize = total;
+    cgiTableRowEnd();
+    safef(msg1, sizeof(msg1), "contig/scaffold<BR>count:");
+    safef(msg2, sizeof(msg2), "total size:");
+    cgiSimpleTableRowStart();
+    cgiSimpleTableFieldStart();
+    puts(msg1);
+    cgiTableFieldEnd();
+    cgiSimpleTableFieldStart();
+    puts(msg2);
+    cgiTableFieldEnd();
+    cgiTableRowEnd();
+    cgiSimpleTableRowStart();
+    cgiSimpleTableFieldStart();
+    printLongWithCommas(stdout, scafCount);
+    cgiTableFieldEnd();
+    cgiSimpleTableFieldStart();
+    printLongWithCommas(stdout, totalSize);
+    cgiTableFieldEnd();
+    cgiTableRowEnd();
+    }
+}
+
 void chromInfoRowsNonChrom(int limit)
 /* Make table rows of non-chromosomal chromInfo name & size, sorted by size. */
 {
+if (trackHubDatabase(database))
+    {
+    chromInfoRowsNonChromTrackHub(limit);
+    return;
+    }
+
 struct sqlConnection *conn = hAllocConn(database);
 struct sqlResult *sr = NULL;
 char **row = NULL;
 long long total = 0;
 char query[512];
 char msg1[512], msg2[512];
 int seqCount = 0;
 boolean truncating;
 
 seqCount = sqlQuickNum(conn, "select count(*) from chromInfo");
 truncating = (limit > 0) && (seqCount > limit);
 
 if (!truncating)
     {
     sr = sqlGetResult(conn, "select chrom,size from chromInfo order by size desc");