Go Back   SEQanswers > Bioinformatics > Bioinformatics

Similar Threads
Thread Thread Starter Forum Replies Last Post
GATK: sorting vcf file given a reference file jorge Bioinformatics 4 01-14-2015 01:16 PM
Splitting a bed file in multiple bed files by track albireo Bioinformatics 3 12-18-2014 12:58 PM
Finding the coordinate of combined bed file AnushaC Bioinformatics 0 11-15-2013 03:17 PM
Is there a BED file format validator? Does a BED file have to be sorted position? LauraSmith Bioinformatics 3 05-21-2013 12:54 PM
sorting sam file crh Bioinformatics 2 06-16-2011 07:45 AM

Thread Tools
Old 05-18-2014, 07:57 PM   #1
Location: San Francisco, CA

Join Date: Aug 2011
Posts: 91
Default Bed file coordinate sorting

Apparently, I don't quite understand how a bed file should be sorted. I can't quite figure out what's wrong.

bedops --ec --everything myData.bed > /dev/null
May use bedops --help for more help.

Error: in oncosnp.bed
Bed file not properly sorted by first column.
See row: 771

cat myData.bed | awk 'NR>=769' | head
9	138338321	138339032
9	139327439	140167730
10	69083	3368595
10	367632	393272
10	448018	448786
10	703003	763714
10	998193	999290
10	1084691	1123868
10	1368946	1369689
10	1500525	1503838

Any idea? How does the ordering rule work for bed files?

A related question: when I used bedtools and use the "-sorted" flag, how should that bed file be sorted?

Thanks in advance.

Last edited by lethalfang; 05-18-2014 at 08:06 PM.
lethalfang is offline   Reply With Quote
Old 05-19-2014, 02:56 AM   #2
Devon Ryan
Location: Freiburg, Germany

Join Date: Jul 2011
Posts: 3,480

You treated them as numbers, so they're in numeric order. However, they need to be in lexicographic order, since "10" as a word comes before "9" as a word (the normal order would be something like: 1, 10, 11 ... 19, 2, 3, ...). This will make more sense if you have chromosomes X and Y and/or MT (or are using UCSC chromosome names).
dpryan is offline   Reply With Quote
Old 05-19-2014, 04:12 AM   #3
Senior Member
Location: Cambridge, UK

Join Date: May 2010
Posts: 311

Originally Posted by lethalfang View Post
A related question: when I used bedtools and use the "-sorted" flag, how should that bed file be sorted?
Sort by chromosome (lexicograhic) then by position. Something like this will do

sort -k1,1 -k2,2n -k3,3n a.bed > asort.bed
(In fact I suspect that for -sorted option to work, what matters is that chromosomes are in the same order in both files).

By the way, if records within chromosomes are already sorted by position and so you just want to sort chromosomes, use the --stable option in sort. It will save quite some time for big files.
dariober is offline   Reply With Quote
Old 07-01-2014, 10:09 AM   #4
Location: Seattle, WA

Join Date: Feb 2013
Posts: 45

You can use BEDOPS sort-bed to sort BED files:

GNU sort is not as fast as sort-bed (even with various tricks, like --parallel and so forth) and it's easy to get the options wrong.
AlexReynolds is offline   Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

All times are GMT -8. The time now is 03:00 AM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Single Sign On provided by vBSSO