221b61a21e2feda98e209a28b08bf098913c7aa7
[qpalma.git] / tools / data_tools / sort_genes.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "datastructures.h"
4
5 void sort_genes(struct gene*** allGenes, int numGenes) {
6
7 int gstart = (*allGenes)[0]->start;
8 int gstop = (*allGenes)[0]->stop;
9 int pre_start;
10 int pre_stop;
11
12 //struct gene* tmp;
13 int round;
14 int gidx;
15
16 for(round=0;round<1;round++) {
17 printf("Next round!\n");
18
19 for(gidx=1;gidx<numGenes;gidx++) {
20 pre_start = gstart;
21 pre_stop = gstop;
22 gstart = (*allGenes)[gidx]->start;
23 gstop = (*allGenes)[gidx]->stop;
24
25 if ( pre_stop > gstart ) {
26 printf("Swapping genes!\n");
27 printf("idx is %d\n",gidx);
28 //printf("pos are %d %d - %d %d\n",pre_start,pre_stop,gstart,gstop);
29 //(*allGenes)[gidx-1] = (*allGenes)[gidx];
30 //(*allGenes)[gidx] = tmp;
31 //printf("pos with new indices: %d %d - %d %d\n",(*allGenes)[gidx-1]->start,(*allGenes)[gidx-1]->stop,(*allGenes)[gidx]->start,(*allGenes)[gidx]->stop);
32 gstart = (*allGenes)[gidx]->start;
33 gstop = (*allGenes)[gidx]->stop;
34 (*allGenes)[gidx] = NULL;
35 }
36 }
37 }
38 printf("End of swapping elements!\n");
39 }