Bio-DB-GFF
view release on metacpan or search on metacpan
lib/Bio/DB/GFF.pm view on Meta::CPAN
This method can be used to fetch a set of features from the database.
Attributes are a list of name=E<gt>value pairs. They will be logically
ANDED together.
=cut
sub get_feature_by_attribute {
my $self = shift;
my %attributes = ref($_[0]) ? %{$_[0]} : @_;
# we need to refactor this... It's repeated code (see above)...
my @aggregators;
if ($self->automerge) {
for my $a ($self->aggregators) {
unshift @aggregators,$a if $a->disaggregate([],$self);
}
}
my %groups; # cache the groups we create to avoid consuming too much unecessary memory
my $features = [];
my $callback = sub { push @$features,$self->make_feature(undef,\%groups,@_) };
$self->_feature_by_attribute(\%attributes,$callback);
warn "aggregating...\n" if $self->debug;
foreach my $a (@aggregators) { # last aggregator gets first shot
$a->aggregate($features,$self) or next;
}
@$features;
}
# more indecision...
*fetch_feature_by_attribute = \&get_feature_by_attribute;
=head2 get_feature_by_id
Title : get_feature_by_id
Usage : $db->get_feature_by_id($id)
Function: fetch segments by feature ID
Returns : a Bio::DB::GFF::Feature object
Args : the feature ID
Status : public
This method can be used to fetch a feature from the database using its
ID. Not all GFF databases support IDs, so be careful with this.
=cut
sub get_feature_by_id {
my $self = shift;
my $id = ref($_[0]) eq 'ARRAY' ? $_[0] : \@_;
my %groups; # cache the groups we create to avoid consuming too much unecessary memory
my $features = [];
my $callback = sub { push @$features,$self->make_feature(undef,\%groups,@_) };
$self->_feature_by_id($id,'feature',$callback);
return wantarray ? @$features : $features->[0];
}
*fetch_feature_by_id = \&get_feature_by_id;
=head2 get_feature_by_gid
Title : get_feature_by_gid
Usage : $db->get_feature_by_gid($id)
Function: fetch segments by feature ID
Returns : a Bio::DB::GFF::Feature object
Args : the feature ID
Status : public
This method can be used to fetch a feature from the database using its
group ID. Not all GFF databases support IDs, so be careful with this.
The group ID is often more interesting than the feature ID, since
groups can be complex objects containing subobjects.
=cut
sub get_feature_by_gid {
my $self = shift;
my $id = ref($_[0]) eq 'ARRAY' ? $_[0] : \@_;
my %groups; # cache the groups we create to avoid consuming too much unecessary memory
my $features = [];
my $callback = sub { push @$features,$self->make_feature(undef,\%groups,@_) };
$self->_feature_by_id($id,'group',$callback);
return wantarray ? @$features : $features->[0];
}
*fetch_feature_by_gid = \&get_feature_by_gid;
=head2 delete_fattribute_to_features
Title : delete_fattribute_to_features
Usage : $db->delete_fattribute_to_features(@ids_or_features)
Function: delete one or more fattribute_to_features
Returns : count of fattribute_to_features deleted
Args : list of features or feature ids
Status : public
Pass this method a list of numeric feature ids or a set of features.
It will attempt to remove the fattribute_to_features rows of those features
from the database and return a count of the rows removed.
NOTE: This method is also called delete_fattribute_to_feature(). Also see
delete_groups() and delete_features().
=cut
*delete_fattribute_to_feature = \&delete_fattribute_to_features;
sub delete_fattribute_to_features {
my $self = shift;
my @features_or_ids = @_;
my @ids = map {UNIVERSAL::isa($_,'Bio::DB::GFF::Feature') ? $_->id : $_} @features_or_ids;
return unless @ids;
$self->_delete_fattribute_to_features(@ids);
}
=head2 delete_features
Title : delete_features
Usage : $db->delete_features(@ids_or_features)
Function: delete one or more features
Returns : count of features deleted
Args : list of features or feature ids
Status : public
Pass this method a list of numeric feature ids or a set of features.
It will attempt to remove the features from the database and return a
count of the features removed.
NOTE: This method is also called delete_feature(). Also see
delete_groups().
=cut
*delete_feature = \&delete_features;
sub delete_features {
my $self = shift;
my @features_or_ids = @_;
my @ids = map {UNIVERSAL::isa($_,'Bio::DB::GFF::Feature') ? $_->id : $_} @features_or_ids;
return unless @ids;
$self->_delete_features(@ids);
}
=head2 delete_groups
Title : delete_groups
lib/Bio/DB/GFF.pm view on Meta::CPAN
$self->throw('_delete_groups is not implemented in this adaptor');
}
sub _delete {
my $self = shift;
my $delete_options = shift;
$self->throw('_delete is not implemented in this adaptor');
}
sub _delete_fattribute_to_features {
my $self = shift;
my @feature_ids = @_;
$self->throw('_delete_fattribute_to_features is not implemented in this adaptor');
}
sub unescape {
my $v = shift;
$v =~ tr/+/ /;
$v =~ s/%([0-9a-fA-F]{2})/chr hex($1)/ge;
return $v;
}
sub print_gff3_warning {
my $self = shift;
print STDERR <<END
You are loading a Bio::DB::GFF database with GFF3 formatted data.
While this will likely work fine, the Bio::DB::GFF schema does not
always faithfully capture the complexity represented in GFF3 files.
Unless you have a specific reason for using Bio::DB::GFF, we suggest
that you use a Bio::DB::SeqFeature::Store database and its corresponding
loader, bp_seqfeature_load.pl.
END
;
return;
}
package Bio::DB::GFF::ID_Iterator;
$Bio::DB::GFF::ID_Iterator::VERSION = '1.7.4';
use strict;
use base qw(Bio::Root::Root);
sub new {
my $class = shift;
my ($db,$ids,$type) = @_;
return bless {ids=>$ids,db=>$db,type=>$type},$class;
}
sub next_seq {
my $self = shift;
my $next = shift @{$self->{ids}};
return unless $next;
my $name = ref($next) eq 'ARRAY' ? Bio::DB::GFF::Featname->new(@$next) : $next;
my $segment = $self->{type} eq 'name' ? $self->{db}->segment($name)
: $self->{type} eq 'feature' ? $self->{db}->fetch_feature_by_id($name)
: $self->{type} eq 'group' ? $self->{db}->fetch_feature_by_gid($name)
: $self->throw("Bio::DB::GFF::ID_Iterator called to fetch an unknown type of identifier");
$self->throw("id does not exist") unless $segment;
return $segment;
}
package Bio::DB::GFF::FeatureIterator;
$Bio::DB::GFF::FeatureIterator::VERSION = '1.7.4';
sub new {
my $self = shift;
my @features = @_;
return bless \@features,ref $self || $self;
}
sub next_seq {
my $self = shift;
return unless @$self;
return shift @$self;
}
1;
__END__
=head1 BUGS
Features can only belong to a single group at a time. This must be
addressed soon.
Start coordinate can be greater than stop coordinate for relative
addressing. This breaks strict BioPerl compatibility and must be
fixed.
=head1 SEE ALSO
L<Bio::DB::GFF::RelSegment>,
L<Bio::DB::GFF::Aggregator>,
L<Bio::DB::GFF::Feature>,
L<Bio::DB::GFF::Adaptor::dbi::mysqlopt>,
L<Bio::DB::GFF::Adaptor::dbi::oracle>,
L<Bio::DB::GFF::Adaptor::memory>
L<Bio::DB::GFF::Adaptor::berkeleydb>
=head1 AUTHOR
Lincoln Stein E<lt>lstein@cshl.orgE<gt>.
Copyright (c) 2001 Cold Spring Harbor Laboratory.
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
( run in 3.619 seconds using v1.01-cache-2.11-cpan-5735350b133 )