This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to create a fasta file from a list of sequences

I have a txt file with more than a thousand DNA sequences as follows:

seq-name1 DNA-sequence1
seq-name2 DNA-sequence2
seq-name3 DNA-sequence3

Does anyone know a code to transform this file into a fasta file?

>seq-name1
DNA-sequence1
>seq-name2
DNA-sequence2
>seq-name3
DNA-sequence3
fasta sequences dna

3 answers

This command prints > followed by the contents of the first column, then a new line character (\n) followed by second column. It is a fairly trivial operation and should be easy to find many similar solutions by Googling this site or the whole internet.

awk '{print ">"$1"\n"$2}' input.txt > output.fas

You can try sed 's/\(seq-name[0-9]\)\s\(DNA-sequence[0-9]\)/>\1\n\2/g' input_file > output_file

perl: perl -ae 'print ">$F[0]\n$F[1]\n";' in >out.fa

Log in to answer this question.