This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Search And Replace Old Seq-Id With New Seq-Id Across Fasta Files Using A List.Txt Of Both Ids?

Hi Folk,

I have about 90 fasta files, each having multiple sequences. I want to rename the current seq IDs to new seq IDs across all 90 fasta files for all sequences.

How can I do the renaming having a list of current seq IDs (current.txt) and a list of new seq IDs (new.txt) over all fasta files?

Or any other way is much appreciated>

Hossein

unix

2 answers

From your question, we can't say much about your fasta headers and how you should transform them.

For example, your could use sed with option -f script-file

$ cat change.sed
s/^>ABCD/>EFG/
s/^>ID1/>sequence_1/
s/^>id\([A-Z]*\)/>sequence_\1/

$ for F in OLD*.fasta; do sed -f change.sed $F >  NEW/`basename $F` ; done

Thanks a lot Pierre. I did what you wrote and that worked well.

I would like to remind the beginners like me that NEW in the command line is a folder name we need to make in the same working directory.

Best

Hossein

Log in to answer this question.