Module: DbSNP

Extended by:
Resource
Defined in:
lib/rbbt/sources/dbSNP.rb

Constant Summary collapse

URL =
"ftp://ftp.ncbi.nlm.nih.gov/snp/organisms/human_9606/VCF/common_all.vcf.gz"

Class Method Summary collapse

Class Method Details

.mutation_index(organism) ⇒ Object



163
164
165
166
167
168
# File 'lib/rbbt/sources/dbSNP.rb', line 163

def self.mutation_index(organism)
  build = Organism.hg_build(organism)
  file = DbSNP[build == "hg19" ? "mutations" : "mutations_hg18"]
  @mutation_index ||= {}
  @mutation_index[build] ||= file.tsv :persist => true, :fields => ["Genomic Mutation"], :type => :single, :persist => true
end

.rsid_index(organism, chromosome = nil) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/rbbt/sources/dbSNP.rb', line 140

def self.rsid_index(organism, chromosome = nil)
  build = Organism.hg_build(organism)

  tag = [build, chromosome] * ":"
  Persist.persist("StaticPosIndex for dbSNP [#{ tag }]", :fwt, :persist => true) do
    value_size = 0
    file = DbSNP[build == "hg19" ? "mutations" : "mutations_hg18"]
    chr_positions = []
    Open.read(CMD.cmd("grep '\t#{chromosome}:'", :in => file.open, :pipe => true)) do |line|
      next if line[0] == "#"[0]
      rsid, mutation = line.split("\t")
      next if mutation.nil? or mutation.empty?
      chr, pos = mutation.split(":")
      next if chr != chromosome or pos.nil? or pos.empty?
      chr_positions << [rsid, pos.to_i]
      value_size = rsid.length if rsid.length > value_size
    end
    fwt = FixWidthTable.new :memory, value_size
    fwt.add_point(chr_positions)
    fwt
  end
end