]> git.donarmstrong.com Git - mothur.git/blob - setnucmx.cpp
123791d2b8dfafcb4313fc6d0fe45e092dafc573
[mothur.git] / setnucmx.cpp
1 //uchime by Robert C. Edgar http://drive5.com/uchime This code is donated to the public domain.\r
2 \r
3 #include "myutils.h"\r
4 #include "mx.h"\r
5 \r
6 Mx<float> g_SubstMxf;\r
7 float **g_SubstMx;\r
8 \r
9 static const char Alphabet[] = "ACGTU";\r
10 \r
11 void SetNucSubstMx(double Match, double Mismatch)\r
12         {\r
13         static bool Done = false;\r
14         if (Done)\r
15                 return;\r
16         Done = true;\r
17 \r
18         if (Match <= 0.0)\r
19                 Die("Match score should be +ve");\r
20         if (Mismatch >= 0.0)\r
21                 Die("Mismatch score should be -ve");\r
22 \r
23         unsigned N = unsigned(strlen(Alphabet));\r
24 \r
25         g_SubstMxf.Alloc("NUCMX", 256, 256);\r
26         strcpy(g_SubstMxf.m_Alpha, "ACGT");\r
27         g_SubstMxf.Init(0);\r
28         g_SubstMx = g_SubstMxf.GetData();\r
29         for (unsigned i = 0; i < N; ++i)\r
30                 {\r
31                 for (unsigned j = 0; j < N; ++j)\r
32                         {\r
33                         float v = float(i == j ? Match : Mismatch);\r
34 \r
35                         byte ui = (byte) toupper(Alphabet[i]);\r
36                         byte uj = (byte) toupper(Alphabet[j]);\r
37                         byte li = (byte) tolower(ui);\r
38                         byte lj = (byte) tolower(uj);\r
39                         ui = (byte) toupper(ui);\r
40                         uj = (byte) toupper(uj);\r
41 \r
42                         g_SubstMx[ui][uj] = v;\r
43                         g_SubstMx[uj][ui] = v;\r
44 \r
45                         g_SubstMx[ui][lj] = v;\r
46                         g_SubstMx[uj][li] = v;\r
47 \r
48                         g_SubstMx[li][uj] = v;\r
49                         g_SubstMx[lj][ui] = v;\r
50 \r
51                         g_SubstMx[li][lj] = v;\r
52                         g_SubstMx[lj][li] = v;\r
53                         }\r
54                 }\r
55 \r
56         for (unsigned j = 0; j < N; ++j)\r
57                 {\r
58                 float v = 0.0f;\r
59 \r
60                 byte ui = (byte) 'N';\r
61                 byte uj = (byte) toupper(Alphabet[j]);\r
62                 byte li = (byte) 'n';\r
63                 byte lj = (byte) tolower(uj);\r
64                 ui = (byte) toupper(ui);\r
65                 uj = (byte) toupper(uj);\r
66 \r
67                 g_SubstMx[ui][uj] = v;\r
68                 g_SubstMx[uj][ui] = v;\r
69 \r
70                 g_SubstMx[ui][lj] = v;\r
71                 g_SubstMx[uj][li] = v;\r
72 \r
73                 g_SubstMx[li][uj] = v;\r
74                 g_SubstMx[lj][ui] = v;\r
75 \r
76                 g_SubstMx[li][lj] = v;\r
77                 g_SubstMx[lj][li] = v;\r
78                 }\r
79         }\r