help with bedToBam

787 views
Skip to first unread message

Arun

unread,
May 23, 2012, 3:49:56 AM5/23/12
to bedtools-discuss
hi,

I'm getting the following error while trying to convert my .bed file
to .bam


Error: BED entry without name found at line: 1. Exiting!


the command I gave in UNIX is:

bedToBam -i chr1.bed -g hg18.txt > chr1.bam

chr1.bed (bed file for only chromosome1) looks like this:

chr1 100000000 100000036
chr1 100000040 100000076
chr1 100000090 100000126
chr1 100000136 100000172
chr1 100000189 100000225
chr1 100000235 100000271
chr1 100000287 100000323
chr1 100000336 100000372
chr1 100000401 100000437
chr1 100000452 100000488
chr1 100000512 100000548..
.....

and hg18.txt looks like this:

chr1 247249719
chr10 135374737
chr11 134452384
chr12 132349534
chr13 114142980
chr14 106368585
chr15 100338915

thanks!

Ivan Gregoretti

unread,
May 23, 2012, 11:29:35 AM5/23/12
to bedtools...@googlegroups.com
That is a feature, not a bug.

See the last line in the help information:

$ bedtools bedtobam -h

Tool: bedtools bedtobam (aka bedToBam)
Version: v2.16.2
Summary: Converts feature records to BAM format.

Usage: bedtools bedtobam [OPTIONS] -i <bed/gff/vcf> -g <genome>

Options:
-mapq Set the mappinq quality for the BAM records.
(INT) Default: 255

-bed12 The BED file is in BED12 format. The BAM CIGAR
string will reflect BED "blocks".

-ubam Write uncompressed BAM output. Default writes compressed BAM.

Notes:
(1) BED files must be at least BED4 to create BAM (needs name field).


Ivan



Ivan Gregoretti, PhD

Aaron Quinlan

unread,
May 23, 2012, 11:42:36 AM5/23/12
to bedtools...@googlegroups.com
Ivan is right - this is intentional, as the BAM format requires that each alignment have a QNAME.

An alternative would be to just create a "dummy" name, which is just the line number in your file.

Just do:

awk '{print $0"\t"NR}' chr1.bed > chr1.bed4
bedToBam -i chr1.bed4 -g hg18.txt > chr1.bam

Aaron

Arun

unread,
May 24, 2012, 1:07:19 AM5/24/12
to bedtools-discuss
Thanks Dr. Gregoretti and Aaron!

It works nows. Appreciate your help.

Best,

arun
Reply all
Reply to author
Forward
0 new messages