94ab45bc69a304d7f68851812e96de7af8943f6d angie Wed Mar 9 13:12:36 2016 -0800 Libified hgVai's code to find the latest snpNNN table so that other spots in the code could use it instead of hardcoding version numbers. Thx Matt for pointing out the hardcoding. refs #16777 diff --git src/hg/hgVai/hgVai.c src/hg/hgVai/hgVai.c index 2b02dea..7b70949 100644 --- src/hg/hgVai/hgVai.c +++ src/hg/hgVai/hgVai.c @@ -425,34 +425,30 @@ slAddHead(&groupRefList, slRefNew(grp)); } hashFree(&hash); slReverse(&groupRefList); *retGroupRefList = groupRefList; } } boolean isVariantCustomTrack(struct trackDb *tdb, void *filterData) /* This is a TdbFilterFunction to get custom or hub tracks with type pgSnp or vcf(Tabix). */ { return ((sameString(tdb->grp, "user") || isHubTrack(tdb->track)) && (sameString(tdb->type, "pgSnp") || startsWith("vcf", tdb->type))); } -// Function prototype to avoid shuffling code around: -char *findLatestSnpTable(char *suffix); -/* Return the name of the 'snp1__' table with the highest build number, if any. */ - void selectVariants() /* Offer selection of user's variant custom tracks, example variants, pasted input etc. */ { #define PGSNP_OR_VCF "pgSnp or " \ "VCF" printf("
Select Variants
\n"); /* Check for variant custom tracks. If there are none, tell the user that they should add one. */ struct slRef *varTrackList = NULL, *varGroupList = NULL; tdbFilterGroupTrack(fullTrackList, fullGroupList, isVariantCustomTrack, NULL, &varGroupList, &varTrackList); if (varTrackList == NULL) { printf("Your session doesn't have any custom tracks or hub tracks in " PGSNP_OR_VCF " format.\n"); @@ -469,31 +465,31 @@ { printf("If you have more than one custom track or hub track in " PGSNP_OR_VCF " format, please select the one you wish to annotate:
\n"); } printf("variants: "); printf("
\n"); if (hasSnps) { printf("
\n", differentString(selected, hgvaUseVariantIds) ? " style='display: none;'" : ""); printf("Enter dbSNP rs# identifiers separated by whitespace or commas:
\n"); char *oldPasted = cartUsualString(cart, hgvaVariantIds, ""); cgiMakeTextArea(hgvaVariantIds, oldPasted, 10, 70); puts("
"); } printf("maximum number of variants to be processed:\n"); @@ -688,61 +684,35 @@ for (table = dbNsfpTables; table != NULL; table = table->next) { if (sameString(table->name, "dbNsfpPolyPhen2")) { printDbNsfpSource(table->name, HDIV); printDbNsfpSource(table->name, HVAR); } else printDbNsfpSource(table->name, 0); } jsEndContainer(); puts("
"); endCollapsibleSection(); } -char *findLatestSnpTable(char *suffix) -/* Return the name of the 'snp1__' table with the highest build number, if any. */ -{ -if (startsWith(hubTrackPrefix, database)) - return NULL; -if (suffix == NULL) - suffix = ""; -char likeExpr[64]; -safef(likeExpr, sizeof(likeExpr), "LIKE 'snp1__%s'", suffix); -struct sqlConnection *conn = hAllocConn(database); -struct slName *snpNNNTables = sqlListTablesLike(conn, likeExpr); - -hFreeConn(&conn); -if ((snpNNNTables == NULL) || (slCount(snpNNNTables)==0)) - return NULL; -// Skip to last in list -- highest number (show tables can't use rlike or 'order by'): -struct slName *table = snpNNNTables; -while (table->next != NULL && isdigit(table->next->name[4]) && isdigit(table->next->name[5])) - table = table->next; -char *tableName = NULL; -if (table != NULL) - tableName = cloneString(table->name); -slNameFreeList(&snpNNNTables); -return tableName; -} - boolean findSnpBed4(char *suffix, char **retFileName, struct trackDb **retTdb) /* If we can find the latest snpNNNsuffix table, or better yet a bigBed file for it (faster), * set the appropriate ret* and return TRUE, otherwise return FALSE. */ { -char *table = findLatestSnpTable(suffix); +char *table = hFindLatestSnpTable(database, suffix); if (table == NULL) return FALSE; boolean foundIt = FALSE; // Do we happen to have a bigBed version? Better yet, bed4 only for current uses: char origFileName[HDB_MAX_PATH_STRING]; safef(origFileName, sizeof(origFileName), "/gbdb/%s/vai/%s.bed4.bb", database, table); char* fileName = hReplaceGbdb(origFileName); if (fileExists(fileName)) { if (retFileName != NULL) *retFileName = fileName; foundIt = TRUE; } else { @@ -2139,31 +2109,31 @@ dyStringPrintf(dy, "'%s'", el->name); } return dyStringCannibalize(&dy); } //#*** Variant ID-matching should be metadata-driven too. termRegex -> data source. static const char *rsIdRegex = "^rs[0-9]+$"; static void rsIdsToVcfRecords(struct annoAssembly *assembly, struct slName *rsIds, struct vcfFile *vcff, struct vcfRecord **pRecList, struct slName **pCommentList) /* If possible, look up coordinates and alleles of dbSNP rs IDs. */ { if (rsIds == NULL) return; -char *table = findLatestSnpTable(NULL); +char *table = hFindLatestSnpTable(database, NULL); if (table == NULL) return; struct sqlConnection *conn = hAllocConn(assembly->name); // Build a 'name in (...)' query, and build a hash of IDs so we can test whether all were found struct dyString *dq = sqlDyStringCreate("select chrom, chromStart, chromEnd, name, strand, " "refUCSC, observed from %s where name in (", table); struct hash *idHash = hashNew(0); struct slName *id; for (id = rsIds; id != NULL; id = id->next) { tolowers(id->name); dyStringPrintf(dq, "%s'%s'", (id != rsIds ? "," : ""), id->name); hashStoreName(idHash, id->name); }