5e88a1196c6be3d47f925d8d31e401ef0a65c1fc
braney
Fri Nov 10 14:40:51 2017 -0800
add support for bigNarrowPeak in hubs and custom tracks
diff --git src/hg/hgc/encodeClick.c src/hg/hgc/encodeClick.c
index 405e530..ba8dbfa 100644
--- src/hg/hgc/encodeClick.c
+++ src/hg/hgc/encodeClick.c
@@ -39,75 +39,42 @@
}
return TRUE;
}
static void rAddMatching(struct trackDb *tdb, struct slPair *selGroupList, struct slName **pList)
/* Add track and any descendents that match selGroupList to pList */
{
if (selGroupListMatch(tdb, selGroupList))
slNameAddHead(pList, tdb->track);
struct trackDb *sub;
for (sub = tdb->subtracks; sub != NULL; sub = sub->next)
rAddMatching(sub, selGroupList, pList);
}
#endif//def UNUSED
-void doEncodePeak(struct trackDb *tdb, struct customTrack *ct, char *item)
-/* details for encodePeak type tracks. */
-{
-struct sqlConnection *conn;
-struct sqlResult *sr;
-enum encodePeakType peakType;
-char **row;
-char *db;
-char *table = tdb->table;
-char *chrom = cartString(cart,"c");
-int start = cgiInt("o");
-int end = cgiInt("t");
-int rowOffset;
-boolean firstTime = TRUE;
-/* connect to DB */
-if (ct)
- {
- db = CUSTOM_TRASH;
- table = ct->dbTableName;
- }
-else
- db = database;
-conn = hAllocConn(db);
-peakType = encodePeakInferTypeFromTable(db, table, tdb->type);
-if (peakType == 0)
- errAbort("unrecognized peak type from table %s", tdb->table);
-genericHeader(tdb, NULL); // genericClickHandlerPlus gets there first anyway (maybe except for encodePeak custom tracks).
-sr = hOrderedRangeQuery(conn, table, chrom, start, end,
- NULL, &rowOffset);
-while((row = sqlNextRow(sr)) != NULL)
+static void printPeak(char **row, int rowOffset, char *item, char *chrom, int start, int end, enum encodePeakType peakType)
{
char **rowPastOffset = row + rowOffset;
if ((sqlUnsigned(rowPastOffset[1]) != start) || (sqlUnsigned(rowPastOffset[2]) != end))
- continue;
+ return;
if (!sameString(rowPastOffset[3], item))
- continue;
+ return;
float signal = -1;
float pValue = -1;
float qValue = -1;
- if (firstTime)
- firstTime = FALSE;
- else // print separator
- printf("
\n");
/* Name */
if (rowPastOffset[3][0] != '.')
printf("Name: %s
\n", rowPastOffset[3]);
/* Position */
printf("Position: "
"%s:%d-%d
\n",
hgTracksPathAndSettings(), database, chrom, start+1, end, chrom, start+1, end);
/* Print peak base */
if ((peakType == narrowPeak) || (peakType == encodePeak))
{
int peak = sqlSigned(rowPastOffset[9]);
if (peak > -1)
printf("Peak point: %d
\n", start + peak + 1); // one based
}
@@ -123,30 +90,99 @@
qValue = sqlFloat(rowPastOffset[8]);
}
else
{
signal = sqlFloat(rowPastOffset[12]);
pValue = sqlFloat(rowPastOffset[13]);
qValue = sqlFloat(rowPastOffset[14]);
}
if (signal >= 0)
printf("Signal value: %.3f
\n", signal);
if (pValue >= 0)
printf("P-value (-log10): %.3f
\n", pValue);
if (qValue >= 0)
printf("Q-value (FDR): %.3f
\n", qValue);
}
+
+void doBigEncodePeak(struct trackDb *tdb, struct customTrack *ct, char *item)
+/* details for encodePeak type tracks. */
+{
+enum encodePeakType peakType = narrowPeak;
+char *chrom = cartString(cart,"c");
+int start = cgiInt("o");
+int end = cgiInt("t");
+boolean firstTime = TRUE;
+//peakType = encodePeakInferTypeFromTable(db, table, tdb->type);
+if (peakType == 0)
+ errAbort("unrecognized peak type from table %s", tdb->table);
+genericHeader(tdb, NULL); // genericClickHandlerPlus gets there first anyway (maybe except for encodePeak custom tracks).
+char *fileName = bbiNameFromSettingOrTable(tdb, NULL, tdb->table);
+struct bbiFile *bbi = bigBedFileOpen(fileName);
+struct lm *lm = lmInit(0);
+struct bigBedInterval *bb, *bbList = bigBedIntervalQuery(bbi, chrom, start, end, 0, lm);
+int fieldCount = 10;
+char *bedRow[fieldCount];
+char startBuf[16], endBuf[16];
+
+for (bb = bbList; bb != NULL; bb = bb->next)
+ {
+ bigBedIntervalToRow(bb, chrom, startBuf, endBuf, bedRow, ArraySize(bedRow));
+ if (firstTime)
+ firstTime = FALSE;
+ else // print separator
+ printf("
\n");
+ printPeak(bedRow, 0, item, chrom, start, end, peakType);
+ }
+}
+
+void doEncodePeak(struct trackDb *tdb, struct customTrack *ct, char *item)
+/* details for encodePeak type tracks. */
+{
+struct sqlConnection *conn;
+struct sqlResult *sr;
+enum encodePeakType peakType;
+char **row;
+char *db;
+char *table = tdb->table;
+char *chrom = cartString(cart,"c");
+int start = cgiInt("o");
+int end = cgiInt("t");
+int rowOffset;
+boolean firstTime = TRUE;
+/* connect to DB */
+if (ct)
+ {
+ db = CUSTOM_TRASH;
+ table = ct->dbTableName;
+ }
+else
+ db = database;
+conn = hAllocConn(db);
+peakType = encodePeakInferTypeFromTable(db, table, tdb->type);
+if (peakType == 0)
+ errAbort("unrecognized peak type from table %s", tdb->table);
+genericHeader(tdb, NULL); // genericClickHandlerPlus gets there first anyway (maybe except for encodePeak custom tracks).
+sr = hOrderedRangeQuery(conn, table, chrom, start, end,
+ NULL, &rowOffset);
+while((row = sqlNextRow(sr)) != NULL)
+ {
+ if (firstTime)
+ firstTime = FALSE;
+ else // print separator
+ printf("
\n");
+ printPeak(row, rowOffset, item, chrom, start, end, peakType);
+ }
sqlFreeResult(&sr);
hFreeConn(&conn);
}
int encodeFiveCInterCmp(const void *va, const void *vb)
/* reverse sort on bed nine's reserved field which in this */
/* case is the where the strength of the interaction is stored */
{
const struct bed *a = *((struct bed **)va);
const struct bed *b = *((struct bed **)vb);
return b->itemRgb - a->itemRgb;
}
void doEncodeFiveC(struct sqlConnection *conn, struct trackDb *tdb)
/* Print details for 5C track */