[BioRuby] New Bio::Sequence and Handlers

Naohisa GOTO ngoto at gen-info.osaka-u.ac.jp
Mon Mar 3 16:58:09 UTC 2008


Hi,

I think using duck-typing is better. Because the @obj acts
the same as Bio::Sequence, there are no need to wrap
Sequence class and to use method_missing.

To distinguish the object can act as sequence, a module
can be used to define method interfaces and data type.

  module SequenceInterface
    def seq
      NotImplementedError
    end
    #....
  end

  class SequenceFromGenBank
    include SequenceInterface
  end

  a = SequenceFromGenBank.new
  a.kind_of?(SequenceInterface) # ==> true

I have another question. 
How about modification of Sequence objects?
Copy-on-write?

   s1 = Bio::Sequence.new('atg')
   s2 = Bio::Sequence.new('aag')
   s1.concat(s2)
   s1.definition = "test sequence"
   p s1
   # => <Bio::Sequence:0x00000000 @definition="test sequence", @seq="atgaag">

   s3 = Bio::Sequence.new(XXXX) # from some object or duck typing?
   s3.concat(s1)
   s3.definition = 'this is test'
   p s3
   # => ???

Thanks,

Naohisa Goto
ngoto at gen-info.osaka-u.ac.jp / ng at bioruby.org

On Mon, 03 Mar 2008 16:17:50 +0100
Raoul Jean Pierre Bonnal <raoul.bonnal at itb.cnr.it> wrote:

> Hello Guys, 
> my solution to generalize Bio::Sequence for lazy loading or not,
> discussed at Hackathon. Actually I don't know if this is the best
> solution but works and keeps compatibility with current release. 
> rename Bio::Sequence --> Bio::SequenceScratch
> 
> then define a new class reusing namespace Bio::Sequence:
> module Bio
>   class Sequence
>     #Handler for the generic sequence
>     attr_accessor :handler
>     
>     #Class Sequence initializer, actually not well coded.
>     def initialize(obj)
>       if obj.is_a?(String) 
>         @handler= Bio::SequenceScratch.new(obj)
>       else
>         @handler=obj
>       end
>     end
>     
>     # 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:
>       @handler.__send__(sym, *args, &block)
>     end
>   end
> end
> 
> 
> --
> Ra
> 



More information about the BioRuby mailing list