Skip to content

Commit

Permalink
Introspect feature objects and call apporpriate GFF output method
Browse files Browse the repository at this point in the history
Depending on how the database was built, next_seq() may return
something that supports gff3_string() or someting that supports
gff_string(). Introspect on the feature object to figure out which of
these two methods are supported, and call the appropriate one:
gff3_string() if it exists, gff_string() otherwise.

If neither method exists on the feature object, thrown an exception
with a stack trace.
  • Loading branch information
genehack authored and Chris Fields committed Jul 29, 2010
1 parent 34a9857 commit a3ee8b9
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion scripts/Bio-SeqFeature-Store/bp_seqfeature_gff3.PLS
Expand Up @@ -4,6 +4,7 @@

use strict;

use Carp;
use Getopt::Long;
use File::Spec;
use Bio::DB::SeqFeature::Store;
Expand Down Expand Up @@ -55,7 +56,20 @@ $SIG{TERM} = $SIG{INT} = sub { undef $store; die "Aborted..."; };

my $seq_stream = $store->get_seq_stream(@ARGV) or die "failed to get_seq_stream(@ARGV)";
while (my $seq = $seq_stream->next_seq) {
print $seq->gff3_string(@gff3opt) . "\n";
### 20100725 // genehack
# Try to call a gff3_string() method, but fall back to gff_string() if $seq
# doesn't support that. Note that gff_string() is required per
# Bio::SeqFeatureI, while gff3_string() is not. Currently, only
# Bio::SeqFeature::Lite implements gff3_string().
if ( $seq->can( 'gff3_string' )) {
print $seq->gff3_string(@gff3opt) . "\n";
}
elsif ( $seq->can( 'gff_string' )) {
print $seq->gff_string . "\n";
}
else {
confess "sequence object $seq does not support gff3_string() or gff_string() methods!"
}
}

exit 0;

0 comments on commit a3ee8b9

Please sign in to comment.