comparison chromeister/src/combine_reads.c @ 1:3d1fbde7e0cc draft default tip

Deleted selected files
author alvarofaure
date Thu, 13 Dec 2018 03:41:58 -0500
parents 7fdf47a0bae8
children
comparison
equal deleted inserted replaced
0:7fdf47a0bae8 1:3d1fbde7e0cc
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <ctype.h>
5 #include "structs.h"
6 #include "commonFunctions.h"
7
8 #define MAX(x, y) (((x) > (y)) ? (x) : (y))
9 #define MIN(x, y) (((x) <= (y)) ? (x) : (y))
10 #define STARTING_SEQS 1000
11 #define PIECE_OF_DB_REALLOC 3200000 //half a gigabyte if divided by 8 bytes
12 #define MATVAL 101
13
14 int main(int argc, char ** av){
15
16 if(argc != 2) terror("USE:: combine_reads <file>");
17
18 FILE * results, * data;
19 data = fopen(av[1], "rt");
20 if(data == NULL) terror("Could not open input file");
21
22 uint64_t * mat = (uint64_t *) calloc(MATVAL, sizeof(uint64_t));
23 if(mat == NULL) terror("Could not allocate matrix array");
24
25 char buffer[MAXLID];
26 if ((results = fopen("accu.log", "r")) == NULL){
27 results = fopen("accu.log", "wt");
28 }else{
29 // Load the matrix
30 uint64_t i;
31
32 for(i=0;i<100;i++){
33 if(0 == fgets(buffer, MAXLID, results)) terror("Missing number on load");
34
35 //fprintf(stdout, "Have %s\n", buffer);
36 buffer[strlen(buffer)-1] = '\0';
37 mat[i] = asciiToUint64(buffer);
38 //fprintf(stdout, "%"PRIu64"\n", mat[i]);
39 //getchar();
40 }
41 fclose(results);
42 results = fopen("accu.log", "wt"); // Re open
43 }
44
45 // Read file
46 uint64_t read_id_1, read_id_2, coverage, identity, length, current, currmax, j;
47 while(!feof(data)){
48 if(0 == fgets(buffer, MAXLID, data) && !feof(data)) terror("Missing values");
49 // 2 77277 89 64 213
50 sscanf(buffer, "%"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64, &read_id_1, &read_id_2, &coverage, &identity, &length);
51 //fprintf(stdout, "%"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64"\n", read_id_1, read_id_2, coverage, identity, length);
52 currmax = MIN(identity, coverage);
53 //fprintf(stdout, "%"PRIu64"\n", currmax);
54 current = read_id_1;
55 /*
56 for(j=currmax; j > 1; j--){
57 if(current != lasts[j]){
58 mat[j]++;
59 lasts[j] = current;
60 }
61 }
62 */
63 mat[currmax] += 1;
64
65 }
66
67 for(j=99; j>0; j--){
68 mat[j] += mat[j+1];
69 }
70 mat[0] = mat[1];
71
72 for(j=0; j<100; j++){
73 fprintf(stdout, "%"PRIu64"\n", mat[j]);
74 fprintf(results, "%"PRIu64"\n", mat[j]);
75 }
76
77
78 fclose(results);
79 fclose(data);
80 free(mat);
81 return 0;
82 }