How rnajena/bertax works
Project Type and Purpose
• BERTax is a Python‐based command‐line tool and library for taxonomic classification of DNA sequences using a deep neural network (BERT) model.
• The project can be run locally (pip/conda install) or inside a Docker container, with optional GPU acceleration.
File Structure Analysis
• Top-level:
• Dockerfile, .github workflows: container build and CI/CD.
• setup.py, conda.recipe: packaging and distribution.
• confusion_matrices: static PDF outputs, example results.
• Source code: “bertax/” package
• bertax.py: main CLI and inference logic.
• utils.py: data handling, sequence splitting, encoding.
• resources/: model file(s) and related assets.
• No frontend/backend split. It’s a standalone CLI/library with core engine and visualization module.
README Insights
• Describes usage, parameters, installation options (Docker, conda, pip).
• Highlights external dependencies: keras-bert, torch, transformers, bertviz.
• Mentions model download (HDF5) into resources.
• Notes GPU support via NVIDIA toolkit.
Main Components
a. User Interfaces
• CLI “bertax”: takes FASTA input, prints or writes predictions.
b. Core Modules
• Sequence Parser & Splitter (utils.py): reads FASTA, splits long sequences.
• Encoder: tokenizes and encodes DNA k-mers for BERT input.
• Model Loader (resources): loads pretrained .h5 model via keras-bert.
• Inference Engine (bertax.py): runs model.predict on batches (CPU/GPU).
• Postprocessor & Aggregator: averages chunk predictions, formats output.
c. Outputs
• Console or file‐based tabular output.
• Optional JSON confidences (--conf_matrix_file).
• HTML visualizations via bertviz.
• Static confusion matrices folder (for reference).
d. Packaging & Deployment
• Docker image: builds environment, installs package, sets entrypoint.
• Conda recipe: for channel distribution.
• setup.py: pip installation.
Component Interactions and Data Flow
1. User invokes CLI command with sequence file.
2. Sequence Parser reads sequences → Sequence Splitter produces chunks.
3. Encoder transforms chunks into input tensors.
4. Model Loader loads weights → Inference Engine runs forward pass.
5. Postprocessor aggregates predictions → Output Writer sends to console/file.
Architectural Patterns and Design Principles
• Modular separation: parsing, encoding, inference, postprocessing.
• Single‐responsibility principle: each Python module handles one concern.
• Pluggable backend: can swap in custom models (--custom_model_file).
• Containerization: infrastructure as code, reproducibility.
Technologies and Frameworks
• Python 3.x
• keras-bert, TensorFlow/Keras backend
• torch, transformers, bertviz (visualization)
• Biopython or custom FASTA parsing in utils
• Docker, Conda for environment management
• Parameters (batch_size, sequence_split options).
• External dependencies (keras-bert, bertviz) as supporting libraries.
• Conditional path for visualization vs. classification.
• Resources directory as the source of model assets.
• Packaging layers: source code, Dockerfile, conda.recipe, setup.py.