awk '{if ($2 > $3) print $1"\t"$3"\t"$2; else print $1"\t"$2"\t"$3}' old.bed > new.bed
I have a sorted bedfile comprised of three columns: seqid, start, and end.
sort -k1,1 -k2,2n tmp2.bed > tmp3.bed
1 6589256 6589207
1 11627195 12127194
1 12616616 12116617
1 18283067 18273068
1 21826932 21926931
1 28787213 28788212
1 31195434 31195483
1 39374350 39364351
1 42307024 42357023
1 47379997 47374998
~/tools/bedtools2/bin/bedtools merge -i tmp3.bed
Error: unable to open file or unable to determine types for file tmp3.bed
Probably something silly, but I'm not seeing it.
EDIT:
The second column - start must be before the end coordinates. It would be nice if bedtools threw an informative error as the user sucks.
3 answers
Another thing that will cause bedtools merge to produce this error is if the bed file contains an uncommented column header line such as:
chrom start end
1 243651534 243651752
1 243663020 243668636
1 243663020 243663088
1 243663038 243663088
Commenting the header with a leading # will make bedtools happy again:
#chrom start end
1 243651534 243651752
1 243663020 243668636
1 243663020 243663088
1 243663038 243663088
The bed file spec doesn't explicitly state anything about the legality of header lines or their expected format (e.g. should be preceded with '#'). Since the columns are proscribed for bed format, a header is not really necessary but can be convenient. Glad that bedtools supports it -- just don't forget to comment it!
bedtools version: 2.22.1
I get the same error messages:
How did you solved. Could you please help me. I appreciated your help
Sincerely,
Adriana
Thanks a lot
Solved: Some of the ends are before the starts. Stupid mistake.
Log in to answer this question.
What version of bedtools? Are you sure it is tab-delimited (check with
cat -t)?bedtools do throw such error messages:
I got this message using your example (bedtools v2.19.1).
That is weird because my version is above your version number and I didn't get that error.
bedtools v2.21.0-2-g6a92b11