diff --git a/core/match_types.cpp b/core/match_types.cpp index 8006e77..c2a9761 100644 --- a/core/match_types.cpp +++ b/core/match_types.cpp @@ -1,12 +1,13 @@ #include #include +#include #include "match_types.h" namespace MOODS { variant::variant(){} - variant::variant(size_t s, size_t e, std::string seq): start_pos(s), end_pos(e), modified_seq(seq) {} + variant::variant(size_t s, size_t e, std::string seq): start_pos(s), end_pos(e), modified_seq(std::move(seq)) {} } \ No newline at end of file diff --git a/core/moods_scan.cpp b/core/moods_scan.cpp index 1c19b3b..492b19c 100644 --- a/core/moods_scan.cpp +++ b/core/moods_scan.cpp @@ -94,8 +94,6 @@ namespace MOODS { namespace scan{ } } - bool done = 0; - int iteration = 0; @@ -249,7 +247,7 @@ namespace MOODS { namespace scan{ } for (size_t j = 0; j < cols; ++j){ - CODE = MASK & (CODE << SHIFT) | alphabet_map[seq[i+j+q-1]]; + CODE = (MASK & (CODE << SHIFT)) | alphabet_map[seq[i+j+q-1]]; score += matrix[CODE][j]; } diff --git a/core/moods_tools.cpp b/core/moods_tools.cpp index e7ed9ee..f039289 100644 --- a/core/moods_tools.cpp +++ b/core/moods_tools.cpp @@ -141,35 +141,35 @@ double threshold_from_p_with_precision(const score_matrix &pssm, const vector > mat(a, vector(n)); + vector > mat(a, vector(n)); - long maxT = 0; - long minV = std::numeric_limits::max(); + size_t maxT = 0; + size_t minV = std::numeric_limits::max(); for (size_t i = 0; i < n; ++i) { for (size_t j = 0; j < a; ++j) { if (pssm[j][i] > 0.0){ - mat[j][i] = (long) ( precision * pssm[j][i] + 0.5 ); + mat[j][i] = (size_t) ( precision * pssm[j][i] + 0.5 ); } else { - mat[j][i] = (long) ( precision * pssm[j][i] - 0.5 ); + mat[j][i] = (size_t) ( precision * pssm[j][i] - 0.5 ); } } } for (size_t i = 0; i < n; ++i) { - long max = mat[0][i]; - long min = max; + size_t max = mat[0][i]; + size_t min = max; for (size_t j = 1; j < a; ++j) { - long v = mat[j][i]; + size_t v = mat[j][i]; if (max < v) max = v; else if (min > v) @@ -180,7 +180,7 @@ double threshold_from_p_with_precision(const score_matrix &pssm, const vector table0(R + 1, 0.0); vector table1(R + 1, 0.0); @@ -193,10 +193,10 @@ double threshold_from_p_with_precision(const score_matrix &pssm, const vector= 0; --r) + for (size_t r = R-1; r != ((size_t)-1); --r) { sum += table0[r]; if (sum > p) @@ -439,8 +439,8 @@ double min_score(const score_matrix &mat, const size_t a){ double threshold_from_p_with_precision(const score_matrix &pssm, const vector &bg, const double &p, const double precision, const size_t a) { - long rows = pssm.size(); - long cols = pssm[0].size(); + size_t rows = pssm.size(); + size_t cols = pssm[0].size(); unsigned int q = MOODS::misc::q_gram_size(rows, a); @@ -449,20 +449,20 @@ double threshold_from_p_with_precision(const score_matrix &pssm, const vector > mat(rows, vector(cols)); + vector > mat(rows, vector(cols)); - long maxT = 0; - long minV = std::numeric_limits::max(); + size_t maxT = 0; + size_t minV = std::numeric_limits::max(); for (size_t i = 0; i < cols; ++i) { for (size_t CODE = 0; CODE < rows; ++CODE) { if (pssm[CODE][i] > 0.0){ - mat[CODE][i] = (long) ( precision * pssm[CODE][i] + 0.5 ); + mat[CODE][i] = (size_t) ( precision * pssm[CODE][i] + 0.5 ); } else { - mat[CODE][i] = (long) ( precision * pssm[CODE][i] - 0.5 ); + mat[CODE][i] = (size_t) ( precision * pssm[CODE][i] - 0.5 ); } } } @@ -470,11 +470,11 @@ double threshold_from_p_with_precision(const score_matrix &pssm, const vector v) @@ -485,7 +485,7 @@ double threshold_from_p_with_precision(const score_matrix &pssm, const vector> table0(Q_CODE_SIZE, vector(R + 1, 0)); @@ -508,8 +508,8 @@ double threshold_from_p_with_precision(const score_matrix &pssm, const vector> SHIFT) & Q_MASK; bits_t CODE_SUFFIX = CODE & Q_MASK; bits_t CHAR = CODE & A_MASK; - long s = mat[CODE][i] - minV; - for (long r = s; r <= R; ++r) + size_t s = mat[CODE][i] - minV; + for (size_t r = s; r <= R; ++r) table1[CODE_SUFFIX][r] += bg[CHAR] * table0[CODE_PREFIX][r - s]; } table0 = table1; @@ -517,7 +517,7 @@ double threshold_from_p_with_precision(const score_matrix &pssm, const vector table2(R+1, 0.0); - for (long r = 0; r < R+1; ++r){ + for (size_t r = 0; r < R+1; ++r){ for (bits_t CODE = 0; CODE < Q_CODE_SIZE; ++CODE){ table2[r] += table0[CODE][r]; } @@ -530,7 +530,7 @@ double threshold_from_p_with_precision(const score_matrix &pssm, const vector= 0; --r) + for (size_t r = R-1; r >= 0; --r) { sum += table2[r]; if (sum > p) @@ -585,7 +585,7 @@ vector snp_variants(const std::string &seq){ for (size_t i = 0; i < seq.size(); ++i){ for (size_t j = 0; j < snp_alt[seq[i]].size(); ++j){ - ret.push_back(variant{i,i+1,snp_alt[seq[i]].substr(j,1)}); + ret.emplace_back(i,i+1,snp_alt[seq[i]].substr(j,1)); } } diff --git a/core/motif.h b/core/motif.h index 4086f85..edd066f 100644 --- a/core/motif.h +++ b/core/motif.h @@ -23,6 +23,8 @@ class Motif { virtual unsigned int alphabet_size() = 0; virtual unsigned int window_pos() = 0; virtual double threshold() = 0; + + virtual ~Motif() = default; }; diff --git a/core/motif_0.cpp b/core/motif_0.cpp index 6e1aaeb..34f2ee5 100644 --- a/core/motif_0.cpp +++ b/core/motif_0.cpp @@ -25,17 +25,17 @@ vector expected_differences(const score_matrix &mat, const vector ret(m); - for (int i = 0; i < m; ++i) + for (size_t i = 0; i < m; ++i) { double max = -std::numeric_limits::infinity(); - for (int j = 0; j < a; ++j) + for (size_t j = 0; j < a; ++j) { max = std::max(max, mat[j][i]); } ret[i] = max; - for (int j = 0; j < a; ++j) + for (size_t j = 0; j < a; ++j) { ret[i] -= bg[j] * mat[j][i]; } @@ -59,9 +59,9 @@ unsigned int window_position(const vector &ed, unsigned int l, unsigned } double max = current; - int window_pos = 0; + unsigned int window_pos = 0; - for (int i = 0; i < m - l; ++i) + for (unsigned int i = 0; i < m - l; ++i) { current -= ed[i]; current += ed[i+l]; @@ -93,11 +93,11 @@ vector compute_lookahead_order(const vector &ed, unsigned else { vector order(m-l, 0); - for (int i = 0; i < window_pos; ++i) + for (unsigned int i = 0; i < window_pos; ++i) { order[i] = i; } - for (int i = window_pos+l; i < m; ++i) + for (unsigned int i = window_pos+l; i < m; ++i) { order[i-l] = i; } @@ -122,7 +122,7 @@ vector compute_lookahead_scores(const score_matrix &mat, const vector scores(m-l,0); double total = 0; - for (int i = m-l-1; i >= 0; --i) + for (unsigned int i = m-l-1; i != ((unsigned int)-1); --i) { double max = -std::numeric_limits::infinity(); for (unsigned int j = 0; j < a; ++j) diff --git a/core/motif_h.cpp b/core/motif_h.cpp index 669dfba..2b44db3 100644 --- a/core/motif_h.cpp +++ b/core/motif_h.cpp @@ -23,8 +23,8 @@ vector MotifH::expected_scores(const vector &bg){ const bits_t A_MASK = (1 << (SHIFT)) - 1; vector ret(cols, 0); - for (int i = 0; i < cols; ++i){ - for (int j = 0; j < rows; ++j){ + for (unsigned int i = 0; i < cols; ++i){ + for (unsigned int j = 0; j < rows; ++j){ double bg_prop = 1; for (unsigned int k = 0; k < q; ++k){ bg_prop *= bg[A_MASK & (j >> (SHIFT * (q - 1 - k)))]; @@ -39,7 +39,10 @@ vector MotifH::expected_scores(const vector &bg){ vector> MotifH::max_scores_f(size_t start, size_t end){ - double wsize = end - start; + size_t wsize = end - start; + if (end <= start) { + wsize = 0; + } vector> max_scores (wsize, vector (Q_CODE_SIZE, 0)); if (end > start){ @@ -47,7 +50,7 @@ vector> MotifH::max_scores_f(size_t start, size_t end){ max_scores[0][j & Q_MASK] = std::max(mat[j][start], max_scores[0][j & Q_MASK]); } - for (unsigned int i = 1 ; i < wsize; ++i){ + for (size_t i = 1 ; i < wsize; ++i){ for (unsigned int j = 0; j < rows; ++j){ max_scores[i][j & Q_MASK] = std::max(mat[j][i+start] + max_scores[i-1][j >> SHIFT], max_scores[i][j & Q_MASK]); } @@ -59,7 +62,10 @@ vector> MotifH::max_scores_f(size_t start, size_t end){ vector> MotifH::max_scores_b(size_t start, size_t end){ - double wsize = end - start; + size_t wsize = end - start; + if (end <= start) { + wsize = 0; + } vector> max_scores (wsize, vector (Q_CODE_SIZE, 0)); @@ -70,7 +76,7 @@ vector> MotifH::max_scores_b(size_t start, size_t end){ max_scores[wsize-1][j >> SHIFT] = std::max(mat[j][end-1], max_scores[wsize-1][j >> SHIFT]); } - for (unsigned int i = 1; i < wsize; ++i){ + for (size_t i = 1; i < wsize; ++i){ for (unsigned int j = 0; j < rows; ++j){ max_scores[wsize-i-1][j >> SHIFT] = std::max(mat[j][end-i-1] + max_scores[wsize-i][j & Q_MASK], max_scores[wsize-i-1][j >> SHIFT]); @@ -253,7 +259,7 @@ std::pair MotifH::check_hit(const std::string& s, const vector