957e6639419c3faf3ca76d891903ea3023681555 kent Tue Jun 28 18:02:27 2022 -0700 Making 'View details of parts of alignment within browser window.' link on bigPsl and psl work better when query sequence is big. diff --git src/hg/hgc/hgc.c src/hg/hgc/hgc.c index 0c22794..6dc9a51 100644 --- src/hg/hgc/hgc.c +++ src/hg/hgc/hgc.c @@ -6435,31 +6435,30 @@ /* Print list of mRNA alignments with special "in window" alignment function. */ { if (pslList == NULL || tableName == NULL) return; printAlignmentsSimple(pslList, startFirst, hgcCommand, tableName, itemIn); struct psl *psl = pslList; for (psl = pslList; psl != NULL; psl = psl->next) { if ( pslTrimToTargetRange(psl, winStart, winEnd) != NULL && !startsWith("xeno", tableName) && !(startsWith("user", tableName) && pslIsProtein(psl)) && psl->tStart == startFirst && sameString(psl->tName, seqName) - && psl->qSize <= MAX_DISPLAY_QUERY_SEQ_SIZE ) { char otherString[512]; safef(otherString, sizeof(otherString), "%d&aliTable=%s", psl->tStart, tableName); hgcAnchorSomewhere(hgcCommandInWindow, itemIn, otherString, psl->tName); printf("
View details of parts of alignment within browser window.
\n"); } } } void printAlignments(struct psl *pslList, int startFirst, char *hgcCommand, char *tableName, char *itemIn) /* Print list of mRNA alignments. */ { @@ -7530,31 +7529,31 @@ fprintf(f, "

Alignment of %s and %s:%d-%d

\n", psl->qName, psl->tName, psl->tStart+1, psl->tEnd); else fprintf(f, "

Alignment of %s and %s:%d-%d

\n", qName, psl->tName, psl->tStart+1, psl->tEnd); fputs("Click on links in the frame to the left to navigate through " "the alignment.\n", f); blockCount = pslShowAlignment(psl, qType == gftProt, qName, qSeq, qStart, qEnd, tName, tSeq, tStart, tEnd, f); freeDnaSeq(&tSeq); return blockCount; } -struct ffAli *pslToFfAliAndSequence(struct psl *psl, struct dnaSeq *qSeq, +static struct ffAli *pslToFfAliAndSequence(struct psl *psl, struct dnaSeq *qSeq, boolean *retIsRc, struct dnaSeq **retSeq, int *retTStart) /* Given psl, dig up target sequence and convert to ffAli. * Note: if strand is -, this does a pslRc to psl! */ { int tStart, tEnd, tRcAdjustedStart; struct dnaSeq *dnaSeq; tStart = psl->tStart - 100; if (tStart < 0) tStart = 0; if (retTStart) *retTStart = tStart; tEnd = psl->tEnd + 100; if (tEnd > psl->tSize) tEnd = psl->tSize; @@ -7569,75 +7568,101 @@ if (psl->strand[1] == '-') pslRc(psl); if (psl->strand[0] == '-') { if (retIsRc) *retIsRc = TRUE; reverseComplement(dnaSeq->dna, dnaSeq->size); pslRc(psl); tRcAdjustedStart = psl->tSize - tEnd; } return pslToFfAli(psl, qSeq, dnaSeq, tRcAdjustedStart); } +static void ffStartEndQ(char *qDna, struct ffAli *ff, int *retStartQ, int *retEndQ) +/* Return query start and end */ +{ +if (ff == NULL) + *retStartQ = *retEndQ = 0; +else + { + struct ffAli *right = ffRightmost(ff); + *retStartQ = ff->nStart - qDna; + *retEndQ = right->nEnd - qDna; + } +} + int showPartialDnaAlignment(struct psl *wholePsl, struct dnaSeq *rnaSeq, FILE *body, int cdsS, int cdsE, boolean restrictToWindow) /* Show (part of) alignment for accession. wholePsl is the whole alignment; * if restrictToWindow then display the part of the alignment in the current * browser window. */ { +/* Do a consistency check between rnaSeq and psl*/ +int rnaSize = rnaSeq->size; +if (rnaSize != wholePsl->qSize) + { + fprintf(body, "

Cannot display alignment. Size of rna %s is %d has changed since alignment was performed when it was %d.\n", + wholePsl->qName, rnaSize, wholePsl->qSize); + return 0; + } + +/* Possibly just do smaller subset that is within window. */ +struct psl *psl = wholePsl; +if (restrictToWindow) + { + psl = pslTrimToTargetRange(wholePsl, winStart, winEnd); + if (psl == NULL) + fprintf(body, "

No alignment of %s within browser window.", wholePsl->qName); + } + struct dnaSeq *dnaSeq; int wholeTStart; -int partTStart = wholePsl->tStart, partTEnd = wholePsl->tEnd; -DNA *rna; -int rnaSize; +int partTStart = psl->tStart, partTEnd = psl->tEnd; +DNA *rna = rnaSeq->dna; boolean isRc = FALSE; -struct ffAli *wholeFfAli; +struct ffAli *ffAli; int blockCount; -/* Get RNA sequence and convert psl to ffAli. */ -rna = rnaSeq->dna; -rnaSize = rnaSeq->size; - -/* Don't forget -- this may change wholePsl! */ -wholeFfAli = pslToFfAliAndSequence(wholePsl, rnaSeq, &isRc, &dnaSeq, +/* Don't forget -- this may change psl if on reverse strand! */ +ffAli = pslToFfAliAndSequence(psl, rnaSeq, &isRc, &dnaSeq, &wholeTStart); +int rnaStart = 0; +int rnaEnd = rnaSize; + if (restrictToWindow) { - partTStart = max(wholePsl->tStart, winStart); - partTEnd = min(wholePsl->tEnd, winEnd); + /* Find start/end in ffAli, which is clipped to target from PSL and maybe RC'd */ + ffStartEndQ(rna, ffAli, &rnaStart, &rnaEnd); + + /* Add 100 bases either side if possible */ + if (rnaStart >= 100) rnaStart -= 100; + if (rnaEnd + 100 <= rnaSize) rnaEnd += 100; } /* Write body heading info. */ fprintf(body, "

Alignment of %s and %s:%d-%d

\n", - wholePsl->qName, wholePsl->tName, partTStart+1, partTEnd); + psl->qName, psl->tName, partTStart+1, partTEnd); fprintf(body, "Click on links in the frame to the left to navigate through " "the alignment.\n"); -if (rnaSize != wholePsl->qSize) - { - fprintf(body, "

Cannot display alignment. Size of rna %s is %d has changed since alignment was performed when it was %d.\n", - wholePsl->qName, rnaSize, wholePsl->qSize); - return 0; - } - -blockCount = ffShAliPart(body, wholeFfAli, wholePsl->qName, - rna, rnaSize, 0, +blockCount = ffShAliPart(body, ffAli, wholePsl->qName, + rna + rnaStart, rnaEnd - rnaStart, rnaStart, dnaSeq->name, dnaSeq->dna, dnaSeq->size, wholeTStart, 8, FALSE, isRc, FALSE, TRUE, TRUE, TRUE, TRUE, cdsS, cdsE, partTStart, partTEnd); return blockCount; } void showSomeAlignment(struct psl *psl, bioSeq *oSeq, enum gfType qType, int qStart, int qEnd, char *qName, int cdsS, int cdsE) /* Display protein or DNA alignment in a frame. */ { int blockCount, i; struct tempName indexTn, bodyTn; FILE *index, *body;