# File lib/bio/db/sam.rb, line 417
      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