more deprecated code removal; squash test failing due to different error being returned
[bioperl-live.git] / scripts / Bio-DB-SeqFeature-Store / bp_seqfeature_gff3.PLS
blobcc69e3590e192c310af002eb3195da1a1bf01e29
1 #!/usr/bin/env perl
2 # AUTHOR: malcolm.cook@stowers-institute.org
4 use strict;
6 use Carp;
7 use Getopt::Long;
8 use File::Spec;
9 use Bio::DB::SeqFeature::Store;
11 #use Carp::Always;
13 my $DSN;
14 my $ADAPTOR;
15 my $VERBOSE = 1;
16 my $USER = '';
17 my $PASS = '';
18 my @gff3opt;
20 GetOptions(
21 'dsn=s' => \$DSN,
22 'adaptor=s' => \$ADAPTOR,
23 'user=s' => \$USER,
24 'password=s' => \$PASS,
25 'gff3opt=i{,}' => \@gff3opt,
26 ) || die <<END;
27 Usage: $0 [options] -- [WHICH FEATURES]
28 output GFF3 for selected database features
29 Options:
30 -d --dsn The database name ($DSN)
31 -a --adaptor The storage adaptor to use ($ADAPTOR)
32 -u --user User to connect to database as
33 -p --password Password to use to connect to database
34 -g --gff3opt flag options to gff3_string (i.e.: pass -gffopt 1 to recurse)
36 WHICH FEATURES: any remaining options after '--' will select
37 a subset of features. The arguments are identical to those
38 accepted by Bio::DB::SeqFeature::Store->features().
40 END
42 $ADAPTOR ||= 'DBI::mysql';
43 $DSN ||= $ADAPTOR eq 'DBI::mysql' ? "mysql_read_default_file=$ENV{HOME}/.my.cnf" : '';
45 my $store = Bio::DB::SeqFeature::Store->new(
46 -dsn => $DSN,
47 -adaptor => $ADAPTOR,
48 -user => $USER,
49 -pass => $PASS,
51 or die "Couldn't create connection to the database";
53 # on signals, give objects a chance to call their DESTROY methods
54 $SIG{TERM} = $SIG{INT} = sub { undef $store; die "Aborted..."; };
56 my $seq_stream = $store->get_seq_stream(@ARGV) or die "failed to get_seq_stream(@ARGV)";
57 while (my $seq = $seq_stream->next_seq) {
58 ### 20100725 // genehack
59 # Try to call a gff3_string() method, but fall back to gff_string() if $seq
60 # doesn't support that. Note that gff_string() is required per
61 # Bio::SeqFeatureI, while gff3_string() is not. Currently, only
62 # Bio::SeqFeature::Lite implements gff3_string().
63 if ( $seq->can( 'gff3_string' )) {
64 print $seq->gff3_string(@gff3opt) . "\n";
66 elsif ( $seq->can( 'gff_string' )) {
67 # since we intend on getting a GFF3 string, make sure to pass the version
68 $seq->gff_format->gff_version(3);
69 print $seq->gff_string() . "\n";
71 else {
72 confess "sequence object $seq does not support gff3_string() or gff_string() methods!"
76 exit 0;