Field search in BED
1
0
Entering edit mode
8.5 years ago
rishi ▴ 10

Hi. I am an amateur undergraduate computational biologist so please cut me some slack

I have a BED file with five columns, and the fifth column has some field with blank values. So when I intersect it with another file, it shows an error. What command(s) should I write to find and replace the blank values in the fifth column and replace it with something else?

Thanks a lot!

ChIP-Seq unix BED • 1.8k views
ADD COMMENT
0
Entering edit mode

Hi. I have to modify my question. Whenever I search a blank field, can I write a command to delete that line containing the blank field?

ADD REPLY
0
Entering edit mode

Even if I replace it with 0 or XX, can I delete that line?That was actually the main purpose. I may have thousands of lines that have blank fields and I need to delete them all. Can it be done in one line or first I replace them with 0 or XX and then run some command to delete the line containing that string? If so, what is that 'sed' command? Can i replace 0 with sed in that loop?

ADD REPLY
0
Entering edit mode

Here is the solution.

Remove lines from tab-delimited file with missing values

And please utilise ADD COMMENT function to add your comments instead of using Add your answer box.

ADD REPLY
0
Entering edit mode

Ah so you modified the question then. You do not need to move to 0 for deleting the row. Simple grep that identifies a cell with space removes it. Venu shows the correct one. Please keep your questions targetted as to what you want to do and what you have tried.

ADD REPLY
2
Entering edit mode
8.5 years ago
ivivek_ngs ★ 5.2k

With awk you can do it. It is just checking for blank spaces and replaceing with 0

awk 'BEGIN { FS = OFS = "\t" } { for(i=1; i<=NF; i++) if($i ~ /^ *$/) $i = 0 }; 1' foo.bed > mod_foo.bed
ADD COMMENT
1
Entering edit mode

Googling took me to this exact solution above.

Replacing missing value blank space with zero - My suggestion would be to replace 0 with "XX" or something to quickly identify.

ADD REPLY
0
Entering edit mode

It is the most widely thing that can be used. It does not matter what replaces. The OP can replace with string as well if its a string column.

ADD REPLY

Login before adding your answer.

Traffic: 1925 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6