File: SeqBuilder.t

package info (click to toggle)
bioperl 1.6.1-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 40,768 kB
  • ctags: 12,005
  • sloc: perl: 174,299; xml: 13,923; sh: 1,941; lisp: 1,803; asm: 109; makefile: 53
file content (129 lines) | stat: -rw-r--r-- 3,563 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
# -*-Perl-*- Test Harness script for Bioperl
# $Id: SeqBuilder.t 15112 2008-12-08 18:12:38Z sendu $

use strict;

BEGIN {     
    use lib '.';
    use Bio::Root::Test;
    
    test_begin(-tests => 101);
	
	use_ok('Bio::SeqIO');
}

my $verbosity = test_debug();

my ($seqio, $seq); # predeclare variables for strict

# default mode
ok $seqio = Bio::SeqIO->new('-file'=> test_input_file('test.genbank'), 
			 '-format' => 'GenBank');
$seqio->verbose($verbosity);

my $numseqs = 0;
my @loci = qw(U63596 U63595 M37762 NT_010368 L26462);
my @numfeas = (3,1,6,3,26);

while($seq = $seqio->next_seq()) {
    is ($seq->accession_number, $loci[$numseqs++]);
    ok ($seq->annotation->get_Annotations());
    is (scalar($seq->top_SeqFeatures), $numfeas[$numseqs-1]);
    ok ($seq->species->binomial);
    ok ($seq->seq);
}
is ($numseqs, 5);

# minimalistic mode
$seqio = Bio::SeqIO->new('-file'=> test_input_file('test.genbank'), 
			 '-format' => 'GenBank');
ok $seqio;
$seqio->verbose($verbosity);
ok my $seqbuilder = $seqio->sequence_builder();
isa_ok $seqbuilder, "Bio::Factory::ObjectBuilderI";
$seqbuilder->want_none();
$seqbuilder->add_wanted_slot('display_id','accession_number','desc');

$numseqs = 0;

while($seq = $seqio->next_seq()) {
    is ($seq->accession_number, $loci[$numseqs++]);
    is (scalar(grep { ! ($_->tagname eq "keyword" ||
			 $_->tagname eq "date_changed" ||
			 $_->tagname eq "secondary_accession"); }
	       $seq->annotation->get_Annotations()), 0);
    if($numseqs <= 3) {
		is (scalar($seq->top_SeqFeatures), 0);
    }
	else {
		is (scalar($seq->top_SeqFeatures), $numfeas[$numseqs-1]);
    }
    is ($seq->species, undef);
    is ($seq->seq, undef);
    # switch on features for the last 2 seqs
    $seqbuilder->add_wanted_slot('features') if $numseqs == 3;
}
is ($numseqs, 5);

# everything but no sequence, and no features
$seqio = Bio::SeqIO->new('-file'=> test_input_file('test.genbank'), 
			 '-format' => 'GenBank');
ok $seqio;
$seqio->verbose($verbosity);
$seqbuilder = $seqio->sequence_builder();
# want-all is default
$seqbuilder->add_unwanted_slot('seq','features');

$numseqs = 0;

while($seq = $seqio->next_seq()) {
    is ($seq->accession_number, $loci[$numseqs++]);
    ok scalar($seq->annotation->get_Annotations());
    if($numseqs <= 3) {
		is (scalar($seq->top_SeqFeatures), 0);
    }
	else {
		is (scalar($seq->top_SeqFeatures), $numfeas[$numseqs-1]);
    }
    ok $seq->species->binomial;
    is ($seq->seq, undef);
    # switch on features for the last 2 seqs
    if($numseqs == 3) {
	$seqbuilder->add_unwanted_slot(
	     grep { $_ ne 'features'; } $seqbuilder->remove_unwanted_slots());
    }
}
is ($numseqs, 5);

# skip sequences less than 100bp or accession like 'NT_*'
$seqio = Bio::SeqIO->new('-file'=> test_input_file('test.genbank'), 
			 '-format' => 'GenBank');
ok $seqio;
$seqio->verbose($verbosity);
$seqbuilder = $seqio->sequence_builder();
# we could have as well combined the two conditions into one, but we want to
# test the implicit AND here
$seqbuilder->add_object_condition(sub {
    my $h = shift;
    return 0 if($h->{'-length'} < 100);
    return 1;
});
$seqbuilder->add_object_condition(sub {
    my $h = shift;
    return 0 if($h->{'-display_id'} =~ /^NT_/);
    return 1;
});

$numseqs = 0;
my $i = 0;

while($seq = $seqio->next_seq()) {
    $numseqs++;
    is ($seq->accession_number, $loci[$i]);
    ok scalar($seq->annotation->get_Annotations());
    is (scalar($seq->top_SeqFeatures), $numfeas[$i]);
    ok $seq->species->binomial;
    ok $seq->seq;
    $i += 2;
}
is ($numseqs, 3);