How To Get The Fasta Format From The Sequence File That Each Row Has A Sequence
3
0
Entering edit mode
11.8 years ago
2011101101 ▴ 110

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 • 3.0k views
ADD COMMENT
1
Entering edit mode

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

ADD REPLY
8
Entering edit mode
11.8 years ago
PoGibas 5.1k

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

ADD COMMENT
3
Entering edit mode
11.8 years ago
perl -e 'while(<>){chomp; print ">$_\n$_\n";}' inputfile.txt
ADD COMMENT
2
Entering edit mode

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

ADD REPLY
0
Entering edit mode

True :). I 'chomp' by default.

ADD REPLY
0
Entering edit mode

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

ADD REPLY
3
Entering edit mode

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

ADD REPLY
0
Entering edit mode

Oh, how cool! Thanks.

ADD REPLY
1
Entering edit mode
11.8 years ago
KCC ★ 4.1k

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
ADD COMMENT

Login before adding your answer.

Traffic: 2397 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6