Question: Fasta to axt - KaKs Calculator
0
gravatar for tlorin
4.6 years ago by
tlorin250
Switzerland
tlorin250 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 • 3.7k views
ADD COMMENTlink modified 4.6 years ago by Pierre Lindenbaum124k • written 4.6 years ago by tlorin250
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 4.6 years ago by Cytosine450

Thanks @Cytosine!!! Perfect! :)

ADD REPLYlink written 4.6 years ago by tlorin250
4
gravatar for Pierre Lindenbaum
4.6 years ago by
France/Nantes/Institut du Thorax - INSERM UMR1087
Pierre Lindenbaum124k wrote:
cat  file.fa | paste - - - - | awk '{print  substr($3,2)"\n"$2"\n"$4}'
ADD COMMENTlink written 4.6 years ago by Pierre Lindenbaum124k
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: 1690 users visited in the last hour