thank you, I was trying to do it in awk and I was doing it wrong... now I know for the next time !
Hi, I'm parsing some sequences and I need to transform them from a single line to fasta format... The format I have now is something like this:
Name_of_the_specie AGTAGAGATTGAGATGAGGAGATTCCCATAGAGTTCGAATAGCTGTAATAGAG
Name_of_the_specie2 AGGAGGTTTGAGAGTTTTGAGAGGTGGGGAGAGTTTTTTAAAGGGGGAAAGAAGGAGAATGAGAGGGTTGAG
Name_of_the_ specie_3 ACATGCGATGAGGGCCCTTTATAATTTAATTGCGCTAAATAGATCTCCCTTTAGGGATATTGAGGAAGAGGAGGGATTAGGAGATTAGAGAGATAT
and so on... (>300)
I want to make a single file containing all those sequences in fasta format, if possible using perl/awk/sed.
Thanks!
4 answers
Assuming the name of the file doesn't have spaces, neither does the sequence and the new sequence starts in a new line - this should be straightforward
awk '{print ">"$1 "n" $2}' file_name > new_filename
the command would print > before the name ($1) and after a new line "n" you would get the sequence ($2) - which would be the fasta format
>Name_of_the_specie
AGTAGAGATTGAGATGAGGAGATTCCCATAGAGTTCGAATAGCTGTAATAGAG
>Name_of_the_specie2
AGGAGGTTTGAGAGTTTTGAGAGGTGGGGAGAGTTTTTTAAAGGGGGAAAGAAGGAGAATGAGAGGGTTGAG
>Name_of_the_ specie_3
ACATGCGATGAGGGCCCTTTATAATTTAATTGCGCTAAATAGATCTCCCT TTAGGGATATTGAGGAAGAGGAGGGATTAGGAGATTAGAGAGATAT
If it is one line per name and sequence, you can use this command:
perl -ane 'print ">$F[o]\n$F[1]\n";' yourFile.txt > yourFile.fasta
many thanks! :)
If your file is really as simple as you say then just do:
sed 's/^/>/' file1 >file2
sed 's/ /\n/' file2 >file3.fasta
Log in to answer this question.