// This file is a part of Framsticks SDK. http://www.framsticks.com/ // Copyright (C) 1999-2018 Maciej Komosinski and Szymon Ulatowski. // See LICENSE.txt for details. #ifndef _FB_GENERAL_H_ #define _FB_GENERAL_H_ #include class fB_GenoHelpers { public: static int geneCount(SString geno) { int start = 0; int prev = 0; int count = -1; do { count++; start = geno.indexOf("aa", start) + 1; // +1 is for progress, starting codons can overlap int quotecount = 0; for (int q = prev; q < start; q++) if (geno[q] == '\"') quotecount++; prev = start; if (quotecount % 2 != 0) count--; // 'aa' sequence is within quotes } while (start - 1 != -1); return count; } static SString getGene(int i, SString genotype, int &start, int &end) { start = 0; int count = -1; do { count++; start = genotype.indexOf("aa", start) + 1; int quotecount = 0; for (int q = 0; q < start; q++) if (genotype[q] == '\"') quotecount++; if (quotecount % 2 != 0) count--; // 'aa' sequence is within quotes } while (start - 1 != -1 && count != i); if (start - 1 == -1) // there is no gene with a given "i" { start = -1; end = -1; return ""; } end = start; int quotecount = 0; do { quotecount = 0; end = genotype.indexOf("zz", end); if (end != -1) { for (int q = start; q < end; q++) if (genotype[q] == '\"') quotecount++; if (quotecount % 2 != 0) end++; } } while (quotecount % 2 != 0 && end != -1); if (end == -1) end = genotype.len(); else end += 2; start -= 1; return genotype.substr(start, end - start); } private: fB_GenoHelpers() {} }; #endif // _FB_GENERAL_H_