Genotype API Documentation - v0.1.0
    Preparing search index...

    Class BAMWriter

    BAM writer with BGZF compression and binary serialization

    Designed for memory efficiency with large BAM files from modern sequencers. Handles real-world BAM complexity including:

    • Long reads from PacBio/Oxford Nanopore (>100kb sequences)
    • Large CIGAR strings with complex operations
    • Comprehensive optional tag support
    • BGZF block-level error recovery
    const writer = new BAMWriter();
    const bamData = await writer.writeString(header, alignments);
    const writer = new BAMWriter({ compressionLevel: 9 });
    await writer.writeFile('output.bam', header, alignments);
    const writer = new BAMWriter();
    const stream = writer.createWriteStream();
    await writer.writeHeader(stream, header);
    for (const alignment of alignments) {
    await writer.writeAlignment(stream, alignment, references);
    }
    await writer.finalize(stream);
    Index

    Constructors

    Methods

    • Write complete BAM data to memory as binary string

      Parameters

      Returns Promise<Uint8Array<ArrayBufferLike>>

      Promise resolving to BAM binary data

      If writing fails

    • Write BAM data to file using Bun's optimized file I/O

      Parameters

      • filePath: string

        Path to output BAM file

      • header: SAMHeader | SAMHeader[]

        SAM header information

      • alignments: Iterable<SAMAlignment, any, any> | AsyncIterable<SAMAlignment, any, any>

        Iterable of SAM alignment records

      Returns Promise<void>

      If file writing fails

    • Create a writable stream for streaming BAM output

      Returns WritableStream<Uint8Array<ArrayBufferLike>>

      Writable stream for BAM data

    • Serialize a single alignment record to binary format

      Parameters

      • alignment: SAMAlignment

        SAM alignment record

      • references: string[]

        Reference sequence names

      Returns Promise<Uint8Array<ArrayBufferLike>>

      Serialized alignment binary data

    • Get writer performance statistics and configuration

      Returns {
          options: Required<BAMWriterOptions>;
          compressionInfo: {
              compressionLevel: number;
              blockSize: number;
              bunOptimized: boolean;
              streamingSupported: boolean;
              maxBlockSize: number;
          };
          serializerStats: {
              maxAlignmentSize: number;
              bufferPoolSize: number;
              bufferUtilization: number;
              bunOptimized: boolean;
          };
          bunOptimized: boolean;
      }

      Writer statistics and capabilities

    • Create an optimized BAM writer for high-performance scenarios

      Parameters

      • options: BAMWriterOptions & {
            prioritizeSpeed?: boolean;
            prioritizeCompression?: boolean;
        } = {}

        Performance tuning options

      Returns BAMWriter

      Optimized writer instance