483716a7cd43a3c24c9b3273206f37021fe3f2d7
kent
  Tue Jan 11 17:58:48 2011 -0800
Adding hub support to hgc.
diff --git src/hg/lib/hubConnect.c src/hg/lib/hubConnect.c
index 9325832..a1d1222 100644
--- src/hg/lib/hubConnect.c
+++ src/hg/lib/hubConnect.c
@@ -1,30 +1,31 @@
 /* hubConnect - stuff to manage connections to track hubs.  Most of this is mediated through
  * the hubConnect table in the hgCentral database.  Here there are routines to translate between
  * hub symbolic names and hub URLs,  to see if a hub is up or down or sideways (up but badly
  * formatted) etc.  Note that there is no C structure corresponding to a row in the hubConnect 
  * table by design.  We just want field-by-field access to this. */
 
 #include "common.h"
 #include "linefile.h"
 #include "hash.h"
 #include "dystring.h"
 #include "sqlNum.h"
 #include "jksql.h"
 #include "hdb.h"
 #include "trackHub.h"
 #include "hubConnect.h"
+#include "hui.h"
 
 
 boolean isHubTrack(char *trackName)
 /* Return TRUE if it's a hub track. */
 {
 return startsWith(hubTrackPrefix, trackName);
 }
 
 boolean hubConnectTableExists()
 /* Return TRUE if the hubConnect table exists. */
 {
 struct sqlConnection *conn = hConnectCentral();
 boolean exists = sqlTableExists(conn, hubConnectTableName);
 hDisconnectCentral(&conn);
 return exists;
@@ -141,15 +142,47 @@
     }
 slFreeList(&nameList);
 hDisconnectCentral(&conn);
 slReverse(&hubList);
 return hubList;
 }
 
 int hubIdFromTrackName(char *trackName)
 /* Given something like "hub_123_myWig" return 123 */
 {
 assert(startsWith("hub_", trackName));
 trackName += 4;
 assert(isdigit(trackName[0]));
 return atoi(trackName);
 }
+
+struct trackDb *hubConnectAddHubForTrackAndFindTdb(char *database, 
+	char *trackName, struct trackDb **pTdbList, struct hash *trackHash)
+/* Go find hub for trackName (which will begin with hub_), and load the tracks
+ * for it, appending to end of list and adding to trackHash.  Return the
+ * trackDb associated with trackName.  */
+{
+int hubId = hubIdFromTrackName(trackName);
+struct sqlConnection *conn = hConnectCentral();
+struct hubConnectStatus *hubStatus = hubConnectStatusForId(conn, hubId);
+hDisconnectCentral(&conn);
+if (hubStatus == NULL)
+    errAbort("The hubId %d was not found", hubId);
+if (!isEmpty(hubStatus->errorMessage))
+    errAbort("Hub %s at %s has the error: %s", hubStatus->shortLabel, 
+	    hubStatus->hubUrl, hubStatus->errorMessage);
+char hubName[16];
+safef(hubName, sizeof(hubName), "%d", hubId);
+struct trackHub *hub = trackHubOpen(hubStatus->hubUrl, hubName);
+struct trackHubGenome *hubGenome = trackHubFindGenome(hub, database);
+struct trackDb *tdbList = trackHubTracksForGenome(hub, hubGenome);
+tdbList = trackDbLinkUpGenerations(tdbList);
+tdbList = trackDbPolishAfterLinkup(tdbList, database);
+rAddTrackListToHash(trackHash, tdbList, NULL, FALSE);
+if (pTdbList != NULL)
+    *pTdbList = slCat(*pTdbList, tdbList);
+struct trackDb *tdb = hashFindVal(trackHash, trackName);
+if (tdb == NULL)
+    errAbort("Can't find track %s in %s", trackName, hubStatus->hubUrl);
+return tdb;
+}
+