Class: Sam
- Inherits:
-
Object
- Object
- Sam
- Defined in:
- lib/sam.rb
Instance Attribute Summary collapse
-
#chrom ⇒ Object
Returns the value of attribute chrom.
-
#cigar ⇒ Object
Returns the value of attribute cigar.
-
#flag ⇒ Object
Returns the value of attribute flag.
-
#insert ⇒ Object
Returns the value of attribute insert.
-
#mapq ⇒ Object
Returns the value of attribute mapq.
-
#mchrom ⇒ Object
Returns the value of attribute mchrom.
-
#mpos ⇒ Object
Returns the value of attribute mpos.
-
#name ⇒ Object
Returns the value of attribute name.
-
#pos ⇒ Object
Returns the value of attribute pos.
-
#qual ⇒ Object
Returns the value of attribute qual.
-
#seq ⇒ Object
Returns the value of attribute seq.
-
#tags ⇒ Object
Returns the value of attribute tags.
Instance Method Summary collapse
-
#initialize(line = nil) ⇒ Sam
constructor
A new instance of Sam.
- #parse_line(line) ⇒ Object
Constructor Details
#initialize(line = nil) ⇒ Sam
Returns a new instance of Sam.
5 6 7 8 |
# File 'lib/sam.rb', line 5 def initialize(line=nil) @tags = {} parse_line(line) if line != nil end |
Instance Attribute Details
#chrom ⇒ Object
Returns the value of attribute chrom.
3 4 5 |
# File 'lib/sam.rb', line 3 def chrom @chrom end |
#cigar ⇒ Object
Returns the value of attribute cigar.
3 4 5 |
# File 'lib/sam.rb', line 3 def cigar @cigar end |
#flag ⇒ Object
Returns the value of attribute flag.
3 4 5 |
# File 'lib/sam.rb', line 3 def flag @flag end |
#insert ⇒ Object
Returns the value of attribute insert.
3 4 5 |
# File 'lib/sam.rb', line 3 def insert @insert end |
#mapq ⇒ Object
Returns the value of attribute mapq.
3 4 5 |
# File 'lib/sam.rb', line 3 def mapq @mapq end |
#mchrom ⇒ Object
Returns the value of attribute mchrom.
3 4 5 |
# File 'lib/sam.rb', line 3 def mchrom @mchrom end |
#mpos ⇒ Object
Returns the value of attribute mpos.
3 4 5 |
# File 'lib/sam.rb', line 3 def mpos @mpos end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/sam.rb', line 3 def name @name end |
#pos ⇒ Object
Returns the value of attribute pos.
3 4 5 |
# File 'lib/sam.rb', line 3 def pos @pos end |
#qual ⇒ Object
Returns the value of attribute qual.
3 4 5 |
# File 'lib/sam.rb', line 3 def qual @qual end |
#seq ⇒ Object
Returns the value of attribute seq.
3 4 5 |
# File 'lib/sam.rb', line 3 def seq @seq end |
#tags ⇒ Object
Returns the value of attribute tags.
3 4 5 |
# File 'lib/sam.rb', line 3 def @tags end |
Instance Method Details
#parse_line(line) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/sam.rb', line 10 def parse_line(line) return false if line[0] == "@" f = line.chomp.split("\t", -1) raise "SAM lines must have at least 11 fields (had #{f.size})" if f.size < 11 # colnames = %w(1:name 2:flag 3:chr 4:pos 5:mapq 6:cigar 7:mchr 8:mpos 9:insrt 10:seq 11:qual) @name = f[0] @flag = int_or_raw(f[1]) @chrom = f[2] @pos = int_or_neg1(f[3]) @mapq = int_or_neg1(f[4]) @cigar = f[5] @mchrom = f[6] @mpos = int_or_neg1(f[7]) @insert = int_or_raw(f[8]) @seq = f[9] @qual = f[10] @tags = {} i = 11 while i < f.size tag = f[i] i += 1 colon_index = tag.rindex(':') raise line if f.rindex == nil key = tag[0, colon_index] value = int_or_raw(tag[colon_index + 1, tag.size - colon_index] || "") @tags[key] = value end return true; end |