Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/exodb/addon/string.rb

Overview

raise “Please, use ruby 1.9.0 or later.” if RUBY_VERSION < “1.9.0”

Instance Method Summary collapse

Instance Method Details

#count_alleleObject

For Pileup string



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# 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

#idObject



20
21
22
# File 'lib/exodb/addon/string.rb', line 20

def id
  return self.is_miriam? ? self.split(':', 4)[-1] : ''
end

#is_hgvs?Boolean

For HGV

Returns:

  • (Boolean)


34
35
36
# File 'lib/exodb/addon/string.rb', line 34

def is_hgvs?
  return self =~ Exodb::HGVPATTERN
end

#is_loc?Boolean

Location String

Returns:

  • (Boolean)


142
143
144
# File 'lib/exodb/addon/string.rb', line 142

def is_loc?
  return /^\w+:(\d+|\d+\.\.\d+|\d+-\d+)(:\w+)?$/
end

#is_miriam?Boolean

For miriam

Returns:

  • (Boolean)


16
17
18
# File 'lib/exodb/addon/string.rb', line 16

def is_miriam?
  return self =~ /^urn:miriam:/
end

#is_pileup_var?Boolean

For pileup var

Returns:

  • (Boolean)


113
114
115
116
# File 'lib/exodb/addon/string.rb', line 113

def is_pileup_var?
  dat = self.split(/\//)
  return dat[0].is_loc? && dat[1] =~ /[\+\-]?[ATCG]+/
end

#namespaceObject



24
25
26
# File 'lib/exodb/addon/string.rb', line 24

def namespace
  return self.is_miriam? ? self.split(':', 4)[2] : ''
end

#parse_hgvsObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# 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_locObject

Assign gene location in format of chromosome_number:start..stop

Parameters:

  • gene (String)

    location in format of chromosome_number:start..stop



150
151
152
153
154
155
156
157
158
159
160
161
162
163
# 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_varObject



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# 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

#resolveObject



28
29
30
# File 'lib/exodb/addon/string.rb', line 28

def resolve
  
end