Class: HTS::Bam::Alignment

Inherits:
Object
  • Object
show all
Defined in:
lib/hts/bam/alignment.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bam1_t, bam_hdr_t) ⇒ Alignment

Returns a new instance of Alignment.



9
10
11
12
# File 'lib/hts/bam/alignment.rb', line 9

def initialize(bam1_t, bam_hdr_t)
  @b = bam1_t
  @h = bam_hdr_t
end

Class Method Details

.rom_sam_strObject

def initialize_copy

super

end



18
# File 'lib/hts/bam/alignment.rb', line 18

def self.rom_sam_str; end

Instance Method Details

#base_at(n) ⇒ Object



119
120
121
122
123
124
125
126
# File 'lib/hts/bam/alignment.rb', line 119

def base_at(n)
  n += @b[:core][:l_qseq] if n < 0
  seq_nt16_str = '=ACMGRSVTWYHKDBN'
  return '.' if (n >= @b[:core][:l_qseq]) || (n < 0) # eg. base_at(-1000)

  r = FFI.bam_get_seq(@b)
  seq_nt16_str[FFI.bam_seqi(r, n)]
end

#base_qualitiesObject



128
129
130
131
# File 'lib/hts/bam/alignment.rb', line 128

def base_qualities
  q_ptr = FFI.bam_get_qual(@b)
  q_ptr.read_array_of_uint8(@b[:core][:l_qseq])
end

#base_quality_at(n) ⇒ Object



133
134
135
136
137
138
139
# File 'lib/hts/bam/alignment.rb', line 133

def base_quality_at(n)
  n += @b[:core][:l_qseq] if n < 0 # eg. base_quality_at(-1000)
  return 0 if (n >= @b[:core][:l_qseq]) || (n < 0)

  q_ptr = FFI.bam_get_qual(@b)
  q_ptr.get_uint8(n)
end

#chromObject

returns the chromosome or ” if not mapped.



66
67
68
69
70
71
# File 'lib/hts/bam/alignment.rb', line 66

def chrom
  tid = @b[:core][:tid]
  return '' if tid == -1

  FFI.sam_hdr_tid2name(@h, tid)
end

#cigarObject

returns a Cigar object.



92
93
94
# File 'lib/hts/bam/alignment.rb', line 92

def cigar
  Cigar.new(FFI.bam_get_cigar(@b), @b[:core][:n_cigar])
end

#flagObject

returns a Flag object.



146
147
148
# File 'lib/hts/bam/alignment.rb', line 146

def flag
  @b[:core][:flag]
end

#flag_strObject



141
142
143
# File 'lib/hts/bam/alignment.rb', line 141

def flag_str
  FFI.bam_flag2str(flag)
end

#isizeObject

insert size



82
83
84
# File 'lib/hts/bam/alignment.rb', line 82

def isize
  @b[:core][:isize]
end

#mapping_qualityObject

mapping quality



87
88
89
# File 'lib/hts/bam/alignment.rb', line 87

def mapping_quality
  @b[:core][:qual]
end

#mate_chromObject

returns the chromosome of the mate or ” if not mapped.



33
34
35
36
37
38
# File 'lib/hts/bam/alignment.rb', line 33

def mate_chrom
  tid = @b[:core][:mtid]
  return '' if tid == -1

  FFI.sam_hdr_tid2name(@h, tid)
end

#mate_posObject

mate position



51
52
53
# File 'lib/hts/bam/alignment.rb', line 51

def mate_pos
  @b[:core][:mpos]
end

#mate_tidObject

returns the tid of the mate or -1 if not mapped.



41
42
43
# File 'lib/hts/bam/alignment.rb', line 41

def mate_tid
  @b[:core][:mtid]
end

#qlenObject



96
97
98
99
100
101
# File 'lib/hts/bam/alignment.rb', line 96

def qlen
  FFI.bam_cigar2qlen(
    @b[:core][:n_cigar],
    FFI.bam_get_cigar(@b)
  )
end

#qnameObject

Read (query) name.



23
24
25
# File 'lib/hts/bam/alignment.rb', line 23

def qname
  FFI.bam_get_qname(@b).read_string
end

#rlenObject



103
104
105
106
107
108
# File 'lib/hts/bam/alignment.rb', line 103

def rlen
  FFI.bam_cigar2rlen(
    @b[:core][:n_cigar],
    FFI.bam_get_cigar(@b)
  )
end

#sequenceObject

return the read sequence



111
112
113
114
115
116
117
# File 'lib/hts/bam/alignment.rb', line 111

def sequence
  seq_nt16_str = '=ACMGRSVTWYHKDBN'
  r = FFI.bam_get_seq(@b)
  Array.new(@b[:core][:l_qseq]) do |i|
    seq_nt16_str[FFI.bam_seqi(r, i)]
  end.join
end

#startObject

returns 0-based start position.



56
57
58
# File 'lib/hts/bam/alignment.rb', line 56

def start
  @b[:core][:pos]
end

#stopObject

returns end position of the read.



61
62
63
# File 'lib/hts/bam/alignment.rb', line 61

def stop
  FFI.bam_endpos @b
end

#strandObject



73
74
75
# File 'lib/hts/bam/alignment.rb', line 73

def strand
  FFI.bam_is_rev(@b) ? '-' : '+'
end

#tagsObject



20
# File 'lib/hts/bam/alignment.rb', line 20

def tags; end

#tidObject

returns the tid of the alignment or -1 if not mapped.



46
47
48
# File 'lib/hts/bam/alignment.rb', line 46

def tid
  @b[:core][:tid]
end