[Bioperl-l] about Bio::Annotation::Collection
Jason Stajich
jason.stajich at duke.edu
Mon Nov 1 13:55:29 EST 2004
Locations do have a place to store the reference system -- the seq_id
method. This would hold the ref coordinate system you are looking for
I think. I think using a LocationI would be better than LocatableSeq
because you can also use Location::Split to represent the multiple
sub-locations and LocatableSeq necessarily is contiguous as it only has
start/end. Maybe LocatableSeq could be updated to be more Location
friendly and re-use those objects within?
-jason
On Nov 1, 2004, at 1:39 PM, Allen Day wrote:
> a couple of points:
>
> [1] Bio::Annotation::Collection won't accomodate anything that isn't an
> annotation. This means it won't accept Bio::Location::Simple or
> Bio::LocatableSeq objects. We need to write our own accessors into the
> SeqFeature (or inherit from something that stores multiple locations)
>
> [2] Bio::Location::Simple only stores a coordinate pair. It doesn't
> store the reference sequence identifier -- something that is important
> for
> a feature target.
>
> I'm about to commit code for handling target objects. It requires you
> instantiate a Bio::LocatableSeq outside the Bio::SeqFeature::Annotated,
> and pass it in. We can try to make the method smarter so it can
> understand strings like "chr1:+:1..100", but I've left it out for now.
>
> Here's the patch (which has been applied):
>
> --- ./Bio/SeqFeature/Annotated.pm 22 Oct 2004 14:55:15 -0000
> 1.5
> +++ ./Bio/SeqFeature/Annotated.pm 1 Nov 2004 19:04:22 -0000
> @@ -5,6 +5,7 @@ use base qw(Bio::Root::Root Bio::SeqFeat
>
> use Bio::Root::Root;
> use Bio::Annotation::Collection;
> +use Bio::LocatableSeq;
> use Bio::Location::Simple;
> use Bio::Tools::GFF;
>
> @@ -448,21 +449,20 @@ sub score {
> return $self->{'_gsf_score'};
> }
>
> -=head2 phase
> -
> +=head2 phase
> +
> Title : phase
> Usage : $phase = $feat->phase()
> $feat->phase($phase)
> Function: get/set on phase information
> Returns : 0,1,2, '.'
> Args : none if get, the new value if set
> -
> -
> +
> =cut
>
> sub phase {
> my $self = shift;
> -
> +
> if ( @_ ) {
> my $value = shift;
> if ( defined $value &&
> @@ -531,6 +531,40 @@ sub location {
> }
> return $self->{'_location'};
> }
> +
> +=head2 add_target()
> +
> + Usage : $seqfeature->add_target(Bio::LocatableSeq->new(...));
> + Function: adds a target location on another reference sequence for
> this feature
> + Returns : true on success
> + Args : a Bio::LocatableSeq object
> +
> +
> +=cut
> +
> +sub add_target {
> + my ($self,$seq) = @_;
> + $self->throw("$seq is not a Bio::LocatableSeq, bailing out") unless
> ref($seq) and seq->isa('Bio::LocatableSeq');
> + push @{ $self->{'targets'} }, $seq;
> + return $seq;
> +}
> +
> +=head2 each_target()
> +
> + Usage : @targets = $seqfeature->each_target();
> + Function: Returns a list of Bio::LocatableSeqs which are the
> locations of this object.
> + To obtain the "primary" location, see L</location()>.
> + Returns : a list of 0..N Bio::LocatableSeq objects
> + Args : none
> +
> +
> +=cut
> +
> +sub each_target {
> + my ($self) = @_;
> + return $self->{'targets'} ? @{ $self->{'targets'} } : ();
> +}
> +
>
> sub _no_tags {
> my $self = shift;
>
>
>
> -Allen
>
>
>
> On Mon, 1 Nov 2004, Steffen Grossmann wrote:
>
>> 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
>>>
>>>
>>>
>>>
>>
>>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at portal.open-bio.org
> http://portal.open-bio.org/mailman/listinfo/bioperl-l
>
>
--
Jason Stajich
jason.stajich at duke.edu
http://www.duke.edu/~jes12/
More information about the Bioperl-l
mailing list