0758b8011d2e5723d7eff91ceb6d8f9629f1f3f3 angie Thu Apr 17 06:59:42 2014 -0700 When an insertion falls at the end of CDS, fetchCodons looks aheadto the next exon. However, when this happens in the last exon, there is no next exon so gene->chromStarts[i+1] is past the end of the array. Fix: make sure i+1 is a valid index before looking at the next exon. fixes #13089 diff --git src/hg/lib/pgSnp.c src/hg/lib/pgSnp.c index 14d96db..e635f60 100644 --- src/hg/lib/pgSnp.c +++ src/hg/lib/pgSnp.c @@ -294,58 +294,61 @@ else { /* minus strand coding start == chromEnd */ cEnd = gene->chromStart + gene->chromStarts[i] + gene->blockSizes[i] - (st - codStart + 1); cStart = gene->chromStart + gene->chromStarts[i] + gene->blockSizes[i] - (end - codStart + 1); } //printf("TESTING fetching sequence for %s:%d-%d\n", gene->chrom, cStart, cEnd); if (cStart < cEnd) { struct dnaSeq *s = hDnaFromSeq(db, gene->chrom, cStart, cEnd, dnaUpper); dyStringPrintf(seq, "%s", s->dna); //printf("TESTING got seq=%s<br>\n", s->dna); //freeDnaSeq(&s); } /* check following exons, chrom order */ + if (i+1 < gene->blockCount) + { if (posStrand && rv->cdEnd >= codStart + gene->blockSizes[i]) { int st = codStart + gene->blockSizes[i] + 1; int end = rv->cdEnd; cStart = gene->chromStart + gene->chromStarts[i+1] - 1; cEnd = gene->chromStart + gene->chromStarts[i+1] + (end - st + 1); if (cStart < cEnd) { struct dnaSeq *s = hDnaFromSeq(db, gene->chrom, cStart, cEnd, dnaUpper); dyStringPrintf(seq, "%s", s->dna); //freeDnaSeq(&s); } } else if (!posStrand && rv->cdStart < (codStart - 1)) { int st = rv->cdStart; int end = codStart - 1; cStart = gene->chromStart + gene->chromStarts[i+1]; cEnd = gene->chromStart + gene->chromStarts[i+1] + (end - st); //printf("TESTING fetching sequence for %s:%d-%d\n", gene->chrom, cStart, cEnd); if (cStart < cEnd) { struct dnaSeq *s = hDnaFromSeq(db, gene->chrom, cStart, cEnd, dnaUpper); dyStringPrintf(seq, "%s", s->dna); //freeDnaSeq(&s); //printf("TESTING got seq=%s<br>\n", s->dna); } } + } rv->seq = dyStringCannibalize(&seq); break; } /* increment values past this exon */ codNum += trunc((gene->blockSizes[i] - frame) / 3); if (frame > 0) codNum++; cPos += gene->blockSizes[i]; frame = 3 - ((gene->blockSizes[i] - frame) % 3); } if (rv->seq == NULL) return NULL; /* not found */ return rv; } char *replaceString(char *old, int from, int to, char *rep) @@ -410,31 +413,31 @@ for (el = th; el != NULL; el = el->next) { struct pgCodon *cod = fetchCodons(db, el, item->chromStart, item->chromEnd); if (cod == NULL) continue; /* not in exon */ if (found == 0) printf("\n<BR>Coding sequence changes are relative to strand of transcript:<BR>\n"); found++; if (sameString(el->strand, "-")) reverseComplement(cod->seq, strlen(cod->seq)); /* bold changing seq */ char old[512]; strncpy(old, cod->seq+(cod->regStart - cod->cdStart), (cod->regEnd - cod->regStart)); old[cod->regEnd - cod->regStart] = '\0'; char b[512]; - safef(b, sizeof(b), "<B>%s</B>", old); + safef(b, sizeof(b), "<B>%s</B>", isEmpty(old) ? "-" : old); char *bold = replaceString(cod->seq, (cod->regStart - cod->cdStart), (cod->regEnd - cod->cdStart), b); char *nameCopy = cloneString(item->name); char *allele[8]; (void) chopByChar(nameCopy, '/', allele, item->alleleCount); int i; printf("%s:starting positions codon %d cds %d<BR>\n", el->name, cod->firstCodon, (cod->cdStart+1)); for (i=0;i<item->alleleCount;i++) { char a[512]; if (sameString(el->strand, "-")) reverseComplement(allele[i], strlen(allele[i])); safef(a, sizeof(a), "<B>%s</B>", allele[i]); char *rep = replaceString(cod->seq, (cod->regStart - cod->cdStart), (cod->regEnd - cod->cdStart), a); if (sameString(bold, rep)) continue;