48755201e4f1fe10901961cfdce5cc6caad8cdba
braney
  Wed May 13 15:56:50 2015 -0700
make genePredToGtf put out the right exon number for start and stop
codons refs #15216

diff --git src/hg/genePredToGtf/genePredToGtf.c src/hg/genePredToGtf/genePredToGtf.c
index 51fd547..98cb8e6 100644
--- src/hg/genePredToGtf/genePredToGtf.c
+++ src/hg/genePredToGtf/genePredToGtf.c
@@ -216,35 +216,38 @@
         break;
     }
 if (iExon == gp->exonCount)
     return zeroCodonCoords;  // no CDS
 
 // get frame and validate that we are on a bound.
 int frame = (gp->strand[0] == '+') ? frames[iExon]
     : frameIncr(frames[iExon], (cdsEnd-cdsStart));
 if (frame != 0)
     return zeroCodonCoords;  // not on a frame boundary
 
 /* get first part of codon */
 struct codonCoords codon = zeroCodonCoords;
 codon.start= codon.start1 = cdsStart;
 codon.end = codon.end1 = codon.start1 + min(cdsEnd-cdsStart, 3);
+codon.iExon1 = iExon;
 
 /* second part, if spliced */
 if ((codon.end1 - codon.start1) < 3)
     {
+    codon.iExon2 = iExon;
     iExon++;
+    codon.iExon1 = iExon;
     if ((iExon == gp->exonCount) || !genePredCdsExon(gp, iExon, &cdsStart, &cdsEnd))
         return zeroCodonCoords;  // no more
     int needed = 3 - (codon.end1 - codon.start1);
     if ((cdsEnd - cdsStart) < needed)
         return zeroCodonCoords;  // not enough space
     codon.start2 = cdsStart;
     codon.end = codon.end2 = codon.start2 + needed;
     }
 return codon;
 }
 
 static struct codonCoords findLastCodon(struct genePred *gp, int *frames)
 /* get the coordinates of the last codon (start or stop). It must be in
  * correct frame, or zero is returned. */
 {
@@ -260,37 +263,40 @@
         break;
     }
 if (iExon == -1)
     return zeroCodonCoords;  // no CDS
 
 // get frame of last base and validate that we are on a bound.
 int frame = (gp->strand[0] == '-') ? frames[iExon]
     : frameIncr(frames[iExon], (cdsEnd-cdsStart));
 if (frame != 0)
     return zeroCodonCoords;  // not on a frame boundary
 
 /* get last part of codon */
 struct codonCoords codon = zeroCodonCoords;
 codon.start= codon.start1 = max(cdsStart, cdsEnd-3);
 codon.end = codon.end1 = cdsEnd;
+codon.iExon1 = iExon;
 
 /* first part, if spliced */
 if ((codon.end1 - codon.start1) < 3)
     {
     codon.start2 = codon.start1;
     codon.end = codon.end2 = codon.end1;
+    codon.iExon2 = iExon;
     iExon--;
+    codon.iExon1 = iExon;
     if ((iExon == -1) || !genePredCdsExon(gp, iExon, &cdsStart, &cdsEnd))
         return zeroCodonCoords;  // no more
     int needed = 3 - (codon.end2 - codon.start2);
     if ((cdsEnd - cdsStart) < needed)
         return zeroCodonCoords;  // not enough space
     codon.start = codon.start1 = cdsEnd-needed;
     codon.end1 = cdsEnd;
     }
 return codon;
 }
 
 static int *calcFrames(struct genePred *gp)
 /* compute frames for a genePred the doesn't have them.  Free resulting array */
 {
 int *frames = needMem(gp->exonCount*sizeof(int));