2de160a334786c2168e379c5f02838f4aed40a3b
chmalee
  Thu Jul 27 12:20:35 2023 -0700
Fix two separate hgPcr related bugs. One, the primers entered by the user do not have to match the genome/transcript fully, and so when looking up the primers for showing mismatches we need to ensure we find them by relying on the psl qName rather than the primer file that holds the users input. Second, when clicking through to hgc, ensure that we check that the tStart and tEnd of the psl match what was clicked on so the right amplicon sequence can be shown, in the case that two separate searches that hit the same transcript are visible, refs #31784

diff --git src/hg/hgTracks/cds.c src/hg/hgTracks/cds.c
index 47a2aed..79bfd4f 100644
--- src/hg/hgTracks/cds.c
+++ src/hg/hgTracks/cds.c
@@ -962,34 +962,50 @@
 #else
 return NULL;
 #endif
 }
 
 #ifndef GBROWSE
 static struct dnaSeq *maybeGetPcrResultSeq(struct linkedFeatures *lf)
 /* Return (if possible) the primer sequences concatenated with the 
  * target sequence between where they match. */
 {
 struct dnaSeq *seq = NULL;
 char *pslFileName, *primerFileName;
 struct targetDb *target;
 if (! pcrResultParseCart(database, cart, &pslFileName, &primerFileName, &target))
     return NULL;
-char *fPrimer=NULL, *rPrimer=NULL, *nonCompRPrimer;
+char *fPrimer = NULL, *rPrimer = NULL, *nonCompRPrimer = NULL;
 char *primerKey = NULL;
 if (lf->original)
-    primerKey = ((struct psl *)lf->original)->qName;
+    {
+    // we can use the qName to extract the primer sequence, which
+    // may be different from the primers the user pasted in!
+    struct psl *psl = (struct psl *)lf->original;
+    fPrimer = cloneString(psl->qName);
+    char *under = strchr(fPrimer, '_');
+    if (under)
+        *under = 0;
+    else
+        {
+        errAbort("Badly formatted qName ('%s', missing '_' character. "
+            "Please send an email to genome-www@soe.ucsc.edu with the assembly, "
+            "forward and reverse primers, and other PCR settings.", psl->qName);
+        }
+    rPrimer = under + 1;
+    }
+else
     pcrResultGetPrimers(primerFileName, &fPrimer, &rPrimer, primerKey);
 if ((fPrimer == NULL) || (rPrimer == NULL))
         return NULL;
 int fPrimerSize = strlen(fPrimer);
 int rPrimerSize = strlen(rPrimer);
 // we need to reverse complement the sequence for the display, but we
 // don't want to when we do the lookup in the psl file
 nonCompRPrimer = cloneString(rPrimer);
 reverseComplement(rPrimer, rPrimerSize);
 if (lf->name && isNotEmpty(lf->name))
     {
     struct psl *tpsl;
     char *words[3];
     int wordCount = chopByChar(cloneString(lf->extra), '|', words, ArraySize(words));
     if (wordCount != 3)