Class: HTS::Bam::BaseMod::Position

Inherits:
Object
  • Object
show all
Defined in:
lib/hts/bam/base_mod.rb

Overview

Position-specific modification information

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(position, modifications) ⇒ Position

Returns a new instance of Position.

Parameters:

  • position (Integer)

    Position in query sequence

  • modifications (Array<Modification>)

    Array of modifications at this position



91
92
93
94
# File 'lib/hts/bam/base_mod.rb', line 91

def initialize(position, modifications)
  @position = position
  @modifications = modifications
end

Instance Attribute Details

#modificationsObject (readonly)

Returns the value of attribute modifications.



87
88
89
# File 'lib/hts/bam/base_mod.rb', line 87

def modifications
  @modifications
end

#positionObject (readonly)

Returns the value of attribute position.



87
88
89
# File 'lib/hts/bam/base_mod.rb', line 87

def position
  @position
end

Instance Method Details

#hydroxymethylated?Boolean

Check if this position has hydroxymethylation

Returns:

  • (Boolean)

    true if any modification is hydroxymethylation (‘h’)



104
105
106
# File 'lib/hts/bam/base_mod.rb', line 104

def hydroxymethylated?
  @modifications.any? { |m| m.code == "h" }
end

#inspectString

Inspect string

Returns:

  • (String)

    Inspect string



126
127
128
# File 'lib/hts/bam/base_mod.rb', line 126

def inspect
  "#<HTS::Bam::BaseMod::Position #{self}>"
end

#methylated?Boolean

Check if this position has methylation

Returns:

  • (Boolean)

    true if any modification is methylation (‘m’)



98
99
100
# File 'lib/hts/bam/base_mod.rb', line 98

def methylated?
  @modifications.any? { |m| m.code == "m" }
end

#to_hHash

Convert to hash representation

Returns:

  • (Hash)

    Hash with position information



110
111
112
113
114
115
# File 'lib/hts/bam/base_mod.rb', line 110

def to_h
  {
    position: @position,
    modifications: @modifications.map(&:to_h)
  }
end

#to_sString

String representation

Returns:

  • (String)

    String representation



119
120
121
122
# File 'lib/hts/bam/base_mod.rb', line 119

def to_s
  mods_str = @modifications.map(&:to_s).join(", ")
  "pos=#{@position} [#{mods_str}]"
end