length of specific sequences from multi fasta file
I have a list of fasta headers in a file (list.txt). I want to get the size or the length of the sequences of list.txt file from a big multi fasta file (main.fasta). Please let me know how to do this, Thank you,
• 2,341 views
•
link
2 answers
$ grep --no-group-separator -h -A 1 -wf file.txt *.fa | awk -v OFS="\t" 'NR==1 {print "sequence","length"}; BEGIN{RS=">"} NR>1 {print $1, length($2)}'
if you have one fasta file, try following line:
$ awk -v OFS="\t" 'NR==FNR {a[$1]=$1; next} BEGIN{RS=">"} ($1 in a) {print a[$1], length($2)}' file.txt a.fa
Assuming that all fasta files are linearized. If you have smaller number of fasta files, try:
$ awk -v OFS="\t" 'BEGIN{RS=">"} {print $1, length($2)}' *.fa | grep -f file.txt
• 0 views
•
link
Log in to answer this question.
The awk commands do the job. Thank you.
If an answer was helpful, you should upvote it; if the answer resolved your question, you should mark it as accepted. You can accept more than one if they work.
