a9f63dc1818dee79f72db4ccaa858581b6f9f5aa
angie
  Mon Mar 3 09:44:02 2014 -0800
Fixed coord-arithmetic bug that caused crash for user in MLQ #12778.refs #12778

diff --git src/hg/lib/gpFx.c src/hg/lib/gpFx.c
index fdbcee1..c4d8811 100644
--- src/hg/lib/gpFx.c
+++ src/hg/lib/gpFx.c
@@ -157,31 +157,31 @@
 	{
 	uint nextExonStart = pred->exonStarts[ii+1];
 	// 'exonIx' is actually an intronIx in this case:
 	if (varStart >= exonEnd && varStart < nextExonStart)
 	    {
 	    txc.startExonIx = ii;
 	    if (varEnd > nextExonStart)
 		{
 		// Variant starts in an intron, but it overlaps the next exon;
 		// note the start in cDNA (and CDS if applicable):
 		txc.startInCdna = exonOffset + exonEnd - exonStart;
 		if (varStart < pred->cdsEnd && varEnd > pred->cdsStart)
 		    {
 		    uint nextExonEnd = pred->exonEnds[ii+1];
 		    if (nextExonEnd > pred->cdsStart)
-			txc.startInCds = cdsOffset;
+			txc.startInCds = cdsOffset + exonCdsSize;
 		    else
 			txc.startInCds = 0;
 		    }
 		}
 	    }
 	if (varEnd > exonEnd && varEnd <= nextExonStart)
 	    {
 	    txc.endExonIx = ii;
 	    if (varStart < exonEnd)
 		{
 		// Variant ends in an intron, but it also overlaps the previous exon;
 		// note the end in cDNA (and CDS if applicable):
 		txc.endInCdna = exonOffset + exonEnd - exonStart;
 		if (varEnd > pred->cdsStart && varStart < pred->cdsEnd)
 		    {
@@ -573,31 +573,33 @@
 	    }
 	else
 	    effect->soNumber = frameshift_variant;
 	}
     else
 	{
 	// Not a deletion; could be single-base (including early stop) or insertion
 	if (newAaSize < oldAaSize)
 	    {
 	    // Not a deletion but protein got smaller; must have been an early stop codon,
 	    // possibly following a frameshift caused by an insertion.
 	    if (cc->aaNew[0] != 'Z')
 		{
 		if (newAa[newAaSize-1] != 'Z')
 		    errAbort("gpFx: new protein is smaller but last base in new sequence "
-			     "is '%c' not 'Z'", newAa[newAaSize-1]);
+			     "is '%c' not 'Z'.\n"
+			     "oldAa (%daa): %s\nnewAa (%daa): %s\n"
+			     , newAa[newAaSize-1], oldAaSize, oldAa, newAaSize, newAa);
 		effect->soNumber = frameshift_variant;
 		}
 	    else
 		effect->soNumber = stop_gained;
 	    }
 	else if (newAaSize > oldAaSize)
 	    {
 	    // protein got bigger; insertion or lost stop codon
 	    if (cc->aaOld[0] == 'Z')
 		effect->soNumber = stop_lost;
 	    else if ((cdsBasesAdded % 3) == 0)
 		effect->soNumber = inframe_insertion;
 	    else
 		effect->soNumber = frameshift_variant;
 	    }