[BioRuby] RestrictionEnzyme?

Toshiaki Katayama ktym at hgc.jp
Mon Nov 14 20:14:25 EST 2005


Hi Trevor,

On 2005/11/15, at 7:59, Trevor Wennblom wrote:
> Has anyone started work on a RestrictionEnzyme module like what BioPerl has?
> http://doc.bioperl.org/releases/bioperl-1.5.0-RC1/Bio/Tools/RestrictionEnzyme.html
>
> If no one has beat me too it yet I can tackle this one.


I don't know anyone is working on this.

Here's a sample I wrote for my ruby seminar to count
just the length of each fragments (I didn't care about
the circular genome).

Toshiaki


#!/usr/bin/env ruby

require 'bio'

class REnzyme
  Enzymes = [
    ["EcoRI",   /GAATTC/i,      1,      5 ],    # G*AATTC
    ["HindIII", /AAGCTT/i,      1,      5 ],    # A*AGCTT
    ["BamHI",   /GGATCC/i,      1,      5 ],    # G*GATCC
    ["NotI",    /GCGGCCGC/i,    2,      6 ],    # GC*GGCCGC
  ]

  def initialize(seq)
    @seq = seq
    Enzymes.each do |name, pattern, before, after|
      ary = @seq.split(pattern)
      print "#{name}\t"
      #p ary.map {|subseq| subseq.length}
      p adjust(ary, before, after)
    end
  end

  def adjust(ary, before, after)
    if ary.size > 1
      sizes = Array.new

      sizes << ary.shift.length + before
      ary.each do |subseq|
        sizes << after + subseq.length + before
      end
      sizes[-1] -= before

      return sizes
    else
      return [ary.first.length]
    end
  end
end

Bio::FlatFile.auto(ARGF) do |ff|
  ff.each do |entry|
    puts ">>> #{entry.entry_id} (#{entry.nalen}bp)"
    REnzyme.new(entry.naseq)  
  end
end




More information about the BioRuby mailing list