24408c4294387692dc2fc26d4faab480a3e8fa3a galt Fri Aug 7 01:15:02 2015 -0700 Fixes bugs related to RM#15751 diff --git src/hg/lib/hgFind.c src/hg/lib/hgFind.c index 8262ad1..e854682 100644 --- src/hg/lib/hgFind.c +++ src/hg/lib/hgFind.c @@ -477,73 +477,70 @@ result = NULL; } freeDyString(&query); sqlFreeResult(&sr); hFreeConn(&conn); return result; } static boolean findKnownGeneExact(char *db, char *spec, char *geneSymbol, struct hgPositions *hgp, char *tableName) /* Look for position in Known Genes table. */ { struct sqlConnection *conn; struct sqlResult *sr = NULL; -struct dyString *query; +char query[256]; char **row; boolean ok = FALSE; struct hgPosTable *table = NULL; struct hgPos *pos = NULL; int rowOffset; char *localName; localName = spec; if (!hTableExists(db, tableName)) return FALSE; rowOffset = hOffsetPastBin(db, NULL, tableName); conn = hAllocConn(db); -query = newDyString(256); -sqlDyStringPrintf(query, - "SELECT chrom, txStart, txEnd, name FROM %s WHERE name='%s'", +sqlSafef(query, sizeof query, "SELECT chrom, txStart, txEnd, name FROM %s WHERE name='%s'", tableName, localName); -sr = sqlGetResult(conn, query->string); +sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { if (ok == FALSE) { ok = TRUE; AllocVar(table); if (hTableExists(db, "kgProtMap2")) table->description = cloneString("UCSC Genes"); else table->description = cloneString("Known Genes"); table->name = cloneString("knownGene"); slAddHead(&hgp->tableList, table); } AllocVar(pos); pos->chrom = hgOfficialChromName(db, row[0]); pos->chromStart = atoi(row[1]); pos->chromEnd = atoi(row[2]); pos->name = cloneString(geneSymbol); /* pos->browserName = cloneString(geneSymbol); highlight change */ pos->browserName = cloneString(row[3]); slAddHead(&table->posList, pos); } if (table != NULL) slReverse(&table->posList); -freeDyString(&query); sqlFreeResult(&sr); hFreeConn(&conn); return ok; } static struct hgPosTable *addKnownGeneTable(char *db, struct hgPositions *hgp) /* Create new table for known genes matches, add it to hgp, and return it. */ { struct hgPosTable *table; AllocVar(table); if (hTableExists(db, "kgProtMap2")) table->description = cloneString("UCSC Genes"); else table->description = cloneString("Known Genes"); table->name = cloneString("knownGene"); @@ -1869,30 +1866,32 @@ hashFree(&allKeysHash); hFreeConn(&conn); return(found); } static boolean isUnsignedInt(char *s) /* Return TRUE if s is in format to be an unsigned int. */ { int size=0; char c; while ((c = *s++) != 0) { if (++size > 10 || !isdigit(c)) return FALSE; } +if (size==0) + return FALSE; return TRUE; } #if 0 /* not used */ static void findAffyProbe(char *spec, struct hgPositions *hgp) /* Look up affy probes. */ { } #endif int findKgGenesByAlias(char *db, char *spec, struct hgPositions *hgp) /* Look up Known Genes using the gene Alias table, kgAlias. */ { struct sqlConnection *conn = hAllocConn(db); struct sqlConnection *conn2 = hAllocConn(db); @@ -2100,32 +2099,34 @@ } sqlFreeResult(&sr); } } static boolean findRefGenes(char *db, struct hgFindSpec *hfs, char *spec, struct hgPositions *hgp) /* Look up refSeq genes in table. */ { struct sqlConnection *conn = hAllocConn(db); struct dyString *ds = newDyString(256); struct refLink *rlList = NULL, *rl; boolean gotRefLink = hTableExists(db, "refLink"); boolean found = FALSE; char *specNoVersion = cloneString(spec); +// chop off the version number, e.g. "NM_000454.4 ", +// but if spec starts with "." like ".stuff" then specNoVersion is entirely empty. (void) chopPrefix(specNoVersion); -if (gotRefLink) +if (gotRefLink && isNotEmpty(specNoVersion)) { if (startsWith("NM_", specNoVersion) || startsWith("NR_", specNoVersion) || startsWith("XM_", specNoVersion)) { sqlDyStringPrintf(ds, "select * from refLink where mrnaAcc = '%s'", specNoVersion); addRefLinks(conn, ds, &rlList); } else if (startsWith("NP_", specNoVersion) || startsWith("XP_", specNoVersion)) { sqlDyStringPrintf(ds, "select * from refLink where protAcc = '%s'", specNoVersion); addRefLinks(conn, ds, &rlList); } else if (isUnsignedInt(specNoVersion)) { sqlDyStringPrintf(ds, "select * from refLink where locusLinkId = '%s'", specNoVersion);