Class: Bio::Bam::Alignment

Inherits:
Object
  • Object
show all
Defined in:
lib/bio-sambamba/alignment.rb

Overview

Class representing an alignment record

Instance Attribute Summary collapse

Instance Method Summary collapse

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_referenceObject (readonly)

Mate reference sequence name



161
162
163
# File 'lib/bio-sambamba/alignment.rb', line 161

def mate_reference
  @mate_reference
end

#referenceObject (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
  tags[tag]
end

#bases_coveredObject

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

#cigarObject

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_operationsObject

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_controlObject

Not passing quality controls



148
149
150
# File 'lib/bio-sambamba/alignment.rb', line 148

def failed_quality_control   
  (flag & 0x200) != 0
end

#flagObject

Bitwise flag



68
69
70
# File 'lib/bio-sambamba/alignment.rb', line 68

def flag
  obj[1]
end

#is_duplicateObject

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_pairObject

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_pairedObject

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_strandObject

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_pairObject

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_alignmentObject

Secondary alignment



143
144
145
# File 'lib/bio-sambamba/alignment.rb', line 143

def is_secondary_alignment   
  (flag & 0x100) != 0
end

#is_unmappedObject

Segment unmapped



113
114
115
# File 'lib/bio-sambamba/alignment.rb', line 113

def is_unmapped              
  (flag & 0x4) != 0
end

#mapping_qualityObject

Mapping quality



45
46
47
# File 'lib/bio-sambamba/alignment.rb', line 45

def mapping_quality
  obj[4]
end

#mate_is_reverse_strandObject

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_unmappedObject

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_positionObject

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_idObject

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

#positionObject

1-based leftmost mapping position



40
41
42
# File 'lib/bio-sambamba/alignment.rb', line 40

def position
  obj[3]
end

#proper_pairObject

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

#qualityObject

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_nameObject

Query template name



35
36
37
# File 'lib/bio-sambamba/alignment.rb', line 35

def read_name
  obj[0]
end

#ref_idObject

ID of reference sequence



30
31
32
# File 'lib/bio-sambamba/alignment.rb', line 30

def ref_id
  obj[2]
end

#sequenceObject

Segment sequence



79
80
81
# File 'lib/bio-sambamba/alignment.rb', line 79

def sequence
  obj[10]
end

#tagsObject

Hash of record tags



25
26
27
# File 'lib/bio-sambamba/alignment.rb', line 25

def tags
  obj[12]
end

#template_lengthObject

Observed template length



63
64
65
# File 'lib/bio-sambamba/alignment.rb', line 63

def template_length
  obj[9]
end