Editing Bed file
1
0
Entering edit mode
7.2 years ago
dimitrischat ▴ 210

Hello to all. This is my first question here. so be kind. So i have a .bed file, and there is a problem to it. One line is written in wrong way, maybe misspelled. Instead of typing chr11 ( chromosome 11), is writes r11 which is wrong. Anyway, i edited it in excel 1) deleted whole line 2) renamed it to chr11 , saved it as .txt then just renamed to .bed as i found here as answer, but it doesn't work when i want to use it in terminal ( bedtools - intersectBed ). I dont think its the right way to convert it. My question is , how do i edit it in excel and then save it as .bed file that actually works with bedtools, and maybe there is a way to delete lines or edit .bed files in terminal. But keep in mind, there are many lines, not just 4-5 of them, and i need a way to find/search the wrong one. Many thanks, i hope i was clear

ChIP-Seq bed alignment sequence • 6.4k views
ADD COMMENT
0
Entering edit mode

This is my first question here. so be kind.

Regardless of how many questions you have asked, if the question is good everyone should be kind, always :-)

ADD REPLY
0
Entering edit mode

Hello!! My problem is something like this, but instead of having only one line wrote wrong, I have the whole first column. I have "chr12" but I need it to be only the number of the chromosome (like "12"). How can I correct that? if it is with sed, which command should I use?

P.s.: It's a genome annotation file

ADD REPLY
0
Entering edit mode

You'll want something like:

sed -i `s/^chr//` foo.bed

Also, post things like this as new questions next time.

ADD REPLY
0
Entering edit mode

Please use ADD COMMENT or ADD REPLY to answer to previous reactions, as such this thread remains logically structured and easy to follow. I have now moved your reaction but as you can see it's not optimal. Adding an answer should only be used for providing a solution to the question asked.

ADD REPLY
1
Entering edit mode
7.2 years ago
GenoMax 141k

If there is only one location which has an error then you could try the following in the terminal (I assume you are using macOS?): sed -e 's/r11/chr11/' your_file > fixed_file

ADD COMMENT
0
Entering edit mode

yea macOS. it worked. but when there are many locations? is there any way to edit it from excel(and still be functional?) or other program? Also where do you find these commands? Many thanks!

ADD REPLY
2
Entering edit mode

If there are multiple locations then you can do a global replacement (note the g) like sed -e 's/^r11/chr11/g' your_file > fixed_file. Since r11 is likely at the beginning of affected lines doing it the way depicted now would ensure that only those instances will be replaced.

It is not advisable to edit files used for bioinformatics in excel (it should be safe to view them) since it can cause silent corruptions due to formatting (e.g. gene names change).

ADD REPLY
0
Entering edit mode

i opened the file with excel and it seems corrected. then i ran intersectBed and now it displays error : chchr11 ( before the mistake was r11 ). I dont know if you have any clue.

is there any page where are commands like these for editing etc?

ADD REPLY
1
Entering edit mode

Using a stream editor like sed you need to be aware of all patterns that may be affected by an edit you are doing. Do you think chchr11 is another pattern that is distinct from r11 or did that result from the first sed edit you did?

If that was a second pattern that was wrong then both fixes can be done in one command like this: sed -e 's/^r11/chr11/g' -e 's/^chchr11/chr11/g' your_file > fixed_file

ADD REPLY
0
Entering edit mode

yea this worked. Also i would like to ask the following : 1) if there are many r11's but i want to change 1 of them or 2 of them , how do i do that? 2) how do i delete a specific line(s) from bed file ?

ADD REPLY
1
Entering edit mode

This page shows you how to delete specific lines from a file using sed. Replacing occurrences on specific lines can be done this way.

ADD REPLY
1
Entering edit mode

Also where do you find these commands?

https://www.google.fr/search?q=learning+linux

:-)

ADD REPLY
0
Entering edit mode

So only google france will work?

ADD REPLY
1
Entering edit mode

just google learning linux

ADD REPLY
1
Entering edit mode

That was a poor attempt at a joke on my part.

ADD REPLY
0
Entering edit mode

hahaha.. well you never know...!

ADD REPLY

Login before adding your answer.

Traffic: 2543 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