annotate IMSAME/src/IMSAME.c @ 5:353e5673bcb8 draft default tip

Uploaded
author bitlab
date Mon, 17 Dec 2018 12:20:41 -0500
parents 762009a91895
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
762009a91895 Uploaded
bitlab
parents:
diff changeset
1 /*********
762009a91895 Uploaded
bitlab
parents:
diff changeset
2
762009a91895 Uploaded
bitlab
parents:
diff changeset
3 File IMSAME.c
762009a91895 Uploaded
bitlab
parents:
diff changeset
4 Author EPW <estebanpw@uma.es>
762009a91895 Uploaded
bitlab
parents:
diff changeset
5 Description Computes an incremental alignment on reads versus reads using n threads
762009a91895 Uploaded
bitlab
parents:
diff changeset
6
762009a91895 Uploaded
bitlab
parents:
diff changeset
7 USAGE Usage is described by calling ./IMSAME --help
762009a91895 Uploaded
bitlab
parents:
diff changeset
8
762009a91895 Uploaded
bitlab
parents:
diff changeset
9
762009a91895 Uploaded
bitlab
parents:
diff changeset
10
762009a91895 Uploaded
bitlab
parents:
diff changeset
11 **********/
762009a91895 Uploaded
bitlab
parents:
diff changeset
12
762009a91895 Uploaded
bitlab
parents:
diff changeset
13
762009a91895 Uploaded
bitlab
parents:
diff changeset
14 #include <stdio.h>
762009a91895 Uploaded
bitlab
parents:
diff changeset
15 #include <stdlib.h>
762009a91895 Uploaded
bitlab
parents:
diff changeset
16 #include <math.h>
762009a91895 Uploaded
bitlab
parents:
diff changeset
17 #include <string.h>
762009a91895 Uploaded
bitlab
parents:
diff changeset
18 #include <ctype.h>
762009a91895 Uploaded
bitlab
parents:
diff changeset
19 #include <pthread.h>
762009a91895 Uploaded
bitlab
parents:
diff changeset
20 #include "structs.h"
762009a91895 Uploaded
bitlab
parents:
diff changeset
21 #include "alignmentFunctions.h"
762009a91895 Uploaded
bitlab
parents:
diff changeset
22 #include "commonFunctions.h"
762009a91895 Uploaded
bitlab
parents:
diff changeset
23
762009a91895 Uploaded
bitlab
parents:
diff changeset
24 #define MAX(x, y) (((x) > (y)) ? (x) : (y))
762009a91895 Uploaded
bitlab
parents:
diff changeset
25 #define MIN(x, y) (((x) <= (y)) ? (x) : (y))
762009a91895 Uploaded
bitlab
parents:
diff changeset
26 #define STARTING_SEQS 1000
762009a91895 Uploaded
bitlab
parents:
diff changeset
27 #define PIECE_OF_DB_REALLOC 3200000 //half a gigabyte if divided by 8 bytes
762009a91895 Uploaded
bitlab
parents:
diff changeset
28
762009a91895 Uploaded
bitlab
parents:
diff changeset
29
762009a91895 Uploaded
bitlab
parents:
diff changeset
30 uint64_t custom_kmer = 12; // Defined as external in structs.h
762009a91895 Uploaded
bitlab
parents:
diff changeset
31
762009a91895 Uploaded
bitlab
parents:
diff changeset
32 void init_args(int argc, char ** av, FILE ** query, FILE ** database, FILE ** out_database, uint64_t * n_threads, long double * minevalue, long double * mincoverage, int * igap, int * egap, long double * minidentity, long double * window, unsigned char * full_comp, uint64_t * custom_kmer, unsigned char * hits_only, uint64_t * n_parts);
762009a91895 Uploaded
bitlab
parents:
diff changeset
33
762009a91895 Uploaded
bitlab
parents:
diff changeset
34 int VERBOSE_ACTIVE = 0;
762009a91895 Uploaded
bitlab
parents:
diff changeset
35
762009a91895 Uploaded
bitlab
parents:
diff changeset
36 int main(int argc, char ** av){
762009a91895 Uploaded
bitlab
parents:
diff changeset
37
762009a91895 Uploaded
bitlab
parents:
diff changeset
38
762009a91895 Uploaded
bitlab
parents:
diff changeset
39
762009a91895 Uploaded
bitlab
parents:
diff changeset
40
762009a91895 Uploaded
bitlab
parents:
diff changeset
41
762009a91895 Uploaded
bitlab
parents:
diff changeset
42 clock_t begin, end;
762009a91895 Uploaded
bitlab
parents:
diff changeset
43
762009a91895 Uploaded
bitlab
parents:
diff changeset
44 int error; //To tell if threads could not be launched
762009a91895 Uploaded
bitlab
parents:
diff changeset
45 uint64_t i,j;
762009a91895 Uploaded
bitlab
parents:
diff changeset
46
762009a91895 Uploaded
bitlab
parents:
diff changeset
47 //query to read kmers from, database to find seeds
762009a91895 Uploaded
bitlab
parents:
diff changeset
48 FILE * query = NULL, * database = NULL, * out_database = NULL;
762009a91895 Uploaded
bitlab
parents:
diff changeset
49 long double minevalue = 1/powl(10, 10); //Default 1 * 10^-10
762009a91895 Uploaded
bitlab
parents:
diff changeset
50
762009a91895 Uploaded
bitlab
parents:
diff changeset
51 long double mincoverage = 0.5, minidentity = 0.5, window = 0.15; //Default
762009a91895 Uploaded
bitlab
parents:
diff changeset
52 int igap = -5, egap = -2;
762009a91895 Uploaded
bitlab
parents:
diff changeset
53 unsigned char full_comp = FALSE;
762009a91895 Uploaded
bitlab
parents:
diff changeset
54 unsigned char hits_only = FALSE;
762009a91895 Uploaded
bitlab
parents:
diff changeset
55
762009a91895 Uploaded
bitlab
parents:
diff changeset
56 uint64_t n_threads = 4;
762009a91895 Uploaded
bitlab
parents:
diff changeset
57 uint64_t n_parts = 3; // Default is 3
762009a91895 Uploaded
bitlab
parents:
diff changeset
58
762009a91895 Uploaded
bitlab
parents:
diff changeset
59 init_args(argc, av, &query, &database, &out_database, &n_threads, &minevalue, &mincoverage, &igap, &egap, &minidentity, &window, &full_comp, &custom_kmer, &hits_only, &n_parts);
762009a91895 Uploaded
bitlab
parents:
diff changeset
60
762009a91895 Uploaded
bitlab
parents:
diff changeset
61 //uint64_t reads_per_thread;
762009a91895 Uploaded
bitlab
parents:
diff changeset
62 uint64_t sum_accepted_reads = 0;
762009a91895 Uploaded
bitlab
parents:
diff changeset
63
762009a91895 Uploaded
bitlab
parents:
diff changeset
64 begin = clock();
762009a91895 Uploaded
bitlab
parents:
diff changeset
65
762009a91895 Uploaded
bitlab
parents:
diff changeset
66 fprintf(stdout, "[INFO] Init. quick table\n");
762009a91895 Uploaded
bitlab
parents:
diff changeset
67
762009a91895 Uploaded
bitlab
parents:
diff changeset
68 pthread_t * threads = (pthread_t *) malloc(n_threads * sizeof(pthread_t));
762009a91895 Uploaded
bitlab
parents:
diff changeset
69 if(threads == NULL) terror("Could not create threads");
762009a91895 Uploaded
bitlab
parents:
diff changeset
70
762009a91895 Uploaded
bitlab
parents:
diff changeset
71 pthread_t * loading_threads = (pthread_t *) malloc(FIXED_LOADING_THREADS * sizeof(pthread_t));
762009a91895 Uploaded
bitlab
parents:
diff changeset
72 if(loading_threads == NULL) terror("Could not create loading threads");
762009a91895 Uploaded
bitlab
parents:
diff changeset
73
762009a91895 Uploaded
bitlab
parents:
diff changeset
74
762009a91895 Uploaded
bitlab
parents:
diff changeset
75 HashTableArgs * hta = (HashTableArgs *) malloc(n_threads*sizeof(HashTableArgs));
762009a91895 Uploaded
bitlab
parents:
diff changeset
76 if(hta == NULL) terror("Could not allocate arguments for hash table");
762009a91895 Uploaded
bitlab
parents:
diff changeset
77
762009a91895 Uploaded
bitlab
parents:
diff changeset
78 pthread_mutex_t lock; //The mutex to lock the queue
762009a91895 Uploaded
bitlab
parents:
diff changeset
79 if (pthread_mutex_init(&lock, NULL) != 0) terror("Could not init mutex");
762009a91895 Uploaded
bitlab
parents:
diff changeset
80
762009a91895 Uploaded
bitlab
parents:
diff changeset
81 // To be used if only computing hits
762009a91895 Uploaded
bitlab
parents:
diff changeset
82 uint64_t ** hits_table = NULL;
762009a91895 Uploaded
bitlab
parents:
diff changeset
83
762009a91895 Uploaded
bitlab
parents:
diff changeset
84 unsigned char ** my_x = (unsigned char **) malloc(n_threads * sizeof(unsigned char*));
762009a91895 Uploaded
bitlab
parents:
diff changeset
85 unsigned char ** my_y = (unsigned char **) malloc(n_threads * sizeof(unsigned char*));
762009a91895 Uploaded
bitlab
parents:
diff changeset
86
762009a91895 Uploaded
bitlab
parents:
diff changeset
87 unsigned char ** marker_taggs = NULL; // To be used with full comparison
762009a91895 Uploaded
bitlab
parents:
diff changeset
88
762009a91895 Uploaded
bitlab
parents:
diff changeset
89 struct positioned_cell ** mc = (struct positioned_cell **) malloc(n_threads * sizeof(struct positioned_cell *));
762009a91895 Uploaded
bitlab
parents:
diff changeset
90 struct cell *** table = (struct cell ***) malloc(n_threads * sizeof(struct cell **));
762009a91895 Uploaded
bitlab
parents:
diff changeset
91 if(table == NULL) terror("Could not allocate NW table");
762009a91895 Uploaded
bitlab
parents:
diff changeset
92 char ** reconstruct_X = (char **) malloc(n_threads * sizeof(char *));
762009a91895 Uploaded
bitlab
parents:
diff changeset
93 char ** reconstruct_Y = (char **) malloc(n_threads * sizeof(char *));
762009a91895 Uploaded
bitlab
parents:
diff changeset
94 if(reconstruct_Y == NULL || reconstruct_X == NULL) terror("Could not allocate output alignment sequences");
762009a91895 Uploaded
bitlab
parents:
diff changeset
95 char ** writing_buffer_alignment = (char **) malloc(n_threads * sizeof(char*));
762009a91895 Uploaded
bitlab
parents:
diff changeset
96 for(i=0;i<n_threads;i++){
762009a91895 Uploaded
bitlab
parents:
diff changeset
97
762009a91895 Uploaded
bitlab
parents:
diff changeset
98 table[i] = (struct cell **) malloc(MAX_READ_SIZE * sizeof(struct cell *));
762009a91895 Uploaded
bitlab
parents:
diff changeset
99 for(j=0;j<MAX_READ_SIZE;j++){
762009a91895 Uploaded
bitlab
parents:
diff changeset
100 table[i][j] = (struct cell *) malloc((1+MAX_WINDOW_SIZE)*sizeof(struct cell));
762009a91895 Uploaded
bitlab
parents:
diff changeset
101 if(table[i][j] == NULL) terror("Could not allocate memory for second loop of table");
762009a91895 Uploaded
bitlab
parents:
diff changeset
102 // Delete this
762009a91895 Uploaded
bitlab
parents:
diff changeset
103 /*
762009a91895 Uploaded
bitlab
parents:
diff changeset
104 uint64_t r;
762009a91895 Uploaded
bitlab
parents:
diff changeset
105 for(r=0;r<MAX_WINDOW_SIZE+1;r++){
762009a91895 Uploaded
bitlab
parents:
diff changeset
106 table[i][j][r].score = INT64_MIN;
762009a91895 Uploaded
bitlab
parents:
diff changeset
107 table[i][j][r].xfrom = 10000000000;
762009a91895 Uploaded
bitlab
parents:
diff changeset
108 table[i][j][r].yfrom = 10000000000;
762009a91895 Uploaded
bitlab
parents:
diff changeset
109 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
110 */
762009a91895 Uploaded
bitlab
parents:
diff changeset
111 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
112 mc[i] = (struct positioned_cell *) malloc(MAX_READ_SIZE * sizeof(struct positioned_cell));
762009a91895 Uploaded
bitlab
parents:
diff changeset
113 my_x[i] = (unsigned char *) malloc(2*MAX_READ_SIZE * sizeof(unsigned char));
762009a91895 Uploaded
bitlab
parents:
diff changeset
114 my_y[i] = (unsigned char *) malloc(2*MAX_READ_SIZE * sizeof(unsigned char));
762009a91895 Uploaded
bitlab
parents:
diff changeset
115 reconstruct_X[i] = (char *) malloc(2*MAX_READ_SIZE * sizeof(char));
762009a91895 Uploaded
bitlab
parents:
diff changeset
116 reconstruct_Y[i] = (char *) malloc(2*MAX_READ_SIZE * sizeof(char));
762009a91895 Uploaded
bitlab
parents:
diff changeset
117 writing_buffer_alignment[i] = (char *) malloc(6*MAX_READ_SIZE*sizeof(char)); //6 times because of 2 times the length of the max of the read, and that happens 3 times (seqX,align,Y)
762009a91895 Uploaded
bitlab
parents:
diff changeset
118 if(table[i] == NULL || mc[i] == NULL || my_x[i] == NULL || my_y[i] == NULL || reconstruct_X[i] == NULL || reconstruct_Y[i] == NULL || writing_buffer_alignment[i] == NULL) terror("Could not allocate buffer for alignment output");
762009a91895 Uploaded
bitlab
parents:
diff changeset
119 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
120
762009a91895 Uploaded
bitlab
parents:
diff changeset
121
762009a91895 Uploaded
bitlab
parents:
diff changeset
122
762009a91895 Uploaded
bitlab
parents:
diff changeset
123 end = clock();
762009a91895 Uploaded
bitlab
parents:
diff changeset
124 fprintf(stdout, "[INFO] Initialization took %e seconds.\n", (double)(end-begin)/CLOCKS_PER_SEC);
762009a91895 Uploaded
bitlab
parents:
diff changeset
125
762009a91895 Uploaded
bitlab
parents:
diff changeset
126 //Variables to account for positions
762009a91895 Uploaded
bitlab
parents:
diff changeset
127 //Print info
762009a91895 Uploaded
bitlab
parents:
diff changeset
128 fprintf(stdout, "[INFO] Loading database.\n");
762009a91895 Uploaded
bitlab
parents:
diff changeset
129 //Variables to read kmers
762009a91895 Uploaded
bitlab
parents:
diff changeset
130 char c = 'N'; //Char to read character
762009a91895 Uploaded
bitlab
parents:
diff changeset
131 //Current length of array and variables for the buffer
762009a91895 Uploaded
bitlab
parents:
diff changeset
132 uint64_t idx = 0, r = 0;
762009a91895 Uploaded
bitlab
parents:
diff changeset
133
762009a91895 Uploaded
bitlab
parents:
diff changeset
134 //Vector to read in batches
762009a91895 Uploaded
bitlab
parents:
diff changeset
135 char * temp_seq_buffer = NULL;
762009a91895 Uploaded
bitlab
parents:
diff changeset
136 if ((temp_seq_buffer = calloc(READBUF, sizeof(char))) == NULL) {
762009a91895 Uploaded
bitlab
parents:
diff changeset
137 terror("Could not allocate memory for read buffer");
762009a91895 Uploaded
bitlab
parents:
diff changeset
138 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
139 //Vector to store database seq
762009a91895 Uploaded
bitlab
parents:
diff changeset
140 unsigned char ** seq_vector_database = (unsigned char **) malloc(FIXED_LOADING_THREADS*sizeof(unsigned char *));
762009a91895 Uploaded
bitlab
parents:
diff changeset
141 if(seq_vector_database == NULL) terror("Could not allocate memory for database vector");
762009a91895 Uploaded
bitlab
parents:
diff changeset
142 uint64_t ** database_positions = (uint64_t **) malloc(FIXED_LOADING_THREADS*sizeof(uint64_t));
762009a91895 Uploaded
bitlab
parents:
diff changeset
143 if(database_positions == NULL) terror("Could not allocate database sequences positions");
762009a91895 Uploaded
bitlab
parents:
diff changeset
144
762009a91895 Uploaded
bitlab
parents:
diff changeset
145 //Mempool_l * mp = (Mempool_l *) malloc(MAX_MEM_POOLS*sizeof(Mempool_l));
762009a91895 Uploaded
bitlab
parents:
diff changeset
146 //if(mp == NULL) terror("Could not allocate vectors for memory pools");
762009a91895 Uploaded
bitlab
parents:
diff changeset
147 //Mempool_l mp[FIXED_LOADING_THREADS][MAX_MEM_POOLS];
762009a91895 Uploaded
bitlab
parents:
diff changeset
148
762009a91895 Uploaded
bitlab
parents:
diff changeset
149
762009a91895 Uploaded
bitlab
parents:
diff changeset
150 Mempool_l ** mp = (Mempool_l **) malloc(FIXED_LOADING_THREADS*sizeof(Mempool_l *));
762009a91895 Uploaded
bitlab
parents:
diff changeset
151 if(mp == NULL) terror("Could not allocate memory pools");
762009a91895 Uploaded
bitlab
parents:
diff changeset
152 for(i=0; i<FIXED_LOADING_THREADS; i++){
762009a91895 Uploaded
bitlab
parents:
diff changeset
153 mp[i] = (Mempool_l *) malloc(MAX_MEM_POOLS*sizeof(Mempool_l));
762009a91895 Uploaded
bitlab
parents:
diff changeset
154 if(mp[i] == NULL) terror("Could not allocate individual memory pools");
762009a91895 Uploaded
bitlab
parents:
diff changeset
155 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
156
762009a91895 Uploaded
bitlab
parents:
diff changeset
157 Mempool_AVL ** mp_AVL = (Mempool_AVL **) malloc(FIXED_LOADING_THREADS*sizeof(Mempool_AVL *));
762009a91895 Uploaded
bitlab
parents:
diff changeset
158 if(mp_AVL == NULL) terror("Could not allocate memory AVL pools");
762009a91895 Uploaded
bitlab
parents:
diff changeset
159 for(i=0; i<FIXED_LOADING_THREADS; i++){
762009a91895 Uploaded
bitlab
parents:
diff changeset
160 mp_AVL[i] = (Mempool_AVL *) malloc(MAX_MEM_POOLS*sizeof(Mempool_AVL));
762009a91895 Uploaded
bitlab
parents:
diff changeset
161 if(mp_AVL[i] == NULL) terror("Could not allocate individual memory AVL pools");
762009a91895 Uploaded
bitlab
parents:
diff changeset
162 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
163
762009a91895 Uploaded
bitlab
parents:
diff changeset
164
762009a91895 Uploaded
bitlab
parents:
diff changeset
165 AVLContainer * ct_A = (AVLContainer *) calloc(1, sizeof(AVLContainer));
762009a91895 Uploaded
bitlab
parents:
diff changeset
166 if(ct_A == NULL) terror("Could not allocate container A");
762009a91895 Uploaded
bitlab
parents:
diff changeset
167 AVLContainer * ct_B = (AVLContainer *) calloc(1, sizeof(AVLContainer));
762009a91895 Uploaded
bitlab
parents:
diff changeset
168 if(ct_B == NULL) terror("Could not allocate container B");
762009a91895 Uploaded
bitlab
parents:
diff changeset
169 AVLContainer * ct_C = (AVLContainer *) calloc(1, sizeof(AVLContainer));
762009a91895 Uploaded
bitlab
parents:
diff changeset
170 if(ct_C == NULL) terror("Could not allocate container C");
762009a91895 Uploaded
bitlab
parents:
diff changeset
171 AVLContainer * ct_D = (AVLContainer *) calloc(1, sizeof(AVLContainer));
762009a91895 Uploaded
bitlab
parents:
diff changeset
172 if(ct_D == NULL) terror("Could not allocate container D");
762009a91895 Uploaded
bitlab
parents:
diff changeset
173
762009a91895 Uploaded
bitlab
parents:
diff changeset
174
762009a91895 Uploaded
bitlab
parents:
diff changeset
175 SeqInfo data_database[FIXED_LOADING_THREADS];
762009a91895 Uploaded
bitlab
parents:
diff changeset
176 uint64_t full_db_n_seqs = 0;
762009a91895 Uploaded
bitlab
parents:
diff changeset
177
762009a91895 Uploaded
bitlab
parents:
diff changeset
178
762009a91895 Uploaded
bitlab
parents:
diff changeset
179 unsigned char curr_kmer[custom_kmer];
762009a91895 Uploaded
bitlab
parents:
diff changeset
180 unsigned char aux_kmer[custom_kmer+1];
762009a91895 Uploaded
bitlab
parents:
diff changeset
181 curr_kmer[0] = '\0';
762009a91895 Uploaded
bitlab
parents:
diff changeset
182 uint64_t word_size = 0;
762009a91895 Uploaded
bitlab
parents:
diff changeset
183
762009a91895 Uploaded
bitlab
parents:
diff changeset
184
762009a91895 Uploaded
bitlab
parents:
diff changeset
185 SeqInfo data_query;
762009a91895 Uploaded
bitlab
parents:
diff changeset
186
762009a91895 Uploaded
bitlab
parents:
diff changeset
187 //To force reading from the buffer
762009a91895 Uploaded
bitlab
parents:
diff changeset
188 idx = READBUF + 1;
762009a91895 Uploaded
bitlab
parents:
diff changeset
189
762009a91895 Uploaded
bitlab
parents:
diff changeset
190 //Vector to store query seq
762009a91895 Uploaded
bitlab
parents:
diff changeset
191 unsigned char * seq_vector_query = (unsigned char *) malloc(READBUF*sizeof(unsigned char));
762009a91895 Uploaded
bitlab
parents:
diff changeset
192 if(seq_vector_query == NULL) terror("Could not allocate memory for query vector");
762009a91895 Uploaded
bitlab
parents:
diff changeset
193 uint64_t n_realloc_query = 1, pos_in_query = 0, n_seqs_query_realloc = 1;
762009a91895 Uploaded
bitlab
parents:
diff changeset
194 uint64_t * query_positions = (uint64_t *) malloc(INITSEQS*sizeof(uint64_t));
762009a91895 Uploaded
bitlab
parents:
diff changeset
195 if(query_positions == NULL) terror("Could not allocate query sequences positions");
762009a91895 Uploaded
bitlab
parents:
diff changeset
196
762009a91895 Uploaded
bitlab
parents:
diff changeset
197
762009a91895 Uploaded
bitlab
parents:
diff changeset
198
762009a91895 Uploaded
bitlab
parents:
diff changeset
199 // Read number of sequences and load into RAM
762009a91895 Uploaded
bitlab
parents:
diff changeset
200 begin = clock();
762009a91895 Uploaded
bitlab
parents:
diff changeset
201 fseek(database, 0L, SEEK_END);
762009a91895 Uploaded
bitlab
parents:
diff changeset
202 uint64_t db_temp_size = ftell(database);
762009a91895 Uploaded
bitlab
parents:
diff changeset
203 char * load_buffer = (char *) malloc(db_temp_size * sizeof(char));
762009a91895 Uploaded
bitlab
parents:
diff changeset
204 if(load_buffer == NULL) terror("Could not allocate intermediate buffer for threads sequence array");
762009a91895 Uploaded
bitlab
parents:
diff changeset
205 fseek(database, 0L, SEEK_SET);
762009a91895 Uploaded
bitlab
parents:
diff changeset
206
762009a91895 Uploaded
bitlab
parents:
diff changeset
207 if(db_temp_size != fread(load_buffer, sizeof(char), db_temp_size, database)) terror("Could not read full sequence");
762009a91895 Uploaded
bitlab
parents:
diff changeset
208
762009a91895 Uploaded
bitlab
parents:
diff changeset
209 LoadingDBArgs args_DB_load[FIXED_LOADING_THREADS];
762009a91895 Uploaded
bitlab
parents:
diff changeset
210
762009a91895 Uploaded
bitlab
parents:
diff changeset
211
762009a91895 Uploaded
bitlab
parents:
diff changeset
212 args_DB_load[0].data_database = &data_database[0];
762009a91895 Uploaded
bitlab
parents:
diff changeset
213 args_DB_load[1].data_database = &data_database[1];
762009a91895 Uploaded
bitlab
parents:
diff changeset
214 args_DB_load[2].data_database = &data_database[2];
762009a91895 Uploaded
bitlab
parents:
diff changeset
215 args_DB_load[3].data_database = &data_database[3];
762009a91895 Uploaded
bitlab
parents:
diff changeset
216
762009a91895 Uploaded
bitlab
parents:
diff changeset
217 args_DB_load[0].ct = ct_A;
762009a91895 Uploaded
bitlab
parents:
diff changeset
218 args_DB_load[1].ct = ct_B;
762009a91895 Uploaded
bitlab
parents:
diff changeset
219 args_DB_load[2].ct = ct_C;
762009a91895 Uploaded
bitlab
parents:
diff changeset
220 args_DB_load[3].ct = ct_D;
762009a91895 Uploaded
bitlab
parents:
diff changeset
221 for(i=0; i<FIXED_LOADING_THREADS; i++){
762009a91895 Uploaded
bitlab
parents:
diff changeset
222 args_DB_load[i].read_to = 0;
762009a91895 Uploaded
bitlab
parents:
diff changeset
223 args_DB_load[i].read_from = 0;
762009a91895 Uploaded
bitlab
parents:
diff changeset
224 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
225
762009a91895 Uploaded
bitlab
parents:
diff changeset
226 //uint64_t a_fourth = db_temp_size / 4;
762009a91895 Uploaded
bitlab
parents:
diff changeset
227
762009a91895 Uploaded
bitlab
parents:
diff changeset
228
762009a91895 Uploaded
bitlab
parents:
diff changeset
229 //get_num_seqs_and_length(load_buffer, &full_db_n_seqs, &db_temp_size, args_DB_load);
762009a91895 Uploaded
bitlab
parents:
diff changeset
230
762009a91895 Uploaded
bitlab
parents:
diff changeset
231 end = clock();
762009a91895 Uploaded
bitlab
parents:
diff changeset
232 fprintf(stdout, "[INFO] Loading into RAM took %e seconds.\n", (double)(end-begin)/CLOCKS_PER_SEC);
762009a91895 Uploaded
bitlab
parents:
diff changeset
233 begin = clock();
762009a91895 Uploaded
bitlab
parents:
diff changeset
234
762009a91895 Uploaded
bitlab
parents:
diff changeset
235 /*
762009a91895 Uploaded
bitlab
parents:
diff changeset
236 char * temp_seq_buffer;
762009a91895 Uploaded
bitlab
parents:
diff changeset
237 SeqInfo * data_database;
762009a91895 Uploaded
bitlab
parents:
diff changeset
238 uint64_t t_len;
762009a91895 Uploaded
bitlab
parents:
diff changeset
239 uint64_t word_size;
762009a91895 Uploaded
bitlab
parents:
diff changeset
240 uint64_t read_from;
762009a91895 Uploaded
bitlab
parents:
diff changeset
241 uint64_t read_to;
762009a91895 Uploaded
bitlab
parents:
diff changeset
242 char thread_id;
762009a91895 Uploaded
bitlab
parents:
diff changeset
243 Mempool_l * mp;
762009a91895 Uploaded
bitlab
parents:
diff changeset
244 uint64_t n_pools_used;
762009a91895 Uploaded
bitlab
parents:
diff changeset
245 */
762009a91895 Uploaded
bitlab
parents:
diff changeset
246
762009a91895 Uploaded
bitlab
parents:
diff changeset
247 // Launch threads to process database
762009a91895 Uploaded
bitlab
parents:
diff changeset
248
762009a91895 Uploaded
bitlab
parents:
diff changeset
249 args_DB_load[0].thread_id = 'A';
762009a91895 Uploaded
bitlab
parents:
diff changeset
250 args_DB_load[1].thread_id = 'B';
762009a91895 Uploaded
bitlab
parents:
diff changeset
251 args_DB_load[2].thread_id = 'C';
762009a91895 Uploaded
bitlab
parents:
diff changeset
252 args_DB_load[3].thread_id = 'D';
762009a91895 Uploaded
bitlab
parents:
diff changeset
253
762009a91895 Uploaded
bitlab
parents:
diff changeset
254
762009a91895 Uploaded
bitlab
parents:
diff changeset
255 for(i=0; i<FIXED_LOADING_THREADS; i++){
762009a91895 Uploaded
bitlab
parents:
diff changeset
256
762009a91895 Uploaded
bitlab
parents:
diff changeset
257 //seq_vector_database[i] = (unsigned char *) malloc((args_DB_load[i].read_to - args_DB_load[i].read_from)*sizeof(unsigned char));
762009a91895 Uploaded
bitlab
parents:
diff changeset
258 seq_vector_database[i] = (unsigned char *) malloc((READBUF)*sizeof(unsigned char));
762009a91895 Uploaded
bitlab
parents:
diff changeset
259 //database_positions[i] = (uint64_t *) malloc((1+data_database[i].n_seqs)*sizeof(uint64_t));
762009a91895 Uploaded
bitlab
parents:
diff changeset
260 database_positions[i] = (uint64_t *) malloc((INITSEQS)*sizeof(uint64_t));
762009a91895 Uploaded
bitlab
parents:
diff changeset
261 if(seq_vector_database[i] == NULL || database_positions[i] == NULL) terror("Could not allocate memory for individual database vectors");
762009a91895 Uploaded
bitlab
parents:
diff changeset
262 data_database[i].sequences = seq_vector_database[i];
762009a91895 Uploaded
bitlab
parents:
diff changeset
263
762009a91895 Uploaded
bitlab
parents:
diff changeset
264
762009a91895 Uploaded
bitlab
parents:
diff changeset
265 //To hold all information related to database
762009a91895 Uploaded
bitlab
parents:
diff changeset
266 args_DB_load[i].n_pools_used = 0;
762009a91895 Uploaded
bitlab
parents:
diff changeset
267 args_DB_load[i].n_pools_used_AVL = 0;
762009a91895 Uploaded
bitlab
parents:
diff changeset
268
762009a91895 Uploaded
bitlab
parents:
diff changeset
269 init_mem_pool_llpos(&mp[i][args_DB_load[i].n_pools_used]);
762009a91895 Uploaded
bitlab
parents:
diff changeset
270 init_mem_pool_AVL(&mp_AVL[i][args_DB_load[i].n_pools_used_AVL]);
762009a91895 Uploaded
bitlab
parents:
diff changeset
271
762009a91895 Uploaded
bitlab
parents:
diff changeset
272 data_database[i].start_pos = database_positions[i];
762009a91895 Uploaded
bitlab
parents:
diff changeset
273
762009a91895 Uploaded
bitlab
parents:
diff changeset
274 args_DB_load[i].n_allocs = 1;
762009a91895 Uploaded
bitlab
parents:
diff changeset
275 args_DB_load[i].read_from = i * (db_temp_size / 4);
762009a91895 Uploaded
bitlab
parents:
diff changeset
276 args_DB_load[i].read_to = (i+1) * (db_temp_size / 4);
762009a91895 Uploaded
bitlab
parents:
diff changeset
277 args_DB_load[i].temp_seq_buffer = load_buffer;
762009a91895 Uploaded
bitlab
parents:
diff changeset
278 args_DB_load[i].t_len = db_temp_size;
762009a91895 Uploaded
bitlab
parents:
diff changeset
279 args_DB_load[i].word_size = custom_kmer;
762009a91895 Uploaded
bitlab
parents:
diff changeset
280 args_DB_load[i].mp = mp[i];
762009a91895 Uploaded
bitlab
parents:
diff changeset
281 args_DB_load[i].mp_AVL = mp_AVL[i];
762009a91895 Uploaded
bitlab
parents:
diff changeset
282
762009a91895 Uploaded
bitlab
parents:
diff changeset
283 if( 0 != (error = pthread_create(&loading_threads[i], NULL, load_input, (void *) (&args_DB_load[i])) )){
762009a91895 Uploaded
bitlab
parents:
diff changeset
284 fprintf(stdout, "[@loading] Thread %"PRIu64" returned %d:", i, error); terror("Could not launch");
762009a91895 Uploaded
bitlab
parents:
diff changeset
285 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
286 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
287
762009a91895 Uploaded
bitlab
parents:
diff changeset
288 //Wait for threads to finish
762009a91895 Uploaded
bitlab
parents:
diff changeset
289 for(i=0;i<FIXED_LOADING_THREADS;i++){
762009a91895 Uploaded
bitlab
parents:
diff changeset
290 pthread_join(loading_threads[i], NULL);
762009a91895 Uploaded
bitlab
parents:
diff changeset
291 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
292
762009a91895 Uploaded
bitlab
parents:
diff changeset
293 // Deallocate memory not needed anymore
762009a91895 Uploaded
bitlab
parents:
diff changeset
294 free(load_buffer);
762009a91895 Uploaded
bitlab
parents:
diff changeset
295 free(loading_threads);
762009a91895 Uploaded
bitlab
parents:
diff changeset
296
762009a91895 Uploaded
bitlab
parents:
diff changeset
297
762009a91895 Uploaded
bitlab
parents:
diff changeset
298
762009a91895 Uploaded
bitlab
parents:
diff changeset
299 //fprintf(stdout, "[INFO] WARNING!!!!!!!!! USING NON OVERLAPPING MERS, WHICH IS NOT INCLUDED AS OPTION!!!! DISABLE\n");
762009a91895 Uploaded
bitlab
parents:
diff changeset
300
762009a91895 Uploaded
bitlab
parents:
diff changeset
301
762009a91895 Uploaded
bitlab
parents:
diff changeset
302
762009a91895 Uploaded
bitlab
parents:
diff changeset
303
762009a91895 Uploaded
bitlab
parents:
diff changeset
304
762009a91895 Uploaded
bitlab
parents:
diff changeset
305 //data_database.total_len = pos_in_database;
762009a91895 Uploaded
bitlab
parents:
diff changeset
306 //printf("tables have %"PRIu64" %"PRIu64", %"PRIu64" %"PRIu64"\n", data_database[0].total_len, data_database[1].total_len, data_database[2].total_len, data_database[3].total_len);
762009a91895 Uploaded
bitlab
parents:
diff changeset
307 uint64_t full_db_len = data_database[0].total_len + data_database[1].total_len + data_database[2].total_len + data_database[3].total_len;
762009a91895 Uploaded
bitlab
parents:
diff changeset
308 full_db_n_seqs = args_DB_load[0].contained_reads + args_DB_load[1].contained_reads + args_DB_load[2].contained_reads + args_DB_load[3].contained_reads;
762009a91895 Uploaded
bitlab
parents:
diff changeset
309
762009a91895 Uploaded
bitlab
parents:
diff changeset
310 end = clock();
762009a91895 Uploaded
bitlab
parents:
diff changeset
311 fprintf(stdout, "[INFO] Database loaded and of length %"PRIu64" (%"PRIu64" sequences). Hash table building took %e seconds\n", full_db_len, full_db_n_seqs, (double)(end-begin)/CLOCKS_PER_SEC);
762009a91895 Uploaded
bitlab
parents:
diff changeset
312 //close database
762009a91895 Uploaded
bitlab
parents:
diff changeset
313 fclose(database);
762009a91895 Uploaded
bitlab
parents:
diff changeset
314
762009a91895 Uploaded
bitlab
parents:
diff changeset
315 // Allocate marker tags to avoid repeting computation
762009a91895 Uploaded
bitlab
parents:
diff changeset
316
762009a91895 Uploaded
bitlab
parents:
diff changeset
317 marker_taggs = (unsigned char **) malloc(n_threads * sizeof(unsigned char *));
762009a91895 Uploaded
bitlab
parents:
diff changeset
318 if(marker_taggs == NULL) terror("Could not allocate marker taggs");
762009a91895 Uploaded
bitlab
parents:
diff changeset
319 for(i=0;i<n_threads;i++){
762009a91895 Uploaded
bitlab
parents:
diff changeset
320 marker_taggs[i] = (unsigned char *) malloc(full_db_n_seqs);
762009a91895 Uploaded
bitlab
parents:
diff changeset
321 if(marker_taggs[i] == NULL) terror("Could not allocate second loop of marker taggs");
762009a91895 Uploaded
bitlab
parents:
diff changeset
322 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
323 if(hits_only == TRUE){
762009a91895 Uploaded
bitlab
parents:
diff changeset
324 hits_table = (uint64_t **) calloc(n_threads, sizeof(uint64_t *));
762009a91895 Uploaded
bitlab
parents:
diff changeset
325 if(hits_table == NULL) terror("Could not allocate hits table");
762009a91895 Uploaded
bitlab
parents:
diff changeset
326 uint64_t z;
762009a91895 Uploaded
bitlab
parents:
diff changeset
327 for(z=0;z<n_threads;z++){
762009a91895 Uploaded
bitlab
parents:
diff changeset
328 hits_table[z] = (uint64_t *) calloc(full_db_n_seqs, sizeof(uint64_t));
762009a91895 Uploaded
bitlab
parents:
diff changeset
329 if(hits_table[z] == NULL) terror("Could not allocate sub table of hits");
762009a91895 Uploaded
bitlab
parents:
diff changeset
330 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
331 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
332
762009a91895 Uploaded
bitlab
parents:
diff changeset
333
762009a91895 Uploaded
bitlab
parents:
diff changeset
334 begin = clock();
762009a91895 Uploaded
bitlab
parents:
diff changeset
335
762009a91895 Uploaded
bitlab
parents:
diff changeset
336
762009a91895 Uploaded
bitlab
parents:
diff changeset
337
762009a91895 Uploaded
bitlab
parents:
diff changeset
338 //To force reading from the buffer
762009a91895 Uploaded
bitlab
parents:
diff changeset
339 idx = READBUF + 1;
762009a91895 Uploaded
bitlab
parents:
diff changeset
340
762009a91895 Uploaded
bitlab
parents:
diff changeset
341
762009a91895 Uploaded
bitlab
parents:
diff changeset
342 data_query.sequences = seq_vector_query;
762009a91895 Uploaded
bitlab
parents:
diff changeset
343 data_query.start_pos = query_positions;
762009a91895 Uploaded
bitlab
parents:
diff changeset
344 data_query.total_len = 0;
762009a91895 Uploaded
bitlab
parents:
diff changeset
345 data_query.n_seqs = 0;
762009a91895 Uploaded
bitlab
parents:
diff changeset
346
762009a91895 Uploaded
bitlab
parents:
diff changeset
347
762009a91895 Uploaded
bitlab
parents:
diff changeset
348 //Print info
762009a91895 Uploaded
bitlab
parents:
diff changeset
349 fprintf(stdout, "[INFO] Loading query.\n");
762009a91895 Uploaded
bitlab
parents:
diff changeset
350
762009a91895 Uploaded
bitlab
parents:
diff changeset
351
762009a91895 Uploaded
bitlab
parents:
diff changeset
352 c = buffered_fgetc(temp_seq_buffer, &idx, &r, query);
762009a91895 Uploaded
bitlab
parents:
diff changeset
353 while((!feof(query) || (feof(query) && idx < r))){
762009a91895 Uploaded
bitlab
parents:
diff changeset
354
762009a91895 Uploaded
bitlab
parents:
diff changeset
355 if(c == '>'){
762009a91895 Uploaded
bitlab
parents:
diff changeset
356 data_query.start_pos[data_query.n_seqs++] = pos_in_query;
762009a91895 Uploaded
bitlab
parents:
diff changeset
357 word_size = 0;
762009a91895 Uploaded
bitlab
parents:
diff changeset
358
762009a91895 Uploaded
bitlab
parents:
diff changeset
359 if(pos_in_query == READBUF*n_realloc_query){
762009a91895 Uploaded
bitlab
parents:
diff changeset
360 n_realloc_query++; data_query.sequences = (unsigned char *) realloc(data_query.sequences, READBUF*n_realloc_query*sizeof(unsigned char));
762009a91895 Uploaded
bitlab
parents:
diff changeset
361 if(data_query.sequences == NULL) terror("Could not reallocate temporary query");
762009a91895 Uploaded
bitlab
parents:
diff changeset
362 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
363
762009a91895 Uploaded
bitlab
parents:
diff changeset
364 if(data_query.n_seqs == INITSEQS*n_seqs_query_realloc){
762009a91895 Uploaded
bitlab
parents:
diff changeset
365 n_seqs_query_realloc++; data_query.start_pos = (uint64_t *) realloc(data_query.start_pos, INITSEQS*n_seqs_query_realloc*sizeof(uint64_t));
762009a91895 Uploaded
bitlab
parents:
diff changeset
366 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
367
762009a91895 Uploaded
bitlab
parents:
diff changeset
368
762009a91895 Uploaded
bitlab
parents:
diff changeset
369 while(c != '\n'){ c = buffered_fgetc(temp_seq_buffer, &idx, &r, query); } //Skip ID
762009a91895 Uploaded
bitlab
parents:
diff changeset
370
762009a91895 Uploaded
bitlab
parents:
diff changeset
371
762009a91895 Uploaded
bitlab
parents:
diff changeset
372 while(c != '>' && (!feof(query) || (feof(query) && idx < r))){ //Until next id
762009a91895 Uploaded
bitlab
parents:
diff changeset
373 c = buffered_fgetc(temp_seq_buffer, &idx, &r, query);
762009a91895 Uploaded
bitlab
parents:
diff changeset
374 c = toupper(c);
762009a91895 Uploaded
bitlab
parents:
diff changeset
375 if(c == 'A' || c == 'C' || c == 'G' || c == 'T'){
762009a91895 Uploaded
bitlab
parents:
diff changeset
376 data_query.sequences[pos_in_query++] = (unsigned char) c;
762009a91895 Uploaded
bitlab
parents:
diff changeset
377 curr_kmer[word_size++] = (unsigned char) c;
762009a91895 Uploaded
bitlab
parents:
diff changeset
378
762009a91895 Uploaded
bitlab
parents:
diff changeset
379 if(word_size == custom_kmer){
762009a91895 Uploaded
bitlab
parents:
diff changeset
380 memcpy(aux_kmer, curr_kmer, custom_kmer);
762009a91895 Uploaded
bitlab
parents:
diff changeset
381 aux_kmer[custom_kmer] = '\0';
762009a91895 Uploaded
bitlab
parents:
diff changeset
382
762009a91895 Uploaded
bitlab
parents:
diff changeset
383 memcpy(aux_kmer, &curr_kmer[1], custom_kmer-1);
762009a91895 Uploaded
bitlab
parents:
diff changeset
384 memcpy(curr_kmer, aux_kmer, custom_kmer-1);
762009a91895 Uploaded
bitlab
parents:
diff changeset
385 word_size--;
762009a91895 Uploaded
bitlab
parents:
diff changeset
386 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
387
762009a91895 Uploaded
bitlab
parents:
diff changeset
388 if(pos_in_query == READBUF*n_realloc_query){
762009a91895 Uploaded
bitlab
parents:
diff changeset
389 n_realloc_query++; data_query.sequences = (unsigned char *) realloc(data_query.sequences, READBUF*n_realloc_query*sizeof(unsigned char));
762009a91895 Uploaded
bitlab
parents:
diff changeset
390 if(data_query.sequences == NULL) terror("Could not reallocate temporary query");
762009a91895 Uploaded
bitlab
parents:
diff changeset
391 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
392 }else{
762009a91895 Uploaded
bitlab
parents:
diff changeset
393 if(c != '\n' && c != '\r' && c != '>'){
762009a91895 Uploaded
bitlab
parents:
diff changeset
394 word_size = 0;
762009a91895 Uploaded
bitlab
parents:
diff changeset
395 data_query.sequences[pos_in_query++] = (unsigned char) 'N'; //Convert to N
762009a91895 Uploaded
bitlab
parents:
diff changeset
396 if(pos_in_query == READBUF*n_realloc_query){
762009a91895 Uploaded
bitlab
parents:
diff changeset
397 n_realloc_query++; data_query.sequences = (unsigned char *) realloc(data_query.sequences, READBUF*n_realloc_query*sizeof(unsigned char));
762009a91895 Uploaded
bitlab
parents:
diff changeset
398 if(data_query.sequences == NULL) terror("Could not reallocate temporary query");
762009a91895 Uploaded
bitlab
parents:
diff changeset
399 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
400 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
401 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
402 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
403 }else{
762009a91895 Uploaded
bitlab
parents:
diff changeset
404 c = buffered_fgetc(temp_seq_buffer, &idx, &r, query);
762009a91895 Uploaded
bitlab
parents:
diff changeset
405 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
406
762009a91895 Uploaded
bitlab
parents:
diff changeset
407 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
408
762009a91895 Uploaded
bitlab
parents:
diff changeset
409
762009a91895 Uploaded
bitlab
parents:
diff changeset
410
762009a91895 Uploaded
bitlab
parents:
diff changeset
411 end = clock();
762009a91895 Uploaded
bitlab
parents:
diff changeset
412
762009a91895 Uploaded
bitlab
parents:
diff changeset
413
762009a91895 Uploaded
bitlab
parents:
diff changeset
414 data_query.total_len = pos_in_query;
762009a91895 Uploaded
bitlab
parents:
diff changeset
415
762009a91895 Uploaded
bitlab
parents:
diff changeset
416 fprintf(stdout, "[INFO] Query loaded and of length %"PRIu64". Took %e seconds\n", data_query.total_len, (double)(end-begin)/CLOCKS_PER_SEC);
762009a91895 Uploaded
bitlab
parents:
diff changeset
417
762009a91895 Uploaded
bitlab
parents:
diff changeset
418 begin = clock();
762009a91895 Uploaded
bitlab
parents:
diff changeset
419
762009a91895 Uploaded
bitlab
parents:
diff changeset
420 Head queue_head;
762009a91895 Uploaded
bitlab
parents:
diff changeset
421 Queue * first_task = generate_queue(&queue_head, data_query.n_seqs, n_threads, n_parts);
762009a91895 Uploaded
bitlab
parents:
diff changeset
422
762009a91895 Uploaded
bitlab
parents:
diff changeset
423 /*
762009a91895 Uploaded
bitlab
parents:
diff changeset
424 Queue * traverse = queue_head.head;
762009a91895 Uploaded
bitlab
parents:
diff changeset
425 while(traverse != NULL){
762009a91895 Uploaded
bitlab
parents:
diff changeset
426 printf("current_piece: %"PRIu64"-%"PRIu64"\n", traverse->r1, traverse->r2);
762009a91895 Uploaded
bitlab
parents:
diff changeset
427 traverse = traverse->next;
762009a91895 Uploaded
bitlab
parents:
diff changeset
428 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
429 getchar();
762009a91895 Uploaded
bitlab
parents:
diff changeset
430 */
762009a91895 Uploaded
bitlab
parents:
diff changeset
431
762009a91895 Uploaded
bitlab
parents:
diff changeset
432
762009a91895 Uploaded
bitlab
parents:
diff changeset
433
762009a91895 Uploaded
bitlab
parents:
diff changeset
434 //reads_per_thread = (uint64_t) (floorl((long double) data_query.n_seqs / (long double) n_threads));
762009a91895 Uploaded
bitlab
parents:
diff changeset
435
762009a91895 Uploaded
bitlab
parents:
diff changeset
436 fprintf(stdout, "[INFO] Computing alignments.\n");
762009a91895 Uploaded
bitlab
parents:
diff changeset
437
762009a91895 Uploaded
bitlab
parents:
diff changeset
438
762009a91895 Uploaded
bitlab
parents:
diff changeset
439
762009a91895 Uploaded
bitlab
parents:
diff changeset
440 /*
762009a91895 Uploaded
bitlab
parents:
diff changeset
441 uint64_t z;
762009a91895 Uploaded
bitlab
parents:
diff changeset
442 for(z=0; z<POOL_SIZE; z++){
762009a91895 Uploaded
bitlab
parents:
diff changeset
443 aux = mp[0].base + z;
762009a91895 Uploaded
bitlab
parents:
diff changeset
444 fprintf(stdout, "%p\n", aux);
762009a91895 Uploaded
bitlab
parents:
diff changeset
445 fflush(stdout);
762009a91895 Uploaded
bitlab
parents:
diff changeset
446 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
447 */
762009a91895 Uploaded
bitlab
parents:
diff changeset
448
762009a91895 Uploaded
bitlab
parents:
diff changeset
449 // Make the full db
762009a91895 Uploaded
bitlab
parents:
diff changeset
450 uint64_t contained_reads[FIXED_LOADING_THREADS] = {0,0,0,0};
762009a91895 Uploaded
bitlab
parents:
diff changeset
451 uint64_t base_coordinates[FIXED_LOADING_THREADS] = {0,0,0,0};
762009a91895 Uploaded
bitlab
parents:
diff changeset
452 //contained_reads[0] = 0;
762009a91895 Uploaded
bitlab
parents:
diff changeset
453 //base_coordinates[0] = 0;
762009a91895 Uploaded
bitlab
parents:
diff changeset
454 for(i=1;i<FIXED_LOADING_THREADS;i++){
762009a91895 Uploaded
bitlab
parents:
diff changeset
455 contained_reads[i] = args_DB_load[i-1].contained_reads + contained_reads[i-1];
762009a91895 Uploaded
bitlab
parents:
diff changeset
456 base_coordinates[i] = args_DB_load[i-1].base_coordinates + base_coordinates[i-1];
762009a91895 Uploaded
bitlab
parents:
diff changeset
457 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
458
762009a91895 Uploaded
bitlab
parents:
diff changeset
459 /*
762009a91895 Uploaded
bitlab
parents:
diff changeset
460 for(i = 0; i < 4 ; i++){
762009a91895 Uploaded
bitlab
parents:
diff changeset
461 printf("total len: %"PRIu64"\n", data_database[i].total_len);
762009a91895 Uploaded
bitlab
parents:
diff changeset
462
762009a91895 Uploaded
bitlab
parents:
diff changeset
463 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
464 getchar();
762009a91895 Uploaded
bitlab
parents:
diff changeset
465 */
762009a91895 Uploaded
bitlab
parents:
diff changeset
466 /*
762009a91895 Uploaded
bitlab
parents:
diff changeset
467 for(i = 0; i < 4 ; i++){
762009a91895 Uploaded
bitlab
parents:
diff changeset
468
762009a91895 Uploaded
bitlab
parents:
diff changeset
469 printf("c:%"PRIu64" - b:%"PRIu64"\n", contained_reads[i], base_coordinates[i]);
762009a91895 Uploaded
bitlab
parents:
diff changeset
470 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
471 getchar();
762009a91895 Uploaded
bitlab
parents:
diff changeset
472 */
762009a91895 Uploaded
bitlab
parents:
diff changeset
473
762009a91895 Uploaded
bitlab
parents:
diff changeset
474
762009a91895 Uploaded
bitlab
parents:
diff changeset
475
762009a91895 Uploaded
bitlab
parents:
diff changeset
476
762009a91895 Uploaded
bitlab
parents:
diff changeset
477 SeqInfo final_db;
762009a91895 Uploaded
bitlab
parents:
diff changeset
478 final_db.sequences = (unsigned char *) malloc(full_db_len * sizeof(unsigned char));
762009a91895 Uploaded
bitlab
parents:
diff changeset
479 if(final_db.sequences == NULL) terror ("Could not allocate final database sequences");
762009a91895 Uploaded
bitlab
parents:
diff changeset
480 memcpy(&final_db.sequences[0], &data_database[0].sequences[0], data_database[0].total_len);
762009a91895 Uploaded
bitlab
parents:
diff changeset
481 memcpy(&final_db.sequences[data_database[0].total_len], &data_database[1].sequences[0], data_database[1].total_len);
762009a91895 Uploaded
bitlab
parents:
diff changeset
482 memcpy(&final_db.sequences[data_database[0].total_len+data_database[1].total_len], &data_database[2].sequences[0], data_database[2].total_len);
762009a91895 Uploaded
bitlab
parents:
diff changeset
483 memcpy(&final_db.sequences[data_database[0].total_len+data_database[1].total_len+data_database[2].total_len], &data_database[3].sequences[0], data_database[3].total_len);
762009a91895 Uploaded
bitlab
parents:
diff changeset
484 final_db.start_pos = (uint64_t *) malloc(full_db_n_seqs * sizeof(uint64_t));
762009a91895 Uploaded
bitlab
parents:
diff changeset
485 if(final_db.start_pos == NULL) terror("Could not allocate final db starting positions");
762009a91895 Uploaded
bitlab
parents:
diff changeset
486 // Copy them with offset
762009a91895 Uploaded
bitlab
parents:
diff changeset
487 i=0;
762009a91895 Uploaded
bitlab
parents:
diff changeset
488 while(i<data_database[0].n_seqs){ final_db.start_pos[i] = data_database[0].start_pos[i]; ++i; }
762009a91895 Uploaded
bitlab
parents:
diff changeset
489 j=0;
762009a91895 Uploaded
bitlab
parents:
diff changeset
490 //printf("switch\n");
762009a91895 Uploaded
bitlab
parents:
diff changeset
491 while(j<data_database[1].n_seqs){ final_db.start_pos[i] = data_database[1].start_pos[j] + data_database[0].total_len; ++i; ++j; }
762009a91895 Uploaded
bitlab
parents:
diff changeset
492 j=0;
762009a91895 Uploaded
bitlab
parents:
diff changeset
493 //printf("switch\n");
762009a91895 Uploaded
bitlab
parents:
diff changeset
494 while(j<data_database[2].n_seqs){ final_db.start_pos[i] = data_database[2].start_pos[j] + data_database[1].total_len + data_database[0].total_len; ++i; ++j; }
762009a91895 Uploaded
bitlab
parents:
diff changeset
495 j=0;
762009a91895 Uploaded
bitlab
parents:
diff changeset
496 //printf("switch\n");
762009a91895 Uploaded
bitlab
parents:
diff changeset
497 while(j<data_database[3].n_seqs){ final_db.start_pos[i] = data_database[3].start_pos[j] + data_database[2].total_len + data_database[1].total_len + data_database[0].total_len; ++i; ++j; }
762009a91895 Uploaded
bitlab
parents:
diff changeset
498
762009a91895 Uploaded
bitlab
parents:
diff changeset
499 final_db.total_len = full_db_len;
762009a91895 Uploaded
bitlab
parents:
diff changeset
500 final_db.n_seqs = full_db_n_seqs;
762009a91895 Uploaded
bitlab
parents:
diff changeset
501
762009a91895 Uploaded
bitlab
parents:
diff changeset
502 for(i=0;i<FIXED_LOADING_THREADS;i++){
762009a91895 Uploaded
bitlab
parents:
diff changeset
503 free(data_database[i].sequences);
762009a91895 Uploaded
bitlab
parents:
diff changeset
504 free(data_database[i].start_pos);
762009a91895 Uploaded
bitlab
parents:
diff changeset
505 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
506
762009a91895 Uploaded
bitlab
parents:
diff changeset
507
762009a91895 Uploaded
bitlab
parents:
diff changeset
508 // Debug
762009a91895 Uploaded
bitlab
parents:
diff changeset
509 /*
762009a91895 Uploaded
bitlab
parents:
diff changeset
510 uint64_t max = 0;
762009a91895 Uploaded
bitlab
parents:
diff changeset
511 for(i=0; i<full_db_n_seqs-2; i++){
762009a91895 Uploaded
bitlab
parents:
diff changeset
512 //printf("%"PRIu64" - %"PRIu64" res in \n", final_db.start_pos[i], final_db.start_pos[i+1]);
762009a91895 Uploaded
bitlab
parents:
diff changeset
513 //printf("%"PRIu64"\n", final_db.start_pos[i+2] - final_db.start_pos[i+1]);
762009a91895 Uploaded
bitlab
parents:
diff changeset
514 if(final_db.start_pos[i+2] - final_db.start_pos[i+1] > max) max = final_db.start_pos[i+2] - final_db.start_pos[i+1];
762009a91895 Uploaded
bitlab
parents:
diff changeset
515 //getchar();
762009a91895 Uploaded
bitlab
parents:
diff changeset
516 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
517 printf("%"PRIu64"\n", max);
762009a91895 Uploaded
bitlab
parents:
diff changeset
518 */
762009a91895 Uploaded
bitlab
parents:
diff changeset
519
762009a91895 Uploaded
bitlab
parents:
diff changeset
520
762009a91895 Uploaded
bitlab
parents:
diff changeset
521
762009a91895 Uploaded
bitlab
parents:
diff changeset
522
762009a91895 Uploaded
bitlab
parents:
diff changeset
523
762009a91895 Uploaded
bitlab
parents:
diff changeset
524 for(i=0;i<n_threads;i++){
762009a91895 Uploaded
bitlab
parents:
diff changeset
525 hta[i].id = i;
762009a91895 Uploaded
bitlab
parents:
diff changeset
526 hta[i].database = &final_db;
762009a91895 Uploaded
bitlab
parents:
diff changeset
527 hta[i].query = &data_query;
762009a91895 Uploaded
bitlab
parents:
diff changeset
528
762009a91895 Uploaded
bitlab
parents:
diff changeset
529 //hta[i].from = i * reads_per_thread;
762009a91895 Uploaded
bitlab
parents:
diff changeset
530 //hta[i].to = (i + 1) * reads_per_thread;
762009a91895 Uploaded
bitlab
parents:
diff changeset
531 hta[i].container_a = ct_A;
762009a91895 Uploaded
bitlab
parents:
diff changeset
532 hta[i].container_b = ct_B;
762009a91895 Uploaded
bitlab
parents:
diff changeset
533 hta[i].container_c = ct_C;
762009a91895 Uploaded
bitlab
parents:
diff changeset
534 hta[i].container_d = ct_D;
762009a91895 Uploaded
bitlab
parents:
diff changeset
535 hta[i].contained_reads = contained_reads;
762009a91895 Uploaded
bitlab
parents:
diff changeset
536 hta[i].base_coordinates = base_coordinates;
762009a91895 Uploaded
bitlab
parents:
diff changeset
537 hta[i].accepted_query_reads = 0;
762009a91895 Uploaded
bitlab
parents:
diff changeset
538 hta[i].min_e_value = minevalue;
762009a91895 Uploaded
bitlab
parents:
diff changeset
539 hta[i].min_coverage = mincoverage;
762009a91895 Uploaded
bitlab
parents:
diff changeset
540 hta[i].min_identity = minidentity;
762009a91895 Uploaded
bitlab
parents:
diff changeset
541 hta[i].out = out_database;
762009a91895 Uploaded
bitlab
parents:
diff changeset
542 hta[i].igap = igap;
762009a91895 Uploaded
bitlab
parents:
diff changeset
543 hta[i].egap = egap;
762009a91895 Uploaded
bitlab
parents:
diff changeset
544 hta[i].window = window;
762009a91895 Uploaded
bitlab
parents:
diff changeset
545 hta[i].mc = mc[i];
762009a91895 Uploaded
bitlab
parents:
diff changeset
546 hta[i].table = table[i];
762009a91895 Uploaded
bitlab
parents:
diff changeset
547 hta[i].reconstruct_X = reconstruct_X[i];
762009a91895 Uploaded
bitlab
parents:
diff changeset
548 hta[i].reconstruct_Y = reconstruct_Y[i];
762009a91895 Uploaded
bitlab
parents:
diff changeset
549 hta[i].writing_buffer_alignment = writing_buffer_alignment[i];
762009a91895 Uploaded
bitlab
parents:
diff changeset
550 hta[i].my_x = my_x[i];
762009a91895 Uploaded
bitlab
parents:
diff changeset
551 hta[i].my_y = my_y[i];
762009a91895 Uploaded
bitlab
parents:
diff changeset
552 hta[i].queue_head = &queue_head;
762009a91895 Uploaded
bitlab
parents:
diff changeset
553 hta[i].lock = &lock;
762009a91895 Uploaded
bitlab
parents:
diff changeset
554 hta[i].full_comp = full_comp;
762009a91895 Uploaded
bitlab
parents:
diff changeset
555 hta[i].markers = marker_taggs[i];
762009a91895 Uploaded
bitlab
parents:
diff changeset
556 if(hits_only) hta[i].hits = hits_table[i]; else hta[i].hits = NULL;
762009a91895 Uploaded
bitlab
parents:
diff changeset
557
762009a91895 Uploaded
bitlab
parents:
diff changeset
558
762009a91895 Uploaded
bitlab
parents:
diff changeset
559 //if(i==n_threads-1) hta[i].to = data_query.n_seqs;
762009a91895 Uploaded
bitlab
parents:
diff changeset
560
762009a91895 Uploaded
bitlab
parents:
diff changeset
561 if( 0 != (error = pthread_create(&threads[i], NULL, computeAlignmentsByThread, (void *) (&hta[i])) )){
762009a91895 Uploaded
bitlab
parents:
diff changeset
562 fprintf(stdout, "Thread %"PRIu64" returned %d:", i, error); terror("Could not launch");
762009a91895 Uploaded
bitlab
parents:
diff changeset
563 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
564 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
565
762009a91895 Uploaded
bitlab
parents:
diff changeset
566 //Wait for threads to finish
762009a91895 Uploaded
bitlab
parents:
diff changeset
567 for(i=0;i<n_threads;i++){
762009a91895 Uploaded
bitlab
parents:
diff changeset
568 pthread_join(threads[i], NULL);
762009a91895 Uploaded
bitlab
parents:
diff changeset
569 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
570
762009a91895 Uploaded
bitlab
parents:
diff changeset
571
762009a91895 Uploaded
bitlab
parents:
diff changeset
572 for(i=0;i<n_threads;i++){
762009a91895 Uploaded
bitlab
parents:
diff changeset
573 sum_accepted_reads += hta[i].accepted_query_reads;
762009a91895 Uploaded
bitlab
parents:
diff changeset
574 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
575 // Accumulate hits just in case
762009a91895 Uploaded
bitlab
parents:
diff changeset
576 if(hits_only == TRUE){
762009a91895 Uploaded
bitlab
parents:
diff changeset
577 for(i=0;i<full_db_n_seqs;i++){
762009a91895 Uploaded
bitlab
parents:
diff changeset
578 for(j=1;j<n_threads;j++){
762009a91895 Uploaded
bitlab
parents:
diff changeset
579 hta[0].hits[i] += hta[j].hits[i];
762009a91895 Uploaded
bitlab
parents:
diff changeset
580 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
581 if(out_database != NULL){
762009a91895 Uploaded
bitlab
parents:
diff changeset
582
762009a91895 Uploaded
bitlab
parents:
diff changeset
583 if(i == final_db.n_seqs - 1){
762009a91895 Uploaded
bitlab
parents:
diff changeset
584 fprintf(out_database, "%"PRIu64"\t%"PRIu64"\t%"PRIu64"\n", i, hta[0].hits[i], full_db_len - final_db.start_pos[i]);
762009a91895 Uploaded
bitlab
parents:
diff changeset
585 }else{
762009a91895 Uploaded
bitlab
parents:
diff changeset
586 fprintf(out_database, "%"PRIu64"\t%"PRIu64"\t%"PRIu64"\n", i, hta[0].hits[i], final_db.start_pos[i+1] - final_db.start_pos[i]);
762009a91895 Uploaded
bitlab
parents:
diff changeset
587 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
588 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
589 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
590 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
591
762009a91895 Uploaded
bitlab
parents:
diff changeset
592
762009a91895 Uploaded
bitlab
parents:
diff changeset
593 end = clock();
762009a91895 Uploaded
bitlab
parents:
diff changeset
594 fprintf(stdout, "[INFO] Alignments computed in %e seconds.\n", (double)(end-begin)/CLOCKS_PER_SEC);
762009a91895 Uploaded
bitlab
parents:
diff changeset
595 fprintf(stdout, "[INFO] %"PRIu64" reads (%"PRIu64") from the query were found in the database (%"PRIu64") at a minimum e-value of %Le and minimum coverage of %d%%.\n", sum_accepted_reads, data_query.n_seqs, final_db.n_seqs, (long double)minevalue, (int) (100*mincoverage));
762009a91895 Uploaded
bitlab
parents:
diff changeset
596 fprintf(stdout, "[INFO] The Jaccard-index is: %Le\n", (long double)sum_accepted_reads/((final_db.n_seqs+data_query.n_seqs)-sum_accepted_reads));
762009a91895 Uploaded
bitlab
parents:
diff changeset
597 fprintf(stdout, "[INFO] Deallocating heap memory.\n");
762009a91895 Uploaded
bitlab
parents:
diff changeset
598
762009a91895 Uploaded
bitlab
parents:
diff changeset
599 fclose(query);
762009a91895 Uploaded
bitlab
parents:
diff changeset
600
762009a91895 Uploaded
bitlab
parents:
diff changeset
601 if(out_database != NULL) fclose(out_database);
762009a91895 Uploaded
bitlab
parents:
diff changeset
602 free(temp_seq_buffer);
762009a91895 Uploaded
bitlab
parents:
diff changeset
603
762009a91895 Uploaded
bitlab
parents:
diff changeset
604
762009a91895 Uploaded
bitlab
parents:
diff changeset
605 if(hits_only == TRUE){
762009a91895 Uploaded
bitlab
parents:
diff changeset
606 // Write hits here
762009a91895 Uploaded
bitlab
parents:
diff changeset
607 for(i=0;i<n_threads;i++){
762009a91895 Uploaded
bitlab
parents:
diff changeset
608 free(hits_table[i]);
762009a91895 Uploaded
bitlab
parents:
diff changeset
609 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
610 free(hits_table);
762009a91895 Uploaded
bitlab
parents:
diff changeset
611 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
612
762009a91895 Uploaded
bitlab
parents:
diff changeset
613 free(final_db.sequences);
762009a91895 Uploaded
bitlab
parents:
diff changeset
614 free(final_db.start_pos);
762009a91895 Uploaded
bitlab
parents:
diff changeset
615 free(data_query.sequences);
762009a91895 Uploaded
bitlab
parents:
diff changeset
616 free(data_query.start_pos);
762009a91895 Uploaded
bitlab
parents:
diff changeset
617 free(ct_A->root);
762009a91895 Uploaded
bitlab
parents:
diff changeset
618 free(ct_B->root);
762009a91895 Uploaded
bitlab
parents:
diff changeset
619 free(ct_C->root);
762009a91895 Uploaded
bitlab
parents:
diff changeset
620 free(ct_D->root);
762009a91895 Uploaded
bitlab
parents:
diff changeset
621 //free(ct);
762009a91895 Uploaded
bitlab
parents:
diff changeset
622 free(threads);
762009a91895 Uploaded
bitlab
parents:
diff changeset
623 free(hta);
762009a91895 Uploaded
bitlab
parents:
diff changeset
624
762009a91895 Uploaded
bitlab
parents:
diff changeset
625
762009a91895 Uploaded
bitlab
parents:
diff changeset
626
762009a91895 Uploaded
bitlab
parents:
diff changeset
627 for(i=0;i<n_threads;i++){
762009a91895 Uploaded
bitlab
parents:
diff changeset
628
762009a91895 Uploaded
bitlab
parents:
diff changeset
629 for(j=0;j<MAX_READ_SIZE;j++){
762009a91895 Uploaded
bitlab
parents:
diff changeset
630 free(table[i][j]);
762009a91895 Uploaded
bitlab
parents:
diff changeset
631 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
632
762009a91895 Uploaded
bitlab
parents:
diff changeset
633 free(table[i]);
762009a91895 Uploaded
bitlab
parents:
diff changeset
634
762009a91895 Uploaded
bitlab
parents:
diff changeset
635 free(mc[i]);
762009a91895 Uploaded
bitlab
parents:
diff changeset
636 free(reconstruct_X[i]);
762009a91895 Uploaded
bitlab
parents:
diff changeset
637 free(reconstruct_Y[i]);
762009a91895 Uploaded
bitlab
parents:
diff changeset
638 free(my_x[i]);
762009a91895 Uploaded
bitlab
parents:
diff changeset
639 free(my_y[i]);
762009a91895 Uploaded
bitlab
parents:
diff changeset
640 free(writing_buffer_alignment[i]);
762009a91895 Uploaded
bitlab
parents:
diff changeset
641
762009a91895 Uploaded
bitlab
parents:
diff changeset
642 free(marker_taggs[i]);
762009a91895 Uploaded
bitlab
parents:
diff changeset
643
762009a91895 Uploaded
bitlab
parents:
diff changeset
644 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
645 free(marker_taggs);
762009a91895 Uploaded
bitlab
parents:
diff changeset
646
762009a91895 Uploaded
bitlab
parents:
diff changeset
647
762009a91895 Uploaded
bitlab
parents:
diff changeset
648 free(table);
762009a91895 Uploaded
bitlab
parents:
diff changeset
649 free(mc);
762009a91895 Uploaded
bitlab
parents:
diff changeset
650 free(reconstruct_X);
762009a91895 Uploaded
bitlab
parents:
diff changeset
651 free(reconstruct_Y);
762009a91895 Uploaded
bitlab
parents:
diff changeset
652 free(my_y);
762009a91895 Uploaded
bitlab
parents:
diff changeset
653 free(my_x);
762009a91895 Uploaded
bitlab
parents:
diff changeset
654 free(writing_buffer_alignment);
762009a91895 Uploaded
bitlab
parents:
diff changeset
655
762009a91895 Uploaded
bitlab
parents:
diff changeset
656 pthread_mutex_destroy(&lock);
762009a91895 Uploaded
bitlab
parents:
diff changeset
657
762009a91895 Uploaded
bitlab
parents:
diff changeset
658
762009a91895 Uploaded
bitlab
parents:
diff changeset
659
762009a91895 Uploaded
bitlab
parents:
diff changeset
660 for(i=0; i<FIXED_LOADING_THREADS; i++){
762009a91895 Uploaded
bitlab
parents:
diff changeset
661 for(j=0;j<=args_DB_load[i].n_pools_used;j++){
762009a91895 Uploaded
bitlab
parents:
diff changeset
662 free(mp[i][j].base);
762009a91895 Uploaded
bitlab
parents:
diff changeset
663 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
664 free(mp[i]);
762009a91895 Uploaded
bitlab
parents:
diff changeset
665 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
666 for(i=0; i<FIXED_LOADING_THREADS; i++){
762009a91895 Uploaded
bitlab
parents:
diff changeset
667 for(j=0;j<=args_DB_load[i].n_pools_used_AVL;j++){
762009a91895 Uploaded
bitlab
parents:
diff changeset
668 free(mp_AVL[i][j].base);
762009a91895 Uploaded
bitlab
parents:
diff changeset
669 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
670 free(mp_AVL[i]);
762009a91895 Uploaded
bitlab
parents:
diff changeset
671 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
672 free(mp);
762009a91895 Uploaded
bitlab
parents:
diff changeset
673 free(mp_AVL);
762009a91895 Uploaded
bitlab
parents:
diff changeset
674 free(seq_vector_database);
762009a91895 Uploaded
bitlab
parents:
diff changeset
675 free(database_positions);
762009a91895 Uploaded
bitlab
parents:
diff changeset
676
762009a91895 Uploaded
bitlab
parents:
diff changeset
677 //Deallocate queue (its allocated as an array)
762009a91895 Uploaded
bitlab
parents:
diff changeset
678 free(first_task);
762009a91895 Uploaded
bitlab
parents:
diff changeset
679
762009a91895 Uploaded
bitlab
parents:
diff changeset
680 //free(mp);
762009a91895 Uploaded
bitlab
parents:
diff changeset
681
762009a91895 Uploaded
bitlab
parents:
diff changeset
682 return 0;
762009a91895 Uploaded
bitlab
parents:
diff changeset
683 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
684
762009a91895 Uploaded
bitlab
parents:
diff changeset
685 void init_args(int argc, char ** av, FILE ** query, FILE ** database, FILE ** out_database, uint64_t * n_threads, long double * minevalue, long double * mincoverage, int * igap, int * egap, long double * minidentity, long double * window, unsigned char * full_comp, uint64_t * custom_kmer, unsigned char * hits_only, uint64_t * n_parts){
762009a91895 Uploaded
bitlab
parents:
diff changeset
686
762009a91895 Uploaded
bitlab
parents:
diff changeset
687 int pNum = 0;
762009a91895 Uploaded
bitlab
parents:
diff changeset
688 while(pNum < argc){
762009a91895 Uploaded
bitlab
parents:
diff changeset
689 if(strcmp(av[pNum], "--verbose") == 0) VERBOSE_ACTIVE = 1;
762009a91895 Uploaded
bitlab
parents:
diff changeset
690 if(strcmp(av[pNum], "--help") == 0){
762009a91895 Uploaded
bitlab
parents:
diff changeset
691 fprintf(stdout, "USAGE:\n");
762009a91895 Uploaded
bitlab
parents:
diff changeset
692 fprintf(stdout, " IMSAME -query [query] -db [database]\n");
762009a91895 Uploaded
bitlab
parents:
diff changeset
693 fprintf(stdout, "OPTIONAL:\n");
762009a91895 Uploaded
bitlab
parents:
diff changeset
694 fprintf(stdout, " -n_threads [Integer: 0<n_threads] (default 4)\n");
762009a91895 Uploaded
bitlab
parents:
diff changeset
695 fprintf(stdout, " -evalue [Double: 0<=pval<1] (default: 1 * 10^-10)\n");
762009a91895 Uploaded
bitlab
parents:
diff changeset
696 fprintf(stdout, " -coverage [Double: 0<coverage<=1 (default: 0.5)\n");
762009a91895 Uploaded
bitlab
parents:
diff changeset
697 fprintf(stdout, " -identity [Double: 0<identity<=1 (default: 0.5)\n");
762009a91895 Uploaded
bitlab
parents:
diff changeset
698 fprintf(stdout, " -igap [Integer: (default: 5)\n");
762009a91895 Uploaded
bitlab
parents:
diff changeset
699 fprintf(stdout, " -egap [Integer: (default: 2)\n");
762009a91895 Uploaded
bitlab
parents:
diff changeset
700 fprintf(stdout, " -window [Double: 0<window<=0.5 (default: 0.15)\n");
762009a91895 Uploaded
bitlab
parents:
diff changeset
701 fprintf(stdout, " -kmer [Integer: k>1 (default 12)]\n");
762009a91895 Uploaded
bitlab
parents:
diff changeset
702 fprintf(stdout, " -n_parts [Integer: n>0 (default 3)]\n");
762009a91895 Uploaded
bitlab
parents:
diff changeset
703 fprintf(stdout, " -out [File path]\n");
762009a91895 Uploaded
bitlab
parents:
diff changeset
704 fprintf(stdout, " --full Does not stop at first match and reports all equalities\n");
762009a91895 Uploaded
bitlab
parents:
diff changeset
705 fprintf(stdout, " --verbose Turns verbose on\n");
762009a91895 Uploaded
bitlab
parents:
diff changeset
706 fprintf(stdout, " --help Shows help for program usage\n");
762009a91895 Uploaded
bitlab
parents:
diff changeset
707 fprintf(stdout, " --hits Compute only the non-overlapping hits\n");
762009a91895 Uploaded
bitlab
parents:
diff changeset
708 exit(1);
762009a91895 Uploaded
bitlab
parents:
diff changeset
709 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
710 if(strcmp(av[pNum], "--full") == 0) *full_comp = TRUE;
762009a91895 Uploaded
bitlab
parents:
diff changeset
711 if(strcmp(av[pNum], "--hits") == 0) *hits_only = TRUE;
762009a91895 Uploaded
bitlab
parents:
diff changeset
712 if(strcmp(av[pNum], "-n_parts") == 0) *n_parts = (uint64_t) atoi(av[pNum+1]);
762009a91895 Uploaded
bitlab
parents:
diff changeset
713 if(strcmp(av[pNum], "-query") == 0){
762009a91895 Uploaded
bitlab
parents:
diff changeset
714 *query = fopen64(av[pNum+1], "rt");
762009a91895 Uploaded
bitlab
parents:
diff changeset
715 if(query==NULL) terror("Could not open query file");
762009a91895 Uploaded
bitlab
parents:
diff changeset
716 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
717 if(strcmp(av[pNum], "-db") == 0){
762009a91895 Uploaded
bitlab
parents:
diff changeset
718 *database = fopen64(av[pNum+1], "rt");
762009a91895 Uploaded
bitlab
parents:
diff changeset
719 if(database==NULL) terror("Could not open database file");
762009a91895 Uploaded
bitlab
parents:
diff changeset
720 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
721 if(strcmp(av[pNum], "-out") == 0){
762009a91895 Uploaded
bitlab
parents:
diff changeset
722 *out_database = fopen64(av[pNum+1], "wt");
762009a91895 Uploaded
bitlab
parents:
diff changeset
723 if(out_database==NULL) terror("Could not open output database file");
762009a91895 Uploaded
bitlab
parents:
diff changeset
724 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
725 if(strcmp(av[pNum], "-evalue") == 0){
762009a91895 Uploaded
bitlab
parents:
diff changeset
726 *minevalue = (long double) atof(av[pNum+1]);
762009a91895 Uploaded
bitlab
parents:
diff changeset
727 if(*minevalue < 0) terror("Min-e-value must be larger than zero");
762009a91895 Uploaded
bitlab
parents:
diff changeset
728 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
729 if(strcmp(av[pNum], "-window") == 0){
762009a91895 Uploaded
bitlab
parents:
diff changeset
730 *window = (long double) atof(av[pNum+1]);
762009a91895 Uploaded
bitlab
parents:
diff changeset
731 if(*window <= 0 || *window > 0.5) terror("Window percentage size must lie between 0<window<=0.5");
762009a91895 Uploaded
bitlab
parents:
diff changeset
732 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
733 if(strcmp(av[pNum], "-coverage") == 0){
762009a91895 Uploaded
bitlab
parents:
diff changeset
734 *mincoverage = (long double) atof(av[pNum+1]);
762009a91895 Uploaded
bitlab
parents:
diff changeset
735 if(*mincoverage <= 0) terror("Min-coverage must be larger than zero");
762009a91895 Uploaded
bitlab
parents:
diff changeset
736 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
737 if(strcmp(av[pNum], "-identity") == 0){
762009a91895 Uploaded
bitlab
parents:
diff changeset
738 *minidentity = (long double) atof(av[pNum+1]);
762009a91895 Uploaded
bitlab
parents:
diff changeset
739 if(*minidentity <= 0) terror("Min-identity must be larger than zero");
762009a91895 Uploaded
bitlab
parents:
diff changeset
740 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
741 if(strcmp(av[pNum], "-igap") == 0){
762009a91895 Uploaded
bitlab
parents:
diff changeset
742 *igap = - (atoi(av[pNum+1]));
762009a91895 Uploaded
bitlab
parents:
diff changeset
743 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
744 if(strcmp(av[pNum], "-egap") == 0){
762009a91895 Uploaded
bitlab
parents:
diff changeset
745 *egap = - (atoi(av[pNum+1]));
762009a91895 Uploaded
bitlab
parents:
diff changeset
746 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
747 if(strcmp(av[pNum], "-n_threads") == 0){
762009a91895 Uploaded
bitlab
parents:
diff changeset
748 *n_threads = (uint64_t) atoi(av[pNum+1]);
762009a91895 Uploaded
bitlab
parents:
diff changeset
749 if(*n_threads < 0) terror("Number of threads must be larger than zero");
762009a91895 Uploaded
bitlab
parents:
diff changeset
750 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
751 if(strcmp(av[pNum], "-kmer") == 0){
762009a91895 Uploaded
bitlab
parents:
diff changeset
752 *custom_kmer = (uint64_t) atoi(av[pNum+1]);
762009a91895 Uploaded
bitlab
parents:
diff changeset
753 if(*custom_kmer < 2) terror("K-mer size must be larger than 1");
762009a91895 Uploaded
bitlab
parents:
diff changeset
754 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
755 pNum++;
762009a91895 Uploaded
bitlab
parents:
diff changeset
756 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
757
762009a91895 Uploaded
bitlab
parents:
diff changeset
758 if(*query==NULL || *database==NULL) terror("A query and database is required");
762009a91895 Uploaded
bitlab
parents:
diff changeset
759 }
762009a91895 Uploaded
bitlab
parents:
diff changeset
760