Skip to content

Commit

Permalink
fix seg.fault when wrong parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
MPIBR-tushevg committed Sep 13, 2018
1 parent bd76d8f commit 04bed56
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 39 deletions.
39 changes: 20 additions & 19 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,29 @@
const char VERSION[] = "v0.01";
const char PROGRAM_NAME[] = "PASSFinder";

void aux_init(aux_config_t *aux)
void aux_parse(aux_config_t *aux, int argc, const char *argv[])
{
/* initialize default auxiliary values */
aux->file_in = NULL;
aux->file_mask = NULL;
aux->polysize = AUX_DEFAULT_POLYSIZE;
aux->masksize = AUX_DEFAULT_MASKSIZE;
aux->mapq = AUX_DEFAULT_MAPQ;

return;
}

int aux_parse(aux_config_t *aux, int argc, const char *argv[])
{
if ((argc != 2) && (argc < 4))
{
fprintf(stderr, "Error: provide input, output and mask\n");
help();
}


/* parse input pairs */
for(int i = 1; i < argc; i++)
{

// current paramter length
uint64_t parameterLength = strlen(argv[i]);

// check each parameter and its value
if((PARAMETER_CHECK("-h", 2, parameterLength)) ||
(PARAMETER_CHECK("--help", 6, parameterLength)))
Expand Down Expand Up @@ -74,41 +77,39 @@ int aux_parse(aux_config_t *aux, int argc, const char *argv[])
else
{
fprintf(stderr, "Error:: Unknown parameter %s\n", argv[i]);
return EXIT_FAILURE;
help();
}


}

return EXIT_SUCCESS;
return;
}



void version(void)
{
fprintf(stderr, "PASSFinder %s\n", VERSION);
return;
exit(EXIT_SUCCESS);
}

void help(void)
{

fprintf(stderr, "\nTool: PASSFinder\n");
fprintf(stderr, "Version: %s\n", VERSION);
fprintf(stderr, "Summary:\n");
fprintf(stderr, "\tCluster PolyA supported sites from 3'End sequencing.\n");
fprintf(stderr, "\nUsage:\t%s [OPTIONS] -i/--input <bam/stdin> -m/--maskpoly <bed> -o/--output <bed/stdout>\n", PROGRAM_NAME);
fprintf(stderr, "Options:\n");
fprintf(stderr, "\t-i/--input BAM/stdin file\n");
fprintf(stderr, "\t-o/--output BED/stdout file\n");
fprintf(stderr, "\t-m/--maskpoly BED/stdin file with genomic poly regions\n");
fprintf(stderr, "\t-i/--input BAM/stdin file [required]\n");
fprintf(stderr, "\t-o/--output BED/stdout file [required]\n");
fprintf(stderr, "\t-m/--maskpoly BED/stdin file with genomic poly regions [required]\n");
fprintf(stderr, "\t-w/--window\tsliding window size\n");
fprintf(stderr, "\t-d/--depth\tminimum number of polyA reads to define PASS\n");
fprintf(stderr, "\t-p/--polysize\tminimum number of As for tail and Ts for head to define poly stretch\n");
fprintf(stderr, "\t-h/--help\tprint help message\n");
fprintf(stderr, "\t-v/--version\tprint current version\n");
return;
exit(EXIT_SUCCESS);
}

int chomp(char *line_buf)
Expand All @@ -117,6 +118,6 @@ int chomp(char *line_buf)
line_length = strlen(line_buf) - 1;
if(line_buf[line_length] == '\n')
line_buf[line_length] = '\0';

return 0;
}
}
3 changes: 1 addition & 2 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ typedef struct _aux_config_t
} aux_config_t;

// function declarations
void aux_init(aux_config_t *);
int aux_parse(aux_config_t *, int, const char **);
void aux_parse(aux_config_t *, int, const char **);
void help(void);
void version(void);
int chomp(char *);
Expand Down
31 changes: 13 additions & 18 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,30 @@ int main(int argc, const char * argv[])
{
aux_config_t aux;
hts_config_t hts;

clock_t begin = clock();



// parse auxiliary configuration
aux_init(&aux);
if (aux_parse(&aux, argc, argv))
{
help();
return EXIT_FAILURE;
}

aux_parse(&aux, argc, argv);

clock_t begin = clock();

// initialize with hts
hts_init(&hts, &aux);

// parse with hts
hts_parse(&hts, &aux);

// dump hash
hts_printout(&hts);

// free
hts_destroy(&hts);



clock_t end = clock();

double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;

fprintf(stderr, "Time: %.4f sec\n", time_spent);

return 0;
}

0 comments on commit 04bed56

Please sign in to comment.