Last change
on this file since 798 was
797,
checked in by Maciej Komosinski, 7 years ago
|
A more complete implementation of fB, fH, fL
|
File size:
1.6 KB
|
Rev | Line | |
---|
[797] | 1 | // This file is a part of Framsticks SDK. http://www.framsticks.com/ |
---|
| 2 | // Copyright (C) 1999-2018 Maciej Komosinski and Szymon Ulatowski. |
---|
| 3 | // See LICENSE.txt for details. |
---|
| 4 | |
---|
[780] | 5 | #ifndef _FB_GENERAL_H_ |
---|
| 6 | #define _FB_GENERAL_H_ |
---|
| 7 | |
---|
| 8 | #include <frams/util/sstring.h> |
---|
| 9 | |
---|
| 10 | class fB_GenoHelpers |
---|
| 11 | { |
---|
| 12 | public: |
---|
| 13 | static int geneCount(SString geno) |
---|
| 14 | { |
---|
| 15 | int start = 0; |
---|
[797] | 16 | int prev = 0; |
---|
[780] | 17 | int count = -1; |
---|
| 18 | do { |
---|
| 19 | count++; |
---|
| 20 | start = geno.indexOf("aa", start) + 1; // +1 is for progress, starting codons can overlap |
---|
[797] | 21 | int quotecount = 0; |
---|
| 22 | for (int q = prev; q < start; q++) if (geno[q] == '\"') quotecount++; |
---|
| 23 | prev = start; |
---|
| 24 | if (quotecount % 2 != 0) count--; // 'aa' sequence is within quotes |
---|
[780] | 25 | } while (start - 1 != -1); |
---|
| 26 | return count; |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | static SString getGene(int i, SString genotype, int &start, int &end) |
---|
| 30 | { |
---|
| 31 | start = 0; |
---|
| 32 | int count = -1; |
---|
| 33 | do { |
---|
| 34 | count++; |
---|
| 35 | start = genotype.indexOf("aa", start) + 1; |
---|
[797] | 36 | int quotecount = 0; |
---|
| 37 | for (int q = 0; q < start; q++) if (genotype[q] == '\"') quotecount++; |
---|
| 38 | if (quotecount % 2 != 0) count--; // 'aa' sequence is within quotes |
---|
[780] | 39 | } while (start - 1 != -1 && count != i); |
---|
| 40 | if (start - 1 == -1) // there is no gene with a given "i" |
---|
| 41 | { |
---|
| 42 | start = -1; |
---|
| 43 | end = -1; |
---|
| 44 | return ""; |
---|
| 45 | } |
---|
| 46 | end = start; |
---|
[797] | 47 | int quotecount = 0; |
---|
| 48 | do { |
---|
| 49 | quotecount = 0; |
---|
| 50 | end = genotype.indexOf("zz", end); |
---|
| 51 | if (end != -1) |
---|
| 52 | { |
---|
| 53 | for (int q = start; q < end; q++) if (genotype[q] == '\"') quotecount++; |
---|
| 54 | if (quotecount % 2 != 0) end++; |
---|
| 55 | } |
---|
| 56 | } while (quotecount % 2 != 0 && end != -1); |
---|
| 57 | |
---|
[780] | 58 | if (end == -1) end = genotype.len(); |
---|
| 59 | else end += 2; |
---|
| 60 | start -= 1; |
---|
| 61 | return genotype.substr(start, end - start); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | private: |
---|
| 65 | fB_GenoHelpers() {} |
---|
| 66 | }; |
---|
| 67 | |
---|
| 68 | #endif // _FB_GENERAL_H_ |
---|
Note: See
TracBrowser
for help on using the repository browser.