Skip to main content

SCGBinner

Metagenomic binning method

Install SCGBinner

Install the dependecies of SCGBinner

mamba create -n SCGBinner python=3.9
mamba activate SCGBinner
mamba install biopython numpy=1.19 scipy igraph leidenalg joblib pandas=1.4 scikit-learn pyyaml tensorboard tqdm hnswlib atomicwrites bedtools
pip install torch==2.0.0 torchvision==0.15.1 torchaudio==2.0.1 --index-url https://download.pytorch.org/whl/cu118

Install SCGBinner

git clone https://github.com/htaohan/SCGBinner.git
cd SCGBinner
pip install .

Run SCGBinner

SCGBinner is recommended to be run in a GPU environment.

If no GPU is available or GPU resources are limited for large-scale datasets, see the Time-Saving Tips.

conda activate SCGBinner
########################## Run SCGBinner using single-coverage ##########################
scgbinner -a contig_file.fa -o output_path -b S1.sorted.bam -t 16

########################## Run SCGBinner using multi-coverage ##########################
scgbinner -a contig_file.fa -o output_path -b "S1.sorted.bam S2.sorted.bam" -t 16

Alternatively, using wildcard expansion:
scgbinner -a contig_file.fa -o output_path -b "*.sorted.bam" -t 16

Output

The MAGs can be found in the scgbinner_res/SCGBINNER_result directory.

Time-saving tips

  1. If no GPU is available or GPU resources are limited for large-scale datasets, you can speed up the process by setting -x 50 to reduce the training epochs (default: 200), while still producing comparable results.
scgbinner -a contig_file.fa -o output_path -b "*.sorted.bam" -t 16 -x 50
  1. If you have a large number of samples and limited GPU resources, or if you want to integrate SCGBinner into a pipeline (e.g., Snakemake), note that only the training step requires a GPU. SCGBinner can therefore be run in separate stages as follows.
# Data Augmentation
scgbinner -a contig_file.fa -o output_path -b "*.sorted.bam" -t 16 --stage data_augmentation
# Training (only this stage needs a GPU)
scgbinner -a contig_file.fa -o output_path -b "*.sorted.bam" -t 16 --stage training
# Clustering
scgbinner -a contig_file.fa -o output_path -b "*.sorted.bam" -t 16 --stage clustering

Additional supported coverage information formats

Bedtools output

This can save substantial storage space for large-scale multi-coverage binning.

# Use bedtools to convert BAM files into smaller compressed coverage files.
bedtools genomecov -bga -ibam S1.sorted.bam | gzip > S1.sorted.bam.coverage.gz
bedtools genomecov -bga -ibam S2.sorted.bam | gzip > S2.sorted.bam.coverage.gz
scgbinner -a contig_file.fa -o output_path -z "S1.sorted.bam.coverage.gz S2.sorted.bam.coverage.gz" -t 16

CoverM output

CoverM is a fast tool for calculating read coverage.

# Since CoverM does not provide mapping information for each position of the contigs, contig splitting is required for data augmentation.
mamba activate SCGBinner
split_contigs -a contig_file.fa -o output_path/contigs_splited.fasta

##############################Get output of CoverM##############################
mamba activate CoverM
# Generate single-coverage output from a HiFi sample.
coverm contig --methods metabat --single S1_hifi.fastq -p minimap2-hifi -t 16 -o output_path/coverm.tsv --reference output_path/contigs_splited.fasta
# Generate multi-coverage output from HiFi samples.
coverm contig --methods metabat --single S1_hifi.fastq S2_hifi.fastq -p minimap2-hifi -t 16 -o output_path/coverm.tsv --reference output_path/contigs_splited.fasta
# Generate single-coverage output from a Nanopore sample.
coverm contig --methods metabat --single S1_nano.fastq -p minimap2-ont -t 16 -o output_path/coverm.tsv --reference output_path/contigs_splited.fasta
# Generate multi-coverage output from Nanopore samples.
coverm contig --methods metabat --single S1_nano.fastq S2_nano.fastq -p minimap2-ont -t 16 -o output_path/coverm.tsv --reference output_path/contigs_splited.fasta
# Generate single-coverage output from an Illumina sample.
coverm contig --methods metabat -1 S1_illu_1.fastq -2 S1_illu_2.fastq -t 16 -o output_path/coverm.tsv --reference output_path/contigs_splited.fasta
# Generate multi-coverage output from Illumina samples.
coverm contig --methods metabat -1 S1_illu_1.fastq S2_illu_1.fastq -2 S1_illu_2.fastq S2_illu_1.fastq -t 16 -o output_path/coverm.tsv --reference output_path/contigs_splited.fasta

#####################Running SCGBinner using CoverM output#####################
mamba activate SCGBinner
scgbinner -a contig_file.fa -o output_path -m output_path/coverm.tsv -t 16

Options

Options:
  -a STR          metagenomic assembly file
  -o STR          output directory
  -b STR          bam files
  -t INT          number of threads (default=16)
  -p INT          standard batch size (default=1024)
  -x INT          epochs for training process (default=200)
  --stage STR     execution stage: data_augmentation, training, clustering, all=all stages (default=all)

A test dataset to demo SCGBinner

We provide a real dataset to demo and test the software. https://zenodo.org/records/19476565 You can run SCGBinner on this dataset as follows:

scgbinner -a contigs.fasta -o output_path -b test.sorted.bam -t 16

How to generate BAM files

# PacBio Hifi reads
minimap2 -t 16 -ax map-hifi contig_file.fa S1_hifi.fastq | \
        samtools view -@ 16 -b - | \
        samtools sort -@ 16 -o S1.sorted.bam -

samtools index S1.sorted.bam

# Nanopore reads
minimap2 -t 16 -ax map-ont contig_file.fa S1_nano.fastq | \
        samtools view -@ 16 -b - | \
        samtools sort -@ 16 -o S1.sorted.bam -

samtools index S1.sorted.bam

# Illumina reads
bowtie2-build --threads 16 contig_file.fa contig_file.index

bowtie2 --threads 16 -q --fr \
    -x contig_file.index \
    -1 S1_illu_1.fastq \
    -2 S1_illu_2.fastq | \
    samtools view -@ 16 -b - | \
    samtools sort -@ 16 -o S1.sorted.bam -

samtools index S1.sorted.bam

References

[1] Wang Z, You R, Han H, et al. Effective binning of metagenomic contigs using contrastive multi-view representation learning[J]. Nature Communications, 2024, 15(1): 585.

[2] Pan S, Zhao X M, Coelho L P. SemiBin2: self-supervised contrastive learning leads to better MAGs for short-and long-read sequencing[J]. Bioinformatics, 2023, 39(Supplement_1): i21-i29.

[3] Liu C C, Dong S S, Chen J B, et al. MetaDecoder: a novel method for clustering metagenomic contigs[J]. Microbiome, 2022, 10(1): 46.

[4] Han H, Wang Z, Zhu S. Benchmarking metagenomic binning tools on real datasets across sequencing platforms and binning modes[J]. Nature Communications, 2025, 16(1): 2865.

Download files

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

Source Distribution

scgbinner-1.0.3.tar.gz (5.0 MB view details)

Uploaded Source

Built Distribution

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

scgbinner-1.0.3-py3-none-any.whl (5.1 MB view details)

Uploaded Python 3

File details

Details for the file scgbinner-1.0.3.tar.gz.

File metadata

  • Download URL: scgbinner-1.0.3.tar.gz
  • Upload date:
  • Size: 5.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.12

File hashes

Hashes for scgbinner-1.0.3.tar.gz
Algorithm Hash digest
SHA256 06c7d3ff87a2ad6d6f676d5faec3867c587c3b3062dc77cd46380630eeb0e5e9
MD5 163c0d9ed530be5e1767ea57c9083022
BLAKE2b-256 af5b822799d0f541d2a1b505c954bd434cce42bc7f4d45e01cccee46564d6ddc

See more details on using hashes here.

File details

Details for the file scgbinner-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: scgbinner-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 5.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.12

File hashes

Hashes for scgbinner-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 191ed87b0a99c177fedaa36dd8a368d0dfc9ede9c428174e58a01adeb373e987
MD5 861a20799e13826e2ea0d6c6fe89132d
BLAKE2b-256 bfb7dc38abd4b52ef2c3955486c76ede2578828c1c0ff1bd5c5efefe04b64430

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.4

2 files

This release

1.0.3 This release

2 files

Supported by

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