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 my $filename = test_output_file();
122 my $newcollection = Bio::SeqFeature::Collection->new(-verbose => $verbose,
125 $newcollection->add_features(\@feat);
126 is($newcollection->feature_count, 54);
127 undef $newcollection;
129 $newcollection = Bio::SeqFeature::Collection->new(-verbose => $verbose,
131 is($newcollection->feature_count, 54);
132 undef $newcollection;
134 # without -keep => 1, $filename was deleted as expected.
135 # to stop BioperlTest complaining that the temp file was already deleted,
136 # we'll just create it again
137 open(TMP, ">", $filename);
142 my @fts = sort { $a->start <=> $b->start}
143 grep { $r->overlaps($_,'ignore') } @features;
146 foreach my $f ( @fts ) {
147 print $f->primary_tag, " ", $f->location->to_FTstring(), "\n";
152 my %G = map { ($_,1) } @feat;
154 foreach my $A ( @fts ) {
156 print "missing ", $A->primary_tag, " ", $A->location->to_FTstring(), "\n";
161 print "Number of features correctly retrieved $c\n";
162 foreach my $f ( sort { $a->start <=> $b->start} @feat ) {
163 print $f->primary_tag, " ", $f->location->to_FTstring(), "\n";
170 for( $i = @$array; $i--; ) {
171 my $j = int rand($i+1);
173 @$array[$i,$j] = @$array[$j,$i];