Class: SSW::Align

Inherits:
Object
  • Object
show all
Defined in:
lib/ssw/align.rb

Overview

structure of the alignment result

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr) ⇒ Align

Returns a new instance of Align.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ssw/align.rb', line 42

def initialize(ptr)
  @ptr          = ptr
  @cstruct      = align = FFI::Align.new(ptr)
  @score1       = align.score1
  @score2       = align.score2
  @ref_begin1   = align.ref_begin1
  @ref_end1     = align.ref_end1
  @read_begin1  = align.read_begin1
  @read_end1    = align.read_end1
  @ref_end2     = align.ref_end2
  @cigar_len    = align.cigarLen
  @cigar        = cigar_len.positive? ? align.cigar[0, 4 * cigar_len].unpack('L*') : []
  # Attributes for ruby binding only
  @cigar_string = array_to_cigar_string(@cigar)
  SSW.align_destroy(ptr)
end

Instance Attribute Details

#cigarArray (readonly)

Returns best alignment cigar; stored the same as that in BAM format, high 28 bits: length, low 4 bits: M/I/D (0/1/2); cigar = 0 when the best alignment path is not available.

Returns:

  • (Array)

    best alignment cigar; stored the same as that in BAM format, high 28 bits: length, low 4 bits: M/I/D (0/1/2); cigar = 0 when the best alignment path is not available



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/ssw/align.rb', line 33

class Align
  def self.keys
    %i[score1 score2 ref_begin1 ref_end1
       read_begin1 read_end1 ref_end2 cigar cigar_len cigar_string]
  end

  # This class is read_only
  attr_reader(*keys)

  def initialize(ptr)
    @ptr          = ptr
    @cstruct      = align = FFI::Align.new(ptr)
    @score1       = align.score1
    @score2       = align.score2
    @ref_begin1   = align.ref_begin1
    @ref_end1     = align.ref_end1
    @read_begin1  = align.read_begin1
    @read_end1    = align.read_end1
    @ref_end2     = align.ref_end2
    @cigar_len    = align.cigarLen
    @cigar        = cigar_len.positive? ? align.cigar[0, 4 * cigar_len].unpack('L*') : []
    # Attributes for ruby binding only
    @cigar_string = array_to_cigar_string(@cigar)
    SSW.align_destroy(ptr)
  end

  def to_h
    self.class.keys.map { |k| [k, __send__(k)] }.to_h
  end

  private

  def array_to_cigar_string(arr)
    cigar_string = String.new
    arr.each do |x|
      n = x >> 4
      m = x & 15
      c = m > 8 ? 'M' : 'MIDNSHP=X'[m]
      cigar_string << n.to_s << c
    end
    cigar_string
  end
end

#cigar_lenInteger

Returns length of the cigar string; cigarLen = 0 when the best alignment path is not available.

Returns:

  • (Integer)

    length of the cigar string; cigarLen = 0 when the best alignment path is not available



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/ssw/align.rb', line 33

class Align
  def self.keys
    %i[score1 score2 ref_begin1 ref_end1
       read_begin1 read_end1 ref_end2 cigar cigar_len cigar_string]
  end

  # This class is read_only
  attr_reader(*keys)

  def initialize(ptr)
    @ptr          = ptr
    @cstruct      = align = FFI::Align.new(ptr)
    @score1       = align.score1
    @score2       = align.score2
    @ref_begin1   = align.ref_begin1
    @ref_end1     = align.ref_end1
    @read_begin1  = align.read_begin1
    @read_end1    = align.read_end1
    @ref_end2     = align.ref_end2
    @cigar_len    = align.cigarLen
    @cigar        = cigar_len.positive? ? align.cigar[0, 4 * cigar_len].unpack('L*') : []
    # Attributes for ruby binding only
    @cigar_string = array_to_cigar_string(@cigar)
    SSW.align_destroy(ptr)
  end

  def to_h
    self.class.keys.map { |k| [k, __send__(k)] }.to_h
  end

  private

  def array_to_cigar_string(arr)
    cigar_string = String.new
    arr.each do |x|
      n = x >> 4
      m = x & 15
      c = m > 8 ? 'M' : 'MIDNSHP=X'[m]
      cigar_string << n.to_s << c
    end
    cigar_string
  end
end

#cigar_stringString

Returns cigar string.

Returns:

  • (String)

    cigar string



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/ssw/align.rb', line 33

class Align
  def self.keys
    %i[score1 score2 ref_begin1 ref_end1
       read_begin1 read_end1 ref_end2 cigar cigar_len cigar_string]
  end

  # This class is read_only
  attr_reader(*keys)

  def initialize(ptr)
    @ptr          = ptr
    @cstruct      = align = FFI::Align.new(ptr)
    @score1       = align.score1
    @score2       = align.score2
    @ref_begin1   = align.ref_begin1
    @ref_end1     = align.ref_end1
    @read_begin1  = align.read_begin1
    @read_end1    = align.read_end1
    @ref_end2     = align.ref_end2
    @cigar_len    = align.cigarLen
    @cigar        = cigar_len.positive? ? align.cigar[0, 4 * cigar_len].unpack('L*') : []
    # Attributes for ruby binding only
    @cigar_string = array_to_cigar_string(@cigar)
    SSW.align_destroy(ptr)
  end

  def to_h
    self.class.keys.map { |k| [k, __send__(k)] }.to_h
  end

  private

  def array_to_cigar_string(arr)
    cigar_string = String.new
    arr.each do |x|
      n = x >> 4
      m = x & 15
      c = m > 8 ? 'M' : 'MIDNSHP=X'[m]
      cigar_string << n.to_s << c
    end
    cigar_string
  end
end

#read_begin1Integer

Returns 0-based best alignment beginning position on read; read_begin1 = -1 when the best alignment beginning position is not available.

Returns:

  • (Integer)

    0-based best alignment beginning position on read; read_begin1 = -1 when the best alignment beginning position is not available



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/ssw/align.rb', line 33

class Align
  def self.keys
    %i[score1 score2 ref_begin1 ref_end1
       read_begin1 read_end1 ref_end2 cigar cigar_len cigar_string]
  end

  # This class is read_only
  attr_reader(*keys)

  def initialize(ptr)
    @ptr          = ptr
    @cstruct      = align = FFI::Align.new(ptr)
    @score1       = align.score1
    @score2       = align.score2
    @ref_begin1   = align.ref_begin1
    @ref_end1     = align.ref_end1
    @read_begin1  = align.read_begin1
    @read_end1    = align.read_end1
    @ref_end2     = align.ref_end2
    @cigar_len    = align.cigarLen
    @cigar        = cigar_len.positive? ? align.cigar[0, 4 * cigar_len].unpack('L*') : []
    # Attributes for ruby binding only
    @cigar_string = array_to_cigar_string(@cigar)
    SSW.align_destroy(ptr)
  end

  def to_h
    self.class.keys.map { |k| [k, __send__(k)] }.to_h
  end

  private

  def array_to_cigar_string(arr)
    cigar_string = String.new
    arr.each do |x|
      n = x >> 4
      m = x & 15
      c = m > 8 ? 'M' : 'MIDNSHP=X'[m]
      cigar_string << n.to_s << c
    end
    cigar_string
  end
end

#read_end1Integer

Returns 0-based best alignment ending position on read.

Returns:

  • (Integer)

    0-based best alignment ending position on read



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/ssw/align.rb', line 33

class Align
  def self.keys
    %i[score1 score2 ref_begin1 ref_end1
       read_begin1 read_end1 ref_end2 cigar cigar_len cigar_string]
  end

  # This class is read_only
  attr_reader(*keys)

  def initialize(ptr)
    @ptr          = ptr
    @cstruct      = align = FFI::Align.new(ptr)
    @score1       = align.score1
    @score2       = align.score2
    @ref_begin1   = align.ref_begin1
    @ref_end1     = align.ref_end1
    @read_begin1  = align.read_begin1
    @read_end1    = align.read_end1
    @ref_end2     = align.ref_end2
    @cigar_len    = align.cigarLen
    @cigar        = cigar_len.positive? ? align.cigar[0, 4 * cigar_len].unpack('L*') : []
    # Attributes for ruby binding only
    @cigar_string = array_to_cigar_string(@cigar)
    SSW.align_destroy(ptr)
  end

  def to_h
    self.class.keys.map { |k| [k, __send__(k)] }.to_h
  end

  private

  def array_to_cigar_string(arr)
    cigar_string = String.new
    arr.each do |x|
      n = x >> 4
      m = x & 15
      c = m > 8 ? 'M' : 'MIDNSHP=X'[m]
      cigar_string << n.to_s << c
    end
    cigar_string
  end
end

#read_end2Integer

Returns 0-based sub-optimal alignment ending position on read.

Returns:

  • (Integer)

    0-based sub-optimal alignment ending position on read



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/ssw/align.rb', line 33

class Align
  def self.keys
    %i[score1 score2 ref_begin1 ref_end1
       read_begin1 read_end1 ref_end2 cigar cigar_len cigar_string]
  end

  # This class is read_only
  attr_reader(*keys)

  def initialize(ptr)
    @ptr          = ptr
    @cstruct      = align = FFI::Align.new(ptr)
    @score1       = align.score1
    @score2       = align.score2
    @ref_begin1   = align.ref_begin1
    @ref_end1     = align.ref_end1
    @read_begin1  = align.read_begin1
    @read_end1    = align.read_end1
    @ref_end2     = align.ref_end2
    @cigar_len    = align.cigarLen
    @cigar        = cigar_len.positive? ? align.cigar[0, 4 * cigar_len].unpack('L*') : []
    # Attributes for ruby binding only
    @cigar_string = array_to_cigar_string(@cigar)
    SSW.align_destroy(ptr)
  end

  def to_h
    self.class.keys.map { |k| [k, __send__(k)] }.to_h
  end

  private

  def array_to_cigar_string(arr)
    cigar_string = String.new
    arr.each do |x|
      n = x >> 4
      m = x & 15
      c = m > 8 ? 'M' : 'MIDNSHP=X'[m]
      cigar_string << n.to_s << c
    end
    cigar_string
  end
end

#ref_begin1Integer

Returns 0-based best alignment beginning position on reference; ref_begin1 = -1 when the best alignment beginning position is not available.

Returns:

  • (Integer)

    0-based best alignment beginning position on reference; ref_begin1 = -1 when the best alignment beginning position is not available



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/ssw/align.rb', line 33

class Align
  def self.keys
    %i[score1 score2 ref_begin1 ref_end1
       read_begin1 read_end1 ref_end2 cigar cigar_len cigar_string]
  end

  # This class is read_only
  attr_reader(*keys)

  def initialize(ptr)
    @ptr          = ptr
    @cstruct      = align = FFI::Align.new(ptr)
    @score1       = align.score1
    @score2       = align.score2
    @ref_begin1   = align.ref_begin1
    @ref_end1     = align.ref_end1
    @read_begin1  = align.read_begin1
    @read_end1    = align.read_end1
    @ref_end2     = align.ref_end2
    @cigar_len    = align.cigarLen
    @cigar        = cigar_len.positive? ? align.cigar[0, 4 * cigar_len].unpack('L*') : []
    # Attributes for ruby binding only
    @cigar_string = array_to_cigar_string(@cigar)
    SSW.align_destroy(ptr)
  end

  def to_h
    self.class.keys.map { |k| [k, __send__(k)] }.to_h
  end

  private

  def array_to_cigar_string(arr)
    cigar_string = String.new
    arr.each do |x|
      n = x >> 4
      m = x & 15
      c = m > 8 ? 'M' : 'MIDNSHP=X'[m]
      cigar_string << n.to_s << c
    end
    cigar_string
  end
end

#ref_end1Integer

Returns 0-based best alignment ending position on reference.

Returns:

  • (Integer)

    0-based best alignment ending position on reference



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/ssw/align.rb', line 33

class Align
  def self.keys
    %i[score1 score2 ref_begin1 ref_end1
       read_begin1 read_end1 ref_end2 cigar cigar_len cigar_string]
  end

  # This class is read_only
  attr_reader(*keys)

  def initialize(ptr)
    @ptr          = ptr
    @cstruct      = align = FFI::Align.new(ptr)
    @score1       = align.score1
    @score2       = align.score2
    @ref_begin1   = align.ref_begin1
    @ref_end1     = align.ref_end1
    @read_begin1  = align.read_begin1
    @read_end1    = align.read_end1
    @ref_end2     = align.ref_end2
    @cigar_len    = align.cigarLen
    @cigar        = cigar_len.positive? ? align.cigar[0, 4 * cigar_len].unpack('L*') : []
    # Attributes for ruby binding only
    @cigar_string = array_to_cigar_string(@cigar)
    SSW.align_destroy(ptr)
  end

  def to_h
    self.class.keys.map { |k| [k, __send__(k)] }.to_h
  end

  private

  def array_to_cigar_string(arr)
    cigar_string = String.new
    arr.each do |x|
      n = x >> 4
      m = x & 15
      c = m > 8 ? 'M' : 'MIDNSHP=X'[m]
      cigar_string << n.to_s << c
    end
    cigar_string
  end
end

#score1Integer

Returns the best alignment score.

Returns:

  • (Integer)

    the best alignment score



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/ssw/align.rb', line 33

class Align
  def self.keys
    %i[score1 score2 ref_begin1 ref_end1
       read_begin1 read_end1 ref_end2 cigar cigar_len cigar_string]
  end

  # This class is read_only
  attr_reader(*keys)

  def initialize(ptr)
    @ptr          = ptr
    @cstruct      = align = FFI::Align.new(ptr)
    @score1       = align.score1
    @score2       = align.score2
    @ref_begin1   = align.ref_begin1
    @ref_end1     = align.ref_end1
    @read_begin1  = align.read_begin1
    @read_end1    = align.read_end1
    @ref_end2     = align.ref_end2
    @cigar_len    = align.cigarLen
    @cigar        = cigar_len.positive? ? align.cigar[0, 4 * cigar_len].unpack('L*') : []
    # Attributes for ruby binding only
    @cigar_string = array_to_cigar_string(@cigar)
    SSW.align_destroy(ptr)
  end

  def to_h
    self.class.keys.map { |k| [k, __send__(k)] }.to_h
  end

  private

  def array_to_cigar_string(arr)
    cigar_string = String.new
    arr.each do |x|
      n = x >> 4
      m = x & 15
      c = m > 8 ? 'M' : 'MIDNSHP=X'[m]
      cigar_string << n.to_s << c
    end
    cigar_string
  end
end

#score2Integer

Returns sub-optimal alignment score.

Returns:

  • (Integer)

    sub-optimal alignment score



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/ssw/align.rb', line 33

class Align
  def self.keys
    %i[score1 score2 ref_begin1 ref_end1
       read_begin1 read_end1 ref_end2 cigar cigar_len cigar_string]
  end

  # This class is read_only
  attr_reader(*keys)

  def initialize(ptr)
    @ptr          = ptr
    @cstruct      = align = FFI::Align.new(ptr)
    @score1       = align.score1
    @score2       = align.score2
    @ref_begin1   = align.ref_begin1
    @ref_end1     = align.ref_end1
    @read_begin1  = align.read_begin1
    @read_end1    = align.read_end1
    @ref_end2     = align.ref_end2
    @cigar_len    = align.cigarLen
    @cigar        = cigar_len.positive? ? align.cigar[0, 4 * cigar_len].unpack('L*') : []
    # Attributes for ruby binding only
    @cigar_string = array_to_cigar_string(@cigar)
    SSW.align_destroy(ptr)
  end

  def to_h
    self.class.keys.map { |k| [k, __send__(k)] }.to_h
  end

  private

  def array_to_cigar_string(arr)
    cigar_string = String.new
    arr.each do |x|
      n = x >> 4
      m = x & 15
      c = m > 8 ? 'M' : 'MIDNSHP=X'[m]
      cigar_string << n.to_s << c
    end
    cigar_string
  end
end

Class Method Details

.keysObject



34
35
36
37
# File 'lib/ssw/align.rb', line 34

def self.keys
  %i[score1 score2 ref_begin1 ref_end1
     read_begin1 read_end1 ref_end2 cigar cigar_len cigar_string]
end

Instance Method Details

#to_hObject



59
60
61
# File 'lib/ssw/align.rb', line 59

def to_h
  self.class.keys.map { |k| [k, __send__(k)] }.to_h
end