Class: ViralSeq::DrmVersion

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

Overview

DRM version configuration. Configuration files are located at ‘lib/viral_seq/drm_versions_config.json`

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(drm_version, drm_range, seq_coord, seq_drm_correlation, ref_info) ⇒ DrmVersion

initialize a ViralSeq::DrmVersion instance

Parameters:

  • drm_version (String)

    version of the instance of DrmVersion

  • drm_range (Hash)

    region/class of DRM and the range of amino acid positions included in this version.

  • seq_coord (Hash)

    region and its amplicon positions on HXB2 reference

  • seq_drm_corrlation (Hash)

    correlation of sequenced region and DRM class

  • ref_info (Hash)

    information of the reference genome, including sequence coordinates on HXB2



15
16
17
18
19
20
21
# File 'lib/viral_seq/drm_version.rb', line 15

def initialize(drm_version, drm_range, seq_coord, seq_drm_correlation, ref_info)
  @drm_version = drm_version
  @drm_range = drm_range
  @seq_coord = seq_coord
  @seq_drm_correlation = seq_drm_correlation
  @ref_info = ref_info
end

Instance Attribute Details

#drm_rangeObject

Returns the value of attribute drm_range.



23
24
25
# File 'lib/viral_seq/drm_version.rb', line 23

def drm_range
  @drm_range
end

#drm_versionObject

Returns the value of attribute drm_version.



23
24
25
# File 'lib/viral_seq/drm_version.rb', line 23

def drm_version
  @drm_version
end

#ref_infoObject

Returns the value of attribute ref_info.



23
24
25
# File 'lib/viral_seq/drm_version.rb', line 23

def ref_info
  @ref_info
end

#seq_coordObject

Returns the value of attribute seq_coord.



23
24
25
# File 'lib/viral_seq/drm_version.rb', line 23

def seq_coord
  @seq_coord
end

#seq_drm_correlationObject

Returns the value of attribute seq_drm_correlation.



23
24
25
# File 'lib/viral_seq/drm_version.rb', line 23

def seq_drm_correlation
  @seq_drm_correlation
end

Class Method Details

.config_version(v = "v1") ⇒ ViralSeq::DrmVersion

construct a specific version of ViralSeq::DrmVersion

Parameters:

  • v (String) (defaults to: "v1")

    version string

Returns:



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/viral_seq/drm_version.rb', line 42

def self.config_version(v="v1")
  v = v.downcase
  v = "v1" if v == "v2"

  drm_config = JSON.parse(
    File.read(
      File.join( ViralSeq.root, 'viral_seq', 'util', 'drm_versions_config.json')
      )
  )

  drm_versions = {}

  drm_config.each do |config|
    drm_versions[config["version"]] = ViralSeq::DrmVersion.construct(config)
  end

  if drm_versions[v]
    drm_versions[v]
  else
    abort (
    "Version '#{v}' config not found. Program aborted. \nCurrent supported versions '#{drm_versions.keys.sort.join(", ")}'\nCheck documentations for details".red
    )
  end
end

.construct(version_config_hash) ⇒ ViralSeq::DrmVersion

construct an instance of ViralSeq::DrmVersion

Parameters:

  • version_config_hash (Hash)

    json hash of stored version configurations.

Returns:



29
30
31
32
33
34
35
36
# File 'lib/viral_seq/drm_version.rb', line 29

def self.construct(version_config_hash)
  drm_version = version_config_hash["version"]
  drm_range = version_config_hash["DRM_range"]
  seq_coord = version_config_hash["seq_coord"]
  seq_drm_correlation = version_config_hash["seq_drm_correlation"]
  ref_info = version_config_hash["ref_info"]
  ViralSeq::DrmVersion.new(drm_version, drm_range, seq_coord, seq_drm_correlation, ref_info)
end

Instance Method Details

#pull_drm_jsonHash

summarize the DRM information for the output as JSON

Returns:

  • (Hash)

    json has for DRM inforation of each position



106
107
108
109
110
111
112
113
114
115
116
# File 'lib/viral_seq/drm_version.rb', line 106

def pull_drm_json

  summary_json_hash = {}

  self.seq_drm_correlation.keys.each do |region|
    summary_json_hash = summary_json_hash.merge query_region(region).drm_json
  end

  summary_json_hash

end

#query_region(region) ⇒ ViralSeq::DrmRegionConfig

construct a ViralSeq::DrmRegionConfig instance from a specific version

Parameters:

  • region (String)

    name of the region

Returns:



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/viral_seq/drm_version.rb', line 71

def query_region(region)
  region = region.to_s.upcase
  drm_classes = self.seq_drm_correlation[region]

  if drm_classes.nil?
    abort "Region not recognized by the specific DRM config version. Program aborted."
  end

  drm_range = {}
  drm_list = {}

  drm_classes.each do |drm_class|
    drm_range[drm_class] = self.drm_range[drm_class]
    drm_list_single_class = ViralSeq::DRMs.sdrm_hash(drm_class)

    drm_list[drm_class] = drm_list_single_class.select { |k, _v| drm_range[drm_class].include? k }

  end


  seq_coord = self.seq_coord[region]

  ref_info = {}
  ref_info["ref_type"] = self.ref_info["ref_type"]
  ref_info["ref_coord"] = self.ref_info["ref_coord"][region]


  ViralSeq::DrmRegionConfig.new(
    self.drm_version, region, drm_classes, drm_range, drm_list, seq_coord, ref_info
  )
end