+ parser works now with mmap and sscanf
[qpalma.git] / tools / data_tools / datastructures.c
index 2f464c4..dd9e48e 100644 (file)
@@ -9,8 +9,6 @@ struct gene* gene_alloc(void) {
    newGene->exon_stops = malloc(2*sizeof(int));
    newGene->num_exons = 0;
    newGene->max_exons = 2;
-   newGene->start = -1;
-
    return newGene;
 }
 
@@ -20,14 +18,15 @@ void free_gene(struct gene* oldGene) {
 }
 
 void add_exon(struct gene* currentGene,int start, int stop) {
+   int idx = currentGene->num_exons;
 
-   if (currentGene->num_exons < currentGene->num_exons) {
-      int idx = currentGene->num_exons;
-      currentGene->exon_starts[idx] = start;
-      currentGene->exon_stops[idx] = stop;
-      currentGene->num_exons++;
-   } else {
+   if ( idx >= currentGene->max_exons) {
       currentGene->exon_starts = realloc(currentGene->exon_starts,sizeof(int)*2*currentGene->max_exons);
       currentGene->exon_stops = realloc(currentGene->exon_stops,sizeof(int)*2*currentGene->max_exons);
+      currentGene->max_exons *= 2;
    }
+
+   currentGene->exon_starts[idx] = start;
+   currentGene->exon_stops[idx] = stop;
+   currentGene->num_exons++;
 }