~ubuntu-branches/ubuntu/saucy/bioperl/saucy-proposed

« back to all changes in this revision

Viewing changes to t/Assembly/ContigSpectrum.t

  • Committer: Bazaar Package Importer
  • Author(s): Charles Plessy
  • Date: 2009-03-10 07:19:11 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090310071911-fukqzw54pyb1f0bd
Tags: 1.6.0-2
* Removed patch system (not used):
  - removed instuctions in debian/rules;
  - removed quilt from Build-Depends in debian/control.
* Re-enabled tests:
  - uncommented test command in debian/rules;
  - uncommented previously missing build-dependencies in debian/control.
  - Re-enabled tests and uncommented build-dependencies accordingly.
* Removed libmodule-build-perl and libtest-harness-perl from
  Build-Depends-Indep (provided by perl-modules).
* Better cleaning of empty directories using find -type d -empty -delete
  instead of rmdir in debian/rules (LP: #324001).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
use strict;
 
2
 
 
3
BEGIN {
 
4
    use lib '.';
 
5
    use Bio::Root::Test;
 
6
    test_begin(-tests => 134);
 
7
    use_ok('Bio::Assembly::IO');
 
8
    use_ok('Bio::Assembly::Tools::ContigSpectrum');
 
9
}
 
10
 
 
11
my $in = Bio::Assembly::IO->new(
 
12
  -file => test_input_file("contigspectrumtest.asm"),
 
13
  -format => 'tigr'
 
14
);
 
15
isa_ok($in, 'Bio::Assembly::IO');
 
16
my $sc = $in->next_assembly;
 
17
isa_ok($sc, 'Bio::Assembly::Scaffold');
 
18
 
 
19
# Try all the get/set methods
 
20
ok(my $csp = Bio::Assembly::Tools::ContigSpectrum->new);
 
21
isa_ok($csp, 'Bio::Assembly::Tools::ContigSpectrum');
 
22
ok($csp->id('asdf'));
 
23
is($csp->id, 'asdf');
 
24
ok($csp->nof_seq(123));
 
25
is($csp->nof_seq, 123);
 
26
ok($csp->nof_rep(456));
 
27
is($csp->nof_rep, 456);
 
28
ok($csp->max_size(789));
 
29
is($csp->max_size, 789);
 
30
ok($csp->nof_overlaps(111));
 
31
is($csp->nof_overlaps, 111);
 
32
ok($csp->min_overlap(50));
 
33
is($csp->min_overlap, 50);
 
34
ok($csp->avg_overlap(54.3));
 
35
is($csp->avg_overlap, 54.3);
 
36
ok($csp->min_identity(89.1));
 
37
is($csp->min_identity, 89.1);
 
38
ok($csp->avg_identity(98.7));
 
39
is($csp->avg_identity, 98.7);
 
40
ok($csp->avg_seq_len(123.456));
 
41
is($csp->avg_seq_len, 123.456);
 
42
ok($csp->eff_asm_params(1));
 
43
is($csp->eff_asm_params, 1);
 
44
 
 
45
# contig spectrum based on simple spectrum
 
46
ok(my $spectrum_csp = Bio::Assembly::Tools::ContigSpectrum->new);
 
47
ok($spectrum_csp->spectrum({1=>1, 2=>2, 3=>3}));
 
48
is($spectrum_csp->eff_asm_params, 0);
 
49
is($spectrum_csp->nof_seq, 14);
 
50
is($spectrum_csp->max_size, 3);
 
51
is($spectrum_csp->nof_rep, 1);
 
52
is($spectrum_csp->nof_overlaps, 0);
 
53
is($spectrum_csp->min_overlap, undef);
 
54
is($spectrum_csp->avg_overlap, 0);
 
55
is($spectrum_csp->min_identity, undef);
 
56
is($spectrum_csp->avg_identity, 0);
 
57
is($spectrum_csp->avg_seq_len, 0);
 
58
 
 
59
ok(my $string = $spectrum_csp->to_string(1));
 
60
is($string, '1 2 3');
 
61
ok($string = $spectrum_csp->to_string(2));
 
62
is($string, "1\t2\t3");
 
63
ok($string = $spectrum_csp->to_string(3));
 
64
is($string, "1\n2\n3");
 
65
 
 
66
# mixed contig spectrum imported from assembly
 
67
ok(my $mixed_csp = Bio::Assembly::Tools::ContigSpectrum->new(
 
68
  -assembly       => $sc,
 
69
  -eff_asm_params => 1 ));
 
70
is(scalar @{$mixed_csp->assembly()}, 1);
 
71
is_deeply($mixed_csp->spectrum, {1=>0, 9=>1}); # [0 0 0 0 0 0 0 0 1]
 
72
is($mixed_csp->eff_asm_params, 1);
 
73
is($mixed_csp->nof_seq, 9);
 
74
is($mixed_csp->max_size, 9);
 
75
is($mixed_csp->nof_rep, 1);
 
76
is($mixed_csp->nof_overlaps, 8);
 
77
is($mixed_csp->min_overlap, 35);
 
78
is($mixed_csp->avg_overlap, 71.875);
 
79
is($mixed_csp->min_identity, 97.1153846153846);
 
80
is($mixed_csp->avg_identity, 99.6394230769231);
 
81
is($mixed_csp->avg_seq_len, 100.222222222222);
 
82
 
 
83
# dissolved contig spectrum
 
84
ok(my $dissolved_csp = Bio::Assembly::Tools::ContigSpectrum->new(
 
85
  -dissolve => [$mixed_csp, 'ZZZ'] ));
 
86
is_deeply($dissolved_csp->spectrum, {1=>1}); # [1]
 
87
is($dissolved_csp->eff_asm_params, 0);
 
88
is($dissolved_csp->nof_seq, 1);
 
89
is($dissolved_csp->max_size, 1);
 
90
is($dissolved_csp->nof_rep, 1);
 
91
is($dissolved_csp->nof_overlaps, 0);
 
92
is($dissolved_csp->min_overlap, undef);
 
93
is($dissolved_csp->avg_overlap, 0);
 
94
is($dissolved_csp->min_identity, undef);
 
95
is($dissolved_csp->avg_identity, 0);
 
96
is($dissolved_csp->avg_seq_len, 96);
 
97
 
 
98
ok($dissolved_csp = Bio::Assembly::Tools::ContigSpectrum->new(
 
99
  -dissolve => [$mixed_csp, 'ABC'] ));
 
100
is_deeply($dissolved_csp->spectrum, {1=>1, 7=>1}); # [1 0 0 0 0 0 1]
 
101
is($dissolved_csp->eff_asm_params, 0);
 
102
is($dissolved_csp->nof_seq, 8);
 
103
is($dissolved_csp->max_size, 7);
 
104
is($dissolved_csp->nof_rep, 1);
 
105
is($dissolved_csp->nof_overlaps, 0);
 
106
is($dissolved_csp->min_overlap, undef);
 
107
is($dissolved_csp->avg_overlap, 0);
 
108
is($dissolved_csp->min_identity, undef);
 
109
is($dissolved_csp->avg_identity, 0);
 
110
is($dissolved_csp->avg_seq_len, 100.75);
 
111
 
 
112
ok($dissolved_csp = Bio::Assembly::Tools::ContigSpectrum->new(
 
113
  -min_overlap  => 62,
 
114
  -min_identity => 1,
 
115
  -dissolve     => [$mixed_csp, 'ABC'] ));
 
116
is_deeply($dissolved_csp->spectrum, {1=>1, 7=>1}); # [1 0 0 0 0 0 1]
 
117
 
 
118
ok($dissolved_csp = Bio::Assembly::Tools::ContigSpectrum->new(
 
119
   -min_overlap  => 63,
 
120
   -min_identity => 1,
 
121
   -dissolve     => [$mixed_csp, 'ABC'] ));
 
122
is_deeply($dissolved_csp->spectrum, {1=>1, 2=>1, 5=>1}); # [1 1 0 0 1]
 
123
 
 
124
ok($dissolved_csp = Bio::Assembly::Tools::ContigSpectrum->new(
 
125
  -min_overlap  => 62,
 
126
  -min_identity => 97,
 
127
  -dissolve     => [$mixed_csp, 'ABC'] ));
 
128
is_deeply($dissolved_csp->spectrum, {1=>1, 7=>1}); # [1 0 0 0 0 0 1]
 
129
 
 
130
ok($dissolved_csp = Bio::Assembly::Tools::ContigSpectrum->new(
 
131
   -min_overlap  => 62,
 
132
   -min_identity => 98,
 
133
   -dissolve     => [$mixed_csp, 'ABC'] ));
 
134
is_deeply($dissolved_csp->spectrum, {1=>2, 6=>1}); # [2 0 0 0 0 1]
 
135
 
 
136
ok($dissolved_csp = Bio::Assembly::Tools::ContigSpectrum->new(
 
137
  -dissolve       => [$mixed_csp, 'ABC'],
 
138
  -eff_asm_params => 1 ));
 
139
is_deeply($dissolved_csp->spectrum, {1=>1, 7=>1}); # [1 0 0 0 0 0 1]
 
140
is($dissolved_csp->eff_asm_params, 1);
 
141
is($dissolved_csp->nof_seq, 8);
 
142
is($dissolved_csp->max_size, 7);
 
143
is($dissolved_csp->nof_rep, 1);
 
144
is($dissolved_csp->nof_overlaps, 6);
 
145
is($dissolved_csp->min_overlap, 62);
 
146
is($dissolved_csp->avg_overlap, 81.3333333333333);
 
147
is($dissolved_csp->min_identity, 97.1153846153846);
 
148
is($dissolved_csp->avg_identity, 99.5192307692308);
 
149
is($dissolved_csp->avg_seq_len, 100.75);
 
150
 
 
151
# cross contig spectrum
 
152
ok(my $cross_csp = Bio::Assembly::Tools::ContigSpectrum->new(
 
153
  -cross => $mixed_csp));
 
154
is_deeply($cross_csp->spectrum, {1=>2, 9=>1}); # [2 0 0 0 0 0 0 0 1]
 
155
 
 
156
# sum of contig spectra
 
157
ok(my $sum_csp = Bio::Assembly::Tools::ContigSpectrum->new(-eff_asm_params=>1));
 
158
ok($sum_csp->add($dissolved_csp));
 
159
ok($sum_csp->add($mixed_csp));
 
160
is_deeply($sum_csp->spectrum, {1=>1, 7=>1, 9=>1}); # [1 0 0 0 0 0 1 0 1]
 
161
is($sum_csp->eff_asm_params, 1);
 
162
is($sum_csp->nof_seq, 17);
 
163
is($sum_csp->max_size, 9);
 
164
is($sum_csp->nof_rep, 2);
 
165
is($sum_csp->nof_overlaps, 14);
 
166
is($sum_csp->min_overlap, 35);
 
167
is($sum_csp->avg_overlap, 75.9285714285714);
 
168
is($sum_csp->min_identity, 97.1153846153846);
 
169
is($sum_csp->avg_identity, 99.5879120879121);
 
170
is($sum_csp->avg_seq_len, 100.470588235294);
 
171
 
 
172
# average of contig spectra
 
173
ok(my $avg_csp = Bio::Assembly::Tools::ContigSpectrum->new);
 
174
ok($avg_csp = $avg_csp->average([$dissolved_csp, $mixed_csp]));
 
175
is_deeply($avg_csp->spectrum, {1=>0.5, 7=>0.5, 9=>0.5}); # [0.5 0 0 0 0 0 0.5 0 0.5]
 
176
is($avg_csp->eff_asm_params, 1);
 
177
is($avg_csp->nof_seq, 8.5);
 
178
is($avg_csp->max_size, 9);
 
179
is($avg_csp->nof_rep, 2);
 
180
is($avg_csp->nof_overlaps, 7);
 
181
is($avg_csp->min_overlap, 35);
 
182
is($avg_csp->avg_overlap, 75.9285714285714);
 
183
is($avg_csp->min_identity, 97.1153846153846);
 
184
is($avg_csp->avg_identity, 99.5879120879121);
 
185
is($avg_csp->avg_seq_len, 100.470588235294);
 
186
 
 
187
# drop assembly info from contig spectrum
 
188
ok($mixed_csp->drop_assembly());
 
189
is(scalar @{$mixed_csp->assembly()}, 0);