// -*- 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 /// #ifndef __QSCORE_CACHE_HH #define __QSCORE_CACHE_HH #include #include struct qphred_cache { static double get_error_prob(const int qscore) { return qc().get_error_prob_imp(qscore); } static double get_lncompe(const int qscore) { return qc().get_lncompe_imp(qscore); } static double get_lne(const int qscore) { return qc().get_lne_imp(qscore); } static int get_mapped_qscore(const int basecall_qscore, const int mapping_qscore) { return qc().get_mapped_qscore_imp(basecall_qscore,mapping_qscore); } private: qphred_cache(); static const qphred_cache& qc() { static const qphred_cache qc; return qc; } void qscore_error(const int qscore) const; void qscore_check(const int qscore) const { if((qscore < 0) or (qscore > MAX_QSCORE)) qscore_error(qscore); } double get_error_prob_imp(const int qscore) const { qscore_check(qscore); return q2p[qscore]; } double get_lncompe_imp(const int qscore) const { qscore_check(qscore); return q2lncompe[qscore]; } double get_lne_imp(const int qscore) const { qscore_check(qscore); return q2lne[qscore]; } int get_mapped_qscore_imp(const int basecall_qscore, int mapping_qscore) const { qscore_check(basecall_qscore); assert(mapping_qscore>=0); if(mapping_qscore>MAX_MAP) { mapping_qscore=MAX_MAP; } return mappedq[mapping_qscore][basecall_qscore]; } enum { MAX_QSCORE = 70, MAX_MAP = 90 }; double q2p[MAX_QSCORE+1]; double q2lncompe[MAX_QSCORE+1]; double q2lne[MAX_QSCORE+1]; uint8_t mappedq[MAX_MAP+1][MAX_QSCORE+1]; }; struct qlogodds_cache { static double get_error_prob(const int qscore) { static const qlogodds_cache qc; return qc.get_error_prob_imp(qscore); } private: qlogodds_cache(); void qscore_error(const int qscore) const; double get_error_prob_imp(const int qscore) const { if((qscore < MIN_QSCORE) or (qscore > MAX_QSCORE)) qscore_error(qscore); return q2p[qscore]; } enum { MIN_QSCORE = -40, MAX_QSCORE = 70 }; double q2p_base[MAX_QSCORE+1-MIN_QSCORE]; double* const q2p; }; #endif