Question: Editing Bed file
0
gravatar for dimitrischat
3.1 years ago by
dimitrischat110
dimitrischat110 wrote:

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

alignment chip-seq sequence bed • 2.5k views
ADD COMMENTlink modified 21 months ago by roberta.cracco0 • written 3.1 years ago by dimitrischat110

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 REPLYlink written 3.1 years ago by WouterDeCoster43k

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 REPLYlink written 21 months ago by roberta.cracco0

You'll want something like:

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

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

ADD REPLYlink written 21 months ago by Devon Ryan94k

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 REPLYlink written 21 months ago by WouterDeCoster43k
1
gravatar for genomax
3.1 years ago by
genomax80k
United States
genomax80k wrote:

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 COMMENTlink modified 3.1 years ago • written 3.1 years ago by genomax80k

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 REPLYlink written 3.1 years ago by dimitrischat110
2

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 REPLYlink modified 3.1 years ago • written 3.1 years ago by genomax80k

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 REPLYlink written 3.1 years ago by dimitrischat110
1

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 REPLYlink modified 3.1 years ago • written 3.1 years ago by genomax80k

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 REPLYlink written 3.1 years ago by dimitrischat110
1

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 REPLYlink written 3.1 years ago by genomax80k
1

Also where do you find these commands?

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

:-)

ADD REPLYlink written 3.1 years ago by Pierre Lindenbaum127k

So only google france will work?

ADD REPLYlink written 3.1 years ago by genomax80k
1

just google learning linux

ADD REPLYlink written 3.1 years ago by dimitrischat110
1

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

ADD REPLYlink written 3.1 years ago by genomax80k

hahaha.. well you never know...!

ADD REPLYlink written 3.1 years ago by dimitrischat110
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1124 users visited in the last hour