11import { AnnotationFeature } from '@apollo-annotation/mst'
22import { splitStringIntoChunks } from '@apollo-annotation/shared'
3- import { revcom } from '@jbrowse/core/util'
3+ import { defaultCodonTable , revcom } from '@jbrowse/core/util'
44import {
55 Button ,
66 MenuItem ,
@@ -18,7 +18,7 @@ import { ApolloSessionModel } from '../session'
1818const SEQUENCE_WRAP_LENGTH = 60
1919
2020type SegmentType = 'upOrDownstream' | 'UTR' | 'CDS' | 'intron' | 'protein'
21- type SegmentListType = 'CDS' | 'cDNA' | 'genomic'
21+ type SegmentListType = 'CDS' | 'cDNA' | 'genomic' | 'protein'
2222
2323interface 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