Skip to main content

A lightweight Python utility for targeted synthetic FASTQ generation

Project description

mock-fastq-generator

DOI Tests License Python

mock-fastq-generator is an open-source software utility for generating targeted synthetic FASTQ datasets with controllable Phred quality score profiles. Available both as an installable Python package/CLI and as a standalone client-side web application, it allows bioinformatics developers to benchmark sequence processing tools (trimmers, aligners, denoisers) without relying on heavy empirical reference-genome simulators or exposing proprietary data.


Key Features

  • Parametric Quality Decay Models: Choose between three distinct decay models:
    • Gaussian: Bounded bell-curve quality peak centered at a designated position.
    • Exponential: Simulates 3' end quality degradation with a sub-exponential initial plateau.
    • Sigmoidal: Sharp quality score drop centered at a specific nucleotide coordinate.
  • Illumina 4-State Quality Binning (--binned_quality): Snaps Phred scores to discrete bins (Q2, Q12, Q23, Q37) emulating modern Illumina NovaSeq platforms.
  • Homopolymer Quality Penalties (--homopolymer_penalty): Applies context-dependent $-10$ Phred score penalties inside runs of $>4$ identical consecutive nucleotides.
  • Targeted Construct Assembly: Combines custom FASTA templates with adapter/flanking upstream sequences and randomized nucleotide margins.
  • Paired-End Read Simulation (--paired-end): Generates matching R1 (forward) and R2 (reverse complement) paired FASTQ files with matching headers (/1 and /2).
  • Inline Gzip Compression (--gzip): Directly writes .fastq.gz archives.
  • Standard Output Streaming (--stdout): Streams FASTQ records directly to stdout for UNIX piping (|) into tools like bwa, fastp, or fastqc.
  • JSON Configuration Profiles (--parameters_file): Load reproducible simulation settings from structured JSON files.
  • Standalone Web Application: Complete client-side web interface (public/index.html) requiring no backend server.

Quality Profiles

Figure 1: Comparison of synthetic Phred quality score profiles generated across a 500-base construct. (A) Parametric Gaussian decay. (B) Exponential 3' quality dropoff. (C) Sigmoidal drop combined with 4-state NovaSeq binning and homopolymer penalties.


Installation

Prerequisites

  • Python 3.8+
  • numpy >= 1.20

Package Installation

Install directly from GitHub via pip:

git clone https://github.com/florez-alberto/mock-fastq-generator.git
cd mock-fastq-generator
pip install .

For active development (includes pytest and ruff):

pip install -e ".[dev]"

Usage

Command-Line Interface (CLI)

1. Basic Single-End Generation

mock-fastq-generator \
  --template_sequence template_example.fasta \
  --output_file synthetic.fastq

2. Advanced Paired-End with NovaSeq Binning & Gzip Compression

mock-fastq-generator \
  --template_sequence template_example.fasta \
  --output_file sample_data \
  --paired-end \
  --gzip \
  --decay_model sigmoidal \
  --decay_rate 0.05 \
  --center 100 \
  --binned_quality \
  --homopolymer_penalty \
  --number_of_sequences 1000

(Produces sample_data_R1.fastq.gz and sample_data_R2.fastq.gz)

3. UNIX Piping (Streaming directly into aligner or trimmer)

mock-fastq-generator \
  --template_sequence template_example.fasta \
  --number_of_sequences 500 \
  --stdout | bwa mem reference.fasta - > mapped_reads.sam

4. JSON Configuration File

Create a config.json file:

{
  "upstream_sequence": "GCCGGCCATGGCG",
  "left_margin": 15,
  "total_length": 300,
  "number_of_sequences": 200,
  "decay_model": "exponential",
  "decay_rate": 0.001,
  "min_val": 7,
  "max_val": 40,
  "score_type": "phred"
}

And execute:

mock-fastq-generator --template_sequence template_example.fasta --parameters_file config.json --output_file output.fastq

Python API

You can also import mock-fastq-generator into Python scripts or automated test suites:

from mock_fastq_generator import assemble_sequences, assemble_paired_sequences
from mock_fastq_generator.io import write_fastq

# Single-end records
records = assemble_sequences(
    template_sequence="GAATTCGCAAGCTT",
    upstream_sequence="GCCGGCCATGGCG",
    left_margin=15,
    total_length=150,
    number_of_sequences=100,
    decay_model="exponential",
    decay_rate=0.0008,
    min_val=7,
    max_val=40,
    score_type="phred",
    binned_quality=True
)

# Write to file
write_fastq("output.fastq.gz", records, compress=True)

Standalone Web Application

mock-fastq-generator includes a zero-dependency, client-side web application located in public/index.html.

  • Open public/index.html directly in any modern web browser.
  • Interactive controls allow configuring all simulation parameters.
  • Real-time visualization of positional Phred score decay curves powered by Chart.js.
  • Generates and downloads FASTQ files client-side using browser Blob APIs without server computation.

CLI Reference

Argument Default Description
--output_file None Output file path (or prefix for paired-end mode). Mutually exclusive with --stdout.
--stdout False Stream FASTQ content directly to stdout. Mutually exclusive with --output_file.
--template_sequence None Path to FASTA template file. Defaults to bundled template_example.fasta.
--parameters_file None Path to JSON configuration file overriding defaults.
--paired-end False Generate R1 forward and R2 reverse complement read pairs.
--gzip False Write gzip-compressed .fastq.gz output files.
--upstream_sequence "GCCGGCCATGGCG" Upstream adapter/flanking sequence prepended to reads.
--left_margin 15 Number of random bases between upstream adapter and template.
--total_length 500 Total read length in bases.
--number_of_sequences 50 Number of reads (or read pairs) to simulate.
--decay_model "gaussian" Quality decay model (gaussian, exponential, sigmoidal).
--decay_rate 0.0008 Steepness parameter for exponential ($1.25$ exponent) or sigmoidal drop.
--center 100 Peak center index (Gaussian) or drop position (Sigmoidal).
--std_dev 300 Standard deviation for Gaussian decay curve.
--min_val 40 Minimum quality score floor (clamped).
--max_val 73 Maximum quality score ceiling.
--score_type "ascii" Input format for min_val/max_val ("ascii" offset 33 or "phred" absolute).
--noise_level 0.5 Standard deviation of additive Gaussian noise on Phred scores.
--binned_quality False Snap quality scores to Illumina 4-state bins (Q2, Q12, Q23, Q37).
--homopolymer_penalty False Subtract $10$ Phred points within homopolymer runs $>4$ bases.

Testing

Run the test suite with pytest:

pytest tests/

If fastp is installed on your system PATH, integration tests will automatically execute fastp quality filtering verification.


License

This project is licensed under the MIT License. See LICENSE for details.

References

  1. Cock PJ, Fields CJ, Goto N, Heuer ML, Rice PM. The Sanger FASTQ file format for sequences with quality scores, and the Solexa/Illumina FASTQ variants. Nucleic Acids Research. 2010;38(6):1767-1771. DOI: 10.1093/nar/gkp1137

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mock_fastq_generator-1.0.0.tar.gz (672.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mock_fastq_generator-1.0.0-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file mock_fastq_generator-1.0.0.tar.gz.

File metadata

  • Download URL: mock_fastq_generator-1.0.0.tar.gz
  • Upload date:
  • Size: 672.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.9

File hashes

Hashes for mock_fastq_generator-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9051c3cc3e90eb19e7910297d4bef9c2cdd61ffe6e7a4e29ff4c7522372722c0
MD5 02809f4ef57fa3f07b062363611ff859
BLAKE2b-256 ccfa2d95e0155e64a9a129794a2ee623e2082405f9b1a3393d91b658b6de182f

See more details on using hashes here.

File details

Details for the file mock_fastq_generator-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mock_fastq_generator-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e6c82e5d485d73d79c47d7175be9901a50cc3b9a3fee6cc97b3dde65249289bb
MD5 822e1e39157506320e790acdb70fd94f
BLAKE2b-256 3043d068695e7a3e8744b7b6b1aca191b6137b137ca637a3d3aec1485e11a0fc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page