UNPKG

@gmod/bam

Version:

Parser for BAM and BAM index (bai) files

92 lines (91 loc) 3.21 kB
import QuickLRU from '@jbrowse/quick-lru'; import BAI from './bai.ts'; import CSI from './csi.ts'; import BAMFeature from './record.ts'; import type Chunk from './chunk.ts'; import type { Bytes } from './record.ts'; import type { BamOpts, BaseOpts } from './util.ts'; import type { GenericFilehandle } from 'generic-filehandle2'; export interface BamRecordLike { ref_id: number; start: number; end: number; name: string; fileOffset: number; next_pos: number; next_refid: number; flags: number; tags: Record<string, unknown>; } export type BamRecordClass<T extends BamRecordLike = BAMFeature> = new (args: { bytes: Bytes; fileOffset: number; dataView: DataView; }) => T; export declare const BAM_MAGIC = 21840194; interface ChunkEntry<T> { minBlock: number; maxBlock: number; features: T[]; } export default class BamFile<T extends BamRecordLike = BAMFeature> { renameRefSeq: (a: string) => string; bam: GenericFilehandle; header?: string; chrToIndex?: Record<string, number>; indexToChr?: { refName: string; length: number; }[]; index?: BAI | CSI; htsget: boolean; headerP?: ReturnType<BamFile<T>['getHeaderPre']>; chunkFeatureCache: QuickLRU<string, ChunkEntry<T>>; private RecordClass; constructor({ bamFilehandle, bamPath, bamUrl, baiPath, baiFilehandle, baiUrl, csiPath, csiFilehandle, csiUrl, htsget, renameRefSeqs, recordClass, }: { bamFilehandle?: GenericFilehandle; bamPath?: string; bamUrl?: string; baiPath?: string; baiFilehandle?: GenericFilehandle; baiUrl?: string; csiPath?: string; csiFilehandle?: GenericFilehandle; csiUrl?: string; renameRefSeqs?: (a: string) => string; htsget?: boolean; recordClass?: BamRecordClass<T>; }); getHeaderPre(opts?: BaseOpts): Promise<{ tag: string; data: { tag: string; value: string; }[]; }[] | undefined>; getHeader(opts?: BaseOpts): Promise<{ tag: string; data: { tag: string; value: string; }[]; }[] | undefined>; getHeaderText(opts?: BaseOpts): Promise<string | undefined>; getRecordsForRange(chr: string, min: number, max: number, opts?: BamOpts): Promise<T[]>; private evictOverlappingChunks; private _fetchChunkFeaturesDirect; fetchPairs(chrId: number, records: T[], opts: BamOpts): Promise<T[]>; _readChunkFeatures(chunk: Chunk, opts: BaseOpts): Promise<T[]>; readBamFeatures(ba: Uint8Array, cpositions: number[], dpositions: number[], chunk: Chunk): Promise<T[]>; hasRefSeq(seqName: string): Promise<boolean>; lineCount(seqName: string): Promise<number>; indexCov(seqName: string, start?: number, end?: number): Promise<never[] | import("./bai.ts").IndexCovEntry[]>; blocksForRange(seqName: string, start: number, end: number, opts?: BaseOpts): Promise<Chunk[] | never[]>; clearFeatureCache(): void; estimatedBytesForRegions(regions: { refName: string; start: number; end: number; }[], opts?: BaseOpts): Promise<number>; } export {};