This is a test version of Biostars. For the public version, visit https://www.biostars.org.
how to sort fasta format DNA sequences based on a given sequence name list

Hello,

I have a fasta file with many DNA sequences. I want to sort these sequence based on a designated order in a sequence name list file. How to acheive this?

Thanks.

Yongjie

sort fasta sequences

Biopython or python, create a dictionary and then sort the keys as you wish :) .

2 answers

Hi! I believe that this was answered before: Sort Sequences In A Fasta File According To The Sequence List In Another Fasta/Txt File

If you first linearise your fasta sequences (search this forum for many, many ways to do this), then the following should work:

while read line ; do grep -A 1 "$line" sequences.fasta >> sorted_sequences.fasta ; done < indexfile.txt

(Not tested)

Log in to answer this question.