renaming fasta file with part of fasta header
I have about 100 multiple fasta files (e.g., file.faa), which I have to rename with the species name mentioned in the fasta header. The fasta headers of these files are in the following format:
>XP_003072227.1 aminopeptidase N [Encephalitozoon intestinalis ATCC 50506]
How do I rename 'file.faa' to 'Encephalitozoon intestinalis.faa'?
I saw that people have used awk and sed for a similar purpose but could not figure out what I have to do. Any help is appreciated.
Thank you.
• 1,850 views
•
link
1 answer
Create a backup copy of your files before trying the following. Replace this line below in your command above
head -1 $i | cut -f1 -d ' ' | tr -d '>'
with following
head -1 test.fa | cut -f2 -d [ | cut -f1,2 -d " " | awk -F " " '{OFS="_"}{print $1,$2}' /dev/stdin
With your example this produces:
$ head -1 test.fa | cut -f2 -d [ | cut -f1,2 -d " " | awk -F " " '{OFS="_"}{print $1,$2}' /dev/stdin
Encephalitozoon_intestinalis
• 0 views
•
link
Log in to answer this question.
See answers here for inspiration: Rename FASTA files according to FASTA file header
You will need to make some changes to the solutions. Please do not use spaces in file names even though your OS may allow them.
I have tried doing
This changed 'file.faa' to 'XP_003072227.1.faa' but I need 'Encephalitozoon intestinalis.faa'.
How to modify the script?