Replacing a character in multiple fasta files within a folder
2
0
Entering edit mode
3 months ago

How can I replace a character in multiple fasta files within a folder? More specific, I want to replace the character "?" by "N" through multiple fasta files. enter image description here

Thanks in advance for your advice.

replace find and • 328 views
ADD COMMENT
2
Entering edit mode
3 months ago
Mensur Dlakic ★ 14k

Assuming that your files all end in .fasta, go to that directory and type:

find . -name "*.fasta" | xargs -i sed -i 's/\?/N/g' {}

Yet another approach:

for f in *.fasta ; do sed -i 's/\?/N/g' $f ; done
ADD COMMENT
0
Entering edit mode

Hi Mensur Dlakic,

Thanks so much! It worked. I also found another way: sed -i -se 's/?/N/g' *.fasta.

ADD REPLY
0
Entering edit mode
3 months ago

look at find /path/to/dir -exec and Remove unwanted characters from FASTA file

ADD COMMENT
0
Entering edit mode

Thanks for your prompt response, however I do not want to remove the character "?", I want to replace it by "N". I tried sed -i 's/?/N/g' *, but with no success.

enter image description here

The fact that all of my files end with the letter "A" before the format denomination seems to be an issue for the command.

enter image description here

Do you have an idea how to solve this?

ADD REPLY

Login before adding your answer.

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