Question: Fasta to axt - KaKs Calculator
0
gravatar for tlorin
5.3 years ago by
tlorin270
Switzerland
tlorin270 wrote:

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 python kaks R perl • 4.2k views
ADD COMMENTlink modified 5 months ago by Biostar ♦♦ 20 • written 5.3 years ago by tlorin270
2

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 REPLYlink written 5.3 years ago by Cytosine450

Thanks @Cytosine!!! Perfect! :)

ADD REPLYlink written 5.3 years ago by tlorin270
4
gravatar for Pierre Lindenbaum
5.3 years ago by
France/Nantes/Institut du Thorax - INSERM UMR1087
Pierre Lindenbaum129k wrote:
cat  file.fa | paste - - - - | awk '{print  substr($3,2)"\n"$2"\n"$4}'
ADD COMMENTlink written 5.3 years ago by Pierre Lindenbaum129k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1116 users visited in the last hour