This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Unable to intersect BAM file with bedtools

Hi everyone, I'm trying to use bedtools intersect to check the number of mapped reads in target regions (in a .bed file) originated by targeted bisulfite sequencing experiment (EpiSeq Roche).

I used the following command.

./bedtools intersect -bed -abam sample2.bam -b 
 ~/Data/MethylSeq/dataset/Agesmoke_dataset/AgeSmkSop_all_primary_targets.bed

The program terminate with the following message and no result at all.

* WARNING: File sample2.bam has inconsistent naming convention for record:
NC_000016.9  24163386  24163537  M03971:33:000000000-BN5NL:1:2114:12003:16132/1  255  +

* WARNING: File sample2.bam has inconsistent naming convention for record:
NC_000016.9  24163386  24163537  M03971:33:000000000-BN5NL:1:2114:12003:16132/1  255  +

I tried to modify the original SAM file removing the read that cause the problem (that was the first read in the SAM file) and the problem persists with the second read. I tried also the option -nonamecheck with no results.

Can someone help us? Thank you.
Nicola

bedtools

Is that line starting with NC_000016.9 supposed to be from the .bam file?

Hi, the problem was that in the .bed file chromosome's names was like "chr1, chr2...", while the .bam files use the "NCBI names" (NC_000001.10 etc). I resolved the issue renaming chromosomes in .bed file!

1 answer

Here's another option, using BEDOPS bedmap and bam2bed:

$ bedmap --echo --count --delim '\t' regions.bed <(bam2bed < reads.bam) > answer.bed

The last column in answer.bed will contain the number of reads in reads.bam that overlap each region in regions.bed by one or more bases.

Log in to answer this question.