Module 4: Bin refinement¶

module_4_binrefinement.nf collects Module 3 bins, predicts genes with
Prodigal, searches marker proteins with HMMER, runs MAGScoT, and reconstructs
refined MAG FASTAs. The intended input is compatible bin output from more than
one binner. Module 3 normally supplies quickbin, metabat2, and maxbin2.
Using only one binner does not provide the multiple-binner comparison required
for meaningful refinement.
Usage¶
nextflow run module_4_binrefinement.nf \
--working_dir ./output_samwise \
--magscot_threshold 0
# Use `--` for additional MAGScoT flags passed through by the workflow.
--threads is also accepted as an HMMER-only thread override, for example:
The original MAGScoT threshold is 0.5. SAMWISE defaults to 0 so that all
possible MAGs are retained for downstream GTDB and CheckM evaluation; use
--magscot_threshold 0.5 when the stricter original threshold is desired.
The value must be between 0 and 1.
Input Manifest¶
By default, the workflow reads:
<results_dir>/module_3_binning/summary/binning_manifest.tsv
Use --input_binning_manifest to provide another manifest. It must be a
tab-separated file with these columns:
| Column | Description |
|---|---|
bin_id |
Identifier for the source bin. If empty, a generated identifier is used. |
binner |
Binner name, normally quickbin, metabat2, or maxbin2. |
bin_fasta |
Path to the bin FASTA file; .gz FASTA is supported. |
Rows without bin_fasta are ignored. Relative bin_fasta paths are resolved
relative to the Nextflow launch directory, not the task directory. Missing
source FASTAs are skipped and counted in mag_collection_stats.tsv.
Processing¶
- Gather the manifest's bin FASTAs into
gathered_bins/and create a combinedmag_contigs.faplus combined and per-binner contig-to-bin tables. - Run Prodigal in metagenome mode (
-p meta) on the combined FASTA, producing protein, nucleotide, and GFF files. - Run HMMER
hmmsearchagainst the GTDB rel207 TIGRFAM and Pfam databases with--cut_nc, usingthreadsorhmm_threadsCPUs. These parameters control HMMER only; they do not set the CPU count for Prodigal, MAGScoT, or the setup process. The resulting marker table is passed to MAGScoT. - Run
bin/MAGScoT.pywith the combined contig-to-bin table, marker table, GTDB rel207 default marker profiles, the configured threshold, and anymagscot_extra_args. - Reconstruct one FASTA per refined MAGScoT assignment and write the refined bin manifest and statistics.
Dependencies¶
The default dependency root is ${samwise_dir}/dependencies. The workflow
uses:
python,pandas,r-base,r-optparse,r-dplyr,r-readr,r-funr, andr-digest.- HMMER (
hmmsearch), Prodigal, and GNU Parallel. gtdbtk_rel207_tigrfam.hmmandgtdbtk_rel207_Pfam-A.hmmfor marker searches.gtdb_rel207_default_markers.tsvin the selected MAGScoT profiles directory.bin/MAGScoT.py.
If the configured tool environment is absent or fails its checks, the workflow
creates it with mamba or conda when auto_install is true. With
auto_install set to false, the required tools and packages must already be
available. HMM and MAGScoT paths can be overridden explicitly with the path
parameters below.
Best-Effort Behavior¶
MAGScoT is intentionally best-effort. Empty contig-to-bin input or an empty
HMM table causes MAGScoT to be skipped with a status record. A nonzero MAGScoT
exit is recorded as failed_nonfatal and does not fail the workflow. If no
refined assignments are available, the reconstruction step writes an empty
refined manifest and stats instead of refined FASTAs.
Missing required input manifests, tools, HMM databases, or the MAGScoT script
are not silently accepted. The default profile file is also required: if
contig and HMM inputs are non-empty and
gtdb_rel207_default_markers.tsv is missing from the selected profiles
directory, the MAGScoT process exits nonzero and the workflow fails. This
profile validation occurs before MAGScoT's nonzero execution status is treated
as failed_nonfatal. Empty contig or HMM input is checked first and skips
MAGScoT without validating the script or profile. Prodigal and HMMER failures
are workflow failures. Always review the Module 4 summary and refined manifest
before running Module 5 or Module 6; those modules require usable refined MAGs.
Parameters¶
| Argument | Default | Description |
|---|---|---|
working_dir |
null |
Results root. Module 4 outputs are written to <working_dir>/module_4_binrefinement. If omitted, it inherits samwise_dir. |
samwise_dir |
null |
SAMWISE source directory containing the workflows, bin/, and dependencies/. If omitted, it defaults to the directory containing the launched workflow. |
input_binning_manifest |
null |
Input binning manifest, normally Module 3's summary/binning_manifest.tsv. |
dependencies_dir |
${samwise_dir}/dependencies |
Directory containing Module 4 dependency files. |
tigrfam_hmm |
null |
Path to the TIGRFAM HMM database. If unset, the workflow searches the dependency directory for the GTDB rel207 file. |
pfam_hmm |
null |
Path to the Pfam HMM database. If unset, the workflow searches the dependency directory for the GTDB rel207 file. |
magscot_script |
null |
Path to the MAGScoT script. If unset, the workflow checks ${samwise_dir}/bin/MAGScoT.py, then ${samwise_dir}/bin/magscot.py; it does not search the dependency directories for the script. |
magscot_profiles_dir |
null |
Directory containing MAGScoT marker profiles. If unset, the workflow selects the first existing path in this order: ${dependencies_dir}/, ${samwise_dir}/dependencies/, ${dependencies_dir}/MAGScoT_profiles, then ${samwise_dir}/dependencies/MAGScoT_profiles. The selected directory must contain gtdb_rel207_default_markers.tsv; the lookup does not search within an already-selected directory. |
auto_install |
true |
Automatically install required tools with mamba or conda when needed. |
tool_env_dir |
null |
Optional custom path for the Module 4 conda environment. |
threads |
null |
HMMER-only thread override; takes precedence over hmm_threads and does not change Prodigal, MAGScoT, or setup threads. |
hmm_threads |
8 |
HMMER thread count when threads is not provided. |
r_base_version |
null |
r-base version to install/use. |
hmmer_version |
null |
HMMER version to install/use. |
prodigal_version |
null |
Prodigal version to install/use. |
parallel_version |
null |
GNU Parallel version to install/use. |
magscot_extra_args |
"" |
Additional arguments passed directly to MAGScoT. |
magscot_threshold |
0 |
MAGScoT minimum completeness threshold; must be between 0 and 1. |
publish_gathered_bins_mode |
copy |
Publication mode for gathered bins: symlink, copy, or move. |
publish_refined_bins_mode |
copy |
Publication mode for refined bins: symlink, copy, or move. |
results_dir |
derived | Internal results root derived from the resolved working_dir. |
module3_outdir |
<results_dir>/module_3_binning |
Expected Module 3 output directory. |
outdir |
<results_dir>/module_4_binrefinement |
Module 4 output directory. |
Outputs and Paths¶
The primary downstream contract is:
summary/magscot_refined_bins_manifest.tsv, with columnsrefined_bin_id,refined_bin_fasta,contig_count, andtotal_bp.refined_bins/, containing the reconstructed*.fafiles referenced by that manifest.
Other published outputs include:
gathered_bins/andsummary/mag_collection_manifest.tsv/mag_collection_stats.tsv.concat/mag_contigs.fa, with the combined contig-to-bin table also retained in the MAGScoT publication inputs.prodigal/Prodigal outputs andhmm/HMMER outputs.magscot/MAGScoT inputs and outputs.setup/,logs/, andsummary/status and run-summary files, includingmodule4_run_summary.tsv,prodigal_status.tsv,hmm_status.tsv,magscot_status.tsv, andmagscot_refined_bins_stats.tsv.
Published bin directories under outdir are cleaned before the run. The
publication modes apply to gathered_bins/ and refined_bins/; status,
summary, logs, and intermediate outputs are published by the workflow in copy
mode.
Validation¶
Before continuing downstream, confirm that:
summary/module4_run_summary.tsvand the individual status files show the expected completed or intentionally skipped states.summary/magscot_refined_bins_manifest.tsvexists and contains usable non-emptyrefined_bin_fastaentries.- The referenced FASTAs exist under
refined_bins/and have contigs. mag_collection_stats.tsvdoes not show an unexpected number of missing source bins, and a completed HMMER run reports TIGRFAM/Pfam hits.
An empty refined manifest is a valid best-effort result, but it is not a usable input for Module 5 or Module 6 and should be investigated before proceeding.