@@ -77,18 +77,14 @@ export function processFeaturesToFasta({
7777 let insertionSequence = ''
7878 while ( i < alignment . length && seq [ i ] === '-' ) {
7979 const alignChar = alignment [ i ] !
80- insertionSequence +=
81- alignChar !== '-' && alignChar !== ' '
82- ? alignChar . toLowerCase ( )
83- : '-'
80+ if ( alignChar !== '-' && alignChar !== ' ' ) {
81+ insertionSequence += alignChar . toLowerCase ( )
82+ }
8483 i ++
8584 }
8685 i --
8786
88- // Only add insertion if it contains at least one actual base (not
89- // just gaps). This filters out insertions that only exist in samples
90- // that aren't currently visible.
91- if ( insertionSequence . length > 0 && / [ ^ - ] / . test ( insertionSequence ) ) {
87+ if ( insertionSequence . length > 0 ) {
9288 const insertPos = leftCoord + o - region . start
9389 if ( insertPos >= 0 && insertPos <= rlen ) {
9490 const existing = insertionsAtPosition . get ( insertPos ) || [ ]
@@ -150,14 +146,15 @@ function expandWithInsertions(
150146 const insertionSeq = sampleInsertions . get ( sampleIdx )
151147
152148 if ( insertionSeq ) {
153- // This sample has an insertion - add it, padded with gaps if needed
154149 const paddedInsertion = insertionSeq . padEnd ( maxLen , '-' )
155- // Insert after position `pos`
156- rowArray . splice ( pos , 0 , ...paddedInsertion . split ( '' ) )
150+ const chars = paddedInsertion . split ( '' )
151+ for ( let k = chars . length - 1 ; k >= 0 ; k -- ) {
152+ rowArray . splice ( pos , 0 , chars [ k ] ! )
153+ }
157154 } else {
158- // No insertion for this sample - fill with gaps
159- const gaps = new Array ( maxLen ) . fill ( '-' )
160- rowArray . splice ( pos , 0 , ... gaps )
155+ for ( let k = 0 ; k < maxLen ; k ++ ) {
156+ rowArray . splice ( pos , 0 , '-' )
157+ }
161158 }
162159 }
163160 }
0 commit comments