060ada2535fca719656219c1214a3e1c16490693 tdreszer Wed Nov 9 16:06:41 2011 -0800 Moved as code in hgTables down to lib and access it from hgc and hgTrackUi. This is to remove 'extraFields' support as per Jim's request in redmine 5883 and 5582 diff --git src/hg/hgc/hgc.c src/hg/hgc/hgc.c index e08362e..0f7797f 100644 --- src/hg/hgc/hgc.c +++ src/hg/hgc/hgc.c @@ -1382,74 +1382,121 @@ char dbOnly[4096]; diff = comp2->start - (comp1->start + comp1->size); safef(dbOnly, sizeof(dbOnly), "%s", comp1->src); chopPrefix(dbOnly); printf("%-20s %d\n",hOrganism(dbOnly), diff); } printf("
"); } } } } -int extraFieldsPrint(struct trackDb *tdb,struct sqlResult *sr,char **row) -// Any extra fields defined in trackDb. Retruns number of extra fields actually printed +int extraFieldsPrint(struct trackDb *tdb,struct sqlResult *sr,char **fields,int fieldCount) +// Any extra bed or bigBed fields (defined in as and occurring after N in bed N + types. +// sr may be null for bigBeds. +// Returns number of extra fields actually printed. { -// Additional fields requested in trackDb? -struct extraField *extras = extraFieldsGet(tdb); +#ifdef EXTRA_FIELDS_SUPPORT +struct extraField *extras = extraFieldsGet(database, tdb); if (extras == NULL) return 0; +#else///ifndef EXTRA_FIELDS_SUPPORT +struct sqlConnection *conn = hAllocConnTrack(database, tdb); +struct asObject *as = asForTdb(conn, tdb); +hFreeConn(&conn); +if (as == NULL) + return 0; +#endif///ndef EXTRA_FIELDS_SUPPORT +// We are trying to print extra fields so we need to figure out how many fields to skip +int start = 0; +char *type = cloneString(tdb->type); +char *word = nextWord(&type); +if (word && (sameWord(word,"bed") || sameWord(word,"bigBed"))) + { + if (NULL != (word = nextWord(&type))) + start = sqlUnsigned(word); + #ifdef EXTRA_FIELDS_SUPPORT + // extraFields do not have to define all fields + if (fieldCount > slCount(extras)) + start = 0; + #endif///def EXTRA_FIELDS_SUPPORT + } int count = 0; -struct extraField *extra = extras; -for(;extra != NULL;extra=extra->next) +#ifdef EXTRA_FIELDS_SUPPORT +struct extraField *col = extras; +#else///ifndef EXTRA_FIELDS_SUPPORT +struct asColumn *col = as->columnList; +#endif///ndef EXTRA_FIELDS_SUPPORT +for(;col != NULL && count < fieldCount;col=col->next) { - int ix = sqlFieldColumn(sr, extra->name); // Name must match sql columnn name! - if (ix == -1) // so extraField really just provides a label + if (start > 0) // skip past already known fields { - char *setting = trackDbSetting(tdb, "extraFields"); // showFileds pValue=P_Value qValue=qValue - warn("trackDb setting [extraFields %s] could not find %s in %s.\n", setting, extra->name,tdb->table); + start--; + continue; } - else + int ix = count; + if (sr != NULL) { + ix = sqlFieldColumn(sr, col->name); // If sr provided, name must match sql columnn name! + if (ix == -1 || ix > fieldCount) // so extraField really just provides a label + continue; + } + // Print as table rows if(count == 0) printf("
"); count++; - printf("", extra->label); - switch (extra->type) + #ifdef EXTRA_FIELDS_SUPPORT + printf("", col->label); + if (col->type == ftInteger) { - case ftInteger: { - long long valInt = sqlLongLong(row[ix]); + long long valInt = sqlLongLong(fields[ix]); printf("\n", valInt); } - break; - case ftFloat: { - double valDouble = sqlDouble(row[ix]); + else if (col->type == ftFloat) + { + double valDouble = sqlDouble(fields[ix]); printf("\n", valDouble); } - break; - default: - printf("\n", row[ix]); - break; + #else///ifndef EXTRA_FIELDS_SUPPORT + printf("", col->comment); + if (asTypesIsInt(col->lowType->type)) + { + long long valInt = sqlLongLong(fields[ix]); + printf("\n", valInt); + } + else if (asTypesIsFloating(col->lowType->type)) + { + double valDouble = sqlDouble(fields[ix]); + printf("\n", valDouble); } + #endif///ndef EXTRA_FIELDS_SUPPORT + else + { + printf("\n", fields[ix]); } } +#ifdef EXTRA_FIELDS_SUPPORT extraFieldsFree(&extras); +#else///ifndef EXTRA_FIELDS_SUPPORT +asObjectFree(&as); +#endif///ndef EXTRA_FIELDS_SUPPORT if(count > 0) printf("
%s:
%s:%lld
%g
%s
%s:%lld
%g
%s
\n"); return count; } void genericBedClick(struct sqlConnection *conn, struct trackDb *tdb, char *item, int start, int bedSize) /* Handle click in generic BED track. */ { char table[64]; boolean hasBin; struct bed *bed; char query[512]; struct sqlResult *sr; @@ -1473,31 +1520,31 @@ sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { if (firstTime) firstTime = FALSE; else htmlHorizontalLine(); bed = bedLoadN(row+hasBin, bedSize); if ((tdb->type != NULL) && sameString(tdb->type, "interaction")) { interactionPrintPos( bed, bedSize, tdb); } else bedPrintPos(bed, bedSize, tdb); - extraFieldsPrint(tdb,sr,row); + extraFieldsPrint(tdb,sr,row,sqlCountColumns(sr)); // check for seq1 and seq2 in columns 7+8 (eg, pairedTagAlign) char *setting = trackDbSetting(tdb, BASE_COLOR_USE_SEQUENCE); if (bedSize == 6 && setting && sameString(setting, "seq1Seq2")) printf("
Sequence 1: %s
Sequence 2: %s
\n",row[hasBin+6], row[hasBin+7]); printCompareGenomeLinks(tdb,bed->name); } sqlFreeResult(&sr); getBedTopScorers(conn, tdb, table, item, start, bedSize); } #define INTRON 10 #define CODINGA 11 #define CODINGB 12 #define UTR5 13 #define UTR3 14