static void printActiveGenomes() /* Print out JSON for an object mapping each genome that has at least one db with active=1 * to its taxId. */ { struct jsonWrite *jw = jsonWriteNew(); jsonWriteObjectStart(jw, NULL); struct sqlConnection *conn = hConnectCentral(); // Join with defaultDb because in rare cases, different taxIds (species vs. subspecies) // may be used for different assemblies of the same species. Using defaultDb means that // we send a taxId consistent with the taxId of the assembly that we'll change to when // the species is selected from the tree. char *query = NOSQLINJ "select dbDb.genome, taxId, dbDb.name from dbDb, defaultDb " "where defaultDb.name = dbDb.name and active = 1 " "and taxId > 1;"; // filter out experimental hgwdev-only stuff with invalid taxIds struct sqlResult *sr = sqlGetResult(conn, query); char **row; while ((row = sqlNextRow(sr)) != NULL) { char *genome = row[0], *db = row[2]; int taxId = atoi(row[1]); if (hDbExists(db)) jsonWriteNumber(jw, genome, taxId); } hDisconnectCentral(&conn); jsonWriteObjectEnd(jw); puts(jw->dy->string); jsonWriteFree(&jw); }
static unsigned getHubId(char *url, char **errorMessage) /* find id for url in hubStatus table */ { struct sqlConnection *conn = hConnectCentral(); char query[4096]; char **row; boolean foundOne = FALSE; int id = 0; char *statusTableName = getHubStatusTableName(); sqlSafef(query, sizeof(query), "select id,errorMessage from %s where hubUrl = \"%s\"", statusTableName, url); struct sqlResult *sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { if (foundOne) errAbort("more than one line in %s with hubUrl %s\n", statusTableName, url); foundOne = TRUE; char *thisId = row[0], *thisError = row[1]; if (!isEmpty(thisError)) *errorMessage = cloneString(thisError); id = sqlUnsigned(thisId); } sqlFreeResult(&sr); hDisconnectCentral(&conn); return id; }
void findClosestServer(char **pDb, char **pOrg) /* If db doesn't have a blat server, look for the closest db (or org) that has one, * as hgPcr does. */ { char *db = *pDb, *org = *pOrg; struct sqlConnection *conn = hConnectCentral(); char query[256]; safef(query, sizeof(query), "select db from blatServers where db = '%s'", db); if (!sqlExists(conn, query)) { safef(query, sizeof(query), "select blatServers.db from blatServers,dbDb " "where blatServers.db = dbDb.name and dbDb.genome = '%s'", org); char *db = sqlQuickString(conn, query); if (db == NULL) { safef(query, sizeof(query), "select blatServers.db from blatServers,dbDb " "where blatServers.db = dbDb.name order by dbDb.orderKey,dbDb.name desc"); char *db = sqlQuickString(conn, query); if (db == NULL) errAbort("central database tables blatServers and dbDb are disjoint/empty"); else { *pDb = db; *pOrg = hGenome(db); } } else { *pDb = db; *pOrg = hGenome(db); } } hDisconnectCentral(&conn); }
static char *ccFreezeDbConversion(char *database, char *freeze, char *org) /* Find freeze given database or vice versa. Pass in NULL * for parameter that is unknown and it will be returned * as a result. This result can be freeMem'd when done. */ { struct sqlConnection *conn = hConnectCentral(); struct sqlResult *sr; char **row; char *ret = NULL; struct dyString *dy = newDyString(128); if (database != NULL) dyStringPrintf(dy, "select description from dbDb where name = '%s' and (genome like '%s' or genome like 'Zoo')", database, org); else if (freeze != NULL) dyStringPrintf(dy, "select name from dbDb where description = '%s' and (genome like '%s' or genome like 'Zoo')", freeze, org); else internalErr(); sr = sqlGetResult(conn, dy->string); if ((row = sqlNextRow(sr)) != NULL) ret = cloneString(row[0]); sqlFreeResult(&sr); hDisconnectCentral(&conn); freeDyString(&dy); return ret; }
struct pcrServer *getServerList() /* Get list of available servers. */ { struct pcrServer *serverList = NULL, *server; struct sqlConnection *conn = hConnectCentral(); struct sqlResult *sr; char **row; /* Do a little join to get data to fit into the pcrServer. */ sr = sqlGetResult(conn, "NOSQLINJ select dbDb.name,dbDb.genome,dbDb.description,blatServers.host," "blatServers.port,dbDb.nibPath " "from dbDb,blatServers where " "dbDb.name = blatServers.db " "and blatServers.canPcr = 1 order by dbDb.orderKey" ); while ((row = sqlNextRow(sr)) != NULL) { AllocVar(server); server->db = cloneString(row[0]); server->genome = cloneString(row[1]); server->description = cloneString(row[2]); server->host = cloneString(row[3]); server->port = cloneString(row[4]); server->seqDir = hReplaceGbdbSeqDir(row[5], server->db); slAddHead(&serverList, server); } sqlFreeResult(&sr); hDisconnectCentral(&conn); if (serverList == NULL) errAbort("Sorry, no PCR servers are available"); slReverse(&serverList); return serverList; }
int hubTrackSettings(char *hubUrl, struct hash *totals) /* Read hub trackDb files, noting settings used. If hubUrl is NULL, do this for * all public hubs */ { if (hubUrl != NULL) return oneHubTrackSettings(hubUrl, totals); // Get all urls from hubPublic table struct sqlConnection *conn = hConnectCentral(); char query[1024]; // NOTE: don't bother with site-local names for these tables /* sqlSafef(query, sizeof(query), "select hubUrl from %s where hubUrl not in (select hubUrl from %s)\n", defaultHubPublicTableName, defaultHubStatusTableName); */ sqlSafef(query, sizeof(query), "select hubUrl from %s where shortLabel not like '%%Test%%'", defaultHubPublicTableName); struct slName *hub, *hubs = sqlQuickList(conn, query); int errs = 0; for (hub = hubs; hub != NULL; hub = hub->next) { errs += oneHubTrackSettings(hub->name, totals); } if (totals) printCounts(totals); return errs; }
static void disconnectHubsSamePrefix(struct cart *cart, char *url) /* disconnect all the hubs with the same prefix */ { char *prefix = cloneString(url); char *ptr = strrchr(prefix, '/'); if (ptr == NULL) return; *ptr = 0; char query[2048]; sqlSafef(query, sizeof(query), "select id from %s where hubUrl like \"%s%%\"", getHubStatusTableName(), prefix); struct sqlConnection *conn = hConnectCentral(); struct sqlResult *sr = sqlGetResult(conn, query); char **row; while ((row = sqlNextRow(sr)) != NULL) { int id = sqlUnsigned(row[0]); char buffer[512]; safef(buffer, sizeof(buffer), "hgHubConnect.hub.%d", id); cartRemove(cart, buffer); } sqlFreeResult(&sr); hDisconnectCentral(&conn); }
boolean hubConnectTableExists() /* Return TRUE if the hubStatus table exists. */ { struct sqlConnection *conn = hConnectCentral(); boolean exists = sqlTableExists(conn, getHubStatusTableName()); hDisconnectCentral(&conn); return exists; }
void checkForGeoMirrorRedirect(struct cart *cart) // Implement Geo/IP based redirection. { char *thisNodeStr = geoMirrorNode(); if (thisNodeStr) // if geo-mirroring is enabled { char *redirectCookie = findCookieData("redirect"); char *redirect = cgiOptionalString("redirect"); // if we're not already redirected if (redirect == NULL && redirectCookie == NULL) { int thisNode = sqlUnsigned(thisNodeStr); struct sqlConnection *centralConn = hConnectCentral(); char *ipStr = cgiRemoteAddr(); int node = defaultNode(centralConn, ipStr); // if our node is not the node that's closest. if (thisNode != node) { char *geoSuffix = cfgOptionDefault("browser.geoSuffix",""); char query[1056]; sqlSafef(query, sizeof query, "select domain from gbNode%s where node = %d", geoSuffix, node); char *newDomain = sqlQuickString(centralConn, query); char *oldDomain = cgiServerName(); char *port = cgiServerPort(); char *uri = cgiRequestUri(); char *sep = strchr(uri, '?') ? "&" : "?"; int newUriSize = strlen(uri) + 1024; char *newUri = needMem(newUriSize); char *oldUri = needMem(newUriSize); safef(oldUri, newUriSize, "http%s://%s:%s%s%sredirect=manual&source=%s", cgiServerHttpsIsOn() ? "s" : "", oldDomain, port, uri, sep, oldDomain); safef(newUri, newUriSize, "http%s://%s:%s%s%sredirect=manual&source=%s", cgiServerHttpsIsOn() ? "s" : "", newDomain, port, uri, sep, oldDomain); printf("<TR><TD COLSPAN=3 id='redirectTd' onclick=\"javascript:document.getElementById('redirectTd').innerHTML='';\">" "<div style=\"margin: 10px 25%%; border-style:solid; border-width:thin; border-color:#97D897;\">" "<h3 style=\"background-color: #97D897; text-align: left; margin-top:0px; margin-bottom:0px;\">" " You might want to navigate to your nearest mirror - %s" "</h3> " "<ul style=\"margin:5px;\">", newDomain); printf("<li>User settings (sessions and custom tracks) <B>will differ</B> between sites." "<idiv style=\"float:right;\"><a href=\"../goldenPath/help/genomeEuro.html#sessions\">Read more.</a></idiv>"); printf("<li>Take me to <a href=\"%s\">%s</a> </li>", newUri, newDomain); printf("<li>Let me stay here <a href=\"%s\">%s</a>", oldUri, oldDomain ); printf("</div></TD></TR>\n"); exit(0); } hDisconnectCentral(¢ralConn); } } }
char *hubNameFromUrl(char *hubUrl) /* Given the URL for a hub, return its hub_# name. */ { char query[PATH_LEN*4]; sqlSafef(query, sizeof(query), "select concat('hub_', id) from %s where hubUrl = '%s'", getHubStatusTableName(), hubUrl); struct sqlConnection *conn = hConnectCentral(); char *name = sqlQuickString(conn, query); hDisconnectCentral(&conn); return name; }
struct serverTable *findServer(char *db, boolean isTrans) /* Return server for given database. Db can either be * database name or description. */ { if (trackHubDatabase(db)) { struct serverTable *hubSt = trackHubServerTable(db, isTrans); if (hubSt != NULL) return hubSt; errAbort("Cannot get blat server parameters for track hub with database %s\n", db); } static struct serverTable st; struct sqlConnection *conn = hConnectCentral(); char query[256]; struct sqlResult *sr; char **row; char dbActualName[32]; /* If necessary convert database description to name. */ sqlSafef(query, sizeof(query), "select name from dbDb where name = '%s'", db); if (!sqlExists(conn, query)) { sqlSafef(query, sizeof(query), "select name from dbDb where description = '%s'", db); if (sqlQuickQuery(conn, query, dbActualName, sizeof(dbActualName)) != NULL) db = dbActualName; } /* Do a little join to get data to fit into the serverTable. */ sqlSafef(query, sizeof(query), "select dbDb.name,dbDb.description,blatServers.isTrans" ",blatServers.host,blatServers.port,dbDb.nibPath " "from dbDb,blatServers where blatServers.isTrans = %d and " "dbDb.name = '%s' and dbDb.name = blatServers.db", isTrans, db); sr = sqlGetResult(conn, query); if ((row = sqlNextRow(sr)) == NULL) { errAbort("Can't find a server for %s database %s. Click " "<A HREF=\"/cgi-bin/hgBlat?%s&command=start&db=%s\">here</A> " "to reset to default database.", (isTrans ? "translated" : "DNA"), db, cartSidUrlString(cart), hDefaultDb()); } st.db = cloneString(row[0]); st.genome = cloneString(row[1]); st.isTrans = atoi(row[2]); st.host = cloneString(row[3]); st.port = cloneString(row[4]); st.nibDir = hReplaceGbdbSeqDir(row[5], st.db); sqlFreeResult(&sr); hDisconnectCentral(&conn); return &st; }
int searchProteinsInSupportedGenomes(char *queryID, char **database) /* search existing genome databases to see if they contain the protein Input: queryID return: number of proteins found in existing genome databases output: the last genome database is stored at *database */ { int pbProteinCnt = {0}; char *gDatabase; char *org = NULL; char cond_str[255]; struct sqlConnection *conn; struct sqlConnection *connCentral; char queryCentral[256]; struct sqlResult *srCentral; char **row3; char *answer; /* get all genome DBs that support PB */ connCentral = hConnectCentral(); sqlSafef(queryCentral, sizeof(queryCentral), "select defaultDb.name, dbDb.organism from dbDb,defaultDb where hgPbOk=1 and defaultDb.name=dbDb.name"); srCentral = sqlMustGetResult(connCentral, queryCentral); row3 = sqlNextRow(srCentral); /* go through each valid genome database that has PB */ while (row3 != NULL) { gDatabase = row3[0]; org = row3[1]; conn = sqlConnect(gDatabase); sqlSafefFrag(cond_str, sizeof(cond_str), "alias='%s'", queryID); answer = sqlGetField(gDatabase, "kgSpAlias", "count(distinct spID)", cond_str); sqlDisconnect(&conn); if ((answer != NULL) && (!sameWord(answer, "0"))) { /* increase the count only by one, because new addition of splice variants to kgSpAlias would give a count of 2 for both the parent and the variant, which caused the problem when rescale button is pressed */ if (atoi(answer) > 0) pbProteinCnt++; *database = strdup(gDatabase); } row3 = sqlNextRow(srCentral); } sqlFreeResult(&srCentral); hDisconnectCentral(&connCentral); return(pbProteinCnt); }
struct hubConnectStatus *hubFromId(unsigned hubId) /* Given a hub ID number, return corresponding trackHub structure. * ErrAbort if there's a problem. */ { struct sqlConnection *conn = hConnectCentral(); struct hubConnectStatus *status = hubConnectStatusForId(conn, hubId); hDisconnectCentral(&conn); if (status == NULL) errAbort("The hubId %d was not found", hubId); if (!isEmpty(status->errorMessage)) errAbort("%s", status->errorMessage); return status; }
char *hDbOrganism(char *database) /* Function to get organism from the genome db */ { struct sqlConnection *connCentral = hConnectCentral(); char buf[128]; char query[256]; char *res; sqlSafef(query, sizeof(query), "select organism from dbDb where name = '%s'", database); res = strdup(sqlQuickQuery(connCentral, query, buf, sizeof(buf))); hDisconnectCentral(&connCentral); return res; }
static void insertHubUrlInStatus(char *url) /* add a url to the hubStatus table */ { struct sqlConnection *conn = hConnectCentral(); char query[4096]; char *statusTable = getHubStatusTableName(); if (sqlFieldIndex(conn, statusTable, "firstAdded") >= 0) sqlSafef(query, sizeof(query), "insert into %s (hubUrl,firstAdded) values (\"%s\",now())", statusTable, url); else sqlSafef(query, sizeof(query), "insert into %s (hubUrl) values (\"%s\")", statusTable, url); sqlUpdate(conn, query); hDisconnectCentral(&conn); }
static void tryHubOpen(unsigned id) /* try to open hub, leaks trackHub structure */ { /* try opening this again to reset error */ struct sqlConnection *conn = hConnectCentral(); struct errCatch *errCatch = errCatchNew(); struct hubConnectStatus *hub = NULL; if (errCatchStart(errCatch)) hub = hubConnectStatusForId(conn, id); errCatchEnd(errCatch); if (errCatch->gotError) hubUpdateStatus( errCatch->message->string, NULL); else hubUpdateStatus(NULL, hub); errCatchFree(&errCatch); hDisconnectCentral(&conn); }
static char *genomeDbForImage(struct sqlConnection *conn, int imageId) /* Return the genome database to associate with image or NULL if none. */ { char *db; char *scientificName = visiGeneOrganism(conn, imageId); struct sqlConnection *cConn = hConnectCentral(); char query[256]; safef(query, sizeof(query), "select defaultDb.name from defaultDb,dbDb where " "defaultDb.genome = dbDb.organism and " "dbDb.active = 1 and " "dbDb.scientificName = '%s'" , scientificName); db = sqlQuickString(cConn, query); hDisconnectCentral(&cConn); return db; }
struct hash *hgHubConnectPublic() /* Put up the list of public hubs and other controls for the page. */ { struct hash *retHash = NULL; struct sqlConnection *conn = hConnectCentral(); char *publicTable = cfgOptionEnvDefault("HGDB_HUB_PUBLIC_TABLE", hubPublicTableConfVariable, defaultHubPublicTableName); if (!(sqlTableExists(conn, publicTable) && (retHash = outputPublicTable(conn, publicTable)) != NULL )) { printf("<div id=\"publicHubs\" class=\"hubList\"> \n"); printf("No Public Track Hubs for this genome assembly<BR>"); printf("</div>"); } hDisconnectCentral(&conn); return retHash; }
static struct aHubMatch *filterTrixSearchMatches(struct dbDb *dbDbList, struct trixSearchResult *tsrList) /* Collect the assembly hub matches (not track hub matches) from a search in hub trix files. */ { if (tsrList == NULL) return NULL; struct aHubMatch *aHubMatchList = NULL; // Make a hash of local dbs so we can tell which hub dbs must be assembly hubs // not track hubs. struct hash *localDbs = hashNew(0); struct dbDb *dbDb; for (dbDb = dbDbList; dbDb != NULL; dbDb = dbDb->next) hashStore(localDbs, dbDb->name); // tsrList gives hub URLs which we can then look up in hubPublic. struct dyString *query = sqlDyStringCreate("select shortLabel,hubUrl,dbList from %s " "where hubUrl in (", hubPublicTableName()); struct trixSearchResult *tsr; for (tsr = tsrList; tsr != NULL; tsr = tsr->next) { if (tsr != tsrList) dyStringAppend(query, ", "); dyStringPrintf(query, "'%s'", tsr->itemId); } dyStringAppendC(query, ')'); struct sqlConnection *conn = hConnectCentral(); struct sqlResult *sr = sqlGetResult(conn, query->string); char **row; while ((row = sqlNextRow(sr)) != NULL) { char *shortLabel = row[0]; char *hubUrl = row[1]; struct slName *dbName, *dbList = slNameListFromComma(row[2]); for (dbName = dbList; dbName != NULL; dbName = dbName->next) if (! hashLookup(localDbs, dbName->name)) { slAddHead(&aHubMatchList, aHubMatchNew(shortLabel, hubUrl, dbName->name)); } } slReverse(&aHubMatchList); hDisconnectCentral(&conn); return aHubMatchList; }
void printCladeListHtml(char *genome, char *onChangeText) /* Make an HTML select input listing the clades. */ { char **row = NULL; char *clades[128]; char *labels[128]; char *defaultClade = hClade(genome); char *defaultLabel = NULL; int numClades = 0; struct sqlConnection *conn = hConnectCentral(); // after hClade since it access hgcentral too // get only the clades that have actual active genomes char query[4096]; safef(query, sizeof query, "NOSQLINJ SELECT DISTINCT(c.name), c.label FROM %s c, %s g, %s d WHERE c.name=g.clade AND d.organism=g.genome AND d.active=1 ORDER BY c.priority", cladeTable(),genomeCladeTable(), dbDbTable()); struct sqlResult *sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { clades[numClades] = cloneString(row[0]); labels[numClades] = cloneString(row[1]); if (sameWord(defaultClade, clades[numClades])) defaultLabel = clades[numClades]; numClades++; if (numClades >= ArraySize(clades)) internalErr(); } sqlFreeResult(&sr); hDisconnectCentral(&conn); struct slPair *names = trackHubGetCladeLabels(); for(; names; names = names->next) { clades[numClades] = names->name; labels[numClades] = names->val; if (sameWord(defaultClade, clades[numClades])) defaultLabel = clades[numClades]; numClades++; if (numClades >= ArraySize(clades)) internalErr(); } cgiMakeDropListFull(cladeCgiName, labels, clades, numClades, defaultLabel, onChangeText); }
void getChromNamesAndDirForDb(char *db) { struct sqlConnection *conn = hConnectCentral(); char query[512]; char buff[512]; char *tmpMark = NULL; int buffSize = 512; sqlSafef(query, sizeof(query), "select nibPath from dbDb where name='%s'", db); if(sqlQuickQuery(conn, query, buff, buffSize) == NULL) errAbort("Coun't find nib dir for genome %s\n", db); dirName = needMem(buffSize*sizeof(char)); tmpMark = strrchr(buff, '/'); if(tmpMark != NULL) *tmpMark = '\0'; snprintf(dirName, buffSize, "%s/mixedNib/", buff); chromNames = hAllChromNames(); hDisconnectCentral(&conn); }
struct hubConnectStatus *hubConnectStatusListFromCartAll(struct cart *cart) /* Return list of all track hubs that are referenced by cart. */ { struct hubConnectStatus *hubList = NULL, *hub; struct slPair *pair, *pairList = cartVarsWithPrefix(cart, hgHubConnectHubVarPrefix); struct sqlConnection *conn = hConnectCentral(); for (pair = pairList; pair != NULL; pair = pair->next) { int id = hubIdFromCartName(pair->name); hub = hubConnectStatusForId(conn, id); if (hub != NULL) { slAddHead(&hubList, hub); } } slFreeList(&pairList); hDisconnectCentral(&conn); slReverse(&hubList); return hubList; }
struct hubConnectStatus *hubConnectStatusListFromCart(struct cart *cart) /* Return list of track hubs that are turned on by user in cart. */ { struct hubConnectStatus *hubList = NULL, *hub; struct slName *name, *nameList = hubConnectHubsInCart(cart); struct sqlConnection *conn = hConnectCentral(); for (name = nameList; name != NULL; name = name->next) { int id = sqlSigned(name->name); hub = hubConnectStatusForId(conn, id); if (hub != NULL) { slAddHead(&hubList, hub); } } slFreeList(&nameList); hDisconnectCentral(&conn); slReverse(&hubList); return hubList; }
unsigned hubClearStatus(char *url) /* drop the information about this url from the hubStatus table */ { struct sqlConnection *conn = hConnectCentral(); char query[512]; sqlSafef(query, sizeof(query), "select id from %s where hubUrl = \"%s\"", getHubStatusTableName(), url); unsigned id = sqlQuickNum(conn, query); if (id == 0) errAbort("could not find url %s in status table (%s)\n", url, getHubStatusTableName()); sqlSafef(query, sizeof(query), "delete from %s where hubUrl = \"%s\"", getHubStatusTableName(), url); sqlUpdate(conn, query); hDisconnectCentral(&conn); return id; }
unsigned hubResetError(char *url) /* clear the error for this url in the hubStatus table,return the id */ { struct sqlConnection *conn = hConnectCentral(); char query[512]; sqlSafef(query, sizeof(query), "select id from %s where hubUrl = \"%s\"", getHubStatusTableName(), url); unsigned id = sqlQuickNum(conn, query); if (id == 0) errAbort("could not find url %s in status table (%s)\n", url, getHubStatusTableName()); sqlSafef(query, sizeof(query), "update %s set errorMessage=\"\" where hubUrl = \"%s\"", getHubStatusTableName(), url); sqlUpdate(conn, query); hDisconnectCentral(&conn); return id; }
struct targetPcrServer *getTargetServerList(char *db, char *name) /* Get list of available non-genomic-assembly target pcr servers associated * with db (and name, if not NULL). There may be none -- that's fine. */ { struct targetPcrServer *serverList = NULL, *server; struct sqlConnection *conn = hConnectCentral(); struct sqlConnection *conn2 = hAllocConn(db); struct sqlResult *sr; char **row; struct dyString *dy = dyStringNew(0); sqlDyStringPrintf(dy, "select b.host, b.port, t.* from targetDb as t, blatServers as b " "where b.db = t.name and t.db = '%s' and b.canPcr = 1 ", db); if (isNotEmpty(name)) sqlDyStringPrintf(dy, "and t.name = '%s' ", name); dyStringAppend(dy, "order by t.priority"); sr = sqlGetResult(conn, dy->string); while ((row = sqlNextRow(sr)) != NULL) { /* Keep this server only if its timestamp is newer than the tables * and file on which it depends. */ struct targetDb *target = targetDbMaybeLoad(conn2, row+2); if (target != NULL) { AllocVar(server); server->host = cloneString(row[0]); server->port = cloneString(row[1]); server->targetDb = target; slAddHead(&serverList, server); } } dyStringFree(&dy); sqlFreeResult(&sr); hDisconnectCentral(&conn); hFreeConn(&conn2); slReverse(&serverList); return serverList; }
void hubUpdateStatus(char *errorMessage, struct hubConnectStatus *hub) /* set the error message in the hubStatus table */ { struct sqlConnection *conn = hConnectCentral(); char query[64 * 1024]; struct trackHub *tHub = NULL; if (hub != NULL) tHub = hub->trackHub; if (errorMessage != NULL) { // make sure there is no newline at the end. This should be unneccesary // but there are many, many places where newlines are added in calls // to warn and errAbort char buffer[64 * 1024]; safecpy(buffer, sizeof buffer, errorMessage); while (lastChar(buffer) == '\n') buffer[strlen(buffer) - 1] = '\0'; sqlSafef(query, sizeof(query), "update %s set errorMessage=\"%s\", lastNotOkTime=now() where id=%d", getHubStatusTableName(), buffer, hub->id); sqlUpdate(conn, query); } else if (tHub != NULL) { int dbCount = 0; char *dbList = getDbList(tHub, &dbCount); // users may include quotes in their hub names requiring escaping sqlSafef(query, sizeof(query), "update %s set shortLabel=\"%s\",longLabel=\"%s\",dbCount=\"%d\",dbList=\"%s\",errorMessage=\"\",lastOkTime=now() where id=%d", getHubStatusTableName(), tHub->shortLabel, tHub->longLabel, dbCount, dbList, hub->id); sqlUpdate(conn, query); } hDisconnectCentral(&conn); }
struct dbDb *loadDbInformation_mod(char *database) /* load up the information for a particular draft */ { struct sqlConnection *conn = hConnectCentral(); struct sqlResult *sr = NULL; char **row; struct dbDb *dbList = NULL, *db = NULL; char query[256]; snprintf(query, sizeof(query), "select * from dbDb where name='%s'", database); /* Scan through dbDb table, loading into list */ sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { db = dbDbLoad(row); slAddHead(&dbList, db); } sqlFreeResult(&sr); hDisconnectCentral(&conn); if(slCount(dbList) != 1) errAbort("coordConv.c::loadDbInformation() - expecting 1 dbDb record for %s got %d", db, slCount(dbList)); return dbList; }
struct galleryEntry *galleryFetch() /* Return an slList of gallery entries fetched from hgcentral */ { struct sqlConnection *conn = hConnectCentral(); struct sqlResult *sr = NULL; struct galleryEntry *gal, *galList = NULL; char otherConstraints[80] = "", query[2048], **row; sqlSafef (query, sizeof(query), "select m.realName, s.userName, m.idx, s.sessionName, s.useCount, s.settings, s.contents, s.firstUse from " "%s s left join gbMembers m on m.userName = s.userName where shared = 2%s limit 30" , namedSessionTable, otherConstraints); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { gal = galLoad(row); slAddHead (&galList, gal); } sqlFreeResult(&sr); hDisconnectCentral(&conn); return galList; }
void makeActiveImagePB(char *psOutput, char *psOutput2) /* Make image and image map. */ { char *mapName = "map"; int pixWidth, pixHeight; char *answer; char cond_str[255]; struct sqlConnection *conn; struct sqlConnection *connCentral; char query[256]; struct sqlResult *sr; char **row; int iypos; char *blatGbDb; char *sciName, *commonName; char *spDisplayId; char *oldDisplayId; conn = sqlConnect(UNIPROT_DB_NAME); hPrintf("<br><font size=4>Protein "); hPrintf("<A HREF=\"http://www.uniprot.org/uniprot/%s\" TARGET=_blank><B>%s</B></A>\n", proteinID, proteinID); spDisplayId = spAccToId(conn, spFindAcc(conn, proteinID)); if (strstr(spDisplayId, spFindAcc(conn, proteinID)) == 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)) { hPrintf(" or %s", oldSpDisplayId(spDisplayId)); } } hPrintf(")\n"); } hPrintf(" %s\n", description); hPrintf("</font><br>"); hPrintf("Organism: "); /* get scientific and Genbank common name of this organism */ sciName = NULL; commonName = NULL; sqlSafefFrag(cond_str, sizeof(cond_str),"accession='%s'", proteinID); answer = sqlGetField(PROTEOME_DB_NAME, "spXref3", "division", cond_str); if (answer != NULL) { sqlSafefFrag(cond_str, sizeof(cond_str), "id=%s and nameType='scientific name'", answer); sciName = sqlGetField(PROTEOME_DB_NAME, "taxonNames", "name", cond_str); sqlSafefFrag(cond_str, sizeof(cond_str), "id=%s and nameType='genbank common name'", answer); commonName = sqlGetField(PROTEOME_DB_NAME, "taxonNames", "name", cond_str); } if (sciName != NULL) { hPrintf("%s", sciName); } if (commonName != NULL) { hPrintf(" (%s)", commonName); } hPrintf("<br>"); protSeq = getAA(proteinID); if (protSeq == NULL) { hUserAbort("%s is not a current valid entry in UniProtKB\n", proteinID); } protSeqLen = strlen(protSeq); fflush(stdout); iypos = 15; doTracks(proteinID, mrnaID, protSeq, &iypos, psOutput); if (!hTableExists(database, "pbStamp")) goto histDone; pbScale = 3; pixWidth = 765; insideWidth = pixWidth-gfxBorder; pixHeight = 350; if (psOutput2) { vg2 = vgOpenPostScript(pixWidth, pixHeight, psOutput2); } else { trashDirFile(&gifTn2, "pbt", "pbt", ".png"); vg2 = vgOpenPng(pixWidth, pixHeight, gifTn2.forCgi, FALSE); } g_vg = vg2; pbRed = vgFindColorIx(vg2, 0xf9, 0x51, 0x59); pbBlue = vgFindColorIx(g_vg, 0x00, 0x00, 0xd0); normalColor = pbBlue; abnormalColor = pbRed; bkgColor = vgFindColorIx(vg2, 255, 254, 232); vgBox(vg2, 0, 0, insideWidth, pixHeight, bkgColor); /* Start up client side map. */ mapName=cloneString("pbStamps"); hPrintf("\n<MAP Name=%s>\n", mapName); vgSetClip(vg2, 0, gfxBorder, insideWidth, pixHeight - 2*gfxBorder); iypos = 15; /* Draw stamps. */ doStamps(proteinID, mrnaID, protSeq, vg2, &iypos); /* Finish map. */ hPrintf("</MAP>\n"); /* Save out picture and tell html file about it. */ vgClose(&vg2); hPrintf("<P>"); hPrintf("\n<IMG SRC=\"%s\" BORDER=1 WIDTH=%d HEIGHT=%d USEMAP=#%s><BR>", gifTn2.forCgi, pixWidth, pixHeight, mapName); if (proteinInSupportedGenome) { hPrintf("\n<A HREF=\"../goldenPath/help/pbTracksHelpFiles/pbTracksHelp.shtml#histograms\" TARGET=_blank>"); } else { hPrintf("\n<A HREF=\"../goldenPath/help/pbTracksHelpFiles/pbTracksHelp.shtml#histograms\" TARGET=_blank>"); } hPrintf("Explanation of Protein Property Histograms</A><BR>"); hPrintf("<P>"); histDone: hPrintf("<P>"); fflush(stdout); /* See if a UCSC Genome Browser exist for this organism. If so, display BLAT link. */ connCentral = hConnectCentral(); sqlSafef(query, sizeof(query), "select defaultDb.name from dbDb, defaultDb where dbDb.scientificName='%s' and dbDb.name=defaultDb.name", sciName); sr = sqlGetResult(connCentral, query); row = sqlNextRow(sr); if (row != NULL) { blatGbDb = strdup(row[0]); } else { blatGbDb = NULL; } sqlFreeResult(&sr); hDisconnectCentral(&connCentral); if (proteinInSupportedGenome || (blatGbDb != NULL)) { hPrintf("\n<B>UCSC Links:</B><BR>\n "); hPrintf("<UL>\n"); /* Show GB links only if the protein belongs to a supported genome */ if (proteinInSupportedGenome) { doGenomeBrowserLink(proteinID, mrnaID, hgsidStr); doGeneDetailsLink(proteinID, mrnaID, hgsidStr); } /* Show Gene Sorter link only if it is valid for this genome */ if (hgNearOk(database)) { doGeneSorterLink(protDisplayID, mrnaID, hgsidStr); } /* Show BLAT link if we have UCSC Genome Browser for it */ if (blatGbDb != NULL) { doBlatLink(blatGbDb, sciName, commonName, protSeq); } hPrintf("</UL><P>"); } /* This section shows various types of domains */ conn = sqlConnect(UNIPROT_DB_NAME); domainsPrint(conn, proteinID); hPrintf("<P>"); /* Do Pathway section only if the protein belongs to a supported genome */ if (proteinInSupportedGenome); { doPathwayLinks(proteinID, mrnaID); } printFASTA(proteinID, protSeq); }