Try 3 things:
1) Instead of:
closestBed -a a.bed -b b.bed -D b > c.bed
use
closestBed -a a.bed -b b.bed -D "b" > c.bed
2) Check that your file is formatted properly (are marina suggested):
head a.bed
head b.bed
if you don't get something like what you put above then do:
cat a.bed | tr '\r' '\n' > a_v2.bed #removes carriage returns and makes a new line
or if it's not tab delimited
cat a.bed | tr '--> x <--' '\t' #where --> x is your separator is, i.e. ' ' (space) ',' (comma) etc...
3) Sort the file
sort -k1,1 -k2,2n a.bed > a_sorted.bed
--->> EDIT <<---
I just copy/pasted your input which looks like space delimited, I converted it to tab delimited:
cat a.bed | tr ' ' '\t' > a2.bed
cat b.bed | tr ' ' '\t' > b2.bed
then used closestBed:
closestBed -a a2.bed -b b2.bed -D "b"
which gave me
chr1 631977 631979 -2.777777778 chr1 17435 17436 MIR6859-3 0 - -614542
chr1 631994 631996 31.5625 chr1 17435 17436 MIR6859-3 0 - -614559
Thanks guys. The spaces were inappropriately added by awk:
There were no spaces in
b.txt
. Any suggestion?Can we have a snapshot of the
b.txt
file? You can edit your answer and add it there.No commas in awk (your script puts spaces (comma) and tabs but you need only tabs: