d12a52edb9b3841adcfe42fc25b361e59654ef11 jcasper Fri Feb 28 15:59:19 2020 -0800 Better accounting for chromosome aliases in .hic files, refs #25055 diff --git src/hg/lib/chromAlias.c src/hg/lib/chromAlias.c index f400df2..0ec22b8 100644 --- src/hg/lib/chromAlias.c +++ src/hg/lib/chromAlias.c @@ -174,15 +174,42 @@ 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; } + +struct hash *chromAliasMakeReverseLookupTable(char *database) +/* Given a database name and a connection to that database, construct a lookup table + * that takes the actual assembly chromosome names to struct chromAliases. Because a + * chromosome name may well have multiple aliases, repeated calls to hashLookupNext + * may be required to see them all. 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->chrom, new); + } +sqlFreeResult(&sr); +hFreeConn(&conn); +return hash; +}