Class: Bio::DB::Alignment

Inherits:
Object
  • Object
show all
Defined in:
lib/bio/db/sam.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAlignment

Returns a new instance of Alignment.



229
230
231
232
# File 'lib/bio/db/sam.rb', line 229

def initialize
  ObjectSpace.define_finalizer(self,
  self.class.method(:finalize).to_proc)
end

Instance Attribute Details

#alObject

Attributes from the format



247
248
249
# File 'lib/bio/db/sam.rb', line 247

def al
  @al
end

#calendObject

Attributes pulled with the C library



249
250
251
# File 'lib/bio/db/sam.rb', line 249

def calend
  @calend
end

#cigarObject

Attributes from the format



247
248
249
# File 'lib/bio/db/sam.rb', line 247

def cigar
  @cigar
end

#failed_qualityObject

Attrobites frp, the flag field (see chapter 2.2.2 of the sam file documentation) query_strand and mate_strand are true if they are forward. It is the opposite to the definition in the BAM format for clarity. primary is the negation of is_negative from the BAM format



253
254
255
# File 'lib/bio/db/sam.rb', line 253

def failed_quality
  @failed_quality
end

#first_in_pairObject

Attrobites frp, the flag field (see chapter 2.2.2 of the sam file documentation) query_strand and mate_strand are true if they are forward. It is the opposite to the definition in the BAM format for clarity. primary is the negation of is_negative from the BAM format



253
254
255
# File 'lib/bio/db/sam.rb', line 253

def first_in_pair
  @first_in_pair
end

#flagObject

Attributes from the format



247
248
249
# File 'lib/bio/db/sam.rb', line 247

def flag
  @flag
end

#is_duplicateObject

Attrobites frp, the flag field (see chapter 2.2.2 of the sam file documentation) query_strand and mate_strand are true if they are forward. It is the opposite to the definition in the BAM format for clarity. primary is the negation of is_negative from the BAM format



253
254
255
# File 'lib/bio/db/sam.rb', line 253

def is_duplicate
  @is_duplicate
end

#is_mappedObject

Attrobites frp, the flag field (see chapter 2.2.2 of the sam file documentation) query_strand and mate_strand are true if they are forward. It is the opposite to the definition in the BAM format for clarity. primary is the negation of is_negative from the BAM format



253
254
255
# File 'lib/bio/db/sam.rb', line 253

def is_mapped
  @is_mapped
end

#is_pairedObject

Attrobites frp, the flag field (see chapter 2.2.2 of the sam file documentation) query_strand and mate_strand are true if they are forward. It is the opposite to the definition in the BAM format for clarity. primary is the negation of is_negative from the BAM format



253
254
255
# File 'lib/bio/db/sam.rb', line 253

def is_paired
  @is_paired
end

#isizeObject

Attributes from the format



247
248
249
# File 'lib/bio/db/sam.rb', line 247

def isize
  @isize
end

#mapqObject

Attributes from the format



247
248
249
# File 'lib/bio/db/sam.rb', line 247

def mapq
  @mapq
end

#mate_strandObject

Attrobites frp, the flag field (see chapter 2.2.2 of the sam file documentation) query_strand and mate_strand are true if they are forward. It is the opposite to the definition in the BAM format for clarity. primary is the negation of is_negative from the BAM format



253
254
255
# File 'lib/bio/db/sam.rb', line 253

def mate_strand
  @mate_strand
end

#mate_unmappedObject

Attrobites frp, the flag field (see chapter 2.2.2 of the sam file documentation) query_strand and mate_strand are true if they are forward. It is the opposite to the definition in the BAM format for clarity. primary is the negation of is_negative from the BAM format



253
254
255
# File 'lib/bio/db/sam.rb', line 253

def mate_unmapped
  @mate_unmapped
end

#mposObject

Attributes from the format



247
248
249
# File 'lib/bio/db/sam.rb', line 247

def mpos
  @mpos
end

#mrnmObject

Attributes from the format



247
248
249
# File 'lib/bio/db/sam.rb', line 247

def mrnm
  @mrnm
end

#posObject

Attributes from the format



247
248
249
# File 'lib/bio/db/sam.rb', line 247

def pos
  @pos
end

#primaryObject

Attrobites frp, the flag field (see chapter 2.2.2 of the sam file documentation) query_strand and mate_strand are true if they are forward. It is the opposite to the definition in the BAM format for clarity. primary is the negation of is_negative from the BAM format



253
254
255
# File 'lib/bio/db/sam.rb', line 253

def primary
  @primary
end

#qlenObject

Attributes pulled with the C library



249
250
251
# File 'lib/bio/db/sam.rb', line 249

def qlen
  @qlen
end

#qnameObject

Attributes from the format



247
248
249
# File 'lib/bio/db/sam.rb', line 247

def qname
  @qname
end

#qualObject

Attributes from the format



247
248
249
# File 'lib/bio/db/sam.rb', line 247

def qual
  @qual
end

#query_strandObject

Attrobites frp, the flag field (see chapter 2.2.2 of the sam file documentation) query_strand and mate_strand are true if they are forward. It is the opposite to the definition in the BAM format for clarity. primary is the negation of is_negative from the BAM format



253
254
255
# File 'lib/bio/db/sam.rb', line 253

def query_strand
  @query_strand
end

#query_unmappedObject

Attrobites frp, the flag field (see chapter 2.2.2 of the sam file documentation) query_strand and mate_strand are true if they are forward. It is the opposite to the definition in the BAM format for clarity. primary is the negation of is_negative from the BAM format



253
254
255
# File 'lib/bio/db/sam.rb', line 253

def query_unmapped
  @query_unmapped
end

#rnameObject

Attributes from the format



247
248
249
# File 'lib/bio/db/sam.rb', line 247

def rname
  @rname
end

#samstrObject

Attributes from the format



247
248
249
# File 'lib/bio/db/sam.rb', line 247

def samstr
  @samstr
end

#second_in_pairObject

Attrobites frp, the flag field (see chapter 2.2.2 of the sam file documentation) query_strand and mate_strand are true if they are forward. It is the opposite to the definition in the BAM format for clarity. primary is the negation of is_negative from the BAM format



253
254
255
# File 'lib/bio/db/sam.rb', line 253

def second_in_pair
  @second_in_pair
end

#seqObject

Attributes from the format



247
248
249
# File 'lib/bio/db/sam.rb', line 247

def seq
  @seq
end

#tagsObject

Attributes from the format



247
248
249
# File 'lib/bio/db/sam.rb', line 247

def tags
  @tags
end

Class Method Details

.finalize(object_id) ⇒ Object



233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/bio/db/sam.rb', line 233

def Alignment.finalize(object_id)

  #           puts "Object #{object_id} dying at #{Time.new}"
  #             p  "?" . object_id.al
  #            p object_id.al
  LibC.free object_id.al
  LibC.free object_id.sam
  LibC.free object_id.calend
  LibC.free object_id.qlen

  LibC.free object_id.samstr
end

Instance Method Details

#sam=(sam) ⇒ Object



287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/bio/db/sam.rb', line 287

def sam=(sam)
  #p sam
  s = sam.split("\t")
  self.qname = s[0]
  self.flag  = s[1].to_i
  self.rname = s[2]
  self.pos   = s[3].to_i
  self.mapq  = s[4].to_i
  self.cigar = s[5]
  self.mrnm  = s[6]
  self.mpos  = s[7].to_i
  self.isize = s[8].to_i
  self.seq   = s[9]
  self.qual =  s[10]
  self.tags = {} 
  11.upto(s.size-1) {|n| 
    t = Tag.new 
    t.set(s[n])
    tags[t.tag] = t
  }


  #<QNAME> <FLAG> <RNAME> <POS> <MAPQ> <CIGAR> <MRNM> <MPOS> <ISIZE> <SEQ> <QUAL> \
  #[<TAG>:<VTYPE>:<VALUE> [...]] 

end

#set(bam_alignment, header) ⇒ Object



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/bio/db/sam.rb', line 255

def set(bam_alignment, header)
  #Create the FFI object
  @al = Bio::DB::SAM::Tools::Bam1T.new(bam_alignment) 

  #set the raw data
  tmp_str =  Bio::DB::SAM::Tools.bam_format1(header,al)
  #self.sam =  tmp_str
  #ObjectSpace.define_finalizer(self, proc {|id| puts "Finalizer one on #{id}" })
  self.sam = String.new(tmp_str)
  #LibC.free tmp_str
  #Set values calculated by libbam
  core = al[:core]
  cigar = al[:data][core[:l_qname]]#define bam1_cigar(b) ((uint32_t*)((b)->data + (b)->core.l_qname)) 
  @calend = Bio::DB::SAM::Tools.bam_calend(core,cigar)
  @qlen = Bio::DB::SAM::Tools.bam_cigar2qlen(core,cigar)

  #process the flags
  @is_paired             = @flag & 0x0001 > 0
  @is_mapped             = @flag & 0x0002 > 0
  @query_unmapped        = @flag & 0x0004 > 0
  @mate_unmapped         = @flag & 0x0008 > 0
  @query_strand          = !(@flag & 0x0010 > 0)
  @mate_strand           = !(@flag & 0x0020 > 0)
  @first_in_pair         = @flag & 0x0040 > 0
  @second_in_pair        = @flag & 0x0080 > 0
  @primary               = !(@flag & 0x0100 > 0)
  @failed_quality        = @flag & 0x0200 > 0
  @is_duplicate          = @flag & 0x0400 > 0

end