Skip to content

Commit

Permalink
Merge branch 'master' into branch-1-6
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Fields committed Jul 29, 2010
2 parents 0c61488 + f63c4db commit 40eb18f
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 9 deletions.
29 changes: 24 additions & 5 deletions Bio/DB/SeqFeature/Store/DBI/Pg.pm
Expand Up @@ -327,9 +327,9 @@ END
typeid int not null,
seqid int not null,
bin int not null,
cum_count int not null,
CREATE UNIQUE INDEX interval_stats_id ON interval_stats(typeid,seqid,bin)
)
cum_count int not null
);
CREATE UNIQUE INDEX interval_stats_id ON interval_stats(typeid,seqid,bin);
END
};
}
Expand Down Expand Up @@ -934,9 +934,28 @@ sub _add_interval_stats_table {
my $self = shift;
my $tables = $self->table_definitions;
my $interval_stats = $self->_interval_stats_table;
eval {
$self->dbh->do("CREATE TABLE $interval_stats $tables->{interval_stats}");
##check to see if it exists yet; if it does, just return because
##there is a drop from in the next step
my $dbh = $self->dbh;
my @table_exists = $dbh->selectrow_array("SELECT * FROM pg_tables WHERE tablename
= '$interval_stats' AND schemaname = '".$self->namespace."'");
if (!scalar(@table_exists)) {
my $query = "CREATE TABLE $interval_stats $tables->{interval_stats}";
$dbh->do($query) or $self->throw($dbh->errstr);
}
}

sub _fetch_indexed_features_sql {
my $self = shift;
my $features = $self->_feature_table;
return <<END;
SELECT typeid,seqid,start-1,"end"
FROM $features as f
WHERE f.indexed=1
ORDER BY typeid,seqid,start
END
}



1;
28 changes: 26 additions & 2 deletions Bio/DB/SeqFeature/Store/DBI/mysql.pm
Expand Up @@ -1756,7 +1756,31 @@ sub _rebuild_obj {

$attribs{$attribute} = $attribute_value;
}


# if we weren't called with all the params, pull those out of the database too
if ( not ( grep { defined($_) } ( $typeid, $db_seqid, $start, $end, $strand ))) {
my $sql = qq{ SELECT start,end,tag,strand,seqname
FROM feature,feature_location,typelist,locationlist
WHERE feature.id=feature_location.id AND feature.typeid=typelist.id
AND seqid=locationlist.id AND feature.id = ? };
my $sth = $self->_prepare($sql) or $self->throw($self->dbh->errstr);
$sth->execute($id);
my ($feature_start, $feature_end, $feature_type, $feature_strand,$feature_seqname);
$sth->bind_columns(\($feature_start, $feature_end, $feature_type, $feature_strand, $feature_seqname));
while ($sth->fetch()) {
# there should be only one row returned, but we call like this to
# ensure we get all rows
}
$start ||= $feature_start;
$end ||= $feature_end;
$strand ||= $feature_strand;
$seqid ||= $feature_seqname;

my( $feature_typename , $feature_typesource ) = split /:/ , $feature_type;
$type ||= $feature_typename;
$source ||= $feature_typesource;
}

my $obj = Bio::SeqFeature::Lite->new(-primary_id => $id,
$type ? (-type => $type) : (),
$source ? (-source => $source) : (),
Expand All @@ -1765,7 +1789,7 @@ sub _rebuild_obj {
defined $end ? (-end => $end) : (),
defined $strand ? (-strand => $strand) : (),
keys %attribs ? (-attributes => \%attribs) : ());

return $obj;
}

Expand Down
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;
44 changes: 43 additions & 1 deletion t/SeqFeature/SeqFeature.t
Expand Up @@ -7,7 +7,7 @@ BEGIN {
use lib '.';
use Bio::Root::Test;

test_begin(-tests => 222);
test_begin(-tests => 245);

use_ok('Bio::Seq');
use_ok('Bio::SeqIO');
Expand Down Expand Up @@ -377,3 +377,45 @@ lives_ok {
is_deeply( [$sf->get_tagset_values('notag') ], [], 'get_tagset_values no tag values found');
} 'get_tagset_values lives with no tag';
throws_ok { $sf->get_tag_values('notag') } qr/tag value that does not exist/, 'get_tag_values throws with no tag';

# circular sequence SeqFeature tests
$seqin = Bio::SeqIO->new(-format => 'genbank',
-file => test_input_file('PX1CG.gb'));

$seq = $seqin->next_seq;
ok($seq->is_circular, 'Phi-X174 genome is circular');

# retrieving the spliced sequence from any split location requires
# spliced_seq()

my %sf_data = (
# start
'A' => [3981, 136, 1, 1542, 'join(3981..5386,1..136)', 'ATGGTTCGTT'],
'A*' => [4497, 136, 1, 1026, 'join(4497..5386,1..136)', 'ATGAAATCGC'],
'B' => [5075, 136, 1, 363, 'join(5075..5386,1..51)', 'ATGGAACAAC'],
);

my @split_sfs = grep {
$_->location->isa('Bio::Location::SplitLocationI')
} $seq->get_SeqFeatures();

is(@split_sfs, 3, 'only 3 split locations');

for my $sf (@split_sfs) {
isa_ok($sf->location, 'Bio::Location::SplitLocationI');
my ($tag) = $sf->get_tag_values('product');
my ($start, $end, $strand, $length, $ftstring, $first_ten) = @{$sf_data{$tag}};

# these pass
is($sf->location->to_FTstring, $ftstring, 'feature string');
is($sf->spliced_seq->subseq(1,10), $first_ten, 'first ten nucleotides');
is($sf->strand, $strand, 'strand');

TODO: {
local $TODO = "Need to define how to deal with start, end length for circular sequences";
is($sf->start, $start, 'start');
is($sf->end, $end, 'end');
is($sf->length, $length, 'expected length');
}
}

0 comments on commit 40eb18f

Please sign in to comment.