]> git.donarmstrong.com Git - mothur.git/blobdiff - uchime_src/alpha2.cpp
added uchime_src folder. added biom parameter to make.shared. added biom as a current...
[mothur.git] / uchime_src / alpha2.cpp
diff --git a/uchime_src/alpha2.cpp b/uchime_src/alpha2.cpp
new file mode 100644 (file)
index 0000000..26bc1c6
--- /dev/null
@@ -0,0 +1,100 @@
+#include "myutils.h"\r
+#include "alpha.h"\r
+#include "timing.h"\r
+\r
+bool isgap(byte c)\r
+       {\r
+       return c == '-' || c == '.';\r
+       }\r
+\r
+const char *WordToStrAmino(unsigned Word, unsigned WordLength)\r
+       {\r
+       static char Str[32];\r
+       for (unsigned i = 0; i < WordLength; ++i)\r
+               {\r
+               unsigned Letter = Word%20;\r
+               Str[WordLength-i-1] = g_LetterToCharAmino[Letter];\r
+               Word /= 20;\r
+               }\r
+       Str[WordLength] = 0;\r
+       return Str;\r
+       }\r
+\r
+const char *WordToStrAmino2(unsigned Word, unsigned WordLength, char *Str)\r
+       {\r
+       for (unsigned i = 0; i < WordLength; ++i)\r
+               {\r
+               unsigned Letter = Word%20;\r
+               Str[WordLength-i-1] = g_LetterToCharAmino[Letter];\r
+               Word /= 20;\r
+               }\r
+       Str[WordLength] = 0;\r
+       return Str;\r
+       }\r
+\r
+const char *WordToStrNucleo(unsigned Word, unsigned WordLength)\r
+       {\r
+       static char Str[32];\r
+       for (unsigned i = 0; i < WordLength; ++i)\r
+               {\r
+               unsigned Letter = Word%4;\r
+               Str[WordLength-i-1] = g_LetterToCharNucleo[Letter];\r
+               Word /= 4;\r
+               }\r
+       Str[WordLength] = 0;\r
+       return Str;\r
+       }\r
+\r
+const char *WordToStr(unsigned Word, unsigned WordLength, bool Nucleo)\r
+       {\r
+       return (Nucleo ? WordToStrNucleo : WordToStrAmino)(Word, WordLength);\r
+       }\r
+\r
+byte *RevCompAlloc(const byte *Seq, unsigned L)\r
+       {\r
+       byte *RCSeq = MYALLOC(byte, L, Alpha);\r
+\r
+       for (unsigned i = 0; i < L; ++i)\r
+               RCSeq[L-i-1] = g_CharToCompChar[Seq[i]];\r
+\r
+       return RCSeq;\r
+       }\r
+\r
+void RevCompInPlace(byte *Seq, unsigned L)\r
+       {\r
+       unsigned L1 = L - 1;\r
+       unsigned L2 = L/2;\r
+       for (unsigned i = 0; i < L2; ++i)\r
+               {\r
+               unsigned j = L1 - i;\r
+               unsigned ci = Seq[i];\r
+               unsigned cj = Seq[j];\r
+\r
+               unsigned ri = g_CharToCompChar[ci];\r
+               unsigned rj = g_CharToCompChar[cj];\r
+\r
+               Seq[i] = rj;\r
+               Seq[j] = ri;\r
+               }\r
+\r
+       if (L%2 == 1)\r
+               Seq[L2] = g_CharToCompChar[Seq[L2]];\r
+       }\r
+\r
+void RevComp(const byte *Seq, unsigned L, byte *RCSeq)\r
+       {\r
+       for (unsigned i = 0; i < L; ++i)\r
+               RCSeq[L-i-1] = g_CharToCompChar[Seq[i]];\r
+       }\r
+\r
+unsigned char GetAminoCharFrom3NucChars(unsigned char c1, unsigned char c2,\r
+  unsigned char c3)\r
+       {\r
+       unsigned Letter1 = g_CharToLetterNucleo[c1];\r
+       unsigned Letter2 = g_CharToLetterNucleo[c2];\r
+       unsigned Letter3 = g_CharToLetterNucleo[c3];\r
+       unsigned Word = Letter1*(4*4) + Letter2*4 + Letter3;\r
+\r
+       unsigned Letter = g_CodonWordToAminoLetter[Word];\r
+       return g_LetterToCharAmino[Letter];\r
+       }\r