1 # -*-Perl-*- Test Harness script for Bioperl
12 -requires_module => 'DB_File'
15 use_ok('Bio::SeqFeature::Collection');
16 use_ok('Bio::Location::Simple');
17 use_ok('Bio::Tools::GFF');
21 my $verbose = test_debug();
23 #First of all we need to create an flat db
24 my $simple = Bio::SeqIO->new(
26 -file => test_input_file('AB077698.gb')
30 my $seq = $simple->next_seq();
31 @features = $seq->top_SeqFeatures();
32 is(scalar @features, 11);
34 ok my $col = Bio::SeqFeature::Collection->new(-verbose => $verbose);
36 is($col->add_features( \@features), 11);
37 my @feat = $col->features_in_range(
39 Bio::Location::Simple->new(
50 print "location: ", $f->location->to_FTstring(), "\n";
54 is(scalar $col->features_in_range(
56 Bio::Location::Simple->new(
62 -strandmatch => 'ignore',
66 @feat = $col->features_in_range(
70 -strandmatch => 'strong',
75 for my $f ( sort { $a->start <=> $b->start} @feat ) {
76 print $f->primary_tag, " ", $f->location->to_FTstring(), "\n";
80 is($feat[0]->primary_tag, 'CDS');
81 ok($feat[0]->has_tag('gene'));
84 # specify input via -fh or -file
85 my $gffio = Bio::Tools::GFF->new(
86 -file => test_input_file('myco_sites.gff'),
90 # loop over the input stream
91 while(my $feature = $gffio->next_feature()) {
92 # do something with feature
93 push @features, $feature;
97 is(scalar @features, 412);
98 $col = Bio::SeqFeature::Collection->new(
105 is($col->add_features( \@features), 412);
107 my $r = Bio::Location::Simple->new(
113 @feat = $col->features_in_range(
115 -strandmatch => 'ignore',
119 is(scalar @feat, 56);
120 is($col->feature_count, 412);
121 my $count = $col->feature_count;
122 $col->remove_features( [$features[58], $features[60]]);
124 is( $col->feature_count, 410);
125 @feat = $col->features_in_range(
127 -strandmatch => 'ignore',
130 is( scalar @feat, 54);
131 # add the removed features back in in order to get the collection back to size
133 $col->add_features([$features[58], $features[60]]);
135 # let's randomize so we aren't removing and adding in the same order
136 # and hopefully randomly deal with a bin's expiration
137 fy_shuffle(\@features);
139 for my $f ( @features ) {
140 $count--, next unless defined $f;
141 $col->remove_features([$f]);
142 # ok( $col->feature_count, --$count);
144 is($col->feature_count, 0);
146 # explicitly destroy old instances above (should clear out any open filehandles
147 # w/o -keep flag set)
150 my $filename = test_output_file();
151 my $newcollection = Bio::SeqFeature::Collection->new(
152 -verbose => $verbose,
156 $newcollection->add_features(\@feat);
157 is($newcollection->feature_count, 54);
158 undef $newcollection;
160 $newcollection = Bio::SeqFeature::Collection->new(
161 -verbose => $verbose,
164 is($newcollection->feature_count, 54);
165 undef $newcollection;
167 # without -keep => 1, $filename was deleted as expected.
168 # to stop Bio::Root::Test complaining that the temp file was already deleted,
169 # we'll just create it again
170 open(TMP, ">", $filename);
175 my @fts = sort { $a->start <=> $b->start}
176 grep { $r->overlaps($_,'ignore') } @features;
180 print $f->primary_tag, " ", $f->location->to_FTstring(), "\n";
185 my %G = map { ($_,1) } @feat;
189 print "missing ", $A->primary_tag, " ", $A->location->to_FTstring(), "\n";
194 print "Number of features correctly retrieved $c\n";
195 for my $f ( sort { $a->start <=> $b->start} @feat ) {
196 print $f->primary_tag, " ", $f->location->to_FTstring(), "\n";
203 for( $i = @$array; $i--; ) {
204 my $j = int rand($i+1);
206 @$array[$i,$j] = @$array[$j,$i];