#include #include "tools.h" string seed_contiguous(int k) { string seed = "" ; for (int i = 0; i < k; i++) seed += SEED_YES; return seed ; } int seed_weight(const string &seed) { return count(seed.begin(), seed.end(), SEED_YES); } char spaced_buf[MAX_SEED_SIZE+1]; string spaced(const string &input, const string &seed) { // #ifdef STATIC_SPACED_SEED_FOURTEEN // return input.substr(0, 7) + input.substr(8, 7); // #endif #ifdef NO_SPACED_SEEDS return input ; #endif int j = 0 ; // cout << input << endl << seed << endl ; assert(input.length() == seed.length()); for (size_t i = 0; i < input.length(); i++) if (seed[i] == SEED_YES) spaced_buf[j++] = input[i] ; spaced_buf[j] = (char) 0; #ifdef DEBUG_SPACED cout << input << " => |" << spaced_buf << "|" << endl ; #endif return string(spaced_buf); } string string_of_int(int number) { stringstream ss; ss << number ; return ss.str(); } string scientific_string_of_double(double number) { stringstream ss; ss << scientific << number ; return ss.str(); } bool is_extended_nucleotide(char nuc) { switch(nuc) { case 'A': case 'a': case 'C': case 'c': case 'G': case 'g': case 'T': case 't': return false ; default: return true; } } bool has_extended_nucleotides(string s) { for (unsigned int i = 0; i 0 && (str[str.size() - 1] == '\r' || str[str.size()-1] == ' ' || str[str.size()-1] == '\t')) { count++; str.resize(str.size() - 1); } return count; } string revcomp(const string &dna, bool do_revcomp) { if (!do_revcomp) return dna; string rcomp(dna); for (size_t i = 0; i < dna.length(); i++) { rcomp[dna.length() - i - 1] = complement_nucleotide(dna[i]); } // cout << dna << " " << dna.length() << " " << rcomp << " " << rcomp.length() << endl ; return rcomp; } int revcomp_int(int word, int size) { int revcomp = 0; while (size) { revcomp <<= 2; revcomp |= (word & 3) ^ 3; word >>= 2; size--; } return revcomp; } string reverse(const string &text) { return string(text.rbegin(), text.rend()); } double nChoosek_stored[NB_N_CHOOSE_K_STORED][NB_N_CHOOSE_K_STORED] = {}; double nChoosek(unsigned n, unsigned k) { if (k > n) return 0; if (k * 2 > n) k = n-k; if (k == 0) return 1; if (n >= NB_N_CHOOSE_K_STORED || nChoosek_stored[n][k] == 0) { double result = 1; unsigned i; for (i = 0; i < k && ((n-i) >= NB_N_CHOOSE_K_STORED || nChoosek_stored[n-i][k-i] == 0); i++ ) { result *= (n - i)*1./(k - i); } if (i < k) { result *= nChoosek_stored[n-i][k-i]; } if (n < NB_N_CHOOSE_K_STORED) nChoosek_stored[n][k] = result; return result; } return nChoosek_stored[n][k]; }