-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHolyDNA.HC
executable file
·110 lines (95 loc) · 2.2 KB
/
HolyDNA.HC
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
Bool CheckChains(U8 *chain1, U8 *chain2)
{
// if the two chains aren't of the same length, return
if (StrLen(chain1) != StrLen(chain2))
{
"the lengths of the two chains don't match\n";
return FALSE;
}
// iterate through each character in the first chain
// and return false if the character which is at the
// corresponding position in the second chain doesn't
// match the nucleotide
I64 i;
for (i = 0; i < StrLen(chain1); i++)
{
I8 *char = chain1[i];
switch (char)
{
case 'A':
if(chain2[i] != 'T')
{
return FALSE;
}; break;
case 'T':
if(chain2[i] != 'A')
{
return FALSE;
}; break;
case 'G':
if(chain2[i] != 'C')
{
return FALSE;
}; break;
case 'C':
if(chain2[i] != 'G')
{
return FALSE;
}; break;
}
}
return TRUE;
}
U8 CreateMatchingSequence(U8 *inputChain)
{
I64 i;
I64 len = StrLen(inputChain);
// initialize a char array with the length of the inputChain
U8 matchingChain[len];
// for each character in the inputChain, we will check its value
// and assign the corresponding pair at the same index in the
// matchingChain char array
for (i = 0; i < len; i++)
{
switch(inputChain[i])
{
case 'A':
matchingChain[i] = 'T'; break;
case 'T':
matchingChain[i] = 'A'; break;
case 'G':
matchingChain[i] = 'C'; break;
case 'C':
matchingChain[i] = 'G'; break;
}
}
return matchingChain;
}
U8 GetChainInput()
{
U8 *chain = StrNew(""); // without initializing this string like this, the first length == 0 check will fail
while (StrLen(chain) == 0)
{
chain = GetStr("enter your chain:");
}
return chain;
}
// sample inputs from the exercise
U8 *chain1 = "ACGTT";
U8 *chain2 = "TGCAA";
U8 *chain3 = "GTTAC";
// throughout this implementation i decided to use PopUpOk()
// instead of simply printing strings to stdout. this is just
// because i wanted to goof around with it, simply printing
// "welcome to holy dna!\n";
// like it is done above will work just fine
PopUpOk("welcome to holy dna!");
Bool ChainsMatch = CheckChains(chain1, chain3);
if(ChainsMatch)
{
PopUpOk("The chains are compatible.\n");
}
else
{
PopUpOk("The chains are not compatible.\n");
}