54406b80d5d435970989acff7b22dd6146c6b411 braney Sat Jan 22 15:24:59 2022 -0800 adding chrom alias support to big files diff --git src/hg/hgTables/bigWig.c src/hg/hgTables/bigWig.c index 7b6f9de..5b1f160 100644 --- src/hg/hgTables/bigWig.c +++ src/hg/hgTables/bigWig.c @@ -12,30 +12,31 @@ #include "cheapcgi.h" #include "cart.h" #include "web.h" #include "bed.h" #include "hdb.h" #include "trackDb.h" #include "customTrack.h" #include "wiggle.h" #include "hmmstats.h" #include "correlate.h" #include "bbiFile.h" #include "bigWig.h" #include "hubConnect.h" #include "hgTables.h" #include "mathWig.h" +#include "chromAlias.h" boolean isBigWig(char *database, char *table, struct trackDb *parent, struct customTrack *(*ctLookupName)(char *table)) /* Local test to see if something is big wig. Handles hub tracks unlike hIsBigWig. */ { struct trackDb *tdb = hashFindVal(fullTableToTdbHash, table); if (tdb) return tdbIsBigWig(tdb); else return hIsBigWig(database, table, parent, ctLookupName); } boolean isBigWigTable(char *table) /* Return TRUE if table corresponds to a bigWig file. */ { @@ -231,31 +232,31 @@ resultCount = wigPrintDataVectorOut(dv, wigOutType, maxOut, NULL); dataVectorFree(&dv); return resultCount; } int bigWigOutRegion(char *table, struct sqlConnection *conn, struct region *region, int maxOut, enum wigOutputType wigOutType) /* Write out bigWig for region, doing intersecting and filtering as need be. */ { boolean isMerged = anySubtrackMerge(table, database); int resultCount = 0; char *wigFileName = bigWigFileName(table, conn); if (wigFileName) { - struct bbiFile *bwf = bigWigFileOpen(wigFileName); + struct bbiFile *bwf = bigWigFileOpenAlias(wigFileName, chromAliasGetHash(database)); if (bwf) { /* Easy case, just dump out data. */ if (!anyFilter() && !anyIntersection() && !isMerged && wigOutType == wigOutData) resultCount = bigWigIntervalDump(bwf, region->chrom, region->start, region->end, maxOut, stdout); /* Pretty easy case, still do it ourselves. */ else if (!isMerged && wigOutType == wigOutData) { double ll, ul; enum wigCompare cmp; getWigFilter(database, curTable, &cmp, &ll, &ul); struct lm *lm = lmInit(0); struct bbiInterval *ivList, *iv; ivList = intersectedFilteredBbiIntervalsOnRegion(conn, bwf, region, cmp, ll, ul, lm); @@ -283,31 +284,31 @@ /* Put up page showing summary stats for bigWig track. */ { struct trackDb *track = curTrack; char *table = curTable; char *shortLabel = (track == NULL ? table : track->shortLabel); char *fileName = bigWigFileName(table, conn); long startTime = clock1000(); htmlOpen("%s (%s) Big Wig Summary Statistics", shortLabel, table); if (anySubtrackMerge(database, curTable)) hPrintf("
Note: subtrack merge is currently ignored on this "
"page (not implemented yet). Statistics shown here are only for "
"the primary table %s (%s).", shortLabel, table);
-struct bbiFile *bwf = bigWigFileOpen(fileName);
+struct bbiFile *bwf = bigWigFileOpenAlias(fileName, chromAliasGetHash(database));
struct region *region, *regionList = getRegions();
double sumData = 0, sumSquares = 0, minVal = 0, maxVal = 0;
bits64 validCount = 0;
if (!anyFilter() && !anyIntersection())
{
for (region = regionList; region != NULL; region = region->next)
{
struct bbiSummaryElement sum;
if (bbiSummaryArrayExtended(bwf, region->chrom, region->start, region->end,
bigWigIntervalQuery, 1, &sum))
{
if (validCount == 0)
{
minVal = sum.minVal;
@@ -372,58 +373,58 @@
long wigFetchTime = clock1000() - startTime;
floatStatRow("load and calc time", 0.001*wigFetchTime);
hTableEnd();
bbiFileClose(&bwf);
htmlClose();
}
struct bed *bigWigIntervalsToBed(struct sqlConnection *conn, char *table, struct region *region,
struct lm *lm)
/* Return a list of unfiltered, unintersected intervals in region as bed (for
* secondary table in intersection). */
{
struct bed *bed, *bedList = NULL;
char *fileName = bigWigFileName(table, conn);
-struct bbiFile *bwf = bigWigFileOpen(fileName);
+struct bbiFile *bwf = bigWigFileOpenAlias(fileName, chromAliasGetHash(database));
struct bbiInterval *iv, *ivList = bigWigIntervalQuery(bwf, region->chrom, region->start,
region->end, lm);
for (iv = ivList; iv != NULL; iv = iv->next)
{
lmAllocVar(lm, bed);
bed->chrom = region->chrom;
bed->chromStart = iv->start;
bed->chromEnd = iv->end;
slAddHead(&bedList, bed);
}
slReverse(&bedList);
return bedList;
}
void bigWigFillDataVector(char *table, struct region *region,
struct sqlConnection *conn, struct dataVector *vector)
/* Fill in data vector with bigWig info on region. Handles filters and intersections. */
{
/* Figure out filter values if any. */
double ll, ul;
enum wigCompare cmp;
getWigFilter(database, curTable, &cmp, &ll, &ul);
/* Get intervals that pass filter and intersection. */
struct lm *lm = lmInit(0);
char *fileName = bigWigFileName(table, conn);
-struct bbiFile *bwf = bigWigFileOpen(fileName);
+struct bbiFile *bwf = bigWigFileOpenAlias(fileName, chromAliasGetHash(database));
struct bbiInterval *iv, *ivList;
ivList = intersectedFilteredBbiIntervalsOnRegion(conn, bwf, region, cmp, ll, ul, lm);
int vIndex = 0;
for (iv = ivList; iv != NULL; iv = iv->next)
{
int start = max(iv->start, region->start);
int end = min(iv->end, region->end);
double val = iv->val;
int i;
for (i=start; i