Class: Bio::BFRTools::BFRContainer

Inherits:
Container
  • Object
show all
Defined in:
lib/bio/BFRTools.rb

Constant Summary

Constants inherited from Container

Container::BASES

Instance Attribute Summary

Attributes inherited from Container

#bulk_1_name, #bulk_1_sam, #bulk_2_name, #bulk_2_sam, #parental_1_name, #parental_1_sam, #parental_2_name, #parental_2_sam, #processed_regions, #putative_snps, #reference_db, #total_length

Instance Method Summary collapse

Methods inherited from Container

#bulk_1, #bulk_2, #parental_1, #parental_2, #reference, #reference_sequence, snps_between

Instance Method Details

#get_region(opts = {}) ⇒ Object



386
387
388
389
# File 'lib/bio/BFRTools.rb', line 386

def get_region(opts={})
  opts[:container] = self
  region = BFRRegion.new(opts)
end

#init_countersObject



362
363
364
365
366
367
368
369
370
371
372
# File 'lib/bio/BFRTools.rb', line 362

def init_counters
  @putative_snps      = 0
  @proccesed_regions  = 0
  @not_enogh_coverage = 0
  @total_avg_coverage_bulk_1 = 0.0
  @total_avg_coverage_bulk_2 = 0.0
  @total_snp_1kbp = 0.0
  @no_snps = 0
  @too_many_snps = 0

end


373
374
375
376
# File 'lib/bio/BFRTools.rb', line 373

def print_header(opts={}) 
  output = opts[:output_file_stats] ? opts[:output_file_stats] : $stderr
  output.print "#bulk_1\tbulk_2\tProcessed_regions\tputative_snps\tno_snps\ttoo_many_snps\tno_enough_coverage\tavg_cov_bulk_1\tavg_cov_bulk_2\tavg_snp_1kbp\n"
end


378
379
380
381
382
383
384
# File 'lib/bio/BFRTools.rb', line 378

def print_stats(opts={}) 
  output = opts[:output_file_stats] ? opts[:output_file_stats] : $stderr
  output.print @bulk_1_name, "\t", @bulk_2_name, "\t"
  output.print @proccesed_regions, "\t", @putative_snps, "\t", @no_snps, "\t", @too_many_snps,"\t", @not_enogh_coverage, "\t"
  output.print @total_avg_coverage_bulk_1/@proccesed_regions, "\t",@total_avg_coverage_bulk_2/@proccesed_regions, "\t" 
  output.print @total_snp_1kbp / @proccesed_regions,"\n"
end

#process_region(opts = {}) ⇒ Object



391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
# File 'lib/bio/BFRTools.rb', line 391

def process_region(opts={})        
  opts = { :min_cov=>20, :max_snp_1kbp => 10, :max_per=>0.20 }.merge!(opts)

  @proccesed_regions += 1
  output = opts[:output_file] ? opts[:output_file] : $stdout
  print_output = opts[:output_file] ? true : false
  opts[:container] = self

  region = BFRRegion.new(opts)

  #puts region.to_multi_fasta

  @total_snp_1kbp += region.snp_1kbp 
 # puts "SNPS: #{region.snp_1kbp}"
  if region.snp_count == 0
    @no_snps += 1 
    print_output = false 
  end

  if region.snp_1kbp  > opts[:max_snp_1kbp]
    @too_many_snps += 1
    print_output = false
  end



  @total_avg_coverage_bulk_2 += region.avg_cov_bulk_2
  @total_avg_coverage_bulk_1 += region.avg_cov_bulk_1

  if region.avg_cov_bulk_2 < opts[:min_cov] or region.avg_cov_bulk_1 < opts[:min_cov]
    @not_enogh_coverage += 1
    print_output = false
  end

  info = Array.new

  if print_output
    for i in (0..region.size-1)
      if region.coverages_1[i] > opts[:min_cov] and region.coverages_2[i] > opts[:min_cov]
        BASES.each do |base|

          info.clear
          if  Bio::NucleicAcid.is_valid( region.parental_1_sequence[i],  base.to_s  ) and 
            not  Bio::NucleicAcid.is_valid( region.parental_2_sequence[i],  base.to_s  )
            info << :first
          end

          if   Bio::NucleicAcid.is_valid( region.parental_2_sequence[i],  base.to_s  ) and 
            not Bio::NucleicAcid.is_valid( region.parental_1_sequence[i],  base.to_s  )
            info << :second
          end


          for informative in info
            line = region.get_bfr_line(i, base, informative)
            output.print  line , "\n"
          end
        end
      end
    end
  end


  @parental_1_sam.mpileup_clear_cache region
  @parental_2_sam.mpileup_clear_cache region
  @bulk_2_sam.mpileup_clear_cache region
  @bulk_1_sam.mpileup_clear_cache region
  return region
end