[BioRuby] Bio::Sequence and Bio::Sequence::NA

Toshiaki Katayama ktym at hgc.jp
Tue May 17 20:53:18 UTC 2011


Hi Anthony,

In lib/bio/sequence.rb, you can find the definition of "method_missing".

  # Pass any unknown method calls to the wrapped sequence object.  see
  # http://www.rubycentral.com/book/ref_c_object.html#Object.method_missing
  def method_missing(sym, *args, &block) #:nodoc:
    begin
      seq.__send__(sym, *args, &block)

   :

  # The sequence object, usually Bio::Sequence::NA/AA, 
  # but could be a simple String
  attr_accessor :seq

This means any methods which are not understood by the Bio::Sequence object
are simply redirected to the internal sequence object.

Therefore, if the sequence object is a Bio::Sequence::NA instance, it will
respond to any methods implemented in the Bio::Sequence::NA class (and mix-ins).

Older versions were much simpler but the internal code gets complicated over time
to improve usability and functionality. Hopefully, it should be clearly documented.

Cheers,
Toshiaki

On 2011/05/18, at 5:06, Anthony Underwood wrote:

> Dear Toshiaki
> 
> Thank you for your reply.
> 
> I have just tested your code below and all worked OK. I have found unexpectedly that embl_bioseq.translate works even though embl_bioseq.methods does not list translate as an available method. 
> What extra methods does a Bio::Sequence::NA object instantiated using the auto method give?
> 
> Thanks again for your advice, Anthony
> 
> On 17 May 2011 02:33, Toshiaki Katayama <ktym at hgc.jp> wrote:
> Hi Anthony,
> 
> Bio::Sequence is a generic container class for a sequence with features which was
> introduced relatively recently for interconversion of Bio::GenBank, Bio::EMBL and
> Bio::SQL sequence objects (and it also provides common APIs for those seq objects).
> 
> Bio::Sequence#na or #auto method extract a sequence from a Bio::Sequence object, so
> you should use another variable to store (instead of overriding the object reference).
> 
> > biosequence = biosequence.auto
> 
> seq = biosequence.auto
> 
> so that you can still access to biosequence.features.
> 
> % bioruby
> bioruby> embl = Bio::EMBL.new(open("http://togows.dbcls.jp/entry/embl/J00231").read)
> bioruby> embl.class
>  ==> Bio::EMBL
> bioruby> embl_bioseq = embl.to_biosequence
> bioruby> embl_bioseq.class
>  ==> Bio::Sequence
> bioruby> embl_seq = embl_bioseq.auto
> bioruby> embl_seq.class
>  ==> Bio::Sequence::NA
> 
> Toshiaki
> 
> 
> On 2011/05/16, at 18:07, Anthony Underwood wrote:
> 
> > Here's something that has alway puzzled me about BioRuby
> >
> > If I start with a Bio::EMBL object and want to extract the features I can do the following
> >
> > biosequence = embl_object.to_biosequence
> >
> > This returns an instance of a Bio::Sequence class. I can now access the features
> >
> > features = biosequence.features
> >
> > However if the sequence is nucleotide and I want to translate it I have to do the following
> >
> > biosequence.na
> >
> > OR
> >
> > biosequence = biosequence.auto
> >
> >
> > This returns a Bio::Sequence::NA instance and I can now translate
> >
> > protein = biosequence.translate(1,11)
> >
> >
> > Why can I not now get at the features
> >
> > biosequence.features #=> undefined method `features' for #<Bio::Sequence::NA:0x00000100cae5f8>
> >
> >
> > I would have though that after converting to Bio::Sequence::NA or Bio::Sequence:AA the methods available to Bio::Sequence should still be available.
> >
> > Can anyone tell me what's going on here. Is there another method I should use?
> >
> >
> > Thanks
> >
> > Anthony
> > _______________________________________________
> > BioRuby Project - http://www.bioruby.org/
> > BioRuby mailing list
> > BioRuby at lists.open-bio.org
> > http://lists.open-bio.org/mailman/listinfo/bioruby
> 
> 





More information about the BioRuby mailing list