Multiline fasta to single line
1
0
Entering edit mode
20 months ago
LaFra ▴ 10

Hi all,

I'm trying to convert my multiline fasta in a single line fasta.

My input file is like this (I put only the first lines, but they are many more):

>sample1
gttaatgtagcttaaacccaaagcaaggcactgaaaatgcctagatgagtacaccaactc
cataaacacataggtttggtcccagccttcctgtttactttcaataggcctacacatgca
agcatccacgccccggtgagtaacaccctccaaatcaacaagactaagaggagtaggtat
caagcacacatcctgtagctcataacacctcgcccaaccacacccccacgggagacagca
gtgacaaaaattaagccataaacgaaagtttgactaagccatattgattagggttggtaa
atctcgtgccagccaccgcggtcatacgattaacccgagctaacaggaatacggcgtaaa

And the desired output would be this:

>sample1
gttaatgtagcttaaacccaaagcaaggcactgaaaatgcctagatgagtacaccaactccataaacacataggtttggtcccagccttcctgtttactttcaataggcctacacatgcaagcatccacgccccggtgagtaacaccctccaaatcaacaagactaagaggagtaggtatcaagcacacatcctgtagctcataacacctcgcccaaccacacccccacgggagacagcagtgacaaaaattaagccataaacgaaagtttgactaagccatattgattagggttggtaaatctcgtgccagccaccgcggtcatacgattaacccgagctaacaggaatacggcgtaaa

I tried this command, but it give me the same file as the input, that menas a multiline fasta

awk '{if(NR==1) {print $0} else {if($0 ~ /^>/) {print "\n"$0} else {printf $0}}}' input.fa > output.fa

I also tried several other commands, but they don't work..why?

multilne singleline fasta • 1.7k views
ADD COMMENT
0
Entering edit mode
# https://github.com/lh3/seqtk/    
seqtk seq *.fasta
ADD REPLY
0
Entering edit mode
20 months ago
tr -d '\r' < input.fasta | awk '/^>/ {printf("%s%s\t",(N>0?"\n":""),$0);N++;next;} {printf("%s",$0);} END {printf("\n");}'  | tr "\t" "\n"

the first tr is just in case your file comes from windows. see how to linearize a fasta file

ADD COMMENT

Login before adding your answer.

Traffic: 1593 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