bddb262e29ccaea9bdf08d393f81375c66e5abb6 hiram Mon Dec 8 16:29:59 2025 -0800 fix the toga click code to use a simple local hideToggle class refs #35776 diff --git src/hg/hgc/togaClick.c src/hg/hgc/togaClick.c index f446ec6bb5b..9d8f957bbbf 100644 --- src/hg/hgc/togaClick.c +++ src/hg/hgc/togaClick.c @@ -1,734 +1,730 @@ /* togaClick - click handling for TOGA tracks */ #include "common.h" #include "hgc.h" #include "togaClick.h" #include "string.h" #include "htmshell.h" #include "chromAlias.h" struct togaDataBB *togaDataBBLoad(char **row, bits16 fieldCount) /* Load a togaData from row fetched with select * from togaData * from database. Dispose of this with togaDataFree(). */ { struct togaDataBB *ret; AllocVar(ret); ret->projection = cloneString(row[0]); ret->ref_trans_id = cloneString(row[1]); ret->ref_region = cloneString(row[2]); ret->query_region = cloneString(row[3]); ret->chain_score = cloneString(row[4]); ret->chain_synteny = cloneString(row[5]); ret->chain_flank = cloneString(row[6]); ret->chain_gl_cds_fract = cloneString(row[7]); ret->chain_loc_cds_fract = cloneString(row[8]); ret->chain_exon_cov = cloneString(row[9]); ret->chain_intron_cov = cloneString(row[10]); ret->status = cloneString(row[11]); ret->perc_intact_ign_M = cloneString(row[12]); ret->perc_intact_int_M = cloneString(row[13]); ret->intact_codon_prop = cloneString(row[14]); ret->ouf_prop = cloneString(row[15]); ret->mid_intact = cloneString(row[16]); ret->mid_pres = cloneString(row[17]); ret->prot_alignment = cloneString(row[18]); ret->svg_line = cloneString(row[19]); ret->ref_link = cloneString(row[20]); ret->inact_mut_html_table = cloneString(row[21]); ret->exon_ali_html = cloneString(row[22]); /* read two optional new items, CDSseq and frame-corrected protein */ ret->CDSseq = NULL; if (fieldCount >= 35) /* 0-11 are bed core fields. This fct gets a pointer starting with element 12. 12+23 = 35 */ ret->CDSseq = cloneString(row[23]); ret->protseqFrameCorrected = NULL; if (fieldCount >= 36) /* 12+24 = 36 */ ret->protseqFrameCorrected = cloneString(row[24]); /* number and percent of mutated exons (additional data now shown for the gene loss status) */ ret->numExonsMutated = NULL; ret->percentExonsMutated = NULL; if (fieldCount >= 37) /* 12+25 = 37 */ ret->numExonsMutated = cloneString(row[25]); if (fieldCount >= 38) /* 12+26 = 38 */ ret->percentExonsMutated = cloneString(row[26]); return ret; } struct togaData *togaDataLoad(char **row) /* Load a togaData from row fetched with select * from togaData * from database. Dispose of this with togaDataFree(). */ { struct togaData *ret; AllocVar(ret); ret->projection = cloneString(row[0]); ret->ref_trans_id = cloneString(row[1]); ret->ref_region = cloneString(row[2]); ret->query_region = cloneString(row[3]); ret->chain_score = cloneString(row[4]); ret->chain_synteny = cloneString(row[5]); ret->chain_flank = cloneString(row[6]); ret->chain_gl_cds_fract = cloneString(row[7]); ret->chain_loc_cds_fract = cloneString(row[8]); ret->chain_exon_cov = cloneString(row[9]); ret->chain_intron_cov = cloneString(row[10]); ret->status = cloneString(row[11]); ret->perc_intact_ign_M = cloneString(row[12]); ret->perc_intact_int_M = cloneString(row[13]); ret->intact_codon_prop = cloneString(row[14]); ret->ouf_prop = cloneString(row[15]); ret->mid_intact = cloneString(row[16]); ret->mid_pres = cloneString(row[17]); ret->prot_alignment = cloneString(row[18]); ret->svg_line = cloneString(row[19]); return ret; } void togaDataBBFree(struct togaDataBB **pEl) /* Free a single dynamically allocated togaDatasuch as created * with togaDataLoad(). */ { struct togaDataBB *el; if ((el = *pEl) == NULL) return; freeMem(el->projection); freeMem(el->ref_trans_id); freeMem(el->ref_region); freeMem(el->query_region); freeMem(el->chain_score); freeMem(el->chain_synteny); freeMem(el->chain_flank); freeMem(el->chain_gl_cds_fract); freeMem(el->chain_loc_cds_fract); freeMem(el->chain_exon_cov); freeMem(el->chain_intron_cov); freeMem(el->status); freeMem(el->perc_intact_ign_M); freeMem(el->perc_intact_int_M); freeMem(el->intact_codon_prop); freeMem(el->ouf_prop); freeMem(el->mid_intact); freeMem(el->mid_pres); freeMem(el->prot_alignment); freeMem(el->svg_line); freeMem(el->ref_link); freeMem(el->inact_mut_html_table); freeMem(el->exon_ali_html); freez(pEl); } void togaDataFree(struct togaData **pEl) /* Free a single dynamically allocated togaDatasuch as created * with togaDataLoad(). */ { struct togaData *el; if ((el = *pEl) == NULL) return; freeMem(el->projection); freeMem(el->ref_trans_id); freeMem(el->ref_region); freeMem(el->query_region); freeMem(el->chain_score); freeMem(el->chain_synteny); freeMem(el->chain_flank); freeMem(el->chain_gl_cds_fract); freeMem(el->chain_loc_cds_fract); freeMem(el->chain_exon_cov); freeMem(el->chain_intron_cov); freeMem(el->status); freeMem(el->perc_intact_ign_M); freeMem(el->perc_intact_int_M); freeMem(el->intact_codon_prop); freeMem(el->ouf_prop); freeMem(el->mid_intact); freeMem(el->mid_pres); freeMem(el->prot_alignment); freeMem(el->svg_line); freez(pEl); } struct togaNucl *togaNuclLoad(char **row) /* Load a togaNucl from row fetched with select * from togaNucl * from database. Dispose of this with togaNuclFree(). */ { struct togaNucl *ret; AllocVar(ret); ret->transcript = cloneString(row[0]); ret->exon_num = cloneString(row[1]); ret->exon_region = cloneString(row[2]); ret->pid = cloneString(row[3]); ret->blosum = cloneString(row[4]); ret->gaps = cloneString(row[5]); ret->ali_class = cloneString(row[6]); ret->exp_region = cloneString(row[7]); ret->in_exp_region = cloneString(row[8]); ret->alignment = cloneString(row[9]); return ret; } void togaNuclFree(struct togaNucl **pEl) /* Free a single dynamically allocated togaNucl such as created * with togaNuclLoad(). */ { struct togaNucl *el; if ((el = *pEl) == NULL) return; freeMem(el->transcript); freeMem(el->exon_num); freeMem(el->exon_region); freeMem(el->pid); freeMem(el->blosum); freeMem(el->gaps); freeMem(el->ali_class); freeMem(el->exp_region); freeMem(el->in_exp_region); freeMem(el->alignment); freez(pEl); } struct togaInactMut *togaInactMutLoad(char **row) /* Load a togaInactMut from row fetched with select * from togaInactMut * from database. Dispose of this with togaInactMutFree(). */ { struct togaInactMut *ret; AllocVar(ret); ret->transcript = cloneString(row[0]); ret->exon_num = cloneString(row[1]); ret->position = cloneString(row[2]); ret->mut_class = cloneString(row[3]); ret->mutation = cloneString(row[4]); ret->is_inact = cloneString(row[5]); ret->mut_id = cloneString(row[6]); return ret; } void togaInactMutFree(struct togaInactMut **pEl) /* Free a single dynamically allocated togaInactMut such as created * with togaInactMutLoad(). */ { struct togaInactMut *el; if ((el = *pEl) == NULL) return; freeMem(el->transcript); freeMem(el->exon_num); freeMem(el->position); freeMem(el->mut_class); freeMem(el->mutation); freeMem(el->is_inact); freeMem(el->mut_id); freez(pEl); } void extractHLTOGAsuffix(char *suffix) /* Extract suffix from TOGA table name. Prefix must be HLTOGAannot */ { int suff_len = strlen(suffix); if (suff_len <= HLTOGA_BED_PREFIX_LEN) // we cannot chop first PREFIX_LEN characters { // TODO: NOT SURE IF IT WORKS; but this must not happen char empty[5] = { '\0' }; strcpy(suffix, empty); } else { // just start the string 11 characters upstream memmove(suffix, suffix + HLTOGA_BED_PREFIX_LEN, suff_len - HLTOGA_BED_PREFIX_LEN + 1); } } void HLprintQueryProtSeqForAli(char *proteinAlignment) { // take protein sequence alignment // print only the query sequence char *str = proteinAlignment; int printed_char_num = 0; while ((str = strstr(str, "que:")) != NULL) { str += 10; char ch; while ((ch = *str++) != '<') { if (ch != '-') { putchar(ch); ++printed_char_num; } if (printed_char_num == 80) { printed_char_num = 0; printf("
"); } } } } void print_with_newlines(const char *str) { int line_length = 80; // Number of characters per line int length = strlen(str); int i = 0; while (i < length) { /* Print up to 80 characters or the remainder of the string */ int chars_to_print = (length - i < line_length) ? (length - i) : line_length; printf("%.*s
", chars_to_print, &str[i]); i += chars_to_print; } } void doHillerLabTOGAGeneBig(char *database, struct trackDb *tdb, char *item, char *table_name) /* Put up TOGA Gene track info. */ // To think about -> put into a single bigBed // string: HTML formatted inact mut // string: HTML formatted exon ali section { int start = cartInt(cart, "o"); int end = cartInt(cart, "t"); char *chrom = cartString(cart, "c"); char *fileName = bbiNameFromSettingOrTable(tdb, NULL, tdb->table); struct bbiFile *bbi = bigBedFileOpenAlias(hReplaceGbdb(fileName), chromAliasFindAliases); struct lm *lm = lmInit(0); struct bigBedInterval *bbList = bigBedIntervalQuery(bbi, chrom, start, end, 0, lm); struct bigBedInterval *bb; char *fields[bbi->fieldCount]; for (bb = bbList; bb != NULL; bb = bb->next) { if (!(bb->start == start && bb->end == end)) continue; // our names are unique char *name = cloneFirstWordByDelimiterNoSkip(bb->rest, '\t'); boolean match = (isEmpty(name) && isEmpty(item)) || sameOk(name, item); if (!match) continue; char startBuf[16], endBuf[16]; bigBedIntervalToRow(bb, chrom, startBuf, endBuf, fields, bbi->fieldCount); break; } printf("

Projection v2 %s

\n", item); struct togaDataBB *info = togaDataBBLoad(&fields[11], bbi->fieldCount); // Bogdan: why 11? 0-11 are bed-like fields likely printf("Reference transcript: %s
", info->ref_link); printf("Genomic locus in reference: %s
\n", info->ref_region); printf("Genomic locus in query: %s
\n", info->query_region); printf("Projection classification: %s
\n", info->status); printf("Probability that query locus is orthologous: %s
\n", info->chain_score); // list of chain features (for orthology classification) printf("Show features used for ortholog probability:\n"); printf("\n"); printf("
\n"); // show inact mut plot printf("

Visualization of inactivating mutations on exon-intron structure

\n"); printf("%s\n", info->svg_line); printf("
Exons shown in grey are missing (often overlap assembly gaps).\nExons shown in"); printf(" red or blue are deleted or do not align at all.\nRed indicates that the exon deletion "); printf("shifts the reading frame, while blue indicates that exon deletion(s) are framepreserving.
\n"); // GLP features printf("Show features used for transcript classification\n"); printf("\n"); printf("
\n"); printf("

Predicted protein sequence

\n"); printf("Show protein sequence of query\n"); printf("
\n"); if (info->protseqFrameCorrected != NULL) { printf("Show frame-corrected protein sequence of query (potential frameshifts are masked)\n"); printf("\n"); } if (info->CDSseq != NULL) { printf("
\n"); printf("

Predicted coding (DNA) sequence

\n"); printf("Show coding sequence of query\n"); printf("\n"); } // and show protein sequence printf("
\n"); printf("

Protein sequence alignment

\n"); printf("Show alignment between reference and query\n"); printf("\n"); // show inactivating mutations if required printf("
\n"); printf("

List of inactivating mutations

\n"); printf("Show inactivating mutations\n"); printf("\n\n"); // show exons data printf("
\n"); printf("

Exon alignments

\n"); printf("Show exon sequences and features\n"); printf("\n

\n"); printTrackHtml(tdb); // and do I need this? } void doHillerLabTOGAGene(char *database, struct trackDb *tdb, char *item, char *table_name) /* Put up TOGA Gene track info. */ { //int start = cartInt(cart, "o"); char headerTitle[512]; char suffix[512]; strcpy(suffix, table_name); extractHLTOGAsuffix(suffix); safef(headerTitle, sizeof(headerTitle), "%s", item); genericHeader(tdb, headerTitle); printf("

TOGA gene annotation

\n"); // htmlHorizontalLine(); if (startsWith("bigBed", tdb->type)) { doHillerLabTOGAGeneBig(database, tdb, item, table_name); return; } struct sqlConnection *conn = hAllocConn(database); // define TOGA table names: initate with pre-defined prefixes char togaDataTableName[256]; char togaNuclTableName[256]; char togaInactMutTableName[256]; strcpy(togaDataTableName, HLTOGA_DATA_PREFIX); strcpy(togaNuclTableName, HLTOGA_NUCL_PREFIX); strcpy(togaInactMutTableName, HLTOGA_INACT_PREFIX); // add suffix strcat(togaDataTableName, suffix); strcat(togaNuclTableName, suffix); strcat(togaInactMutTableName, suffix); if (hTableExists(database, togaDataTableName)) { printf("

Projection %s


\n", item); char query[256]; struct sqlResult *sr = NULL; char **row; struct togaData *info = NULL; sqlSafef(query, sizeof(query), "select * from %s where transcript='%s'", togaDataTableName, item); sr = sqlGetResult(conn, query); if ((row = sqlNextRow(sr)) != NULL) { info = togaDataLoad(row); // parse sql output // fill HTML template: printf("Reference transcript: %s
", info->ref_trans_id, info->ref_trans_id); printf("Genomic locus in reference: %s
\n", info->ref_region); printf("Genomic locus in query: %s
\n", info->query_region); printf("Projection classification: %s
\n", info->status); printf("Probability that query locus is orthologous: %s
\n", info->chain_score); // list of chain features (for orthology classification) printf("Show features used for ortholog probability\n"); printf("\n
\n"); htmlHorizontalLine(); // show inact mut plot printf("

Visualization of inactivating mutations on exon-intron structure

\n"); printf("%s
\n", info->svg_line); printf("
Exons shown in grey are missing (often overlap assembly gaps).\nExons shown in"); printf(" red or blue are deleted or do not align at all.\nRed indicates that the exon deletion "); printf("shifts the reading frame, while blue indicates that exon deletion(s) are framepreserving.
\n"); // GLP features printf("Show features used for transcript classification\n"); printf("\n
\n"); printf("

Query protein sequence


"); printf("Show protein sequence of query\n"); printf("\n"); // and show protein sequence htmlHorizontalLine(); printf("

Protein sequence alignment


\n"); printf("Show alignment between reference and query\n"); - printf("
\n"); + printf("\n

\n"); // do not forget to free toga data struct togaDataFree(&info); } else { // no data found, need to report this printf("

No found data for %s

\n", item); } sqlFreeResult(&sr); } // show inactivating mutations if required printf("

List of inactivating mutations


\n"); if (hTableExists(database, togaInactMutTableName)) { char query[256]; struct sqlResult *sr = NULL; char **row; sqlSafef(query, sizeof(query), "select * from %s where transcript='%s'", togaInactMutTableName, item); sr = sqlGetResult(conn, query); - printf("Show inactivating mutations\n"); - printf("
\n"); + printf("Show inactivating mutations\n"); + printf("\n
\n"); } else { printf("Sorry, cannot find TOGAInactMut table.
\n"); } // show exons data htmlHorizontalLine(); printf("

Exon alignments


\n"); if (hTableExists(database, togaNuclTableName)) { char query[256]; struct sqlResult *sr = NULL; char **row; - printf("Show exon sequences and features\n"); - printf("
\n"); + printf("Show exon sequences and features\n"); + printf("\n

\n"); } else { printf("Sorry, cannot find TOGANucl table.
\n"); } htmlHorizontalLine(); // TODO: check whether I need this printf("%s", hgTracksPathAndSettings()); - hPrintf(""); - hPrintf(""); - hPrintf(""); - printTrackHtml(tdb); // and do I need this? hFreeConn(&conn); }