-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFNAFilePreprocess.c
66 lines (54 loc) · 1.83 KB
/
FNAFilePreprocess.c
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
#include "FNAFilePreprocess.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
unsigned int valueMap[86]; // ASCII value of U = 85
const unsigned long MAX_OCCURRENCES = 100;
const unsigned long MAX_LENGTH = 10000000000;
const unsigned long MAX_INPUT = 100000;
char *readFile(char *datasetName) {
/* read from the specified file.
* Return: char array, with non-DNA/RNA information deleted.*/
// change the path here:
char path[1000];
sprintf(path, "dataset/%s",datasetName);
FILE * file = fopen(path, "r");
char dummyInput[200];
char *inputSequence = (char*)malloc(MAX_LENGTH * sizeof(char));
char buffer;
unsigned int id = 0;
fgets(dummyInput, 200, file); // remove start lines from the file
while (buffer = fgetc(file), buffer != EOF) {
if (buffer == '\n') {
continue;
} else {
inputSequence[id] = buffer;
id += 1;
}
}
inputSequence[id] = '\0';
fclose(file);
return inputSequence;
}
void initializeValueMap() {
/* Initialize the binary values for C,A,T,U,G in uniform distribution. */
srand (time(NULL));
valueMap['G'] = 0;
valueMap['A'] = 0;
valueMap['C'] = 0;
valueMap['T'] = 0;
valueMap['U'] = 0;
for (int i = 0; i < sizeof(int) * 8; i++) {
valueMap['G'] = valueMap['G'] * 2 + rand() % 2;
valueMap['A'] = valueMap['A'] * 2 + rand() % 2;
valueMap['C'] = valueMap['C'] * 2 + rand() % 2;
valueMap['T'] = valueMap['T'] * 2 + rand() % 2;
valueMap['U'] = valueMap['U'] * 2 + rand() % 2;
}
printf("==========Random Numbers Generated==========\n");
printf("G = %u\n", valueMap['G']);
printf("A = %u\n", valueMap['A']);
printf("C = %u\n", valueMap['C']);
printf("T = %u\n", valueMap['T']);
printf("U = %u\n", valueMap['U']);
}