e81403a315a24af601884b8a19e89bcecc92f267 galt Sat Dec 8 20:04:28 2018 -0800 Fixing hFindSplitTable and its use. Standard size, give real string size so no undetected overflows. Test result and abort if not found. Avoids SQL errors that otherwise will popup. Handles uninitialzed stack better for the output name. refs #22596. diff --git src/hg/hgc/hgc.c src/hg/hgc/hgc.c index f304287..e45451a 100644 --- src/hg/hgc/hgc.c +++ src/hg/hgc/hgc.c @@ -999,39 +999,40 @@ { printCustomUrlWithLabel(tdb, itemName, itemName, urlSetting, encode, fields); } void printOtherCustomUrl(struct trackDb *tdb, char *itemName, char* urlSetting, boolean encode) /* Wrapper to call printCustomUrlWithLabel to use another url setting other than url in trackDb e.g. url2, this allows the use of multiple urls for a track to be set in trackDb. */ { printCustomUrlWithLabel(tdb, itemName, itemName, urlSetting, encode, NULL); } void genericSampleClick(struct sqlConnection *conn, struct trackDb *tdb, char *item, int start, int smpSize) /* Handle click in generic sample (wiggle) track. */ { -char table[64]; +char table[HDB_MAX_TABLE_STRING]; boolean hasBin; struct sample *smp; char query[512]; struct sqlResult *sr; char **row; boolean firstTime = TRUE; -hFindSplitTable(database, seqName, tdb->table, table, &hasBin); +if (!hFindSplitTable(database, seqName, tdb->table, table, sizeof table, &hasBin)) + errAbort("genericSampleClick track %s not found", tdb->table); sqlSafef(query, sizeof query, "select * from %s where name = '%s' and chrom = '%s' and chromStart = %d", table, item, seqName, start); /*errAbort( "select * from %s where name = '%s' and chrom = '%s' and chromStart = %d", table, item, seqName, start);*/ sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { if (firstTime) firstTime = FALSE; else htmlHorizontalLine(); smp = sampleLoad(row+hasBin); @@ -1062,45 +1063,47 @@ printf("(list truncated -- more than %d elements)<BR>\n", max); } void showBedTopScorersInWindow(struct sqlConnection *conn, struct trackDb *tdb, char *item, int start, int maxScorers, char *filterTable, int filterCt) /* Show a list of track items in the current browser window, ordered by * score. Track must be BED 5 or greater. maxScorers is upper bound on * how many items will be displayed. If filterTable is not NULL and exists, * it contains the 100K top-scorers in the entire track, and filterCt * is the threshold for how many are candidates for display. */ { struct sqlResult *sr = NULL; char **row = NULL; struct bed *bedList = NULL, *bed = NULL; -char table[64]; +char table[HDB_MAX_TABLE_STRING]; boolean hasBin = FALSE; char query[512]; if (filterTable) { /* Track display only shows top-scoring N elements -- restrict * the list to these. Get them from the filter table */ hasBin = hOffsetPastBin(database, hDefaultChrom(database), filterTable); sqlSafef(query, sizeof(query), "select * from %s order by score desc limit %d", filterTable, filterCt); } else { - hFindSplitTable(database, seqName, tdb->table, table, &hasBin); + if (!hFindSplitTable(database, seqName, tdb->table, table, sizeof table, &hasBin)) + errAbort("showBedTopScorersInWindow track %s not found", tdb->table); + sqlSafef(query, sizeof(query), "select * from %s where chrom = '%s' and chromEnd > %d and " "chromStart < %d order by score desc", table, seqName, winStart, winEnd); } sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { bed = bedLoadN(row+hasBin, 5); if (!filterTable || ( sameString(bed->chrom, seqName) && bed->chromStart < winEnd && bed->chromEnd > winStart)) { slAddHead(&bedList, bed); @@ -1223,46 +1226,47 @@ sqlFreeResult(&sr); } hFreeConn(&conn); freeMem(setting); if (gotOne) printf("</UL>\n"); else printf("<P>Currently the item \"%s\" has not been located in another genome.\n",name); } void mafPrettyOut(FILE *f, struct mafAli *maf, int lineSize, boolean onlyDiff, int blockNo); void doAtom( struct trackDb *tdb, char *item) { -char table[64]; +char table[HDB_MAX_TABLE_STRING]; boolean hasBin; //struct bed *bed; char query[512]; struct sqlResult *sr; char **row; //boolean firstTime = TRUE; int start = cartInt(cart, "o"); //struct sqlConnection *conn = hAllocConn(database); char *user = cfgOption("db.user"); char *password = cfgOption("db.password"); struct sqlConnection *sc; struct atom ret; genericHeader(tdb, item); -hFindSplitTable(database, seqName, tdb->table, table, &hasBin); +if (!hFindSplitTable(database, seqName, tdb->table, table, sizeof table, &hasBin)) + errAbort("mafPrettyOut track %s not found", tdb->table); #if 0 sqlSafef(query, sizeof query, "select * from %s where name = '%s' and chrom = '%s' and chromStart = %d", table, escapedName, seqName, start); sr = sqlGetResult(conn, query); printf("<B>This is the item you clicked on:</B><BR>\n"); while ((row = sqlNextRow(sr)) != NULL) { if (firstTime) firstTime = FALSE; else htmlHorizontalLine(); bed = bedLoadN(row+hasBin, 4); bedPrintPos(bed, 4, tdb); } sqlFreeResult(&sr); @@ -1638,39 +1642,40 @@ if (skipIds) slFreeList(skipIds); if (sepFields) slFreeList(sepFields); if (count > 0) printf("</table>\n"); return count; } void genericBedClick(struct sqlConnection *conn, struct trackDb *tdb, char *item, int start, int bedSize) /* Handle click in generic BED track. */ { -char table[64]; +char table[HDB_MAX_TABLE_STRING]; boolean hasBin; struct bed *bed; char query[512]; struct sqlResult *sr; char **row; boolean firstTime = TRUE; -hFindSplitTable(database, seqName, tdb->table, table, &hasBin); +if (!hFindSplitTable(database, seqName, tdb->table, table, sizeof table, &hasBin)) + errAbort("genericBedClick track %s not found", tdb->table); if (bedSize <= 3) sqlSafef(query, sizeof query, "select * from %s where chrom = '%s' and chromStart = %d", table, seqName, start); else { struct hTableInfo *hti = hFindTableInfoWithConn(conn, seqName, tdb->table); if (hti && *hti->nameField && differentString("name", hti->nameField)) sqlSafef(query, sizeof query, "select * from %s where %s = '%s' and chrom = '%s' and chromStart = %d", table, hti->nameField, item, seqName, start); else sqlSafef(query, sizeof query, "select * from %s where name = '%s' and chrom = '%s' and chromStart = %d", table, item, seqName, start); } sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { @@ -1796,39 +1801,40 @@ } int numberOfGaps(char *q,int size) /* count number of gaps in a string array */ { int i; int count = 0; for (i = 0 ; i<size ; i++) if (q[i] == '-') count++; return (count); } void pseudoGeneClick(struct sqlConnection *conn, struct trackDb *tdb, char *item, int start, int bedSize) /* Handle click in track. */ { -char table[64]; +char table[HDB_MAX_TABLE_STRING]; boolean hasBin; struct bed *bed; char query[512]; struct sqlResult *sr; char **row; boolean firstTime = TRUE; -hFindSplitTable(database, seqName, tdb->table, table, &hasBin); +if (!hFindSplitTable(database, seqName, tdb->table, table, sizeof table, &hasBin)) + errAbort("pseudoGeneClick track %s not found", tdb->table); if (bedSize <= 3) sqlSafef(query, sizeof query, "select * from %s where chrom = '%s' and chromStart = %d", table, seqName, start); else sqlSafef(query, sizeof query, "select * from %s where name = '%s' and chrom = '%s' and chromStart = %d", table, item, seqName, start); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { if (firstTime) firstTime = FALSE; else htmlHorizontalLine(); bed = bedLoadN(row+hasBin, bedSize); bedPrintPos(bed, bedSize, tdb); } @@ -2524,38 +2530,38 @@ printf("<em>not</em> complete<br>\n"); break; case cdsComplete: /* "cmpl" - CDS is complete at this end */ printf("complete<br>\n"); break; } } void showGenePos(char *name, struct trackDb *tdb) /* Show gene prediction position and other info. */ { char *rootTable = tdb->table; char query[512]; struct sqlConnection *conn = hAllocConn(database); struct genePred *gpList = NULL, *gp = NULL; -boolean hasBin; -char table[64]; +char table[HDB_MAX_TABLE_STRING]; struct sqlResult *sr = NULL; char **row = NULL; char *classTable = trackDbSetting(tdb, GENEPRED_CLASS_TBL); -hFindSplitTable(database, seqName, rootTable, table, &hasBin); +if (!hFindSplitTable(database, seqName, rootTable, table, sizeof table, NULL)) + errAbort("showGenePos track %s not found", rootTable); sqlSafefFrag(query, sizeof(query), "name = \"%s\"", name); gpList = genePredReaderLoadQuery(conn, table, query); for (gp = gpList; gp != NULL; gp = gp->next) { printPos(gp->chrom, gp->txStart, gp->txEnd, gp->strand, FALSE, NULL); if(sameString(tdb->type,"genePred") && startsWith("ENCODE Gencode",tdb->longLabel) && startsWith("ENST",name)) { char *ensemblIdUrl = trackDbSetting(tdb, "ensemblIdUrl"); printf("<b>Ensembl Transcript Id: </b>"); if (ensemblIdUrl != NULL) printf("<a href=\"%s%s\" target=\"_blank\">%s</a><br>", ensemblIdUrl,name,name); else @@ -2655,33 +2661,34 @@ sqlFreeResult(&sr); hFreeConn(&conn); } void showGenePosMouse(char *name, struct trackDb *tdb, struct sqlConnection *connMm) /* Show gene prediction position and other info. */ { char query[512]; char *rootTable = tdb->table; struct sqlResult *sr; char **row; struct genePred *gp = NULL; boolean hasBin; int posCount = 0; -char table[64] ; +char table[HDB_MAX_TABLE_STRING]; -hFindSplitTable(database, seqName, rootTable, table, &hasBin); +if (!hFindSplitTable(database, seqName, rootTable, table, sizeof table, &hasBin)) + errAbort("showGenePosMouse track %s not found", rootTable); sqlSafef(query, sizeof query, "select * from %s where name = '%s'", table, name); sr = sqlGetResult(connMm, query); while ((row = sqlNextRow(sr)) != NULL) { if (posCount > 0) printf("<BR>\n"); ++posCount; gp = genePredLoad(row + hasBin); printPos(gp->chrom, gp->txStart, gp->txEnd, gp->strand, FALSE, NULL); genePredFree(&gp); } sqlFreeResult(&sr); } void linkToPal(char *track, char *chrom, int start, int end, char *geneName) @@ -3167,46 +3174,46 @@ { *retQs = chain->qSize - chain->qEnd+1; *retQe = chain->qSize - chain->qStart; } else { *retQs = chain->qStart+1; *retQe = chain->qEnd; } } struct chain *chainDbLoad(struct sqlConnection *conn, char *db, char *track, char *chrom, int id) /* Load chain. */ { -char table[64]; +char table[HDB_MAX_TABLE_STRING]; char query[256]; struct sqlResult *sr; char **row; -int rowOffset; +boolean hasBin; struct chain *chain; -if (!hFindSplitTable(db, seqName, track, table, &rowOffset)) +if (!hFindSplitTable(db, seqName, track, table, sizeof table, &hasBin)) errAbort("No %s track in database %s for %s", track, db, seqName); sqlSafef(query, sizeof(query), "select * from %s where id = %d", table, id); sr = sqlGetResult(conn, query); row = sqlNextRow(sr); if (row == NULL) errAbort("Can't find %d in %s", id, table); -chain = chainHeadLoad(row + rowOffset); +chain = chainHeadLoad(row + hasBin); sqlFreeResult(&sr); chainDbAddBlocks(chain, track, conn); return chain; } void linkToOtherBrowserExtra(char *otherDb, char *chrom, int start, int end, char *extra) /* Make anchor tag to open another browser window. */ { printf("<A TARGET=\"_blank\" HREF=\"%s?db=%s&%s&position=%s%%3A%d-%d\">", hgTracksName(), otherDb, extra, chrom, start+1, end); } void linkToOtherBrowserSearch(char *otherDb, char *tag) /* Make anchor tag to open another browser window. */ { @@ -3350,33 +3357,33 @@ printf("<B>Score:</B> %1.0f\n", chain->score); if (nullSubset) printf("<B>Score within browser window:</B> N/A (no aligned bases)<BR>\n"); else if (hDbIsActive(otherDb) && subChain != chain) printf("<B> Approximate Score within browser window:</B> %1.0f<BR>\n", subSetScore); else printf("<BR>\n"); printf("<BR>Fields above refer to entire chain or gap, not just the part inside the window.<BR>\n"); boolean normScoreAvailable = chainDbNormScoreAvailable(tdb); if (normScoreAvailable) { - boolean hasBin; char tableName[HDB_MAX_TABLE_STRING]; - hFindSplitTable(database, chain->tName, tdb->table, tableName, &hasBin); + if (!hFindSplitTable(database, chain->tName, tdb->table, tableName, sizeof tableName, NULL)) + errAbort("genericChainClick track %s not found", tdb->table); char query[256]; struct sqlResult *sr; char **row; sqlSafef(query, ArraySize(query), "select normScore from %s where id = '%s'", tableName, item); sr = sqlGetResult(conn, query); if ((row = sqlNextRow(sr)) != NULL) printf("<B>Normalized Score:</B> %1.0f (bases matched: %d)<BR>\n", atof(row[0]), (int) (chain->score/atof(row[0]))); sqlFreeResult(&sr); } printf("<BR>\n"); chainWinSize = min(winEnd-winStart, chain->tEnd - chain->tStart); @@ -3475,58 +3482,59 @@ { char *space = " "; if (org == NULL) org = space = ""; printf("<B>%s%s%s:</B> ", org, space, label); printLongWithCommas(stdout, p); if (q != 0) printf(" (%3.1f%%)", 100.0 * p / q); printf("<BR>\n"); } void genericNetClick(struct sqlConnection *conn, struct trackDb *tdb, char *item, int start, char *otherDb, char *chainTrack) /* Generic click handler for net tracks. */ { -char table[64]; -int rowOffset; +char table[HDB_MAX_TABLE_STRING]; +boolean hasBin; char query[256]; struct sqlResult *sr; char **row; struct netAlign *net; char *org = hOrganism(database); char *otherOrg = hOrganism(otherDb); char *otherOrgBrowser = otherOrg; int tSize, qSize; int netWinSize; struct chain *chain; if (otherOrg == NULL) { /* use first word in short track label */ otherOrg = firstWordInLine(cloneString(tdb->shortLabel)); } -hFindSplitTable(database, seqName, tdb->table, table, &rowOffset); +if (!hFindSplitTable(database, seqName, tdb->table, table, sizeof table, &hasBin)) + errAbort("genericNetClick track %s not found", tdb->table); sqlSafef(query, sizeof(query), "select * from %s where tName = '%s' and tStart <= %d and tEnd > %d " "and level = %s", table, seqName, start, start, item); sr = sqlGetResult(conn, query); if ((row = sqlNextRow(sr)) == NULL) errAbort("Couldn't find %s:%d in %s", seqName, start, table); -net = netAlignLoad(row+rowOffset); +net = netAlignLoad(row+hasBin); sqlFreeResult(&sr); tSize = net->tEnd - net->tStart; qSize = net->qEnd - net->qStart; if (net->chainId != 0) { netWinSize = min(winEnd-winStart, net->tEnd - net->tStart); printf("<BR>\n"); /* Show alignment if the database exists and */ /* if there is a chromInfo table for that database and the sequence */ /* file exists. This means that alignments can be shown on the archive */ /* server (or in other cases) if there is a database with a chromInfo */ /* table, the sequences are available and there is an entry added to */ /* dbDb for the otherDb. */ if (chromSeqFileExists(otherDb, net->qName)) @@ -3604,58 +3612,60 @@ if (net->tEnd >= net->tStart) printLabeledNumber(org, "size", net->tEnd - net->tStart); if (net->qEnd >= net->qStart) printLabeledNumber(otherOrg, "size", net->qEnd - net->qStart); printf("<BR>Fields above refer to entire chain or gap, not just the part inside the window.<BR>\n"); netAlignFree(&net); } void tfbsConsSites(struct trackDb *tdb, char *item) /* detail page for tfbsConsSites track */ { boolean printedPlus = FALSE; boolean printedMinus = FALSE; int start = cartInt(cart, "o"); struct sqlConnection *conn = hAllocConn(database); -char table[64]; +char table[HDB_MAX_TABLE_STRING]; boolean hasBin; char query[512]; struct sqlResult *sr; char **row; struct tfbsConsSites *tfbsConsSites; struct tfbsConsSites *tfbsConsSitesList = NULL; struct tfbsConsFactors *tfbsConsFactor; struct tfbsConsFactors *tfbsConsFactorList = NULL; boolean firstTime = TRUE; char *mappedId = NULL; genericHeader(tdb, item); -hFindSplitTable(database, seqName, tdb->table, table, &hasBin); +if (!hFindSplitTable(database, seqName, tdb->table, table, sizeof table, &hasBin)) + errAbort("tfbsConsSites track %s not found", tdb->table); sqlSafef(query, sizeof query, "select * from %s where name = '%s' and chrom = '%s' and chromStart = %d", table, item, seqName, start); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { tfbsConsSites = tfbsConsSitesLoad(row+hasBin); slAddHead(&tfbsConsSitesList, tfbsConsSites); } sqlFreeResult(&sr); slReverse(&tfbsConsSitesList); -hFindSplitTable(database, seqName, "tfbsConsFactors", table, &hasBin); +if (!hFindSplitTable(database, seqName, "tfbsConsFactors", table, sizeof table, &hasBin)) + errAbort("tfbsConsSites table tfbsConsFactors not found"); sqlSafef(query, sizeof query, "select * from %s where name = '%s' ", table, item); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { tfbsConsFactor = tfbsConsFactorsLoad(row+hasBin); slAddHead(&tfbsConsFactorList, tfbsConsFactor); } sqlFreeResult(&sr); slReverse(&tfbsConsFactorList); if (tfbsConsFactorList) mappedId = cloneString(tfbsConsFactorList->ac); printf("<B style='font-size:large;'>Transcription Factor Binding Site information:</B><BR><BR><BR>"); @@ -3696,44 +3706,45 @@ } } printTrackHtml(tdb); hFreeConn(&conn); } void tfbsCons(struct trackDb *tdb, char *item) /* detail page for tfbsCons track */ { boolean printFactors = FALSE; boolean printedPlus = FALSE; boolean printedMinus = FALSE; int start = cartInt(cart, "o"); struct sqlConnection *conn = hAllocConn(database); -char table[64]; +char table[HDB_MAX_TABLE_STRING]; boolean hasBin; char query[512]; struct sqlResult *sr; char **row; struct tfbsCons *tfbs; struct tfbsCons *tfbsConsList = NULL; struct tfbsConsMap tfbsConsMap; boolean firstTime = TRUE; char *mappedId = NULL; genericHeader(tdb, item); -hFindSplitTable(database, seqName, tdb->table, table, &hasBin); +if (!hFindSplitTable(database, seqName, tdb->table, table, sizeof table, &hasBin)) + errAbort("tfbsCons track %s not found", tdb->table); sqlSafef(query, sizeof query, "select * from %s where name = '%s' and chrom = '%s' and chromStart = %d", table, item, seqName, start); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { tfbs = tfbsConsLoad(row+hasBin); slAddHead(&tfbsConsList, tfbs); } sqlFreeResult(&sr); slReverse(&tfbsConsList); if (hTableExists(database, "tfbsConsMap")) { sqlSafef(query, sizeof query, "select * from tfbsConsMap where id = '%s'", tfbsConsList->name); @@ -3787,80 +3798,82 @@ printf("<B>Species:</B> %s<BR>\n", tfbs->species); printf("<B>SwissProt ID:</B> %s<BR>\n", sameString(tfbs->id, "N")? "unknown": tfbs->id); } } } printTrackHtml(tdb); hFreeConn(&conn); } void firstEF(struct trackDb *tdb, char *item) { int start = cartInt(cart, "o"); struct sqlConnection *conn = hAllocConn(database); -char table[64]; +char table[HDB_MAX_TABLE_STRING]; boolean hasBin; struct bed *bed; char query[512]; struct sqlResult *sr; char **row; boolean firstTime = TRUE; /* itemForUrl = item; */ genericHeader(tdb, item); printCustomUrl(tdb, item, FALSE); /* printCustomUrl(tdb, itemForUrl, item == itemForUrl); */ -hFindSplitTable(database, seqName, tdb->table, table, &hasBin); +if (!hFindSplitTable(database, seqName, tdb->table, table, sizeof table, &hasBin)) + errAbort("firstEF track %s not found", tdb->table); sqlSafef(query, sizeof query, "select * from %s where name = '%s' and chrom = '%s' and chromStart = %d", table, item, seqName, start); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { if (firstTime) firstTime = FALSE; else htmlHorizontalLine(); bed = bedLoadN(row+hasBin, 6); printf("<B>Item:</B> %s<BR>\n", bed->name); printf("<B>Probability:</B> %g<BR>\n", bed->score / 1000.0); printf("<B>Strand:</B> %s<BR>\n", bed->strand); printPos(bed->chrom, bed->chromStart, bed->chromEnd, NULL, TRUE, bed->name); } printTrackHtml(tdb); hFreeConn(&conn); } void doBed5FloatScore(struct trackDb *tdb, char *item) /* Handle click in BED 5+ track: BED 5 with 0-1000 score (for useScore * shading in hgTracks) plus real score for display in details page. */ { struct sqlConnection *conn = hAllocConn(database); struct sqlResult *sr = NULL; -char table[64]; +char table[HDB_MAX_TABLE_STRING]; boolean hasBin; struct bed5FloatScore *b5; struct dyString *query = newDyString(512); char **row; boolean firstTime = TRUE; int start = cartInt(cart, "o"); int bedSize = 5; -hFindSplitTable(database, seqName, tdb->table, table, &hasBin); +if (!hFindSplitTable(database, seqName, tdb->table, table, sizeof table, &hasBin)) + errAbort("doBed5FloatScore track %s not found", tdb->table); sqlDyStringPrintf(query, "select * from %s where chrom = '%s' and ", table, seqName); hAddBinToQuery(winStart, winEnd, query); sqlDyStringPrintf(query, "name = '%s' and chromStart = %d", item, start); sr = sqlGetResult(conn, query->string); while ((row = sqlNextRow(sr)) != NULL) { if (firstTime) firstTime = FALSE; else htmlHorizontalLine(); b5 = bed5FloatScoreLoad(row+hasBin); bedPrintPos((struct bed *)b5, 4, tdb); printf("<B>Score:</B> %f<BR>\n", b5->floatScore); if (sameString(tdb->type, "bed5FloatScoreWithFdr")) @@ -3869,41 +3882,42 @@ printf("<B>False Discovery Rate (FDR):</B> %s%%<BR>\n", row[7]); } } getBedTopScorers(conn, tdb, table, item, start, bedSize); sqlFreeResult(&sr); hFreeConn(&conn); /* printTrackHtml is done in genericClickHandlerPlus. */ } void doBed6FloatScore(struct trackDb *tdb, char *item) /* Handle click in BED 4+ track that's like BED 6 but with floating pt score */ { struct sqlConnection *conn = hAllocConn(database); struct sqlResult *sr = NULL; -char table[64]; +char table[HDB_MAX_TABLE_STRING]; boolean hasBin; struct bed6FloatScore *b6 = NULL; struct dyString *query = newDyString(512); char **row; boolean firstTime = TRUE; int start = cartInt(cart, "o"); genericHeader(tdb, item); -hFindSplitTable(database, seqName, tdb->table, table, &hasBin); +if (!hFindSplitTable(database, seqName, tdb->table, table, sizeof table, &hasBin)) + errAbort("doBed6FloatScore track %s not found", tdb->table); sqlDyStringPrintf(query, "select * from %s where chrom = '%s' and ", table, seqName); hAddBinToQuery(winStart, winEnd, query); sqlDyStringPrintf(query, "name = '%s' and chromStart = %d", item, start); sr = sqlGetResult(conn, query->string); while ((row = sqlNextRow(sr)) != NULL) { if (firstTime) firstTime = FALSE; else htmlHorizontalLine(); b6 = bed6FloatScoreLoad(row+hasBin); bedPrintPos((struct bed *)b6, 4, tdb); printf("<B>Score:</B> %f<BR>\n", b6->score); printf("<B>Strand:</B> %s<BR>\n", b6->strand); @@ -4842,38 +4856,39 @@ "other software can safely display. The tool will format 10 Mb and more, however.</P>"); } trackDbFreeList(&tdbList); } void doGetBlastPep(char *readName, char *table) /* get predicted protein */ { int qStart; struct psl *psl; int start, end; struct sqlResult *sr; struct sqlConnection *conn = hAllocConn(database); struct dnaSeq *tSeq; char query[256], **row; -char fullTable[64]; +char fullTable[HDB_MAX_TABLE_STRING]; boolean hasBin; char *buffer, *str; int i, j; char *ptr; start = cartInt(cart, "o"); -hFindSplitTable(database, seqName, table, fullTable, &hasBin); +if (!hFindSplitTable(database, seqName, table, fullTable, sizeof fullTable, &hasBin)) + errAbort("doGetBlastPep track %s not found", table); sqlSafef(query, sizeof query, "select * from %s where qName = '%s' and tName = '%s' and tStart=%d", fullTable, readName, seqName, start); sr = sqlGetResult(conn, query); if ((row = sqlNextRow(sr)) == NULL) errAbort("Couldn't find alignment for %s at %d", readName, start); psl = pslLoad(row+hasBin); sqlFreeResult(&sr); hFreeConn(&conn); printf("<PRE><TT>"); end = psl->tEnd; if (psl->strand[1] == '+') end = psl->tStarts[psl->blockCount - 1] + psl->blockSizes[psl->blockCount - 1] *3; if ((ptr = strchr(readName, '.')) != NULL) *ptr++ = 0; @@ -5940,68 +5955,69 @@ void printAlignments(struct psl *pslList, int startFirst, char *hgcCommand, char *tableName, char *itemIn) /* Print list of mRNA alignments. */ { printAlignmentsExtra(pslList, startFirst, hgcCommand, "htcCdnaAliInWindow", tableName, itemIn); } static struct psl *getAlignmentsTName(struct sqlConnection *conn, char *table, char *acc, char *tName) /* get the list of alignments for the specified acc and tName (if given). */ { struct sqlResult *sr = NULL; char **row; struct psl *psl, *pslList = NULL; boolean hasBin; -char splitTable[256]; +char splitTable[HDB_MAX_TABLE_STRING]; char query[1024]; -if (!hFindSplitTable(database, seqName, table, splitTable, &hasBin)) +if (!hFindSplitTable(database, seqName, table, splitTable, sizeof splitTable, &hasBin)) errAbort("can't find table %s or %s_%s", table, seqName, table); if (isNotEmpty(tName)) sqlSafef(query, sizeof(query), "select * from %s where qName = '%s' and tName = '%s'", splitTable, acc, tName); else sqlSafef(query, sizeof(query), "select * from %s where qName = '%s'", splitTable, acc); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { psl = pslLoad(row+hasBin); slAddHead(&pslList, psl); } sqlFreeResult(&sr); slReverse(&pslList); return pslList; } struct psl *getAlignments(struct sqlConnection *conn, char *table, char *acc) /* get the list of alignments for the specified acc */ { return getAlignmentsTName(conn, table, acc, NULL); } struct psl *loadPslRangeT(char *table, char *qName, char *tName, int tStart, int tEnd) /* Load a list of psls given qName tName tStart tEnd */ { struct sqlResult *sr = NULL; char **row; struct psl *psl = NULL, *pslList = NULL; boolean hasBin; -char splitTable[64]; +char splitTable[HDB_MAX_TABLE_STRING]; char query[256]; struct sqlConnection *conn = hAllocConn(database); -hFindSplitTable(database, seqName, table, splitTable, &hasBin); +if (!hFindSplitTable(database, seqName, table, splitTable, sizeof splitTable, &hasBin)) + errAbort("loadPslRangeT track %s not found", table); sqlSafef(query, sizeof(query), "select * from %s where qName = '%s' and tName = '%s' and tEnd > %d and tStart < %d", splitTable, qName, tName, tStart, tEnd); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { psl = pslLoad(row+hasBin); slAddHead(&pslList, psl); } sqlFreeResult(&sr); slReverse(&pslList); hFreeConn(&conn); return pslList; } void doHgRna(struct trackDb *tdb, char *acc) /* Click on an individual RNA. */ @@ -6596,41 +6612,42 @@ struct sqlConnection *conn2 = hAllocConn(database); struct sqlConnection *conn3 = hAllocConn(database); char query[256]; struct sqlResult *sr; char **row; char query2[256]; struct sqlResult *sr2; char **row2; char query3[256]; struct sqlResult *sr3; char **row3; struct agpFrag frag; struct contigAcc contigAcc; int start = cartInt(cart, "o"); boolean hasBin; -char splitTable[64]; +char splitTable[HDB_MAX_TABLE_STRING]; char *chp; char *accession1, *accession2, *spanner, *variation, *varEvidence, *contact, *remark, *comment; // char *evaluation; unused variable char *secondAcc, *secondAccVer; char *tmpString; int first; cartWebStart(cart, database, "%s", fragName); -hFindSplitTable(database, seqName, tdb->table, splitTable, &hasBin); +if (!hFindSplitTable(database, seqName, tdb->table, splitTable, sizeof splitTable, &hasBin)) + errAbort("doHgGold track %s not found", tdb->table); sqlSafef(query, sizeof query, "select * from %s where frag = '%s' and chromStart = %d", splitTable, fragName, start); sr = sqlMustGetResult(conn, query); row = sqlNextRow(sr); agpFragStaticLoad(row+hasBin, &frag); printf("<B>Entrez nucleotide:</B><A TARGET=_blank HREF='https://www.ncbi.nlm.nih.gov/nuccore/%s'> %s</A><BR>\n", fragName, fragName); printf("<B>Clone Fragment ID:</B> %s<BR>\n", frag.frag); printf("<B>Clone Fragment Type:</B> %s<BR>\n", frag.type); printf("<B>Clone Bases:</B> %d-%d<BR>\n", frag.fragStart+1, frag.fragEnd); if (hTableExists(database, "contigAcc")) { sqlSafef(query2, sizeof query2, "select * from contigAcc where contig = '%s'", frag.frag); if ((sr2 = sqlGetResult(conn2, query2))) @@ -6736,65 +6753,66 @@ hFreeConn(&conn2); hFreeConn(&conn3); printTrackHtml(tdb); } void doHgGap(struct trackDb *tdb, char *gapType) /* Print a teeny bit of info about a gap. */ { struct sqlConnection *conn = hAllocConn(database); char query[256]; struct sqlResult *sr; char **row; struct agpGap gap; int start = cartInt(cart, "o"); boolean hasBin; -char splitTable[64]; +char splitTable[HDB_MAX_TABLE_STRING]; cartWebStart(cart, database, "Gap in Sequence"); -hFindSplitTable(database, seqName, tdb->table, splitTable, &hasBin); +if (!hFindSplitTable(database, seqName, tdb->table, splitTable, sizeof splitTable, &hasBin)) + errAbort("doHgGap track %s not found", tdb->table); if (sameString(tdb->table, splitTable)) sqlSafef(query, sizeof(query), "select * from %s where chrom = '%s' and " "chromStart = %d", splitTable, seqName, start); else sqlSafef(query, sizeof(query), "select * from %s where chromStart = %d", splitTable, start); sr = sqlMustGetResult(conn, query); row = sqlNextRow(sr); if (row == NULL) errAbort("Couldn't find gap at %s:%d", seqName, start); agpGapStaticLoad(row+hasBin, &gap); printf("<B>Gap Type:</B> %s<BR>\n", gap.type); printf("<B>Bridged:</B> %s<BR>\n", gap.bridge); printPos(gap.chrom, gap.chromStart, gap.chromEnd, NULL, FALSE, NULL); printTrackHtml(tdb); sqlFreeResult(&sr); hFreeConn(&conn); } void selectOneRow(struct sqlConnection *conn, char *table, char *query, struct sqlResult **retSr, char ***retRow) /* Do query and return one row offset by bin as needed. */ { -char fullTable[64]; +char fullTable[HDB_MAX_TABLE_STRING]; boolean hasBin; char **row; -if (!hFindSplitTable(database, seqName, table, fullTable, &hasBin)) +if (!hFindSplitTable(database, seqName, table, fullTable, sizeof fullTable, &hasBin)) errAbort("Table %s doesn't exist in database", table); *retSr = sqlGetResult(conn, query); if ((row = sqlNextRow(*retSr)) == NULL) errAbort("No match to query '%s'", query); *retRow = row + hasBin; } void doHgContig(struct trackDb *tdb, char *ctgName) /* Click on a contig. */ { struct sqlConnection *conn = hAllocConn(database); struct sqlConnection *conn2 = hAllocConn(database); char query[256], query2[256], ctgUrl[256]; struct sqlResult *sr, *sr2; @@ -7386,58 +7404,59 @@ return hDnaSeqGet(database, itemName, words[1], words[2]); else if (sameString(words[0], "db")) { char *db = (nwords == 2) ? words[1] : database; return hChromSeq(db, itemName, 0, 0); } else errAbort("invalid %s track setting: %s", BASE_COLOR_USE_SEQUENCE, spec); return NULL; // make compiler happy } void htcCdnaAli(char *acc) /* Show alignment for accession. */ { char query[256]; -char table[64]; +char table[HDB_MAX_TABLE_STRING]; char accTmp[64]; struct sqlConnection *conn; struct sqlResult *sr; char **row; struct psl *psl; struct dnaSeq *rnaSeq; char *aliTable; int start; unsigned int cdsStart = 0, cdsEnd = 0; boolean hasBin; char accChopped[512] ; safef(accChopped, sizeof(accChopped), "%s",acc); chopSuffix(accChopped); aliTable = cartString(cart, "aliTable"); char title[1024]; safef(title, sizeof title, "%s vs Genomic [%s]", accChopped, aliTable); htmlFramesetStart(title); /* Get some environment vars. */ start = cartInt(cart, "o"); conn = hAllocConn(database); getCdsStartAndStop(conn, accChopped, aliTable, &cdsStart, &cdsEnd); /* Look up alignments in database */ -hFindSplitTable(database, seqName, aliTable, table, &hasBin); +if (!hFindSplitTable(database, seqName, aliTable, table, sizeof table, &hasBin)) + errAbort("Failed to find aliTable=%s", aliTable); sqlSafef(query, sizeof query, "select * from %s where qName like '%s%%' and tName=\"%s\" and tStart=%d", table, acc, seqName, start); sr = sqlGetResult(conn, query); if ((row = sqlNextRow(sr)) == NULL) errAbort("Couldn't find alignment for %s at %d", acc, start); psl = pslLoad(row+hasBin); sqlFreeResult(&sr); /* get bz rna snapshot for blastz alignments */ if (sameString("mrnaBlastz", aliTable) || sameString("pseudoMrna", aliTable)) { struct sqlConnection *conn = hAllocConn(database); unsigned retId = 0; safef(accTmp, sizeof accTmp, "bz-%s", acc); if (hRnaSeqAndIdx(accTmp, &rnaSeq, &retId, conn) == -1) @@ -7557,31 +7576,32 @@ errAbort("Couldn't find alignment at %s:%d", seqName, start); oSeqList = faReadAllSeq(faName, !isProt); for (oSeq = oSeqList; oSeq != NULL; oSeq = oSeq->next) { if (sameString(oSeq->name, qName)) break; } if (oSeq == NULL) errAbort("%s is in %s but not in %s. Internal error.", qName, pslName, faName); wholePsl = psl; rnaSeq = oSeq; } else { /* Look up alignments in database */ - hFindSplitTable(database, seqName, aliTable, table, &hasBin); + if (!hFindSplitTable(database, seqName, aliTable, table, sizeof table, &hasBin)) + errAbort("aliTable %s not found", aliTable); sqlSafef(query, sizeof(query), "select * from %s where qName = '%s' and tName=\"%s\" and tStart=%d", table, acc, seqName, start); sr = sqlGetResult(conn, query); if ((row = sqlNextRow(sr)) == NULL) errAbort("Couldn't find alignment for %s at %d", acc, start); wholePsl = pslLoad(row+hasBin); sqlFreeResult(&sr); if (startsWith("ucscRetroAli", aliTable) || startsWith("retroMrnaAli", aliTable) || sameString("pseudoMrna", aliTable) || startsWith("altSeqLiftOverPsl", aliTable) || startsWith("fixSeqLiftOverPsl", aliTable) || startsWith("ncbiRefSeqPsl", aliTable)) { rnaSeq = getBaseColorSequence(acc, aliTable); } @@ -7769,44 +7789,45 @@ } if (oSeq == NULL) errAbort("%s is in %s but not in %s. Internal error.", qName, pslName, faName); showSomeAlignment(psl, oSeq, qt, 0, oSeq->size, NULL, 0, 0); } void htcProteinAli(char *readName, char *table) /* Show protein to translated dna alignment for accession. */ { struct psl *psl; int start; enum gfType qt = gftProt; struct sqlResult *sr; struct sqlConnection *conn = hAllocConn(database); struct dnaSeq *seq = NULL; char query[256], **row; -char fullTable[64]; +char fullTable[HDB_MAX_TABLE_STRING]; boolean hasBin; char buffer[256]; int addp = 0; char *pred = NULL; char title[1024]; safef(title, sizeof title, "Protein Sequence vs Genomic"); htmlFramesetStart(title); addp = cartUsualInt(cart, "addp",0); pred = cartUsualString(cart, "pred",NULL); start = cartInt(cart, "o"); -hFindSplitTable(database, seqName, table, fullTable, &hasBin); +if (!hFindSplitTable(database, seqName, table, fullTable, sizeof fullTable, &hasBin)) + errAbort("track %s not found", table); sqlSafef(query, sizeof query, "select * from %s where qName = '%s' and tName = '%s' and tStart=%d", fullTable, readName, seqName, start); sr = sqlGetResult(conn, query); if ((row = sqlNextRow(sr)) == NULL) errAbort("Couldn't find alignment for %s at %d", readName, start); psl = pslLoad(row+hasBin); sqlFreeResult(&sr); if ((addp == 1) || (pred != NULL)) { char *ptr; safef(buffer, sizeof buffer, "%s",readName); if (!(sameString(pred, "ce3.blastWBPep01") || sameString(pred, "ce9.blastSGPep01") @@ -7836,39 +7857,40 @@ else seq = hPepSeq(database, readName); hFreeConn(&conn); showSomeAlignment(psl, seq, qt, 0, seq->size, NULL, 0, 0); } void htcBlatXeno(char *readName, char *table) /* Show alignment for accession. */ { struct psl *psl; int start; struct sqlResult *sr; struct sqlConnection *conn = hAllocConn(database); struct dnaSeq *seq; char query[256], **row; -char fullTable[64]; +char fullTable[HDB_MAX_TABLE_STRING]; boolean hasBin; char title[1024]; safef(title, sizeof title, "Sequence %s", readName); htmlFramesetStart(title); start = cartInt(cart, "o"); -hFindSplitTable(database, seqName, table, fullTable, &hasBin); +if (!hFindSplitTable(database, seqName, table, fullTable, sizeof fullTable, &hasBin)) + errAbort("track %s not found", table); sqlSafef(query, sizeof query, "select * from %s where qName = '%s' and tName = '%s' and tStart=%d", fullTable, readName, seqName, start); sr = sqlGetResult(conn, query); if ((row = sqlNextRow(sr)) == NULL) errAbort("Couldn't find alignment for %s at %d", readName, start); psl = pslLoad(row+hasBin); sqlFreeResult(&sr); hFreeConn(&conn); seq = hExtSeq(database, readName); showSomeAlignment(psl, seq, gftDnaX, 0, seq->size, NULL, 0, 0); } void writeMatches(FILE *f, char *a, char *b, int count) /* Write a | where a and b agree, a ' ' elsewhere. */ { @@ -7936,35 +7958,36 @@ } void doHgRepeat(struct trackDb *tdb, char *repeat) /* Do click on a repeat track. */ { int offset = cartInt(cart, "o"); cartWebStart(cart, database, "Repeat"); if (offset >= 0) { struct sqlConnection *conn = hAllocConn(database); struct sqlResult *sr; char **row; struct rmskOut *ro; char query[256]; - char table[64]; + char table[HDB_MAX_TABLE_STRING]; boolean hasBin; int start = cartInt(cart, "o"); - hFindSplitTable(database, seqName, tdb->table, table, &hasBin); + if (!hFindSplitTable(database, seqName, tdb->table, table, sizeof table, &hasBin)) + errAbort("Track %s not found", tdb->table); sqlSafef(query, sizeof query, "select * from %s where repName = '%s' and genoName = '%s' and genoStart = %d", table, repeat, seqName, start); sr = sqlGetResult(conn, query); if (sameString(tdb->table,"rmskNew")) printf("<H3>CENSOR Information</H3>\n"); else printf("<H3>RepeatMasker Information</H3>\n"); while ((row = sqlNextRow(sr)) != NULL) { ro = rmskOutLoad(row+hasBin); printf("<B>Name:</B> <A HREF='http://www.girinst.org/protected/repbase_extract.php?access=%s'>%s</A>\n", ro->repName, ro->repName); printf("(link requires <A HREF='http://www.girinst.org/accountservices/register.php'>registration</A>)<BR>"); printf("<B>Family:</B> %s<BR>\n", ro->repFamily); printf("<B>Class:</B> %s<BR>\n", ro->repClass); @@ -13329,39 +13352,40 @@ if (wordCount > 1 && sameWord(words[0], "genePred") && words[1] != NULL) pepTable = cloneString(words[1]); freeMem(dupe); return pepTable; } struct bed *getBedAndPrintPos(struct trackDb *tdb, char *name, int maxN) /* Dig up the bed for this item just to print the position. */ { struct bed *bed = NULL; struct sqlConnection *conn = hAllocConn(database); struct sqlResult *sr = NULL; char **row = NULL; char query[256]; -char table[64]; +char table[HDB_MAX_TABLE_STRING]; boolean hasBin = FALSE; int n = atoi(tdb->type + 4); int start = cgiInt("o"); if (n < 3) n = 3; if (n > maxN) n = maxN; -hFindSplitTable(database, seqName, tdb->table, table, &hasBin); +if (!hFindSplitTable(database, seqName, tdb->table, table, sizeof table, &hasBin)) + errAbort("track %s not found", tdb->table); sqlSafef(query, sizeof(query), "select * from %s where chrom = '%s' and chromStart = %d " "and name = '%s'", table, seqName, start, name); sr = sqlGetResult(conn, query); if ((row = sqlNextRow(sr)) != NULL) { bed = bedLoadN(row+hasBin, n); bedPrintPos(bed, n, tdb); } sqlFreeResult(&sr); hFreeConn(&conn); return bed; } @@ -13791,31 +13815,31 @@ printf("</TT></PRE>"); freeDnaSeq(&seq); } void doBlatMouse(struct trackDb *tdb, char *itemName) /* Handle click on blatMouse track. */ { char query[256]; struct sqlConnection *conn = hAllocConn(database); struct sqlResult *sr = NULL; char **row; int start = cartInt(cart, "o"); struct psl *pslList = NULL, *psl; char *tiNum = strrchr(itemName, '|'); boolean hasBin; -char table[64]; +char table[HDB_MAX_TABLE_STRING]; /* Print heading info including link to NCBI. */ if (tiNum != NULL) ++tiNum; cartWebStart(cart, database, "%s", itemName); printf("<H1>Information on Mouse %s %s</H1>", (tiNum == NULL ? "Contig" : "Read"), itemName); /* Print links to NCBI and to sequence. */ if (tiNum != NULL) { printf("Link to "); printf("<A HREF=\"https://www.ncbi.nlm.nih.gov/Traces/trace.cgi?val=%s\" TARGET=_blank>", tiNum); printf("NCBI Trace Repository for %s\n</A><BR>\n", itemName); } @@ -13844,31 +13868,32 @@ printf("Get "); printf("<A HREF=\"%s&g=htcExtSeq&c=%s&l=%d&r=%d&i=%s\">", hgcPathAndSettings(), seqName, winStart, winEnd, ti); printf("DNA for read on other end of plasmid</A><BR>\n"); gotMate = TRUE; } } sqlFreeResult(&sr); } if (!gotMate) printf("No read from other end of plasmid in database.<BR>\n"); } /* Get alignment info and print. */ printf("<H2>Alignments</H2>\n"); -hFindSplitTable(database, seqName, tdb->table, table, &hasBin); +if (!hFindSplitTable(database, seqName, tdb->table, table, sizeof table, &hasBin)) + errAbort("track %s not found", tdb->table); sqlSafef(query, sizeof query, "select * from %s where qName = '%s'", table, itemName); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { psl = pslLoad(row+hasBin); slAddHead(&pslList, psl); } sqlFreeResult(&sr); slReverse(&pslList); printAlignments(pslList, start, "htcBlatXeno", tdb->table, itemName); printTrackHtml(tdb); } boolean parseRange(char *range, char **retSeq, int *retStart, int *retEnd) /* Parse seq:start-end into components. */ @@ -13890,37 +13915,38 @@ return TRUE; } void mustParseRange(char *range, char **retSeq, int *retStart, int *retEnd) /* Parse seq:start-end or die. */ { if (!parseRange(range, retSeq, retStart, retEnd)) errAbort("Malformed range %s", range); } struct psl *loadPslAt(char *track, char *qName, int qStart, int qEnd, char *tName, int tStart, int tEnd) /* Load a specific psl */ { struct dyString *dy = newDyString(1024); struct sqlConnection *conn = hAllocConn(database); -char table[64]; +char table[HDB_MAX_TABLE_STRING]; boolean hasBin; struct sqlResult *sr; char **row; struct psl *psl; -hFindSplitTable(database, tName, track, table, &hasBin); +if (!hFindSplitTable(database, tName, track, table, sizeof table, &hasBin)) + errAbort("track %s not found", track); sqlDyStringPrintf(dy, "select * from %s ", table); sqlDyStringPrintf(dy, "where qStart = %d ", qStart); sqlDyStringPrintf(dy, "and qEnd = %d ", qEnd); sqlDyStringPrintf(dy, "and qName = '%s' ", qName); sqlDyStringPrintf(dy, "and tStart = %d ", tStart); sqlDyStringPrintf(dy, "and tEnd = %d ", tEnd); sqlDyStringPrintf(dy, "and tName = '%s'", tName); sr = sqlGetResult(conn, dy->string); row = sqlNextRow(sr); if (row == NULL) errAbort("Couldn't loadPslAt %s:%d-%d", tName, tStart, tEnd); psl = pslLoad(row + hasBin); sqlFreeResult(&sr); freeDyString(&dy); hFreeConn(&conn); @@ -14198,61 +14224,61 @@ struct axtInfo *aiList = NULL; struct axt *axtList = NULL; struct sqlResult *sr; char **row; char trackTemp[256]; char *track = cartString(cart, "o"); char *chrom = cartString(cart, "c"); char *name = cartOptionalString(cart, "i"); char *db2 = cartString(cart, "db2"); int tStart = cgiInt("l"); int tEnd = cgiInt("r"); char *qChrom = cgiOptionalString("qc"); int chainId = cgiInt("ci"); int qStart = cgiInt("qs"); int qEnd = cgiInt("qe"); -char table[64]; +char table[HDB_MAX_TABLE_STRING]; char query[512]; char nibFile[512]; char qNibFile[512]; char qNibDir[512]; char tNibDir[512]; char path[512]; boolean hasBin; struct sqlConnection *conn = hAllocConn(database); struct sqlConnection *conn2; struct hash *qChromHash = hashNew(0); struct cnFill *fill; struct chain *chain; struct dnaSeq *tChrom = NULL; cartWebStart(cart, database, "Alignment of %s in %s to pseudogene in %s", name, hOrganism(db2), hOrganism(database)); conn2 = hAllocConn(db2); /* get nibFile for pseudoGene */ sqlSafef(query, sizeof query, "select fileName from chromInfo where chrom = '%s'", chrom); if (sqlQuickQuery(conn, query, nibFile, sizeof(nibFile)) == NULL) errAbort("Sequence %s isn't in chromInfo", chrom); /* get nibFile for Gene in other species */ sqlSafef(query, sizeof query, "select fileName from chromInfo where chrom = '%s'" ,qChrom); if (sqlQuickQuery(conn2, query, qNibFile, sizeof(qNibFile)) == NULL) errAbort("Sequence chr1 isn't in chromInfo"); /* get gp */ -if (!hFindSplitTable(db2, qChrom, track, table, &hasBin)) +if (!hFindSplitTable(db2, qChrom, track, table, sizeof table, &hasBin)) errAbort("htcPseudoGene: table %s not found.\n",track); else if (sameString(track, "mrna")) { struct psl *psl = NULL ; sqlSafef(query, sizeof(query), "select * from %s where qName = '%s' and tName = '%s' and tStart = %d ", table, name, qChrom, qStart ); sr = sqlGetResult(conn2, query); if ((row = sqlNextRow(sr)) != NULL) { psl = pslLoad(row+hasBin); if (psl != NULL) gp = genePredFromPsl(psl, psl->tStart, psl->tEnd, 10); } @@ -14384,59 +14410,60 @@ } void doAlignCompGeno(struct trackDb *tdb, char *itemName, char *otherGenome) /* Handle click on blat or blastz track in a generic fashion */ /* otherGenome is the text to display for genome name on details page */ { char query[256]; struct sqlConnection *conn = hAllocConn(database); struct sqlResult *sr = NULL; char **row; int start = cartInt(cart, "o"); int end = cartInt(cart, "t"); char *chrom = cartString(cart, "c"); struct psl *pslList = NULL, *psl; boolean hasBin; -char table[64]; +char table[HDB_MAX_TABLE_STRING]; char *typeLine = cloneString(tdb->type); char *words[8]; int wordCount = chopLine(typeLine, words); if (wordCount == 3) { if (sameString(words[0], "psl") && sameString(words[1], "xeno")) { /* words[2] will contain other db */ doAlignmentOtherDb(tdb, itemName); freeMem(typeLine); return; } } freeMem(typeLine); cartWebStart(cart, database, "%s", itemName); printPosOnChrom(chrom,start,end,NULL,FALSE,NULL); printf("<H1>Information on %s Sequence %s</H1>", otherGenome, itemName); printf("Get "); printf("<A HREF=\"%s&g=htcExtSeq&c=%s&l=%d&r=%d&i=%s\">", hgcPathAndSettings(), seqName, winStart, winEnd, itemName); printf("%s DNA</A><BR>\n", otherGenome); /* Get alignment info and print. */ printf("<H2>Alignments</H2>\n"); -hFindSplitTable(database, seqName, tdb->table, table, &hasBin); +if (!hFindSplitTable(database, seqName, tdb->table, table, sizeof table, &hasBin)) + errAbort("doAlignCompGeno track %s not found", tdb->table); /* if this is a non-split table then query with tName */ if (startsWith(tdb->table, table)) sqlSafef(query, sizeof(query), "select * from %s where qName = '%s' and tName = '%s'", table, itemName,seqName); else sqlSafef(query, sizeof(query), "select * from %s where qName = '%s'", table, itemName); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { psl = pslLoad(row+hasBin); slAddHead(&pslList, psl); } sqlFreeResult(&sr); slReverse(&pslList); printAlignments(pslList, start, "htcBlatXeno", tdb->table, itemName); @@ -18867,77 +18894,79 @@ { char *strand = NULL; if (bedSize >= 4) printf("<B>Item:</B> %s<BR>\n", bed->name); if (bedSize >= 6) { strand = bed->strand; } printPos(bed->chrom, bed->chromStart, bed->chromEnd, strand, TRUE, bed->name); } void doNcRna(struct trackDb *tdb, char *item) /* Handle click in ncRna track. */ { struct ncRna *ncRna; -char table[64]; +char table[HDB_MAX_TABLE_STRING]; boolean hasBin; struct bed *bed; char query[512]; struct sqlResult *sr; char **row; struct sqlConnection *conn = hAllocConn(database); int bedSize; genericHeader(tdb, item); bedSize = 8; -hFindSplitTable(database, seqName, tdb->table, table, &hasBin); +if (!hFindSplitTable(database, seqName, tdb->table, table, sizeof table, &hasBin)) + errAbort("track %s not found", tdb->table); sqlSafef(query, sizeof query, "select * from %s where name = '%s'", table, item); sr = sqlGetResult(conn, query); if ((row = sqlNextRow(sr)) != NULL) { ncRna = ncRnaLoad(row); printCustomUrl(tdb, item, TRUE); printf("<B>Type:</B> %s<BR>", ncRna->type); if (ncRna->extGeneId != NULL && !sameWord(ncRna->extGeneId, "")) { printf("<B>External Gene ID:</B> %s<BR>", ncRna->extGeneId); } bed = bedLoadN(row+hasBin, bedSize); ncRnaPrintPos(bed, bedSize); } sqlFreeResult(&sr); printTrackHtml(tdb); } void doWgRna(struct trackDb *tdb, char *item) /* Handle click in wgRna track. */ { struct wgRna *wgRna; -char table[64]; +char table[HDB_MAX_TABLE_STRING]; boolean hasBin; struct bed *bed; char query[512]; struct sqlResult *sr; char **row; struct sqlConnection *conn = hAllocConn(database); int bedSize; genericHeader(tdb, item); bedSize = 8; -hFindSplitTable(database, seqName, tdb->table, table, &hasBin); +if (!hFindSplitTable(database, seqName, tdb->table, table, sizeof table, &hasBin)) + errAbort("track %s not found", tdb->table); sqlSafef(query, sizeof query, "select * from %s where name = '%s'", table, item); sr = sqlGetResult(conn, query); if ((row = sqlNextRow(sr)) != NULL) { wgRna = wgRnaLoad(row); /* display appropriate RNA type and URL */ if (sameWord(wgRna->type, "HAcaBox")) { printCustomUrl(tdb, item, TRUE); printf("<B>RNA Type:</B> H/ACA Box snoRNA\n"); } if (sameWord(wgRna->type, "CDBox")) { printCustomUrl(tdb, item, TRUE); @@ -19226,38 +19255,39 @@ if (!first) puts("<BR>"); } printTrackHtml(tdb); hFreeConn(&conn); } void doJaxAliasGenePred(struct trackDb *tdb, char *item) /* Show gene prediction position and other info. */ { char query[512]; struct sqlConnection *conn = hAllocConn(database); struct sqlConnection *conn2 = hAllocConn(database); struct genePred *gpList = NULL, *gp = NULL; boolean hasBin; -char table[128]; +char table[HDB_MAX_TABLE_STRING]; char aliasTable[256]; boolean gotAlias = FALSE; genericHeader(tdb, item); safef(aliasTable, sizeof(aliasTable), "%sAlias", tdb->table); gotAlias = hTableExists(database, aliasTable); -hFindSplitTable(database, seqName, tdb->table, table, &hasBin); +if (!hFindSplitTable(database, seqName, tdb->table, table, sizeof table, &hasBin)) + errAbort("track %s not found", tdb->table); sqlSafefFrag(query, sizeof(query), "name = \"%s\"", item); gpList = genePredReaderLoadQuery(conn, table, query); for (gp = gpList; gp != NULL; gp = gp->next) { if (gotAlias) { char query2[1024]; char buf[512]; char *mgiId; sqlSafef(query2, sizeof(query2), "select alias from %s where name = '%s'", aliasTable, item); mgiId = sqlQuickQuery(conn2, query2, buf, sizeof(buf)); if (mgiId != NULL) printCustomUrl(tdb, mgiId, TRUE); } @@ -19489,31 +19519,31 @@ char* handler = trackDbSetting(tdb, "trackHandler"); return (sameWord(word, tdb->table) || (handler==NULL || sameWord(word, handler))); } void doLinkedFeaturesSeries(char *track, char *clone, struct trackDb *tdb) /* Create detail page for linked features series tracks */ { char query[256]; char title[256]; struct sqlConnection *conn = hAllocConn(database), *conn1 = hAllocConn(database); struct sqlResult *sr = NULL, *sr2 = NULL, *srb = NULL; char **row, **row1, **row2, **rowb; char *lfLabel = NULL; char *table = NULL; char *intName = NULL; -char pslTable[64]; +char pslTable[HDB_MAX_TABLE_STRING]; int start = cartInt(cart, "o"); int end = cartInt(cart, "t"); int length = end - start; int i; struct lfs *lfs; struct psl *pslList = NULL, *psl; boolean hasBin = hOffsetPastBin(database, seqName, track); /* Determine type */ if (matchTableOrHandler("bacEndPairs", tdb)) { safef(title, sizeof title, "Location of %s using BAC end sequences", clone); lfLabel = "BAC ends"; table = track; } @@ -19674,31 +19704,32 @@ if (lfs->score == 1000) { printf("<H4>This is the only location found for %s</H4>\n",clone); } else { //printOtherLFS(clone, table, start, end); } safef(title, sizeof title, "Genomic alignments of %s:", lfLabel); webNewSection("%s",title); for (i = 0; i < lfs->lfCount; i++) { sqlFreeResult(&sr); - hFindSplitTable(database, seqName, lfs->pslTable, pslTable, &hasBin); + if (!hFindSplitTable(database, seqName, lfs->pslTable, pslTable, sizeof pslTable, &hasBin)) + errAbort("track %s not found", lfs->pslTable); if (isEmpty(pslTable) && trackDbSetting(tdb, "lfPslTable")) safecpy(pslTable, sizeof(pslTable), trackDbSetting(tdb, "lfPslTable")); sqlSafef(query, sizeof query, "SELECT * FROM %s WHERE qName = '%s'", pslTable, lfs->lfNames[i]); sr = sqlMustGetResult(conn, query); while ((row1 = sqlNextRow(sr)) != NULL) { psl = pslLoad(row1+hasBin); slAddHead(&pslList, psl); } slReverse(&pslList); if ((!sameString("fosEndPairs", track)) @@ -20156,44 +20187,45 @@ printf("<b>Source annotation:</b> %s<br>\n", chick->sourceAnnot); printf("<b>TIGR assigned TC:</b> %s<br>\n", chick->tigrTc); printf("<b>TIGR TC annotation:</b> %s<br>\n", chick->tigrTcAnnot); printf("<b>BLAST determined annotation:</b> %s<br>\n", chick->blastAnnot); printf("<b>Comment:</b> %s<br>\n", chick->comment); } genericBedClick(conn, tdb, item, start, 1); printTrackHtml(tdb); hFreeConn(&conn); } void perlegenDetails(struct trackDb *tdb, char *item) { int start = cartInt(cart, "o"); struct sqlConnection *conn = hAllocConn(database); -char table[64]; +char table[HDB_MAX_TABLE_STRING]; boolean hasBin; struct bed *bed; char query[512]; struct sqlResult *sr; char **row; boolean firstTime = TRUE; int numSnpsReq = -1; if(tdb == NULL) errAbort("TrackDb entry null for perlegen, item=%s\n", item); genericHeader(tdb, item); printCustomUrl(tdb, item, FALSE); -hFindSplitTable(database, seqName, tdb->table, table, &hasBin); +if (!hFindSplitTable(database, seqName, tdb->table, table, sizeof table, &hasBin)) + errAbort("track %s not found", tdb->table); sqlSafef(query, sizeof query, "select * from %s where name = '%s' and chrom = '%s' and chromStart = %d", table, item, seqName, start); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { char *name; /* set up for first time */ if (firstTime) firstTime = FALSE; else htmlHorizontalLine(); bed = bedLoadN(row+hasBin, 12); /* chop leading digits off name which should be in x/yyyyyy format */ @@ -20226,85 +20258,87 @@ /* finish off report ... */ printf("<B>Block:</B> %s<BR>\n", name); printf("<B>Number of SNPs in block:</B> %d<BR>\n", bed->blockCount); printf("<B>Number of SNPs to represent block:</B> %d<BR>\n",numSnpsReq); printf("<B>Strand:</B> %s<BR>\n", bed->strand); bedPrintPos(bed, 3, tdb); } printTrackHtml(tdb); hFreeConn(&conn); } void haplotypeDetails(struct trackDb *tdb, char *item) { int start = cartInt(cart, "o"); struct sqlConnection *conn = hAllocConn(database); -char table[64]; +char table[HDB_MAX_TABLE_STRING]; boolean hasBin; struct bed *bed; char query[512]; struct sqlResult *sr; char **row; boolean firstTime = TRUE; if(tdb == NULL) errAbort("TrackDb entry null for haplotype, item=%s\n", item); genericHeader(tdb, item); printCustomUrl(tdb, item, TRUE); -hFindSplitTable(database, seqName, tdb->table, table, &hasBin); +if (!hFindSplitTable(database, seqName, tdb->table, table, sizeof table, &hasBin)) + errAbort("track %s not found", tdb->table); sqlSafef(query, sizeof query, "select * from %s where name = '%s' and chrom = '%s' and chromStart = %d", table, item, seqName, start); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { /* set up for first time */ if (firstTime) firstTime = FALSE; else htmlHorizontalLine(); bed = bedLoadN(row+hasBin, 12); /* finish off report ... */ printf("<B>Block:</B> %s<BR>\n", bed->name); printf("<B>Number of SNPs in block:</B> %d<BR>\n", bed->blockCount); /* printf("<B>Number of SNPs to represent block:</B> %d<BR>\n",numSnpsReq);*/ printf("<B>Strand:</B> %s<BR>\n", bed->strand); bedPrintPos(bed, 3, tdb); } printTrackHtml(tdb); hFreeConn(&conn); } void mitoDetails(struct trackDb *tdb, char *item) { int start = cartInt(cart, "o"); struct sqlConnection *conn = hAllocConn(database); -char table[64]; +char table[HDB_MAX_TABLE_STRING]; boolean hasBin; struct bed *bed; char query[512]; struct sqlResult *sr; char **row; boolean firstTime = TRUE; int numSnpsReq = -1; if(tdb == NULL) errAbort("TrackDb entry null for mitoSnps, item=%s\n", item); genericHeader(tdb, item); printCustomUrl(tdb, item, TRUE); -hFindSplitTable(database, seqName, tdb->table, table, &hasBin); +if (!hFindSplitTable(database, seqName, tdb->table, table, sizeof table, &hasBin)) + errAbort("track %s not found", tdb->table); sqlSafef(query, sizeof query, "select * from %s where name = '%s' and chrom = '%s' and chromStart = %d", table, item, seqName, start); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { char *name; /* set up for first time */ if (firstTime) firstTime = FALSE; else htmlHorizontalLine(); bed = bedLoadN(row+hasBin, 12); /* chop leading digits off name which should be in xx/yyyyyy format */ @@ -20335,45 +20369,46 @@ } /* finish off report ... */ printf("<B>Block:</B> %s<BR>\n", name); printf("<B>Number of SNPs in block:</B> %d<BR>\n", bed->blockCount); printf("<B>Number of SNPs to represent block:</B> %d<BR>\n",numSnpsReq); printf("<B>Strand:</B> %s<BR>\n", bed->strand); bedPrintPos(bed, 3, tdb); } printTrackHtml(tdb); hFreeConn(&conn); } void ancientRDetails(struct trackDb *tdb, char *item) { struct sqlConnection *conn = hAllocConn(database); -char table[64]; +char table[HDB_MAX_TABLE_STRING]; boolean hasBin; struct bed *bed = NULL; char query[512]; struct sqlResult *sr = NULL; char **row; boolean firstTime = TRUE; double ident = -1.0; struct ancientRref *ar = NULL; if(tdb == NULL) errAbort("TrackDb entry null for ancientR, item=%s\n", item); genericHeader(tdb, item); printCustomUrl(tdb, item, TRUE); -hFindSplitTable(database, seqName, tdb->table, table, &hasBin); +if (!hFindSplitTable(database, seqName, tdb->table, table, sizeof table, &hasBin)) + errAbort("track %s not found", tdb->table); sqlSafef(query, sizeof query, "select * from %s where name = '%s' and chrom = '%s'", table, item, seqName ); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { char *name; /* set up for first time */ if (firstTime) firstTime = FALSE; else htmlHorizontalLine(); bed = bedLoadN(row+hasBin, 12); name = bed->name; @@ -20418,35 +20453,36 @@ printTrackHtml(tdb); hFreeConn(&conn); } void doGcDetails(struct trackDb *tdb, char *itemName) /* Show details for gc percent */ { int start = cartInt(cart, "o"); struct sqlConnection *conn = hAllocConn(database); struct sqlResult *sr; char **row; char query[256]; struct gcPercent *gc; boolean hasBin; -char table[64]; +char table[HDB_MAX_TABLE_STRING]; cartWebStart(cart, database, "Percentage GC in 20,000 Base Windows (GC)"); -hFindSplitTable(database, seqName, tdb->table, table, &hasBin); +if (!hFindSplitTable(database, seqName, tdb->table, table, sizeof table, &hasBin)) + errAbort("track %s not found", tdb->table); sqlSafef(query, sizeof query, "select * from %s where chrom = '%s' and chromStart = %d and name = '%s'", table, seqName, start, itemName); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { gc = gcPercentLoad(row + hasBin); printPos(gc->chrom, gc->chromStart, gc->chromEnd, NULL, FALSE, NULL); printf("<B>GC Percentage:</B> %3.1f%%<BR>\n", ((float)gc->gcPpt)/10); gcPercentFree(&gc); } printTrackHtml(tdb); sqlFreeResult(&sr); hFreeConn(&conn); } @@ -21091,63 +21127,65 @@ } static double whichNum( double tmp, double min0, double max0, int n) /*gets range nums. from bin values*/ { return( (max0 - min0)/(double)n * tmp + min0 ); } void humMusSampleClick(struct sqlConnection *conn, struct trackDb *tdb, char *item, int start, int smpSize, char *otherOrg, char *otherDb, char *pslTableName, boolean printWindowFlag ) /* Handle click in humMus sample (wiggle) track. */ { int humMusWinSize = 50; int i; -char table[64]; +char table[HDB_MAX_TABLE_STRING]; boolean hasBin; struct sample *smp; char query[512]; char tempTableName[1024]; struct sqlResult *sr; char **row; char **pslRow; boolean firstTime = TRUE; struct psl *thisPsl; char str[256]; char thisItem[256]; char otherString[256] = ""; struct sqlResult *pslSr; struct sqlConnection *conn2 = hAllocConn(database); int thisStart, thisEnd; int left = cartIntExp( cart, "l" ); int right = cartIntExp( cart, "r" ); char *winOn = cartUsualString( cart, "win", "F" ); -hFindSplitTable(database, seqName, tdb->table, table, &hasBin); +if (!hFindSplitTable(database, seqName, tdb->table, table, sizeof table, &hasBin)) + errAbort("track %s not found", tdb->table); sqlSafef(query, sizeof query, "select * from %s where name = '%s' and chrom = '%s'", table, item, seqName); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { if (firstTime) firstTime = FALSE; else htmlHorizontalLine(); smp = sampleLoad(row+hasBin); safef(tempTableName, sizeof tempTableName, "%s_%s", smp->chrom, pslTableName ); - hFindSplitTable(database, seqName, pslTableName, table, &hasBin); + if (!hFindSplitTable(database, seqName, pslTableName, table, sizeof table, &hasBin)) + errAbort("table %s not found", pslTableName); sqlSafef(query, sizeof query, "select * from %s where tName = '%s' and tEnd >= %d and tStart <= %d" , table, smp->chrom, smp->chromStart+smp->samplePosition[0] , smp->chromStart+smp->samplePosition[smp->sampleCount-1] ); pslSr = sqlGetResult(conn2, query); if(!sameString(winOn,"T")) { while(( pslRow = sqlNextRow(pslSr)) != NULL ) { thisPsl = pslLoad( pslRow+hasBin ); firstAndLastPosition( &thisStart, &thisEnd, thisPsl ); snprintf(thisItem, 256, "%s:%d-%d %s:%d-%d", thisPsl->qName, thisPsl->qStart, thisPsl->qEnd, thisPsl->tName, thisPsl->tStart, thisPsl->tEnd ); longXenoPsl1Given(tdb, thisItem, otherOrg, "chromInfo", @@ -21188,60 +21226,62 @@ humMusWinSize / 2, smp->chromStart + smp->samplePosition[i] + humMusWinSize / 2, str, otherOrg, otherDb, pslTableName ); } printf("<br>"); } } } } void footPrinterSampleClick(struct sqlConnection *conn, struct trackDb *tdb, char *item, int start, int smpSize) /* Handle click in humMus sample (wiggle) track. */ { -char table[64]; +char table[HDB_MAX_TABLE_STRING]; boolean hasBin; struct sample *smp; char query[512]; char tempTableName[1024]; struct sqlResult *sr; char **row; boolean firstTime = TRUE; char filename[10000]; char pslTableName[128] = "blastzBestMouse"; int offset; int motifid; -hFindSplitTable(database, seqName, tdb->table, table, &hasBin); +if (!hFindSplitTable(database, seqName, tdb->table, table, sizeof table, &hasBin)) + errAbort("track %s not found", tdb->table); sqlSafef(query, sizeof query, "select * from %s where name = '%s'", table, item); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { if (firstTime) firstTime = FALSE; else htmlHorizontalLine(); smp = sampleLoad(row+hasBin); sscanf(smp->name,"footPrinter.%d.%d",&offset,&motifid); safef(filename, sizeof filename, "../zoo_blanchem/new_raw2_offset%d.fa.main.html?motifID=%d", offset, motifid); safef(tempTableName, sizeof tempTableName,"%s_%s", smp->chrom, pslTableName ); - hFindSplitTable(database, seqName, pslTableName, table, &hasBin); + if (!hFindSplitTable(database, seqName, pslTableName, table, sizeof table, &hasBin)) + errAbort("table %s not found", pslTableName); sqlSafef(query, sizeof query, "select * from %s where tName = '%s' and tEnd >= %d and tStart <= %d" , table, smp->chrom, smp->chromStart+smp->samplePosition[0], smp->chromStart+smp->samplePosition[smp->sampleCount-1] ); printf("Content-Type: text/html\n\n<HTML><BODY><SCRIPT>\n"); printf("location.replace('%s')\n",filename); printf("</SCRIPT> <NOSCRIPT> No JavaScript support. " "Click <b><a href=\"%s\">continue</a></b> for " "the requested GenBank report. </NOSCRIPT>\n", filename); } } void humMusClickHandler(struct trackDb *tdb, char *item, char *targetName, char *targetDb, char *targetTable, boolean printWindowFlag ) @@ -21772,38 +21812,38 @@ sgdCloneStaticLoad(row+1, &sgd); dyStringPrintf(dy, "<B>ATCC catalog number:</B><A HREF=\"http://www.atcc.org/ATCCAdvancedCatalogSearch/ProductDetails/tabid/452/Default.aspx?ATCCNum=%s&Template=uniqueClones\" TARGET=_blank>%s</A><BR>\n", sgd.atccName, sgd.atccName); } sqlFreeResult(&sr); } hFreeConn(&conn); genericClickHandlerPlus(tdb, item, NULL, dy->string); dyStringFree(&dy); } static void doSimpleDiff(struct trackDb *tdb, char *otherOrg) /* Print out simpleDiff info. */ { struct simpleNucDiff snd; struct sqlConnection *conn = hAllocConn(database); -char fullTable[64]; +char fullTable[HDB_MAX_TABLE_STRING]; char query[256], **row; struct sqlResult *sr; int rowOffset; int start = cartInt(cart, "o"); genericHeader(tdb, NULL); -if (!hFindSplitTable(database, seqName, tdb->table, fullTable, &rowOffset)) +if (!hFindSplitTable(database, seqName, tdb->table, fullTable, sizeof fullTable, &rowOffset)) errAbort("No %s table in database %s", tdb->table, database); sqlSafef(query, sizeof(query), "select * from %s where chrom = '%s' and chromStart=%d", fullTable, seqName, start); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { simpleNucDiffStaticLoad(row + rowOffset, &snd); printf("<B>%s sequence:</B> %s<BR>\n", hOrganism(database), snd.tSeq); printf("<B>%s sequence:</B> %s<BR>\n", otherOrg, snd.qSeq); bedPrintPos((struct bed*)&snd, 3, tdb); printf("<BR>\n"); } sqlFreeResult(&sr); hFreeConn(&conn); printTrackHtml(tdb); @@ -21848,36 +21888,37 @@ } } sqlFreeResult(&sr); hFreeConn(&conn); printTrackHtml(tdb); } static void doZdobnovSynt(struct trackDb *tdb, char *item) /* Gene homology-based synteny blocks from Zdobnov, Bork et al. */ { struct sqlConnection *conn = hAllocConn(database); struct sqlResult *sr = NULL; char **row; char query[256]; int start = cartInt(cart, "o"); -char fullTable[64]; +char fullTable[HDB_MAX_TABLE_STRING]; boolean hasBin = FALSE; genericHeader(tdb, item); genericBedClick(conn, tdb, item, start, 4); -hFindSplitTable(database, seqName, tdb->table, fullTable, &hasBin); +if (!hFindSplitTable(database, seqName, tdb->table, fullTable, sizeof fullTable, &hasBin)) + errAbort("track %s not found", tdb->table); sqlSafef(query, sizeof(query), "select * from %s where name = '%s'", fullTable, item); sr = sqlGetResult(conn, query); if ((row = sqlNextRow(sr)) != NULL) { struct zdobnovSynt *zd = zdobnovSyntLoad(row + hasBin); int l = cgiInt("l"); int r = cgiInt("r"); int i = 0; puts("<B>Homologous gene names in window:</B>"); for (i=0; i < zd->blockCount; i++) { int bStart = zd->chromStarts[i] + zd->chromStart; int bEnd = bStart + zd->blockSizes[i]; if (bStart <= r && bEnd >= l) @@ -21891,37 +21932,38 @@ else errAbort("query returned no results: \"%s\"", query); sqlFreeResult(&sr); hFreeConn(&conn); printTrackHtml(tdb); } static void doDeweySynt(struct trackDb *tdb, char *item) /* Gene homology-based synteny blocks from Dewey, Pachter. */ { struct sqlConnection *conn = hAllocConn(database); struct sqlResult *sr = NULL; char **row; int start = cartInt(cart, "o"); -char fullTable[64]; +char fullTable[HDB_MAX_TABLE_STRING]; boolean hasBin = FALSE; struct bed *bed = NULL; char query[512]; genericHeader(tdb, item); -hFindSplitTable(database, seqName, tdb->table, fullTable, &hasBin); +if (!hFindSplitTable(database, seqName, tdb->table, fullTable, sizeof fullTable, &hasBin)) + errAbort("track %s not found", tdb->table); sqlSafef(query, sizeof(query), "select * from %s where chrom = '%s' and chromStart = %d", fullTable, seqName, start); sr = sqlGetResult(conn, query); if ((row = sqlNextRow(sr)) != NULL) { char *words[4]; int wordCount = 0; bed = bedLoad6(row+hasBin); bedPrintPos(bed, 4, tdb); printf("<B>Strand:</B> %s<BR>\n", bed->strand); wordCount = chopByChar(bed->name, '.', words, ArraySize(words)); if (wordCount == 3 && hDbExists(words[1])) { char *otherOrg = hOrganism(words[1]); @@ -22056,67 +22098,69 @@ encodeStanfordPromotersAverageLoad(row); bedPrintPos((struct bed *)esp, 6, tdb); printf("<B>Gene model ID:</B> %s<BR>\n", esp->geneModel); printf("<B>Gene description:</B> %s<BR>\n", esp->description); printf("<B>Normalized and log2 transformed Luciferase/Renilla Ratio:</B> %g<BR>\n", esp->normLog2Ratio); } void doEncodeStanfordPromoters(struct trackDb *tdb, char *item) /* Print ENCODE Stanford Promoters data. */ { struct sqlConnection *conn = hAllocConn(database); struct sqlResult *sr = NULL; char **row = NULL; int start = cartInt(cart, "o"); -char fullTable[64]; +char fullTable[HDB_MAX_TABLE_STRING]; boolean hasBin = FALSE; char query[1024]; cartWebStart(cart, database, "%s", tdb->longLabel); genericHeader(tdb, item); -hFindSplitTable(database, seqName, tdb->table, fullTable, &hasBin); +if (!hFindSplitTable(database, seqName, tdb->table, fullTable, sizeof fullTable, &hasBin)) + errAbort("track %s not found", tdb->table); sqlSafef(query, sizeof(query), "select * from %s where chrom = '%s' and chromStart = %d and name = '%s'", fullTable, seqName, start, item); sr = sqlGetResult(conn, query); if ((row = sqlNextRow(sr)) != NULL) { if (endsWith(tdb->table, "Average")) printESPAverageDetails(row+hasBin, tdb); else printESPDetails(row+hasBin, tdb); } sqlFreeResult(&sr); hFreeConn(&conn); printTrackHtml(tdb); } void doEncodeStanfordRtPcr(struct trackDb *tdb, char *item) /* Print ENCODE Stanford RTPCR data. */ { struct sqlConnection *conn = hAllocConn(database); struct sqlResult *sr = NULL; char **row = NULL; int start = cartInt(cart, "o"); -char fullTable[64]; +char fullTable[HDB_MAX_TABLE_STRING]; boolean hasBin = FALSE; char query[1024]; cartWebStart(cart, database, "%s", tdb->longLabel); genericHeader(tdb, item); -hFindSplitTable(database, seqName, tdb->table, fullTable, &hasBin); +if (!hFindSplitTable(database, seqName, tdb->table, fullTable, sizeof fullTable, &hasBin)) + errAbort("track %s not found", tdb->table); sqlSafef(query, sizeof(query), "select * from %s where chrom = '%s' and chromStart = %d and name = '%s'", fullTable, seqName, start, item); sr = sqlGetResult(conn, query); if ((row = sqlNextRow(sr)) != NULL) { struct bed *bed = bedLoadN(row+hasBin, 5); bedPrintPos(bed, 5, tdb); printf("<B>Primer pair ID:</B> %s<BR>\n", row[hasBin+5]); printf("<B>Count:</B> %s<BR>\n", row[hasBin+6]); } sqlFreeResult(&sr); hFreeConn(&conn); printTrackHtml(tdb); } @@ -22666,36 +22710,37 @@ else return NULL; struct sqlConnection *conn = hAllocConn(database); char *resultOrNULL = sqlQuickQuery(conn, query, result, sizeof(result)); hFreeConn(&conn); return resultOrNULL; } static void doPscreen(struct trackDb *tdb, char *item) /* P-Screen (BDGP Gene Disruption Project) P el. insertion locations/genes. */ { struct sqlConnection *conn = hAllocConn(database); struct sqlResult *sr = NULL; char **row; int start = cartInt(cart, "o"); -char fullTable[64]; +char fullTable[HDB_MAX_TABLE_STRING]; boolean hasBin = FALSE; char query[512]; genericHeader(tdb, item); -hFindSplitTable(database, seqName, tdb->table, fullTable, &hasBin); +if (!hFindSplitTable(database, seqName, tdb->table, fullTable, sizeof fullTable, &hasBin)) + errAbort("track %s not found", tdb->table); sqlSafef(query, sizeof(query), "select * from %s where chrom = '%s' and chromStart = %d and name = '%s'", fullTable, seqName, start, item); sr = sqlGetResult(conn, query); if ((row = sqlNextRow(sr)) != NULL) { struct pscreen *psc = pscreenLoad(row+hasBin); int i; printCustomUrl(tdb, psc->name, FALSE); printPosOnChrom(psc->chrom, psc->chromStart, psc->chromEnd, psc->strand, FALSE, psc->name); if (psc->stockNumber != 0) printf("<B>Stock number:</B> " "<A HREF=\"http://flystocks.bio.indiana.edu/Reports/%d.html\" " "TARGET=_BLANK>%d</A><BR>\n", psc->stockNumber, @@ -23197,38 +23242,38 @@ puts("</HTML>\n"); exit(0); /* Avoid cartHtmlEnd. */ } void potentPslAlign(char *htcCommand, char *item) {/* show the detail psl alignment between genome */ char *pslTable = cgiString("pslTable"); char *chrom = cgiString("chrom"); int start = cgiInt("cStart"); int end = cgiInt("cEnd"); struct psl *psl = NULL; struct dnaSeq *qSeq = NULL; char *db = cgiString("db"); char name[64]; -char query[256], fullTable[64]; +char query[256], fullTable[HDB_MAX_TABLE_STRING]; char **row; boolean hasBin; struct sqlResult *sr = NULL; struct sqlConnection *conn = hAllocConn(database); - -hFindSplitTable(database, chrom, pslTable, fullTable, &hasBin); +if (!hFindSplitTable(database, seqName, pslTable, fullTable, sizeof fullTable, &hasBin)) + errAbort("track %s not found", pslTable); sqlSafef(query, sizeof query, "SELECT * FROM %s WHERE " "tName = '%s' AND tStart = %d " "AND tEnd = %d", pslTable, chrom, start, end); sr = sqlMustGetResult(conn, query); row = sqlNextRow(sr); if(row != NULL) { psl = pslLoad(row+hasBin); } else { errAbort("No alignment infomation\n"); }