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

    Class FastqParser

    FASTQ format parser with intelligent path selection and quality score handling

    Automatically detects FASTQ format complexity and chooses the optimal parsing strategy:

    • Fast path: For simple 4-line format (handles ~95% of modern FASTQ files)
    • State machine: For complex multi-line format (wrapped sequences/quality)

    Features:

    • Automatic format detection with confidence scoring
    • Streaming support for memory-efficient parsing
    • Quality encoding auto-detection (Phred+33, Phred+64, Solexa)
    • Telemetry tracking for parser performance monitoring
    • Support for both modern (Illumina) and legacy (454, Ion Torrent) formats
    // Auto-detection (recommended)
    const parser = new FastqParser();
    for await (const seq of parser.parseFile('reads.fastq')) {
    console.log(`${seq.id}: ${seq.sequence.length} bp`);
    }

    // Force specific strategy for known format
    const fastParser = new FastqParser({ parsingStrategy: 'fast' });

    // Get parsing metrics
    const metrics = parser.getMetrics();
    console.log(`Used fast path: ${metrics.fastPathCount} times`);
    console.log(`Used state machine: ${metrics.stateMachineCount} times`);

    v0.1.0

    Hierarchy

    Index

    Constructors

    Methods

    • Get current parsing metrics for telemetry and performance monitoring

      Provides insights into parser behavior and performance:

      • Which parser paths were used (fast vs state machine)
      • How many times auto-detection was triggered
      • Detection confidence scores
      • Total sequences processed

      Returns {
          fastPathCount: number;
          stateMachineCount: number;
          autoDetectCount: number;
          totalSequences: number;
          lastStrategy: ParsingStrategy | null;
          lastDetectedFormat: "simple" | "complex" | null;
          lastConfidence: number | null;
      }

      Copy of current parsing metrics

      const parser = new FastqParser();
      // ... parse some files ...

      const metrics = parser.getMetrics();
      console.log(`Fast path used: ${metrics.fastPathCount} times`);
      console.log(`State machine used: ${metrics.stateMachineCount} times`);
      console.log(`Last format detected: ${metrics.lastDetectedFormat}`);
      console.log(`Detection confidence: ${metrics.lastConfidence}`);
    • Reset parsing metrics to initial state

      Clears all accumulated metrics, useful for:

      • Starting fresh measurement periods
      • Benchmarking specific operations
      • Comparing different parsing strategies

      Returns void

      const parser = new FastqParser();

      // Benchmark fast path
      parser.resetMetrics();
      await processFile('simple.fastq', { parsingStrategy: 'fast' });
      const fastMetrics = parser.getMetrics();

      // Benchmark state machine
      parser.resetMetrics();
      await processFile('simple.fastq', { parsingStrategy: 'state-machine' });
      const smMetrics = parser.getMetrics();
    • Parse FASTQ sequences from a string with intelligent path selection

      Automatically detects format complexity and chooses the optimal parser:

      • Simple 4-line format → Fast path parser (optimized for speed)
      • Multi-line format → State machine parser (handles complexity)

      The parser selection can be controlled via parsingStrategy option:

      • 'auto' (default): Automatic detection based on format analysis
      • 'fast': Force fast path parser (fails on complex formats)
      • 'state-machine': Force state machine parser (handles all formats)

      Parameters

      • data: string

        FASTQ format string

      Returns AsyncIterable<FastqSequence>

      Parsed FASTQ sequences with quality scores

      When FASTQ format is invalid

      When sequence validation fails

      const fastq = `@seq1
      ATCG
      +
      IIII`;

      for await (const seq of parser.parseString(fastq)) {
      console.log(seq.id, seq.sequence);
      }
    • Parse FASTQ sequences from a file using streaming I/O with intelligent path selection

      Samples the beginning of the file to detect format complexity, then uses the appropriate parser for optimal performance. Large files are processed in a memory-efficient streaming manner.

      Parameters

      • filePath: string

        Path to FASTQ file to parse (can be compressed)

      • Optionaloptions: FileReaderOptions

        File reading options for performance tuning

      Returns AsyncIterable<FastqSequence>

      FastqSequence objects as they are parsed from the file

      When file cannot be read

      When FASTQ format is invalid

      When sequence validation fails

      // Parse with auto-detection
      const parser = new FastqParser();
      for await (const sequence of parser.parseFile('/path/to/reads.fastq')) {
      console.log(`${sequence.id}: ${sequence.length} bp`);
      }

      // Force specific strategy for known format
      const parser = new FastqParser({ parsingStrategy: 'fast' });
      for await (const seq of parser.parseFile('illumina.fastq.gz')) {
      // Process Illumina reads with fast parser
      }
    • Parse FASTQ sequences from a ReadableStream

      Parameters

      • stream: ReadableStream<Uint8Array<ArrayBufferLike>>

      Returns AsyncIterable<FastqSequence>