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.



555
556
557
558
# File 'lib/bio/db/sam.rb', line 555

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

Instance Attribute Details

#alObject

Attributes from the format



573
574
575
# File 'lib/bio/db/sam.rb', line 573

def al
  @al
end

#calendObject

Attributes pulled with the C library



575
576
577
# File 'lib/bio/db/sam.rb', line 575

def calend
  @calend
end

#cigarObject

Attributes from the format



573
574
575
# File 'lib/bio/db/sam.rb', line 573

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



579
580
581
# File 'lib/bio/db/sam.rb', line 579

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



579
580
581
# File 'lib/bio/db/sam.rb', line 579

def first_in_pair
  @first_in_pair
end

#flagObject

Attributes from the format



573
574
575
# File 'lib/bio/db/sam.rb', line 573

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



579
580
581
# File 'lib/bio/db/sam.rb', line 579

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



579
580
581
# File 'lib/bio/db/sam.rb', line 579

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



579
580
581
# File 'lib/bio/db/sam.rb', line 579

def is_paired
  @is_paired
end

#isizeObject

Attributes from the format



573
574
575
# File 'lib/bio/db/sam.rb', line 573

def isize
  @isize
end

#mapqObject

Attributes from the format



573
574
575
# File 'lib/bio/db/sam.rb', line 573

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



579
580
581
# File 'lib/bio/db/sam.rb', line 579

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



579
580
581
# File 'lib/bio/db/sam.rb', line 579

def mate_unmapped
  @mate_unmapped
end

#mposObject

Attributes from the format



573
574
575
# File 'lib/bio/db/sam.rb', line 573

def mpos
  @mpos
end

#mrnmObject

Attributes from the format



573
574
575
# File 'lib/bio/db/sam.rb', line 573

def mrnm
  @mrnm
end

#posObject

Attributes from the format



573
574
575
# File 'lib/bio/db/sam.rb', line 573

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



579
580
581
# File 'lib/bio/db/sam.rb', line 579

def primary
  @primary
end

#qlenObject

Attributes pulled with the C library



575
576
577
# File 'lib/bio/db/sam.rb', line 575

def qlen
  @qlen
end

#qnameObject

Attributes from the format



573
574
575
# File 'lib/bio/db/sam.rb', line 573

def qname
  @qname
end

#qualObject

Attributes from the format



573
574
575
# File 'lib/bio/db/sam.rb', line 573

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



579
580
581
# File 'lib/bio/db/sam.rb', line 579

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



579
580
581
# File 'lib/bio/db/sam.rb', line 579

def query_unmapped
  @query_unmapped
end

#rnameObject

Attributes from the format



573
574
575
# File 'lib/bio/db/sam.rb', line 573

def rname
  @rname
end

#samstrObject

Attributes from the format



573
574
575
# File 'lib/bio/db/sam.rb', line 573

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



579
580
581
# File 'lib/bio/db/sam.rb', line 579

def second_in_pair
  @second_in_pair
end

#seqObject

Attributes from the format



573
574
575
# File 'lib/bio/db/sam.rb', line 573

def seq
  @seq
end

#tagsObject

Attributes from the format



573
574
575
# File 'lib/bio/db/sam.rb', line 573

def tags
  @tags
end

Class Method Details

.finalize(object_id) ⇒ Object



559
560
561
562
563
564
565
566
567
568
569
570
# File 'lib/bio/db/sam.rb', line 559

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



613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
# File 'lib/bio/db/sam.rb', line 613

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



581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
# File 'lib/bio/db/sam.rb', line 581

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