Skip to content

Commit

Permalink
Bio::Seq compliance with Bio::FeatureHolderI
Browse files Browse the repository at this point in the history
  • Loading branch information
fangly committed Mar 7, 2012
1 parent d0584ca commit a5bebe0
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 25 deletions.
8 changes: 4 additions & 4 deletions Bio/FeatureHolderI.pm
Expand Up @@ -116,14 +116,14 @@ sub get_SeqFeatures {
Usage : $feat->add_SeqFeature($subfeat);
$feat->add_SeqFeature($subfeat,'EXPAND')
Function: adds a SeqFeature into the subSeqFeature array.
Function: Add a SeqFeature into the subSeqFeature array.
with no 'EXPAND' qualifer, subfeat will be tested
as to whether it lies inside the parent, and throw
an exception if not.
If EXPAND is used, the parent''s start/end/strand will
be adjusted so that it grows to accommodate the new
subFeature
If EXPAND is used and the object implements Bio::RangeI
(which is not guaranteed), the parent''s start/end/strand
will be extended so that the new subFeature can be accomodated.
Example :
Returns : nothing
Args : a Bio::SeqFeatureI object
Expand Down
25 changes: 20 additions & 5 deletions Bio/Seq.pm
Expand Up @@ -1123,19 +1123,34 @@ sub feature_count {
Function: Adds the given feature object to the feature array of this
sequence. The object passed is required to implement the
Bio::SeqFeatureI interface.
The 'EXPAND' qualifier (see L<Bio::FeatureHolderI>) is supported, but
has no effect,
Returns : 1 on success
Args : A Bio::SeqFeatureI implementing object, or an array of such objects.
Args : A Bio::SeqFeatureI implementing object.
=cut

sub add_SeqFeature {
my ($self,@feat) = @_;
my ($self, @feat) = @_;

$self->{'_as_feat'} = [] unless $self->{'_as_feat'};

foreach my $feat ( @feat ) {
if (scalar @feat > 1) {
$self->deprecated(
-message => 'Providing an array of features to Bio::Seq add_SeqFeature()'.
' is deprecated and will be removed in a future version. '.
'Add a single feature at a time instead.',
-warn_version => 1.007,
-throw_version => 1.009,
);
}

for my $feat ( @feat ) {

next if $feat eq 'EXPAND'; # Need to support it for FeatureHolderI compliance

if( !$feat->isa("Bio::SeqFeatureI") ) {
$self->throw("$feat is not a SeqFeatureI and that's what we expect...");
$self->throw("Expected a Bio::SeqFeatureI object, but got a $feat.");
}

# make sure we attach ourselves to the feature if the feature wants it
Expand Down Expand Up @@ -1179,7 +1194,7 @@ and work as one expects, building new Bio::Seq objects
or other information as expected. See L<Bio::PrimarySeq>
for more information.
Sequence Features are B<not> transfered to the new objects.
Sequence Features are B<not> transferred to the new objects.
This is possibly a mistake. Anyone who feels the urge in
dealing with this is welcome to give it a go.
Expand Down
2 changes: 1 addition & 1 deletion Bio/SeqFeature/Tools/Unflattener.pm
Expand Up @@ -1518,7 +1518,7 @@ sub unflatten_seq{
# modify the original Seq object - the top seqfeatures are now
# the top features from each group
$seq->remove_SeqFeatures;
$seq->add_SeqFeature(@top_sfs);
$seq->add_SeqFeature($_) foreach @top_sfs;

# --------- FINISHED UNFLATTENING -------------

Expand Down
4 changes: 2 additions & 2 deletions Bio/SeqIO/game/gameWriter.pm
Expand Up @@ -177,7 +177,7 @@ sub write_to_game {
# $self->_rearrange_hierarchies($seq, @gene_containers);

# add back nested feats
$seq->add_SeqFeature( @nested_feats );
$seq->add_SeqFeature( $_ ) foreach @nested_feats;

my $atts = {};
my $xml = '';
Expand Down Expand Up @@ -295,7 +295,7 @@ sub _rearrange_hierarchies { #renamed to not conflict with Bio::Root::_rearrange
}

push @addback, (@containers, grep { defined $_ } @genes );
$seq->add_SeqFeature(@addback);
$seq->add_SeqFeature($_) foreach @addback;
}


Expand Down
3 changes: 2 additions & 1 deletion Bio/SeqIO/interpro.pm
Expand Up @@ -166,6 +166,8 @@ sub next_seq {
-seq_id => $protein_node->getAttribute('id') ),
} @locNodes;
foreach my $seqFeature (@seqFeatures){
$bioSeq->add_SeqFeature($seqFeature);

my $annotation1 = Bio::Annotation::DBLink->new;
$annotation1->database($matchNodes[$match]->getAttribute('dbname'));
$annotation1->primary_id($matchNodes[$match]->getAttribute('id'));
Expand Down Expand Up @@ -195,7 +197,6 @@ sub next_seq {
$seqFeature->annotation->add_Annotation('dblink', $go_annotation);
}
}
$bioSeq->add_SeqFeature(@seqFeatures);
}
}
my $accession = $protein_node->getAttribute('id');
Expand Down
14 changes: 10 additions & 4 deletions Bio/SeqUtils.pm
Expand Up @@ -535,15 +535,19 @@ sub trunc_with_features{
unless $seq->isa('Bio::SeqI');
my $trunc=$seq->trunc($start, $end);
my $truncrange=Bio::Range->new(-start=>$start, -end=>$end, -strand=>0);
#move annotations
# move annotations
foreach my $key ( $seq->annotation->get_all_annotation_keys() ) {
foreach my $value ( $seq->annotation->get_Annotations($key) ) {
$trunc->annotation->add_Annotation($key, $value);
}
}

#move features
$trunc->add_SeqFeature(grep {$_=$self->_coord_adjust($_, 1-$start, $end+1-$start) if $_->overlaps($truncrange)} $seq->get_SeqFeatures);
# move features
foreach ( grep
{ $_=$self->_coord_adjust($_, 1-$start, $end+1-$start) if $_->overlaps($truncrange) }
$seq->get_SeqFeatures ) {
$trunc->add_SeqFeature($_);
}
return $trunc;
}

Expand Down Expand Up @@ -1316,7 +1320,9 @@ sub revcom_with_features{
}

#move features
$revcom->add_SeqFeature(map {$self->_feature_revcom($_, $seq->length)} reverse $seq->get_SeqFeatures);
for (map {$self->_feature_revcom($_, $seq->length)} reverse $seq->get_SeqFeatures) {
$revcom->add_SeqFeature($_);
}
return $revcom;
}

Expand Down
4 changes: 2 additions & 2 deletions scripts/Bio-DB-GFF/bp_genbank2gff3.pl
Expand Up @@ -1059,8 +1059,8 @@ sub filter {
my $m = $f->primary_tag;
push @sources, $f if ($m eq 'source'); # dgg? but leave in @feats ?
push @feats, $f unless $filter =~ /$m/i;
}
$seq->add_SeqFeature(@feats) if @feats;
}
$seq->add_SeqFeature($_) foreach @feats;
} else {
for my $f ( $seq->get_SeqFeatures ){
my $m = $f->primary_tag;
Expand Down
11 changes: 8 additions & 3 deletions t/SeqTools/SeqUtils.t
Expand Up @@ -362,7 +362,10 @@ my $feature5 = Bio::SeqFeature::Generic->new(
-start => 11,
-end => 20
);
$seq_obj->add_SeqFeature( $composite_feat1, $feature1, $feature2, $feature3, $feature4, $feature5);

for ($composite_feat1, $feature1, $feature2, $feature3, $feature4, $feature5) {
$seq_obj->add_SeqFeature( $_ );
}

my $coll = Bio::Annotation::Collection->new;
$coll->add_Annotation(
Expand Down Expand Up @@ -560,8 +563,10 @@ my $foo_seq_obj = Bio::Seq::Foo->new(
-seq =>'aaaaaaaaaaccccccccccggggggggggtttttttttt',
-display_id => 'seq1',
-desc => 'some sequence for testing'
);
$foo_seq_obj->add_SeqFeature( $composite_feat1, $feature1, $feature2, $feature3, $feature4, $feature5);
);
for ($composite_feat1, $feature1, $feature2, $feature3, $feature4, $feature5) {
$foo_seq_obj->add_SeqFeature( $_ );
}
$foo_seq_obj->annotation($coll);

dies_ok(
Expand Down
4 changes: 3 additions & 1 deletion t/Tools/Analysis/Protein/Domcut.t
Expand Up @@ -75,6 +75,8 @@ SKIP: {

ok my $seq4 = Bio::Seq->new();
ok $seq2->primary_seq($meta2);
ok $seq2->add_SeqFeature(@res);
for (@res) {
ok $seq2->add_SeqFeature($_);
}
ok $seq2->primary_seq->named_submeta_text('Domcut', 1,2);
}
6 changes: 4 additions & 2 deletions t/Tools/Analysis/Protein/HNN.t
Expand Up @@ -7,7 +7,7 @@ BEGIN {
use lib '.';
use Bio::Root::Test;

test_begin(-tests => 13,
test_begin(-tests => 14,
-requires_modules => [qw(IO::String LWP::UserAgent)],
-requires_networking => 1);

Expand Down Expand Up @@ -35,7 +35,9 @@ SKIP: {

ok my $meta = $tool->result('meta');
ok my $seqobj = Bio::Seq->new(-primary_seq => $meta, display_id=>"a");
ok $seqobj->add_SeqFeature($tool->result('Bio::SeqFeatureI'));
for ( $tool->result('Bio::SeqFeatureI') ) {
ok $seqobj->add_SeqFeature($_);
}

test_skip(-tests => 2, -requires_module => 'Bio::Seq::Meta::Array');
is $meta->named_submeta_text('HNN_helix',1,2), '0 111';
Expand Down

0 comments on commit a5bebe0

Please sign in to comment.