Skip to content

Commit

Permalink
fixup: handle ? end
Browse files Browse the repository at this point in the history
  • Loading branch information
phildarnowsky-broad committed Aug 14, 2023
1 parent 26f5ccb commit 4157bab
Show file tree
Hide file tree
Showing 3 changed files with 442 additions and 12 deletions.
41 changes: 41 additions & 0 deletions browser/src/ClinvarVariantsTrack/ClinvarAllVariantsPlot.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,5 +290,46 @@ describe('ClinvarAllVariantsPlot', () => {
expect(() => plotLayoutMatches(expectedPlotLayout, plotBody)).not.toThrowError()
expect(tree).toMatchSnapshot()
})

test('clamps end to end of the downstream UTR when the end in the HGVSP is "?"', () => {
const variant = { ...baseVariant, hgvsp: 'p.Tyr30SerfsTer?' }
const tree = render(
<ClinvarAllVariantsPlot
scalePosition={scalePosition}
transcripts={[transcript]}
variants={[variant]}
width={width}
onClickVariant={onClickVariant}
/>
).asFragment()
const plotBody = extractPlotFragment(tree)

const plotLayouts: Record<Strand, PlotLayoutElement[]> = {
'+': [
['overlay', 310, 822 - 310],
['cds', 310, 322],
['utr', 322, 423],
['cds', 423, 522],
['utr', 522, 623],
['cds', 623, 722],
['utr', 723, 822],
['stop_marker', 822],
],
'-': [
['overlay', 123, 635 - 123],
['utr', 123, 222],
['cds', 223, 322],
['utr', 322, 423],
['cds', 423, 522],
['utr', 522, 623],
['cds', 623, 635],
['stop_marker', 123],
],
}
const expectedPlotLayout = plotLayouts[strand]

expect(() => plotLayoutMatches(expectedPlotLayout, plotBody)).not.toThrowError()
expect(tree).toMatchSnapshot()
})
})
})
21 changes: 9 additions & 12 deletions browser/src/ClinvarVariantsTrack/ClinvarAllVariantsPlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,32 +46,29 @@ const getGlobalFrameshiftCoordinates = (
const codingAndDownstreamExons = exons.slice(
exons.findIndex((exon: Exon) => exon.feature_type === 'CDS')
)
const codingRegionStart =
transcript.strand === '+' ? codingAndDownstreamExons[0].start : codingAndDownstreamExons[0].stop

// Termination site position may be "?" if the new reading frame does not encounter a stop codon
// In this case, place the termination site at the end of the transcript
const lastExon = codingAndDownstreamExons[codingAndDownstreamExons.length - 1]
const transcriptEnd = transcript.strand === '+' ? lastExon.stop : lastExon.start

// Codon numbers are 1 indexed
const startOffsetFromCDS = position * 3 - 2

const { remainingIntervals, globalCoordinate: startCoordinate } = advanceOverIntervals(
codingAndDownstreamExons,
startOffsetFromCDS,
transcript.strand
)
if (terminationSitePosition === '?') {
return [codingRegionStart, transcriptEnd]
return [startCoordinate || transcriptEnd, transcriptEnd]
}

// Offset in bases from the start of the transcript's CDS region to the termination site
// Codon numbers are 1 indexed
const startOffsetFromCDS = position * 3 - 2
// The extra "+2" at the end is because we start at the first nucleotide of
// the first codon, and end with the last nucleotide (rather than the first)
// of some downstream codon.
const lengthInNucleotides = (Number(terminationSitePosition) - 1) * 3 + 2

// Both ends should always fall within an exon
const { remainingIntervals, globalCoordinate: startCoordinate } = advanceOverIntervals(
codingAndDownstreamExons,
startOffsetFromCDS,
transcript.strand
)
const { globalCoordinate: endCoordinate } = advanceOverIntervals(
remainingIntervals,
lengthInNucleotides,
Expand Down
Loading

0 comments on commit 4157bab

Please sign in to comment.