Hello,
I was assembling metagenomic reads into contigs and binning contigs with MegaHIT and MetaBAT2, and noticed that the depth file from jgi_summarize_bam_contig_depths contained negative depths in the totalAvgDepth column. So when I ran metabat2 command, I got a warning:
[Warning!] Negative coverage depth is not allowed for the contig k141_141795, column 1: -1.46002e+09
[Warning!] Negative coverage depth is not allowed for the contig k141_171645, column 1: -6.6807e+08
All of my samples contained 2-3 such contigs. Additionally, the jgi_summarize_bam_contig_depths showed this warning:
WARNING: your aligner reports an incorrect NM field. You should run samtools calmd! nm < ins + del: cmatch=0 nm=13 ( insert=0 + del=55 + mismatch=13 == 68) A00609:874:HC557DSX7:3:2371:5864:9079
I thought that the incorrect NM field could have caused the depths to be negative. But when I ran
samtools calmd -b sample1_bothReadsMapped_sorted.bam sample1_final.contigs.fa \
> sample1_mapped_and_unmapped_fixed.bam
I kept getting such errors for every contig:
[bam_fillmd] fail to find sequence 'k141_231346 flag=0 multi=126.6091 len=1937' in the reference.
[W::fai_get_val] Reference k141_231346 flag=0 multi=126.6091 len=1937 not found in FASTA file, returning empty sequence
The question is: How can the negative depths and the NM field be fixed? I would appreciate your help.
My command for Metabat2 (it was a for loop on many samples, but this is the basic example) was:
metabat2 -i sample1.final.contigs.fa \
-a depth.txt \
-o sample1_bins/sample1_bin \
-v
And the jgi_summarize_bam_contig_depths command (also a for loop) was:
jgi_summarize_bam_contig_depths --percentIdentity 97 \
--minContigLength 1000 \
--minContigDepth 1.0 \
--referenceFasta sample1_final.contigs.fa \
sample1_bothReadsMapped_sorted.bam \
--outputDepth sample1.depth.txt
The BAM file was sorted (I checked with samtools view -H sample1_bothReadsMapped_sorted.bam |grep "SO:coordinate" and got only @HD VN:1.4 SO:coordinate).
I am using metabat2 with conda on Windows subsystem for Linux.
Thank you very much! I built a docker image, and jgi_summarize_bam_contig_depths created depth files without negative values.