This is a test version of Biostars. For the public version, visit https://www.biostars.org.
bedmap output on one line

I am using:

bedmap --echo --skip-unmapped --delim '\t' --echo-map-id-uniq sort_3column_xgen_targets.bed sort_gene.bed > answer.bed

answer.bed

chr1    957570    957852     
        NOC2L
chr1    976034    976270    
        PERM1
chr1    976542    976787     
        PERM1

Is there a way that using that command answer.bed can look like (entries on one line):

answer.bed

chr1    957570    957852     NOC2L
chr1    976034    976270     PERM1
chr1    976542    976787     PERM1

Using Ubuntu 12.0.4 and opening the file in gedit. Thank you.

bedops

1 answer

That shouldn't happen. Is there something weird about your inputs? (Are they coming out of Excel?)

Maybe use cat -et file and make sure that your input files have proper line endings and tab delimiters.

$ head -10 a.bed | cat -et
chr1^I15167^I15168^Iid-001$
chr1^I15168^I15169^Iid-002$
chr1^I15169^I15170^Iid-003$
...

If you have metacharacters other than ^I (tab) and $ (newline), you'll need to apply some fixes with sed, awk, dos2unix or similar.

Yes the bed was an excel document and it looks like I will need to use dos2unix or awk to apply a fix. Thanks :).

head -10 answer.bed | cat -et
chr1^I957570^I957852^M^INOC2L$
chr1^I976034^I976270^M^IPERM1$
chr1^I976542^I976787^M^IPERM1$
chr1^I978907^I979122^M^IPERM1$
chr1^I979192^I979413^M^IPERM1$
chr1^I979478^I979647^M^IPERM1$
chr1^I979703^I979829^M^IPERM1$
chr1^I980530^I980667^M^IPERM1$
chr1^I980728^I980913^M^IPERM1$
chr1^I981102^I981266^M^IPERM1$

Something like this maybe

awk '{ sub("\r$", ""); print }' answer.bed > unix_answer.bed

You can also use sed:

$ sed 's/\r//' foo.bed > foo_fixed.bed

Instead of fixing the output, you might first take a look at your input files and fix those. Either way, it looks like you have some bad characters coming in from Excel, before you use BEDOPS.

Thank you very much :).

Log in to answer this question.