@@ -19,6 +19,7 @@ import { parseAssemblyAndChrSimple } from '../util/parseAssemblyName'
1919
2020import type { RowInstruction } from './rowInstructions'
2121import type { AlignmentRecord , IndexData } from './types'
22+ import type { MafAdapterOptions } from '../types'
2223
2324// Represents a row in the alignment (like Alignment_Row in C)
2425interface RowState {
@@ -159,6 +160,7 @@ export default class BgzipTaffyAdapter extends BaseFeatureDataAdapter {
159160 * parseTafBlocksStreaming (
160161 buffer : Uint8Array ,
161162 runLengthEncodeBases : boolean ,
163+ sampleFilter ?: Set < string > ,
162164 ) : Generator < TafFeature > {
163165 let pBlock : AlignmentBlock | undefined
164166 let currentBlock : AlignmentBlock | undefined
@@ -182,7 +184,7 @@ export default class BgzipTaffyAdapter extends BaseFeatureDataAdapter {
182184 // If we have a current block with columns, finalize and yield it
183185 if ( currentBlock && columns . length > 0 ) {
184186 this . finalizeBlock ( currentBlock , columns )
185- const feature = this . blockToFeature ( currentBlock )
187+ const feature = this . blockToFeature ( currentBlock , sampleFilter )
186188 if ( feature ) {
187189 yield feature
188190 }
@@ -234,7 +236,7 @@ export default class BgzipTaffyAdapter extends BaseFeatureDataAdapter {
234236 // Finalize and yield last block
235237 if ( currentBlock && columns . length > 0 ) {
236238 this . finalizeBlock ( currentBlock , columns )
237- const feature = this . blockToFeature ( currentBlock )
239+ const feature = this . blockToFeature ( currentBlock , sampleFilter )
238240 if ( feature ) {
239241 yield feature
240242 }
@@ -246,8 +248,15 @@ export default class BgzipTaffyAdapter extends BaseFeatureDataAdapter {
246248 buffer : Uint8Array ,
247249 runLengthEncodeBases : boolean ,
248250 _opts ?: BaseOptions ,
251+ sampleFilter ?: Set < string > ,
249252 ) : TafFeature [ ] {
250- return [ ...this . parseTafBlocksStreaming ( buffer , runLengthEncodeBases ) ]
253+ return [
254+ ...this . parseTafBlocksStreaming (
255+ buffer ,
256+ runLengthEncodeBases ,
257+ sampleFilter ,
258+ ) ,
259+ ]
251260 }
252261
253262 // TextDecoder for efficient string building from typed array
@@ -280,7 +289,10 @@ export default class BgzipTaffyAdapter extends BaseFeatureDataAdapter {
280289 }
281290 }
282291
283- blockToFeature ( block : AlignmentBlock ) : TafFeature | undefined {
292+ blockToFeature (
293+ block : AlignmentBlock ,
294+ sampleFilter ?: Set < string > ,
295+ ) : TafFeature | undefined {
284296 if ( block . rows . length === 0 || block . columnNumber === 0 ) {
285297 return undefined
286298 }
@@ -290,6 +302,9 @@ export default class BgzipTaffyAdapter extends BaseFeatureDataAdapter {
290302
291303 for ( const row of block . rows ) {
292304 const { assemblyName, chr } = parseAssemblyAndChrSimple ( row . sequenceName )
305+ if ( sampleFilter && ! sampleFilter . has ( assemblyName ) ) {
306+ continue
307+ }
293308 alignments [ assemblyName ] = {
294309 chr,
295310 start : row . start ,
@@ -392,12 +407,16 @@ export default class BgzipTaffyAdapter extends BaseFeatureDataAdapter {
392407 return entries
393408 }
394409
395- getFeatures ( query : Region , opts ?: BaseOptions ) {
410+ getFeatures ( query : Region , opts ?: MafAdapterOptions ) {
396411 const { statusCallback = ( ) => { } } = opts || { }
397412 return ObservableCreate < Feature > ( async observer => {
398413 try {
399414 const { index, runLengthEncodeBases } = await this . setup ( opts )
400415
416+ const sampleFilter = opts ?. samples
417+ ? new Set ( opts . samples . map ( s => s . id ) )
418+ : undefined
419+
401420 // Get byte range for this query
402421 const records = index [ query . refName ]
403422 if ( ! records || records . length === 0 ) {
@@ -447,6 +466,7 @@ export default class BgzipTaffyAdapter extends BaseFeatureDataAdapter {
447466 for ( const feat of this . parseTafBlocksStreaming (
448467 slice ,
449468 runLengthEncodeBases ,
469+ sampleFilter ,
450470 ) ) {
451471 // Filter features that overlap with query region
452472 if ( feat . end > query . start && feat . start < query . end ) {
0 commit comments