本文へ移動
cccskills
無料GitHub で公開

bio-genome-assembly-metagenome-assembly

Assembles microbial-community sequencing into metagenome-assembled genomes (MAGs) with metaFlye (ONT), metaSPAdes/MEGAHIT (Illumina), and hifiasm-meta/metaMDBG (PacBio HiFi), then recovers genomes via multi-binner consolidation (MetaBAT2, MaxBin2, CONCOCT, SemiBin2, VAMB -> DAS_Tool) and QCs them against MIMAG with CheckM2, GUNC, and GTDB-Tk. Covers why a metagenome is not a genome (uneven coverage, micro-diversity, strain collapse to consensus), differential-coverage binning, co-assembly vs per-sample, the rRNA-operon collapse that fails short-read MAGs, and strain resolution with inStrain. Use when reconstructing genomes from a microbiome, soil, ocean, or gut community, recovering MAGs, or resolving strain-level variation.

インストール方法を見る

含まれるファイル(3)

  • SKILL.md19.5 KB
  • examples/metagenome_workflow.sh3.2 KB
  • usage-guide.md5.3 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

Version Compatibility

Reference examples tested with: Flye 2.9+, SPAdes 3.15+ (metaSPAdes), MEGAHIT 1.2+, hifiasm-meta 0.3+, metaMDBG 1.0+, MetaBAT2 2.15+, MaxBin 2.2.7+, CONCOCT 1.1+, SemiBin 2.0+, VAMB 4.1+, DAS_Tool 1.1.6+, CheckM2 1.0+, GUNC 1.0+, GTDB-Tk 2.4+, inStrain 1.7+, minimap2 2.26+, samtools 1.19+.

Before using code patterns, verify installed versions match. If versions differ:

  • CLI: <tool> --version then <tool> --help to confirm flags
  • Python: pip show <package> then help(module.function) to check signatures

GTDB-Tk results track the reference-package RELEASE (e.g. R214 vs R220); the DB release MUST match the GTDB-Tk binary or classification silently fails. CheckM2 and GUNC each download their own DIAMOND DB. SemiBin2's pretrained --environment models are versioned. If code throws an error, introspect the installed tool and adapt rather than retrying.

Metagenome Assembly

"Assemble genomes from my metagenome" -> Co-assemble a community at uneven, strain-mixed coverage, then bin the contigs into a set of consensus population genomes (MAGs) and QC each against MIMAG. The deliverable is MAGs, not a single assembly.

  • CLI: flye --meta --nano-hq reads.fq (ONT), spades.py --meta -1 R1.fq -2 R2.fq or megahit -1 R1.fq -2 R2.fq (Illumina), hifiasm_meta/metaMDBG (HiFi); then binners -> DAS_Tool -> checkm2 predict + gunc run + gtdbtk classify_wf

The Single Most Important Modern Insight -- A Metagenome Is Not a Genome; the Assembler Cannot Assume Uniform Coverage

Every isolate assembler is built on the premise that the true sequence sits at roughly one depth, so a coverage drop or spike signals a repeat or an error. In a community that premise is false by construction: an abundant species at 500x and a rare one at 3x are both real. Running plain SPAdes/Unicycler or single-genome Flye on a community treats the abundance spread and strain bubbles as errors to "fix" and produces garbage. Use --meta modes. Three consequences cascade:

  1. A MAG is a population consensus, not an organism's genome. Co-occurring strains differing by <1% ANI become bubbles the assembler collapses into one consensus path -- a sequence that may match no actual cell in the sample. A 99%-complete circular MAG is still the consensus of the dominant strain; minority-strain accessory genome is averaged away. Treat every per-strain, per-allele, or pangenome claim from a single consensus MAG as suspect until read-level microdiversity (inStrain) or strain-aware assembly confirms it.
  2. The deliverable is a community of MAGs, not one assembly -- a community has no N50. N50 is dominated by whichever few abundant genomes assembled well and says nothing about the community; a "better N50" assembly can have recovered fewer genomes. Report MAG count split by MIMAG tier (HQ/medium/low) and community fraction binned. Bigger total assembly size is not better -- it can mean more chimeras and strain-fragmentation.
  3. Modern practice is multi-binner -> consolidate -> CheckM2 + GUNC -> GTDB-Tk. Never trust one binner; run several (each weights composition vs coverage differently and recovers a partially-different genome set), reconcile with DAS_Tool, then QC every bin with CheckM2 AND GUNC (completeness lies about chimeras) before classifying against the MIMAG 90%/5% bar. HiFi/long reads are the single biggest quality jump: they span the conserved rRNA operons and strain bubbles short reads shred, yielding complete, circular, genuinely-HQ MAGs.

Assembler Taxonomy

ToolCitationMechanism / roleWhen
metaFlyeKolmogorov 2020 Nat Methodsrepeat-graph long-read meta-assembler (--meta mandatory)ONT/CLR community de novo; polish after
metaSPAdesNurk 2017 Genome Resstrain-aware multi-k de Bruijn (spades.py --meta)Illumina, contiguity priority; ONE paired library only
MEGAHITLi 2015 Bioinformaticssuccinct de Bruijn, low-memoryhuge/complex Illumina co-assemblies, soil; lower contiguity
hifiasm-metaFeng 2022 Nat Methodsstrain-resolved HiFi string graphPacBio HiFi communities; keeps strains apart
metaMDBGBenoit 2024 Nat Biotechnolminimizer de Bruijn for HiFiHiFi; often ~2x the HQ circular MAGs, low RAM
OPERA-MSBertrand 2019 Nat Biotechnolshort-read meta scaffolded by long readshybrid short + long

Binner Taxonomy

BinnerCitationSignalWhen
MetaBAT2Kang 2019 PeerJtetranucleotide freq (TNF) + coverage, parameter-freefast default workhorse (-m 1500)
MaxBin2Wu 2016 BioinformaticsEM over TNF + marker genes + coveragesingle/few samples
CONCOCTAlneberg 2014 Nat MethodsGMM on composition+coverage of cut-up contigsmany samples; 4-step pipeline, not one command
SemiBin2Pan 2023 Bioinformaticsself-supervised contrastive deep learningcurrent SOTA; short + long; pretrained env models
VAMBNissen 2021 Nat Biotechnolvariational autoencoder of coabundance + k-mermulti-sample; separates close strains
DAS_ToolSieber 2018 Nat Microbioldereplicate-aggregate-score across binners (consolidation)ALWAYS run; non-redundant set beats any single binner

Decision Tree by Scenario

ScenarioRecommendedWhy
Illumina, complex/huge/soil, low RAMMEGAHIT --presets meta-sensitivesuccinct dBG fits in memory; multi-library
Illumina, contiguity priority, tractable sizemetaSPAdes (spades.py --meta)strain-aware repeat resolution; merge libraries first (one paired lib only)
ONT-only communitymetaFlye --meta --nano-hq -> polishrepeat-graph meta mode; ONT needs polishing -> assembly-polishing
PacBio HiFi communityhifiasm-meta or metaMDBGcomplete circular strain-resolved MAGs; fixes rRNA collapse
Hybrid short + longOPERA-MSshort-read meta scaffolded with long reads
Recover MAGs (any assembly)>=2-3 binners -> DAS_Tool -> CheckM2 + GUNC -> GTDB-Tkensemble beats one binner; chimera + taxonomy gates
Only ONE samplecomposition-only binning, expect weak binsdifferential coverage needs multiple samples; add samples, not tuning
Multiple samples availablemap ALL samples to each assembly for binning depthdifferential-coverage is the strongest binning signal
Strain-level question-> inStrain on reads mapped to MAGsconsensus MAGs blur strains; needs read-level microdiversity
Read-based taxonomy / rare biosphere-> metagenomics/kraken-classificationassembly is blind below the abundance-detection limit
Reads not QC'd / host-contaminated-> long-read-sequencing/long-read-qcremove host reads vs a T2T reference before assembly
MAG contamination forensics-> contamination-detectiondetailed CheckM2/GUNC interpretation

metaFlye (ONT / Long Reads)

flye --meta --nano-hq ont.fastq.gz --out-dir flye_out -t 32
#   --meta        uneven-coverage metagenome mode (REQUIRED for communities)
#   read-type flag (mutually exclusive): --nano-hq (Guppy5+/Q20) | --nano-raw (older) |
#       --pacbio-hifi | --pacbio-raw (CLR)
# outputs: assembly.fasta, assembly_graph.gfa, assembly_info.txt (circularity flag in col 'circ.')

ONT contigs are contiguous but error-prone (indels in homopolymers); polish before downstream use (-> assembly-polishing; medaka needs the matching basecaller model). HiFi usually needs no polishing.

metaSPAdes / MEGAHIT (Illumina)

# metaSPAdes -- contiguity priority; exactly ONE paired library
spades.py --meta -1 R1.fastq.gz -2 R2.fastq.gz -o spades_out -t 32 -m 500
#   -m memory cap in GB (SPAdes aborts if exceeded); -k auto by default
# outputs: contigs.fasta, scaffolds.fasta

# MEGAHIT -- huge/low-RAM; accepts comma-separated multiple libraries
megahit -1 a1.fq.gz,b1.fq.gz -2 a2.fq.gz,b2.fq.gz -o megahit_out -t 32 \
        --presets meta-sensitive --min-contig-len 1000
#   --presets meta-sensitive | meta-large (huge complex); raise --min-contig-len to ~1000 for binning

metaSPAdes --meta supports exactly ONE paired-end library -- a real constraint people miss; concatenate libraries first or use MEGAHIT for many. metaSPAdes is heavier on RAM/time and chokes on soil-scale co-assembly; MEGAHIT assembled a 252 Gbp soil set on one node at the cost of somewhat more fragmentation.

HiFi (the transformative case)

hifiasm_meta -t 32 -o asm hifi.fastq.gz
awk '/^S/{print ">"$2"\n"$3}' asm.p_ctg.gfa > asm.p_ctg.fa   # GFA -> FASTA

metaMDBG asm --out-dir mdbg_out --in-hifi hifi.fastq.gz --threads 32   # often ~2x HQ circular MAGs

Coverage for Binning, then Bin

# Map reads back to the assembly -- per sample for differential coverage
minimap2 -ax map-ont -t 32 contigs.fa reads.fq.gz | samtools sort -@ 32 -o s1.sorted.bam -
samtools index s1.sorted.bam
jgi_summarize_bam_contig_depths --outputDepth depth.txt s1.sorted.bam s2.sorted.bam   # all samples

metabat2 -i contigs.fa -a depth.txt -o metabat/bin -m 1500 -t 32   # -m 1500 = min contig (do not go below ~1000)
run_MaxBin.pl -contig contigs.fa -abund abund1.txt -out maxbin/bin -thread 32 -min_contig_length 1000
SemiBin2 single_easy_bin -i contigs.fa -b s1.sorted.bam -o semibin_out   # add --environment human_gut for a pretrained model

CONCOCT is a 4-step pipeline (cut_up_fasta.py -> concoct_coverage_table.py -> concoct -> merge_cutup_clustering.py -> extract_fasta_bins.py), not one command. Differential-coverage binning needs MULTIPLE samples with abundance variation; with one sample binning collapses to weak composition-only signal -- more samples, not more tuning.

Consolidate (DAS_Tool), then QC

# Convert each binner's output to contig2bin tables, then aggregate-and-score
Fasta_to_Contig2Bin.sh -i metabat/ -e fa    > metabat.tsv
Fasta_to_Contig2Bin.sh -i maxbin/  -e fasta > maxbin.tsv               # MaxBin emits .fasta
gunzip -k semibin_out/output_bins/*.gz 2>/dev/null || true             # SemiBin2 bins are gzipped
Fasta_to_Contig2Bin.sh -i semibin_out/output_bins/ -e fa > semibin.tsv
DAS_Tool -i metabat.tsv,maxbin.tsv,semibin.tsv -l metabat,maxbin,semibin \
         -c contigs.fa -o dastool/DAS --write_bins -t 32
# DAS_Tool assumes the SAME contig set across binners -- feeding bins from different assemblies is a silent error

checkm2 predict --input dastool/DAS_DASTool_bins/ -x fa --output-directory checkm2_out -t 32
gunc run --input_dir dastool/DAS_DASTool_bins/ --file_suffix .fa --out_dir gunc_out --threads 32
gtdbtk classify_wf --genome_dir dastool/DAS_DASTool_bins/ -x fa --out_dir gtdbtk_out --cpus 32

Run CheckM2 AND GUNC: CheckM2 counts marker copy number (completeness/contamination), GUNC tests whether a genome's genes share one lineage (chimerism). A bin made of two half-genomes can score high completeness, low contamination, and still be a chimera -- GUNC is the orthogonal catch. Dereplicate MAGs across samples (dRep ~95% ANI species, ~99% strain) before reporting counts.

Strain Resolution

# Consensus MAGs blur strains; recover read-level microdiversity
inStrain profile sample.sorted.bam mags.fa -o instrain_out -p 16 -g genes.fna
inStrain compare -i instrain_A instrain_B -o instrain_compare   # popANI: shared-strain detection across samples

Per-Method Failure Modes

Isolate assembler on a community

Trigger: plain spades.py/flye (no --meta) on community reads. Mechanism: uniform-coverage assumption deletes rare-taxon contigs and mis-resolves strain bubbles as errors. Symptom: few short contigs, missing abundant taxa. Fix: --meta mode for every meta-assembler.

Single-binner pipeline

Trigger: "we used SemiBin2 because it's SOTA," one binner. Mechanism: each binner recovers a partially-different genome set. Symptom: real MAGs left on the table; lower count than peers. Fix: run >=2-3 binners -> DAS_Tool consolidation.

Single-sample differential-coverage expectation

Trigger: MetaBAT2/CONCOCT on one sample, surprised bins are bad. Mechanism: one coverage value -> composition (TNF) only, which is weak (related genera share TNF). Symptom: poor, split bins. Fix: more samples with abundance variation, then map all back; do not retune.

Short-read MAG reported HQ on 90/5 alone

Trigger: calling a 95%-complete/2%-contam short-read MAG "high-quality." Mechanism: conserved + multi-copy rRNA operon tangles the short-read graph and stays unbinned. Symptom: MAG fails MIMAG HQ for missing 16S/23S/5S despite great completeness. Fix: check the FULL MIMAG HQ definition (rRNA + tRNA); use HiFi/long reads to span the operon.

High CheckM2 completeness read as quality

Trigger: trusting completeness/contamination alone. Mechanism: non-overlapping markers from two half-genomes score high completeness, low contamination. Symptom: "clean" MAG that is a chimera. Fix: always pair CheckM2 with GUNC -> contamination-detection.

Strain claims from a consensus MAG

Trigger: per-allele/per-strain interpretation of one MAG. Mechanism: the assembler collapsed strains to consensus. Symptom: strain findings that read-level data contradict. Fix: inStrain popANI or strain-aware (hifiasm-meta) assembly.

Reading MAG richness as community richness

Trigger: "200 MAGs cover 60% of reads" treated as the whole community. Mechanism: the rare biosphere never crosses the assembly detection limit. Symptom: species richness massively undercounted. Fix: complement with read-based profiling -> metagenomics/kraken-classification.

Quantitative Thresholds

ThresholdSourceRationale
MIMAG high-quality: completeness >90%, contamination <5%, AND 16S/23S/5S rRNA + >=18 tRNAsBowers 2017 Nat BiotechnolrRNA criterion is the silent killer; short-read MAGs fail it
MIMAG medium-quality: completeness >=50%, contamination <10%Bowers 2017most short-read MAGs land here
Min contig length for binning ~1000-1500 bpMetaBAT2 default 1500shorter contigs have unreliable TNF/coverage -> noise/chimeras
Differential-coverage binning needs N >= ~3-5 samples with abundance variationbinning practiceone coverage value cannot separate co-abundant genomes
Assembly detection limit ~3-5x coveragede Bruijn requirementbelow this the rare biosphere does not assemble at all
MAG dereplication 95% ANI (species), 99% (strain)dRep/ANI conventioncollapse redundant per-sample MAGs before counting
metaSPAdes input: exactly ONE paired library--meta constraintmerge libraries or use MEGAHIT for many
N50 / contiguitynot a community metricreport MAG count + MIMAG tiers instead

Common Errors

Error / symptomCauseSolution
Few short contigs, missing abundant taxaisolate mode on a communityadd --meta
metaSPAdes rejects multiple libraries--meta supports one paired libraryconcatenate, or use MEGAHIT
metaSPAdes aborts / out of memoryRAM cap hit on a complex co-assemblyraise -m, or switch to MEGAHIT
Poor bins from one sampleno differential-coverage signaladd samples; map all back for depth
"HQ MAG" lacks rRNArRNA-operon collapse in short readsfull MIMAG check; HiFi/long reads
Clean CheckM2 but suspect binchimera invisible to marker countsrun GUNC alongside CheckM2
GTDB-Tk classify_wf errorsDB release != binary versionmatch the GTDB reference-package release
Strain finding not reproducibleconsensus MAG blurs strainsinStrain popANI / strain-aware assembly

References

  • Nurk S, Meleshko D, Korobeynikov A, Pevzner PA. 2017. metaSPAdes: a new versatile metagenomic assembler. Genome Res 27:824-834.
  • Li D, Liu CM, Luo R, Sadakane K, Lam TW. 2015. MEGAHIT: an ultra-fast single-node solution for large and complex metagenomics assembly via succinct de Bruijn graph. Bioinformatics 31:1674-1676.
  • Kolmogorov M, et al. 2020. metaFlye: scalable long-read metagenome assembly using repeat graphs. Nat Methods 17:1103-1110.
  • Feng X, Cheng H, Portik D, Li H. 2022. Metagenome assembly of high-fidelity long reads with hifiasm-meta. Nat Methods 19:671-674.
  • Benoit G, et al. 2024. High-quality metagenome assembly from long accurate reads with metaMDBG. Nat Biotechnol 42:1378-1383.
  • Bertrand D, et al. 2019. Hybrid metagenomic assembly enables high-resolution analysis of resistance determinants and mobile elements in human microbiomes (OPERA-MS). Nat Biotechnol 37:937-944.
  • Kang DD, et al. 2019. MetaBAT 2: an adaptive binning algorithm for robust and efficient genome reconstruction from metagenome assemblies. PeerJ 7:e7359.
  • Wu YW, Simmons BA, Singer SW. 2016. MaxBin 2.0: an automated binning algorithm to recover genomes from multiple metagenomic datasets. Bioinformatics 32:605-607.
  • Alneberg J, et al. 2014. Binning metagenomic contigs by coverage and composition (CONCOCT). Nat Methods 11:1144-1146.
  • Pan S, Zhao XM, Coelho LP. 2023. SemiBin2: self-supervised contrastive learning leads to better MAGs for short- and long-read sequencing. Bioinformatics 39:i21-i29.
  • Nissen JN, et al. 2021. Improved metagenome binning and assembly using deep variational autoencoders (VAMB). Nat Biotechnol 39:555-560.
  • Sieber CMK, et al. 2018. Recovery of genomes from metagenomes via a dereplication, aggregation and scoring strategy (DAS_Tool). Nat Microbiol 3:836-843.
  • Chklovski A, et al. 2023. CheckM2: a rapid, scalable and accurate tool for assessing microbial genome quality using machine learning. Nat Methods 20:1203-1212.
  • Orakov A, et al. 2021. GUNC: detection of chimerism and contamination in prokaryotic genomes. Genome Biol 22:178.
  • Chaumeil PA, Mussig AJ, Hugenholtz P, Parks DH. 2020. GTDB-Tk: a toolkit to classify genomes with the Genome Taxonomy Database. Bioinformatics 36:1925-1927.
  • Bowers RM, et al. 2017. Minimum information about a single amplified genome (MISAG) and a metagenome-assembled genome (MIMAG) of bacteria and archaea. Nat Biotechnol 35:725-731.
  • Olm MR, et al. 2021. inStrain profiles population microdiversity from metagenomic data and sensitively detects shared microbial strains. Nat Biotechnol 39:727-736.

Related Skills

  • contamination-detection - CheckM2/GUNC interpretation and chimerism forensics for MAGs
  • assembly-qc - Isolate-assembly QC; the uniform-coverage assumption metagenomes abandon
  • assembly-polishing - Polish ONT/CLR meta-contigs before binning (HiFi usually needs none)
  • metagenomics/kraken-classification - Read-based taxonomy; recovers the rare biosphere assembly cannot
  • metagenomics/abundance-estimation - Community abundance downstream of recovered MAGs
  • metagenomics/functional-profiling - Functional potential complementary to genome recovery
  • long-read-sequencing/long-read-qc - Read-level QC and host removal before assembly

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

生成图文并茂的分析报告/实验报告/质检报告(固定模版)。当用户要求"生成报告/总结报告/实验报告/质检报告/QC报告",或分析流程收尾需要交付报告时使用。报告必须基于真实分析输出,包含固定章节结构、关键指标表格和真实结果图。

日本語の概要は準備中です。原文の説明を表示しています。

peacezha/TRACE32026年10月11日 更新

Predicts ADMET properties using ADMETlab 3.0 (119 endpoints with uncertainty), ADMET-AI, DeepChem MolNet, and chemprop D-MPNN with explicit handling of OECD QSAR principles, applicability domain assessment, calibration, hERG/CYP/AMES gold-standard endpoints, and PAINS / Lipinski / Ro5 / Veber / BBB druglikeness filters. Use when filtering compounds for drug-likeness, prioritizing leads by predicted safety, or building an in-house ADMET QSAR model.

日本語の概要は準備中です。原文の説明を表示しています。

peacezha/TRACE32026年10月11日 更新

Trim PCR primers from aligned reads in amplicon-panel BAMs using samtools ampliconclip. Use when processing SARS-CoV-2 ARTIC, hereditary cancer panels, ctDNA hot-spot panels, or any amplicon assay where primer-derived bases would falsely confirm reference at primer footprints.

日本語の概要は準備中です。原文の説明を表示しています。

peacezha/TRACE32026年10月11日 更新

Filter alignments by flags, mapping quality, and regions using samtools view and pysam. Use when extracting specific reads, removing low-quality alignments, or subsetting to target regions.

日本語の概要は準備中です。原文の説明を表示しています。

peacezha/TRACE32026年10月11日 更新

Create and use BAI/CSI indices for BAM/CRAM files using samtools and pysam. Use when enabling random access to alignment files or fetching specific genomic regions.

日本語の概要は準備中です。原文の説明を表示しています。

peacezha/TRACE32026年10月11日 更新

Read, write, and convert multiple sequence alignment files using Biopython Bio.AlignIO. Supports Clustal, PHYLIP, Stockholm, FASTA, Nexus, and other alignment formats for phylogenetics and conservation analysis. Use when reading, writing, or converting alignment file formats.

日本語の概要は準備中です。原文の説明を表示しています。

peacezha/TRACE32026年10月11日 更新

peacezha のスキルをすべて見る

このスキルの問題を報告する