+ added processing function for reads
[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 return newGene;
13 }
14
15 void free_gene(struct gene* oldGene) {
16 free(oldGene->exon_starts);
17 free(oldGene->exon_stops);
18 }
19
20 void add_exon(struct gene* currentGene,int start, int stop) {
21 int idx = currentGene->num_exons;
22
23 if ( idx >= currentGene->max_exons) {
24 currentGene->exon_starts = realloc(currentGene->exon_starts,sizeof(int)*2*currentGene->max_exons);
25 currentGene->exon_stops = realloc(currentGene->exon_stops,sizeof(int)*2*currentGene->max_exons);
26 currentGene->max_exons *= 2;
27 }
28
29 currentGene->exon_starts[idx] = start;
30 currentGene->exon_stops[idx] = stop;
31 currentGene->num_exons++;
32 }