Sha256: a793c17bfae107e54c2f6a4471c8cb91a045a15f4799d41fe8f8e083cd57de00

Contents?: true

Size: 1.46 KB

Versions: 2

Compression:

Stored size: 1.46 KB

Contents

module ViralSeq
  class DRMs

    # function to retrieve sdrm positions as a hash, DRM list are stored at `lib/viral_seq/util/drm_list.json`
    # @param ref_option [Symbol], name of reference genomes, options are `:hiv_pr`, `:hiv_rt`, `:hiv_in`, `hcv_ns5a`
    # @return [Hash] Hash of :position_number => [ 'wildtype_codon', ['mutation_codons']]

    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 # end of #sdrm_hash

    # function to export SDRM positions as json object
    # @param (see #sdrm_hash)
    # @return [Array] json Array of SDRM positions

    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 #end of #sdrm_json
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
viral_seq-1.9.1 lib/viral_seq/sdrm.rb
viral_seq-1.9.0 lib/viral_seq/sdrm.rb