+ wrote faster parser / file processing tools in C
[qpalma.git] / tools / data_tools / filterReads.c
1 ////////////////////////////////////////////////////////////
2 // The purpose of this program is to read a gff and a
3 // solexa reads file and create a data set used by QPalma.
4 //
5 //
6 //
7 //
8 ////////////////////////////////////////////////////////////
9
10 #include <sys/mman.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14
15 #include "datastructures.h"
16
17 void parse_gff(char* filename,FILE* fid,struct gene* allGenes);
18
19 static char *info = "Usage is:\n./filterReads gff reads";
20
21 int main(int argc, char* argv[]) {
22
23 if(argc != 3) {
24 printf("%s\n",info);
25 exit(EXIT_FAILURE);
26 }
27
28 //static size_t page_size;
29 // page_size = (size_t) sysconf (_SC_PAGESIZE);
30 int filenameSize = 256;
31 char *gff_filename = malloc(sizeof(char)*filenameSize);
32 char *reads_filename = malloc(sizeof(char)*filenameSize);
33
34 strncpy(gff_filename,argv[1],filenameSize);
35 strncpy(reads_filename,argv[2],filenameSize);
36
37 FILE *gff_fs = fopen(gff_filename,"r");
38 FILE *reads_fs = fopen(reads_filename,"r");
39
40 if(gff_fs == NULL) {
41 printf("Error: Could not open file: %s",gff_filename);
42 exit(EXIT_FAILURE);
43 }
44
45 if(reads_fs == NULL) {
46 printf("Error: Could not open file: %s",reads_filename);
47 exit(EXIT_FAILURE);
48 }
49
50 struct gene **allGenes;
51 parse_gff(gff_filename,gff_fs,allGenes);
52
53
54 int reads_fid = fileno(reads_fs);
55 size_t mmapAreaSize = 16;
56 void *reads_area = mmap (NULL,mmapAreaSize,PROT_READ|PROT_WRITE,MAP_PRIVATE,reads_fid,0);
57 if((long int) reads_area == -1)
58 printf("mmapping failed!\n");
59
60 char *test_string = malloc(sizeof(char)*10);
61 strncpy(test_string,(char*)reads_area,10);
62 //printf("Reads area at %s\n",test_string);
63
64 int status = munmap(reads_area,mmapAreaSize);
65 if(status != 0)
66 printf("munmap failed!\n");
67
68 status = fclose(gff_fs);
69 status += fclose(reads_fs);
70 if(status != 0)
71 printf("closing of filestreams failed!\n");
72
73 printf("sizeof(struct gene) %d\n",sizeof(struct gene));
74 printf("sizeof(struct read) %d\n",sizeof(struct read));
75
76
77 free(gff_filename);
78 free(reads_filename);
79 return 0;
80 }