Skip to content

Commit e32b415

Browse files
Add protein sequence to transcript detail panel (#486)
* add protein sequence * fix lint
1 parent 76ac734 commit e32b415

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptSequence.tsx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { AnnotationFeature } from '@apollo-annotation/mst'
22
import { splitStringIntoChunks } from '@apollo-annotation/shared'
3-
import { revcom } from '@jbrowse/core/util'
3+
import { defaultCodonTable, revcom } from '@jbrowse/core/util'
44
import {
55
Button,
66
MenuItem,
@@ -18,7 +18,7 @@ import { ApolloSessionModel } from '../session'
1818
const SEQUENCE_WRAP_LENGTH = 60
1919

2020
type SegmentType = 'upOrDownstream' | 'UTR' | 'CDS' | 'intron' | 'protein'
21-
type SegmentListType = 'CDS' | 'cDNA' | 'genomic'
21+
type SegmentListType = 'CDS' | 'cDNA' | 'genomic' | 'protein'
2222

2323
interface SequenceSegment {
2424
type: SegmentType
@@ -121,6 +121,28 @@ function getSequenceSegments(
121121
segments.push({ type: 'CDS', sequenceLines, locs })
122122
return segments
123123
}
124+
case 'protein': {
125+
let wholeSequence = ''
126+
const [firstLocation] = cdsLocations
127+
const locs: { min: number; max: number }[] = []
128+
for (const loc of firstLocation) {
129+
let sequence = getSequence(loc.min, loc.max)
130+
if (strand === -1) {
131+
sequence = revcom(sequence)
132+
}
133+
wholeSequence += sequence
134+
locs.push({ min: loc.min, max: loc.max })
135+
}
136+
let protein = ''
137+
for (let i = 0; i < wholeSequence.length; i += 3) {
138+
const codonSeq: string = wholeSequence.slice(i, i + 3).toUpperCase()
139+
protein +=
140+
defaultCodonTable[codonSeq as keyof typeof defaultCodonTable] || '&'
141+
}
142+
const sequenceLines = splitStringIntoChunks(protein, SEQUENCE_WRAP_LENGTH)
143+
segments.push({ type: 'protein', sequenceLines, locs })
144+
return segments
145+
}
124146
}
125147
}
126148

@@ -238,6 +260,7 @@ export const TranscriptSequence = observer(function TranscriptSequence({
238260
<MenuItem value="CDS">CDS</MenuItem>
239261
<MenuItem value="cDNA">cDNA</MenuItem>
240262
<MenuItem value="genomic">Genomic</MenuItem>
263+
<MenuItem value="protein">Protein</MenuItem>
241264
</Select>
242265
<Paper
243266
style={{

0 commit comments

Comments
 (0)