dc33f1e79e44f3d7ac0c8bc63c3c43847325c548 braney Thu May 26 12:40:57 2022 -0700 add a new click handler for TOGA tracks from Michael Hiller's group diff --git src/hg/hgc/togaClick.c src/hg/hgc/togaClick.c index 62b7627..e3d53c8 100644 --- src/hg/hgc/togaClick.c +++ src/hg/hgc/togaClick.c @@ -1,24 +1,60 @@ /* 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) +/* 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]); + 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]); @@ -28,30 +64,67 @@ 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); @@ -158,233 +231,240 @@ { 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 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 %s


\n", item); -struct togaData *info = togaDataLoad(&fields[11]); -// fill HTML template: -printf("Projected via: %s
", - info->ref_trans_id, info->ref_trans_id); -printf("Region in reference: %s
\n", info->ref_region); -printf("Region in query: %s
\n", info->query_region); +struct togaDataBB *info = togaDataBBLoad(&fields[11]); // Bogdan: why 11? 0-11 are bed-like fields likely -printf("Projection class: %s
\n", info->status); -printf("Chain score: %s
\n", info->chain_score); +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 chain features for classification\n"); +printf("Show features used for ortholog probability\n"); printf("
\n"); printf("\n"); + +printf("
\nFeature description:\n"); +printf("For each projection (one reference transcript and one overlapping chain),\n"); +printf("TOGA computes the following features by intersecting the reference coordinates of aligning\n"); +printf("blocks in the chain with different gene parts (coding exons, UTR (untranslated region) exons, introns)\n"); +printf("and the respective intergenic regions.\n
\n"); + +printf("We define the following variables:\n\n"); +printf("Using these variables, TOGA computes the following features:\n"); +printf("\n"); + + printf("\n
\n
\n"); htmlHorizontalLine(); // show inact mut plot -printf("

Inactivating mutations plot

\n"); +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 GLP features\n"); +printf("Show features used for transcript classification\n"); printf("
\n"); printf("\n
\n
\n"); -// and show protein sequence + htmlHorizontalLine(); -printf("

Protein sequence


\n"); -printf("Show protein alignment\n"); + +printf("

Predicted protein sequence


\n"); + +printf("Show protein sequence of query\n"); printf("
\n"); +// printf("{protein seq of the query without dashes or other things. Should end with *}\n"); +printf(""); +HLprintQueryProtSeqForAli(info->prot_alignment); +printf("\n
\n
\n
\n"); + +// and show protein sequence +htmlHorizontalLine(); +printf("

Protein sequence alignment


\n"); +printf("Show alignment between reference and query\n"); +printf("
\n"); printf("%s
\n", info->prot_alignment); printf("
\n

\n"); // show inactivating mutations if required -printf("

Inactivating mutations


\n"); +printf("

List of inactivating mutations


\n"); printf("Show inactivating mutations\n"); printf("
\n"); printf("\n"); // init table -printf("\n"); +printf("\n"); printf("\n"); -fileName = trackDbSetting(tdb, "inactMutUrl"); -bbi = bigBedFileOpenAlias(hReplaceGbdb(fileName), chromAliasFindAliases); -//struct lm *lm = lmInit(0); -bbList = bigBedIntervalQuery(bbi, chrom, start, end, 0, lm); -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); - struct togaInactMut *info = NULL; - info = togaInactMutLoad(&fields[3]); - printf("\n"); - printf("\n", info->exon_num); - printf("\n", info->position); - printf("\n", info->mut_class); - printf("\n", info->mutation); - if (sameWord(info->is_inact, ONE_)){ - printf("\n", YES_); - } else { - printf("\n", NO_); - } - printf("\n", info->mut_id); - printf("\n"); - togaInactMutFree(&info); - } - //sqlFreeResult(&sr); +printf("%s\n", info->inact_mut_html_table); printf("
exonposm_classmutis_inactmut_id
Exon numberCodon numberMutation classMutationTreated as inactivatingMutation ID
%s%s%s%s%s%s%s
\n"); printf("
\n
\n"); // show exons data htmlHorizontalLine(); -printf("

Exons data


\n"); +printf("

Exon alignments


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

\n"); printf("
\n"); -fileName = trackDbSetting(tdb, "nuclUrl"); -bbi = bigBedFileOpenAlias(hReplaceGbdb(fileName), chromAliasFindAliases); -//struct lm *lm = lmInit(0); -bbList = bigBedIntervalQuery(bbi, chrom, start, end, 0, lm); -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); - struct togaNucl *info = NULL; - info = togaNuclLoad(&fields[3]); - printf("
Exon number: %s

\n", info->exon_num); - printf("Exon region: %s
\n", info->exon_region); - printf("Nucleotide percent identity: %s | BLOSUM: %s
\n", info->pid, info->blosum); - if (sameWord(info->gaps, ONE_)){ - printf("Intersects assembly gaps: %s
\n", YES_); - } else { - printf("Intersects assembly gaps: %s
\n", NO_); - } - printf("Exon alignment class: %s
\n", info->ali_class); - if (sameWord(info->in_exp_region, ONE_)){ - printf("Detected within expected region: %s
\n", YES_); - } else { - printf("Detected within expected region: %s
\n", NO_); - } - printf("Expected region: %s
\n", info->exp_region); - printf("
\n"); - printf("Sequence alignment:
\n"); - printf("%s
\n", info->alignment); - togaNuclFree(&info); - } - - //sqlFreeResult(&sr); - printf("
\n

\n"); +// printf("%s\n", info->exon_ali_string); +printf("%s\n", info->exon_ali_html); htmlHorizontalLine(); // TODO: check whether I need this printf("%s", hgTracksPathAndSettings()); hPrintf(""); hPrintf(""); hPrintf(""); 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); @@ -396,175 +476,220 @@ 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("Projected via: %s
", + printf("Reference transcript: %s
", info->ref_trans_id, info->ref_trans_id); - printf("Region in reference: %s
\n", info->ref_region); - printf("Region in query: %s
\n", info->query_region); + printf("Genomic locus in reference: %s
\n", info->ref_region); + printf("Genomic locus in query: %s
\n", info->query_region); - printf("Projection class: %s
\n", info->status); - printf("Chain score: %s
\n", info->chain_score); + 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 chain features for classification\n"); + printf("Show features used for ortholog probability\n"); printf("
\n"); printf("\n"); + + printf("
\nFeature description:\n"); + printf("For each projection (one reference transcript and one overlapping chain),\n"); + printf("TOGA computes the following features by intersecting the reference coordinates of aligning\n"); + printf("blocks in the chain with different gene parts (coding exons, UTR (untranslated region) exons, introns)\n"); + printf("and the respective intergenic regions.\n
\n"); + + printf("We define the following variables:\n\n"); + printf("Using these variables, TOGA computes the following features:\n"); + printf("\n"); + + printf("\n
\n
\n"); htmlHorizontalLine(); // show inact mut plot - printf("

Inactivating mutations plot

\n"); + 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 GLP features\n"); + printf("Show features used for transcript classification\n"); printf("
\n"); printf("\n
\n
\n"); + printf("

Query protein sequence


"); + + printf("Show protein sequence of query\n"); + printf("
\n"); + printf("{protein seq of the query without dashes or other things. Should end with *}\n"); + printf("
\n
\n
\n"); // and show protein sequence htmlHorizontalLine(); - printf("

Protein sequence


\n"); - printf("Show protein alignment\n"); - printf("
\n"); + printf("

Protein sequence alignment


\n"); + printf("Show alignment between reference and query\n"); + printf("
\n"); printf("%s
\n", info->prot_alignment); printf("
\n

\n"); // do not forget to free toga data struct togaDataFree(&info); } else { // no data found, need to report this printf("Not found data for %s\n", item); } sqlFreeResult(&sr); } // show inactivating mutations if required - printf("

Inactivating mutations


\n"); + 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("\n"); // init table - printf("\n"); + printf("\n"); printf("\n"); while ((row = sqlNextRow(sr)) != NULL) { struct togaInactMut *info = NULL; info = togaInactMutLoad(row); printf("\n"); printf("\n", info->exon_num); printf("\n", info->position); printf("\n", info->mut_class); printf("\n", info->mutation); if (sameWord(info->is_inact, ONE_)){ printf("\n", YES_); } else { printf("\n", NO_); } printf("\n", info->mut_id); printf("\n"); togaInactMutFree(&info); } sqlFreeResult(&sr); printf("
exonposm_classmutis_inactmut_id
Exon numberCodon numberMutation classMutationTreated as inactivatingMutation ID
%s%s%s%s%s%s%s
\n"); printf("
\n
\n"); } else { printf("Sorry, cannot find TOGAInactMut table.
\n"); } // show exons data htmlHorizontalLine(); - printf("

Exons data


\n"); + 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"); sqlSafef(query, sizeof(query), "select * from %s where transcript='%s'", togaNuclTableName, item); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { struct togaNucl *info = NULL; info = togaNuclLoad(row); printf("
Exon number: %s

\n", info->exon_num); printf("Exon region: %s
\n", info->exon_region); printf("Nucleotide percent identity: %s | BLOSUM: %s
\n", info->pid, info->blosum); if (sameWord(info->gaps, ONE_)){ printf("Intersects assembly gaps: %s
\n", YES_); } else { printf("Intersects assembly gaps: %s
\n", NO_); } printf("Exon alignment class: %s
\n", info->ali_class); if (sameWord(info->in_exp_region, ONE_)){ - printf("Detected within expected region: %s
\n", YES_); + printf("Detected within expected region (%s): %s
\n", info->exp_region, YES_); } else { - printf("Detected within expected region: %s
\n", NO_); + printf("Detected within expected region (%s): %s
\n", info->exp_region, NO_); } - printf("Expected region: %s
\n", info->exp_region); + // printf("Expected region: %s
\n", info->exp_region); printf("
\n"); - printf("Sequence alignment:
\n"); + printf("Sequence alignment between reference and query exon:
\n"); printf("%s
\n", info->alignment); togaNuclFree(&info); } sqlFreeResult(&sr); 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); } -