File: SeqBuilder.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 (141 lines) | stat: -rw-r--r-- 3,858 bytes parent folder | download | duplicates (2)
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
# -*-Perl-*- mode (to keep my emacs happy)
# $Id: SeqBuilder.t,v 1.2 2003/02/18 03:37:58 lapp Exp $

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

use Bio::Seq;
use Bio::SeqIO;
use Bio::Root::IO;

ok(1);

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

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

# default mode
$seqio = Bio::SeqIO->new('-file'=> Bio::Root::IO->catfile(
						   "t","data","test.genbank"), 
			 '-format' => 'GenBank');
ok $seqio;
$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()) {
    ok ($seq->accession_number, $loci[$numseqs++]);
    ok ($seq->annotation->get_Annotations());
    ok (scalar($seq->top_SeqFeatures), $numfeas[$numseqs-1]);
    ok ($seq->species->binomial);
    ok ($seq->seq);
}
ok ($numseqs, 5);

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

$numseqs = 0;

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

# everything but no sequence, and no features
$seqio = Bio::SeqIO->new('-file'=> Bio::Root::IO->catfile(
						   "t","data","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()) {
    ok ($seq->accession_number, $loci[$numseqs++]);
    ok scalar($seq->annotation->get_Annotations());
    if($numseqs <= 3) {
	ok (scalar($seq->top_SeqFeatures), 0);
    } else {
	ok (scalar($seq->top_SeqFeatures), $numfeas[$numseqs-1]);
    }
    ok $seq->species->binomial;
    ok ($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());
    }
}
ok ($numseqs, 5);

# skip sequences less than 100bp or accession like 'NT_*'
$seqio = Bio::SeqIO->new('-file'=> Bio::Root::IO->catfile(
						   "t","data","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++;
    ok ($seq->accession_number, $loci[$i]);
    ok scalar($seq->annotation->get_Annotations());
    ok (scalar($seq->top_SeqFeatures), $numfeas[$i]);
    ok $seq->species->binomial;
    ok $seq->seq;
    $i += 2;
}
ok ($numseqs, 3);