File: Unflattener2.t

package info (click to toggle)
bioperl 1.4-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 20,336 kB
  • ctags: 8,476
  • sloc: perl: 119,890; xml: 6,001; lisp: 121; makefile: 57
file content (168 lines) | stat: -rw-r--r-- 4,585 bytes parent folder | download
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
# -*-Perl-*- mode (to keep my emacs happy)
# $Id: Unflattener2.t,v 1.6 2003/12/12 20:39:16 cjm Exp $

use strict;
use vars qw($DEBUG $TESTCOUNT);
BEGIN {     
    eval { require Test; };
    if( $@ ) {
	use lib 't';
    }
    use Test;
    $TESTCOUNT = 11;
    plan tests => $TESTCOUNT;
}

use Bio::Seq;
use Bio::SeqIO;
use Bio::Root::IO;
use Bio::SeqFeature::Tools::Unflattener;

ok(1);

my $verbosity = 0;   # Set to -1 for release version, so warnings aren't printed
#$verbosity = 1;

my ($seq, @sfs);
my $unflattener = Bio::SeqFeature::Tools::Unflattener->new;
$unflattener->verbose($verbosity);

if (1) {
    
    # this is an arabidopsise gbk record. it has no mRNA features.
    # it has explicit exon/intron records

    my @path = ("t","data","ATF14F8.gbk");
    $seq = getseq(@path);
    
    ok ($seq->accession_number, 'AL391144');
    my @topsfs = $seq->get_SeqFeatures;
    my @cdss = grep {$_->primary_tag eq 'CDS'} @topsfs;
    my $n = scalar(@topsfs);
    printf "TOP:%d\n", scalar(@topsfs);
#    write_hier(@topsfs);
    
    # UNFLATTEN
    @sfs = $unflattener->unflatten_seq(-seq=>$seq,
				       -use_magic=>1,
				      );
    print "\n\nPOST PROCESSING:\n";
    @sfs = $seq->get_SeqFeatures;
    write_hier(@sfs);
    printf "PROCESSED/TOP:%d\n", scalar(@sfs);
    ok(@sfs == 28);
    my @allsfs = $seq->get_all_SeqFeatures;
    printf "ALL:%d\n", scalar(@allsfs);
    ok(@allsfs == 202);
    my @mrnas = grep {$_->primary_tag eq 'mRNA'} @allsfs;
    printf "mRNAs:%d\n", scalar(@mrnas);
    # relationship between mRNA and CDS should be one-one
    ok(@mrnas == @cdss);
}

if (1) {
    
    # this is a record from FlyBase
    # it has mRNA features, and explicit exon/intron records

    my @path = ("t","data","AnnIX-v003.gbk");
    $seq = getseq(@path);
    
    my @topsfs = $seq->get_SeqFeatures;
    printf "TOP:%d\n", scalar(@topsfs);
#    write_hier(@topsfs);
    
    # UNFLATTEN
    @sfs = $unflattener->unflatten_seq(-seq=>$seq,
				       -use_magic=>1,
				      );
    print "\n\nPOST PROCESSING:\n";
    @sfs = $seq->get_SeqFeatures;
    write_hier(@sfs);
    printf "PROCESSED/TOP:%d\n", scalar(@sfs);
    ok(@sfs == 1);
    my @exons = grep {$_->primary_tag eq 'exon'} $seq->get_all_SeqFeatures;
    ok(@exons == 10);    # total number of exons per splice
    my %numberh = map {$_->get_tag_values("number") => 1} @exons;
    my @numbers = keys %numberh;
    printf "DISTINCT EXONS: %d [@numbers]\n", scalar(@numbers);
    ok(@numbers == 6);  # distinct exons
}

if (1) {
    
    # example of a BAD genbank entry

    my @path = ("t","data","dmel_2Lchunk.gb");
    $seq = getseq(@path);
    
    my @topsfs = $seq->get_SeqFeatures;
    printf "TOP:%d\n", scalar(@topsfs);
#    write_hier(@topsfs);
    
    # UNFLATTEN
    #
    # we EXPECT problems with this erroneous record
    $unflattener->error_threshold(2);
    @sfs = $unflattener->unflatten_seq(-seq=>$seq,
                                       -use_magic=>1,
                                      );
    my @probs = $unflattener->get_problems;
    $unflattener->report_problems(\*STDOUT);
    $unflattener->clear_problems;
    print "\n\nPOST PROCESSING:\n";
    @sfs = $seq->get_SeqFeatures;
    write_hier(@sfs);
    printf "PROCESSED/TOP:%d\n", scalar(@sfs);
    ok(@sfs == 2);
    my @exons = grep {$_->primary_tag eq 'exon'} $seq->get_all_SeqFeatures;
    ok(@exons == 6);    # total number of exons per splice

    printf "PROBLEMS ENCOUNTERED: %d (EXPECTED: 6)\n", scalar(@probs);
    ok(@probs == 6);
}


sub write_hier {
    my @sfs = @_;
    _write_hier(0, @sfs);
}
sub _write_hier {
    my $indent = shift;
    my @sfs = @_;
    foreach my $sf (@sfs) {
        my $label = '?';
        if ($sf->has_tag('gene')) {
            ($label) = $sf->get_tag_values('gene');
        }
        if ($sf->has_tag('product')) {
            ($label) = $sf->get_tag_values('product');
        }
        if ($sf->has_tag('number')) {
            $label = join("; ", $sf->get_tag_values('number'));
        }
        printf "%s%s $label\n", '  ' x $indent, $sf->primary_tag;
        my @sub_sfs = $sf->sub_SeqFeature;
        _write_hier($indent+1, @sub_sfs);
    }
}

sub getseq {
    my @path = @_;
    my $seqio =
      Bio::SeqIO->new('-file'=> Bio::Root::IO->catfile(
                                                       @path
                                                      ), 
                      '-format' => 'GenBank');
    $seqio->verbose($verbosity);

    my $seq = $seqio->next_seq();
    return $seq;
}

# 1 2,3
# 2 1,2
# 3 4,5
# 4 1,4,5,6
# 5 1,4,5,6
# 6 1,4,5,6