lib/cheripic/bfr.rb in cheripic-1.0.0 vs lib/cheripic/bfr.rb in cheripic-1.1.0
- old
+ new
@@ -1,19 +1,29 @@
# encoding: utf-8
module Cheripic
+ # Custom error handling for Bfr class
class BfrError < CheripicError; end
+ # A class to calculate bulk frequency ratio (bfr) using one or two hashes of base fractions resulted from pileup
+ #
+ # @!attribute [rw] bfr_adj
+ # @return [Float] a float value to adjust the bfr calculation
class Bfr
attr_accessor :bfr_adj
- # get bulk frequency ratio (bfr) for marked hemi snps only
- # ignore positions with complex variants
+ # A method to get bulk frequency ratio (bfr) for selected hemi snps.
+ # This is done by selecting which hash (mutant or background) to use for bfr calculation
+ # either calculates fraction or bfr
+ # and ignores positions with complex variants.
+ # @param mut_hash [Hash] a hash of base fractions from pileup of mutant bulk
+ # @param bg_hash [Hash] a hash of base fractions from pileup of background bulk
+ # @return [Float] a ratio calculated
def self.get_bfr(mut_hash, bg_hash='')
- @bfr_adj = Options.params.bfr_adjust
+ @bfr_adj = Options.bfr_adjust
if bg_hash != ''
# checking if only two vars in base hash and that includes ref
# checking if only one var in hemi snp
# suggests enrichment for one of two alleles
if mut_hash.length == 2 and mut_hash.key?(:ref)
@@ -35,13 +45,16 @@
bfr = ''
end
bfr
end
- # calculate bfr using both mutant and background bulk information
+ # A method to calculate bfr using a base fraction hash with hemi-snp
+ # @param two_key_hash [Hash] a hash of base fractions from pileup with 2 keys (a ref and variant base)
+ # @param other_hash [Hash] a hash of base fractions from pileup
+ # @return [Float] a ratio calculated
def self.calculate_bfr(two_key_hash, other_hash)
- # fix :ref value if absent due to below noise depth
+ # if :ref is absent such as below noise depth, then set to zero
unless two_key_hash.key?(:ref)
two_key_hash[:ref] = 0
end
unless other_hash.key?(:ref)
other_hash[:ref] = 0
@@ -61,9 +74,12 @@
bfr = frac_2/frac_1
end
bfr
end
+ # A method to calculate ratio using a base fraction hash
+ # @param hash [Hash] a hash of base fractions from pileup with 2 or 1 keys
+ # @return [Array<Float><String>] an array of ratio calculated and base character
def self.calc_fraction(hash)
unless hash.key?(:ref)
hash[:ref] = 0
end
array = hash.keys