37977956905d588f73ee5f635fae2f609cb40842 angie Wed Aug 9 12:52:00 2017 -0700 Assorted little util functions in support of adding HGVS output to hgVai -- refs #19968 diff --git src/hg/lib/hdb.c src/hg/lib/hdb.c index aa9d1fc..9690a72 100644 --- src/hg/lib/hdb.c +++ src/hg/lib/hdb.c @@ -5516,15 +5516,54 @@ // Don't know how to find SNP tracks on hub yet return NULL; struct sqlConnection *conn = hAllocConn(db); struct slName *snpNNNTables = hListSnpNNNTables(conn, suffix); // Return the first trackDb that we can find (sometimes there is a brand new lastest-version table // that does not yet have a trackDb) struct slName *table; for (table = snpNNNTables; table != NULL; table = table->next) { struct trackDb *tdb = tdbForTrack(db, table->name, pFullTrackList); if (tdb) return tdb; } return NULL; } + +boolean hDbHasNcbiRefSeq(char *db) +/* Return TRUE if db has NCBI's RefSeq alignments and annotations. */ +{ +// hTableExists() caches results so this shouldn't make for loads of new SQL queries if called +// more than once. +return (hTableExists(db, "ncbiRefSeq") && hTableExists(db, "ncbiRefSeqPsl") && + hTableExists(db, "ncbiRefSeqCds") && hTableExists(db, "ncbiRefSeqLink") && + hTableExists(db, "ncbiRefSeqPepTable") && + hTableExists(db, "seqNcbiRefSeq") && hTableExists(db, "extNcbiRefSeq")); +} + +char *hRefSeqAccForChrom(char *db, char *chrom) +/* Return the RefSeq NC_000... accession for chrom if we can find it, else just chrom. + * db must never change. */ +{ +static char *firstDb = NULL; +static struct hash *accHash = NULL; +static boolean checkExistence = TRUE; +if (firstDb && !sameString(firstDb, db)) + errAbort("hRefSeqAccForChrom: only works for one db. %s was passed in earlier, now %s.", + firstDb, db); +char *seqAcc = NULL; +if (checkExistence && !trackHubDatabase(db) && hTableExists(db, "chromAlias")) + // Will there be a chromAlias for hubs someday?? + { + firstDb = db; + struct sqlConnection *conn = hAllocConn(db); + accHash = sqlQuickHash(conn, + NOSQLINJ "select chrom, alias from chromAlias where source = 'refseq'"); + hFreeConn(&conn); + checkExistence = FALSE; + } +if (accHash && hashNumEntries(accHash) > 0) + seqAcc = cloneString(hashFindVal(accHash, chrom)); +if (seqAcc == NULL) + seqAcc = cloneString(chrom); +return seqAcc; +}