[Bioperl-l] calculating the Ka/Ks ratio

Albert Vilella avilella at gmail.com
Wed Aug 10 04:26:53 EDT 2005

El dc 10 de 08 del 2005 a les 08:54 +0100, en/na Darren Obbard va
> Hi all,
> Is there a module that will take a pair of aligned (coding) sequences, and 
> report the Ka/Ks ratio? (non-synonymous mutations per non-synonymous site / 
> synonymous mutations per synonymous site).
> I appreciate that PAML will give me an ML estimate of Ka/Ks, but I'm aiming 
> to do a sliding-window analysis and don't wish to send each window to PAML 
> individually, - I  wondered whether there may be a quicker alternative.

There is a calc_KaKs_Pair method in Bio::Align::DNAStatistics
(Nei-Gojobori method)

>From the synopsis:

  my $in = new Bio::AlignIO(-format => 'fasta',
                            -file   => 't/data/nei_gojobori_test.aln');
  my $alnobj = $in->next_aln;
  my ($seq1id,$seq2id) = map { $_->display_id } $alnobj->each_seq;
  my $results = $stats->calc_KaKs_pair($alnobj, $seq1id, $seq2id);
  print "comparing ".$results->[0]{'Seq1'}." and
  for (sort keys %{$results->[0]} ){
      next if /Seq/;
      printf("%-9s %.4f \n",$_ , $results->[0]{$_});

  my $results2 = $stats->calc_all_KaKs_pairs($alnobj);
  for my $an (@$results2){
      print "comparing ". $an->{'Seq1'}." and ". $an->{'Seq2'}. " \n";
      for (sort keys %$an ){
	  next if /Seq/;
	  printf("%-9s %.4f \n",$_ , $an->{$_});
      print "\n\n";

  my $result3 = $stats->calc_average_KaKs($alnobj, 1000);
  for (sort keys %$result3 ){
      next if /Seq/;
      printf("%-9s %.4f \n",$_ , $result3->{$_});

Hope it helps,


Albert J. Vilella    avilella_at_ub_edu
Departament de Genetica
Universitat de Barcelona
Diagonal 645 08028, Barcelona
Tel: +34 934035306 Fax: +34 934034420
EMBL Outstation, European Bioinformatics Institute
Wellcome Trust Genome Campus, Hinxton
Cambs. CB10 1SD, United Kingdom

More information about the Bioperl-l mailing list