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)
\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("\n");
else
printf("
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("This is the item you clicked on:
\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("\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
\n");
break;
case cdsComplete: /* "cmpl" - CDS is complete at this end */
printf("complete
\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("Ensembl Transcript Id: ");
if (ensemblIdUrl != NULL)
printf("%s
", 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("
\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("",
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("Score: %1.0f\n", chain->score);
if (nullSubset)
printf("Score within browser window: N/A (no aligned bases)
\n");
else if (hDbIsActive(otherDb) && subChain != chain)
printf(" Approximate Score within browser window: %1.0f
\n",
subSetScore);
else
printf("
\n");
printf("
Fields above refer to entire chain or gap, not just the part inside the window.
\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("Normalized Score: %1.0f (bases matched: %d)
\n",
atof(row[0]), (int) (chain->score/atof(row[0])));
sqlFreeResult(&sr);
}
printf("
\n");
chainWinSize = min(winEnd-winStart, chain->tEnd - chain->tStart);
@@ -3475,58 +3482,59 @@
{
char *space = " ";
if (org == NULL)
org = space = "";
printf("%s%s%s: ", org, space, label);
printLongWithCommas(stdout, p);
if (q != 0)
printf(" (%3.1f%%)", 100.0 * p / q);
printf("
\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("
\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("
Fields above refer to entire chain or gap, not just the part inside the window.
\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("Transcription Factor Binding Site information:
");
@@ -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("Species: %s
\n", tfbs->species);
printf("SwissProt ID: %s
\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("Item: %s
\n", bed->name);
printf("Probability: %g
\n", bed->score / 1000.0);
printf("Strand: %s
\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("Score: %f
\n", b5->floatScore);
if (sameString(tdb->type, "bed5FloatScoreWithFdr"))
@@ -3869,41 +3882,42 @@
printf("False Discovery Rate (FDR): %s%%
\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("Score: %f
\n", b6->score);
printf("Strand: %s
\n", b6->strand);
@@ -4842,38 +4856,39 @@
"other software can safely display. The tool will format 10 Mb and more, however.
"); 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("Entrez nucleotide: %s"); 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("
\n", fragName, fragName); printf("Clone Fragment ID: %s
\n", frag.frag); printf("Clone Fragment Type: %s
\n", frag.type); printf("Clone Bases: %d-%d
\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("Gap Type: %s
\n", gap.type); printf("Bridged: %s
\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("CENSOR Information
\n"); else printf("RepeatMasker Information
\n"); while ((row = sqlNextRow(sr)) != NULL) { ro = rmskOutLoad(row+hasBin); printf("Name: %s\n", ro->repName, ro->repName); printf("(link requires registration)
"); printf("Family: %s
\n", ro->repFamily); printf("Class: %s
\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("