[BUG] bug 2598
[bioperl-live.git] / t / GFF.t
blob823b5a46af04ff907396bf48d3ebd0068e0602f9
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 => 34);
11         
12     use_ok('Bio::Tools::GFF');
13     use_ok('Bio::SeqFeature::Generic');
16 my $feat = Bio::SeqFeature::Generic->new( -start => 10, -end => 100,
17                                 -strand => -1, -primary => 'repeat',
18                                 -source => 'repeatmasker',
19                                 -score  => 1000,
20                                 -tag    => {
21                                     new => 1,
22                                     author => 'someone',
23                                     sillytag => 'this is silly!;breakfast' } );
24 ok($feat);
26 my ($out1, $out2) = (test_output_file(), test_output_file());
27 my $gff1out = Bio::Tools::GFF->new(-gff_version => 1, -file => ">$out1");
28 ok($gff1out);
29 my $gff2out = Bio::Tools::GFF->new(-gff_version => 2, -file => ">$out2");
30 ok($gff2out);
32 $gff1out->write_feature($feat);
33 $gff2out->write_feature($feat);
35 $gff1out->close();
36 $gff2out->close();
38 my $gff1in = Bio::Tools::GFF->new(-gff_version => 1,  -file => "$out1");
39 ok($gff1in);
40 my $gff2in = Bio::Tools::GFF->new(-gff_version => 2, -file => "$out2");
41 ok($gff2in);
43 my $feat1 = $gff1in->next_feature();
44 ok($feat1);
45 is($feat1->start, $feat->start);
46 is($feat1->end, $feat->end);
47 is($feat1->primary_tag, $feat->primary_tag);
48 is($feat1->score, $feat->score);
50 my $feat2 = $gff2in->next_feature();
51 ok($feat2);
52 is($feat2->start, $feat->start);
53 is($feat2->end, $feat->end);
54 is($feat2->primary_tag, $feat->primary_tag);
55 is($feat2->score, $feat->score);
56 is(($feat2->each_tag_value('sillytag'))[0], 'this is silly!;breakfast');
58 #test sequence-region parsing
59 $gff2in = Bio::Tools::GFF->new(-gff_version => 2, -file => test_input_file('hg16_chroms.gff'));
60 is($gff2in->next_feature(),undef);
61 my $seq = $gff2in->next_segment;
62 is($seq->display_id, 'chr1');
63 is($seq->end, 246127941);
64 is($seq->start, 1);
67 # GFF3
68 SKIP: {
69         test_skip(-tests => 12, -requires_module => 'IO::String');
70     my $str = IO::String->new;
71     my $gffout = Bio::Tools::GFF->new(-fh => $str, -gff_version => 3);
72     my $feat_test = Bio::SeqFeature::Generic->new
73     (-primary_tag => 'tag',
74      -source_tag  => 'exon',
75      -seq_id      => 'testseq',
76      -score       => undef,
77      -start       => 10,
78      -end         => 120,
79      -strand      => 1,
80      -tag         => { 
81          'bungle' => 'jungle;mumble',
82          'lion'   => 'snake=tree'
83          });
84     $feat_test->add_tag_value('giant_squid', 'lakeshore manor');
85     $gffout->write_feature($feat_test);
86     seek($str,0,0);
87     my $in = Bio::Tools::GFF->new(-fh          => $str,
88                  -gff_version => 3);
89     my $f_recon = $in->next_feature;
90     is($f_recon->primary_tag, $feat_test->primary_tag);
91     is($f_recon->source_tag,  $feat_test->source_tag);
92     is($f_recon->score, $feat_test->score);
93     is($f_recon->start, $feat_test->start);
94     is($f_recon->end, $feat_test->end);
95     is($f_recon->strand, $feat_test->strand);
96     for my $tag ( $feat_test->get_all_tags ) {
97         ok($f_recon->has_tag($tag));
98         if( $f_recon->has_tag($tag) ) {
99             my @v = $feat_test->get_tag_values($tag);
100             my @g = $f_recon->get_tag_values($tag);
101             while( @v && @g ) {
102                is(shift @v, shift @g);
103             }
104         }
105     }