Next version of JABA
[jabaws.git] / binaries / src / muscle / mhack.cpp
1 #include "muscle.h"\r
2 #include "seqvect.h"\r
3 #include "msa.h"\r
4 \r
5 /***\r
6 Methionine hack.\r
7 Most proteins start with M.\r
8 This results in odd-looking alignments with the terminal Ms aligned followed\r
9 immediately by gaps.\r
10 Hack this by treating terminal M like X.\r
11 ***/\r
12 \r
13 static bool *M;\r
14 \r
15 void MHackStart(SeqVect &v)\r
16         {\r
17         if (ALPHA_Amino != g_Alpha)\r
18                 return;\r
19 \r
20         const unsigned uSeqCount = v.Length();\r
21         M = new bool[uSeqCount];\r
22         memset(M, 0, uSeqCount*sizeof(bool));\r
23         for (unsigned uSeqIndex = 0; uSeqIndex < uSeqCount; ++uSeqIndex)\r
24                 {\r
25                 Seq &s = v.GetSeq(uSeqIndex);\r
26                 if (0 == s.Length())\r
27                         continue;\r
28                 unsigned uId = s.GetId();\r
29                 if (s[0] == 'M' || s[0] == 'm')\r
30                         {\r
31                         M[uId] = true;\r
32                         s[0] = 'X';\r
33                         }\r
34                 }\r
35         }\r
36 \r
37 void MHackEnd(MSA &msa)\r
38         {\r
39         if (ALPHA_Amino != g_Alpha)\r
40                 return;\r
41         if (0 == M)\r
42                 return;\r
43 \r
44         const unsigned uSeqCount = msa.GetSeqCount();\r
45         const unsigned uColCount = msa.GetColCount();\r
46         for (unsigned uSeqIndex = 0; uSeqIndex < uSeqCount; ++uSeqIndex)\r
47                 {\r
48                 unsigned uId = msa.GetSeqId(uSeqIndex);\r
49                 if (M[uId])\r
50                         {\r
51                         for (unsigned uColIndex = 0; uColIndex < uColCount; ++uColIndex)\r
52                                 {\r
53                                 if (!msa.IsGap(uSeqIndex, uColIndex))\r
54                                         {\r
55                                         msa.SetChar(uSeqIndex, uColIndex, 'M');\r
56                                         break;\r
57                                         }\r
58                                 }\r
59                         }\r
60                 }\r
61 \r
62         delete[] M;\r
63         M = 0;\r
64         }\r