Catch failing tie'd DB_File handle
[bioperl-live.git] / t / FeatureIO.t
blobb52c3e2d357c44842cbeb74fd4f6c9c105770b9f
1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id$
4 use strict;
6 BEGIN {
7   use lib 't/lib';
8   use BioperlTest;
9   
10   test_begin(-tests => 33,
11                          -requires_module => 'Graph');
12   
13   use_ok('Bio::FeatureIO');
16 my $io;
17 my $f;
18 my $s;
19 my $fcount;
20 my $scount;
22 ################################################################################
24 # use FeatureIO::gff to read a FASTA file.
26 $fcount = 0;
27 $scount = 0;
29 ok( $io = Bio::FeatureIO->new( -file => test_input_file('dna1.fa') ) );
31 #read features
32 while($f = $io->next_feature()){
33 warn $f;
34   $fcount++;
36 is($fcount, 0);
38 #then try to read sequences again.  should get seqs now
39 while($s = $io->next_seq()){
40   $scount++;
42 is($scount,  1);
44 ################################################################################
46 # use FeatureIO::gff to read a GFF3 file.
48 $fcount = 0;
49 $scount = 0;
51 ok( $io = Bio::FeatureIO->new( -file => test_input_file('knownGene.gff3') ) );
53 #try to read sequences first.  should be undef
54 while($s = $io->next_seq()){
55   $scount++;
57 is($scount,0);
59 #then read features
60 while($f = $io->next_feature()){
61   $fcount++;
63 is($fcount, 15);
65 #then try to read sequences again.  should still be undef
66 while($s = $io->next_seq()){
67   $scount++;
69 is($scount,0);
71 ################################################################################
73 # use FeatureIO::gff to read a GFF3 file w/ directivized FASTA tail
75 $fcount = 0;
76 $scount = 0;
78 ok( $io = Bio::FeatureIO->new( -file => test_input_file('hybrid1.gff3') ) );
80 #try to read sequences first.  should be undef
81 while($s = $io->next_seq()){
82   $scount++;
84 is($scount , 0);
86 #then read features
87 while($f = $io->next_feature()){
88   $fcount++;
90 is($fcount , 6);
92 #then try to read sequences again.
93 while($s = $io->next_seq()){
94   $scount++;
96 is($scount , 1);
98 ################################################################################
100 # use FeatureIO::gff to read a GFF3 file w/ non-directivized FASTA tail
102 $fcount = 0;
103 $scount = 0;
105 ok( $io = Bio::FeatureIO->new( -file => test_input_file('hybrid2.gff3') ) );
107 #try to read sequences first.  should be undef
108 while($s = $io->next_seq()){
109   $scount++;
111 is($scount , 0);
113 #then read features
114 while($f = $io->next_feature()){
115   $fcount++;
117 is($fcount , 6);
119 ################################################################################
121 # use FeatureIO::gff to read a GFF3 file of directives
123 $fcount = 0;
124 $scount = 0;
126 ok( $io = Bio::FeatureIO->new(-file => test_input_file('directives.gff3'),
127                                                           -verbose => test_debug() ? test_debug() : -1));
129 #read features
130 while($f = $io->next_feature()){
131   $fcount++;
133 is($fcount , 1); #sequence-region
135 ################################################################################
137 # use FeatureIO::gff to read a GFF3 file as aggregated feature groups
139 $fcount = 0;
140 $scount = 0;
142 ok( $io = Bio::FeatureIO->new( -file => test_input_file('hybrid1.gff3') ) );
144 #try to read sequences first.  should be undef
145 while($s = $io->next_seq()){
146   $scount++;
148 is($scount , 0);
150 #read feature groups
151 $f = $io->next_feature_group();
152 is($f , 1);
153 $f = $io->next_feature_group();
154 is($f , 0);
156 #then try to read sequences again.
157 while($s = $io->next_seq()){
158   $scount++;
160 is($scount , 1);
162 ################################################################################
164 # use FeatureIO::gff to read a PTT file.
166 $fcount = 0;
168 my $ptt_in = Bio::FeatureIO->new(
169   -file => test_input_file('test.ptt'), 
170   -format => 'ptt',
172 ok($ptt_in);
174 while (my $f = $ptt_in->next_feature) {
175   $fcount++;
176   if ($fcount==2) {
177     # 2491..3423  + 310 24217063  metF  LB002 - COG0685E  5,10-methylenetetrahydrofolate reductase
178     is( $f->start , 2491 );
179     is( $f->end , 3423 );
180     cmp_ok( $f->strand, '>', 0 );
181     is( ($f->get_tag_values('PID'))[0],'24217063' );
182     is( ($f->get_tag_values('Gene'))[0], 'metF' );
183     is( ($f->get_tag_values('Synonym'))[0], 'LB002' );
184     ok( ! $f->has_tag('Code') );
185     is( ($f->get_tag_values('COG'))[0],'COG0685E' );
186     is( ($f->get_tag_values('Product'))[0], '5,10-methylenetetrahydrofolate reductase' );   
187   }
189 is($fcount , 367);