2 # AUTHOR: malcolm.cook@stowers-institute.org
10 use Bio
::DB
::SeqFeature
::Store
;
23 'adaptor=s' => \
$ADAPTOR,
25 'password=s' => \
$PASS,
26 'gff3opt=i{,}' => \
@gff3opt,
28 Usage: $0 [options] -- [WHICH FEATURES]
29 output GFF3 for selected database features
31 -d --dsn The database name ($DSN)
32 -a --adaptor The storage adaptor to use ($ADAPTOR)
33 -u --user User to connect to database as
34 -p --password Password to use to connect to database
35 -g --gff3opt flag options to gff3_string (i.e.: pass -gffopt 1 to recurse)
37 WHICH FEATURES: any remaining options after '--' will select
38 a subset of features. The arguments are identical to those
39 accepted by Bio::DB::SeqFeature::Store->features().
43 $ADAPTOR ||= 'DBI::mysql';
44 $DSN ||= $ADAPTOR eq 'DBI::mysql' ?
"mysql_read_default_file=$ENV{HOME}/.my.cnf" : '';
46 my $store = Bio
::DB
::SeqFeature
::Store
->new(
52 or die "Couldn't create connection to the database";
54 # on signals, give objects a chance to call their DESTROY methods
55 $SIG{TERM
} = $SIG{INT
} = sub { undef $store; die "Aborted..."; };
57 my $seq_stream = $store->get_seq_stream(@ARGV) or die "failed to get_seq_stream(@ARGV)";
58 while (my $seq = $seq_stream->next_seq) {
59 ### 20100725 // genehack
60 # Try to call a gff3_string() method, but fall back to gff_string() if $seq
61 # doesn't support that. Note that gff_string() is required per
62 # Bio::SeqFeatureI, while gff3_string() is not. Currently, only
63 # Bio::SeqFeature::Lite implements gff3_string().
64 if ( $seq->can( 'gff3_string' )) {
65 print $seq->gff3_string(@gff3opt) . "\n";
67 elsif ( $seq->can( 'gff_string' )) {
68 # since we intend on getting a GFF3 string, make sure to pass the version
69 $seq->gff_format->gff_version(3);
70 print $seq->gff_string() . "\n";
73 confess
"sequence object $seq does not support gff3_string() or gff_string() methods!"