This is a test version of Biostars. For the public version, visit https://www.biostars.org.
bed file indexing problem

Hello

I have a bed file that looks like this:

Capture4

I would like to be able to retrieve data from it using samtools with tabix.

the actions I do:

bgzip sample.bed
tabix -s 1 -b 2 -e 3 sample.bed.gz
tabix sample.bed.gz chr1:19922842-19924305

but I have a problem after trying the second action, it returns this error:

Unsorted positions on sequence #1: 244318174 followed by 1179391

what can I do?

bed samtools tabix

1 answer

A BED has no header, so get rid of it, then sort it with sort -k1,1 -k2,2n, compress with bgzip and then retry to index.

Even though unix sort will probably be faster you could also sort sample.bed with bedtools (default parameters are probably fine)

bedtools sort -i sample.bed > sample_sorted.bed

In addition to the first row (header), you also need to drop the first column as BED format is defined with chr, start, end in the first three columns.

Log in to answer this question.