Skip to content

Commit

Permalink
* clean up by katayama
Browse files Browse the repository at this point in the history
  • Loading branch information
ktym committed Aug 9, 2005
1 parent 3ab80de commit 2275fab
Showing 1 changed file with 153 additions and 128 deletions.
281 changes: 153 additions & 128 deletions lib/bio/util/sirna.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# bio/util/sirna.rb - Class for Designing small inhibitory RNAs
# bio/util/sirna.rb - Class for designing small inhibitory RNAs
#
# Copyright (C) 2004 Itoshi NIKAIDO <itoshi.nikaido@nifty.com>
# Copyright (C) 2004, 2005 Itoshi NIKAIDO <dritoshi@gmail.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand All @@ -17,12 +17,13 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id: sirna.rb,v 1.1 2005/08/09 03:50:36 k Exp $
# $Id: sirna.rb,v 1.2 2005/08/09 05:39:26 k Exp $
#

require 'bio/sequence'

module Bio

class SiRNA

def initialize(seq, antisense_size = 21, max_gc_percent = 60.0, min_gc_percent = 40.0)
Expand All @@ -32,173 +33,178 @@ def initialize(seq, antisense_size = 21, max_gc_percent = 60.0, min_gc_percent =
@max_gc_percent = max_gc_percent
@min_gc_percent = min_gc_percent
end
attr_accessor :antisense_size
attr_accessor :antisense_size, :max_gc_percent, :min_gc_percent

def uitei?(target)
return false unless /^.{2}[G|C]/i =~ target.to_s
return false unless /[A|U].{2}$/i =~ target.to_s
return false unless /^.{2}[GC]/i =~ target
return false unless /[AU].{2}$/i =~ target
return false if /[GC]{9}/i =~ target
return false if /[GC]{9}/i =~ target.complement.rna # same as above?

one_third = target.size * 1 / 3
start = @target_size - one_third - 1
one_third_seq = target.subseq(start, @target_size - 2)
gc = 0
one_third_seq.scan(/[A|U]/i) { gc += 1 }
return false if gc < 5
start_pos = @target_size - one_third - 1
remain_seq = target.subseq(start_pos, @target_size - 2)
gc_number = remain_seq.scan(/[AU]/i).size
return false if gc_number < 5

return false if /[G|C]{9}/i =~ target
return false if /[G|C]{9}/i =~ target.complement.rna
return true
end

def reynolds?(target)
return false if /[G|C]{9}/i =~ target
return false if /[G|C]{9}/i =~ target.complement.rna
if /^.{4}A.{6}U.{2}[A|U|C].{5}[A|U].{2}$/i =~ target.to_s
return true
else
return false
end
return false if /[GC]{9}/i =~ target
return false if /[GC]{9}/i =~ target.complement.rna # means same as above?
return false unless /^.{4}A.{6}U.{2}[AUC].{5}[AU].{2}$/i =~ target
return true
end

def uitei
design('uitei')
end

def reynolds
design('reynolds')
end

def design(rule = 'uitei')
@target_size = @antisense_size + 2
bp = 0
@seq.window_search(@target_size) do |target|
bp += 1

target_start = 0
@seq.window_search(@target_size) do |target|
antisense = target.subseq(1, @target_size - 2).complement.rna
sense = target.subseq(3, @target_size)

target_start = bp
target_stop = bp + @target_size
target_start += 1
target_stop = target_start + @target_size

antisense_gc_percent = antisense.gc_percent
next if antisense_gc_percent > @max_gc_percent
next if antisense_gc_percent < @min_gc_percent

if rule == 'uitei'
next if uitei?(target) == false
elsif rule == 'reynolds'
next if reynolds?(target) == false
case rule
when 'uitei'
next unless uitei?(target)
when 'reynolds'
next unless reynolds?(target)
else
next
raise NotImplementedError
end

pair = Bio::SiRNA::Pair.new(target, sense, antisense, target_start, target_stop, rule, antisense_gc_percent)
@pairs.push(pair)

end #window_search
end
return @pairs
end #design
end


class Pair

def initialize(target, sense, antisense, start, stop, rule, gc_percent)
@target = target
@sense = sense
@antisense = antisense
@start = start
@stop = stop
@rule = rule
@target = target
@sense = sense
@antisense = antisense
@start = start
@stop = stop
@rule = rule
@gc_percent = gc_percent
end

attr_accessor :target
attr_accessor :sense
attr_accessor :antisense
attr_accessor :start, :stop
attr_accessor :rule
attr_accessor :gc_percent

def as_human_readable_text
# human readable report
report = "--\n"
report << 'start: ' + @start.to_s + "\n"
report << 'stop: ' + @stop.to_s + "\n"
report << 'rule: ' + @rule.to_s + "\n"
report << 'gc_percent: ' + @gc_percent.to_s + "\n"
report << 'target: ' + @target.upcase + "\n"
report << 'sense: ' + ' ' + @sense.upcase + "\n"
report << 'antisense: ' + @antisense.reverse.upcase + "\n"

# computer parseble
# puts antisense
# puts target_start
# puts target_stop
attr_accessor :target, :sense, :antisense, :start, :stop, :rule, :gc_percent

# human readable report
def report
report = "### siRNA\n"
report << 'Start: ' + @start.to_s + "\n"
report << 'Stop: ' + @stop.to_s + "\n"
report << 'Rule: ' + @rule.to_s + "\n"
report << 'GC %: ' + @gc_percent.to_s + "\n"
report << 'Target: ' + @target.upcase + "\n"
report << 'Sense: ' + ' ' + @sense.upcase + "\n"
report << 'Antisense: ' + @antisense.reverse.upcase + "\n"
end
alias :to_s :as_human_readable_text

end #class Bio::SiRNA::Pair
# computer parsable report
#def to_s
# [ @antisense, @start, @stop ].join("\t")
#end

end #class Pair


class ShRNA

def initialize(pair, method_name)
def initialize(pair)
@pair = pair
@method_name = method_name
@top_strand_shrna = nil
@bottom_strand_shrna = nil
@loop = nil
end
attr_accessor :method_name
attr_accessor :top_strand_shrna
attr_accessor :bottom_strand_shrna
attr_accessor :loop

def design
if @method_name == 'BLOCK-iT'
attr_accessor :top_strand, :bottom_strand

def design(method = 'BLOCK-iT')
case method
when 'BLOCK-iT'
block_it
else
raise NotImplementedError
end
end

def block_it
top_strand_shrna_overhang = Bio::Sequence::NA.new('CACC')
bottom_strand_shrna_overhang = Bio::Sequence::NA.new('AAAA')
# loop = Bio::Sequence::NA.new('CGAA') # From BLOCK-iT's manual
@loop = Bio::Sequence::NA.new('GTGTGCTGTCC') # From piGENE document

if /^[G|g]/ =~ @pair.sense
@top_strand_shrna = top_strand_shrna_overhang + @pair.sense + loop + @pair.sense.complement
@bottom_strand_shrna = bottom_strand_shrna_overhang + @pair.sense + loop.complement + @pair.sense.complement

def block_it(method = 'piGENE')
top = Bio::Sequence::NA.new('CACC') # top_strand_shrna_overhang
bot = Bio::Sequence::NA.new('AAAA') # bottom_strand_shrna_overhang
fwd = @pair.sense
rev = @pair.sense.complement

case method
when 'BLOCK-iT'
# From BLOCK-iT's manual
loop_fwd = Bio::Sequence::NA.new('CGAA')
loop_rev = loop_fwd.complement
when 'piGENE'
# From piGENE document
loop_fwd = Bio::Sequence::NA.new('GTGTGCTGTCC')
loop_rev = loop_fwd.complement
else
raise NotImplementedError
end

if /^G/i =~ fwd
@top_strand = top + fwd + loop_fwd + rev
@bottom_strand = bot + fwd + loop_rev + rev
else
@top_strand_shrna = top_strand_shrna_overhang + 'G' + @pair.sense + loop + @pair.sense.complement
@bottom_strand_shrna = bottom_strand_shrna_overhang + @pair.sense + loop.complement + @pair.sense.complement + 'C'
@top_strand = top + 'G' + fwd + loop_fwd + rev
@bottom_strand = bot + fwd + loop_rev + rev + 'C'
end

# @top_strand_shrna = Bio::Sequence::NA.new(@top_strand_shrna).dna!
# @bottom_strand_shrna = Bio::Sequence::NA.new(@bottom_strand_shrna).dna!
end

def as_human_readable_text
report = ''
# report << 'Top Strand shRNA: ' + @top_strand_shrna.upcase.gsub(/G/, 'g') + "\n"
# report << 'Bottom Strand shRNA: ' + @bottom_strand_shrna.upcase.gsub(/G/, 'g') + "\n"
report << 'Top Strand shRNA: ' + @top_strand_shrna.upcase + "\n"
report << 'Bottom Strand shRNA: ' + @bottom_strand_shrna.upcase + "\n"
report << 'Size of Top Strand shRNA: ' + @top_strand_shrna.size.to_s + ' nt' + "\n"
report << 'Size of Bottom Strand shRNA: ' + @bottom_strand_shrna.size.to_s + ' nt' + "\n"
report << "5'-" + @top_strand_shrna.upcase + "-3'" + "\n"
report << " 3'-" + @bottom_strand_shrna.reverse.upcase + "-5'" + "\n"
def report
report = "### shRNA\n"
report << "Top strand shRNA (#{@top_strand.length} nt):\n"
report << " 5'-#{@top_strand.upcase}-3'\n"
report << "Bottom strand shRNA (#{@bottom_strand.length} nt):\n"
report << " 3'-#{@bottom_strand.reverse.upcase}-5'\n"
end
alias :to_s :as_human_readable_text

end #class Bio::SiRNA::ShRNA
end #class ShRNA

end #class SiRNA

end #module bio


if __FILE__ == $0

input_seq = ARGF.read
seq = Bio::Sequence::NA.new(input_seq)
sirna_designer = Bio::SiRNA.new(seq)
pairs = sirna_designer.design(rule = 'uitei') # or (rule = 'reynolds')
seq = Bio::Sequence::NA.new(ARGF.read)

sirna = Bio::SiRNA.new(seq)
pairs = sirna.design # or .design('uitei') or .uitei or .reynolds

pairs.each do |pair|
shRNA = Bio::SiRNA::ShRNA.new(pair, 'BLOCK-iT')
shRNA.design
puts pair.report

puts pair.as_human_readable_text
puts shRNA.as_human_readable_text
puts [shRNA.top_strand_shrna.dna!, shRNA.bottom_strand_shrna.dna!].join("\t")
shrna = Bio::SiRNA::ShRNA.new(pair)
shrna.design # or .design('BLOCK-iT') or .block_it
puts shrna.report

puts "# as DNA"
puts shrna.top_strand.dna
puts shrna.bottom_strand.dna
end

end
Expand All @@ -222,12 +228,23 @@ def as_human_readable_text
Angela Reynolds et al. Rational siRNA design for RNA interference.
Nature Biotech. 2004 22: 326-330.
-- Bio::SiRNA.new(seq, antisense_size, max_gc_percent, min_gc_percent)
--- Bio::SiRNA.new(seq, antisense_size, max_gc_percent, min_gc_percent)
--- Bio::SiRNA#design(rule)
rule can be one of 'uitei' (default) and 'reynolds'.
--- Bio::SiRNA#uitei
same as design('uitei')
--- Bio::SiRNA#reynolds
-- Bio::SiRNA#design(rule)
-- Bio::SiRNA#antisense_size
-- Bio::SiRNA#max_gc_percent
-- Bio::SiRNA#min_gc_percent
same as design('reynolds')
--- Bio::SiRNA#antisense_size
--- Bio::SiRNA#max_gc_percent
--- Bio::SiRNA#min_gc_percent
== Bio::SiRNA::Pair
Expand All @@ -238,22 +255,30 @@ def as_human_readable_text
--- Bio::SiRNA::Pair#antisense
--- Bio::SiRNA::Pair#start
--- Bio::SiRNA::Pair#stop
--- Bio::SiRNA::Pair#as_human_readable_text
--- Bio::SiRNA::Pair#rule
--- Bio::SiRNA::Pair#report
= Bio::ShRNA
== Bio::SiRNA::ShRNA
Input is a Bio::SiRNA::Pair object (the target sequence).
Output is a list of Bio::SiRNA::Pair object.
-- Bio::ShRNA.new(pair, 'design rule name')
--- Bio::ShRNA.new(pair)
--- Bio::ShRNA#design(rule)
only the 'BLOCK-iT' rule is implemented for now
--- Bio::ShRNA#block_it(method)
same as design('BLOCK-iT').
method can be one of 'piGENE' (default) and 'BLOCK-iT'.
-- Bio::ShRNA#design(rule)
-- Bio::ShRNA#antisense_size
-- Bio::ShRNA#max_gc_percent
-- Bio::ShRNA#min_gc_percent
--- Bio::ShRNA#top_strand
--- Bio::ShRNA#bottom_strand
--- Bio::ShRNA#report
-- ChangeLog
=== ChangeLog
2005/03/21 Itoshi NIKAIDO <itoshi.nikaido@nifty.com>
Bio::SiRNA#ShRNA_designer method was changed design method.
Expand Down

0 comments on commit 2275fab

Please sign in to comment.