Fasta to axt - KaKs Calculator
1
0
Entering edit mode
9.6 years ago
tlorin ▴ 370

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 • 7.7k views
ADD COMMENT
2
Entering edit mode

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
ADD REPLY
0
Entering edit mode

Thanks @Cytosine!!! Perfect! :)

ADD REPLY
4
Entering edit mode
9.6 years ago
cat  file.fa | paste - - - - | awk '{print  substr($3,2)"\n"$2"\n"$4}'
ADD COMMENT

Login before adding your answer.

Traffic: 2768 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6