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

    Class SAMParser

    Streaming SAM parser with comprehensive validation

    Designed for memory efficiency - processes records one at a time without loading entire files into memory. Handles real-world SAM file complexity including malformed headers, invalid CIGAR strings, and incorrect optional tags.

    const parser = new SAMParser();
    for await (const record of parser.parseString(samData)) {
    if (record.format === 'sam-header') {
    console.log(`Header: ${record.type}`);
    } else {
    console.log(`Alignment: ${record.qname} -> ${record.rname}:${record.pos}`);
    }
    }
    const parser = new SAMParser({
    skipValidation: false,
    trackLineNumbers: true,
    onError: (error, lineNumber) => console.error(`Line ${lineNumber}: ${error}`)
    });

    Hierarchy

    Index

    Constructors

    • Create a new SAM parser with specified options and interrupt support

      Parameters

      • options: SamParserOptions = {}

        SAM parser configuration options including AbortSignal

      Returns SAMParser

    Methods

    • Parse SAM records from a string

      Parameters

      • data: string

        Raw SAM format string data

      Returns AsyncIterable<SAMHeader | SAMAlignment>

      SAMAlignment or SAMHeader objects as they are parsed from the input

      When SAM format is invalid

      When record data is malformed

    • Parse SAM records from a ReadableStream

      Parameters

      • stream: ReadableStream<Uint8Array<ArrayBufferLike>>

        Binary data stream

      Returns AsyncIterable<SAMHeader | SAMAlignment>

      AsyncIterable of SAM headers and alignments

    • Parse SAM records from a file using streaming I/O

      Parameters

      • filePath: string

        Path to SAM file to parse

      • Optionaloptions: FileReaderOptions

        File reading options for performance tuning

      Returns AsyncIterable<SAMHeader | SAMAlignment>

      SAMAlignment or SAMHeader objects as they are parsed from the file

      When file cannot be read

      When SAM format is invalid

      When record data is malformed

      const parser = new SAMParser();
      for await (const record of parser.parseFile('/path/to/alignments.sam')) {
      if (record.format === 'sam') {
      console.log(`${record.qname} -> ${record.rname}:${record.pos}`);
      }
      }