@gmod/bam 7.4.0 → 7.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/util.ts CHANGED
@@ -3,23 +3,11 @@ import { longFromBytesToUnsigned } from './long.ts'
3
3
 
4
4
  import type { Offset, VirtualOffset } from './virtualOffset.ts'
5
5
 
6
- export interface TagFilter {
7
- tag: string
8
- value?: string
9
- }
10
-
11
- export interface FilterBy {
12
- flagInclude?: number
13
- flagExclude?: number
14
- tagFilter?: TagFilter
15
- }
16
-
17
6
  export interface BamOpts {
18
7
  viewAsPairs?: boolean
19
8
  pairAcrossChr?: boolean
20
9
  maxInsertSize?: number
21
10
  signal?: AbortSignal
22
- filterBy?: FilterBy
23
11
  /**
24
12
  * Called as the BGZF blocks covering the query are fetched, with cumulative
25
13
  * downloaded bytes and the total to fetch. Reported at block granularity (one
@@ -249,54 +237,6 @@ export function concatUint8Array(args: Uint8Array[]) {
249
237
  return mergedArray
250
238
  }
251
239
 
252
- export function filterReadFlag(
253
- flags: number,
254
- flagInclude: number,
255
- flagExclude: number,
256
- ) {
257
- return (flags & flagInclude) !== flagInclude || (flags & flagExclude) !== 0
258
- }
259
-
260
- export function filterTagValue(readVal: unknown, filterVal?: string) {
261
- return filterVal === '*'
262
- ? readVal === undefined
263
- : `${readVal}` !== `${filterVal}`
264
- }
265
-
266
- interface Filterable {
267
- flags: number
268
- tags: Record<string, unknown>
269
- // BamRecord decodes one tag by walking the tag block, without building the
270
- // whole tags object. Optional because a custom recordClass need not have it.
271
- getTag?(tag: string): unknown
272
- }
273
-
274
- // Read a single tag, preferring the targeted accessor. Reaching for `tags`
275
- // instead would decode every unrelated tag on the record (NM/AS/ms/de/… — often
276
- // ~10 per read) just to test one, which measured 2.6x the cost of getTag.
277
- function readTag(record: Filterable, tag: string) {
278
- return record.getTag ? record.getTag(tag) : record.tags[tag]
279
- }
280
-
281
- // Apply flagInclude/flagExclude/tagFilter to a list of records.
282
- export function applyFilters<T extends Filterable>(
283
- records: T[],
284
- filterBy: FilterBy,
285
- ): T[] {
286
- const { flagInclude = 0, flagExclude = 0, tagFilter } = filterBy
287
- const out: T[] = []
288
- for (let i = 0, l = records.length; i < l; i++) {
289
- const r = records[i]!
290
- if (
291
- !filterReadFlag(r.flags, flagInclude, flagExclude) &&
292
- !(tagFilter && filterTagValue(readTag(r, tagFilter.tag), tagFilter.value))
293
- ) {
294
- out.push(r)
295
- }
296
- }
297
- return out
298
- }
299
-
300
240
  interface Positioned {
301
241
  ref_id: number
302
242
  start: number