Add tests for memory leaks and weaken for Issue #81
[bioperl-live.git] / scripts / Bio-DB-SeqFeature-Store / bp_seqfeature_gff3.pl
blob6b9643de66cf96e344e2991ee6c04cb791a280fc
1 #!/usr/bin/env perl
2 # AUTHOR: malcolm.cook@stowers-institute.org
4 use strict;
5 use warnings;
7 use Carp;
8 use Getopt::Long;
9 use File::Spec;
10 use Bio::DB::SeqFeature::Store;
12 #use Carp::Always;
14 my $DSN;
15 my $ADAPTOR;
16 my $VERBOSE = 1;
17 my $USER = '';
18 my $PASS = '';
19 my @gff3opt;
21 GetOptions(
22 'dsn=s' => \$DSN,
23 'adaptor=s' => \$ADAPTOR,
24 'user=s' => \$USER,
25 'password=s' => \$PASS,
26 'gff3opt=i{,}' => \@gff3opt,
27 ) || die <<END;
28 Usage: $0 [options] -- [WHICH FEATURES]
29 output GFF3 for selected database features
30 Options:
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().
41 END
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(
47 -dsn => $DSN,
48 -adaptor => $ADAPTOR,
49 -user => $USER,
50 -pass => $PASS,
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";
72 else {
73 confess "sequence object $seq does not support gff3_string() or gff_string() methods!"
77 exit 0;