1 #include "myutils.h"
2 #include "alpha.h"
3 #include "timing.h"
4 
isgap(byte c)5 bool isgap(byte c)
6 	{
7 	return c == '-' || c == '.';
8 	}
9 
WordToStrAmino(unsigned Word,unsigned WordLength)10 const char *WordToStrAmino(unsigned Word, unsigned WordLength)
11 	{
12 	static char Str[32];
13 	for (unsigned i = 0; i < WordLength; ++i)
14 		{
15 		unsigned Letter = Word%20;
16 		Str[WordLength-i-1] = g_LetterToCharAmino[Letter];
17 		Word /= 20;
18 		}
19 	Str[WordLength] = 0;
20 	return Str;
21 	}
22 
WordToStrAmino2(unsigned Word,unsigned WordLength,char * Str)23 const char *WordToStrAmino2(unsigned Word, unsigned WordLength, char *Str)
24 	{
25 	for (unsigned i = 0; i < WordLength; ++i)
26 		{
27 		unsigned Letter = Word%20;
28 		Str[WordLength-i-1] = g_LetterToCharAmino[Letter];
29 		Word /= 20;
30 		}
31 	Str[WordLength] = 0;
32 	return Str;
33 	}
34 
WordToStrNucleo(unsigned Word,unsigned WordLength)35 const char *WordToStrNucleo(unsigned Word, unsigned WordLength)
36 	{
37 	static char Str[32];
38 	for (unsigned i = 0; i < WordLength; ++i)
39 		{
40 		unsigned Letter = Word%4;
41 		Str[WordLength-i-1] = g_LetterToCharNucleo[Letter];
42 		Word /= 4;
43 		}
44 	Str[WordLength] = 0;
45 	return Str;
46 	}
47 
WordToStr(unsigned Word,unsigned WordLength,bool Nucleo)48 const char *WordToStr(unsigned Word, unsigned WordLength, bool Nucleo)
49 	{
50 	return (Nucleo ? WordToStrNucleo : WordToStrAmino)(Word, WordLength);
51 	}
52 
RevCompAlloc(const byte * Seq,unsigned L)53 byte *RevCompAlloc(const byte *Seq, unsigned L)
54 	{
55 	byte *RCSeq = MYALLOC(byte, L, Alpha);
56 
57 	for (unsigned i = 0; i < L; ++i)
58 		RCSeq[L-i-1] = g_CharToCompChar[Seq[i]];
59 
60 	return RCSeq;
61 	}
62 
RevCompInPlace(byte * Seq,unsigned L)63 void RevCompInPlace(byte *Seq, unsigned L)
64 	{
65 	unsigned L1 = L - 1;
66 	unsigned L2 = L/2;
67 	for (unsigned i = 0; i < L2; ++i)
68 		{
69 		unsigned j = L1 - i;
70 		unsigned ci = Seq[i];
71 		unsigned cj = Seq[j];
72 
73 		unsigned ri = g_CharToCompChar[ci];
74 		unsigned rj = g_CharToCompChar[cj];
75 
76 		Seq[i] = rj;
77 		Seq[j] = ri;
78 		}
79 
80 	if (L%2 == 1)
81 		Seq[L2] = g_CharToCompChar[Seq[L2]];
82 	}
83 
RevComp(const byte * Seq,unsigned L,byte * RCSeq)84 void RevComp(const byte *Seq, unsigned L, byte *RCSeq)
85 	{
86 	for (unsigned i = 0; i < L; ++i)
87 		RCSeq[L-i-1] = g_CharToCompChar[Seq[i]];
88 	}
89 
GetAminoCharFrom3NucChars(unsigned char c1,unsigned char c2,unsigned char c3)90 unsigned char GetAminoCharFrom3NucChars(unsigned char c1, unsigned char c2,
91   unsigned char c3)
92 	{
93 	unsigned Letter1 = g_CharToLetterNucleo[c1];
94 	unsigned Letter2 = g_CharToLetterNucleo[c2];
95 	unsigned Letter3 = g_CharToLetterNucleo[c3];
96 	unsigned Word = Letter1*(4*4) + Letter2*4 + Letter3;
97 
98 	unsigned Letter = g_CodonWordToAminoLetter[Word];
99 	return g_LetterToCharAmino[Letter];
100 	}
101