1
# -*-Perl-*- Test Harness script for Bioperl
10
test_begin(-tests => 24,
11
-requires_module => 'DB_File');
13
use_ok('Bio::SeqFeature::Collection');
14
use_ok('Bio::Location::Simple');
15
use_ok('Bio::Tools::GFF');
19
my $verbose = test_debug();
21
#First of all we need to create an flat db
22
my $simple = Bio::SeqIO->new(-format => 'genbank',
23
-file => test_input_file('AB077698.gb'));
26
my $seq = $simple->next_seq();
27
@features = $seq->top_SeqFeatures();
28
is(scalar @features, 11);
30
my $col = Bio::SeqFeature::Collection->new(-verbose => $verbose);
33
is($col->add_features( \@features), 11);
34
my @feat = $col->features_in_range(-range => ( Bio::Location::Simple->new
41
foreach my $f ( @feat ) {
42
print "location: ", $f->location->to_FTstring(), "\n";
46
is(scalar $col->features_in_range(-range => ( Bio::Location::Simple->new
50
-strandmatch => 'ignore',
53
@feat = $col->features_in_range(-start => 79,
56
-strandmatch => 'strong',
60
foreach my $f ( sort { $a->start <=> $b->start} @feat ) {
61
print $f->primary_tag, " ", $f->location->to_FTstring(), "\n";
65
is($feat[0]->primary_tag, 'CDS');
66
ok($feat[0]->has_tag('gene'));
69
# specify input via -fh or -file
70
my $gffio = Bio::Tools::GFF->new(-file => test_input_file('myco_sites.gff'),
73
# loop over the input stream
74
while(my $feature = $gffio->next_feature()) {
75
# do something with feature
76
push @features, $feature;
80
is(scalar @features, 412);
81
$col = Bio::SeqFeature::Collection->new(-verbose => $verbose,
86
is($col->add_features( \@features), 412);
88
my $r = Bio::Location::Simple->new(-start => 67700,
92
@feat = $col->features_in_range(-range => $r,
93
-strandmatch => 'ignore',
97
is($col->feature_count, 412);
98
my $count = $col->feature_count;
99
$col->remove_features( [$features[58], $features[60]]);
101
is( $col->feature_count, 410);
102
@feat = $col->features_in_range(-range => $r,
103
-strandmatch => 'ignore',
105
is( scalar @feat, 54);
106
# add the removed features back in in order to get the collection back to size
108
$col->add_features([$features[58], $features[60]]);
110
# let's randomize so we aren't removing and adding in the same order
111
# and hopefully randomly deal with a bin's expiration
112
fy_shuffle(\@features);
114
foreach my $f ( @features ) {
115
$count--, next unless defined $f;
116
$col->remove_features([$f]);
117
# ok( $col->feature_count, --$count);
119
is($col->feature_count, 0);
121
# explicitly destroy old instances above (should clear out any open filehandles
122
# w/o -keep flag set)
125
my $filename = test_output_file();
126
my $newcollection = Bio::SeqFeature::Collection->new(-verbose => $verbose,
129
$newcollection->add_features(\@feat);
130
is($newcollection->feature_count, 54);
131
undef $newcollection;
133
$newcollection = Bio::SeqFeature::Collection->new(-verbose => $verbose,
135
is($newcollection->feature_count, 54);
136
undef $newcollection;
138
# without -keep => 1, $filename was deleted as expected.
139
# to stop Bio::Root::Test complaining that the temp file was already deleted,
140
# we'll just create it again
141
open(TMP, ">", $filename);
146
my @fts = sort { $a->start <=> $b->start}
147
grep { $r->overlaps($_,'ignore') } @features;
150
foreach my $f ( @fts ) {
151
print $f->primary_tag, " ", $f->location->to_FTstring(), "\n";
156
my %G = map { ($_,1) } @feat;
158
foreach my $A ( @fts ) {
160
print "missing ", $A->primary_tag, " ", $A->location->to_FTstring(), "\n";
165
print "Number of features correctly retrieved $c\n";
166
foreach my $f ( sort { $a->start <=> $b->start} @feat ) {
167
print $f->primary_tag, " ", $f->location->to_FTstring(), "\n";
174
for( $i = @$array; $i--; ) {
175
my $j = int rand($i+1);
177
@$array[$i,$j] = @$array[$j,$i];