Binning I: Bin with multiple tools¶
Objectives
Overview¶
With the mapping information computed in the last exercise, we can now perform binning. There are a multitude of good binning tools currently published, and each have their strengths and weaknesses. As there is no best tool for binning, the current strategy for binning is to use a number of different tools on your data, then use the tool DAS_Tool to evaluate all potential outcomes and define the best set of bins across all tools used.
In our own workflow, we often use the tools MetaBAT and MaxBin for binning, but there are many alternatives that are equally viable. In the interests of time, we are only going to demonstrate one alternative, MetaDecoder. We recommend that you experiment with several tools when conducting your own research:
MetaBAT¶
MetaBAT binning occurs in two steps. First, the bam files from the last exercise are parsed into a tab-delimited table (tsv file) of the average coverage depth and variance per sample mapped. Binning is then performed using this table.
The .bam files can be passed in via either a user-defined order, or using wildcards.
Remember to update <YOUR FOLDER> to your own folder
Terminal
Both manual and wildcard commands in the code block above give the same result, although the order samples are processed in may vary.
Bash wildcards
The question mark ? is also a Bash wildcard. The difference between ? and * is that:
?represents any character once*represents any character zero or more times
The reason we use a ? here instead is because if you did the SPAdes contig mapping with the for loop AND with the array, you will capture each sample twice (i.e., sample1.bam and sample1_a.bam) with the asterisk *. For this exercise, we really want each sample file to be counted only once.
tsv files
Tab separated value files with the extension .tsv will be displayed in tabular layout by JupyterLab when opening the file from the Jupyter file browser and can also easily be loaded into Excel or LibreOffice Calc.
In this case, the file reports the average coverage of contigs per sample mapped and the respective variance.
We can then pass the table metabat.tsv into the MetaBAT binning tool.
Before we proceed, note that when you run MetaBAT on NeSI you will see the text GIT-NOTFOUND appear in your command line. This has no impact on the performance of the tool.
Run MetaBAT
Note that many metagenomic software tools utilise stochastic processes and therefore make use of random numbers at some point. As a consequence, the results are usually not fully reproducible, i.e., different runs may result in slightly different bins. Often the software tools provide an option to supply a seed for the random number generator, which would be a machine generated random number otherwise. If you want to receive the same deterministic result with every run you will need to provide the same random number seed. For clustering with MetaBAT2 this can be achieved with the --seed option.
Note also that we are specifying a minimum contig size of 1,500 bp, which is the lower limit allowed by the authors of MetaBAT. This is larger than the minimum threshold of 1,000 bp when we filtered the assembly, which means there are some assembled contigs which cannot be binned. Consider the choice of this parameter and your initial contig filtering carefully when binning your own data.
When specifying the output file, notice that we pass both a folder path (metabat/) and file name (metabat). The reason I do this is that MetaBAT writes its output files using the pattern
[USER VALUE].[BIN NUMBER].fa
If we only provided the path, without a file name prefix, MetaBAT would create output like the following:
The problem with this is that on Linux systems, prefixing a file or folder name with a '.' character means the the file is hidden. This can lead to a lot of confusion when your binning job completes successfully but no files are visible!
MaxBin¶
Like MetaBAT, MaxBin requires a text representation of the coverage information for binning. Luckily, we can be sneaky here and just reformat the metabat.tsv file into the format expected by MaxBin. We use cut to select only the columns of interest, which are the contigName and coverage columns, but not the contigLen, totalAvgDepth, or variance columns.
We can inspect the metabat.tsv file with head or less to identify the correct column indices for cut. (Using JupyterLab, we could also open the file directly from the file explorer.)
Terminal output: Snapshot of metabat.tsv
contigName contigLen totalAvgDepth sample1.bam sample1.bam-var sample2.bam sample2.bam-var sample3.bam sample3.bam-var sample4.bam sample4.bam-var
NODE_1_length_1221431_cov_0.752208 1.22143e+06 18.9178 3.55592 3.51379 10.865 11.3668 4.49688 4.51001 0 0
NODE_2_length_871377_cov_1.172283 871377 29.4909 6.14223 6.1249 2.81105 2.77014 20.5376 20.6339 0 0
NODE_3_length_835083_cov_0.372452 835083 9.2898 1.79405 1.74475 4.2584 4.19122 3.23735 3.23068 0 0
NODE_4_length_803085_cov_0.518929 803085 13.054 2.63945 2.65518 2.53475 2.48676 7.87984 8.38717 0 0
NODE_5_length_686960_cov_0.527949 686960 13.2164 2.64157 2.98377 2.59676 2.90338 7.97809 10.8339 0 0
NODE_6_length_607162_cov_1.000759 607162 25.0853 16.7701 17.576 2.759 2.74899 5.55618 5.69041 0 0
Generally speaking, this pattern of first, fourth, then [n + 2]th should work for any number of mapping files, although we always recommend that you check and confirm before you continue.
This table is then passed to MaxBin. Unlike the case with MetaBAT, if we want to direct the output files into a folder, we must create that folder in advance.
Remember to update <YOUR FOLDER> to your own folder
slurm script
MaxBin runtime
This will take a bit longer to complete, as MaxBin uses gene prediction tools to identify the ideal contigs to use as the start of each bin.
MetaDecoder¶
MetaDecoder binning occurs in three steps. The MetaDecoder software package contains all required tools. First, as with MetaBAT, the bam files are parsed into a tab-delimited table of average coverage depths. Then single-copy marker genes are mapped to the assembly to generate seed sequences for the clustering bins. Finally, clustering is performed using the coverage table, the seed file, and internally calculated compositions (k-mer frequencies).
Note that in order to get fully reproducible results with MetaDecoder the --random_number parameter should be set (cf. --seed for MetaBAT2).
Note also that we are specifying a minimum contig size of 2,000 bp, which is the lower limit allowed for MetaDecoder, the default value would have been 2,500 bp.
Remember to update <YOUR FOLDER> to your own folder
slurm script