Bio::Tools::CodonTable and Bio::Tools::IUPAC: prepare with dzil.
[bioperl-live.git] / t / Tools / GFF.t
blobc76c59c62d99d80b50e58b72e29f75a4bbc26780
1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id$
4 use strict;
6 BEGIN {     
7     use Bio::Root::Test;
8     
9     test_begin(-tests => 34);
10         
11     use_ok('Bio::Tools::GFF');
12     use_ok('Bio::SeqFeature::Generic');
15 my $feat = Bio::SeqFeature::Generic->new( -start => 10, -end => 100,
16                                 -strand => -1, -primary => 'repeat',
17                                 -source => 'repeatmasker',
18                                 -score  => 1000,
19                                 -tag    => {
20                                     new => 1,
21                                     author => 'someone',
22                                     sillytag => 'this is silly!;breakfast' } );
23 ok($feat);
25 my ($out1, $out2) = (test_output_file(), test_output_file());
26 my $gff1out = Bio::Tools::GFF->new(-gff_version => 1, -file => ">$out1");
27 ok($gff1out);
28 my $gff2out = Bio::Tools::GFF->new(-gff_version => 2, -file => ">$out2");
29 ok($gff2out);
31 $gff1out->write_feature($feat);
32 $gff2out->write_feature($feat);
34 $gff1out->close();
35 $gff2out->close();
37 my $gff1in = Bio::Tools::GFF->new(-gff_version => 1,  -file => "$out1");
38 ok($gff1in);
39 my $gff2in = Bio::Tools::GFF->new(-gff_version => 2, -file => "$out2");
40 ok($gff2in);
42 my $feat1 = $gff1in->next_feature();
43 ok($feat1);
44 is($feat1->start, $feat->start);
45 is($feat1->end, $feat->end);
46 is($feat1->primary_tag, $feat->primary_tag);
47 is($feat1->score, $feat->score);
49 my $feat2 = $gff2in->next_feature();
50 ok($feat2);
51 is($feat2->start, $feat->start);
52 is($feat2->end, $feat->end);
53 is($feat2->primary_tag, $feat->primary_tag);
54 is($feat2->score, $feat->score);
55 is(($feat2->get_tag_values('sillytag'))[0], 'this is silly!;breakfast');
57 #test sequence-region parsing
58 $gff2in = Bio::Tools::GFF->new(-gff_version => 2, -file => test_input_file('hg16_chroms.gff'));
59 is($gff2in->next_feature(),undef);
60 my $seq = $gff2in->next_segment;
61 is($seq->display_id, 'chr1');
62 is($seq->end, 246127941);
63 is($seq->start, 1);
66 # GFF3
67 SKIP: {
68         test_skip(-tests => 12, -requires_module => 'IO::String');
69     my $str = IO::String->new;
70     my $gffout = Bio::Tools::GFF->new(-fh => $str, -gff_version => 3);
71     my $feat_test = Bio::SeqFeature::Generic->new
72     (-primary_tag => 'tag',
73      -source_tag  => 'exon',
74      -seq_id      => 'testseq',
75      -score       => undef,
76      -start       => 10,
77      -end         => 120,
78      -strand      => 1,
79      -tag         => { 
80          'bungle' => 'jungle;mumble',
81          'lion'   => 'snake=tree'
82          });
83     $feat_test->add_tag_value('giant_squid', 'lakeshore manor');
84     $gffout->write_feature($feat_test);
85     seek($str,0,0);
86     my $in = Bio::Tools::GFF->new(-fh          => $str,
87                  -gff_version => 3);
88     my $f_recon = $in->next_feature;
89     is($f_recon->primary_tag, $feat_test->primary_tag);
90     is($f_recon->source_tag,  $feat_test->source_tag);
91     is($f_recon->score, $feat_test->score);
92     is($f_recon->start, $feat_test->start);
93     is($f_recon->end, $feat_test->end);
94     is($f_recon->strand, $feat_test->strand);
95     for my $tag ( $feat_test->get_all_tags ) {
96         ok($f_recon->has_tag($tag));
97         if( $f_recon->has_tag($tag) ) {
98             my @v = $feat_test->get_tag_values($tag);
99             my @g = $f_recon->get_tag_values($tag);
100             while( @v && @g ) {
101                is(shift @v, shift @g);
102             }
103         }
104     }