2 ## Bioperl Test Harness Script for Modules
5 # Before `make install' is performed this script should be runnable with
6 # `make test'. After `make install' it should work as `perl test.t'
12 # to handle systems with no installed Test module
13 # we include the t dir (where a copy of Test.pm is located)
15 eval { require Test; };
30 use Bio::Align::DNAStatistics;
31 use Bio::Align::ProteinStatistics;
35 my $in = new Bio::AlignIO(-format => 'emboss',
36 -file => Bio::Root::IO->catfile('t', 'data',
38 my $aln = $in->next_aln();
40 my $stats = new Bio::Align::DNAStatistics(-verbose => $debug);
41 ok( $stats->transversions($aln),4);
42 ok( $stats->transitions($aln),9);
43 ok( $stats->pairwise_stats->number_of_gaps($aln),21);
44 ok( $stats->pairwise_stats->number_of_comparable_bases($aln),173);
45 ok( $stats->pairwise_stats->number_of_differences($aln),13);
47 my $d = $stats->distance(-align => $aln,
49 ok( $d->get_entry('hs_insulin','seq2'), '0.07918');
51 $d = $stats->distance(-align=> $aln,
53 ok( $d->get_entry('hs_insulin','seq2'), '0.07918');
55 $d = $stats->distance(-align=> $aln,
57 ok( $d->get_entry('hs_insulin','seq2'), '0.07984');
59 $d = $stats->distance(-align=> $aln,
60 -method => 'TajimaNei');
61 ok( $d->get_entry('seq2','hs_insulin'), '0.08106');
63 $d = $stats->distance(-align=> $aln,
65 ok( $d->get_entry('seq2','hs_insulin'), '0.08037');
67 #$d = $stats->distance(-align => $aln,
68 # -method => 'JinNei');
69 #ok( $d->get_entry('seq2','hs_insulin'), 0.0850);
71 $in = new Bio::AlignIO(-format => 'clustalw',
72 -file => Bio::Root::IO->catfile('t','data',
75 $aln = $in->next_aln();
78 ok( $stats->transversions($aln),10);
79 ok( $stats->transitions($aln),17);
80 ok( $stats->pairwise_stats->number_of_gaps($aln),19);
81 ok( $stats->pairwise_stats->number_of_comparable_bases($aln),170);
82 ok( $stats->pairwise_stats->number_of_differences($aln),27);
84 # now test the distance calculations
85 $d = $stats->distance(-align => $aln, -method => 'jc');
86 ok( $d->get_entry('human','owlmonkey'), 0.17847);
88 $d = $stats->distance(-align => $aln,
90 ok( $d->get_entry('human','owlmonkey'), '0.17847');
92 $d = $stats->distance(-align => $aln, -method => 'uncorrected');
93 ok( $d->get_entry('human','owlmonkey'), 0.15882);
95 $d = $stats->distance(-align => $aln, -method => 'Kimura');
96 ok( $d->get_entry('human','owlmonkey'), 0.18105);
98 $d = $stats->distance(-align => $aln, -method => 'TajimaNei');
99 ok( $d->get_entry('human','owlmonkey'), 0.18489);
101 $d = $stats->distance(-align => $aln,
102 -method => 'Tamura');
104 ok( $d->get_entry('human','owlmonkey'), 0.18333);
105 #$d = $stats->distance(-align => $aln,
106 # -method => 'JinNei');
107 #ok( $d->get_entry('human','owlmonkey'), 0.2079);
109 ### now test Nei_gojobori methods ##
110 $in = Bio::AlignIO->new(-format => 'fasta',
111 -file => Bio::Root::IO->catfile('t','data',
112 'nei_gojobori_test.aln'));
113 my $alnobj = $in->next_aln();
115 my $result = $stats->calc_KaKs_pair($alnobj, 'seq1', 'seq2');
116 ok (sprintf ("%.1f", $result->[0]{'S'}), 40.5);
117 ok (sprintf ("%.1f", $result->[0]{'z_score'}), '4.5');
118 $result = $stats->calc_all_KaKs_pairs($alnobj);
119 ok (int( $result->[1]{'S'}), 41);
120 ok (int( $result->[1]{'z_score'}), 4);
121 $result = $stats->calc_average_KaKs($alnobj, 100);
122 ok (sprintf ("%.4f", $result->{'D_n'}), 0.1628);
125 # now test Protein Distances
126 my $pstats = Bio::Align::ProteinStatistics->new();
127 $in = Bio::AlignIO->new(-format => 'clustalw',
128 -file => Bio::Root::IO->catfile('t','data',
130 $alnobj = $in->next_aln();
132 $result = $pstats->distance(-method => 'Kimura',
136 ok ($result->get_entry('P84139','P814153'), '0.01443');
137 ok ($result->get_entry('P841414','P851414'), '0.01686');
138 ok ($result->get_entry('P84139','P851414'), '3.58352');
140 my $seq = Bio::Seq->new(-id=>'NOT3MUL', -seq=>'gatac');
143 Bio::Align::DNAStatistics->count_syn_sites($seq);
145 ok($@ =~ m/not integral number of codons/);