97f63a83a92ff45375df118f75e0f1323897d594
kent
  Thu Jul 2 12:54:57 2015 -0700
Think I fixed #15643

diff --git src/jkOwnLib/gfPcrLib.c src/jkOwnLib/gfPcrLib.c
index da8fcdb..1f0934a 100644
--- src/jkOwnLib/gfPcrLib.c
+++ src/jkOwnLib/gfPcrLib.c
@@ -294,55 +294,56 @@
     output = outputPsl;
 else
     errAbort("Unrecognized pcr output type %s", outType);
 return output;
 }
 
 void gfPcrOutputWriteList(struct gfPcrOutput *outList, char *outType, 
 	char *url, FILE *f)
 /* Write list of outputs in specified format (either "fa" or "bed") 
  * to file.  If url is non-null it should be a printf formatted
  * string that takes %s, %d, %d for chromosome, start, end. */
 {
 outFunction output = gfPcrOutputFunction(outType);
 struct gfPcrOutput *out;
 for (out = outList; out != NULL; out = out->next)
+    {
     output(out, f, url);
     }
+}
 
 void gfPcrOutputWriteOne(struct gfPcrOutput *out, char *outType, 
 	char *url, FILE *f)
 /* Write a single output in specified format (either "fa" or "bed") 
  * to file.  If url is non-null it should be a printf formatted
  * string that takes %s, %d, %d for chromosome, start, end. */
 {
 outFunction output = gfPcrOutputFunction(outType);
 output(out, f, url);
 }
 
 void gfPcrOutputWriteAll(struct gfPcrOutput *outList, 
 	char *outType, char *url, char *fileName)
 /* Create file of outputs in specified format (either "fa" or "bed") 
  * to file.  If url is non-null it should be a printf formatted
  * string that takes %s, %d, %d for chromosome, start, end. */
 {
 FILE *f = mustOpen(fileName, "w");
 gfPcrOutputWriteList(outList, outType, url, f);
 carefulClose(&f);
 }
 
-
 static void pcrLocalStrand(char *pcrName, 
 	struct dnaSeq *seq,  int seqOffset, char *seqName, int seqSize,
 	int maxSize, char *fPrimer, int fPrimerSize, char *rPrimer, int rPrimerSize,
 	int minPerfect, int minGood,
 	char strand, struct gfPcrOutput **pOutList)
 /* Do detailed PCR scan on one strand and report results. */
 {
 char *fDna = seq->dna, *rDna;
 char *endDna = fDna + seq->size;
 char *fpPerfect = fPrimer + fPrimerSize - minPerfect;
 char *rpPerfect = rPrimer;
 char *fpMatch, *rpMatch;
 int goodSize = minGood - minPerfect;
 struct gfPcrOutput  *out;
 int matchSize;
@@ -376,69 +377,68 @@
 	    {
 	    rTrim = rPos - seq->size;
 	    rPos = seq->size;
 	    }
 	else
 	    rTrim = 0;
 
 	fGoodPos = fpMatch - goodSize - seq->dna;
 	rGoodPos = rpMatch + minPerfect - seq->dna;
 
 	fGoodPos = max(fGoodPos, 0);
 	rGoodPos = min(rGoodPos, seq->size);
 
 	matchSize = rPos - fPos;
 
-	int fGoodSize = fGoodPos - fPos;
+	int fGoodSize = fpMatch - (seq->dna + fGoodPos);
 	int rGoodSize = rPos - rGoodPos;
-	fGoodSize = min(fGoodSize, goodSize);
-	rGoodSize = min(rGoodSize, goodSize);
-
+	if (rGoodSize >= goodSize && fGoodSize >= goodSize)
+	    {
 	    if (rPos >= 0 && fPos >= 0 && fPos < seq->size && matchSize <= maxSize)
 		{
 		/* If matches well enough create output record. */
 		if (goodMatch(seq->dna + fGoodPos, fpPerfect - fGoodSize, fGoodSize) &&
 		    goodMatch(seq->dna + rGoodPos, rpPerfect + minPerfect, rGoodSize))
 		    {
-
 		    /* Truncate the copy of the primers going into the out-> record using rTrim and fTrim if needed. */
 		    AllocVar(out);
 		    out->name  = cloneString(pcrName);
 		    out->fPrimer = cloneString(fPrimer + fTrim);
 		    out->rPrimer = cloneStringZ(rPrimer, rPrimerSize - rTrim);
 		    reverseComplement(out->rPrimer, rPrimerSize - rTrim);
 		    out->seqName = cloneString(seqName);
 		    out->seqSize = seqSize;
 		    out->fPos = fPos + seqOffset;
 		    out->rPos = rPos + seqOffset;
 		    out->strand = strand;
 		    out->dna = cloneStringZ(seq->dna + fPos, matchSize);
 		    
 
 		    /* Dealing with the strand of darkness....  Here we just have to swap
 		     * forward and reverse primers to flip strands, and reverse complement
 		     * the amplified area.. */
 		    if (strand == '-')
 			{
 			char *temp = out->rPrimer;
 			out->rPrimer = out->fPrimer;
 			out->fPrimer = temp;
 			reverseComplement(out->dna, matchSize);
 			}
 		    slAddHead(pOutList, out);
 		    }
 		}
+	    }
 	rDna = rpMatch+1;
 	}
     fDna = fpMatch + 1;
     }
 reverseComplement(rPrimer, rPrimerSize);
 }
 
 void gfPcrLocal(char *pcrName, 
 	struct dnaSeq *seq, int seqOffset, char *seqName, int seqSize,
 	int maxSize, char *fPrimer, int fPrimerSize, char *rPrimer, int rPrimerSize,
 	int minPerfect, int minGood, char strand, struct gfPcrOutput **pOutList)
 /* Do detailed PCR scan on DNA already loaded into memory and put results
  * (in reverse order) on *pOutList. */
 {
 /* For PCR primers reversing search strand just means switching