+ wrote faster parser / file processing tools in C
[qpalma.git] / tools / data_tools / datastructures.c
1 #include <stdlib.h>
2 #include <string.h>
3
4 #include "datastructures.h"
5
6 struct gene* gene_alloc(void) {
7 struct gene* newGene = (struct gene*) malloc(sizeof(struct gene));
8 newGene->exon_starts = malloc(2*sizeof(int));
9 newGene->exon_stops = malloc(2*sizeof(int));
10 newGene->num_exons = 0;
11 newGene->max_exons = 2;
12 newGene->start = -1;
13
14 return newGene;
15 }
16
17 void free_gene(struct gene* oldGene) {
18 free(oldGene->exon_starts);
19 free(oldGene->exon_stops);
20 }
21
22 void add_exon(struct gene* currentGene,int start, int stop) {
23
24 if (currentGene->num_exons < currentGene->num_exons) {
25 int idx = currentGene->num_exons;
26 currentGene->exon_starts[idx] = start;
27 currentGene->exon_stops[idx] = stop;
28 currentGene->num_exons++;
29 } else {
30 currentGene->exon_starts = realloc(currentGene->exon_starts,sizeof(int)*2*currentGene->max_exons);
31 currentGene->exon_stops = realloc(currentGene->exon_stops,sizeof(int)*2*currentGene->max_exons);
32 }
33 }