-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgff_reader.c
80 lines (68 loc) · 2.61 KB
/
gff_reader.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "commons.h"
#include "gff_reader.h"
#include "log.h"
unsigned int gff_file_read(char* filename, gff_line_t* gff_lines_p) {
unsigned int count = 0;
FILE* file = fopen(filename, "r");
if (file == NULL) {
LOG_FATAL("Error opening gff file");
}
char* buffer = (char*) calloc(1, MAX_GFF_FILE_LINE_LENGTH);
const char delimiters[] = "\t";
char* token = NULL;
int pos;
while (fgets(buffer, MAX_GFF_FILE_LINE_LENGTH, file)) {
if ((buffer[0] == '#') || (buffer[0] != 'c') || (buffer[1] != 'h') || (buffer[2] != 'r')) continue;
pos = 0;
token = strtok(buffer, delimiters);
while (token != NULL) {
switch (pos) {
case 0:
gff_lines_p[count].seqname = (char*) calloc(strlen(token), sizeof(char));
strcpy(gff_lines_p[count].seqname, token);
break;
case 1:
gff_lines_p[count].source = (char*) calloc(strlen(token), sizeof(char));
strcpy(gff_lines_p[count].source, token);
break;
case 2:
gff_lines_p[count].feature = (char*) calloc(strlen(token), sizeof(char));
strcpy(gff_lines_p[count].feature, token);
break;
case 3:
sscanf(token, "%i", &(gff_lines_p[count].start));
break;
case 4:
sscanf(token, "%i", &(gff_lines_p[count].end));
break;
case 5:
gff_lines_p[count].score = (char*) calloc(strlen(token), sizeof(char));
strcpy(gff_lines_p[count].score, token);
break;
case 6:
gff_lines_p[count].strand = (char*) calloc(strlen(token), sizeof(char));
strcpy(gff_lines_p[count].strand, token);
break;
case 7:
gff_lines_p[count].frame = (char*) calloc(strlen(token), sizeof(char));
strcpy(gff_lines_p[count].frame, token);
break;
case 8:
gff_lines_p[count].group = (char*) calloc(strlen(token), sizeof(char));
strcpy(gff_lines_p[count].group, token);
break;
default:
break;
}
token = strtok(NULL, delimiters);
pos++;
}
count++;
}
fclose(file);
free(buffer);
return count;
}