class Bio::Bam::Alignment

Class representing an alignment record

Attributes

mate_reference[R]

Mate reference sequence name

obj[RW]
reference[R]

Reference sequence name

Public Class Methods

new(obj, reference_sequence_names) click to toggle source

Creates a new object from MessagePack record

# File lib/bio-sambamba/alignment.rb, line 8
def initialize(obj, reference_sequence_names)
  @obj = obj
  @reference = reference_sequence_names[ref_id]
  @mate_reference = reference_sequence_names[mate_ref_id]
end

Public Instance Methods

==(read) click to toggle source
# File lib/bio-sambamba/alignment.rb, line 20
def ==(read)
  read.obj == obj
end
[](tag) click to toggle source

Access a record tag

# File lib/bio-sambamba/alignment.rb, line 15
def [](tag)
  raise 'tag length must be two' unless tag.length == 2
  tags[tag]
end
bases_covered() click to toggle source

The number of reference bases covered

# File lib/bio-sambamba/alignment.rb, line 94
def bases_covered
  return 0 if cigar_operations.nil?
  cigar_operations.reduce(0) {|res, op| 
    res += op[1] unless ('M=XDN'.index op[0]).nil?
    res
  }
end
cigar() click to toggle source

CIGAR string

# File lib/bio-sambamba/alignment.rb, line 57
def cigar
  return '*' if cigar_operations.nil?
  cigar_operations.reduce(''){|s, op_len| s + op_len[0] + op_len[1].to_s}
end
cigar_operations() click to toggle source

CIGAR: pairs of operations and lengths, or nil if information is not available

# File lib/bio-sambamba/alignment.rb, line 51
def cigar_operations
  return nil if obj[5].nil?
  obj[6].chars.zip obj[5]
end
failed_quality_control() click to toggle source

Not passing quality controls

# File lib/bio-sambamba/alignment.rb, line 148
def failed_quality_control   
  (flag & 0x200) != 0
end
flag() click to toggle source

Bitwise flag

# File lib/bio-sambamba/alignment.rb, line 68
def flag
  obj[1]
end
is_duplicate() click to toggle source

PCR or optical duplicate

# File lib/bio-sambamba/alignment.rb, line 153
def is_duplicate             
  (flag & 0x400) != 0
end
is_first_of_pair() click to toggle source

The first segment in the template

# File lib/bio-sambamba/alignment.rb, line 133
def is_first_of_pair         
  (flag & 0x40) != 0
end
is_paired() click to toggle source

Template having multiple segments in sequencing

# File lib/bio-sambamba/alignment.rb, line 103
def is_paired                
  (flag & 0x1) != 0
end
is_reverse_strand() click to toggle source

Sequence being reverse complemented

# File lib/bio-sambamba/alignment.rb, line 123
def is_reverse_strand        
  (flag & 0x10) != 0
end
is_second_of_pair() click to toggle source

The last segment in the template

# File lib/bio-sambamba/alignment.rb, line 138
def is_second_of_pair        
  (flag & 0x80) != 0
end
is_secondary_alignment() click to toggle source

Secondary alignment

# File lib/bio-sambamba/alignment.rb, line 143
def is_secondary_alignment   
  (flag & 0x100) != 0
end
is_unmapped() click to toggle source

Segment unmapped

# File lib/bio-sambamba/alignment.rb, line 113
def is_unmapped              
  (flag & 0x4) != 0
end
mapping_quality() click to toggle source

Mapping quality

# File lib/bio-sambamba/alignment.rb, line 45
def mapping_quality
  obj[4]
end
mate_is_reverse_strand() click to toggle source

Sequence of the next segment in the template being reversed

# File lib/bio-sambamba/alignment.rb, line 128
def mate_is_reverse_strand   
  (flag & 0x20) != 0
end
mate_is_unmapped() click to toggle source

Next segment in the template unmapped

# File lib/bio-sambamba/alignment.rb, line 118
def mate_is_unmapped         
  (flag & 0x8) != 0
end
mate_position() click to toggle source

1-based leftmost position of the mate/next segment

# File lib/bio-sambamba/alignment.rb, line 89
def mate_position
  obj[8]
end
mate_ref_id() click to toggle source

Reference sequence name of the mate/next segment

# File lib/bio-sambamba/alignment.rb, line 84
def mate_ref_id
  obj[7]
end
position() click to toggle source

1-based leftmost mapping position

# File lib/bio-sambamba/alignment.rb, line 40
def position
  obj[3]
end
proper_pair() click to toggle source

Each segment properly aligned according to the aligner

# File lib/bio-sambamba/alignment.rb, line 108
def proper_pair              
  (flag & 0x2) != 0
end
quality() click to toggle source

Phred-scaled base quality, an integer array of the same length as the sequence

# File lib/bio-sambamba/alignment.rb, line 74
def quality
  obj[11].bytes.to_a
end
read_name() click to toggle source

Query template name

# File lib/bio-sambamba/alignment.rb, line 35
def read_name
  obj[0]
end
ref_id() click to toggle source

ID of reference sequence

# File lib/bio-sambamba/alignment.rb, line 30
def ref_id
  obj[2]
end
sequence() click to toggle source

Segment sequence

# File lib/bio-sambamba/alignment.rb, line 79
def sequence
  obj[10]
end
tags() click to toggle source

Hash of record tags

# File lib/bio-sambamba/alignment.rb, line 25
def tags
  obj[12]
end
template_length() click to toggle source

Observed template length

# File lib/bio-sambamba/alignment.rb, line 63
def template_length
  obj[9]
end