483878d23907da9695facf9610aa986208f0a1d7 galt Fri May 9 11:26:36 2025 -0700 Revert "Simplify use of BLAT results by always creating a custom track. fixes #32751" This reverts commit a5a45be7e379b64278e667f80c75cc0cc41d9ea4. diff --git src/hg/hgBlat/hgBlat.c src/hg/hgBlat/hgBlat.c index 691ccbf9cc9..220789493a5 100644 --- src/hg/hgBlat/hgBlat.c +++ src/hg/hgBlat/hgBlat.c @@ -490,40 +490,61 @@ return same; } boolean allDigits(char *s) /* Return TRUE if s is all digits */ { char c; while ((c = *s++) != 0) if (!isdigit(c)) return FALSE; return TRUE; } +void printLuckyRedirect(char *browserUrl, struct psl *psl, char *database, char *pslName, + char *faName, char *uiState, char *unhideTrack) +/* Print out a very short page that redirects us. */ +{ +char url[1024]; +safef(url, sizeof(url), "%s?position=%s:%d-%d&db=%s&ss=%s+%s&%s%s", + browserUrl, psl->tName, psl->tStart + 1, psl->tEnd, database, + pslName, faName, uiState, unhideTrack); +/* htmlStart("Redirecting"); */ +/* Odd it appears that we've already printed the Content-Typ:text/html line + but I can't figure out where... */ +htmStart(stdout, "Redirecting"); +jsInlineF("location.replace('%s');\n", url); +printf("\n", url); +htmlEnd(); + +} + + /* forward declaration to reduce churn */ static void getCustomName(char *database, struct cart *cart, struct psl *psl, char **pName, char **pDescription); void showAliPlaces(char *pslName, char *faName, char *customText, char *database, enum gfType qType, enum gfType tType, char *organism, boolean feelingLucky) /* Show all the places that align. */ { +boolean useBigPsl = cfgOptionBooleanDefault("useBlatBigPsl", TRUE); struct lineFile *lf = pslFileOpen(pslName); struct psl *pslList = NULL, *psl; +char *browserUrl = hgTracksName(); char *hgcUrl = hgcName(); char uiState[64]; char *vis; char unhideTrack[64]; char *sort = cartUsualString(cart, "sort", pslSortList[0]); char *output = cartUsualString(cart, "output", outputList[0]); boolean pslOut = startsWith("psl", output); boolean pslRawOut = sameWord("pslRaw", output); boolean jsonOut = sameWord(output, "json"); sprintf(uiState, "%s=%s", cartSessionVarName(), cartSessionId(cart)); /* If user has hidden BLAT track, add a setting that will unhide the track if user clicks on a browser link. */ vis = cartOptionalString(cart, "hgUserPsl"); @@ -537,84 +558,199 @@ if (psl->match >= minMatchShown) slAddHead(&pslList, psl); } lineFileClose(&lf); if (pslList == NULL && !jsonOut) { printf("

Sorry, no matches found"); if (!allResults) printf(" (with a score of at least %d)", minMatchShown); printf("
\n"); return; } pslSortListByVar(&pslList, sort); -if (pslOut) +if(feelingLucky) + { + /* If we found something jump browser to there. */ + if(slCount(pslList) > 0) + printLuckyRedirect(browserUrl, pslList, database, pslName, faName, uiState, unhideTrack); + /* Otherwise call ourselves again not feeling lucky to print empty + results. */ + else + { + cartWebStart(cart, trackHubSkipHubName(database), "%s (%s) BLAT Results", trackHubSkipHubName(organism), trackHubSkipHubName(database)); + showAliPlaces(pslName, faName, customText, database, qType, tType, organism, FALSE); + cartWebEnd(); + } + } +else if (pslOut) { if (!pslRawOut) printf("
");
     if (!sameString(output, "psl no header"))
 	pslxWriteHead(stdout, qType, tType);
 
     for (psl = pslList; psl != NULL; psl = psl->next)
 	pslTabOut(psl, stdout);
 
     if (pslRawOut)
         exit(0);
     printf("
");
     printf("
"); } else if (jsonOut) { webStartText(); pslWriteAllJson(pslList, stdout, database, TRUE); exit(0); } else // hyperlink { + printf("

BLAT Search Results

"); + char* posStr = cartOptionalString(cart, "position"); + if (posStr != NULL) + printf("

Go back to %s on the Genome Browser.

\n", browserUrl, posStr); + if (useBigPsl) + { char *trackName = NULL; char *trackDescription = NULL; getCustomName(database, cart, pslList, &trackName, &trackDescription); psl = pslList; printf( "
\n", hgcUrl,cartUsualString(cart, "formMethod", "POST")); printf("\n",psl->tStart); printf("\n",psl->tEnd); printf("\n","buildBigPsl"); printf("\n",pslName,faName,psl->qName); printf("\n",psl->tName); printf("\n",psl->tStart); printf("\n",psl->tEnd); printf("\n", cartSessionVarName(), cartSessionId(cart)); if (pslIsProtein(psl)) printf("\n"); - if (feelingLucky) - printf("\n"); + printf(""); + + printf(""); + printf(""); + printf("
Custom track name: "); + cgiMakeTextVar( "trackName", trackName, 30); + printf("
Custom track description: "); + cgiMakeTextVar( "trackDescription", trackDescription,50); + printf("
\n"); + printInfoIcon("The BLAT results below are temporary and will be replaced by your next BLAT search. " + "However, when saved as a custom track with the button on the left, BLAT results are stored on our " + "servers and can be saved as stable session (View > My Sessions) links that can be shared via email or in manuscripts. " + "\n

We have never cleaned up the data under stable session links so far. " + "To reduce track clutter in your own sessions, you can delete BLAT custom tracks from the main Genome Browser " + "view using the little trash icon next to each custom track.

"); + puts("
"); + } - printf("\n", trackName); + printf("
");
 
-    printf("\n", trackDescription);
+    // find maximum query name size for padding calculations and
+    // find maximum target chrom name size for padding calculations
+    int maxQChromNameSize = 0;
+    int maxTChromNameSize = 0;
+    for (psl = pslList; psl != NULL; psl = psl->next)
+	{
+	int qLen = strlen(psl->qName);
+	maxQChromNameSize = max(maxQChromNameSize,qLen);
+	int tLen = strlen(psl->tName);
+	maxTChromNameSize = max(maxTChromNameSize,tLen);
+	}
+    maxQChromNameSize = max(maxQChromNameSize,5);
+    maxTChromNameSize = max(maxTChromNameSize,5);
 
-    printf("\n");
-    puts("");
-    printf("
"); - jsInline("$(document).ready(function() {\n" - "$(\"input[value='Create custom track']\").trigger('click');\n" - "});\n"); + printf(" ACTIONS QUERY "); + + spaceOut(stdout, maxQChromNameSize - 5); + + printf("SCORE START END QSIZE IDENTITY CHROM "); + spaceOut(stdout, maxTChromNameSize - 5); + + printf(" STRAND START END SPAN\n"); + + printf("----------------------------------------------------------------------------------------------------------"); + repeatCharOut(stdout, '-', maxQChromNameSize - 5); + repeatCharOut(stdout, '-', maxTChromNameSize - 5); + + printf("\n"); + + for (psl = pslList; psl != NULL; psl = psl->next) + { + char *browserHelp = "Open a Genome Browser showing this match"; + char *helpText = "Open a Genome Browser with the BLAT results, but in a new internet browser tab"; + // XX putting SVG into C code like this is ugly. define somewhere? maybe have globals for these? + char *icon = ""; + if (customText) + { + printf("browser ", + browserHelp, browserUrl, psl->tName, psl->tStart + 1, psl->tEnd, database, + customText, uiState, unhideTrack); + printf("new tab%s ", + helpText, browserUrl, psl->tName, psl->tStart + 1, psl->tEnd, database, + customText, unhideTrack, icon); + } + else + { + printf("browser ", + browserHelp, browserUrl, psl->tName, psl->tStart + 1, psl->tEnd, database, + pslName, faName, uiState, unhideTrack); + printf("new tab%s ", + helpText, browserUrl, psl->tName, psl->tStart + 1, psl->tEnd, database, + pslName, faName, unhideTrack, icon); + } + printf("", + hgcUrl, psl->tStart, pslName, cgiEncode(faName), psl->qName, psl->tName, + psl->tStart, psl->tEnd, database, uiState); + printf("details "); + + printf("%s",psl->qName); + spaceOut(stdout, maxQChromNameSize - strlen(psl->qName)); + printf(" %5d %5d %5d %5d %5.1f%% ", + pslScore(psl), psl->qStart+1, psl->qEnd, psl->qSize, + 100.0 - pslCalcMilliBad(psl, TRUE) * 0.1); + char *displayChromName = chromAliasGetDisplayChrom(database, cart, psl->tName); + printf("%s",displayChromName); + spaceOut(stdout, maxTChromNameSize - strlen(displayChromName)); + printf(" %-2s %9d %9d %6d", + psl->strand, psl->tStart+1, psl->tEnd, + psl->tEnd - psl->tStart); + + // if you modify this, also modify hgPcr.c:doQuery, which implements a similar feature + char *seq = psl->tName; + if (endsWith(seq, "_fix")) + printf(" What is chrom_fix?"); + else if (endsWith(seq, "_alt")) + printf(" What is chrom_alt?"); + else if (endsWith(seq, "_random")) + printf(" What is chrom_random?"); + else if (startsWith(seq, "chrUn")) + printf(" What is a chrUn sequence?"); + printf("\n"); + } + printf("
\n"); + webNewSection("Help"); + puts("

Missing a match?
"); + puts("What is chr_alt & chr_fix?

\n"); + puts("\n"); } pslFreeList(&pslList); } void trimUniq(bioSeq *seqList) /* Check that all seq's in list have a unique name. Try and * abbreviate longer sequence names. */ { struct hash *hash = newHash(0); bioSeq *seq; for (seq = seqList; seq != NULL; seq = seq->next) { char *saferString = needMem(strlen(seq->name)+1); @@ -767,50 +903,48 @@ safef(buffer, sizeof buffer, "%s (%d)", name, count + 1); } return cloneString(buffer); } static void getCustomName(char *database, struct cart *cart, struct psl *psl, char **pName, char **pDescription) // Find a track name that isn't currently a custom track. Also fill in description. { struct slName *names = namesInPsl(psl); char shortName[4096]; char description[4096]; unsigned count = slCount(names); - if (count == 1) { safef(shortName, sizeof shortName, "blat %s", names->name); safef(description, sizeof description, "blat on %s", names->name); } else if (count == 2) { safef(shortName, sizeof shortName, "blat %s+%d", names->name, count - 1); safef(description, sizeof description, "blat on %d queries (%s, %s)", count, names->name, names->next->name); } else { safef(shortName, sizeof shortName, "blat %s+%d", names->name, count - 1); safef(description, sizeof description, "blat on %d queries (%s, %s, ...)", count, names->name, names->next->name); } *pName = makeNameUnique(shortName, database, cart); *pDescription = cloneString(description); - } void queryServer(char *host, char *port, char *db, struct dnaSeq *seq, char *type, char *xType, boolean complex, boolean isProt, boolean queryRC, int seqNumber, char *genomeDataDir) /* Send simple query to server and report results. (no, it doesn't do this) * queryRC is true when the query has been reverse-complemented */ { struct genomeHits *gH; AllocVar(gH); gH->host=cloneString(host); gH->port=cloneString(port); gH->db = cloneString(db); gH->genome = cloneString(hGenome(db)); @@ -1356,31 +1490,31 @@ boolean feelingLucky = cgiBoolean("Lucky") && !allGenomes; char *xType = NULL; if (allGenomes) { db = database; genome = organism; } else getDbAndGenome(cart, &db, &genome, oldVars); char *output = cgiOptionalString("output"); boolean isJson= sameWordOk(output, "json"); boolean isPslRaw= sameWordOk(output, "pslRaw"); -if (!allGenomes && !isJson && !isPslRaw) +if (!feelingLucky && !allGenomes && !isJson && !isPslRaw) cartWebStart(cart, db, "%s (%s) BLAT Results", trackHubSkipHubName(organism), trackHubSkipHubName(db)); seqList = faSeqListFromMemTextRaw(seqLetters); /* Load user sequence and figure out if it is DNA or protein. */ if (sameWord(type, "DNA")) { isTx = FALSE; xType = "dna"; } else if (sameWord(type, "translated RNA")) { isTx = TRUE; isTxTx = TRUE; xType = "rnax"; @@ -1656,31 +1790,31 @@ { gfAlignStrand(conn, serve->nibDir, seq, TRUE, minMatchShown, tFileCache, gvo); } } gfOutputQuery(gvo, f); ++seqNumber; } carefulClose(&f); if (!allGenomes) { showAliPlaces(pslTn.forCgi, faTn.forCgi, NULL, serve->db, qType, tType, organism, feelingLucky); } -if(!allGenomes) +if(!feelingLucky && !allGenomes) cartWebEnd(); gfFileCacheFree(&tFileCache); } void askForSeq(char *organism, char *db) /* Put up a little form that asks for sequence. * Call self.... */ { /* ignore struct serverTable* return, but can error out if not found */ findServer(db, FALSE); /* JavaScript to update form when org changes */ char *onChangeText = "" "document.mainForm.changeInfo.value='orgChange';"