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

Steffen Grossmann grossman at molgen.mpg.de
Mon Nov 1 12:49:17 EST 2004


Dear Scott,

to make it work you have to write something like

my $ta = Bio::Annotation::SimpleValue->new(-value => $target_loc);
$ac->add_Annotation('Target',$ta);

Do this for every target entry you want to add. You can then retrieve 
the targets from the collection by calling

my @targets = $ac->get_Annotations('Target');

or (from the point of view of the Bio::SeqFeature::Annotated object)

my @targets = $feature->annotation->get_Annotations('Target');

If you are writing your own 'target'-method (which should be a part of 
Bio::SeqFeature::Annotated) in the way you do it, you are outside the 
Bio::Annotation concept. But one can also think about writing a 
'target'-method, which writes/reads into the feature's 
Bio::Annotation::Collection object.

Hope this helps! Actually, I thought it to be more natural to use 
something like Bio::SeqFeature::FeaturePair to deal with the target 
entries in the GFF3 file. But obviously this is not compatible with 
Bio::SeqFeature::Annotated (cf. 
http://bioperl.org/pipermail/bioperl-l/2004-October/017195.html)...

Steffen


Scott Cain wrote:

>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
>
>
>  
>

-- 
%---------------------------------------------%
%            Steffen Grossmann                %
%                                             %
% Max Planck Institute for Molecular Genetics %
%      Computational Molecular Biology        %
%---------------------------------------------%
%              Ihnestrasse 73                 %
%               14195 Berlin                  %
%                 Germany                     %
%---------------------------------------------%
%         Tel: (++49 +30) 8413-1167           %
%         Fax: (++49 +30) 8413-1152           %
%---------------------------------------------%




More information about the Bioperl-l mailing list