e25bb6ee49c45a024860feee889688230d50b413 kate Fri May 10 15:14:06 2019 -0700 Add links pointing to ENCODE portal pages, to peak cluster details. Input from JK. refs #21139 diff --git src/hg/hgc/peakClusters.c src/hg/hgc/peakClusters.c index 39f4254..ff8f790 100644 --- src/hg/hgc/peakClusters.c +++ src/hg/hgc/peakClusters.c @@ -212,53 +212,53 @@ freez(&vocabFile); dyStringFree(&query); } static char *factorSourceVocabLink(char *vocabFile, char *fieldName, char *fieldVal) /* Add link to show controlled vocabulary entry for term. * Handles 'target' (factor) which is a special case, derived from Antibody entries */ { char *vocabType = (sameString(fieldName, "target") || sameString(fieldName, "factor")) ? "target" : "term"; return wgEncodeVocabLink(vocabFile, vocabType, fieldVal, fieldVal, fieldVal, ""); } static void printFactorSourceTableHits(struct factorSource *cluster, struct sqlConnection *conn, char *sourceTable, char *inputTrackTable, - struct slName *fieldList, boolean invert, char *vocab) + struct slName *fieldList, boolean invert, char *vocab, struct hash *fieldToUrl) /* Put out a lines in an html table that shows assayed sources that have hits in this * cluster, or if invert is set, that have misses. */ { char *vocabFile = NULL; if (vocab) { vocabFile = cloneFirstWord(vocab); } /* Make the monster SQL query to get all assays*/ struct dyString *query = dyStringNew(0); sqlDyStringPrintf(query, "select %s.id,%s.name,%s.tableName", sourceTable, sourceTable, inputTrackTable); struct slName *field; for (field = fieldList; field != NULL; field = field->next) sqlDyStringPrintf(query, ",%s.%s", inputTrackTable, field->name); sqlDyStringPrintf(query, " from %s,%s ", inputTrackTable, sourceTable); sqlDyStringPrintf(query, " where %s.source = %s.description", inputTrackTable, sourceTable); sqlDyStringPrintf(query, " and factor='%s' order by %s.source", cluster->name, inputTrackTable); boolean encodeStanford = FALSE; -if (startsWith("encode3", sourceTable) || startsWith("encode4", sourceTable)) +if (startsWith("enc", sourceTable)) encodeStanford = TRUE; int displayNo = 0; int fieldCount = slCount(fieldList); struct sqlResult *sr = sqlGetResult(conn, query->string); char **row; while ((row = sqlNextRow(sr)) != NULL) { int sourceId = sqlUnsigned(row[0]); boolean hit = FALSE; int i; double signal = 0.0; for (i=0; iexpCount; i++) { if (cluster->expNums[i] == sourceId) @@ -270,37 +270,52 @@ } if (hit ^ invert) { printf("\n"); webPrintIntCell(++displayNo); if (!invert) webPrintDoubleCell(signal); webPrintLinkCell(row[1]); int i = 0; // find position of CV metadata in field list int offset = 3; struct slName *field = fieldList; for (i=0; inext) { char *fieldVal = row[i+offset]; + char *link = NULL; if (vocab) { - char *link = cloneString(factorSourceVocabLink(vocabFile, field->name, fieldVal)); - webPrintLinkCell(link); + link = cloneString(factorSourceVocabLink(vocabFile, field->name, fieldVal)); } - else - webPrintLinkCell(fieldVal); + else if (fieldToUrl != NULL) + { + // (outside) links on vocab items + char *urlPattern = hashFindVal(fieldToUrl, field->name); + if (urlPattern != NULL) + { + char *url = replaceInUrl(urlPattern, fieldVal, cart, database, seqName, + winStart, winEnd, NULL, TRUE, NULL); + if (url != NULL) + { + struct dyString *ds = dyStringCreate("%s\n", + url, fieldVal); + link = dyStringCannibalize(&ds); + } + } + } + webPrintLinkCell(link ? link : fieldVal); } char *table = row[2]; if (encodeStanford) { char *file = stringIn("ENCFF", table); if (!file) webPrintLinkCell(table); else { webPrintLinkCellStart(); printf("%s", file, file); webPrintLinkCellEnd(); } } @@ -508,51 +523,53 @@ printPos(cluster->chrom, cluster->chromStart, cluster->chromEnd, NULL, TRUE, item); /* Get list of tracks we'll look through for input. */ char *inputTrackTable = trackDbRequiredSetting(tdb, "inputTrackTable"); char query[256]; sqlSafef(query, sizeof(query), "select tableName from %s where factor='%s' order by source", inputTrackTable, cluster->name); /* Next do the lists of hits and misses. We have the hits from the non-zero signals in * cluster->expScores. We need to figure out the sources actually assayed though * some other way. We'll do this by one of two techniques. */ char *inputTableFieldDisplay = trackDbSetting(tdb, "inputTableFieldDisplay"); if (inputTableFieldDisplay != NULL) { + char *fieldUrls = trackDbSetting(tdb, "inputTableFieldUrls"); + struct hash *fieldToUrl = hashFromString(fieldUrls); struct slName *fieldList = stringToSlNames(inputTableFieldDisplay); char *vocab = trackDbSetting(tdb, "controlledVocabulary"); /* In a new section put up list of hits. */ webNewSection("Assays for %s in Cluster", cluster->name); webPrintLinkTableStart(); printClusterTableHeader(fieldList, TRUE, FALSE, TRUE); printFactorSourceTableHits(cluster, conn, sourceTable, - inputTrackTable, fieldList, FALSE, vocab); + inputTrackTable, fieldList, FALSE, vocab, fieldToUrl); webPrintLinkTableEnd(); webNewSectionHeaderStart(); char sectionTitle[128]; safef(sectionTitle, sizeof(sectionTitle),"Assays for %s Without Hits in Cluster", cluster->name); jsBeginCollapsibleSectionOldStyle(cart, tdb->track, "cellNoHits", sectionTitle, FALSE); webNewSectionHeaderEnd(); webPrintLinkTableStart(); printClusterTableHeader(fieldList, TRUE, FALSE, FALSE); printFactorSourceTableHits(cluster, conn, sourceTable, - inputTrackTable, fieldList, TRUE, vocab); + inputTrackTable, fieldList, TRUE, vocab, fieldToUrl); webPrintLinkTableEnd(); jsEndCollapsibleSection(); } else { errAbort("Missing required trackDb setting %s for track %s", "inputTableFieldDisplay", tdb->track); } webNewSectionHeaderStart(); jsBeginCollapsibleSectionOldStyle(cart, tdb->track, "cellSources", "Cell Abbreviations", FALSE); webNewSectionHeaderEnd(); hPrintFactorSourceAbbrevTable(conn, tdb); jsEndCollapsibleSection(); doClusterMotifDetails(conn, tdb, cluster);