1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
#ifndef SEQUENCE_BIAS_MODEL
#define SEQUENCE_BIAS_MODEL
#include <mutex>
#include <atomic>
#include <memory>
// logger includes
#include "spdlog/spdlog.h"
#include "tbb/concurrent_vector.h"
#include "AtomicMatrix.hpp"
class Transcript;
class LibraryFormat;
class SequenceBiasModel {
public:
SequenceBiasModel(double alpha,
uint32_t windowSize=15 // must be odd
);
bool burnedIn();
void burnedIn(bool burnedIn);
/**
* For unpaired reads, update the bias model to account
* for this read
*/
bool update(Transcript& ref, int32_t pos,
LibraryFormat libFormat,
double mass, double prob);
/**
* For unpaired reads, update the bias model to account
* for this read
*/
bool update(Transcript& ref, int32_t pos, int32_t pos2,
LibraryFormat libFormat,
double mass, double prob);
/**
*
*
*/
double biasFactor(Transcript& ref, int32_t pos, LibraryFormat libFmt);
/**
*
*
*/
double biasFactor(Transcript& ref, int32_t pos1, int32_t pos2,
LibraryFormat libFormat);
void setLogger(std::shared_ptr<spdlog::logger> logger);
bool hasLogger();
std::string toString();
//void normalize();
private:
double seqProb(Transcript& ref, int32_t pos,
bool isFwd, AtomicMatrix<double>& profile);
/**
* These functions, which work directly on bam_seq_t* types, drive the
* update() and logLikelihood() methods above.
*/
bool update(Transcript& ref, int32_t pos,
bool fwd,
double mass, double prob, AtomicMatrix<double>& sequenceModel);
double biasFactor(Transcript& ref,
int32_t pos,
LibraryFormat libFormat,
AtomicMatrix<double>& foregroundModel,
AtomicMatrix<double>& backgroundModel);
// A, C, G, T
constexpr static uint32_t numBases() { return 4; }
// NOTE: Do these need to be concurrent_vectors as before?
// Store the mismatch probability tables for the left and right reads
AtomicMatrix<double> biasLeftForeground_;
AtomicMatrix<double> biasLeftBackground_;
AtomicMatrix<double> biasRightForeground_;
AtomicMatrix<double> biasRightBackground_;
uint32_t windowSize_;
bool isEnabled_;
std::atomic<bool> burnedIn_;
std::shared_ptr<spdlog::logger> logger_;
// Maintain a mutex in case we want to talk to the
// console / log.
std::mutex outputMutex_;
};
#endif // SEQUENCE_BIAS_MODEL
|