Class: Bio::Bam::Alignment
- Inherits:
-
Object
- Object
- Bio::Bam::Alignment
- Defined in:
- lib/bio-sambamba/alignment.rb
Overview
Class representing an alignment record
Instance Attribute Summary collapse
-
#mate_reference ⇒ Object
readonly
Mate reference sequence name.
-
#reference ⇒ Object
readonly
Reference sequence name.
Instance Method Summary collapse
- #==(read) ⇒ Object
-
#[](tag) ⇒ Object
Access a record tag.
-
#bases_covered ⇒ Object
The number of reference bases covered.
-
#cigar ⇒ Object
CIGAR string.
-
#cigar_operations ⇒ Object
CIGAR: pairs of operations and lengths, or nil if information is not available.
-
#failed_quality_control ⇒ Object
Not passing quality controls.
-
#flag ⇒ Object
Bitwise flag.
-
#initialize(obj, reference_sequence_names) ⇒ Alignment
constructor
Creates a new object from MessagePack record.
-
#is_duplicate ⇒ Object
PCR or optical duplicate.
-
#is_first_of_pair ⇒ Object
The first segment in the template.
-
#is_paired ⇒ Object
Template having multiple segments in sequencing.
-
#is_reverse_strand ⇒ Object
Sequence being reverse complemented.
-
#is_second_of_pair ⇒ Object
The last segment in the template.
-
#is_secondary_alignment ⇒ Object
Secondary alignment.
-
#is_unmapped ⇒ Object
Segment unmapped.
-
#mapping_quality ⇒ Object
Mapping quality.
-
#mate_is_reverse_strand ⇒ Object
Sequence of the next segment in the template being reversed.
-
#mate_is_unmapped ⇒ Object
Next segment in the template unmapped.
-
#mate_position ⇒ Object
1-based leftmost position of the mate/next segment.
-
#mate_ref_id ⇒ Object
Reference sequence name of the mate/next segment.
-
#position ⇒ Object
1-based leftmost mapping position.
-
#proper_pair ⇒ Object
Each segment properly aligned according to the aligner.
-
#quality ⇒ Object
Phred-scaled base quality, an integer array of the same length as the sequence.
-
#read_name ⇒ Object
Query template name.
-
#ref_id ⇒ Object
ID of reference sequence.
-
#sequence ⇒ Object
Segment sequence.
-
#tags ⇒ Object
Hash of record tags.
-
#template_length ⇒ Object
Observed template length.
Constructor Details
#initialize(obj, reference_sequence_names) ⇒ Alignment
Creates a new object from MessagePack record
8 9 10 11 12 |
# 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 |
Instance Attribute Details
#mate_reference ⇒ Object (readonly)
Mate reference sequence name
161 162 163 |
# File 'lib/bio-sambamba/alignment.rb', line 161 def mate_reference @mate_reference end |
#reference ⇒ Object (readonly)
Reference sequence name
158 159 160 |
# File 'lib/bio-sambamba/alignment.rb', line 158 def reference @reference end |
Instance Method Details
#==(read) ⇒ Object
20 21 22 |
# File 'lib/bio-sambamba/alignment.rb', line 20 def ==(read) read.obj == obj end |
#[](tag) ⇒ Object
Access a record tag
15 16 17 18 |
# File 'lib/bio-sambamba/alignment.rb', line 15 def [](tag) raise 'tag length must be two' unless tag.length == 2 [tag] end |
#bases_covered ⇒ Object
The number of reference bases covered
94 95 96 97 98 99 100 |
# 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 ⇒ Object
CIGAR string
57 58 59 60 |
# 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 ⇒ Object
CIGAR: pairs of operations and lengths, or nil if information is not available
51 52 53 54 |
# 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 ⇒ Object
Not passing quality controls
148 149 150 |
# File 'lib/bio-sambamba/alignment.rb', line 148 def failed_quality_control (flag & 0x200) != 0 end |
#flag ⇒ Object
Bitwise flag
68 69 70 |
# File 'lib/bio-sambamba/alignment.rb', line 68 def flag obj[1] end |
#is_duplicate ⇒ Object
PCR or optical duplicate
153 154 155 |
# File 'lib/bio-sambamba/alignment.rb', line 153 def is_duplicate (flag & 0x400) != 0 end |
#is_first_of_pair ⇒ Object
The first segment in the template
133 134 135 |
# File 'lib/bio-sambamba/alignment.rb', line 133 def is_first_of_pair (flag & 0x40) != 0 end |
#is_paired ⇒ Object
Template having multiple segments in sequencing
103 104 105 |
# File 'lib/bio-sambamba/alignment.rb', line 103 def is_paired (flag & 0x1) != 0 end |
#is_reverse_strand ⇒ Object
Sequence being reverse complemented
123 124 125 |
# File 'lib/bio-sambamba/alignment.rb', line 123 def is_reverse_strand (flag & 0x10) != 0 end |
#is_second_of_pair ⇒ Object
The last segment in the template
138 139 140 |
# File 'lib/bio-sambamba/alignment.rb', line 138 def is_second_of_pair (flag & 0x80) != 0 end |
#is_secondary_alignment ⇒ Object
Secondary alignment
143 144 145 |
# File 'lib/bio-sambamba/alignment.rb', line 143 def is_secondary_alignment (flag & 0x100) != 0 end |
#is_unmapped ⇒ Object
Segment unmapped
113 114 115 |
# File 'lib/bio-sambamba/alignment.rb', line 113 def is_unmapped (flag & 0x4) != 0 end |
#mapping_quality ⇒ Object
Mapping quality
45 46 47 |
# File 'lib/bio-sambamba/alignment.rb', line 45 def mapping_quality obj[4] end |
#mate_is_reverse_strand ⇒ Object
Sequence of the next segment in the template being reversed
128 129 130 |
# File 'lib/bio-sambamba/alignment.rb', line 128 def mate_is_reverse_strand (flag & 0x20) != 0 end |
#mate_is_unmapped ⇒ Object
Next segment in the template unmapped
118 119 120 |
# File 'lib/bio-sambamba/alignment.rb', line 118 def mate_is_unmapped (flag & 0x8) != 0 end |
#mate_position ⇒ Object
1-based leftmost position of the mate/next segment
89 90 91 |
# File 'lib/bio-sambamba/alignment.rb', line 89 def mate_position obj[8] end |
#mate_ref_id ⇒ Object
Reference sequence name of the mate/next segment
84 85 86 |
# File 'lib/bio-sambamba/alignment.rb', line 84 def mate_ref_id obj[7] end |
#position ⇒ Object
1-based leftmost mapping position
40 41 42 |
# File 'lib/bio-sambamba/alignment.rb', line 40 def position obj[3] end |
#proper_pair ⇒ Object
Each segment properly aligned according to the aligner
108 109 110 |
# File 'lib/bio-sambamba/alignment.rb', line 108 def proper_pair (flag & 0x2) != 0 end |
#quality ⇒ Object
Phred-scaled base quality, an integer array of the same length as the sequence
74 75 76 |
# File 'lib/bio-sambamba/alignment.rb', line 74 def quality obj[11].bytes.to_a end |
#read_name ⇒ Object
Query template name
35 36 37 |
# File 'lib/bio-sambamba/alignment.rb', line 35 def read_name obj[0] end |
#ref_id ⇒ Object
ID of reference sequence
30 31 32 |
# File 'lib/bio-sambamba/alignment.rb', line 30 def ref_id obj[2] end |
#sequence ⇒ Object
Segment sequence
79 80 81 |
# File 'lib/bio-sambamba/alignment.rb', line 79 def sequence obj[10] end |
#tags ⇒ Object
Hash of record tags
25 26 27 |
# File 'lib/bio-sambamba/alignment.rb', line 25 def obj[12] end |
#template_length ⇒ Object
Observed template length
63 64 65 |
# File 'lib/bio-sambamba/alignment.rb', line 63 def template_length obj[9] end |