1 # -*-Perl-*- Test Harness script for Bioperl
10 test_begin(-tests => 50,
11 -requires_module => 'Graph');
13 use_ok('Bio::FeatureIO');
22 ################################################################################
24 # use FeatureIO::gff to read a FASTA file.
29 ok( $io = Bio::FeatureIO->new( -file => test_input_file('dna1.fa') ) );
32 while($f = $io->next_feature()){
39 #then try to read sequences again. should get seqs now
40 while($s = $io->next_seq()){
43 local $TODO = 'How did this ever work?!?';
51 ################################################################################
53 # use FeatureIO::gff to read a GFF3 file.
58 ok( $io = Bio::FeatureIO->new( -file => test_input_file('knownGene.gff3') ) );
60 #try to read sequences first. should be undef
61 while($s = $io->next_seq()){
67 while($f = $io->next_feature()){
72 #then try to read sequences again. should still be undef
73 while($s = $io->next_seq()){
78 ################################################################################
80 # use FeatureIO::gff to read a GFF3 file w/ directivized FASTA tail
85 ok( $io = Bio::FeatureIO->new( -file => test_input_file('hybrid1.gff3') ) );
87 #try to read sequences first. should be undef
89 while($s = $io->next_seq()){
95 while($f = $io->next_feature()){
100 #then try to read sequences again.
101 isa_ok $io->seqio, 'Bio::SeqIO';
102 while($s = $io->next_seq()){
104 isa_ok $s, 'Bio::Seq';
106 local $TODO = 'How did this ever work?!?';
108 is($s->seq, 'Test1');
114 ################################################################################
116 # use FeatureIO::gff to read a GFF3 file w/ non-directivized FASTA tail
121 ok( $io = Bio::FeatureIO->new( -file => test_input_file('hybrid2.gff3') ) );
123 #try to read sequences first. should be undef
124 while($s = $io->next_seq()){
130 while($f = $io->next_feature()){
135 ################################################################################
137 # use FeatureIO::gff to read a GFF3 file of directives
142 ok( $io = Bio::FeatureIO->new(-file => test_input_file('directives.gff3'),
143 -verbose => test_debug() ? test_debug() : -1));
146 while($f = $io->next_feature()){
149 is($fcount , 1); #sequence-region
151 ################################################################################
153 # use FeatureIO::gff to read a GFF3 file as aggregated feature groups
158 ok( $io = Bio::FeatureIO->new( -file => test_input_file('hybrid1.gff3') ) );
160 #try to read sequences first. should be undef
161 while($s = $io->next_seq()){
167 $f = $io->next_feature_group();
169 $f = $io->next_feature_group();
172 #then try to read sequences again.
173 while($s = $io->next_seq()){
176 local $TODO = 'How did this ever work?!?';
178 is($s->seq, 'Test1');
185 ################################################################################
187 # use FeatureIO::bed to read a bed file
189 ok($io = Bio::FeatureIO->new(-file => test_input_file('1.bed')));
191 ok($f = $io->next_feature);
192 # Check correct conversion of [0, feature-end+1) bed-coordinates into [1, feature-end]
193 # bioperl coordinates. (here: bed [0, 10))
197 # Check field values.
198 my @tags = $f->get_tag_values("Name");
199 is(scalar(@tags), 1);
200 is($tags[0], "test-coordinates-1");
202 is($f->seq_id, "chr1");
208 ################################################################################
210 # use FeatureIO::ptt to read a PTT file.
214 my $ptt_in = Bio::FeatureIO->new(
215 -file => test_input_file('test.ptt'),
220 while (my $f = $ptt_in->next_feature) {
223 # 2491..3423 + 310 24217063 metF LB002 - COG0685E 5,10-methylenetetrahydrofolate reductase
224 is( $f->start , 2491 );
225 is( $f->end , 3423 );
226 cmp_ok( $f->strand, '>', 0 );
227 is( ($f->get_tag_values('PID'))[0],'24217063' );
228 is( ($f->get_tag_values('Gene'))[0], 'metF' );
229 is( ($f->get_tag_values('Synonym'))[0], 'LB002' );
230 ok( ! $f->has_tag('Code') );
231 is( ($f->get_tag_values('COG'))[0],'COG0685E' );
232 is( ($f->get_tag_values('Product'))[0], '5,10-methylenetetrahydrofolate reductase' );
237 ################################################################################
239 # use FeatureIO::vecscreen_simple to read a vecscreen file
244 my @expected_features =
247 'seq_id' => 'C02HBa0072A04.1',
248 'primary_tag' => 'moderate_match',
253 'seq_id' => 'SL_FOS91h17_SP6_0',
254 'primary_tag' => 'strong_match',
259 'seq_id' => 'SL_FOS91h18_T7_0',
260 'primary_tag' => 'strong_match',
265 'seq_id' => 'SL_FOS91h18_T7_0',
266 'primary_tag' => 'moderate_match',
271 'seq_id' => 'SL_FOS91h18_T7_0',
272 'primary_tag' => 'weak_match',
277 'seq_id' => 'SL_FOS91h18_T7_0',
278 'primary_tag' => 'suspect_origin',
283 'seq_id' => 'SL_FOS91i01_SP6_0',
284 'primary_tag' => 'strong_match',
289 'seq_id' => 'SL_FOS91i01_SP6_0',
290 'primary_tag' => 'suspect_origin',
295 'seq_id' => 'SL_FOS92b12_T7_0',
296 'primary_tag' => 'strong_match',
301 'seq_id' => 'SL_FOS92b12_T7_0',
302 'primary_tag' => 'moderate_match',
307 'seq_id' => 'SL_FOS92b12_T7_0',
308 'primary_tag' => 'weak_match',
313 'seq_id' => 'SL_FOS92b12_T7_0',
314 'primary_tag' => 'weak_match',
319 'seq_id' => 'SL_FOS92b12_T7_0',
320 'primary_tag' => 'suspect_origin',
325 'seq_id' => 'SL_FOS92b12_T7_0',
326 'primary_tag' => 'suspect_origin',
332 my $vs_in = Bio::FeatureIO->new( -file => test_input_file('vecscreen_simple.test_output'),
333 -format => 'vecscreen_simple',
336 while(my $feat = $vs_in->next_feature) {
337 push @vs_features,$feat;
340 #convert the array of feature objects to something that can more easily be checked with is_deeply
343 my $rec = { map {$_ => $f->$_()} qw/start end primary_tag seq_id/ };
346 is_deeply(\@vs_features,\@expected_features,'vecscreen_simple gets the correct features');
349 ###############################################################################
351 # use FeatureIO to get some attributes from a GFF file
354 ok( $io = Bio::FeatureIO->new( -file => test_input_file('knownGene.gff3') ) );
356 while($f = $io->next_feature()){
357 if ($f->get_Annotations('Target')) {
358 # the last feature in the file should have a Target attribute
359 my $value_obj = $f->get_Annotations('Target');
360 is($value_obj->target_id, "BC046356.1%20space%20test");