1
# -*-Perl-*- Test Harness script for Bioperl
2
# $Id: AlignStats.t 15112 2008-12-08 18:12:38Z sendu $
10
test_begin(-tests => 43);
12
use_ok('Bio::Align::DNAStatistics');
13
use_ok('Bio::Align::ProteinStatistics');
14
use_ok('Bio::AlignIO');
17
my $debug = test_debug();
19
my $in = Bio::AlignIO->new(-format => 'emboss',
20
-file => test_input_file('insulin.water'));
21
my $aln = $in->next_aln();
22
isa_ok($aln, 'Bio::Align::AlignI');
23
my $stats = Bio::Align::DNAStatistics->new(-verbose => $debug);
24
is( $stats->transversions($aln),4);
25
is( $stats->transitions($aln),9);
26
is( $stats->pairwise_stats->number_of_gaps($aln),21);
27
is( $stats->pairwise_stats->number_of_comparable_bases($aln),173);
28
is( $stats->pairwise_stats->number_of_differences($aln),13);
29
is( $stats->pairwise_stats->score_nuc($aln), 224);
30
is( $stats->pairwise_stats->score_nuc( -aln => $aln, -match => 1,
31
-mismatch => -1, -gap_open => -1, -gap_ext => -1), 126);
33
my $d = $stats->distance(-align => $aln,
35
is( $d->get_entry('hs_insulin','seq2'), '0.07918');
37
$d = $stats->distance(-align=> $aln,
39
is( $d->get_entry('hs_insulin','seq2'), '0.07918');
41
$d = $stats->distance(-align=> $aln,
43
is( $d->get_entry('hs_insulin','seq2'), '0.07984');
45
$d = $stats->distance(-align=> $aln,
46
-method => 'TajimaNei');
47
is( $d->get_entry('seq2','hs_insulin'), '0.08106');
49
$d = $stats->distance(-align=> $aln,
51
is( $d->get_entry('seq2','hs_insulin'), '0.08037');
53
#$d = $stats->distance(-align => $aln,
54
# -method => 'JinNei');
55
#is( $d->get_entry('seq2','hs_insulin'), 0.0850);
57
$in = Bio::AlignIO->new(-format => 'clustalw',
58
-file => test_input_file('hs_owlmonkey.aln'));
60
$aln = $in->next_aln();
61
isa_ok($aln,'Bio::Align::AlignI');
63
is( $stats->transversions($aln),10);
64
is( $stats->transitions($aln),17);
65
is( $stats->pairwise_stats->number_of_gaps($aln),19);
66
is( $stats->pairwise_stats->number_of_comparable_bases($aln),170);
67
is( $stats->pairwise_stats->number_of_differences($aln),27);
68
is( $stats->pairwise_stats->score_nuc($aln), 134);
69
is( $stats->pairwise_stats->score_nuc( -aln => $aln, -match => 1,
70
-mismatch => -1, -gap_open => -1, -gap_ext => -1), 97);
72
# now test the distance calculations
73
$d = $stats->distance(-align => $aln, -method => 'jc');
74
is( $d->get_entry('human','owlmonkey'), 0.17847);
76
$d = $stats->distance(-align => $aln,
78
is( $d->get_entry('human','owlmonkey'), '0.17847');
80
$d = $stats->distance(-align => $aln, -method => 'uncorrected');
81
is( $d->get_entry('human','owlmonkey'), 0.15882);
83
$d = $stats->distance(-align => $aln, -method => 'Kimura');
84
is( $d->get_entry('human','owlmonkey'), 0.18105);
86
$d = $stats->distance(-align => $aln, -method => 'TajimaNei');
87
is( $d->get_entry('human','owlmonkey'), 0.18489);
89
$d = $stats->distance(-align => $aln,
92
is( $d->get_entry('human','owlmonkey'), 0.18333);
93
#$d = $stats->distance(-align => $aln,
94
# -method => 'JinNei');
95
#is( $d->get_entry('human','owlmonkey'), 0.2079);
97
### now test Nei_gojobori methods, hiding the expected warnings so we can
98
# avoid printing them ###
99
$stats->verbose($debug ? $debug : -1);
100
my ($alnobj, $result);
101
$in = Bio::AlignIO->new(-format => 'fasta',
102
-file => test_input_file('nei_gojobori_test.aln'));
103
$alnobj = $in->next_aln();
104
isa_ok($alnobj,'Bio::Align::AlignI');
105
$result = $stats->calc_KaKs_pair($alnobj, 'seq1', 'seq2');
106
is (sprintf ("%.1f", $result->[0]{'S'}), 40.5);
107
is (sprintf ("%.1f", $result->[0]{'z_score'}), '4.5');
108
$result = $stats->calc_all_KaKs_pairs($alnobj);
109
is (int( $result->[1]{'S'}), 41);
110
is (int( $result->[1]{'z_score'}), 4);
111
$result = $stats->calc_average_KaKs($alnobj, 100);
112
is (sprintf ("%.4f", $result->{'D_n'}), 0.1628);
113
$stats->verbose($debug);
115
# now test Protein Distances
116
my $pstats = Bio::Align::ProteinStatistics->new();
117
$in = Bio::AlignIO->new(-format => 'clustalw',
118
-file => test_input_file('testaln.aln'));
119
$alnobj = $in->next_aln();
120
isa_ok($alnobj,'Bio::Align::AlignI');
121
$result = $pstats->distance(-method => 'Kimura',
123
isa_ok($result, 'Bio::Matrix::PhylipDist');
125
is ($result->get_entry('P84139','P814153'), '0.01443');
126
is ($result->get_entry('P841414','P851414'), '0.01686');
127
is ($result->get_entry('P84139','P851414'), '3.58352');
129
my $seq = Bio::Seq->new(-id=>'NOT3MUL', -seq=>'gatac');
130
isa_ok($seq, 'Bio::PrimarySeqI');
132
Bio::Align::DNAStatistics->count_syn_sites($seq);
134
like($@, qr/not integral number of codons/);