Class: ViralSeq::DRMs

Inherits:
Object
  • Object
show all
Defined in:
lib/viral_seq/sdrm.rb

Class Method Summary collapse

Class Method Details

.sdrm_hash(options) ⇒ Hash

function to retrieve sdrm positions as a hash, DRM list are stored at ‘lib/viral_seq/util/drm_list.json`

Parameters:

  • ref_option (Symbol)

    , name of reference genomes, options are ‘:hiv_pr`, `:hiv_rt`, `:hiv_in`, `hcv_ns5a`

Returns:

  • (Hash)

    Hash of :position_number => [ ‘wildtype_codon’, [‘mutation_codons’]]



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/viral_seq/sdrm.rb', line 8

def self.sdrm_hash(options)
  options = options.to_s.upcase
  drm_data = JSON.parse(
    File.read(
      File.join(ViralSeq.root, 'viral_seq', 'util', 'drm_list.json')
    )
  )
  if drm_data[options]
    sdrm = {}
    drm_data[options].each do |record|
      sdrm[record["position"]] = [record["wild-type"], record["mutations"]]
    end

  else
    abort "Input option `#{options}` for ViralSeq::DRMs.sdrm_hash not supported. Program aborted.\nSupported type of mutations for '#{drm_data.keys.join(", ")}' only."
  end
  return sdrm
end

.sdrm_json(options) ⇒ Array

function to export SDRM positions as json object

Returns:

  • (Array)

    json Array of SDRM positions



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/viral_seq/sdrm.rb', line 31

def self.sdrm_json(options)
  sdrm = ViralSeq::DRMs.sdrm_hash(options)
  json_array = []
  sdrm.each do |pos, muts|
    mutation = {}
    mutation[:position] = pos
    mutation[:wildtypeCodon] = muts[0]
    mutation[:mutationCodons] = muts[1]
    json_array << mutation
  end
  return json_array
end