class Bio::Bam::Alignment
Class representing an alignment record
Attributes
Mate reference sequence name
Reference sequence name
Public Class Methods
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
# File lib/bio-sambamba/alignment.rb, line 20 def ==(read) read.obj == obj end
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
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 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: 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
Not passing quality controls
# File lib/bio-sambamba/alignment.rb, line 148 def failed_quality_control (flag & 0x200) != 0 end
Bitwise flag
# File lib/bio-sambamba/alignment.rb, line 68 def flag obj[1] end
PCR or optical duplicate
# File lib/bio-sambamba/alignment.rb, line 153 def is_duplicate (flag & 0x400) != 0 end
The first segment in the template
# File lib/bio-sambamba/alignment.rb, line 133 def is_first_of_pair (flag & 0x40) != 0 end
Template having multiple segments in sequencing
# File lib/bio-sambamba/alignment.rb, line 103 def is_paired (flag & 0x1) != 0 end
Sequence being reverse complemented
# File lib/bio-sambamba/alignment.rb, line 123 def is_reverse_strand (flag & 0x10) != 0 end
The last segment in the template
# File lib/bio-sambamba/alignment.rb, line 138 def is_second_of_pair (flag & 0x80) != 0 end
Secondary alignment
# File lib/bio-sambamba/alignment.rb, line 143 def is_secondary_alignment (flag & 0x100) != 0 end
Segment unmapped
# File lib/bio-sambamba/alignment.rb, line 113 def is_unmapped (flag & 0x4) != 0 end
Mapping quality
# File lib/bio-sambamba/alignment.rb, line 45 def mapping_quality obj[4] end
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
Next segment in the template unmapped
# File lib/bio-sambamba/alignment.rb, line 118 def mate_is_unmapped (flag & 0x8) != 0 end
1-based leftmost position of the mate/next segment
# File lib/bio-sambamba/alignment.rb, line 89 def mate_position obj[8] end
Reference sequence name of the mate/next segment
# File lib/bio-sambamba/alignment.rb, line 84 def mate_ref_id obj[7] end
1-based leftmost mapping position
# File lib/bio-sambamba/alignment.rb, line 40 def position obj[3] end
Each segment properly aligned according to the aligner
# File lib/bio-sambamba/alignment.rb, line 108 def proper_pair (flag & 0x2) != 0 end
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
Query template name
# File lib/bio-sambamba/alignment.rb, line 35 def read_name obj[0] end
ID of reference sequence
# File lib/bio-sambamba/alignment.rb, line 30 def ref_id obj[2] end
Segment sequence
# File lib/bio-sambamba/alignment.rb, line 79 def sequence obj[10] end
Observed template length
# File lib/bio-sambamba/alignment.rb, line 63 def template_length obj[9] end