Tuesday, September 6, 2011

Convert BED to BAM format

BAM file has become the standard format for sequence alignment file.
Occasionally, we will see that we have BED file in hand, however some programs can only recognize BAM file. So, we need a way to convert the BED format to BAM format.

BedTools is a nice tool for this purpose. Download BedTools and install it in your computer.

Below is the command of how you can convert BED to BAM using bedTools:
bedToBam -i input.bed -g hg18.txt > input.bam

You need to create the genome file (in this case hg18.txt). This file should contains the chromosome name and the length of the chromosome.
The excerpt from hg18.txt:

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

2 comments:

  1. what is the format for the hg18.txt?
    I tried the following:

    chr3 160039680
    chr4 156508116
    chr9 124595110
    chr11 122082543

    but the system gave the following error message:
    "less than the required two fields encounter in the genome file at line 1. exiting"

    ReplyDelete
  2. got it, should add tab between chr3 and 160039680.

    ReplyDelete