[Bioperl-l] about Bio::Annotation::Collection

Scott Cain cain at cshl.org
Mon Nov 1 11:52:41 EST 2004


Hello all,

I am trying to flesh out Bio::FeatureIO::gff to handle Target strings in
GFF3 files.  What I would like to do is to create an array of
Bio::Location::Simple objects to represent the (potentially more than
one) Target strings, and then add them to the annotations for for the
line, presumably as a Bio::Annotation::Collection.  The thing is, I have
no idea how B::A::C works.  Here is the documentation for the method
'add_Annotation', which is what I would want to use.  Note the mention
of an archetype without defining it (though I think it refers to the
last line in the Usage section):

       add_Annotation
                                                                                            
        Title   : add_Annotation
        Usage   : $self->add_Annotation('reference',$object);
                  $self->add_Annotation($object,'Bio::MyInterface::DiseaseI');
                  $self->add_Annotation($object);
                  $self->add_Annotation('disease',$object,'Bio::MyInterface::DiseaseI');
        Function: Adds an annotation for a specific key.
                                                                                            
                  If the key is omitted, the object to be added must provide a value
                  via its tagname().
                                                                                            
                                                                                            
                                                                                            
                  If the archetype is provided, this and future objects added under
                  that tag have to comply with the archetype and will be rejected
                  otherwise.
                                                                                            
        Returns : none
        Args    : annotation key ('disease', 'dblink', ...)
                  object to store (must be Bio::AnnotationI compliant)
                  [optional] object archetype to map future storage of object
                             of these types to

Here is the section of code from Bio::FeatureIO::gff where I would like
to use the Target string; my approach certainly seems to conflict with
what Bio::Annotation would like, but it is not clear to me how to use it
in this context.

  if($attr{Target}){
    foreach my $target_string (@{ $attr{Target} } ) {
      $target_string =~ s/\+/ /g;
      my ($t_id,$tstart,$tend,$strand,$extra) = split /\s+/, $target_string;
      if (!$tend || $extra) { # too much or too little stuff in the string
        $self->throw("The value in the Target string, $target_string, does not conform to the GFF3 specification");
      }
      my $target_loc = Bio::Location::Simple->new(
          -seq_id => $t_id,
          -start  => $tstart,
          -end    => $tend,
      );
                                                                                
      if ($strand eq '+') {
        $strand = 1;
      } elsif ($strand eq '-') {
        $strand = -1;
      }
      $target_loc->strand($strand) if $strand;
      $target_loc->is_remote(1);
                                                                                
      $self->target($target_loc);
    }
    $ac->add_Annotation('Target',$self->target());
  }

... and ...

=head2 target
                                                                                
 Title   : target
 Usage   : $obj->target($newval)
 Function: Either return an array ref with Bio::LocationI objects
           representing the targets, or to add a target to the
           internal target list
 Example : my @targets = $obj->target();
           $obj->target($newtarget);
 Returns : A list of Bio::LocationI objects
 Args    : On set, a Bio::LocationI object
                                                                                
                                                                                
=cut
                                                                                
sub target {
    my $self = shift;
    push @{$self->{'target'}}, shift if defined(@_);
    return \@{$self->{'target'}};
}

Thanks,
Scott


-- 
------------------------------------------------------------------------
Scott Cain, Ph. D.                                         cain at cshl.org
GMOD Coordinator (http://www.gmod.org/)                     216-392-3087
Cold Spring Harbor Laboratory



More information about the Bioperl-l mailing list