This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to swap fasta entrys in a fasta file?

Hi, my files all have 2 fasta entries and they look like:

>ID.1
GTAACACGACATCCTGCAGGGTTAAAAAAGAAAAAATCAGTAAAAGTACTGGA
>ID.2
GGAATACCACATCCCGCAGGGTTAAAAAAGAAAAAATCAGTAACAGTACTGGA

My desired output looks like:

>ID.2
GGAATACCACATCCCGCAGGGTTAAAAAAGAAAAAATCAGTAACAGTACTGGA
>ID.1
GTAACACGACATCCTGCAGGGTTAAAAAAGAAAAAATCAGTAAAAGTACTGGA

I have looked into awk/sed and the only solutions involve cutting/pasting rows into a sperate file and then moving them back, is there an alternative way?

awk fasta bash sed

2 answers

Seqkit answer for posterity.

seqkit sort -r in.fasta > out.fasta
awk -F'\n' '{print $3, $4, $1, $2}' OFS='\n' RS= ORS='\n\n' $i

Log in to answer this question.