Class: HTS::Bam::Record
- Inherits:
-
Object
- Object
- HTS::Bam::Record
- Defined in:
- lib/hts/bam/record.rb
Constant Summary collapse
- SEQ_NT16_STR =
"=ACMGRSVTWYHKDBN"
Instance Attribute Summary collapse
-
#header ⇒ Object
readonly
Returns the value of attribute header.
Class Method Summary collapse
-
.rom_sam_str ⇒ Object
def initialize_copy super end.
Instance Method Summary collapse
-
#base_at(n) ⇒ Object
return only the base of the requested index “i” of the query sequence.
-
#base_qualities ⇒ Object
return the base qualities.
-
#base_quality_at(n) ⇒ Object
return only the base quality of the requested index “i” of the query sequence.
-
#chrom ⇒ Object
returns the chromosome or ” if not mapped.
-
#cigar ⇒ Object
returns a ‘Cigar` object.
-
#contig ⇒ Object
returns the chromosome or ” if not mapped.
-
#flag ⇒ Object
returns a ‘Flag` object.
- #flag_str ⇒ Object
-
#initialize(bam1_t, header) ⇒ Record
constructor
A new instance of Record.
-
#insert_size ⇒ Object
insert size.
-
#mapping_quality ⇒ Object
mapping quality.
-
#mate_chrom ⇒ Object
returns the chromosome of the mate or ” if not mapped.
-
#mate_start ⇒ Object
(also: #mate_pos)
returns 0-based mate position.
-
#mate_tid ⇒ Object
returns the tid of the mate or -1 if not mapped.
- #qlen ⇒ Object
-
#qname ⇒ Object
returns the query name.
- #rlen ⇒ Object
-
#sequence ⇒ Object
return the read sequence.
-
#start ⇒ Object
returns 0-based start position.
-
#stop ⇒ Object
returns end position of the read.
- #strand ⇒ Object
- #struct ⇒ Object
- #tag(str) ⇒ Object
- #tags ⇒ Object
-
#tid ⇒ Object
returns the tid of the record or -1 if not mapped.
- #to_ptr ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(bam1_t, header) ⇒ Record
Returns a new instance of Record.
11 12 13 14 |
# File 'lib/hts/bam/record.rb', line 11 def initialize(bam1_t, header) @bam1 = bam1_t @header = header end |
Instance Attribute Details
#header ⇒ Object (readonly)
Returns the value of attribute header.
24 25 26 |
# File 'lib/hts/bam/record.rb', line 24 def header @header end |
Class Method Details
.rom_sam_str ⇒ Object
def initialize_copy
super
end
30 |
# File 'lib/hts/bam/record.rb', line 30 def self.rom_sam_str; end |
Instance Method Details
#base_at(n) ⇒ Object
return only the base of the requested index “i” of the query sequence.
138 139 140 141 142 143 144 |
# File 'lib/hts/bam/record.rb', line 138 def base_at(n) n += @bam1[:core][:l_qseq] if n < 0 return "." if (n >= @bam1[:core][:l_qseq]) || (n < 0) # eg. base_at(-1000) r = LibHTS.bam_get_seq(@bam1) SEQ_NT16_STR[LibHTS.bam_seqi(r, n)] end |
#base_qualities ⇒ Object
return the base qualities
147 148 149 150 |
# File 'lib/hts/bam/record.rb', line 147 def base_qualities q_ptr = LibHTS.bam_get_qual(@bam1) q_ptr.read_array_of_uint8(@bam1[:core][:l_qseq]) end |
#base_quality_at(n) ⇒ Object
return only the base quality of the requested index “i” of the query sequence.
153 154 155 156 157 158 159 |
# File 'lib/hts/bam/record.rb', line 153 def base_quality_at(n) n += @bam1[:core][:l_qseq] if n < 0 return 0 if (n >= @bam1[:core][:l_qseq]) || (n < 0) # eg. base_quality_at(-1000) q_ptr = LibHTS.bam_get_qual(@bam1) q_ptr.get_uint8(n) end |
#chrom ⇒ Object
returns the chromosome or ” if not mapped.
71 72 73 74 75 |
# File 'lib/hts/bam/record.rb', line 71 def chrom return "" if tid == -1 LibHTS.sam_hdr_tid2name(@header, tid) end |
#cigar ⇒ Object
returns a ‘Cigar` object.
109 110 111 |
# File 'lib/hts/bam/record.rb', line 109 def cigar Cigar.new(LibHTS.bam_get_cigar(@bam1), @bam1[:core][:n_cigar]) end |
#contig ⇒ Object
returns the chromosome or ” if not mapped.
78 79 80 |
# File 'lib/hts/bam/record.rb', line 78 def contig chrom end |
#flag ⇒ Object
returns a ‘Flag` object.
166 167 168 |
# File 'lib/hts/bam/record.rb', line 166 def flag Flag.new(@bam1[:core][:flag]) end |
#flag_str ⇒ Object
161 162 163 |
# File 'lib/hts/bam/record.rb', line 161 def flag_str LibHTS.bam_flag2str(@bam1[:core][:flag]) end |
#insert_size ⇒ Object
insert size
99 100 101 |
# File 'lib/hts/bam/record.rb', line 99 def insert_size @bam1[:core][:isize] end |
#mapping_quality ⇒ Object
mapping quality
104 105 106 |
# File 'lib/hts/bam/record.rb', line 104 def mapping_quality @bam1[:core][:qual] end |
#mate_chrom ⇒ Object
returns the chromosome of the mate or ” if not mapped.
83 84 85 86 87 88 |
# File 'lib/hts/bam/record.rb', line 83 def mate_chrom mtid = mate_tid return "" if mtid == -1 LibHTS.sam_hdr_tid2name(@header, mtid) end |
#mate_start ⇒ Object Also known as: mate_pos
returns 0-based mate position
65 66 67 |
# File 'lib/hts/bam/record.rb', line 65 def mate_start @bam1[:core][:mpos] end |
#mate_tid ⇒ Object
returns the tid of the mate or -1 if not mapped.
50 51 52 |
# File 'lib/hts/bam/record.rb', line 50 def mate_tid @bam1[:core][:mtid] end |
#qlen ⇒ Object
113 114 115 116 117 118 |
# File 'lib/hts/bam/record.rb', line 113 def qlen LibHTS.bam_cigar2qlen( @bam1[:core][:n_cigar], LibHTS.bam_get_cigar(@bam1) ) end |
#qname ⇒ Object
returns the query name.
35 36 37 |
# File 'lib/hts/bam/record.rb', line 35 def qname LibHTS.bam_get_qname(@bam1).read_string end |
#rlen ⇒ Object
120 121 122 123 124 125 |
# File 'lib/hts/bam/record.rb', line 120 def rlen LibHTS.bam_cigar2rlen( @bam1[:core][:n_cigar], LibHTS.bam_get_cigar(@bam1) ) end |
#sequence ⇒ Object
return the read sequence
128 129 130 131 132 133 134 135 |
# File 'lib/hts/bam/record.rb', line 128 def sequence 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 |
#start ⇒ Object
returns 0-based start position.
55 56 57 |
# File 'lib/hts/bam/record.rb', line 55 def start @bam1[:core][:pos] end |
#stop ⇒ Object
returns end position of the read.
60 61 62 |
# File 'lib/hts/bam/record.rb', line 60 def stop LibHTS.bam_endpos @bam1 end |
#strand ⇒ Object
90 91 92 |
# File 'lib/hts/bam/record.rb', line 90 def strand LibHTS.bam_is_rev(@bam1) ? "-" : "+" end |
#struct ⇒ Object
16 17 18 |
# File 'lib/hts/bam/record.rb', line 16 def struct @bam1 end |
#tag(str) ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/hts/bam/record.rb', line 170 def tag(str) aux = LibHTS.bam_aux_get(@bam1, str) return nil if aux.null? t = aux.read_string(1) # A (character), B (general array), # f (real number), H (hexadecimal array), # i (integer), or Z (string). case t when "i", "I", "c", "C", "s", "S" LibHTS.bam_aux2i(aux) when "f", "d" LibHTS.bam_aux2f(aux) when "Z", "H" LibHTS.bam_aux2Z(aux) when "A" # char LibHTS.bam_aux2A(aux).chr end end |
#tags ⇒ Object
32 |
# File 'lib/hts/bam/record.rb', line 32 def ; end |
#tid ⇒ Object
returns the tid of the record or -1 if not mapped.
45 46 47 |
# File 'lib/hts/bam/record.rb', line 45 def tid @bam1[:core][:tid] end |
#to_ptr ⇒ Object
20 21 22 |
# File 'lib/hts/bam/record.rb', line 20 def to_ptr @bam1.to_ptr end |