[BioRuby] New Bio::Sequence and Handlers

jan aerts (RI) jan.aerts at bbsrc.ac.uk
Mon Mar 3 17:29:38 UTC 2008


I like the idea of programming against an interface (will have to reread that first chapter of "Design Patterns in Ruby", though. But I'm a bit worried to see "class SequenceFromGenBank"... It should not matter what the source of the (annotated) sequence is. Whether it comes from GenBank, or EMBL, or Fasta, it's still just a Bio::Sequence with features and references.

jan.


-----Original Message-----
From: bioruby-bounces at lists.open-bio.org on behalf of Naohisa GOTO
Sent: Mon 3/3/2008 4:58 PM
To: bioruby at lists.open-bio.org
Subject: Re: [BioRuby] New Bio::Sequence and Handlers
 
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
> 
_______________________________________________
BioRuby mailing list
BioRuby at lists.open-bio.org
http://lists.open-bio.org/mailman/listinfo/bioruby





More information about the BioRuby mailing list