Class: Minimap2::Alignment
- Inherits:
-
Object
- Object
- Minimap2::Alignment
- Defined in:
- lib/minimap2/alignment.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(h, cigar, cs = nil, md = nil) ⇒ Alignment
constructor
A new instance of Alignment.
- #primary? ⇒ Boolean
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(h, cigar, cs = nil, md = nil) ⇒ Alignment
Returns a new instance of Alignment.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/minimap2/alignment.rb', line 13 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 + "MIDNSH"[x[1]] }.join end |
Class Method Details
.keys ⇒ Object
5 6 7 8 |
# File 'lib/minimap2/alignment.rb', line 5 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
35 36 37 |
# File 'lib/minimap2/alignment.rb', line 35 def primary? @primary == 1 end |
#to_h ⇒ Object
39 40 41 |
# File 'lib/minimap2/alignment.rb', line 39 def to_h self.class.keys.map { |k| [k, __send__(k)] }.to_h end |
#to_s ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/minimap2/alignment.rb', line 43 def to_s strand = if @strand.positive? "+" elsif @strand.negative? "-" else "?" end tp = @primary != 0 ? "tp:A:P" : "tp:A:S" ts = if @trans_strand.positive? "ts:A:+" elsif @trans_strand.negative? "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.join("\t") end |