This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Fasta to axt - KaKs Calculator

Dear BioStars Users,

I am using KaKs Calculator to estimate selection over a whole sequence, and I need to do this for many multifasta alignments. Here is some example file:

>ref
AAAAAAA
>seq1
BBBBBBB
>ref
AAAAAAA
>seq2
CCCCCCC
>ref
AAAAAAA
>seq3
DDDDDDD

And here is what I would like to get (an AXT formatted file):

seq1
AAAAAAA
BBBBBBB


seq2
AAAAAAA
CCCCCCC


seq3
AAAAAAA
DDDDDDD

I already tried this script but it's not doing properly.. Would anyone have a pipeline (in bash, perl, R, python...) to automatize this, or have an idea of how to proceed? I can for sure do it by hand for several files, but I have too many to do it :)

Thanks a lot!

bash perl r python kaks

If the fasta file is structured like your example file with no blank lines, you can do something like this with awk. Just substitute the example-file.fasta with your file.

awk '$0 ~ ">" {c=substr($0,2,length($0))} NR == 2 {ref=$0} NR % 4 == 0 {print c"\n"ref"\n"$0"\n"}' example-file.fasta

Thanks @Cytosine!!! Perfect! :)

1 answer

cat  file.fa | paste - - - - | awk '{print  substr($3,2)"\n"$2"\n"$4}'

Log in to answer this question.