fe43cd3394528a515b867eb2e8f69d152bd4d178 jcasper Mon May 6 10:01:16 2019 -0700 A few initial library additions for eventual Hi-C support, refs #18842 diff --git src/hg/lib/chromAlias.c src/hg/lib/chromAlias.c index d8a466d..f400df2 100644 --- src/hg/lib/chromAlias.c +++ src/hg/lib/chromAlias.c @@ -1,25 +1,25 @@ /* chromAlias.c was originally generated by the autoSql program, which also * generated chromAlias.h and chromAlias.sql. This module links the database and * the RAM representation of objects. */ #include "common.h" #include "linefile.h" #include "dystring.h" #include "jksql.h" #include "chromAlias.h" - +#include "hdb.h" char *chromAliasCommaSepFieldNames = "alias,chrom,source"; void chromAliasStaticLoad(char **row, struct chromAlias *ret) /* Load a row from chromAlias table into ret. The contents of ret will * be replaced at the next call to this function. */ { ret->alias = row[0]; ret->chrom = row[1]; ret->source = row[2]; } struct chromAlias *chromAliasLoad(char **row) @@ -150,15 +150,39 @@ fprintf(f, "%s", el->chrom); fputc('"',f); fputc(',',f); fputc('"',f); fprintf(f,"source"); fputc('"',f); fputc(':',f); fputc('"',f); fprintf(f, "%s", el->source); fputc('"',f); fputc('}',f); } /* -------------------------------- End autoSql Generated Code -------------------------------- */ +struct hash *chromAliasMakeLookupTable(char *database) +/* Given a database name and a connection to that database, construct a lookup table + * that takes chromosome alias names to a matching struct chromAlias. Returns NULL + * if the given database does not have a chromAlias table. */ +{ +struct hash *hash = NULL; +if (!hTableExists(database, "chromAlias")) + return NULL; + +struct sqlConnection *conn = hAllocConn(database); +hash = hashNew(0); +char query[2048]; +sqlSafef(query, sizeof(query), "select * from chromAlias"); +struct sqlResult *sr = sqlGetResult(conn, query); +char **row; +while ((row = sqlNextRow(sr)) != NULL) + { + struct chromAlias *new = chromAliasLoad(row); + hashAdd(hash, new->alias, new); + } +sqlFreeResult(&sr); +hFreeConn(&conn); +return hash; +}