85eb22caf9e2cd6ecdd0c422993b34029975a7c8
markd
  Tue Aug 14 17:57:02 2012 -0700
fixed crash accessing 2way consensus pseudogenes because they don't have the extended genePred field
diff --git src/hg/hgTracks/gencodeTracks.c src/hg/hgTracks/gencodeTracks.c
index aa14cb4..e748177 100644
--- src/hg/hgTracks/gencodeTracks.c
+++ src/hg/hgTracks/gencodeTracks.c
@@ -3,30 +3,31 @@
 #include "common.h"
 #include "hgTracks.h"
 #include "hdb.h"
 #include "gencodeIntron.h"
 #include "genePredReader.h"
 #include "genePred.h"
 
 struct gencodeQuery
 /* structure used to store information about the query being assembled.
  * this allows a join to bring in additional data without having to
  * do repeated queries. */
 {
     struct dyString *fields;                // select fields
     struct dyString *from;                  // from clause
     struct dyString *where;                 // where clause
+    boolean isGenePredX;                    // does this have the extended fields?
     int nextFieldCol;                       // next available column in result row
     int supportLevelCol;                    // support level column if joined for highlighting, or -1 
     int transcriptTypeCol;                  // transcript type column if joined for highlighting, or -1 
     filterBy_t *supportLevelHighlight;      // choices for support level highlighting if not NULL
     filterBy_t *transcriptTypeHighlight;    // choices for transcript type highlighting if not NULL
     boolean joinAttrs;                      // join the wgEncodeGencodeAttrs table
     boolean joinTransSrc;                   // join the wgEncodeGencodeTranscriptSource table
     boolean joinSupportLevel;               // join the wgEncodeGencodeTranscriptionSupportLevel table
 };
 
 static struct gencodeQuery *gencodeQueryNew(void)
 /* construct a new gencodeQuery object */
 {
 struct gencodeQuery *gencodeQuery;
 AllocVar(gencodeQuery);
@@ -295,63 +296,77 @@
     dyStringPrintf(gencodeQuery->from, ", %s attrs", trackDbRequiredSetting(tg->tdb, "wgEncodeGencodeAttrs"));
     dyStringAppend(gencodeQuery->where, " and (attrs.transcriptId = g.name)");
     }
 if (gencodeQuery->joinTransSrc)
     {
     dyStringPrintf(gencodeQuery->from, ", %s transSrc", trackDbRequiredSetting(tg->tdb, "wgEncodeGencodeTranscriptSource"));
     dyStringAppend(gencodeQuery->where, " and (transSrc.transcriptId = g.name)");
     }
 if (gencodeQuery->joinSupportLevel)
     {
     dyStringPrintf(gencodeQuery->from, ", %s supLevel", trackDbRequiredSetting(tg->tdb, "wgEncodeGencodeTranscriptionSupportLevel"));
     dyStringAppend(gencodeQuery->where, " and (supLevel.transcriptId = g.name)");
     }
 }
 
+static boolean tableIsGenePredX(struct track *tg)
+/* determine if a table has genePred extended fields.  two-way consensus
+ * pseudo doesn't have them. */
+{
+struct sqlConnection *conn = hAllocConn(database);
+struct slName *fields = sqlFieldNames(conn, tg->table);
+hFreeConn(&conn);
+boolean isGenePredX = slNameInList(fields, "score");
+slFreeList(&fields);
+return isGenePredX;
+}
+
 static struct gencodeQuery *gencodeQueryConstruct(struct track *tg)
 /* construct the query for a GENCODE genePred track, which includes filters. */
 {
-static char *genePredFields = "g.name, g.chrom, g.strand, g.txStart, g.txEnd, g.cdsStart, g.cdsEnd, g.exonCount, g.exonStarts, g.exonEnds, g.score, g.name2, g.cdsStartStat, g.cdsEndStat, g.exonFrames";
-struct gencodeQuery *gencodeQuery = gencodeQueryNew();
+static char *genePredXFields = "g.name, g.chrom, g.strand, g.txStart, g.txEnd, g.cdsStart, g.cdsEnd, g.exonCount, g.exonStarts, g.exonEnds, g.score, g.name2, g.cdsStartStat, g.cdsEndStat, g.exonFrames";
+static char *genePredFields = "g.name, g.chrom, g.strand, g.txStart, g.txEnd, g.cdsStart, g.cdsEnd, g.exonCount, g.exonStarts, g.exonEnds";
 
-dyStringAppend(gencodeQuery->fields, genePredFields);
+struct gencodeQuery *gencodeQuery = gencodeQueryNew();
+gencodeQuery->isGenePredX = tableIsGenePredX(tg);
+gencodeQuery->nextFieldCol = (gencodeQuery->isGenePredX ? GENEPREDX_NUM_COLS : GENEPRED_NUM_COLS);
+dyStringAppend(gencodeQuery->fields, (gencodeQuery->isGenePredX ? genePredXFields : genePredFields));
 
 // bin range overlap part
 hAddBinToQuery(winStart, winEnd, gencodeQuery->where);
 dyStringPrintf(gencodeQuery->where, "(g.chrom = \"%s\") and (g.txStart < %u) and (g.txEnd > %u)", chromName, winEnd, winStart);
-gencodeQuery->nextFieldCol = GENEPREDX_NUM_COLS;
 
 gencodeFilterBySetQuery(tg, gencodeQuery);
 gencodeHighlightBySetQuery(tg, gencodeQuery);
 addQueryTables(tg, gencodeQuery);
 return gencodeQuery;
 }
 
 static struct sqlResult *gencodeMakeQuery(struct sqlConnection *conn, struct gencodeQuery *gencodeQuery)
 /* make the actual SQL query */
 {
 struct dyString *query = dyStringNew(0);
 dyStringPrintf(query, "select %s from %s where %s", dyStringContents(gencodeQuery->fields), dyStringContents(gencodeQuery->from), dyStringContents(gencodeQuery->where));
 struct sqlResult *sr = sqlGetResult(conn, dyStringContents(query));
 dyStringFree(&query);
 return sr;
 }
 
 static struct linkedFeatures *loadGencodeGenePred(struct track *tg, struct gencodeQuery *gencodeQuery, char **row, unsigned highlightColor)
 /* load one genePred record into a linkedFeatures object */
 {
-struct genePred *gp = genePredExtLoad(row, GENEPREDX_NUM_COLS);
+struct genePred *gp = genePredExtLoad(row, (gencodeQuery->isGenePredX ? GENEPREDX_NUM_COLS:  GENEPRED_NUM_COLS));
 struct linkedFeatures *lf = linkedFeaturesFromGenePred(tg, gp, TRUE);
 highlightByGetColor(row, gencodeQuery, highlightColor, lf);
 return lf;
 }
 
 static void loadGencodeGenePreds(struct track *tg)
 /* Load genePreds in window info linked feature, with filtering, etc. */
 {
 struct gencodeQuery *gencodeQuery = gencodeQueryConstruct(tg);
 struct sqlConnection *conn = hAllocConn(database);
 struct sqlResult *sr = gencodeMakeQuery(conn, gencodeQuery);
 struct linkedFeatures *lfList = NULL;
 unsigned highlightColor = getHighlightColor(tg);
 char **row;
 while ((row = sqlNextRow(sr)) != NULL)