class CodonUsage::KazusaDB
Public Class Methods
new(host: "http://www.kazusa.or.jp/codon/cgi-bin/showcodon.cgi?species=", aa: "1", species: "9606")
click to toggle source
# File lib/CodonUsage/kazusaDB.rb, line 11 def initialize(host: "http://www.kazusa.or.jp/codon/cgi-bin/showcodon.cgi?species=", aa: "1", species: "9606") # for default values of the arugments, please refer to README.md @url = "#{host}#{species}&aa=#{aa}&style=N" @codonPreferenceTable = {} @codonTable = {} end
Public Instance Methods
fetch()
click to toggle source
# File lib/CodonUsage/kazusaDB.rb, line 21 def fetch tableString = "" codonTable = {} codonList = [] prefList = [] aminoAcidList = [] open(@url) {|url| url.each_line {|line| tableString<<line.gsub(/\( +/, '').gsub(/\)[ |\n]/, "\n").gsub(/ +/, "\t").gsub(/\n\t/,"\n") if line.match(/^[A|U|G|C]{3}/) # Quick & dirty way to change that table to tab-delimited format just like CSV file } } CSV.parse(tableString, {:col_sep => "\t"}).each {|codon| codonList.push(codon[0]) # extract the triplet prefList.push(codon[2]) # extract the fraction, also known as codon preference aminoAcidList.push(codon[1]) # extract the coding amino acid since different organisms have different codon table } @codonPreferenceTable = Hash[codonList.zip(prefList)] @codonTable = Hash[codonList.zip(aminoAcidList)] return 0 end
getCodonTable()
click to toggle source
# File lib/CodonUsage/kazusaDB.rb, line 42 def getCodonTable fetch return @codonTable end
getHash()
click to toggle source
# File lib/CodonUsage/kazusaDB.rb, line 47 def getHash fetch return @codonPreferenceTable end
getURL()
click to toggle source
# File lib/CodonUsage/kazusaDB.rb, line 17 def getURL return @url end
to_json()
click to toggle source
# File lib/CodonUsage/kazusaDB.rb, line 52 def to_json fetch return @codonPreferenceTable.to_json # just simply use built-in json library, only available Ruby 1.9.3+ end