549dcd456f5d557e15426176e487f91246363548
kate
Mon Apr 10 17:21:22 2017 -0700
Better integration with bigBed cod. Fixes loading problem and allows labelFields code to operate (not yet tested). refs #18736
diff --git src/hg/hgc/barChartClick.c src/hg/hgc/barChartClick.c
index c298bfe..62c46fa 100644
--- src/hg/hgc/barChartClick.c
+++ src/hg/hgc/barChartClick.c
@@ -7,81 +7,81 @@
#include "hash.h"
#include "hdb.h"
#include "hvGfx.h"
#include "trashDir.h"
#include "hgc.h"
#include "hCommon.h"
#include "barChartBed.h"
#include "barChartCategory.h"
#include "barChartData.h"
#include "barChartSample.h"
#include "barChartUi.h"
// TODO: Consider moving these to lib/{barChartBed,bigBarChart}.c
-static struct barChartBed *getBarChartFromFile(char *item, char *chrom, int start, int end,
+static struct bed *getBarChartFromFile(char *item, char *chrom, int start, int end,
char *file)
/* Retrieve barChart BED item from big file */
{
struct bbiFile *bbi = bigBedFileOpen(file);
struct lm *lm = lmInit(0);
struct bigBedInterval *bb, *bbList = bigBedIntervalQuery(bbi, chrom, start, end, 0, lm);
for (bb = bbList; bb != NULL; bb = bb->next)
{
char startBuf[16], endBuf[16];
char *bedRow[32];
bigBedIntervalToRow(bb, chrom, startBuf, endBuf, bedRow, ArraySize(bedRow));
- struct barChartBed *barChart = barChartBedLoad(bedRow);
+ struct bed *barChart = barChartSimpleBedLoad(bedRow);
if (sameString(barChart->name, item))
return barChart;
}
return NULL;
}
-static struct barChartBed *getBarChartFromTable(char *item, char *chrom, int start, int end,
+static struct bed *getBarChartFromTable(char *item, char *chrom, int start, int end,
char *table)
/* Retrieve barChart BED item from track table */
{
-struct barChartBed *barChart = NULL;
+struct bed *barChart = NULL;
struct sqlConnection *conn = hAllocConn(database);
char **row;
char query[512];
struct sqlResult *sr;
if (sqlTableExists(conn, table))
{
sqlSafef(query, sizeof query,
"SELECT * FROM %s WHERE name='%s'"
"AND chrom='%s' AND chromStart=%d AND chromEnd=%d",
table, item, chrom, start, end);
sr = sqlGetResult(conn, query);
row = sqlNextRow(sr);
if (row != NULL)
{
- barChart = barChartBedLoad(row);
+ barChart = barChartSimpleBedLoad(row);
}
sqlFreeResult(&sr);
}
hFreeConn(&conn);
return barChart;
}
-static struct barChartBed *getBarChart(char *item, char *chrom, int start, int end,
+static struct bed *getBarChart(char *item, char *chrom, int start, int end,
struct trackDb *tdb)
/* Retrieve barChart BED item from track */
{
-struct barChartBed *barChart = NULL;
+struct bed *barChart = NULL;
char *file = trackDbSetting(tdb, "bigDataUrl");
if (file != NULL)
barChart = getBarChartFromFile(item, chrom, start, end, file);
else
barChart = getBarChartFromTable(item, chrom, start, end, tdb->table);
return barChart;
}
static struct barChartData *getSampleVals(char *track, char *item)
/* Get data values for this item (locus) from all samples */
{
char table[256];
safef(table, sizeof(table), "%s%s", track, "Data");
struct sqlConnection *conn = hAllocConn(database);
if (!sqlTableExists(conn, table))
@@ -172,42 +172,41 @@
/* Plot data frame to image file and include in HTML */
{
struct tempName pngTn;
trashDirFile(&pngTn, "hgc", "barChart", ".png");
/* Exec R in quiet mode, without reading/saving environment or workspace */
char cmd[256];
safef(cmd, sizeof(cmd), "Rscript --vanilla --slave hgcData/barChartBoxplot.R %s %s %s %s %s",
item, units, colorFile, df, pngTn.forHtml);
int ret = system(cmd);
if (ret == 0)
printf("
\n", pngTn.forHtml);
}
void doBarChartDetails(struct trackDb *tdb, char *item)
-
/* Details of barChart item */
{
int start = cartInt(cart, "o");
int end = cartInt(cart, "t");
-struct barChartBed *chartItem = getBarChart(item, seqName, start, end, tdb);
+struct bed *chartItem = getBarChart(item, seqName, start, end, tdb);
if (chartItem == NULL)
errAbort("Can't find item %s in barChart table %s\n", item, tdb->table);
genericHeader(tdb, item);
int categId;
-float highLevel = barChartHighestValue(chartItem, &categId);
+float highLevel = barChartMaxValue(chartItem, &categId);
char *units = trackDbSettingClosestToHomeOrDefault(tdb, BAR_CHART_UNIT, "");
printf("Maximum value: %0.2f %s in %s
\n",
highLevel, units, barChartUiGetCategoryLabelById(categId, database, tdb));
printf("Total all values: %0.2f
\n", barChartTotalValue(chartItem));
printf("Score: %d
\n", chartItem->score);
printf("Genomic position: "
"%s %s:%d-%d
\n",
database, hgTracksPathAndSettings(), database,
chartItem->chrom, chartItem->chromStart+1, chartItem->chromEnd,
chartItem->chrom, chartItem->chromStart+1, chartItem->chromEnd);
struct barChartData *vals = getSampleVals(tdb->table, item);
if (vals != NULL)
{
// Print boxplot
puts("
");