This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How To Get The Fasta Format From The Sequence File That Each Row Has A Sequence

I have a document that one sequence one row.I want to get the fasta format and the name is the sequence.

aaaacccc
aaccctttt
aatgtgtgt
gggg

The result should be this

>aaaacccc
aaaacccc
>aaccctttt
aaccctttt
>aatgtgtgt
aatgtgtgt
>gggg
gggg
fasta format sequence

I am trying to conceive what purpose this could ever be useful for... Anyone?

3 answers

awk '{print ">"$0"\n"$0}' document

perl -e 'while(<>){chomp; print ">$_\n$_\n";}' inputfile.txt

No need to chomp ;) perl -e 'while(<>){print ">",$_,$_}' input.txt

(a bit shorter still: perl -e 'print ">",$_,$_ while<>' input.txt )

no need to while with -n: perl -ne 'print ">$_$_"' input

The python version:

import sys

for line in open(sys.argv[1]):
    print ">"+line.strip()
    print line.strip()

assuming this code is in a file named "makefasta.py", the syntax is:

python makefasta.py input.txt

Log in to answer this question.