SemiBin is a metagenomic binning tool that uses siamese neural networks (PyTorch) to cluster contigs from metagenomic assemblies into genome bins. It supports both self-supervised (SemiBin2, default) and semi-supervised learning modes, with pre-trained models for 11 environments.
python -m pytest # all unit tests
python -m pytest test/test_bin.py # single test file
python -m pytest test/test_bin.py -k test_name # single testuv pip install .
python integration-tests/easy_commands2.py # run one integration testpixi run -e test-py312 pytest # run tests in a specific Python version envuv pip install -e .SemiBin/main.py — CLI argument parsing (parse_args) and all subcommand handlers. The entry point is SemiBin.main:main2, exposed as SemiBin2 command. This is a large file (~1600 lines) that orchestrates the entire pipeline.
SemiBin/semi_supervised_model.py— Siamese network architecture (Semi_encoding_single,Semi_encoding_multiple) and training loop using must-link/cannot-link constraintsSemiBin/self_supervised_model.py— Contrastive learning training (train_self), reuses the network classes fromsemi_supervised_model.py
SemiBin/generate_coverage.py— Converts BAM alignments to coverage/abundance features via samtools+bedtoolsSemiBin/generate_kmer.py— Extracts k-mer composition features from FASTA sequencesSemiBin/markers.py— HMM marker gene detection using HMMER (bundledmarker.hmmprofile)
SemiBin/cluster.py— Main clustering viarun_embed_infomap()(graph-based with python-igraph) andrecluster_bins()for quality refinementSemiBin/long_read_cluster.py— DBSCAN-based ensemble clustering for long reads
SemiBin/utils.py— Shared utilities: data normalization, constraint generation, FASTA loading, bin writingSemiBin/atomicwrite.py— Crash-safe file writingSemiBin/orffinding.py/naive_orffinder.py— ORF prediction (prodigal/fraggenescan/built-in)SemiBin/fasta.py— FASTA parsingSemiBin/gtdb.py— GTDB reference database integration
SemiBin/models/*.pt — 11 environment-specific models (human_gut, ocean, soil, etc.)
- Feature generation: contigs.fa + BAM → coverage features + k-mer features
- Training: features → self-supervised contrastive learning (or semi-supervised with taxonomy constraints)
- Clustering: trained model embeds contigs → infomap graph clustering (or DBSCAN for long reads)
- Output: clustered bins written as FASTA files
Managed via conda/pixi (not pip): samtools, bedtools, hmmer, mmseqs2, prodigal, fraggenescan.
Prefix commits with: BUG, ENH, MIN, RFCT, TST, DOC, RLS. Can be combined (e.g., BUG+DOC).
For new features and bugfixes, update both:
ChangeLog— add a line underUnreleasedsummarising the change (include issue number if applicable)docs/whatsnew.md— add a bullet under the current unreleased version section
Version is single-sourced from SemiBin/semibin_version.py (__version__);
pyproject.toml reads it dynamically. To release version X.Y.Z:
- Bump
__version__inSemiBin/semibin_version.py. ChangeLog: rename theUnreleasedheader toVersion X.Y.Z <Mon DD YYYY> by BigDataBiologyand add a fresh emptyUnreleasedline at the top.docs/whatsnew.md: rename## Unreleasedto## Version X.Y.Zwith a*Released <Month DD, YYYY>*line and a short summary paragraph (see the 2.3.0 entry for the format); add a new empty## Unreleasedsection on top. Split the entries into subsections (### User-visible changes,### Bug fixes,### Documentation fixes), ordering them so that user-visible changes come first. Reconcile it against theChangeLogso both list the same changes.- Bump the example version pins in
README.mdanddocs/install.md(semibin = ">=X.Y.Z,<3"). - Commit everything as
RLS Version X.Y.Z(the commit body is the release summary). - Tag with a signed annotated tag:
git tag -s vX.Y.Z(message = the release summary). - Publish is manual (no CI does it): build with
python -m buildand upload withtwine upload dist/*. A bioconda PR follows separately.
- Python 3.10+ compatibility required
- Uses
mp.get_context('spawn').Poolfor multiprocessing (not fork)