[Bioperl-guts-l] [14481] bioperl-live/trunk: bug 2442

Christopher John Fields cjfields at dev.open-bio.org
Mon Feb 4 21:16:21 EST 2008


Revision: 14481
Author:   cjfields
Date:     2008-02-04 21:16:21 -0500 (Mon, 04 Feb 2008)

Log Message:
-----------
bug 2442

Modified Paths:
--------------
    bioperl-live/trunk/Bio/SeqFeature/Annotated.pm
    bioperl-live/trunk/Bio/SeqFeature/AnnotationAdaptor.pm
    bioperl-live/trunk/t/SeqFeatAnnotated.t

Modified: bioperl-live/trunk/Bio/SeqFeature/Annotated.pm
===================================================================
--- bioperl-live/trunk/Bio/SeqFeature/Annotated.pm	2008-02-04 23:41:47 UTC (rev 14480)
+++ bioperl-live/trunk/Bio/SeqFeature/Annotated.pm	2008-02-05 02:16:21 UTC (rev 14481)
@@ -271,32 +271,34 @@
 =cut
 
 sub from_feature {
-  my ($self,$feat,%opts) = @_;
+    my ($self,$feat,%opts) = @_;
+  
+    # should deal with any SeqFeatureI implementation (i.e. we don't want to
+    # automatically force a OO-heavy implementation on all classes)
+    ref($feat) && ($feat->isa('Bio::SeqFeatureI')) 
+      or $self->throw('invalid arguments to from_feature');
+  
+    #TODO: add overrides in opts for these values, so people don't have to screw up their feature object
+    #if they don't want to
+  
+    ### set most of the data
+    foreach my $fieldname (qw/ start end strand frame score location seq_id source_tag primary_tag/) {
+      #no strict 'refs'; #using symbolic refs, yes, but using them for methods is allowed now
+      $self->$fieldname( $feat->$fieldname );
+    }
 
-  # should deal with any SeqFeatureI implementation (i.e. we don't want to
-  # automatically force a OO-heavy implementation on all classes)
-  ref($feat) && ($feat->isa('Bio::SeqFeatureI')) 
-    or $self->throw('invalid arguments to from_feature');
+    # now pick up the annotations/tags of the other feature
+    # We'll use AnnotationAdaptor to convert everything over
 
-  #TODO: add overrides in opts for these values, so people don't have to screw up their feature object
-  #if they don't want to
-
-  ### set most of the data
-  foreach my $fieldname (qw/ start end strand frame score location seq_id source_tag primary_tag/) {
-    #no strict 'refs'; #using symbolic refs, yes, but using them for methods is allowed now
-    $self->$fieldname( $feat->$fieldname );
-  }
-
-  # now pick up the annotations/tags of the other feature
-  # We'll use AnnotationAdaptor to convert everything over
-  my $anncoll = Bio::SeqFeature::AnnotationAdaptor->new(-feature => $feat);
-  
-    for my $key ( $anncoll->get_all_annotation_keys() ) {
-      my @values = $anncoll->get_Annotations($key);
-      @values = _aggregate_scalar_annotations(\%opts,$key, at values);
-      foreach my $val (@values) {
-        $self->add_Annotation($key,$val)
-      }
+    my %no_copy = map {$_ => 1} qw/seq_id source type frame phase score/;
+    my $adaptor = Bio::SeqFeature::AnnotationAdaptor->new(-feature => $feat);
+    for my $key ( $adaptor->get_all_annotation_keys() ) {
+        next if $no_copy{$key};
+        my @values = $adaptor->get_Annotations($key);
+        @values = _aggregate_scalar_annotations(\%opts,$key, at values);
+        foreach my $val (@values) {
+            $self->add_Annotation($key,$val)
+        }
     }
 }
 #given a key and its values, make the values into

Modified: bioperl-live/trunk/Bio/SeqFeature/AnnotationAdaptor.pm
===================================================================
--- bioperl-live/trunk/Bio/SeqFeature/AnnotationAdaptor.pm	2008-02-04 23:41:47 UTC (rev 14480)
+++ bioperl-live/trunk/Bio/SeqFeature/AnnotationAdaptor.pm	2008-02-05 02:16:21 UTC (rev 14481)
@@ -244,7 +244,11 @@
     my @keys = ();
     
     # get the tags from the feature object
-    push(@keys, $self->feature()->all_tags());
+    if ($self->feature()->can('get_all_tags')) {
+        push(@keys, $self->feature()->get_all_tags());
+    } else {
+        push(@keys, $self->feature()->all_tags());
+    }
     # ask the annotation implementation in addition, while avoiding duplicates
     if($self->annotation()) {
 	push(@keys,

Modified: bioperl-live/trunk/t/SeqFeatAnnotated.t
===================================================================
--- bioperl-live/trunk/t/SeqFeatAnnotated.t	2008-02-04 23:41:47 UTC (rev 14480)
+++ bioperl-live/trunk/t/SeqFeatAnnotated.t	2008-02-05 02:16:21 UTC (rev 14481)
@@ -1,5 +1,5 @@
 # -*-Perl-*- Test Harness script for Bioperl
-# $Id: SeqFeatAnnotated.t,v 1.50 2007/06/27 10:16:37 sendu Exp $
+# $Id$
 
 use strict;
 
@@ -7,7 +7,7 @@
     use lib 't/lib';
     use BioperlTest;
     
-    test_begin(-tests => 26, -requires_module => 'URI::Escape');
+    test_begin(-tests => 34, -requires_module => 'URI::Escape');
 	
 	use_ok('Bio::SeqFeature::Generic');
 	use_ok('Bio::SeqFeature::Annotated');
@@ -17,8 +17,10 @@
 					  -end => 5,
 					  -strand => "+",
 					  -frame => 2,
+					  -type => 'nucleotide_motif',					  
 					  -phase => 2,
 					  -score => 12,
+					  -source => 'program_b',
 					  -display_name => 'test.annot',
 					  -seq_id => 'test.displayname' );
 
@@ -50,6 +52,15 @@
 is $sfa2->end,440;
 is $sfa2->get_Annotations('silly')->value,20;
 is $sfa2->get_Annotations('new')->value,1;
+my $sfaa = Bio::SeqFeature::Annotated->new(-feature => $sfa);
+is $sfaa->type->name,'nucleotide_motif';
+is $sfaa->primary_tag, 'nucleotide_motif';
+is $sfaa->source->display_text,'program_b';
+is $sfaa->source_tag,'program_b';
+is $sfaa->strand,1;
+is $sfaa->start,1;
+is $sfaa->end,5;
+is $sfaa->score,12;
 
 my $sfa3 = Bio::SeqFeature::Annotated->new( -start => 1,
 					-end => 5,




More information about the Bioperl-guts-l mailing list