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.4.tar.gz (2.9 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.4-py3-none-any.whl (3.0 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: scgbinner-1.0.4.tar.gz
  • Upload date:
  • Size: 2.9 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.4.tar.gz
Algorithm Hash digest
SHA256 4d6aac0204af59f5c55a5d6e4749fbf738a0199a9eae97c6c4c59d0050d0a777
MD5 ec2b7608536cbc0385e72be3d5796adc
BLAKE2b-256 b0e4380997ef84cd6b43c0cdd75c1dfc4f5155a58c9b1893814f073df47dfee4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scgbinner-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 3.0 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1212e2f282cd0594ed5babee955e6de6fbbfaa05c6f07933277272985bba0bd4
MD5 a201c02872d4aa79e40edb663d2b9d37
BLAKE2b-256 f24edeae4e9362fc03fb91ce4e830fdb87b5110cb01e7ad2591b6cab4886372a

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.4 This release

2 files

1.0.3

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