Entering edit mode
4.2 years ago
Begonia_pavonina
▴
200
Hello everyone,
I try to replace the headers A of a FASTA file (file.fasta) with headers B.
For this, I have a list which match the headers names.
>A_1 >B_1
>A_2 >B_2
>A_3 >B_3
etc...
I am using this loop to replace the headers:
cat list | while read f ;
do
echo $f > temp_file
A=$(awk '{print $1}' temp_file ) ;
B=$(awk '{print $2}' temp_file ) ;
sed -i 's/$A/$B/g' file.fasta ;
done
But this simple loop does not work. Would anyone know if I have made an obvious mistake?
you already asked several questions on this forum without commenting or validating (green mark on the left) any answer. Please review the answers: Keep metadata gc column using GenomicRanges ; merging overlaping ranges with GenomicRanges ; ...
My apologizes, I thought the thumb up was the way to validate the answer.
If an answer was helpful, you should upvote it; if the answer resolved your question, you should mark it as accepted. You can accept more than one if they work.
https://stackoverflow.com/questions/6697753/
The name in your B fie is a prefix or a different name? Because if it is a prefix you can replace it directly in the A file. And btw, to use bash variables inside of sed you need to use double-quotes.
Use dedicated tools such as seqtk and seqkit to replace fasta headers from a file.