Update, April 4th: I wrote a quick explanation for some of the code here
I wrote a script some time ago that ported the examples in this Python article to Ruby(check out BioRuby for a large scale approach to Bioinformatics). Some sparse documentation can be found at my old(but still usable website) here. Note that I do not actively update the website where the documentation is being kept.
NOTE WELL:
This code is not very well-tested yet, so watch your head. This code is licensed under GPLv2. You can read the license and disclaimers here. VIEWING TIP: In Mac Firefox press Apple++ to enlarge the viewing size.
#!/usr/bin/env ruby
#==Bioinformatics Usage Examples
#Instantiate a DNA object
#=Constructor
#d = DNA.new(”CGGGG”) => DNA object
#=Reversing a strand
#d.reverse => “GGGGC”
#=Finding the complement
#d.complement => “CCCCG”
#=Find the codons in a given strand
#d.codons => ["CGG"]
class DNA
#Holds the base complement information for all instances of the class
@@basecomplement = {‘a‘ => ‘t‘, ‘c‘ => ‘g‘, ‘t‘ => ‘a‘, ‘g‘ => ‘c‘}
def initialize(s)
#Example: d = DNA.new
@seq = s.downcase
@len = s.length
end
#Return as RNA string
#Example d.transcribe
def transcribe
@seq.gsub(‘t‘,‘u‘)
end
#Return DNA string in reverse order
def reverse
@seq.reverse
end
#Internal function (do not use)
def reverse!
@seq.reverse!
end
#Complement function
def complement
compl(@seq)
end
#Internal function (do not use)
def compl(s)
s = s.split(/\B/).to_a.collect!{|base| @@basecomplement[base]}.to_s
end
#reversecomplement function
def reversecomplement
reverse!
complement
end
#statistics function
def gc
gc = @seq.count(‘g‘) + @seq.count(‘c‘)
gc * 100.0 / @seq.length()
end
#Get patterns of three bases
def codons
codons = Array.new
ending = @len - (@len % 3) - 1
0.step(ending,3){|i| codons.push(@seq[i..i+2])}
return codons
end
end
if __FILE__ == $0
d = DNA.new(“CGG“)
puts(d.reverse())
end
0 responses so far ↓
There are no comments yet...Kick things off by filling out the form below.
Leave a Comment