// -*- mode: c++; indent-tabs-mode: nil; -*- // // Copyright 2009 Illumina, Inc. // // This software is covered by the "Illumina Genome Analyzer Software // License Agreement" and the "Illumina Source Code License Agreement", // and certain third party copyright/licenses, and any user of this // source file is bound by the terms therein (see accompanying files // Illumina_Genome_Analyzer_Software_License_Agreement.pdf and // Illumina_Source_Code_License_Agreement.pdf and third party // copyright/license notices). // // /// \file /// \author Chris Saunders /// #include "position_loghood_minfunc.hh" #include "blt_util/log.hh" #include #include #include #include const double onethird(1./3.); /// /// likelihood function is P(obs|model) /// where the model parameter is the reference allele frequency /// /// this becomes: /// sum{ s in seqs } { P(obs|s) * P(s|model) } /// /// a direct expansion would look like: /// L = P(obs=TC|true=AA) * P(true=AA|freq=.9)+ /// P(obs=TC|true=AC) * P(true=AC|freq=.9)+... /// /// L = P(e1)/3*P(e2)/3*.1/3*.1/3 + /// P(e1)/3*(1-P(e2))*.1/3*.9 +... /// /// ...where P(e1) is the error prob for basecall 1 and P(e2) is the error /// prob for basecall 2. /// /// The above sequence can be factored into: /// prod { pos in column_size } { P(A|pos,model)+P(C|pos,model)+... } /// double calc_pos_nonref_freq_loghood(const snp_pos_info& pi, const double nonref_freq){ if((nonref_freq < 0.) or (nonref_freq > 1.)){ log_os << "ERROR:: invalid probability value: " << nonref_freq << "\n"; exit(EXIT_FAILURE); } const unsigned n_calls(pi.calls.size()); double loghood(0.); const uint8_t ref_id(base_to_id(pi.ref_base)); for(unsigned i(0);i(pf)%2){ prob=1.-prob; } return prob; } /// same as above but allow separate frequencies for all nucleotides: /// static double calc_pos_allele_distro_loghood(const snp_pos_info& pi, const double* allele_distro, const unsigned n_allele, const unsigned* allele_map){ // minimization parameters should already be normalized: for(unsigned i(0);i 1.)){ log_os << "ERROR:: invalid probability value: " << allele_distro[i] << "\n"; exit(EXIT_FAILURE); } } const unsigned n_calls(pi.calls.size()); double loghood(0.); for(unsigned i(0);i=0.); if(sum>0.){ const double scale(1./sum); for(unsigned i(0);i<_n_allele;++i) allele_distro[i] *= scale; } else { static const double allele_expect(1./static_cast(_n_allele)); for(unsigned i(0);i<_n_allele;++i) allele_distro[i] = allele_expect; } }