Class: HTS::Bam::Record
- Inherits:
-
Object
- Object
- HTS::Bam::Record
- Defined in:
- lib/hts/bam/record.rb
Overview
A class for working with alignment records.
Constant Summary collapse
- SEQ_NT16_STR =
"=ACMGRSVTWYHKDBN"
Instance Attribute Summary collapse
-
#header ⇒ Object
readonly
Returns the value of attribute header.
Instance Method Summary collapse
-
#aux(key = nil) ⇒ Object
retruns the auxillary fields.
-
#base(n) ⇒ Object
return only the base of the requested index “i” of the query sequence.
-
#base_qual(n) ⇒ Object
return only the base quality of the requested index “i” of the query sequence.
- #bin ⇒ Object
- #bin=(bin) ⇒ Object
-
#chrom ⇒ Object
(also: #contig)
returns the chromosome or ” if not mapped.
-
#cigar ⇒ Object
returns a ‘Cigar` object.
-
#endpos ⇒ Object
returns end position of the read.
-
#flag ⇒ Object
returns a ‘Flag` object.
- #flag=(flag) ⇒ Object
-
#initialize(bam1_t, header) ⇒ Record
constructor
A new instance of Record.
-
#insert_size ⇒ Object
(also: #isize)
insert size.
- #insert_size=(isize) ⇒ Object (also: #isize=)
- #len ⇒ Object
-
#mapq ⇒ Object
mapping quality.
- #mapq=(mapq) ⇒ Object
-
#mate_chrom ⇒ Object
(also: #mate_contig)
returns the chromosome of the mate or ” if not mapped.
-
#mate_pos ⇒ Object
(also: #mpos)
returns 0-based mate position.
- #mate_pos=(mpos) ⇒ Object (also: #mpos=)
-
#mtid ⇒ Object
returns the tid of the mate or -1 if not mapped.
- #mtid=(mtid) ⇒ Object
-
#pos ⇒ Object
returns 0-based start position.
- #pos=(pos) ⇒ Object
- #qlen ⇒ Object
-
#qname ⇒ Object
returns the query name.
-
#qual ⇒ Object
return the base qualities.
- #rlen ⇒ Object
-
#seq ⇒ Object
(also: #sequence)
return the read sequence.
-
#strand ⇒ Object
Get strand information.
- #struct ⇒ Object
-
#tid ⇒ Object
returns the tid of the record or -1 if not mapped.
- #tid=(tid) ⇒ Object
- #to_ptr ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(bam1_t, header) ⇒ Record
Returns a new instance of Record.
15 16 17 18 |
# File 'lib/hts/bam/record.rb', line 15 def initialize(bam1_t, header) @bam1 = bam1_t @header = header end |
Instance Attribute Details
#header ⇒ Object (readonly)
Returns the value of attribute header.
13 14 15 |
# File 'lib/hts/bam/record.rb', line 13 def header @header end |
Instance Method Details
#aux(key = nil) ⇒ Object
retruns the auxillary fields.
209 210 211 212 213 214 215 216 |
# File 'lib/hts/bam/record.rb', line 209 def aux(key = nil) aux = Aux.new(self) if key aux.get(key) else aux end end |
#base(n) ⇒ Object
return only the base of the requested index “i” of the query sequence.
169 170 171 172 173 174 175 |
# File 'lib/hts/bam/record.rb', line 169 def base(n) n += @bam1[:core][:l_qseq] if n < 0 return "." if (n >= @bam1[:core][:l_qseq]) || (n < 0) # eg. base(-1000) r = LibHTS.bam_get_seq(@bam1) SEQ_NT16_STR[LibHTS.bam_seqi(r, n)] end |
#base_qual(n) ⇒ Object
return only the base quality of the requested index “i” of the query sequence.
184 185 186 187 188 189 190 |
# File 'lib/hts/bam/record.rb', line 184 def base_qual(n) n += @bam1[:core][:l_qseq] if n < 0 return 0 if (n >= @bam1[:core][:l_qseq]) || (n < 0) # eg. base_qual(-1000) q_ptr = LibHTS.bam_get_qual(@bam1) q_ptr.get_uint8(n) end |
#bin ⇒ Object
77 78 79 |
# File 'lib/hts/bam/record.rb', line 77 def bin @bam1[:core][:bin] end |
#bin=(bin) ⇒ Object
81 82 83 |
# File 'lib/hts/bam/record.rb', line 81 def bin=(bin) @bam1[:core][:bin] = bin end |
#chrom ⇒ Object Also known as: contig
returns the chromosome or ” if not mapped.
91 92 93 94 95 |
# File 'lib/hts/bam/record.rb', line 91 def chrom return "" if tid == -1 LibHTS.sam_hdr_tid2name(@header, tid) end |
#cigar ⇒ Object
returns a ‘Cigar` object.
135 136 137 |
# File 'lib/hts/bam/record.rb', line 135 def cigar Cigar.new(LibHTS.bam_get_cigar(@bam1), @bam1[:core][:n_cigar]) end |
#endpos ⇒ Object
returns end position of the read.
86 87 88 |
# File 'lib/hts/bam/record.rb', line 86 def endpos LibHTS.bam_endpos @bam1 end |
#flag ⇒ Object
returns a ‘Flag` object.
193 194 195 |
# File 'lib/hts/bam/record.rb', line 193 def flag Flag.new(@bam1[:core][:flag]) end |
#flag=(flag) ⇒ Object
197 198 199 200 201 202 203 204 205 206 |
# File 'lib/hts/bam/record.rb', line 197 def flag=(flag) case flag when Integer @bam1[:core][:flag] = flag when Flag @bam1[:core][:flag] = flag.value else raise "Invalid flag type: #{flag.class}" end end |
#insert_size ⇒ Object Also known as: isize
insert size
114 115 116 |
# File 'lib/hts/bam/record.rb', line 114 def insert_size @bam1[:core][:isize] end |
#insert_size=(isize) ⇒ Object Also known as: isize=
118 119 120 |
# File 'lib/hts/bam/record.rb', line 118 def insert_size=(isize) @bam1[:core][:isize] = isize end |
#len ⇒ Object
164 165 166 |
# File 'lib/hts/bam/record.rb', line 164 def len @bam1[:core][:l_qseq] end |
#mapq ⇒ Object
mapping quality
126 127 128 |
# File 'lib/hts/bam/record.rb', line 126 def mapq @bam1[:core][:qual] end |
#mapq=(mapq) ⇒ Object
130 131 132 |
# File 'lib/hts/bam/record.rb', line 130 def mapq=(mapq) @bam1[:core][:qual] = mapq end |
#mate_chrom ⇒ Object Also known as: mate_contig
returns the chromosome of the mate or ” if not mapped.
100 101 102 103 104 |
# File 'lib/hts/bam/record.rb', line 100 def mate_chrom return "" if mtid == -1 LibHTS.sam_hdr_tid2name(@header, mtid) end |
#mate_pos ⇒ Object Also known as: mpos
returns 0-based mate position
66 67 68 |
# File 'lib/hts/bam/record.rb', line 66 def mate_pos @bam1[:core][:mpos] end |
#mate_pos=(mpos) ⇒ Object Also known as: mpos=
70 71 72 |
# File 'lib/hts/bam/record.rb', line 70 def mate_pos=(mpos) @bam1[:core][:mpos] = mpos end |
#mtid ⇒ Object
returns the tid of the mate or -1 if not mapped.
48 49 50 |
# File 'lib/hts/bam/record.rb', line 48 def mtid @bam1[:core][:mtid] end |
#mtid=(mtid) ⇒ Object
52 53 54 |
# File 'lib/hts/bam/record.rb', line 52 def mtid=(mtid) @bam1[:core][:mtid] = mtid end |
#pos ⇒ Object
returns 0-based start position.
57 58 59 |
# File 'lib/hts/bam/record.rb', line 57 def pos @bam1[:core][:pos] end |
#pos=(pos) ⇒ Object
61 62 63 |
# File 'lib/hts/bam/record.rb', line 61 def pos=(pos) @bam1[:core][:pos] = pos end |
#qlen ⇒ Object
139 140 141 142 143 144 |
# File 'lib/hts/bam/record.rb', line 139 def qlen LibHTS.bam_cigar2qlen( @bam1[:core][:n_cigar], LibHTS.bam_get_cigar(@bam1) ) end |
#qname ⇒ Object
returns the query name.
29 30 31 |
# File 'lib/hts/bam/record.rb', line 29 def qname LibHTS.bam_get_qname(@bam1).read_string end |
#qual ⇒ Object
return the base qualities
178 179 180 181 |
# File 'lib/hts/bam/record.rb', line 178 def qual q_ptr = LibHTS.bam_get_qual(@bam1) q_ptr.read_array_of_uint8(@bam1[:core][:l_qseq]) end |
#rlen ⇒ Object
146 147 148 149 150 151 |
# File 'lib/hts/bam/record.rb', line 146 def rlen LibHTS.bam_cigar2rlen( @bam1[:core][:n_cigar], LibHTS.bam_get_cigar(@bam1) ) end |
#seq ⇒ Object Also known as: sequence
return the read sequence
154 155 156 157 158 159 160 161 |
# File 'lib/hts/bam/record.rb', line 154 def seq r = LibHTS.bam_get_seq(@bam1) seq = String.new (@bam1[:core][:l_qseq]).times do |i| seq << SEQ_NT16_STR[LibHTS.bam_seqi(r, i)] end seq end |
#strand ⇒ Object
Get strand information.
109 110 111 |
# File 'lib/hts/bam/record.rb', line 109 def strand LibHTS.bam_is_rev(@bam1) ? "-" : "+" end |
#struct ⇒ Object
20 21 22 |
# File 'lib/hts/bam/record.rb', line 20 def struct @bam1 end |
#tid ⇒ Object
returns the tid of the record or -1 if not mapped.
39 40 41 |
# File 'lib/hts/bam/record.rb', line 39 def tid @bam1[:core][:tid] end |
#tid=(tid) ⇒ Object
43 44 45 |
# File 'lib/hts/bam/record.rb', line 43 def tid=(tid) @bam1[:core][:tid] = tid end |
#to_ptr ⇒ Object
24 25 26 |
# File 'lib/hts/bam/record.rb', line 24 def to_ptr @bam1.to_ptr end |
#to_s ⇒ Object
233 234 235 236 237 238 |
# File 'lib/hts/bam/record.rb', line 233 def to_s kstr = LibHTS::KString.new raise "Failed to format bam record" if LibHTS.sam_format1(@header.struct, @bam1, kstr) == -1 kstr[:s] end |