This is a test version of Biostars. For the public version, visit https://www.biostars.org.
reorder sequences in fasta file based on ids from different file

Dear all,

I searched for solution but I could not find any. My question is how to reorder sequences in fasta file based on ids from different file. For instance,

I have a fasta file, but I want to reorder sequences based on new order of sequences.

in fasta file

1 2 3 4 and in ids file:

223 3000 433 201

I want to reorder sequences in fasta file based on ids file order.

New fasta file should be in this order:

223 3000 433 201

sequence gene genome

1 answer

You can do this easily with samtools and process substitution:

samtools faidx sequences.fasta

samtools faidx sequences.fasta $(cat order.txt) > sequences.reordered.fasta

Log in to answer this question.