de438b6041d00b72be32bcdec70436a9d201baf2 braney Sat May 21 12:17:40 2016 -0700 libify the guts of ave so I can use it in hgc diff --git src/hg/hgc/hgc.c src/hg/hgc/hgc.c index a96ecbb..7d3c019 100644 --- src/hg/hgc/hgc.c +++ src/hg/hgc/hgc.c @@ -241,30 +241,31 @@ #include "jsHelper.h" #include "virusClick.h" #include "gwasCatalog.h" #include "parClick.h" #include "mdb.h" #include "yaleGencodeAssoc.h" #include "itemDetailsHtml.h" #include "trackVersion.h" #include "numtsClick.h" #include "geneReviewsClick.h" #include "bigBed.h" #include "bigPsl.h" #include "bedTabix.h" #include "longRange.h" #include "hmmstats.h" +#include "aveStats.h" static char *rootDir = "hgcData"; #define LINESIZE 70 /* size of lines in comp seq feature */ struct cart *cart; /* User's settings. */ char *seqName; /* Name of sequence we're working on. */ int winStart, winEnd; /* Bounds of sequence. */ char *database; /* Name of mySQL database. */ char *organism; /* Colloquial name of organism. */ char *genome; /* common name, e.g. Mouse, Human */ char *scientificName; /* Scientific name of organism. */ struct hash *trackHash; /* A hash of all tracks - trackDb valued */ @@ -3920,65 +3921,66 @@ } } static void doLongTabix(struct trackDb *tdb, char *item) { char *bigDataUrl = hashFindVal(tdb->settingsHash, "bigDataUrl"); struct bedTabixFile *btf = bedTabixFileMayOpen(bigDataUrl, NULL, 0, 0); char *chromName = cartString(cart, "c"); struct bed *list = bedTabixReadBeds(btf, chromName, winStart, winEnd, bedLoad5); bedTabixFileClose(btf); unsigned maxWidth; struct longRange *longRangeList = parseLongTabix(list, &maxWidth, 0); struct longRange *longRange, *ourLongRange = NULL; unsigned itemNum = sqlUnsigned(item); -double min = DBL_MAX, max = -DBL_MAX; -double total = 0, average; -unsigned count = 0; -double sumSquares = 0; +unsigned count = slCount(longRangeList); +double *doubleArray; -for(longRange = longRangeList; longRange; longRange = longRange->next) +AllocArray(doubleArray, count); + +int ii = 0; +for(longRange = longRangeList; longRange; longRange = longRange->next, ii++) { if (longRange->id == itemNum) { ourLongRange = longRange; } - if (longRange->score < min) - min = longRange->score; - if (longRange->score > max) - max = longRange->score; - total += longRange->score; - sumSquares += longRange->score * longRange->score; - - count++; + doubleArray[ii] = longRange->score; } -average = total/count; -double stdDev = calcStdFromSums(total, sumSquares, count); - if (ourLongRange == NULL) errAbort("cannot find long range item with id %d\n", itemNum); +struct aveStats *as = aveStatsCalc(doubleArray, count); + printf("Item you clicked on:
\n"); printf("Score: %g
\n", ourLongRange->score); printf("ID: %u
\n", ourLongRange->id); //printf("Link to other block
\n", otherChrom, s, e); printf("
All items in window:\n"); -printf("
Min: %g
Max: %g
Average: %g
Count: %d
Total: %g
StDev: %g\n", min,max,average,count, total, stdDev); +printf("
Q1 %f\n", as->q1); +printf("
median %f\n", as->median); +printf("
Q3 %f\n", as->q3); +printf("
average %f\n", as->average); +printf("
min %f\n", as->minVal); +printf("
max %f\n", as->maxVal); +printf("
count %d\n", as->count); +printf("
total %f\n", as->total); +printf("
standard deviation %f\n", as->stdDev); } void genericClickHandlerPlus( struct trackDb *tdb, char *item, char *itemForUrl, char *plus) /* Put up generic track info, with additional text appended after item. */ { char *dupe, *type, *words[16], *headerItem; int wordCount; int start = cartInt(cart, "o"); int end = cartInt(cart, "t"); struct sqlConnection *conn = NULL; char *imagePath = trackDbSetting(tdb, ITEM_IMAGE_PATH); char *container = trackDbSetting(tdb, "container"); if (!trackHubDatabase(database))