Permalink
Browse files

Bio::Seq compliance with Bio::FeatureHolderI

  • Loading branch information...
1 parent d0584ca commit a5bebe00c505fbf5279f5d717790ed36eefcc2b8 @fangly fangly committed Mar 7, 2012
View
@@ -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
View
@@ -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
@@ -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.
@@ -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 -------------
@@ -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 = '';
@@ -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;
}
View
@@ -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'));
@@ -195,7 +197,6 @@ sub next_seq {
$seqFeature->annotation->add_Annotation('dblink', $go_annotation);
}
}
- $bioSeq->add_SeqFeature(@seqFeatures);
}
}
my $accession = $protein_node->getAttribute('id');
View
@@ -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;
}
@@ -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;
}
@@ -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;
View
@@ -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(
@@ -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(
@@ -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);
}
@@ -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);
@@ -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';

0 comments on commit a5bebe0

Please sign in to comment.