1
1
/* main.c
2
2
* Created by Mengyao Zhao on 06/23/11.
3
3
* Version 1.2.2
4
- * Last revision by Mengyao Zhao on 2022-Apr-15 .
4
+ * Last revision by Mengyao Zhao on 2022-May-21 .
5
5
*/
6
6
7
7
#include <stdlib.h>
@@ -197,11 +197,9 @@ int main (int argc, char * const argv[]) {
197
197
gzFile read_fp , ref_fp ;
198
198
kseq_t * read_seq , * ref_seq ;
199
199
int32_t l , m , k , match = 2 , mismatch = 2 , gap_open = 3 , gap_extension = 1 , path = 0 , reverse = 0 , n = 5 , sam = 0 , protein = 0 , header = 0 , s1 = 67108864 , s2 = 128 , filter = 0 ;
200
- char mat_name [16 ];
201
- mat_name [0 ] = '\0' ;
202
200
int8_t * mata , * ref_num , * num , * num_rc = 0 ;
203
201
const int8_t * mat ;
204
- char * read_rc = 0 ;
202
+ char * read_rc = 0 , * mat_name = 0 ;
205
203
206
204
static const int8_t mat50 [] = {
207
205
// A R N D C Q E G H I L K M F P S T W Y V B Z X *
@@ -257,22 +255,6 @@ int main (int argc, char * const argv[]) {
257
255
258
256
int8_t * table = nt_table ;
259
257
260
- // Parse command line.
261
- while ((l = getopt (argc , argv , "m:x:o:e:a:f:pcrsh" )) >= 0 ) {
262
- switch (l ) {
263
- case 'm' : match = atoi (optarg ); break ;
264
- case 'x' : mismatch = atoi (optarg ); break ;
265
- case 'o' : gap_open = atoi (optarg ); break ;
266
- case 'e' : gap_extension = atoi (optarg ); break ;
267
- case 'a' : strcpy (mat_name , optarg ); break ;
268
- case 'f' : filter = atoi (optarg ); break ;
269
- case 'p' : protein = 1 ; break ;
270
- case 'c' : path = 1 ; break ;
271
- case 'r' : reverse = 1 ; break ;
272
- case 's' : sam = 1 ; break ;
273
- case 'h' : header = 1 ; break ;
274
- }
275
- }
276
258
if (optind + 2 > argc ) {
277
259
fprintf (stderr , "\n" );
278
260
fprintf (stderr , "Usage: ssw_test [options] ... <target.fasta> <query.fasta>(or <query.fastq>)\n" );
@@ -291,6 +273,28 @@ int main (int argc, char * const argv[]) {
291
273
return 1 ;
292
274
}
293
275
276
+ // Parse command line.
277
+ while ((l = getopt (argc , argv , "m:x:o:e:a:f:pcrsh" )) >= 0 ) {
278
+ switch (l ) {
279
+ case 'm' : match = atoi (optarg ); break ;
280
+ case 'x' : mismatch = atoi (optarg ); break ;
281
+ case 'o' : gap_open = atoi (optarg ); break ;
282
+ case 'e' : gap_extension = atoi (optarg ); break ;
283
+
284
+ case 'a' :
285
+ mat_name = (char * )malloc (strlen (optarg ) + 1 );
286
+ strcpy (mat_name , optarg );
287
+ break ;
288
+
289
+ case 'f' : filter = atoi (optarg ); break ;
290
+ case 'p' : protein = 1 ; break ;
291
+ case 'c' : path = 1 ; break ;
292
+ case 'r' : reverse = 1 ; break ;
293
+ case 's' : sam = 1 ; break ;
294
+ case 'h' : header = 1 ; break ;
295
+ }
296
+ }
297
+
294
298
// initialize scoring matrix for genome sequences
295
299
mata = (int8_t * )calloc (25 , sizeof (int8_t ));
296
300
for (l = k = 0 ; LIKELY (l < 4 ); ++ l ) {
@@ -300,14 +304,21 @@ int main (int argc, char * const argv[]) {
300
304
for (m = 0 ; LIKELY (m < 5 ); ++ m ) mata [k ++ ] = 0 ;
301
305
mat = mata ;
302
306
303
- if (protein == 1 && (! strcmp ( mat_name , "\0" )) ) {
307
+ if (protein == 1 && mat_name == 0 ) {
304
308
n = 24 ;
305
309
table = aa_table ;
306
310
mat = mat50 ;
307
- } else if (strcmp ( mat_name , "\0" ) ) {
311
+ } else if (mat_name != 0 ) {
308
312
309
313
// Parse score matrix.
310
314
FILE * f_mat = fopen (mat_name , "r" );
315
+ free (mat_name );
316
+ if (f_mat == NULL ) {
317
+ fprintf (stderr , "Failed to open the weight matrix file.\n" );
318
+ free (mata );
319
+ return 1 ;
320
+ }
321
+
311
322
char line [128 ];
312
323
mata = (int8_t * )realloc (mata , 1024 * sizeof (int8_t ));
313
324
k = 0 ;
0 commit comments