Class: Minimap2::Alignment

Inherits:
Object
  • Object
show all
Defined in:
lib/minimap2/alignment.rb

Overview

Alignment result.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(h, cigar, cs = nil, md = nil) ⇒ Alignment

Returns a new instance of Alignment.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/minimap2/alignment.rb', line 57

def initialize(h, cigar, cs = nil, md = nil)
  @ctg          = h[:ctg]
  @ctg_len      = h[:ctg_len]
  @r_st         = h[:ctg_start]
  @r_en         = h[:ctg_end]
  @strand       = h[:strand]
  @trans_strand = h[:trans_strand]
  @blen         = h[:blen]
  @mlen         = h[:mlen]
  @nm           = h[:NM]
  @primary      = h[:is_primary]
  @q_st         = h[:qry_start]
  @q_en         = h[:qry_end]
  @mapq         = h[:mapq]
  @cigar        = cigar
  @read_num     = h[:seg_id] + 1
  @cs           = cs
  @md           = md

  @cigar_str = cigar.map { |x| x[0].to_s + FFI::CIGAR_STR[x[1]] }.join
end

Instance Attribute Details

#blenInteger

Returns length of the alignment, including both alignment matches and gaps but excluding ambiguous bases.

Returns:

  • (Integer)

    length of the alignment, including both alignment matches and gaps but excluding ambiguous bases.



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
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
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/minimap2/alignment.rb', line 49

class Alignment
  def self.keys
    %i[ctg ctg_len r_st r_en strand trans_strand blen mlen nm primary
       q_st q_en mapq cigar read_num cs md cigar_str]
  end

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, md = nil)
    @ctg          = h[:ctg]
    @ctg_len      = h[:ctg_len]
    @r_st         = h[:ctg_start]
    @r_en         = h[:ctg_end]
    @strand       = h[:strand]
    @trans_strand = h[:trans_strand]
    @blen         = h[:blen]
    @mlen         = h[:mlen]
    @nm           = h[:NM]
    @primary      = h[:is_primary]
    @q_st         = h[:qry_start]
    @q_en         = h[:qry_end]
    @mapq         = h[:mapq]
    @cigar        = cigar
    @read_num     = h[:seg_id] + 1
    @cs           = cs
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + FFI::CIGAR_STR[x[1]] }.join
  end

  def primary?
    @primary == 1
  end

  # Convert Alignment to hash.

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

  # Convert to the PAF format without the QueryName and QueryLength columns.

  def to_s
    strand = if @strand > 0
               "+"
             elsif @strand < 0
               "-"
             else
               "?"
             end
    tp = @primary != 0 ? "tp:A:P" : "tp:A:S"
    ts = if @trans_strand > 0
           "ts:A:+"
         elsif @trans_strand < 0
           "ts:A:-"
         else
           "ts:A:."
         end
    a = [@q_st, @q_en, strand, @ctg, @ctg_len, @r_st, @r_en,
         @mlen, @blen, @mapq, tp, ts, "cg:Z:#{@cigar_str}"]
    a << "cs:Z:#{@cs}" if @cs
    a << "MD:Z:#{@md}" if @md
    a.join("\t")
  end
end

#cigarArray

Returns CIGAR returned as an array of shape (n_cigar,2). The two numbers give the length and the operator of each CIGAR operation.

Returns:

  • (Array)

    CIGAR returned as an array of shape (n_cigar,2). The two numbers give the length and the operator of each CIGAR operation.



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
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
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/minimap2/alignment.rb', line 49

class Alignment
  def self.keys
    %i[ctg ctg_len r_st r_en strand trans_strand blen mlen nm primary
       q_st q_en mapq cigar read_num cs md cigar_str]
  end

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, md = nil)
    @ctg          = h[:ctg]
    @ctg_len      = h[:ctg_len]
    @r_st         = h[:ctg_start]
    @r_en         = h[:ctg_end]
    @strand       = h[:strand]
    @trans_strand = h[:trans_strand]
    @blen         = h[:blen]
    @mlen         = h[:mlen]
    @nm           = h[:NM]
    @primary      = h[:is_primary]
    @q_st         = h[:qry_start]
    @q_en         = h[:qry_end]
    @mapq         = h[:mapq]
    @cigar        = cigar
    @read_num     = h[:seg_id] + 1
    @cs           = cs
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + FFI::CIGAR_STR[x[1]] }.join
  end

  def primary?
    @primary == 1
  end

  # Convert Alignment to hash.

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

  # Convert to the PAF format without the QueryName and QueryLength columns.

  def to_s
    strand = if @strand > 0
               "+"
             elsif @strand < 0
               "-"
             else
               "?"
             end
    tp = @primary != 0 ? "tp:A:P" : "tp:A:S"
    ts = if @trans_strand > 0
           "ts:A:+"
         elsif @trans_strand < 0
           "ts:A:-"
         else
           "ts:A:."
         end
    a = [@q_st, @q_en, strand, @ctg, @ctg_len, @r_st, @r_en,
         @mlen, @blen, @mapq, tp, ts, "cg:Z:#{@cigar_str}"]
    a << "cs:Z:#{@cs}" if @cs
    a << "MD:Z:#{@md}" if @md
    a.join("\t")
  end
end

#cigar_strString

Returns CIGAR string.

Returns:

  • (String)

    CIGAR string.



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
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
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/minimap2/alignment.rb', line 49

class Alignment
  def self.keys
    %i[ctg ctg_len r_st r_en strand trans_strand blen mlen nm primary
       q_st q_en mapq cigar read_num cs md cigar_str]
  end

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, md = nil)
    @ctg          = h[:ctg]
    @ctg_len      = h[:ctg_len]
    @r_st         = h[:ctg_start]
    @r_en         = h[:ctg_end]
    @strand       = h[:strand]
    @trans_strand = h[:trans_strand]
    @blen         = h[:blen]
    @mlen         = h[:mlen]
    @nm           = h[:NM]
    @primary      = h[:is_primary]
    @q_st         = h[:qry_start]
    @q_en         = h[:qry_end]
    @mapq         = h[:mapq]
    @cigar        = cigar
    @read_num     = h[:seg_id] + 1
    @cs           = cs
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + FFI::CIGAR_STR[x[1]] }.join
  end

  def primary?
    @primary == 1
  end

  # Convert Alignment to hash.

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

  # Convert to the PAF format without the QueryName and QueryLength columns.

  def to_s
    strand = if @strand > 0
               "+"
             elsif @strand < 0
               "-"
             else
               "?"
             end
    tp = @primary != 0 ? "tp:A:P" : "tp:A:S"
    ts = if @trans_strand > 0
           "ts:A:+"
         elsif @trans_strand < 0
           "ts:A:-"
         else
           "ts:A:."
         end
    a = [@q_st, @q_en, strand, @ctg, @ctg_len, @r_st, @r_en,
         @mlen, @blen, @mapq, tp, ts, "cg:Z:#{@cigar_str}"]
    a << "cs:Z:#{@cs}" if @cs
    a << "MD:Z:#{@md}" if @md
    a.join("\t")
  end
end

#csString

Returns the cs tag.

Returns:

  • (String)

    the cs tag.



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
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
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/minimap2/alignment.rb', line 49

class Alignment
  def self.keys
    %i[ctg ctg_len r_st r_en strand trans_strand blen mlen nm primary
       q_st q_en mapq cigar read_num cs md cigar_str]
  end

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, md = nil)
    @ctg          = h[:ctg]
    @ctg_len      = h[:ctg_len]
    @r_st         = h[:ctg_start]
    @r_en         = h[:ctg_end]
    @strand       = h[:strand]
    @trans_strand = h[:trans_strand]
    @blen         = h[:blen]
    @mlen         = h[:mlen]
    @nm           = h[:NM]
    @primary      = h[:is_primary]
    @q_st         = h[:qry_start]
    @q_en         = h[:qry_end]
    @mapq         = h[:mapq]
    @cigar        = cigar
    @read_num     = h[:seg_id] + 1
    @cs           = cs
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + FFI::CIGAR_STR[x[1]] }.join
  end

  def primary?
    @primary == 1
  end

  # Convert Alignment to hash.

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

  # Convert to the PAF format without the QueryName and QueryLength columns.

  def to_s
    strand = if @strand > 0
               "+"
             elsif @strand < 0
               "-"
             else
               "?"
             end
    tp = @primary != 0 ? "tp:A:P" : "tp:A:S"
    ts = if @trans_strand > 0
           "ts:A:+"
         elsif @trans_strand < 0
           "ts:A:-"
         else
           "ts:A:."
         end
    a = [@q_st, @q_en, strand, @ctg, @ctg_len, @r_st, @r_en,
         @mlen, @blen, @mapq, tp, ts, "cg:Z:#{@cigar_str}"]
    a << "cs:Z:#{@cs}" if @cs
    a << "MD:Z:#{@md}" if @md
    a.join("\t")
  end
end

#ctgString

Returns name of the reference sequence the query is mapped to.

Returns:

  • (String)

    name of the reference sequence the query is mapped to.



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
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
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/minimap2/alignment.rb', line 49

class Alignment
  def self.keys
    %i[ctg ctg_len r_st r_en strand trans_strand blen mlen nm primary
       q_st q_en mapq cigar read_num cs md cigar_str]
  end

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, md = nil)
    @ctg          = h[:ctg]
    @ctg_len      = h[:ctg_len]
    @r_st         = h[:ctg_start]
    @r_en         = h[:ctg_end]
    @strand       = h[:strand]
    @trans_strand = h[:trans_strand]
    @blen         = h[:blen]
    @mlen         = h[:mlen]
    @nm           = h[:NM]
    @primary      = h[:is_primary]
    @q_st         = h[:qry_start]
    @q_en         = h[:qry_end]
    @mapq         = h[:mapq]
    @cigar        = cigar
    @read_num     = h[:seg_id] + 1
    @cs           = cs
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + FFI::CIGAR_STR[x[1]] }.join
  end

  def primary?
    @primary == 1
  end

  # Convert Alignment to hash.

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

  # Convert to the PAF format without the QueryName and QueryLength columns.

  def to_s
    strand = if @strand > 0
               "+"
             elsif @strand < 0
               "-"
             else
               "?"
             end
    tp = @primary != 0 ? "tp:A:P" : "tp:A:S"
    ts = if @trans_strand > 0
           "ts:A:+"
         elsif @trans_strand < 0
           "ts:A:-"
         else
           "ts:A:."
         end
    a = [@q_st, @q_en, strand, @ctg, @ctg_len, @r_st, @r_en,
         @mlen, @blen, @mapq, tp, ts, "cg:Z:#{@cigar_str}"]
    a << "cs:Z:#{@cs}" if @cs
    a << "MD:Z:#{@md}" if @md
    a.join("\t")
  end
end

#ctg_lenInteger

Returns total length of the reference sequence.

Returns:

  • (Integer)

    total length of the reference sequence.



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
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
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/minimap2/alignment.rb', line 49

class Alignment
  def self.keys
    %i[ctg ctg_len r_st r_en strand trans_strand blen mlen nm primary
       q_st q_en mapq cigar read_num cs md cigar_str]
  end

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, md = nil)
    @ctg          = h[:ctg]
    @ctg_len      = h[:ctg_len]
    @r_st         = h[:ctg_start]
    @r_en         = h[:ctg_end]
    @strand       = h[:strand]
    @trans_strand = h[:trans_strand]
    @blen         = h[:blen]
    @mlen         = h[:mlen]
    @nm           = h[:NM]
    @primary      = h[:is_primary]
    @q_st         = h[:qry_start]
    @q_en         = h[:qry_end]
    @mapq         = h[:mapq]
    @cigar        = cigar
    @read_num     = h[:seg_id] + 1
    @cs           = cs
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + FFI::CIGAR_STR[x[1]] }.join
  end

  def primary?
    @primary == 1
  end

  # Convert Alignment to hash.

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

  # Convert to the PAF format without the QueryName and QueryLength columns.

  def to_s
    strand = if @strand > 0
               "+"
             elsif @strand < 0
               "-"
             else
               "?"
             end
    tp = @primary != 0 ? "tp:A:P" : "tp:A:S"
    ts = if @trans_strand > 0
           "ts:A:+"
         elsif @trans_strand < 0
           "ts:A:-"
         else
           "ts:A:."
         end
    a = [@q_st, @q_en, strand, @ctg, @ctg_len, @r_st, @r_en,
         @mlen, @blen, @mapq, tp, ts, "cg:Z:#{@cigar_str}"]
    a << "cs:Z:#{@cs}" if @cs
    a << "MD:Z:#{@md}" if @md
    a.join("\t")
  end
end

#mapqInteger

Returns mapping quality.

Returns:

  • (Integer)

    mapping quality.



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
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
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/minimap2/alignment.rb', line 49

class Alignment
  def self.keys
    %i[ctg ctg_len r_st r_en strand trans_strand blen mlen nm primary
       q_st q_en mapq cigar read_num cs md cigar_str]
  end

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, md = nil)
    @ctg          = h[:ctg]
    @ctg_len      = h[:ctg_len]
    @r_st         = h[:ctg_start]
    @r_en         = h[:ctg_end]
    @strand       = h[:strand]
    @trans_strand = h[:trans_strand]
    @blen         = h[:blen]
    @mlen         = h[:mlen]
    @nm           = h[:NM]
    @primary      = h[:is_primary]
    @q_st         = h[:qry_start]
    @q_en         = h[:qry_end]
    @mapq         = h[:mapq]
    @cigar        = cigar
    @read_num     = h[:seg_id] + 1
    @cs           = cs
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + FFI::CIGAR_STR[x[1]] }.join
  end

  def primary?
    @primary == 1
  end

  # Convert Alignment to hash.

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

  # Convert to the PAF format without the QueryName and QueryLength columns.

  def to_s
    strand = if @strand > 0
               "+"
             elsif @strand < 0
               "-"
             else
               "?"
             end
    tp = @primary != 0 ? "tp:A:P" : "tp:A:S"
    ts = if @trans_strand > 0
           "ts:A:+"
         elsif @trans_strand < 0
           "ts:A:-"
         else
           "ts:A:."
         end
    a = [@q_st, @q_en, strand, @ctg, @ctg_len, @r_st, @r_en,
         @mlen, @blen, @mapq, tp, ts, "cg:Z:#{@cigar_str}"]
    a << "cs:Z:#{@cs}" if @cs
    a << "MD:Z:#{@md}" if @md
    a.join("\t")
  end
end

#mdString

Returns the MD tag as in the SAM format. It is an empty string unless the md argument is applied when calling Aligner#align.

Returns:

  • (String)

    the MD tag as in the SAM format. It is an empty string unless the md argument is applied when calling Aligner#align.



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
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
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/minimap2/alignment.rb', line 49

class Alignment
  def self.keys
    %i[ctg ctg_len r_st r_en strand trans_strand blen mlen nm primary
       q_st q_en mapq cigar read_num cs md cigar_str]
  end

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, md = nil)
    @ctg          = h[:ctg]
    @ctg_len      = h[:ctg_len]
    @r_st         = h[:ctg_start]
    @r_en         = h[:ctg_end]
    @strand       = h[:strand]
    @trans_strand = h[:trans_strand]
    @blen         = h[:blen]
    @mlen         = h[:mlen]
    @nm           = h[:NM]
    @primary      = h[:is_primary]
    @q_st         = h[:qry_start]
    @q_en         = h[:qry_end]
    @mapq         = h[:mapq]
    @cigar        = cigar
    @read_num     = h[:seg_id] + 1
    @cs           = cs
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + FFI::CIGAR_STR[x[1]] }.join
  end

  def primary?
    @primary == 1
  end

  # Convert Alignment to hash.

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

  # Convert to the PAF format without the QueryName and QueryLength columns.

  def to_s
    strand = if @strand > 0
               "+"
             elsif @strand < 0
               "-"
             else
               "?"
             end
    tp = @primary != 0 ? "tp:A:P" : "tp:A:S"
    ts = if @trans_strand > 0
           "ts:A:+"
         elsif @trans_strand < 0
           "ts:A:-"
         else
           "ts:A:."
         end
    a = [@q_st, @q_en, strand, @ctg, @ctg_len, @r_st, @r_en,
         @mlen, @blen, @mapq, tp, ts, "cg:Z:#{@cigar_str}"]
    a << "cs:Z:#{@cs}" if @cs
    a << "MD:Z:#{@md}" if @md
    a.join("\t")
  end
end

#mlenInteger

Returns length of the matching bases in the alignment, excluding ambiguous base matches.

Returns:

  • (Integer)

    length of the matching bases in the alignment, excluding ambiguous base matches.



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
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
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/minimap2/alignment.rb', line 49

class Alignment
  def self.keys
    %i[ctg ctg_len r_st r_en strand trans_strand blen mlen nm primary
       q_st q_en mapq cigar read_num cs md cigar_str]
  end

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, md = nil)
    @ctg          = h[:ctg]
    @ctg_len      = h[:ctg_len]
    @r_st         = h[:ctg_start]
    @r_en         = h[:ctg_end]
    @strand       = h[:strand]
    @trans_strand = h[:trans_strand]
    @blen         = h[:blen]
    @mlen         = h[:mlen]
    @nm           = h[:NM]
    @primary      = h[:is_primary]
    @q_st         = h[:qry_start]
    @q_en         = h[:qry_end]
    @mapq         = h[:mapq]
    @cigar        = cigar
    @read_num     = h[:seg_id] + 1
    @cs           = cs
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + FFI::CIGAR_STR[x[1]] }.join
  end

  def primary?
    @primary == 1
  end

  # Convert Alignment to hash.

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

  # Convert to the PAF format without the QueryName and QueryLength columns.

  def to_s
    strand = if @strand > 0
               "+"
             elsif @strand < 0
               "-"
             else
               "?"
             end
    tp = @primary != 0 ? "tp:A:P" : "tp:A:S"
    ts = if @trans_strand > 0
           "ts:A:+"
         elsif @trans_strand < 0
           "ts:A:-"
         else
           "ts:A:."
         end
    a = [@q_st, @q_en, strand, @ctg, @ctg_len, @r_st, @r_en,
         @mlen, @blen, @mapq, tp, ts, "cg:Z:#{@cigar_str}"]
    a << "cs:Z:#{@cs}" if @cs
    a << "MD:Z:#{@md}" if @md
    a.join("\t")
  end
end

#nmInteger

Returns number of mismatches, gaps and ambiguous positions in the alignment.

Returns:

  • (Integer)

    number of mismatches, gaps and ambiguous positions in the alignment.



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
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
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/minimap2/alignment.rb', line 49

class Alignment
  def self.keys
    %i[ctg ctg_len r_st r_en strand trans_strand blen mlen nm primary
       q_st q_en mapq cigar read_num cs md cigar_str]
  end

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, md = nil)
    @ctg          = h[:ctg]
    @ctg_len      = h[:ctg_len]
    @r_st         = h[:ctg_start]
    @r_en         = h[:ctg_end]
    @strand       = h[:strand]
    @trans_strand = h[:trans_strand]
    @blen         = h[:blen]
    @mlen         = h[:mlen]
    @nm           = h[:NM]
    @primary      = h[:is_primary]
    @q_st         = h[:qry_start]
    @q_en         = h[:qry_end]
    @mapq         = h[:mapq]
    @cigar        = cigar
    @read_num     = h[:seg_id] + 1
    @cs           = cs
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + FFI::CIGAR_STR[x[1]] }.join
  end

  def primary?
    @primary == 1
  end

  # Convert Alignment to hash.

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

  # Convert to the PAF format without the QueryName and QueryLength columns.

  def to_s
    strand = if @strand > 0
               "+"
             elsif @strand < 0
               "-"
             else
               "?"
             end
    tp = @primary != 0 ? "tp:A:P" : "tp:A:S"
    ts = if @trans_strand > 0
           "ts:A:+"
         elsif @trans_strand < 0
           "ts:A:-"
         else
           "ts:A:."
         end
    a = [@q_st, @q_en, strand, @ctg, @ctg_len, @r_st, @r_en,
         @mlen, @blen, @mapq, tp, ts, "cg:Z:#{@cigar_str}"]
    a << "cs:Z:#{@cs}" if @cs
    a << "MD:Z:#{@md}" if @md
    a.join("\t")
  end
end

#primaryInteger

Returns if the alignment is primary (typically the best and the first to generate).

Returns:

  • (Integer)

    if the alignment is primary (typically the best and the first to generate)



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
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
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/minimap2/alignment.rb', line 49

class Alignment
  def self.keys
    %i[ctg ctg_len r_st r_en strand trans_strand blen mlen nm primary
       q_st q_en mapq cigar read_num cs md cigar_str]
  end

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, md = nil)
    @ctg          = h[:ctg]
    @ctg_len      = h[:ctg_len]
    @r_st         = h[:ctg_start]
    @r_en         = h[:ctg_end]
    @strand       = h[:strand]
    @trans_strand = h[:trans_strand]
    @blen         = h[:blen]
    @mlen         = h[:mlen]
    @nm           = h[:NM]
    @primary      = h[:is_primary]
    @q_st         = h[:qry_start]
    @q_en         = h[:qry_end]
    @mapq         = h[:mapq]
    @cigar        = cigar
    @read_num     = h[:seg_id] + 1
    @cs           = cs
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + FFI::CIGAR_STR[x[1]] }.join
  end

  def primary?
    @primary == 1
  end

  # Convert Alignment to hash.

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

  # Convert to the PAF format without the QueryName and QueryLength columns.

  def to_s
    strand = if @strand > 0
               "+"
             elsif @strand < 0
               "-"
             else
               "?"
             end
    tp = @primary != 0 ? "tp:A:P" : "tp:A:S"
    ts = if @trans_strand > 0
           "ts:A:+"
         elsif @trans_strand < 0
           "ts:A:-"
         else
           "ts:A:."
         end
    a = [@q_st, @q_en, strand, @ctg, @ctg_len, @r_st, @r_en,
         @mlen, @blen, @mapq, tp, ts, "cg:Z:#{@cigar_str}"]
    a << "cs:Z:#{@cs}" if @cs
    a << "MD:Z:#{@md}" if @md
    a.join("\t")
  end
end

#q_enInteger

Returns end positions on the query.

Returns:

  • (Integer)

    end positions on the query.



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
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
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/minimap2/alignment.rb', line 49

class Alignment
  def self.keys
    %i[ctg ctg_len r_st r_en strand trans_strand blen mlen nm primary
       q_st q_en mapq cigar read_num cs md cigar_str]
  end

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, md = nil)
    @ctg          = h[:ctg]
    @ctg_len      = h[:ctg_len]
    @r_st         = h[:ctg_start]
    @r_en         = h[:ctg_end]
    @strand       = h[:strand]
    @trans_strand = h[:trans_strand]
    @blen         = h[:blen]
    @mlen         = h[:mlen]
    @nm           = h[:NM]
    @primary      = h[:is_primary]
    @q_st         = h[:qry_start]
    @q_en         = h[:qry_end]
    @mapq         = h[:mapq]
    @cigar        = cigar
    @read_num     = h[:seg_id] + 1
    @cs           = cs
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + FFI::CIGAR_STR[x[1]] }.join
  end

  def primary?
    @primary == 1
  end

  # Convert Alignment to hash.

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

  # Convert to the PAF format without the QueryName and QueryLength columns.

  def to_s
    strand = if @strand > 0
               "+"
             elsif @strand < 0
               "-"
             else
               "?"
             end
    tp = @primary != 0 ? "tp:A:P" : "tp:A:S"
    ts = if @trans_strand > 0
           "ts:A:+"
         elsif @trans_strand < 0
           "ts:A:-"
         else
           "ts:A:."
         end
    a = [@q_st, @q_en, strand, @ctg, @ctg_len, @r_st, @r_en,
         @mlen, @blen, @mapq, tp, ts, "cg:Z:#{@cigar_str}"]
    a << "cs:Z:#{@cs}" if @cs
    a << "MD:Z:#{@md}" if @md
    a.join("\t")
  end
end

#q_stInteger

Returns start positions on the query.

Returns:

  • (Integer)

    start positions on the query.



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
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
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/minimap2/alignment.rb', line 49

class Alignment
  def self.keys
    %i[ctg ctg_len r_st r_en strand trans_strand blen mlen nm primary
       q_st q_en mapq cigar read_num cs md cigar_str]
  end

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, md = nil)
    @ctg          = h[:ctg]
    @ctg_len      = h[:ctg_len]
    @r_st         = h[:ctg_start]
    @r_en         = h[:ctg_end]
    @strand       = h[:strand]
    @trans_strand = h[:trans_strand]
    @blen         = h[:blen]
    @mlen         = h[:mlen]
    @nm           = h[:NM]
    @primary      = h[:is_primary]
    @q_st         = h[:qry_start]
    @q_en         = h[:qry_end]
    @mapq         = h[:mapq]
    @cigar        = cigar
    @read_num     = h[:seg_id] + 1
    @cs           = cs
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + FFI::CIGAR_STR[x[1]] }.join
  end

  def primary?
    @primary == 1
  end

  # Convert Alignment to hash.

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

  # Convert to the PAF format without the QueryName and QueryLength columns.

  def to_s
    strand = if @strand > 0
               "+"
             elsif @strand < 0
               "-"
             else
               "?"
             end
    tp = @primary != 0 ? "tp:A:P" : "tp:A:S"
    ts = if @trans_strand > 0
           "ts:A:+"
         elsif @trans_strand < 0
           "ts:A:-"
         else
           "ts:A:."
         end
    a = [@q_st, @q_en, strand, @ctg, @ctg_len, @r_st, @r_en,
         @mlen, @blen, @mapq, tp, ts, "cg:Z:#{@cigar_str}"]
    a << "cs:Z:#{@cs}" if @cs
    a << "MD:Z:#{@md}" if @md
    a.join("\t")
  end
end

#r_enInteger

Returns end positions on the reference.

Returns:

  • (Integer)

    end positions on the reference.



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
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
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/minimap2/alignment.rb', line 49

class Alignment
  def self.keys
    %i[ctg ctg_len r_st r_en strand trans_strand blen mlen nm primary
       q_st q_en mapq cigar read_num cs md cigar_str]
  end

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, md = nil)
    @ctg          = h[:ctg]
    @ctg_len      = h[:ctg_len]
    @r_st         = h[:ctg_start]
    @r_en         = h[:ctg_end]
    @strand       = h[:strand]
    @trans_strand = h[:trans_strand]
    @blen         = h[:blen]
    @mlen         = h[:mlen]
    @nm           = h[:NM]
    @primary      = h[:is_primary]
    @q_st         = h[:qry_start]
    @q_en         = h[:qry_end]
    @mapq         = h[:mapq]
    @cigar        = cigar
    @read_num     = h[:seg_id] + 1
    @cs           = cs
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + FFI::CIGAR_STR[x[1]] }.join
  end

  def primary?
    @primary == 1
  end

  # Convert Alignment to hash.

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

  # Convert to the PAF format without the QueryName and QueryLength columns.

  def to_s
    strand = if @strand > 0
               "+"
             elsif @strand < 0
               "-"
             else
               "?"
             end
    tp = @primary != 0 ? "tp:A:P" : "tp:A:S"
    ts = if @trans_strand > 0
           "ts:A:+"
         elsif @trans_strand < 0
           "ts:A:-"
         else
           "ts:A:."
         end
    a = [@q_st, @q_en, strand, @ctg, @ctg_len, @r_st, @r_en,
         @mlen, @blen, @mapq, tp, ts, "cg:Z:#{@cigar_str}"]
    a << "cs:Z:#{@cs}" if @cs
    a << "MD:Z:#{@md}" if @md
    a.join("\t")
  end
end

#r_stInteger

Returns start positions on the reference.

Returns:

  • (Integer)

    start positions on the reference.



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
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
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/minimap2/alignment.rb', line 49

class Alignment
  def self.keys
    %i[ctg ctg_len r_st r_en strand trans_strand blen mlen nm primary
       q_st q_en mapq cigar read_num cs md cigar_str]
  end

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, md = nil)
    @ctg          = h[:ctg]
    @ctg_len      = h[:ctg_len]
    @r_st         = h[:ctg_start]
    @r_en         = h[:ctg_end]
    @strand       = h[:strand]
    @trans_strand = h[:trans_strand]
    @blen         = h[:blen]
    @mlen         = h[:mlen]
    @nm           = h[:NM]
    @primary      = h[:is_primary]
    @q_st         = h[:qry_start]
    @q_en         = h[:qry_end]
    @mapq         = h[:mapq]
    @cigar        = cigar
    @read_num     = h[:seg_id] + 1
    @cs           = cs
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + FFI::CIGAR_STR[x[1]] }.join
  end

  def primary?
    @primary == 1
  end

  # Convert Alignment to hash.

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

  # Convert to the PAF format without the QueryName and QueryLength columns.

  def to_s
    strand = if @strand > 0
               "+"
             elsif @strand < 0
               "-"
             else
               "?"
             end
    tp = @primary != 0 ? "tp:A:P" : "tp:A:S"
    ts = if @trans_strand > 0
           "ts:A:+"
         elsif @trans_strand < 0
           "ts:A:-"
         else
           "ts:A:."
         end
    a = [@q_st, @q_en, strand, @ctg, @ctg_len, @r_st, @r_en,
         @mlen, @blen, @mapq, tp, ts, "cg:Z:#{@cigar_str}"]
    a << "cs:Z:#{@cs}" if @cs
    a << "MD:Z:#{@md}" if @md
    a.join("\t")
  end
end

#read_numInteger

Returns read number that the alignment corresponds to; 1 for the first read and 2 for the second read.

Returns:

  • (Integer)

    read number that the alignment corresponds to; 1 for the first read and 2 for the second read.



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
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
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/minimap2/alignment.rb', line 49

class Alignment
  def self.keys
    %i[ctg ctg_len r_st r_en strand trans_strand blen mlen nm primary
       q_st q_en mapq cigar read_num cs md cigar_str]
  end

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, md = nil)
    @ctg          = h[:ctg]
    @ctg_len      = h[:ctg_len]
    @r_st         = h[:ctg_start]
    @r_en         = h[:ctg_end]
    @strand       = h[:strand]
    @trans_strand = h[:trans_strand]
    @blen         = h[:blen]
    @mlen         = h[:mlen]
    @nm           = h[:NM]
    @primary      = h[:is_primary]
    @q_st         = h[:qry_start]
    @q_en         = h[:qry_end]
    @mapq         = h[:mapq]
    @cigar        = cigar
    @read_num     = h[:seg_id] + 1
    @cs           = cs
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + FFI::CIGAR_STR[x[1]] }.join
  end

  def primary?
    @primary == 1
  end

  # Convert Alignment to hash.

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

  # Convert to the PAF format without the QueryName and QueryLength columns.

  def to_s
    strand = if @strand > 0
               "+"
             elsif @strand < 0
               "-"
             else
               "?"
             end
    tp = @primary != 0 ? "tp:A:P" : "tp:A:S"
    ts = if @trans_strand > 0
           "ts:A:+"
         elsif @trans_strand < 0
           "ts:A:-"
         else
           "ts:A:."
         end
    a = [@q_st, @q_en, strand, @ctg, @ctg_len, @r_st, @r_en,
         @mlen, @blen, @mapq, tp, ts, "cg:Z:#{@cigar_str}"]
    a << "cs:Z:#{@cs}" if @cs
    a << "MD:Z:#{@md}" if @md
    a.join("\t")
  end
end

#strandInteger

Returns +1 if on the forward strand; -1 if on the reverse strand.

Returns:

  • (Integer)

    +1 if on the forward strand; -1 if on the reverse strand.



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
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
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/minimap2/alignment.rb', line 49

class Alignment
  def self.keys
    %i[ctg ctg_len r_st r_en strand trans_strand blen mlen nm primary
       q_st q_en mapq cigar read_num cs md cigar_str]
  end

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, md = nil)
    @ctg          = h[:ctg]
    @ctg_len      = h[:ctg_len]
    @r_st         = h[:ctg_start]
    @r_en         = h[:ctg_end]
    @strand       = h[:strand]
    @trans_strand = h[:trans_strand]
    @blen         = h[:blen]
    @mlen         = h[:mlen]
    @nm           = h[:NM]
    @primary      = h[:is_primary]
    @q_st         = h[:qry_start]
    @q_en         = h[:qry_end]
    @mapq         = h[:mapq]
    @cigar        = cigar
    @read_num     = h[:seg_id] + 1
    @cs           = cs
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + FFI::CIGAR_STR[x[1]] }.join
  end

  def primary?
    @primary == 1
  end

  # Convert Alignment to hash.

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

  # Convert to the PAF format without the QueryName and QueryLength columns.

  def to_s
    strand = if @strand > 0
               "+"
             elsif @strand < 0
               "-"
             else
               "?"
             end
    tp = @primary != 0 ? "tp:A:P" : "tp:A:S"
    ts = if @trans_strand > 0
           "ts:A:+"
         elsif @trans_strand < 0
           "ts:A:-"
         else
           "ts:A:."
         end
    a = [@q_st, @q_en, strand, @ctg, @ctg_len, @r_st, @r_en,
         @mlen, @blen, @mapq, tp, ts, "cg:Z:#{@cigar_str}"]
    a << "cs:Z:#{@cs}" if @cs
    a << "MD:Z:#{@md}" if @md
    a.join("\t")
  end
end

#trans_strandInteger

Returns transcript strand. +1 if on the forward strand; -1 if on the reverse strand; 0 if unknown.

Returns:

  • (Integer)

    transcript strand. +1 if on the forward strand; -1 if on the reverse strand; 0 if unknown.



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
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
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/minimap2/alignment.rb', line 49

class Alignment
  def self.keys
    %i[ctg ctg_len r_st r_en strand trans_strand blen mlen nm primary
       q_st q_en mapq cigar read_num cs md cigar_str]
  end

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, md = nil)
    @ctg          = h[:ctg]
    @ctg_len      = h[:ctg_len]
    @r_st         = h[:ctg_start]
    @r_en         = h[:ctg_end]
    @strand       = h[:strand]
    @trans_strand = h[:trans_strand]
    @blen         = h[:blen]
    @mlen         = h[:mlen]
    @nm           = h[:NM]
    @primary      = h[:is_primary]
    @q_st         = h[:qry_start]
    @q_en         = h[:qry_end]
    @mapq         = h[:mapq]
    @cigar        = cigar
    @read_num     = h[:seg_id] + 1
    @cs           = cs
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + FFI::CIGAR_STR[x[1]] }.join
  end

  def primary?
    @primary == 1
  end

  # Convert Alignment to hash.

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

  # Convert to the PAF format without the QueryName and QueryLength columns.

  def to_s
    strand = if @strand > 0
               "+"
             elsif @strand < 0
               "-"
             else
               "?"
             end
    tp = @primary != 0 ? "tp:A:P" : "tp:A:S"
    ts = if @trans_strand > 0
           "ts:A:+"
         elsif @trans_strand < 0
           "ts:A:-"
         else
           "ts:A:."
         end
    a = [@q_st, @q_en, strand, @ctg, @ctg_len, @r_st, @r_en,
         @mlen, @blen, @mapq, tp, ts, "cg:Z:#{@cigar_str}"]
    a << "cs:Z:#{@cs}" if @cs
    a << "MD:Z:#{@md}" if @md
    a.join("\t")
  end
end

Class Method Details

.keysObject



50
51
52
53
# File 'lib/minimap2/alignment.rb', line 50

def self.keys
  %i[ctg ctg_len r_st r_en strand trans_strand blen mlen nm primary
     q_st q_en mapq cigar read_num cs md cigar_str]
end

Instance Method Details

#primary?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/minimap2/alignment.rb', line 79

def primary?
  @primary == 1
end

#to_hObject

Convert Alignment to hash.



85
86
87
# File 'lib/minimap2/alignment.rb', line 85

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

#to_sObject

Convert to the PAF format without the QueryName and QueryLength columns.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/minimap2/alignment.rb', line 91

def to_s
  strand = if @strand > 0
             "+"
           elsif @strand < 0
             "-"
           else
             "?"
           end
  tp = @primary != 0 ? "tp:A:P" : "tp:A:S"
  ts = if @trans_strand > 0
         "ts:A:+"
       elsif @trans_strand < 0
         "ts:A:-"
       else
         "ts:A:."
       end
  a = [@q_st, @q_en, strand, @ctg, @ctg_len, @r_st, @r_en,
       @mlen, @blen, @mapq, tp, ts, "cg:Z:#{@cigar_str}"]
  a << "cs:Z:#{@cs}" if @cs
  a << "MD:Z:#{@md}" if @md
  a.join("\t")
end