File: AlignStats.t

package info (click to toggle)
bioperl 1.4-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 20,336 kB
  • ctags: 8,476
  • sloc: perl: 119,890; xml: 6,001; lisp: 121; makefile: 57
file content (112 lines) | stat: -rw-r--r-- 3,465 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# -*-Perl-*-
## Bioperl Test Harness Script for Modules
## $Id: AlignStats.t,v 1.6 2003/10/16 14:15:44 heikki Exp $

# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.t'

my $error = 0;

use strict;
BEGIN {
    # to handle systems with no installed Test module
    # we include the t dir (where a copy of Test.pm is located)
    # as a fallback
    eval { require Test; };
    if( $@ ) {
	use lib 't';
    }

    use Test;
    plan tests => 21; 
}

if( $error == 1 ) {
    exit(0);
}

my $debug = -1;

use Bio::Align::DNAStatistics;
use Bio::AlignIO;
use Bio::Root::IO;

# NOTE NOTE NOTE
# A lot more work needs to be done on this DNAStatistics object
# it currently doesn't actually calculate everything correctly
# The currently implemented tests show what DOES work.
# Volunteers welcomed

my $in = new Bio::AlignIO(-format => 'emboss',
			  -file   => Bio::Root::IO->catfile('t', 'data',
							    'insulin.water'));
my $aln = $in->next_aln();
ok($aln);
my $stats = new Bio::Align::DNAStatistics(-verbose => $debug);
ok( $stats->transversions($aln),4);
ok( $stats->transitions($aln),9);
ok( $stats->pairwise_stats->number_of_gaps($aln),21);
ok( $stats->pairwise_stats->number_of_comparable_bases($aln),173);
ok( $stats->pairwise_stats->number_of_differences($aln),13);

my $d = $stats->distance(-align=> $aln,
			 -method => 'JC');
ok( sprintf("%.5f",$d->[1]->[2]), 0.07918);
$d = $stats->distance(-align=> $aln,
			 -method => 'Kimura');
ok( sprintf("%.5f",$d->[1]->[2]), 0.07984);
#$d = $stats->distance(-align=> $aln,
#			 -method => 'TajimaNei');

#ok( sprintf("%.5f",$d->[1]->[2]), 0.0780);

$aln = $in->next_aln();
ok(! defined $aln);

$in = new Bio::AlignIO(-format => 'fasta',
		       -file   => Bio::Root::IO->catfile('t','data',
							 'hs_owlmonkey.fasta'));

$aln = $in->next_aln();
ok($aln);

ok( $stats->transversions($aln),4);
ok( $stats->transitions($aln),14);
ok( $stats->pairwise_stats->number_of_gaps($aln),33);
ok( $stats->pairwise_stats->number_of_comparable_bases($aln),163);
ok( $stats->pairwise_stats->number_of_differences($aln),18);

# now test the distance calculations
if( 0 ) {
    $d = $stats->distance(-align => $aln, -method => 'jc');
    ok( sprintf("%.4f", $d->[1]->[2]), 0.1195);

    $d =  $stats->distance(-align => $aln,
			   -method => 'Kimura');
    ok( sprintf("%.4f", $d->[1]->[2]), 0.1219);

#    $d =  $stats->distance(-align => $aln,
#			   -method => 'TajimaNei');
#    ok( sprintf("%.4f", $d->[1]->[2]), 0.1246);
}
#ok( sprintf("%.4f", Bio::Align::DNAStatistics->D_JukesCantorInCor($aln)), 0.1104);

#ok( sprintf("%.4f", Bio::Align::DNAStatistics->D_Tamura($aln)), 0.1233);
#ok( sprintf("%.4f", Bio::Align::DNAStatistics->D_Tamura($aln)), 0.1246);
#ok( sprintf("%.4f", Bio::Align::DNAStatistics->D_JinNeiGamma($aln)), 0.1350);

### now test Nei_gojobori methods ##
$in = Bio::AlignIO->new(-format => 'fasta',
		       -file   => Bio::Root::IO->catfile('t','data', 'nei_gojobori_test.aln'));
my $alnobj = $in->next_aln();
ok($alnobj);
my $result = $stats->calc_KaKs_pair($alnobj, 'seq1', 'seq2');
ok (sprintf ("%.1f", $result->[0]{'S'}), 40.5);
ok (sprintf ("%.1f", $result->[0]{'z_score'}), '4.5');
$result = $stats->calc_all_KaKs_pairs($alnobj);
ok (int( $result->[1]{'S'}), 41);
ok (int( $result->[1]{'z_score'}), 4);
$result = $stats->calc_average_KaKs($alnobj, 100);
ok (sprintf ("%.4f", $result->{'D_n'}), 0.1628);