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



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

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

Instance Attribute Details

#modificationsObject (readonly)

Returns the value of attribute modifications.



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

def modifications
  @modifications
end

#positionObject (readonly)

Returns the value of attribute position.



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

def position
  @position
end

Instance Method Details

#hydroxymethylated?Boolean

Check if this position has hydroxymethylation

Returns:

  • (Boolean)

    true if any modification is hydroxymethylation ('h')



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

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

#inspectString

Inspect string

Returns:

  • (String)

    Inspect string



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

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')



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

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

#to_hHash

Convert to hash representation

Returns:

  • (Hash)

    Hash with position information



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

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

#to_sString

String representation

Returns:

  • (String)

    String representation



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

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