Extracting fasta file according to Ids
Hello,
I have a huge Fasta file. I would like to extract all the sequences with id such that the ids start from NM?
I tried following two commands which did not work for me.
awk‘BEGIN{RS=”>”}/NM/{print“>”$0}’huge.fasta
grep '^>NM' -B 1 huge.fasta > Nm.fasta
Could someone help me with a better solution. thank you in advance.
• 2,322 views
•
link
1 answer
Index your FASTA file:
samtools faidx input.fasta
Then get ids which start with "NM" and pipe them into samtools faidx to retrieve only those sequences:
cut -f 1 input.fasta.fai | egrep "^NM" | xargs samtools faidx input.fasta > result.fasta
• 0 views
•
link
Log in to answer this question.
is your huge fasta a multi-line fasta or single line fasta?
multi-line fasta file
Hello KVC_bioinfo!
Questions similar to yours can already be found at:
We have closed your question to allow us to keep similar content in the same thread.
If you disagree with this please tell us why in a reply below. We'll be happy to talk about it.
Cheers!