a93daa92b77f5717f8ff247cb049a46cd0f66409
markd
  Sun Aug 21 17:37:28 2022 -0700
add transcriptRank column to wgEncodeGencodeAttrs in preperation for getting transcript ranks in upcomming gencode distribution.  Import GENCODE V42 prerelease to test out creating column

diff --git src/hg/hgTracks/gencodeTracks.c src/hg/hgTracks/gencodeTracks.c
index 56cc100..6fd9684 100644
--- src/hg/hgTracks/gencodeTracks.c
+++ src/hg/hgTracks/gencodeTracks.c
@@ -328,80 +328,76 @@
 return sr;
 }
 
 static boolean annotIsGenePredExt(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 boolean attrsHasProteinId(struct track *tg)
-/* determine if the attributes table has the proteinId field.. */
-{
-struct sqlConnection *conn = hAllocConn(database);
-struct slName *fields = sqlFieldNames(conn, trackDbRequiredSetting(tg->tdb, "wgEncodeGencodeAttrs"));
-hFreeConn(&conn);
-boolean hasProteinId = slNameInList(fields, "proteinId");
-slFreeList(&fields);
-return hasProteinId;
-}
-
 static void geneQueryAddGenePredCols(struct track *tg,
                                      struct gencodeQuery *gencodeQuery)
 /* add genePred columns to query */
 {
 gencodeQuery->isGenePredX = annotIsGenePredExt(tg);
 sqlDyStringPrintf(gencodeQuery->fields, "g.name, g.chrom, g.strand, g.txStart, g.txEnd, g.cdsStart, g.cdsEnd, g.exonCount, g.exonStarts, g.exonEnds");
 gencodeQuery->genePredNumColumns = GENEPRED_NUM_COLS;
 
 if (gencodeQuery->isGenePredX)
     {
     sqlDyStringPrintf(gencodeQuery->fields, ", g.score, g.name2, g.cdsStartStat, g.cdsEndStat, g.exonFrames");
     gencodeQuery->genePredNumColumns = GENEPREDX_NUM_COLS;
     }
 }
 
-static void geneQueryAddAttrsCols(struct track *tg,
+static void geneQueryAddAttrsCols(struct track *tg, struct sqlConnection *conn,
                                   struct gencodeQuery *gencodeQuery)
 /* add attributes columns to query */
 {
+struct slName *fields = sqlFieldNames(conn, trackDbRequiredSetting(tg->tdb, "wgEncodeGencodeAttrs"));
 
 sqlDyStringPrintf(gencodeQuery->fields, ", ");
 sqlDyStringPrintf(gencodeQuery->fields, "attrs.geneId, attrs.geneName, attrs.geneType, attrs.geneStatus, attrs.transcriptId, attrs.transcriptName, attrs.transcriptType, attrs.transcriptStatus, attrs.havanaGeneId, attrs.havanaTranscriptId, attrs.ccdsId, attrs.level, attrs.transcriptClass");
-gencodeQuery->attrsNumColumns = WGENCODEGENCODEATTRS_NO_PROTEIN_ID_NUM_COLS;
-if (attrsHasProteinId(tg))
+gencodeQuery->attrsNumColumns = WGENCODEGENCODEATTRS_MIM_NUM_COLS;
+if (slNameInList(fields, "proteinId"))
     {
     sqlDyStringPrintf(gencodeQuery->fields, ", attrs.proteinId");
+    gencodeQuery->attrsNumColumns++;
+    }
+if (slNameInList(fields, "transcriptRank"))
+    {
+    sqlDyStringPrintf(gencodeQuery->fields, ", attrs.transcriptRank");
     gencodeQuery->attrsNumColumns = WGENCODEGENCODEATTRS_NUM_COLS;
     }
 gencodeQuery->joinAttrs = TRUE;
 }
 
 static struct gencodeQuery *geneQueryConstruct(struct track *tg,
+                                               struct sqlConnection *conn,
                                                boolean includeAttrs)
 /* construct the query for a GENCODE records, which includes filters. */
 {
 struct gencodeQuery *gencodeQuery = gencodeQueryNew();
 geneQueryAddGenePredCols(tg, gencodeQuery);
 if (includeAttrs)
-    geneQueryAddAttrsCols(tg, gencodeQuery);
+    geneQueryAddAttrsCols(tg, conn, gencodeQuery);
 addQueryCommon(tg, filterBySetGet, gencodeQuery);
 return gencodeQuery;
 }
 
 static struct gencodeQuery *highlightQueryConstruct(struct track *tg)
 /* construct the query for GENCODE ids which should be highlighted.
  * this essentially redoes the genePred query, only using the filter functions
  * and only getting ids */
 {
 struct gencodeQuery *gencodeQuery = gencodeQueryNew();
 sqlDyStringPrintf(gencodeQuery->fields, "g.name");
 
 addQueryCommon(tg, highlightBySetGet, gencodeQuery);
 return gencodeQuery;
 }
@@ -538,31 +534,31 @@
 else
     lf->extra = cloneString(gp->name);
 wgEncodeGencodeAttrsFree(&attrs);
 return lf;
 }
 
 static void loadGencodeTrack(struct track *tg)
 /* Load genePreds in window info linked feature, with filtering, etc. */
 {
 struct sqlConnection *conn = hAllocConn(database);
 unsigned enabledLabels = getEnabledLabels(tg);
 boolean needAttrs = (enabledLabels & ITEM_LABEL_GENE_ID) != 0;  // only for certain labels
 struct hash *highlightIds = NULL;
 if (anyFilterBy(tg, highlightBySetGet))
     highlightIds = loadHighlightIds(conn, tg);
-struct gencodeQuery *gencodeQuery = geneQueryConstruct(tg, needAttrs);
+struct gencodeQuery *gencodeQuery = geneQueryConstruct(tg, conn, needAttrs);
 struct sqlResult *sr = executeQuery(conn, gencodeQuery);
 struct linkedFeatures *lfList = NULL;
 unsigned highlightColor = getHighlightColor(tg);
 char **row;
 while ((row = sqlNextRow(sr)) != NULL)
     slAddHead(&lfList, loadGencodeTranscript(tg, gencodeQuery, row, enabledLabels, highlightIds, highlightColor));
 sqlFreeResult(&sr);
 hFreeConn(&conn);
 
 if (tg->visibility != tvDense)
     slSort(&lfList, linkedFeaturesCmpStart);
 else
     slReverse(&lfList);
 tg->items = lfList;
 if (gencodeQuery->isFiltered)