A comprehensive pipeline for comparative analysis of bacterial genomes β designed to make bioinformatics accessible to researchers at all levels.
This repository provides automated shell scripts and Python tools to streamline bacterial genome assembly, annotation, and comparative analysis. Whether you're new to bioinformatics or an experienced researcher, these scripts will help you perform complex analyses without the hassle of manually wrangling individual tools.
This is a maintained, modernized fork of the original bacterial genomics tutorial pipeline. It preserves the original end-to-end workflow while adding a structured runner, standardized outputs, tests, and improved documentation. The goal is to make bacterial comparative genomics reproducible, teachable, and easy to run for both classroom use and small research projects.
Key goals:
- Provide a complete, runnable pipeline from raw reads to comparative analysis
- Reduce setup friction with pinned dependencies and better diagnostics
- Offer a consistent output layout for downstream analysis and reporting
π₯ Learn More:
- Quality Control - FastQC, QUAST for read and assembly quality assessment
- Read Trimming - Sickle and Trimmomatic for sequence quality filtering
- Assembly - SPAdes for de novo genome assembly
- Assembly Polishing - Pilon for draft genome improvement
- Genome Annotation - Prokka for automatic gene annotation
- Comparative Analysis - Roary for pangenome analysis, dREP for genome comparison
- Typing & Resistance - MLST for sequence typing, ABRicate for AMR gene detection
- Visualization - Dendograms, circular genomes, and Venn diagrams
- Type Hints - Full type annotations for better IDE support
- Error Handling - Comprehensive validation and meaningful error messages
- Logging System - Structured logging for easier debugging
- CLI Interface - Professional command-line argument parsing with help
- Unit Tests - Full test coverage with pytest
- Code Quality Tools - Black, Flake8, MyPy for code standards
- Pinned Dependencies - Reproducible environments with explicit versions
- Linux/macOS (or WSL on Windows)
- Conda (Anaconda or Miniconda)
- ~20GB free disk space
# 1. Clone the repository
git clone https://github.com/Zianasif/bacterial-genomics-tutorial.git
cd bacterial-genomics-tutorial
conda env create -f environment.yaml
# 3. Activate the environment
conda activate bacterial-genomics-tutorial
# 4. Download pilon (optional but recommended)
# 5. Make scripts executable
chmod +x *.{py,sh,pl}# Download sample data
./download_data.sh
# Run quality control on raw reads
./qc_raw_reads.sh
# That's it! You're ready to go
Use the end-to-end runner in run_pipeline.sh to execute the full workflow in a reproducible run folder. Each profile runs a defined set of steps.
Profiles:
- demo - Download + QC + trim + assemble
- small - demo + polish + reorder + typing + AMR + annotation
- full - small + pangenome + summary plots
# Full workflow in a timestamped run folder
./run_pipeline.sh --profile full
# Shorter run for quick validation
./run_pipeline.sh --profile demo
# Reuse existing data without downloading
./run_pipeline.sh --profile small --skip-downloadThe runner saves raw step outputs in a work folder and then builds a standardized output tree for browsing using organize_results.sh.
Raw Reads
β
[QC] FastQC βββ Quality Report
β
[Trim] Sickle/Trimmomatic βββ Clean Reads
β
[QC] Trimmed Reads
β
[Assemble] SPAdes βββ Draft Contigs
β
[Polish] Pilon βββ Polished Genome
β
[QC] QUAST βββ Assembly Stats
β
[Reorder] RagTag βββ Reference-aligned
β
[Type] MLST βββ Sequence Type
β
[Resistance] ABRicate βββ AMR Genes
β
[Annotate] Prokka βββ Annotations
β
[Compare] Roary βββ Pangenome
β
[Visualize] Dendograms, Venn Diagrams
./qc_raw_reads.shGenerates FastQC reports for your sequencing reads.
./trim_reads.shRemoves low-quality bases and adapters using Sickle.
./qc_trimmed_reads.shVerifies trimming quality.
./assemble.shAssembles reads into contigs using SPAdes.
./polish.shImproves assembly accuracy using Pilon.
./qc_assembly.shEvaluates both raw and polished assemblies with QUAST.
./reorder_contigs.shAligns and orders contigs against a reference genome.
./mlst.shPerforms MLST analysis for strain identification.
./amr.shIdentifies known AMR genes using ABRicate.
./annotate.shAnnotates genes and features using Prokka.
python get_annot_stats_modernized.py -v annotation_dir genome_prefixExtracts gene counts and feature statistics.
./dendogram.shCreates phylogenetic trees with dREP.
./get_genome_gffs.sh # Generate GFF files
./get_pangenome.sh # Run RoaryAnalyzes shared and unique genes across genomes.
python gene_count_summary_modernized.py isolate1 isolate2 isolate3 gene_presence_absence.csvCreates Venn diagrams showing gene overlap.
Use Proksee or CGView tools with generated GFF files.
All modernized scripts include improved features and full help documentation:
# Get help
python get_annot_stats_modernized.py -h
# Basic usage with logging
python get_annot_stats_modernized.py annotation_dir genome_prefix
# Verbose output with file save
python get_annot_stats_modernized.py -v -o stats.txt annotation_dir genome_prefixFeatures:
- β Type hints for IDE support
- β Structured logging system
- β Detailed error messages
- β Output to file option
- β Verbose debugging mode
# Get help
python gene_count_summary_modernized.py -h
# Generate Venn diagram
python gene_count_summary_modernized.py isolate1 isolate2 isolate3 gene_presence_absence.csv
# Custom output and title
python gene_count_summary_modernized.py \
-o custom_venn.png \
--title "My Bacterial Comparison" \
isolate1 isolate2 isolate3 gene_presence_absence.csvFeatures:
- β Input validation with clear errors
- β Statistics summary before visualization
- β Customizable output filename and title
- β Comprehensive error handling
# Get help
./assemble_modernized.sh -h
# Run with custom options
./assemble_modernized.sh -o results -t 8 -vFeatures:
- β Input validation
- β Colored logging output
- β Error trapping with line numbers
- β Configurable threads
- β Output verification
Run the comprehensive test suite to verify installation:
# Install test dependencies
pip install -r requirements-dev.txt
# Run all tests
pytest tests/ -v
# Run with coverage report
pytest tests/ --cov=. --cov-report=htmlCheck code quality using modern tools:
# Type checking
mypy *.py
# Code formatting
black --check .
# Linting
flake8 .
# Run all checks
black . && flake8 . && mypy . && pytest tests/ -vRuns created with run_pipeline.sh keep raw step outputs in a dedicated work area, then generate a clean, standardized output tree for browsing and downstream analysis using organize_results.sh.
bacterial-genomics-tutorial/
βββ *.sh # Pipeline scripts
βββ *.py # Analysis scripts
βββ *_modernized.py # Enhanced versions with type hints
βββ genomes/ # Sample reference genomes
βββ tests/ # Unit test suite
β βββ test_annotation_scripts.py
β βββ __init__.py
βββ notebooks/ # Walkthrough notebook
β βββ Walkthrough.ipynb
βββ environment.yaml # Conda dependencies (pinned versions)
βββ pip-requirements.txt # Python pip dependencies
βββ requirements-dev.txt # Development tools
βββ run_pipeline.sh # End-to-end runner with profiles
βββ organize_results.sh # Standardized output organizer
βββ README.md # This file
βββ MODERNIZATION_GUIDE.md # Detailed modernization info
βββ MODERNIZATION_SUMMARY.md # Modernization overview
βββ QUICK_REFERENCE.md # Quick command reference
All major bioinformatics tools are included in environment.yaml:
- Assembly: SPAdes, Minimap2, RagTag
- QC: FastQC, QUAST
- Annotation: Prokka
- Comparison: Roary, dREP, Mash, Mummer
- Typing: MLST
- Resistance: ABRicate
- Utilities: Samtools, BWA, Mafft, Sickle
Python packages:
- BioPython, Pandas, Matplotlib, NumPy
- Testing: pytest, pytest-cov
- Code Quality: black, flake8, mypy, pylint
- QUICK_REFERENCE.md - Command cheat sheet
- MODERNIZATION_SUMMARY.md - Overview of code improvements
- MODERNIZATION_GUIDE.md - Detailed modernization documentation
- notebooks/Walkthrough.ipynb - Hands-on pipeline walkthrough
"Command not found"
# Ensure environment is activated
conda activate bacterial-genomics-tutorial
# Make scripts executable
chmod +x *.{py,sh,pl}"No module named 'X'"
# Reinstall environment
conda env remove -n bacterial-genomics-tutorial
conda env create -f environment.yaml"Permission denied"
chmod +x script_name.shDebugging with verbose output:
# Use -v flag for modernized scripts
python script_modernized.py -v
# Use -v flag for modernized shell scripts
./script_modernized.sh -vSee MODERNIZATION_GUIDE.md for more help.
Perform a complete comparative analysis of 3 bacterial genomes:
# Activate environment
conda activate bacterial-genomics-tutorial
# 1. Download and prepare data
./download_data.sh
# 2. Quality control
./qc_raw_reads.sh
./trim_reads.sh
./qc_trimmed_reads.sh
# 3. Assembly
./assemble.sh
./polish.sh
./qc_assembly.sh
# 4. Typing and screening
./mlst.sh
./amr.sh
# 5. Annotation
./annotate.sh
python get_annot_stats_modernized.py -v annotation_dir genome_name
# 6. Comparative analysis
./get_genome_gffs.sh
./get_pangenome.sh
python gene_count_summary_modernized.py genome1 genome2 genome3 pangenome/gene_presence_absence.csv
# 7. Generate report (optional)
./zip_results.shContributions are welcome! Please ensure:
- β Code includes type hints
- β Functions have docstrings
- β Tests are included
- β Code follows PEP 8
- β
All tests pass (
pytest tests/ -v)
MIT License - See LICENSE for details.
Original Creator: Vincent Appiah
Original Repository: vappiah/bacterial-genomics-tutorial
Modernization Contributions:
- Type hints and logging system
- Comprehensive error handling
- Unit tests
- Code quality tools
- Enhanced documentation
- Maintainer: Zian Asif
- Project Issues: Report bugs or request features
- Project Docs: MODERNIZATION_GUIDE.md and QUICK_REFERENCE.md
- Original Project (reference): vappiah/bacterial-genomics-tutorial
| Resource | Link |
|---|---|
| This Repository | https://github.com/Zianasif/bacterial-genomics-tutorial |
| Quick Reference | QUICK_REFERENCE.md |
| Modernization Guide | MODERNIZATION_GUIDE.md |
| Modernization Summary | MODERNIZATION_SUMMARY.md |
| Original Repository (reference) | vappiah/bacterial-genomics-tutorial |
| Original Tutorials (reference) | Playlist |
Made with β€οΈ for the bioinformatics community
β If this project helped you, consider starring it on GitHub!
python get_annot_stats.py P7741_annotation P7741
./dendogram.sh
Input files are gff (version 3 ) format. It is recommended to use prokka generated gff. So we generate the gffs for the files in the genome folder by reannotating with prokka. We use the get_genome_gffs script
./get_genome_gffs.sh
Then perform pangenome analysis\
./get_pangenome.sh
Step 15: Get gene summary for three of the organism. the default is P7741 Agy99 and Liflandii. Feel free to change it. A venn diagram will be generated(gene_count_summary.png)
python gene_count_summary.py P7741 Agy99 Liflandii pangenome/gene_presence_absence.csv
If you are working on a cluster you will want to combine the analysis results into a zip file for download and view locally.
./zip_results.sh
Step 16: Compare your draft genome with the other organisms in the genomes folder by generating circular structures for them . Use the tutorial here to guide you https://youtu.be/pobQgE4z-5Q
The result interpretation are available on my youtube video tutorial : https://youtu.be/S_sRo_85jhs
Now that you have been able to perform a bacterial comparative genome analysis. Its time to apply your skills on a real world data. Good luck and see you next time
Vincent Appiah, 2020. Bacterial Genomics Tutorial https://github.com/vappiah/bacterial-genomics-tutorial
or
Vincent Appiah,2020. Youtube https://youtu.be/S_sRo_85jhs