File: scf.t

package info (click to toggle)
bioperl 1.7.8-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 35,788 kB
  • sloc: perl: 94,019; xml: 14,811; makefile: 20
file content (307 lines) | stat: -rw-r--r-- 8,357 bytes parent folder | download | duplicates (2)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# -*-Perl-*- Test Harness script for Bioperl
# $Id$

use strict;

BEGIN {
    use Bio::Root::Test;
    
    test_begin(-tests => 80);
	
    use_ok('Bio::SeqIO::scf');
    use_ok('Bio::Seq::SequenceTrace');
}

my $verbose = test_debug();

ok my $in_scf = Bio::SeqIO->new(-file => test_input_file('chad100.scf'),
				-format => 'scf',
				-verbose => $verbose);

my $swq = $in_scf->next_seq();

isa_ok($swq,"Bio::Seq::SequenceTrace");

cmp_ok (length($swq->seq()), '>', 10);
my $qualities = join(' ',@{$swq->qual()});

cmp_ok (length($qualities), '>', 10);
my $id = $swq->id();
is ($swq->id(), "ML4942R");

my $a_channel = $swq->trace("a");
cmp_ok (scalar(@$a_channel), '>', 10);
my $c_channel = $swq->trace("c");
cmp_ok (scalar(@$c_channel), '>', 10);
my $g_channel = $swq->trace("g");
cmp_ok (scalar(@$g_channel), '>', 10);
my $t_channel = $swq->trace("t");
cmp_ok (scalar(@$t_channel), '>', 10);

my $ref = $swq->peak_indices();
my @indices = @$ref;
my $indexcount = 761;
is (scalar(@indices), $indexcount);

#use Data::Dumper;
#----------------------------------------
isa_ok $swq->seq_obj, 'Bio::Seq::Quality';
isa_ok $swq->qual_obj, 'Bio::Seq::Quality';
is $swq->alphabet, 'dna', 'alphabet';

is $swq->display_id, 'ML4942R', 'display_id';
like $swq->primary_id, qr/HASH/, 'primary_id is the stringified memory position';
is $swq->primary_id('ABC'), 'ABC', 'set primary_id';

is $swq->accession_number, 'unknown', 'accession_number';
is $swq->desc, undef, 'desc';
is $swq->desc('test'), 'test', 'desc';
is $swq->id, 'ML4942R', 'id';
is $swq->id('test'), 'test', 'id';
is length($swq->seq), $indexcount, 'seq';



my $len = 7; 
my $start = $swq->length-$len+1;
my $end = $swq->length;

is $swq->subseq($start,$end), 'cctcaag', 'subseq';
is $swq->baseat($start), 'c', 'baseat';
is $swq->qualat($start), '18', 'qualat';

is $swq->trace_value_at('a',$start), '482', 'trace_value_at';

TODO: {
    local $TODO = 'documentation and code for accuracies() do not match' if 1;
    is $swq->accuracies('a',$start), '482', 'accuracies';
}
my $qualstring = join(' ',@{$swq->subqual($start,$end)});
is ($qualstring, '18 18 21 15 8 8 8');

my $refs = $swq->sub_peak_index($start,$end);
is @$refs, $len, 'sub_peak_index';
is $swq->peak_index_at($start), 8819, 'peak_index_at';

my $indices_at_end = join(' ',@{$swq->sub_peak_index($start,$end)});
is($indices_at_end, '8819 8831 8843 8853 8862 8873 8891');

my $swq_end = $swq->trace_length();
my $swq_start = $swq_end - $len +1;
my $subtrace_a = join(' ',@{$swq->sub_trace('a',$swq_start,$swq_end)});
is $subtrace_a, '13 3 0 0 75 274 431';

my $swq2 = $swq->sub_trace_object(1,5);
#$traces2->verbose(-1);

isa_ok($swq2, 'Bio::Seq::SequenceTrace');

$swq2->_synthesize_traces(), 1; # this should not be a private method! Heikki
$swq2->set_accuracies(), 1;

is $swq->accuracy_at('a',1), '755', 'accuracy_at';

#----------------------------------------


warn("Now checking version3...\n") if $verbose;
my $in_scf_v3 = Bio::SeqIO->new(-file => test_input_file('version3.scf'),
				-format => 'scf',
				-verbose => $verbose);

my $v3 = $in_scf_v3->next_seq();
isa_ok($v3, 'Bio::Seq::SequenceTrace');
my $ind = $v3->peak_indices();
my @ff = @$ind;

@indices = @{$v3->peak_indices()};
is (scalar(@indices), 1106);

my %header = %{$in_scf_v3->get_header()};
is $header{bases}, 1106;
is $header{samples},  14107;

# is the Bio::Seq::SequenceTrace AnnotatableI?
my $ac = $v3->annotation();

isa_ok($ac,"Bio::Annotation::Collection");

my @name_comments = grep {$_->tagname() eq 'NAME'} 
$ac->get_Annotations('comment');

is $name_comments[0]->as_text(), 'Comment: IIABP1D4373';

# also get comments this way...
$ac = $in_scf_v3->get_comments();

isa_ok($ac,"Bio::Annotation::Collection");

@name_comments = grep {$_->tagname() eq 'NAME'} 
$ac->get_Annotations('comment');

is $name_comments[0]->as_text(), 'Comment: IIABP1D4373';

my @conv_comments = grep {$_->tagname() eq 'CONV'} 
$ac->get_Annotations('comment');

is $conv_comments[0]->as_text(), 'Comment: phred version=0.990722.h';

# is the SequenceTrace object annotated?
my $st_ac = $swq->annotation();

isa_ok ($st_ac, "Bio::Annotation::Collection");

my @ann =   $st_ac->get_Annotations();

is $ann[0]->tagname, 'SIGN';
is $ann[2]->text, 'SRC3700';
is $ann[5]->tagname, 'LANE';
is $ann[5]->text, 89;
is $ann[6]->text, 'phred version=0.980904.e';
is $ann[8]->text, 'ABI 373A or 377';

my $outfile = test_output_file();
my $out_scf = Bio::SeqIO->new(-file => ">$outfile",
			      -format => 'scf',
			      -verbose => $verbose);

# Bug 2196 - commentless scf

my $in = Bio::SeqIO->new(-file => test_input_file('13-pilE-F.scf'),
			 -format => 'scf',
			 -verbose => $verbose);

my $seq = $in->next_seq;

ok ($seq);

isa_ok($seq, 'Bio::Seq::SequenceTrace');

$ac = $seq->annotation;

isa_ok($ac, 'Bio::Annotation::Collection');

@name_comments = grep {$_->tagname() eq 'NAME'} 
$ac->get_Annotations('comment');

is $name_comments[0], undef;

@conv_comments = grep {$_->tagname() eq 'CONV'} 
$ac->get_Annotations('comment');

is $conv_comments[0], undef;

# the new way

warn("Now testing the _writing_ of scfs\n") if $verbose;

$out_scf->write_seq(-target	=>	$v3,
		    -MACH		=>	'CSM sequence-o-matic 5000',
		    -TPSW		=>	'trace processing software',
		    -BCSW		=>	'basecalling software',
		    -DATF		=>	'AM_Version=2.00',
		    -DATN		=>	'a22c.alf',
		    -CONV		=>	'Bioperl-scf.pm');

ok( -s $outfile && ! -z "$outfile" );

# TODO? tests below don't do much

$out_scf = Bio::SeqIO->new(-verbose => 1,
			   -file => ">$outfile",
			   -format => 'scf');

$swq = Bio::Seq::Quality->new(-seq =>'ATCGATCGAA',
			      -qual =>"10 20 30 40 50 20 10 30 40 50",
			      -alphabet =>'dna');

my $trace = Bio::Seq::SequenceTrace->new(-swq => $swq);

$out_scf->write_seq(	-target	        =>	$trace,
			-MACH		=>	'CSM sequence-o-matic 5000',
			-TPSW		=>	'trace processing software',
			-BCSW		=>	'basecalling software',
			-DATF		=>	'AM_Version=2.00',
			-DATN		=>	'a22c.alf',
			-CONV		=>	'Bioperl-scf.pm' );

warn("Trying to write an scf with a subset of a real scf...\n") if $verbose;
$out_scf = Bio::SeqIO->new(-verbose => 1,
			   -file => ">$outfile",
			   -format => 'scf');

$in_scf_v3 = Bio::SeqIO->new(-file => test_input_file('version3.scf'),
			     -format => 'scf',
			     -verbose => $verbose);
$v3 = $in_scf_v3->next_seq();

my $sub_v3 = $v3->sub_trace_object(5,50);

#warn("The subtrace object is this:\n") if $DEBUG;

$out_scf->write_seq(-target => $sub_v3 );

my $in_scf_v2 = Bio::SeqIO->new(-file => test_input_file('version2.scf'),
				-format => 'scf',
				-verbose => $verbose);
$v3 = $in_scf_v2->next_seq();
ok($v3);

$out_scf = Bio::SeqIO->new(-file   => ">$outfile",
                           -format => "scf");
$out_scf->write_seq( -target  => $v3,
                     -version => 2 );

# simple round trip tests (bug 2881)

my %file_map = (
	# filename         # write_seq args
	'chad100.scf'	=> 1,
	'13-pilE-F.scf' => 1,
	'version2.scf'  => 1,
	'version3.scf'  => 1
	);

for my $f (sort keys %file_map) {
	my $outfile = test_output_file();
	my $in = Bio::SeqIO->new(-file => test_input_file($f),
							 -format => 'scf');
	my $out = Bio::SeqIO->new(-file => ">$outfile",
							 -format => 'scf');
	
	my $seq1 = $in->next_seq();
	isa_ok($seq1, 'Bio::Seq::SequenceTrace');
	
	ok($out->write_seq(-target => $seq1));
	
	my $in2 = Bio::SeqIO->new(-file => "<$outfile",
							  -format => 'scf');
	my $seq2 = $in2->next_seq();
	isa_ok($seq2, 'Bio::Seq::SequenceTrace');
	if ($seq1->display_id) {
		TODO: {
			local $TODO = "display_id doesn't round trip yet";
			is($seq1->display_id, $seq2->display_id, 'display_id matches');
		}
	}
	is_deeply($seq1->qual, $seq2->qual, 'qual scores match');
}

# synthesizing traces roundtrip (bug 2881):

my @sequences=('A',
               'ATGGAGCTCATCAAAGAATCGACTCATATATCCATCCCTGAACGGCTGACTCACATTAATGGTTGA');
foreach my $sequence (@sequences) {
    my $qualstr=join ' ', map { 65 } (1 .. length($sequence));
    my $seq_qual=Bio::Seq::Quality->new(-seq=>$sequence, -qual=>$qualstr);

    my $outfile=test_output_file();
    my $out=Bio::SeqIO->new(-file=>">$outfile", -format=>'scf');
    $out->write_seq(-target=>$seq_qual);

    my $in=Bio::SeqIO->new(-file=>$outfile, -format=>'scf');
    my $in_seq=$in->next_seq();

    is_deeply($seq_qual, $in_seq->{swq}, 'Bio::Sequence::Quality matches');
}