Class: Minimap2::Alignment

Inherits:
Object
  • Object
show all
Defined in:
lib/minimap2/alignment.rb,
ext/ruby_minimap2/ruby_minimap2.c

Overview

Alignment result.

Constant Summary collapse

CIGAR_STR =
"MIDNSHP=XB"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Alignment.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/minimap2/alignment.rb', line 64

def initialize(h, cigar, cs = nil, ds = nil, md = nil)
  @qname        = h[:qname]
  @qlen         = h[:qlen]
  @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
  @ds           = ds
  @md           = md

  @cigar_str = cigar.map { |x| x[0].to_s + 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.



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
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/minimap2/alignment.rb', line 54

class Alignment
  CIGAR_STR = "MIDNSHP=XB"

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

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, ds = nil, md = nil)
    @qname        = h[:qname]
    @qlen         = h[:qlen]
    @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
    @ds           = ds
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + 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.

  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 = [@qname, @qlen, @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}" unless @cs.nil? || @cs.empty?
    a << "ds:Z:#{@ds}" unless @ds.nil? || @ds.empty?
    a << "MD:Z:#{@md}" unless @md.nil? || @md.empty?
    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.



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
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/minimap2/alignment.rb', line 54

class Alignment
  CIGAR_STR = "MIDNSHP=XB"

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

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, ds = nil, md = nil)
    @qname        = h[:qname]
    @qlen         = h[:qlen]
    @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
    @ds           = ds
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + 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.

  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 = [@qname, @qlen, @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}" unless @cs.nil? || @cs.empty?
    a << "ds:Z:#{@ds}" unless @ds.nil? || @ds.empty?
    a << "MD:Z:#{@md}" unless @md.nil? || @md.empty?
    a.join("\t")
  end
end

#cigar_strString

Returns CIGAR string.

Returns:

  • (String)

    CIGAR string.



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
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/minimap2/alignment.rb', line 54

class Alignment
  CIGAR_STR = "MIDNSHP=XB"

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

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, ds = nil, md = nil)
    @qname        = h[:qname]
    @qlen         = h[:qlen]
    @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
    @ds           = ds
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + 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.

  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 = [@qname, @qlen, @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}" unless @cs.nil? || @cs.empty?
    a << "ds:Z:#{@ds}" unless @ds.nil? || @ds.empty?
    a << "MD:Z:#{@md}" unless @md.nil? || @md.empty?
    a.join("\t")
  end
end

#csString?

Returns the cs tag.

Returns:

  • (String, nil)

    the cs tag.



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
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/minimap2/alignment.rb', line 54

class Alignment
  CIGAR_STR = "MIDNSHP=XB"

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

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, ds = nil, md = nil)
    @qname        = h[:qname]
    @qlen         = h[:qlen]
    @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
    @ds           = ds
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + 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.

  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 = [@qname, @qlen, @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}" unless @cs.nil? || @cs.empty?
    a << "ds:Z:#{@ds}" unless @ds.nil? || @ds.empty?
    a << "MD:Z:#{@md}" unless @md.nil? || @md.empty?
    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.



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
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/minimap2/alignment.rb', line 54

class Alignment
  CIGAR_STR = "MIDNSHP=XB"

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

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, ds = nil, md = nil)
    @qname        = h[:qname]
    @qlen         = h[:qlen]
    @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
    @ds           = ds
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + 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.

  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 = [@qname, @qlen, @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}" unless @cs.nil? || @cs.empty?
    a << "ds:Z:#{@ds}" unless @ds.nil? || @ds.empty?
    a << "MD:Z:#{@md}" unless @md.nil? || @md.empty?
    a.join("\t")
  end
end

#ctg_lenInteger

Returns total length of the reference sequence.

Returns:

  • (Integer)

    total length of the reference sequence.



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
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/minimap2/alignment.rb', line 54

class Alignment
  CIGAR_STR = "MIDNSHP=XB"

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

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, ds = nil, md = nil)
    @qname        = h[:qname]
    @qlen         = h[:qlen]
    @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
    @ds           = ds
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + 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.

  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 = [@qname, @qlen, @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}" unless @cs.nil? || @cs.empty?
    a << "ds:Z:#{@ds}" unless @ds.nil? || @ds.empty?
    a << "MD:Z:#{@md}" unless @md.nil? || @md.empty?
    a.join("\t")
  end
end

#dsString?

Returns the ds tag.

Returns:

  • (String, nil)

    the ds tag.



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
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/minimap2/alignment.rb', line 54

class Alignment
  CIGAR_STR = "MIDNSHP=XB"

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

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, ds = nil, md = nil)
    @qname        = h[:qname]
    @qlen         = h[:qlen]
    @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
    @ds           = ds
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + 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.

  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 = [@qname, @qlen, @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}" unless @cs.nil? || @cs.empty?
    a << "ds:Z:#{@ds}" unless @ds.nil? || @ds.empty?
    a << "MD:Z:#{@md}" unless @md.nil? || @md.empty?
    a.join("\t")
  end
end

#mapqInteger

Returns mapping quality.

Returns:

  • (Integer)

    mapping quality.



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
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/minimap2/alignment.rb', line 54

class Alignment
  CIGAR_STR = "MIDNSHP=XB"

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

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, ds = nil, md = nil)
    @qname        = h[:qname]
    @qlen         = h[:qlen]
    @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
    @ds           = ds
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + 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.

  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 = [@qname, @qlen, @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}" unless @cs.nil? || @cs.empty?
    a << "ds:Z:#{@ds}" unless @ds.nil? || @ds.empty?
    a << "MD:Z:#{@md}" unless @md.nil? || @md.empty?
    a.join("\t")
  end
end

#mdString?

Returns the MD tag as in the SAM format.

Returns:

  • (String, nil)

    the MD tag as in the SAM format.



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
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/minimap2/alignment.rb', line 54

class Alignment
  CIGAR_STR = "MIDNSHP=XB"

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

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, ds = nil, md = nil)
    @qname        = h[:qname]
    @qlen         = h[:qlen]
    @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
    @ds           = ds
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + 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.

  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 = [@qname, @qlen, @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}" unless @cs.nil? || @cs.empty?
    a << "ds:Z:#{@ds}" unless @ds.nil? || @ds.empty?
    a << "MD:Z:#{@md}" unless @md.nil? || @md.empty?
    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.



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
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/minimap2/alignment.rb', line 54

class Alignment
  CIGAR_STR = "MIDNSHP=XB"

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

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, ds = nil, md = nil)
    @qname        = h[:qname]
    @qlen         = h[:qlen]
    @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
    @ds           = ds
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + 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.

  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 = [@qname, @qlen, @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}" unless @cs.nil? || @cs.empty?
    a << "ds:Z:#{@ds}" unless @ds.nil? || @ds.empty?
    a << "MD:Z:#{@md}" unless @md.nil? || @md.empty?
    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.



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
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/minimap2/alignment.rb', line 54

class Alignment
  CIGAR_STR = "MIDNSHP=XB"

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

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, ds = nil, md = nil)
    @qname        = h[:qname]
    @qlen         = h[:qlen]
    @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
    @ds           = ds
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + 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.

  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 = [@qname, @qlen, @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}" unless @cs.nil? || @cs.empty?
    a << "ds:Z:#{@ds}" unless @ds.nil? || @ds.empty?
    a << "MD:Z:#{@md}" unless @md.nil? || @md.empty?
    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)



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
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/minimap2/alignment.rb', line 54

class Alignment
  CIGAR_STR = "MIDNSHP=XB"

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

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, ds = nil, md = nil)
    @qname        = h[:qname]
    @qlen         = h[:qlen]
    @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
    @ds           = ds
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + 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.

  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 = [@qname, @qlen, @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}" unless @cs.nil? || @cs.empty?
    a << "ds:Z:#{@ds}" unless @ds.nil? || @ds.empty?
    a << "MD:Z:#{@md}" unless @md.nil? || @md.empty?
    a.join("\t")
  end
end

#q_enInteger

Returns end positions on the query.

Returns:

  • (Integer)

    end positions on the query.



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
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/minimap2/alignment.rb', line 54

class Alignment
  CIGAR_STR = "MIDNSHP=XB"

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

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, ds = nil, md = nil)
    @qname        = h[:qname]
    @qlen         = h[:qlen]
    @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
    @ds           = ds
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + 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.

  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 = [@qname, @qlen, @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}" unless @cs.nil? || @cs.empty?
    a << "ds:Z:#{@ds}" unless @ds.nil? || @ds.empty?
    a << "MD:Z:#{@md}" unless @md.nil? || @md.empty?
    a.join("\t")
  end
end

#q_stInteger

Returns start positions on the query.

Returns:

  • (Integer)

    start positions on the query.



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
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/minimap2/alignment.rb', line 54

class Alignment
  CIGAR_STR = "MIDNSHP=XB"

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

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, ds = nil, md = nil)
    @qname        = h[:qname]
    @qlen         = h[:qlen]
    @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
    @ds           = ds
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + 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.

  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 = [@qname, @qlen, @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}" unless @cs.nil? || @cs.empty?
    a << "ds:Z:#{@ds}" unless @ds.nil? || @ds.empty?
    a << "MD:Z:#{@md}" unless @md.nil? || @md.empty?
    a.join("\t")
  end
end

#qlenInteger

Returns query sequence length.

Returns:

  • (Integer)

    query sequence length.



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
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/minimap2/alignment.rb', line 54

class Alignment
  CIGAR_STR = "MIDNSHP=XB"

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

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, ds = nil, md = nil)
    @qname        = h[:qname]
    @qlen         = h[:qlen]
    @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
    @ds           = ds
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + 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.

  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 = [@qname, @qlen, @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}" unless @cs.nil? || @cs.empty?
    a << "ds:Z:#{@ds}" unless @ds.nil? || @ds.empty?
    a << "MD:Z:#{@md}" unless @md.nil? || @md.empty?
    a.join("\t")
  end
end

#qnameString

Returns query sequence name.

Returns:

  • (String)

    query sequence name.



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
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/minimap2/alignment.rb', line 54

class Alignment
  CIGAR_STR = "MIDNSHP=XB"

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

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, ds = nil, md = nil)
    @qname        = h[:qname]
    @qlen         = h[:qlen]
    @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
    @ds           = ds
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + 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.

  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 = [@qname, @qlen, @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}" unless @cs.nil? || @cs.empty?
    a << "ds:Z:#{@ds}" unless @ds.nil? || @ds.empty?
    a << "MD:Z:#{@md}" unless @md.nil? || @md.empty?
    a.join("\t")
  end
end

#r_enInteger

Returns end positions on the reference.

Returns:

  • (Integer)

    end positions on the reference.



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
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/minimap2/alignment.rb', line 54

class Alignment
  CIGAR_STR = "MIDNSHP=XB"

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

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, ds = nil, md = nil)
    @qname        = h[:qname]
    @qlen         = h[:qlen]
    @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
    @ds           = ds
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + 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.

  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 = [@qname, @qlen, @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}" unless @cs.nil? || @cs.empty?
    a << "ds:Z:#{@ds}" unless @ds.nil? || @ds.empty?
    a << "MD:Z:#{@md}" unless @md.nil? || @md.empty?
    a.join("\t")
  end
end

#r_stInteger

Returns start positions on the reference.

Returns:

  • (Integer)

    start positions on the reference.



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
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/minimap2/alignment.rb', line 54

class Alignment
  CIGAR_STR = "MIDNSHP=XB"

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

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, ds = nil, md = nil)
    @qname        = h[:qname]
    @qlen         = h[:qlen]
    @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
    @ds           = ds
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + 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.

  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 = [@qname, @qlen, @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}" unless @cs.nil? || @cs.empty?
    a << "ds:Z:#{@ds}" unless @ds.nil? || @ds.empty?
    a << "MD:Z:#{@md}" unless @md.nil? || @md.empty?
    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.



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
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/minimap2/alignment.rb', line 54

class Alignment
  CIGAR_STR = "MIDNSHP=XB"

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

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, ds = nil, md = nil)
    @qname        = h[:qname]
    @qlen         = h[:qlen]
    @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
    @ds           = ds
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + 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.

  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 = [@qname, @qlen, @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}" unless @cs.nil? || @cs.empty?
    a << "ds:Z:#{@ds}" unless @ds.nil? || @ds.empty?
    a << "MD:Z:#{@md}" unless @md.nil? || @md.empty?
    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.



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
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/minimap2/alignment.rb', line 54

class Alignment
  CIGAR_STR = "MIDNSHP=XB"

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

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, ds = nil, md = nil)
    @qname        = h[:qname]
    @qlen         = h[:qlen]
    @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
    @ds           = ds
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + 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.

  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 = [@qname, @qlen, @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}" unless @cs.nil? || @cs.empty?
    a << "ds:Z:#{@ds}" unless @ds.nil? || @ds.empty?
    a << "MD:Z:#{@md}" unless @md.nil? || @md.empty?
    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.



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
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/minimap2/alignment.rb', line 54

class Alignment
  CIGAR_STR = "MIDNSHP=XB"

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

  attr_reader(*keys)

  def initialize(h, cigar, cs = nil, ds = nil, md = nil)
    @qname        = h[:qname]
    @qlen         = h[:qlen]
    @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
    @ds           = ds
    @md           = md

    @cigar_str = cigar.map { |x| x[0].to_s + 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.

  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 = [@qname, @qlen, @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}" unless @cs.nil? || @cs.empty?
    a << "ds:Z:#{@ds}" unless @ds.nil? || @ds.empty?
    a << "MD:Z:#{@md}" unless @md.nil? || @md.empty?
    a.join("\t")
  end
end

Class Method Details

.keysObject



57
58
59
60
# File 'lib/minimap2/alignment.rb', line 57

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

Instance Method Details

#primary?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/minimap2/alignment.rb', line 89

def primary?
  @primary == 1
end

#to_hObject

Convert Alignment to hash.



95
96
97
# File 'lib/minimap2/alignment.rb', line 95

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

#to_sObject

Convert to the PAF format.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/minimap2/alignment.rb', line 101

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 = [@qname, @qlen, @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}" unless @cs.nil? || @cs.empty?
  a << "ds:Z:#{@ds}" unless @ds.nil? || @ds.empty?
  a << "MD:Z:#{@md}" unless @md.nil? || @md.empty?
  a.join("\t")
end