Class: ViralSeq::DrmRegionConfig

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

Overview

DRM configuration for each region

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(drm_version, region, drm_class, drm_range, drm_list, seq_coord, ref_info) ⇒ DrmRegionConfig

initialize DRM region configuration

Parameters:

  • drm_version (String)

    version of the instance of DrmVersion

  • region (String)

    name of the region

  • drm_class (Array)

    classes of DRMs at this region

  • drm_range (Hash)

    DRM range for each class of DRMs at this region

  • drm_list (Hash)

    List of detailed DRM mutations for each DRM classes at this region

  • seq_drm_corrlation (Hash)

    correlation of sequenced region and DRM class

  • ref_info (Hash)

    information of the reference genome, including sequence coordinates on HXB2



16
17
18
19
20
21
22
23
24
# File 'lib/viral_seq/drm_region_config.rb', line 16

def initialize(drm_version, region, drm_class, drm_range, drm_list, seq_coord, ref_info)
  @drm_version = drm_version
  @region = region
  @drm_class = drm_class
  @drm_range = drm_range
  @drm_list = drm_list
  @seq_coord = seq_coord
  @ref_info = ref_info
end

Instance Attribute Details

#drm_classObject

Returns the value of attribute drm_class.



26
27
28
# File 'lib/viral_seq/drm_region_config.rb', line 26

def drm_class
  @drm_class
end

#drm_listObject

Returns the value of attribute drm_list.



26
27
28
# File 'lib/viral_seq/drm_region_config.rb', line 26

def drm_list
  @drm_list
end

#drm_rangeObject

Returns the value of attribute drm_range.



26
27
28
# File 'lib/viral_seq/drm_region_config.rb', line 26

def drm_range
  @drm_range
end

#drm_versionObject

Returns the value of attribute drm_version.



26
27
28
# File 'lib/viral_seq/drm_region_config.rb', line 26

def drm_version
  @drm_version
end

#ref_infoObject

Returns the value of attribute ref_info.



26
27
28
# File 'lib/viral_seq/drm_region_config.rb', line 26

def ref_info
  @ref_info
end

#regionObject

Returns the value of attribute region.



26
27
28
# File 'lib/viral_seq/drm_region_config.rb', line 26

def region
  @region
end

#seq_coordObject

Returns the value of attribute seq_coord.



26
27
28
# File 'lib/viral_seq/drm_region_config.rb', line 26

def seq_coord
  @seq_coord
end

Instance Method Details

#drm_jsonHash

summarize the DRM information for the output as JSON for the specific version

Returns:

  • (Hash)

    json has for DRM inforation of each position



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

def drm_json
  sdrm = self.drm_list
  json_hash = {}
  sdrm.each do |drm_class, drms|
    json_hash[drm_class] = []
    drms.each do |pos, muts|
      mutation = {}
      mutation[:position] = pos
      mutation[:wildtypeCodon] = muts[0]
      mutation[:mutationCodons] = muts[1]
      json_hash[drm_class] << mutation
    end
  end
  return json_hash
end

#get_reading_frame_numberInteger

determine the reading frame number based on the sequence coordinates

Returns:

  • (Integer)

    reading frame of 0, 1 or 2



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/viral_seq/drm_region_config.rb', line 61

def get_reading_frame_number
  m1 = (self.seq_coord["minimum"] - self.ref_info["ref_coord"][0]) % 3
  if m1.zero?
    n1 = 0
  else
    n1 = 3 - m1
  end

  if seq_coord["gap"]
    m2 = (self.seq_coord["gap"]["maximum"] + 1 - self.ref_info["ref_coord"][0]) % 3
    if m2.zero?
      n2 = 0
    else
      n2 = 3 - m2
    end
    return [n1, n2]
  else
    return [n1]
  end
end

#r1_r2_lengthHash

calculate the length of R1 and R2 based on the sequence coordinates

Returns:

  • (Hash)

    [Integer], r2_length: [Integer]



48
49
50
51
52
53
54
55
56
# File 'lib/viral_seq/drm_region_config.rb', line 48

def r1_r2_length
  seq_coord = self.seq_coord
  return nil unless seq_coord["gap"]

  r1_length = seq_coord["gap"]["minimum"] - seq_coord["minimum"]
  r2_length = seq_coord["maximum"] - seq_coord["gap"]["maximum"]

  return {r1_length: r1_length, r2_length: r2_length}
end