diff --git a/src/utility.cpp b/src/utility.cpp index becd918..76f6b6e 100644 --- a/src/utility.cpp +++ b/src/utility.cpp @@ -111,6 +111,24 @@ vector calcLLKs(const vector &refCount, return tmpLLKs; } +vector calcSiteLikelihoods(const vector &refCount, + const vector &altCount, + const vector &expectedWsaf, + size_t firstIndex, size_t length, + double fac, double err) { + assert(expectedWsaf.size() == length); + vector siteLikelihoods(length); + size_t index = firstIndex; + for (size_t i = 0; i < length; i++) { + assert(expectedWsaf[i] >= 0); + // assert (expectedWsaf[i] <= 1); + siteLikelihoods[i] = calcSiteLikelihood(refCount[index], altCount[index], + expectedWsaf[i], err, fac); + index++; + } + return siteLikelihoods; +} + log_double_t calcSiteLikelihood(double ref, double alt, double unadjustedWsaf, double err, double fac) { diff --git a/src/utility.hpp b/src/utility.hpp index 85d69f3..b5b6303 100644 --- a/src/utility.hpp +++ b/src/utility.hpp @@ -58,17 +58,34 @@ vector vecFromTo(const vector &vec, size_t start, size_t end) { template vector vecSum(const vector &vecA, const vector &vecB) { assert(vecA.size() == vecB.size()); - vector tmpSum(vecA.size(), (T)0); + vector tmpSum(vecA.size()); for (size_t i = 0; i < vecA.size(); i++) { tmpSum[i] = vecA[i] + vecB[i]; } return tmpSum; } +template +vector vecSum(const T &A, const vector &vecB) { + vector tmpSum(vecB.size()); + for (size_t i = 0; i < vecB.size(); i++) { + tmpSum[i] = A + vecB[i]; + } + return tmpSum; +} + +template +vector vecSum(const vector &vecA, const T &B) { + vector tmpSum(vecA.size()); + for (size_t i = 0; i < vecA.size(); i++) { + tmpSum[i] = vecA[i] + B; + } + return tmpSum; +} + template -vector vecProd(const vector &vecA, - const vector &vecB) { +vector vecProd(const vector &vecA, const vector &vecB) { assert(vecA.size() == vecB.size()); vector tmpProd(vecA.size()); for (size_t i = 0; i < vecA.size(); i++) { @@ -77,6 +94,24 @@ vector vecProd(const vector &vecA, return tmpProd; } +template +vector vecProd(const T &A, const vector &vecB) { + vector tmpProd(vecB.size()); + for (size_t i = 0; i < vecB.size(); i++) { + tmpProd[i] = A * vecB[i]; + } + return tmpProd; +} + +template +vector vecProd(const vector &vecA, const T& B) { + vector tmpProd(vecA.size()); + for (size_t i = 0; i < vecA.size(); i++) { + tmpProd[i] = vecA[i] * B; + } + return tmpProd; +} + template T sumOfVec(const vector & array ) { @@ -87,6 +122,15 @@ T sumOfVec(const vector & array ) { return tmp; } +template +T sum(const std::vector & array ) { + T tmp = 0; + for (auto const& value : array) { + tmp += value; + } + return tmp; +} + template T product(const std::vector& xs) { @@ -143,6 +187,10 @@ vector calcLLKs(const vector &refCount, const vector &altCount, const vector &expectedWsaf, size_t firstIndex, size_t length, double fac, double err = 0.01); +vector calcSiteLikelihoods(const vector &refCount, + const vector &altCount, + const vector &expectedWsaf, size_t firstIndex, size_t length, + double fac, double err = 0.01); log_double_t calcSiteLikelihood(double ref, double alt, double unadjustedWsaf, double err, double fac); size_t sampleIndexGivenProp(RandomGenerator* rg, vector proportion);