DeepBioP
Deep Learning Processing Library for Biological Data

Features
🧬 Sequence Encoding for Machine Learning
- One-Hot Encoding: CNNs/RNNs spatial features (4-channel representation)
- K-mer Encoding: Feature-based models (Random Forest, SVM, XGBoost)
- Integer Encoding: Transformers/embeddings (compact tokenization)
- Batch Processing: Parallel encoding with rayon (1M+ sequences/sec)
- Zero-Copy NumPy: Direct array export for PyTorch/TensorFlow/JAX
🔬 Biological File Format Support
- FASTQ/FASTA: Read/write with compression (gzip, bgzip), quality score handling
- BAM/SAM: Multithreaded decompression, alignment feature extraction, CIGAR parsing
- VCF: Variant filtering, SNP/indel classification, quality thresholds
- GTF/GFF: Gene annotation queries, feature indexing, exon/CDS extraction
- Format Conversion: Bidirectional FASTQ ↔ FASTA, BAM → FASTQ
🎲 Data Augmentation for Training
- Reverse Complement: Orientation-invariant training data
- Random Mutations: Simulate SNPs/sequencing errors (configurable rates)
- Subsequence Sampling: Extract random/fixed windows (start/center/end/random)
- Quality Simulation: Generate realistic Phred scores (5 models: Uniform, Normal, HighQuality, MediumQuality, Degrading)
- Batch Operations: Reproducible augmentation with seed control
📊 ML-Friendly Data Export
- Parquet/Arrow: Columnar storage for pandas/polars/DuckDB analytics
- NumPy Arrays: Direct
.npyexport for ML frameworks - Alignment Features: Extract MAPQ, identity, indel rates, clip statistics
- GC Content: Automatic sequence composition analysis
- Zero-Copy Sharing: Memory-efficient interop with Python ecosystem
⚡ Performance & Scalability
- Streaming I/O: Process 100GB+ files with constant memory
- Parallel Processing: Linear scaling to 16+ cores with rayon
- Memory Efficient: ≤2× largest record size for streaming operations
- Benchmarked: 1M+ FASTQ records/sec, <100ms CLI startup
- Production Ready: Battle-tested on HPC clusters and cloud compute
🐍 Python API + 🦀 Rust Library + 🔧 CLI Tool
- Three Interfaces: Use from Python (PyO3 bindings), Rust (crates), or command-line (dbp)
- Type Safety: Full type hints for Python, strongly-typed Rust API
- Error Handling: Descriptive errors with file/line/field context
- Cross-Platform: Linux, macOS, Windows support with CI validation
- Minimal Dependencies: Fast installation, small binary footprint
Setup
Python
install the latest deepbiop version with:
Rust
You can take latest release from crates.io, or if you want to use the latest features / performance improvements point to the main branch of this repo.
Each enabled feature can then be imported by its re-exported name, e.g.,
use fastq;
CLI
Quickstart
Python: Encode DNA Sequences for Machine Learning
# One-hot encoding for CNNs/RNNs
=
=
=
# (3, 8, 4) - [batch, seq_len, alphabet_size]
# K-mer encoding for feature-based models
=
=
# (3, 64) - [batch, num_kmers]
# Integer encoding for transformers/embeddings
=
=
# (3, 8) - [batch, seq_len]
# Use with PyTorch
=
# Use with HuggingFace Transformers
= + 5 # Offset for special tokens
=
Python: PyTorch-Style API for Deep Learning
DeepBioP provides a PyTorch-compatible Dataset and DataLoader interface for seamless deep learning workflows:
# 1. Load FASTQ data with lazy loading (memory efficient)
=
# Fast - doesn't load all data
# 2. Create transforms for data preprocessing
=
# Apply transform to a sample
=
=
# (150, 4) - ready for CNN
# 3. Create DataLoader for batching
=
# 4. Iterate through batches (PyTorch-style)
# batch is a list of samples (dicts with 'sequence', 'quality' keys)
=
# Collate into batch tensors with padding
=
= # Shape: [batch_size, max_len, 4]
= # Original lengths before padding
# Convert to PyTorch tensors (zero-copy)
=
# Ready for model training!
# output = model(tensor)
break # Just show first batch
Data Augmentation Pipeline
# Create augmentation pipeline
=
# Apply to dataset
=
=
# (100, 4)
# Use in training loop
=
# Each iteration gives different augmentations (if using random strategies)
=
=
# Train model...
Dataset Caching for 10x Speedup
# Process and save to cache (first time - slow)
=
=
=
=
# Process first 1000
break
# Save to cache
# Load from cache (subsequent times - 10x faster!)
=
# Automatic cache invalidation
=
Dataset Inspection & Quality Validation
=
# Get summary statistics
=
# Output: {'min': 50, 'max': 300, 'mean': 150.5, 'median': 151.0}
# Validate data quality
=
# Example output:
# Is valid: True
# Warnings: ['Validated 10 of 1000 sequences (sample validation)']
# Errors: []
Complete Training Example
# 1. Setup data pipeline
=
# 2. Define transform pipeline
=
# 3. Create data loader
=
# 4. Define a simple CNN model
=
=
=
= # 200 / 2 / 2 = 50
# x: [batch, length, 4] -> [batch, 4, length] for Conv1d
=
=
=
=
=
=
return
# 5. Training loop
=
=
=
# Transform and collate batch
=
=
# Convert to tensors
=
= # Dummy labels
# Forward pass
=
=
# Backward pass
For complete examples, see:
- PyTorch Quickstart - Complete workflow demonstration
- PyTorch API Tests - All features with usage examples
Rust: Process FASTQ Files
use ;
use EncodingType;
use AmbiguousStrategy;
Python: Process BAM Alignment Files
# Open BAM file with multithreaded decompression
=
# Extract alignment features for machine learning
=
# Filter high-quality alignments (MAPQ >= 30)
=
=
# Extract properly paired reads
=
=
# Count chimeric/supplementary alignments
=
=
Rust: Process BAM Alignment Files
use ;
use Path;
Python: Export to ML-Friendly Formats
# Export FASTQ to Parquet (columnar storage for analytics)
# Read back with pandas/polars/duckdb
=
# Output: id, sequence, length, quality, gc_content columns
# Export to NumPy for direct ML framework use
=
# Integer encoding (compact, for RNN/LSTM)
# One-hot encoding (spatial features, for CNN)
# Load in ML framework
= # Shape: (2, 8)
CLI: Convert and Export Biological Data
# Convert between formats
# Export to Parquet (for pandas/polars/duckdb)
# Export to NumPy (for ML frameworks)
# Encode sequences for ML
Python: Parse VCF Variant Files
# Open VCF file and read variants
=
=
# Access variant properties
# Filter high-quality variants
=
=
# Filter passing variants only
=
=
Python: Query GTF Annotation Files
# Open GTF file and read features
=
=
# Access feature properties
# Build gene index for fast lookups
=
=
# Query by gene ID
=
# Filter by feature type
=
=
Python: Data Augmentation for Training
# Reverse complement (orientation invariance)
=
= b
=
# Batch reverse complement for efficiency
=
=
# Random mutations for robustness (simulate SNPs/errors)
= # 2% mutation rate
=
=
# Batch mutations with reproducibility
=
# Random subsequence sampling (sliding windows)
=
= b * 250 # 1000bp
=
# Quality score simulation (FASTA → FASTQ)
= # Modern Illumina (Q37)
=
=
# Complete augmentation pipeline
"""Generate augmented training data."""
=
=
=
# Original
# Reverse complement
# Mutated versions
return
# Expand 5 sequences to 35 augmented versions
= * 5
=
For more examples, see:
- FASTQ Encoding Notebook - One-hot, k-mer, and integer encoding with PyTorch/HF integration
- Data Augmentation Notebook - Complete augmentation pipeline with quality simulation
- BAM Features Notebook - Alignment analysis and ML feature extraction
- Export Examples
- PyTorch Integration
- HuggingFace Transformers Integration
- ML Framework Compatibility Guide
Minimum Supported Rust Version (MSRV)
This project adheres to a Minimum Supported Rust Version (MSRV) policy. The Minimum Supported Rust Version (MSRV) is 1.90.0. We ensure that all code within the project is compatible with this version or newer to maintain stability and compatibility.
Contribute 🤝
Call for Participation: Deep Learning Processing Library for Biological Data
We are excited to announce the launch of a new open-source project focused on developing a cutting-edge deep learning processing library specifically designed for biological data. This project aims to empower researchers, data scientists, and developers to leverage the latest advancements in deep learning to analyze and interpret complex biological datasets.
Project Overview:
Biological data, such as genomic sequences, proteomics, and imaging data, presents unique challenges and opportunities for machine learning applications. Our library seeks to provide a comprehensive suite of tools and algorithms that streamline the preprocessing, modeling, and analysis of biological data using deep learning techniques.
Key Features:
- Data Preprocessing: Efficient tools for cleaning, normalizing, and augmenting biological data.
- Model Building: Pre-built models and customizable architectures tailored for various types of biological data.
- Visualization: Advanced visualization tools to help interpret model predictions and insights.
- Integration: Seamless integration with popular bioinformatics tools and frameworks.
- APIs: Rust and Python APIs to facilitate easy integration with different deep learning frameworks, ensuring efficient operations across platforms.
Who Should Participate?
We invite participation from individuals and teams who are passionate about bioinformatics, deep learning, and open-source software development. Whether you are a researcher, developer, or student, your contributions can help shape the future of biological data analysis.
How to Get Involved:
- Developers: Contribute code, fix bugs, and develop new features.
- Researchers: Share your domain expertise and help validate models.
- Students: Gain experience by working on real-world data science problems.
- Community Members: Provide feedback, report issues, and help grow the user community.
Join Us:
If you are interested in participating, please visit our GitHub repository at Github to explore the project and get started.
Contact Us:
For more information or questions, feel free to contact us at [yangyang.li@norwestern.edu]. We look forward to your participation and contributions to this exciting project!
Together, let's advance the field of biological data analysis with the power of deep learning!