@gmod/bam
Version:
Parser for BAM and BAM index (bai) files
70 lines (69 loc) • 2.92 kB
TypeScript
import Chunk from './chunk.ts';
import type { Offset, VirtualOffset } from './virtualOffset.ts';
export interface TagFilter {
tag: string;
value?: string;
}
export interface FilterBy {
flagInclude?: number;
flagExclude?: number;
tagFilter?: TagFilter;
}
export interface BamOpts {
viewAsPairs?: boolean;
pairAcrossChr?: boolean;
maxInsertSize?: number;
signal?: AbortSignal;
filterBy?: FilterBy;
/**
* Called as the BGZF blocks covering the query are fetched, with cumulative
* downloaded bytes and the total to fetch. Reported at block granularity (one
* tick per chunk, including instant ticks for cache hits) since chunk byte
* sizes are known up front from the index. Lets callers render a determinate
* download progress bar.
*/
onProgress?: (bytesDownloaded: number, totalBytes?: number) => void;
}
export interface BaseOpts {
signal?: AbortSignal;
/**
* Called as the index (.bai/.csi) is downloaded, with cumulative downloaded
* bytes and the total. The index is a whole-file read, so this streams real
* byte progress. Lets callers show a determinate "downloading index" bar.
* (total is optional to match generic-filehandle2's streaming callback.)
*/
onProgress?: (bytesDownloaded: number, totalBytes?: number) => void;
}
export declare function optimizeChunks(chunks: Chunk[], lowest?: Offset): Chunk[];
export declare function parsePseudoBin(bytes: Uint8Array, offset: number): {
lineCount: number;
};
export declare function clampChunkEnds(chunks: Chunk[], extraBoundaries?: number[]): void;
export declare function parseRefSeqs(uncba: Uint8Array, start: number, renameRefSeq: (s: string) => string): {
chrToIndex: Record<string, number>;
indexToChr: {
refName: string;
length: number;
}[];
} | undefined;
export declare function findFirstData(firstDataLine: VirtualOffset | undefined, virtualOffset: VirtualOffset): VirtualOffset;
export declare function parseNameBytes(namesBytes: Uint8Array, renameRefSeq?: (arg: string) => string): {
refNameToId: Record<string, number>;
refIdToName: string[];
};
export declare function concatUint8Array(args: Uint8Array[]): Uint8Array<ArrayBuffer>;
export declare function filterReadFlag(flags: number, flagInclude: number, flagExclude: number): boolean;
export declare function filterTagValue(readVal: unknown, filterVal?: string): boolean;
export declare function filterCacheKey(filterBy?: FilterBy): string;
interface Filterable {
flags: number;
tags: Record<string, unknown>;
}
export declare function applyFilters<T extends Filterable>(records: T[], filterBy: FilterBy): T[];
interface Positioned {
ref_id: number;
start: number;
end: number;
}
export declare function appendInRange<T extends Positioned>(records: T[], chrId: number, min: number, max: number, out?: T[]): T[];
export {};