2 ## Bioperl Test Harness Script for Modules
10 $DEBUG = $ENV{'BIOPERLDEBUG'};
11 # to handle systems with no installed Test module
12 # we include the t dir (where a copy of Test.pm is located)
14 eval { require Test; };
25 use Bio::Matrix::Generic;
29 my $raw = [ [ 0, 10, 20],
33 my $matrix = new Bio::Matrix::Generic(-values => $raw,
34 -matrix_id => 'fakeid00',
35 -matrix_name=> 'matname',
36 -rownames => [qw(A B C)],
37 -colnames => [qw(D E F)] );
39 ok($matrix->matrix_name, 'matname');
40 ok($matrix->matrix_id, 'fakeid00');
41 ok($matrix->entry('A','F'), $raw->[0]->[2]);
42 my @colE = $matrix->get_column('E');
43 ok($colE[0], $raw->[0]->[1]);
44 ok($colE[1], $raw->[1]->[1]);
45 ok($colE[2], $raw->[2]->[1]);
47 my @rowC = $matrix->get_row('C');
48 ok($rowC[0], $raw->[2]->[0]);
49 ok($rowC[1], $raw->[2]->[1]);
50 ok($rowC[2], $raw->[2]->[2]);
52 ok($matrix->row_num_for_name('A'),0);
53 ok($matrix->column_num_for_name('D'),0);
55 ok($matrix->row_header(1),'B');
56 ok($matrix->column_header(0),'D');
58 ok($matrix->add_row(1, 'b', [qw(21 13 14)]),4);
59 ok($matrix->add_column(2, 'f', [qw(71 81 14 3)]),4);
61 ok($matrix->add_row(4, 'c', [qw(22 11 17)]),5);
62 ok($matrix->remove_row(4),4);
64 ok($matrix->add_column(4, 'g', [qw(11 10 100 71)]),5);
65 ok($matrix->remove_column(4),4);
67 ok($matrix->row_num_for_name('B'),2);
68 ok($matrix->row_num_for_name('b'),1);
70 ok($matrix->column_num_for_name('D'),0);
71 ok($matrix->column_num_for_name('F'),3);
72 ok($matrix->column_num_for_name('f'),2);
74 ok($matrix->row_header(2),'B');
76 ok($matrix->column_header(3),'F');
78 ok($matrix->get_entry('b', 'f'), 81);
81 # read in a scoring matrix
83 my $io = Bio::Matrix::IO->new(-format => 'scoring',
84 -file => Bio::Root::IO->catfile
85 (qw(t data BLOSUM50)));
86 my $blosum_matrix = $io->next_matrix;
87 ok($blosum_matrix->isa('Bio::Matrix::Scoring'));
88 ok($blosum_matrix->entropy, 0.4808);
89 ok($blosum_matrix->expected_score, -0.3573);
90 ok($blosum_matrix->scale, '1/3');
91 ok($blosum_matrix->get_entry('*','A'), -5);
92 ok($blosum_matrix->get_entry('V','Y'), -1);
93 ok($blosum_matrix->get_entry('Y','V'), -1);
94 ok($blosum_matrix->get_entry('L','I'), 2);
95 my @diag = $blosum_matrix->get_diagonal;
97 my @row = $blosum_matrix->get_row('D');
98 ok($row[5], $blosum_matrix->get_entry('D','Q'));
99 ok($blosum_matrix->num_rows,24);
100 ok($blosum_matrix->num_columns,24);
102 $io = Bio::Matrix::IO->new(-format => 'scoring',
103 -file => Bio::Root::IO->catfile
104 (qw(t data PAM250)));
105 my $pam_matrix = $io->next_matrix;
106 ok($pam_matrix->isa('Bio::Matrix::Scoring'));
107 ok($pam_matrix->entropy, 0.354);
108 ok($pam_matrix->expected_score, -0.844,);
109 ok($pam_matrix->scale, 'ln(2)/3');
110 ok($pam_matrix->num_rows,24);
111 ok($pam_matrix->get_entry('G','*'), -8);
112 ok($pam_matrix->get_entry('V','Y'), -2);
113 ok($pam_matrix->get_entry('Y','V'), -2);
114 ok($pam_matrix->get_entry('L','I'), 2);
115 @diag = $pam_matrix->get_diagonal;
117 @row = $pam_matrix->get_row('D');
118 ok($row[5], $pam_matrix->get_entry('D','Q'));
120 # test Phylip parsing
122 $io = new Bio::Matrix::IO(-format => 'phylip',
123 -program => 'phylipdist',
124 -file => Bio::Root::IO->catfile
125 (qw(t data phylipdist.out)));
127 my $phy = $io->next_matrix;
128 ok $phy->program, 'phylipdist';
129 ok $phy->get_entry('Alpha','Beta'), '4.23419';
130 ok $phy->get_entry('Gamma','Alpha'),'3.63330';
132 my @column = $phy->get_column('Alpha');
133 ok $column[0], '0.00000';
134 ok $column[1], '4.23419';
135 ok $column[2], '3.63330';
136 ok $column[3], '6.20865';
137 ok $column[4], '3.45431';
139 @row = $phy->get_row('Gamma');
140 ok $row[0], '3.63330';
141 ok $row[1], '3.49289';
142 ok $row[2], '0.00000';
143 ok $row[3], '3.68733';
144 ok $row[4], '5.84929';
146 @diag = $phy->get_diagonal;
148 ok $diag[0], '0.00000';
149 ok $diag[1], '0.00000';
150 ok $diag[2], '0.00000';
151 ok $diag[3], '0.00000';
152 ok $diag[4], '0.00000';