523148e24cfe92f07c9401bfb8d7f192452abb48
markd
  Mon Aug 3 18:40:09 2015 -0700
fixed problem with previous change to deal with query inserts #15803

diff --git src/hg/lib/genePred.c src/hg/lib/genePred.c
index 373fa8a..dc3f4bd 100644
--- src/hg/lib/genePred.c
+++ src/hg/lib/genePred.c
@@ -1190,31 +1190,31 @@
     }
 
 iExon = -1;  /* indicate none have been added */
 unsigned prevQEnd = 0;
 unsigned prevTEnd = 0;
 for (iBlk = startIdx; iBlk != stopIdx; iBlk += idxIncr)
     {
     int qStart = psl->qStarts[iBlk];
     int qEnd = qStart + psl->blockSizes[iBlk];
     if (psl->strand[0] == '-')
         reverseIntRange(&qStart, &qEnd, psl->qSize);
     int tStart = psl->tStarts[iBlk];
     int tEnd = tStart + psl->blockSizes[iBlk];
     if (psl->strand[1] == '-')
         reverseIntRange(&tStart, &tEnd, psl->tSize);
-    if ((iExon == 0) || !shouldMergeBlocks(gene, tStart, prevTEnd, qStart, prevQEnd, options,
+    if ((iExon < 0) || !shouldMergeBlocks(gene, tStart, prevTEnd, qStart, prevQEnd, options,
                                           cdsMergeSize, utrMergeSize))
         {
         /* new exon */
         iExon++;
         gene->exonStarts[iExon] = tStart;
 	}
     gene->exonEnds[iExon] = tEnd;
     /* Set the frame. We have to deal with multiple blocks being merged.  For
      * positive strand, the first block frame is used, for negative strand,
      * the last is used. */
     if ((gene->optFields & genePredExonFramesFld) && (cds != NULL)
         && (((psl->strand[0] == '+') && (gene->exonFrames[iExon] < 0))
             || (psl->strand[0] == '-')))
 	{
         int fr = getFrame(psl, psl->qStarts[iBlk], psl->qStarts[iBlk]+psl->blockSizes[iBlk], cds);
@@ -1580,36 +1580,41 @@
     gpError(errFh, &errorCnt, "%s: %s chrom not a valid chromosome: \"%s\"", desc, gp->name, gp->chrom);
 else if (chromSize > 0)
     {
     if (gp->txEnd > chromSize)
         gpError(errFh, &errorCnt, "%s: %s txEnd %u >= chromSize %u", desc, gp->name, gp->txEnd, chromSize);
     }
 
 /* check internal consistency */
 if (gp->txStart >= gp->txEnd)
     gpError(errFh, &errorCnt, "%s: %s txStart %u >= txEnd %u", desc, gp->name, gp->txStart, gp->txEnd);
 
 /* no CDS is indicated by cdsStart == cdsEnd */
 if (gp->cdsStart != gp->cdsEnd)
     checkCdsBounds(errFh, &errorCnt, desc, gp);
 
+/* must be at least one exon */
+if (gp->exonCount == 0)
+    gpError(errFh, &errorCnt, "%s: %s contains no exons", desc, gp->name);
+else
+    {
 /* make sure first/last exons match tx range */
     if (gp->txStart != gp->exonStarts[0])
         gpError(errFh, &errorCnt, "%s: %s first exon start %u doesn't match txStart %u", desc, gp->name, gp->exonStarts[0], gp->txStart);
     if (gp->txEnd != gp->exonEnds[gp->exonCount-1])
         gpError(errFh, &errorCnt, "%s: %s last exon end %u doesn't match txEnd %u", desc, gp->name, gp->exonEnds[gp->exonCount-1], gp->txEnd);
-
+    }
 
 /* check each exon */
 for (iExon = 0; iExon < gp->exonCount; iExon++)
     checkExon(errFh, &errorCnt, desc, gp, iExon);
 
 return errorCnt;
 }
 
 static int lookupChromSize(char *desc, FILE* errFh, char* db, struct genePred* gp, int *errorCnt)
 /* lookup the chromosome size in the database, -1 if invalid */
 {
 // hGetChromInfo is case independent
 struct chromInfo *ci = hGetChromInfo(db, gp->chrom);
 if (ci == NULL)
     {