1 # -*-Perl-*- Test Harness script for Bioperl
11 -requires_module => 'DB_File'
14 use_ok('Bio::SeqFeature::Collection');
15 use_ok('Bio::Location::Simple');
16 use_ok('Bio::Tools::GFF');
20 my $verbose = test_debug();
22 #First of all we need to create an flat db
23 my $simple = Bio::SeqIO->new(
25 -file => test_input_file('AB077698.gb')
29 my $seq = $simple->next_seq();
30 @features = $seq->top_SeqFeatures();
31 is(scalar @features, 11);
33 ok my $col = Bio::SeqFeature::Collection->new(-verbose => $verbose);
35 is($col->add_features( \@features), 11);
36 my @feat = $col->features_in_range(
38 Bio::Location::Simple->new(
49 print "location: ", $f->location->to_FTstring(), "\n";
53 is(scalar $col->features_in_range(
55 Bio::Location::Simple->new(
61 -strandmatch => 'ignore',
65 @feat = $col->features_in_range(
69 -strandmatch => 'strong',
74 for my $f ( sort { $a->start <=> $b->start} @feat ) {
75 print $f->primary_tag, " ", $f->location->to_FTstring(), "\n";
79 is($feat[0]->primary_tag, 'CDS');
80 ok($feat[0]->has_tag('gene'));
83 # specify input via -fh or -file
84 my $gffio = Bio::Tools::GFF->new(
85 -file => test_input_file('myco_sites.gff'),
89 # loop over the input stream
90 while(my $feature = $gffio->next_feature()) {
91 # do something with feature
92 push @features, $feature;
96 is(scalar @features, 412);
97 $col = Bio::SeqFeature::Collection->new(
104 is($col->add_features( \@features), 412);
106 my $r = Bio::Location::Simple->new(
112 @feat = $col->features_in_range(
114 -strandmatch => 'ignore',
118 is(scalar @feat, 56);
119 is($col->feature_count, 412);
120 my $count = $col->feature_count;
121 $col->remove_features( [$features[58], $features[60]]);
123 is( $col->feature_count, 410);
124 @feat = $col->features_in_range(
126 -strandmatch => 'ignore',
129 is( scalar @feat, 54);
130 # add the removed features back in in order to get the collection back to size
132 $col->add_features([$features[58], $features[60]]);
134 # let's randomize so we aren't removing and adding in the same order
135 # and hopefully randomly deal with a bin's expiration
136 fy_shuffle(\@features);
138 for my $f ( @features ) {
139 $count--, next unless defined $f;
140 $col->remove_features([$f]);
141 # ok( $col->feature_count, --$count);
143 is($col->feature_count, 0);
145 # explicitly destroy old instances above (should clear out any open filehandles
146 # w/o -keep flag set)
149 my $filename = test_output_file();
150 my $newcollection = Bio::SeqFeature::Collection->new(
151 -verbose => $verbose,
155 $newcollection->add_features(\@feat);
156 is($newcollection->feature_count, 54);
157 undef $newcollection;
159 $newcollection = Bio::SeqFeature::Collection->new(
160 -verbose => $verbose,
163 is($newcollection->feature_count, 54);
164 undef $newcollection;
166 # without -keep => 1, $filename was deleted as expected.
167 # to stop Bio::Root::Test complaining that the temp file was already deleted,
168 # we'll just create it again
169 open my $TMP, '>', $filename or die "Could not write file '$filename': $!\n";
174 my @fts = sort { $a->start <=> $b->start}
175 grep { $r->overlaps($_,'ignore') } @features;
179 print $f->primary_tag, " ", $f->location->to_FTstring(), "\n";
184 my %G = map { ($_,1) } @feat;
188 print "missing ", $A->primary_tag, " ", $A->location->to_FTstring(), "\n";
193 print "Number of features correctly retrieved $c\n";
194 for my $f ( sort { $a->start <=> $b->start} @feat ) {
195 print $f->primary_tag, " ", $f->location->to_FTstring(), "\n";
202 for( $i = @$array; $i--; ) {
203 my $j = int rand($i+1);
205 @$array[$i,$j] = @$array[$j,$i];