class String
raise “Please, use ruby 1.9.0 or later.” if RUBY_VERSION < “1.9.0”
Public Instance Methods
count_allele()
click to toggle source
For Pileup string
# File lib/exodb/addon/string.rb, line 80 def count_allele allellset = { 'A' => "aA", 'T' => "tT", 'C' => "cC", 'G' => "gG", '.' => "\\.\\,", '*' => "\\*" } tmpstr = self.dup allele = {} self.scan(/([+-])(\d+)([ATCGatcg]+)/) do |a, b, c| pattern = "#{a}#{b}#{c[0,(b.to_i)]}".upcase if !allele.has_key?(pattern) allele[pattern] = 0 tmpstr.gsub!(/#{"#{b}#{c[0,(b.to_i)]}"}/, '') end allele[pattern] += 1 end allellset.each_pair do |k, v| allele[k] = tmpstr.count(v) if tmpstr.count(v) > 0 end return allele end
id()
click to toggle source
# File lib/exodb/addon/string.rb, line 20 def id return self.is_miriam? ? self.split(':', 4)[-1] : '' end
is_hgvs?()
click to toggle source
For HGV
# File lib/exodb/addon/string.rb, line 34 def is_hgvs? return self =~ Exodb::HGVPATTERN end
is_loc?()
click to toggle source
Location String
# File lib/exodb/addon/string.rb, line 142 def is_loc? return /^\w+:(\d+|\d+\.\.\d+|\d+-\d+)(:\w+)?$/ end
is_miriam?()
click to toggle source
For miriam
# File lib/exodb/addon/string.rb, line 16 def is_miriam? return self =~ /^urn:miriam:/ end
is_pileup_var?()
click to toggle source
For pileup var
# File lib/exodb/addon/string.rb, line 113 def is_pileup_var? dat = self.split(/\//) return dat[0].is_loc? && dat[1] =~ /[\+\-]?[ATCG]+/ end
namespace()
click to toggle source
# File lib/exodb/addon/string.rb, line 24 def namespace return self.is_miriam? ? self.split(':', 4)[2] : '' end
parse_hgvs()
click to toggle source
# File lib/exodb/addon/string.rb, line 38 def parse_hgvs result = {} Exodb::HGVPATTERN.match(self) do |m| if m[1] =~ /^chr/ ref = m[1].split(/\./) result[:chr] = ref[0] result[:assembly] = ref[1].blank? ? Exodb::DEFAULTASSEMBLY : Exodb.assembly(ref[1]) elsif m[1] =~ /^(\d{0,2}|[MXY])\./ ref = m[1].split(/\./) result[:chr] = "chr#{ref[0]}" result[:assembly] = ref[1].blank? ? Exodb::DEFAULTASSEMBLY : Exodb.assembly(ref[1]) else result[:chrrefseq] = m[1] end pos = m[2].split(/_/).sort result[:pos] = pos[0].to_i result[:start] = pos[0].to_i result[:stop] = pos[1].blank? ? pos[0].to_i : pos[1].to_i case m[3] when /^ins/ result[:type] = 'ins' result[:alt] = m[3][3..-1] when /^del/ result[:type] = 'del' result[:alt] = m[3][3..-1] else result[:type] = 'sub' result[:alt] = m[3].split(/\>/)[1] end end return result end
parse_loc()
click to toggle source
Assign gene location in format of chromosome_number:start..stop
@param [String] gene location in format of chromosome_number:start..stop
# File lib/exodb/addon/string.rb, line 150 def parse_loc if self =~ /^[^:]+:(\d+|\d+\.\.\d+|\d+-\d+)(:\w+)?$/ dat = self.split(/:/) pos = [] dat[1].split(/\.\.|-/).each {|e| pos.push(e.to_i)} pos.sort! return {'chr' => dat[0], 'start' => pos[0], 'pos' => pos[0], 'stop' => pos[1] ? pos[1] : pos[0], 'assembly' => dat[2] ? Exodb::assembly(dat[2]) : Exodb::DEFAULTASSEMBLY} else raise end end
parse_pileup_var()
click to toggle source
# File lib/exodb/addon/string.rb, line 118 def parse_pileup_var result = {} if self.is_pileup_var? dat = self.split(/\//) result = dat[0].parse_loc dat[1] =~ /([\+\-]?)([ATCG]+)/ result[:type] = case $1 when '+' 'ins' when '-' 'del' else 'sub' end result[:alt] = dat[1] end return result end
resolve()
click to toggle source
# File lib/exodb/addon/string.rb, line 28 def resolve end