| 1 |
#!/usr/bin/perl |
| 2 |
# AUTHOR: [email protected] |
| 3 |
|
| 4 |
use strict; |
| 5 |
use warnings; |
| 6 |
|
| 7 |
use Carp; |
| 8 |
use Getopt::Long; |
| 9 |
use File::Spec; |
| 10 |
use Bio::DB::SeqFeature::Store; |
| 11 |
|
| 12 |
#use Carp::Always; |
| 13 |
|
| 14 |
my $DSN; |
| 15 |
my $ADAPTOR; |
| 16 |
my $VERBOSE = 1; |
| 17 |
my $USER = ''; |
| 18 |
my $PASS = ''; |
| 19 |
my @gff3opt; |
| 20 |
|
| 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) |
| 36 |
|
| 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(). |
| 40 |
|
| 41 |
END |
| 42 |
|
| 43 |
$ADAPTOR ||= 'DBI::mysql'; |
| 44 |
$DSN ||= $ADAPTOR eq 'DBI::mysql' ? "mysql_read_default_file=$ENV{HOME}/.my.cnf" : ''; |
| 45 |
|
| 46 |
my $store = Bio::DB::SeqFeature::Store->new( |
| 47 |
-dsn => $DSN, |
| 48 |
-adaptor => $ADAPTOR, |
| 49 |
-user => $USER, |
| 50 |
-pass => $PASS, |
| 51 |
) |
| 52 |
or die "Couldn't create connection to the database"; |
| 53 |
|
| 54 |
# on signals, give objects a chance to call their DESTROY methods |
| 55 |
$SIG{TERM} = $SIG{INT} = sub { undef $store; die "Aborted..."; }; |
| 56 |
|
| 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"; |
| 66 |
} |
| 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"; |
| 71 |
} |
| 72 |
else { |
| 73 |
confess "sequence object $seq does not support gff3_string() or gff_string() methods!" |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
exit 0; |