Description: Fix FTBFS with GCC 14. https://gcc.gnu.org/gcc-14/porting_to.html#implicit-function-declaration Author: Bas Couwenberg Bug-Debian: https://bugs.debian.org/1066716 --- a/Ext/lib/pwm_searchPFF.c +++ b/Ext/lib/pwm_searchPFF.c @@ -33,81 +33,6 @@ *------------------------------------------------------------------*/ #include "pwm_search.h" -int do_search(char* matrixfile, - char* seqfile, - float threshold, - char* tfname, - char* tfclass, - char* outfile) - /*was: main - int argc; - char **argv;*/ -{ - double pwm[2*MAXCOUNTS]; /* for pwm matrix */ - /* do own indexing; 5*pos + nt */ - int exitval = -1; /* exit value from main */ - struct arguments args; /* command line args */ - FILE *fp; /* for sequence input file */ - FILE *outfp; - NUM_ERRS = 0; - if (__DEBUG__) fprintf(stderr, "%s %s %f %s %s %s\n", matrixfile, seqfile, threshold, tfname, tfclass, outfile); - if ( __DEBUG__ ) - announce("+++\nEntering main.\n+++\n"); - - /* Parse command line arguments */ - /*if ( get_cmd_args(argc,argv,&args) ) - { - err_log( - "Usage: pwm_searchPFF pwm_file seq_file threshold [-a][-b]|[-m mask_file] [-n TFname] [-c TFclass]\n" - ); - }*/ - - strcpy(args.counts_file, matrixfile); - strcpy(args.seq_file, seqfile); - args.threshold = threshold; - strcpy(args.name, tfname); - strcpy(args.class, tfclass); - args.print_all = 0; - args.best_only= 0; - /* Read in the pwm; calculate max/min score */ - //else - if ( get_matrix(&args,pwm) ) - { - err_log("MAIN: get_matrix failed."); - } - - /* Open the sequence file */ - else if ( (fp=fopen(args.seq_file,"r")) == NULL ) - { - err_log("MAIN: open_seq_file failed."); - } - else if ( (outfp=fopen(outfile,"w")) == NULL ) - { - err_log("MAIN: open_outfile failed."); - } - - /* Loop on sequences */ - else if ( loop_on_seqs(&args,pwm,fp,outfp) ) - { - err_log("MAIN: loop_on_seqs failed."); - } - - /* Normal completion */ - else - { - exitval = 0; - } - - /* Clean up and close out */ - err_show(); - fclose(fp); - fclose(outfp); - if ( __DEBUG__ ) - announce("+++\nLeaving main.\n+++\n"); - - return(exitval); -} - /*-------------------------------------------------------------------- * Announce * @@ -126,185 +51,6 @@ char *msg; return(retval); } -/*-------------------------------------------------------------------- - * BEST_SAVE - Save the best score so far - * - * Called by do_seq - * - * Returns: 0 - *------------------------------------------------------------------*/ -int best_save(struct arguments* pargs, long base, int strand, double score) - //struct arguments *pargs; /* args from command line */ - //long base; /* base where score occurs */ - //int strand; /* strand where score occurs */ - //double score; /* score of hit to save */ -{ - if ( pargs->best_base < 0 || score > pargs->best_score ) - { - pargs->best_base = base; - pargs->best_score = score; - pargs->best_strand = strand; - } - - return(0); -} - -/*-------------------------------------------------------------------- - * BEST_PULL - Copy back the best score saved - * - * Called by do_seq - * - * Returns: 0 - *------------------------------------------------------------------*/ -best_pull(pargs,pbase,pstrand,pscore) -struct arguments *pargs; /* args from command line */ -long *pbase; /* base where score occurs */ -int *pstrand; /* strand where score occurs */ -double *pscore; /* score of hit to pull back */ -{ - *pbase = pargs->best_base; - if ( pargs->best_base >= 0 ) - { - *pscore = pargs->best_score; - *pstrand = pargs->best_strand; - } - return(0); -} - -/*-------------------------------------------------------------------- - * DO_SEQ - Search through the given sequence with the given matrix - * - * Called by loop_on_seqs - * - * Returns: 0 for success, -1 for failure. - *------------------------------------------------------------------*/ -int -do_seq(pargs,pwm,seqid,seq,outfp) -struct arguments *pargs; /* args from command line */ -double *pwm; /* pwm from get_matrix */ -char *seqid; /* id of sequence to work on */ -char *seq; /* the sequence to work on */ -FILE *outfp; -{ - double backward_score; - double forward_score; - double score; - long base; - int done = 0; - int nt; - int pos; - int retval = 0; - int strand; - long l; - long nhit=0L; - struct HIT hits[MAXHITS]; - - if ( __DEBUG__ ) - announce("+++\nEntering do_seq.\n+++\n"); - - /* first make sure sequence is long enough */ - for ( base=0; base < pargs->width; ++base ) - { - if ( seq[base] == '\0' ) - done = 1; - } - - /* loop on windows */ - pargs->best_base = -1; - for ( base=0; !retval && !done && seq[base+pargs->width-1]; ++base ) - { - forward_score = 0.0; - backward_score = 0.0; - for ( pos=0; poswidth; ++pos ) - { - nt = TRANS[seq[base+pos]]; - forward_score += pwm[5*pos + nt]; - nt = ( nt==4 ) ? 4 : 3-nt; - backward_score += pwm[5*(pargs->width - pos -1) + nt]; - } - if ( forward_score > pargs->threshold ) - { - if ( pargs->print_all ) - { - if ( save_hit(base,0,forward_score,hits,&nhit) ) - { - err_log("DO_SEQ: save_hit failed"); - retval = -1; - } - } - else if ( pargs->best_only ) - { - best_save(pargs,base,0,forward_score); - } - else if ( output(pargs,seqid,base,seq,0,forward_score,outfp) ) - { - err_log("DO_SEQ: output failed"); - retval = -1; - } - } - if ( backward_score > pargs->threshold ) - { - if ( pargs->print_all ) - { - if ( save_hit(base,1,backward_score,hits,&nhit) ) - { - err_log("DO_SEQ: save_hit failed"); - retval = -1; - } - } - else if ( pargs->best_only ) - { - best_save(pargs,base,1,backward_score); - } - else if ( output(pargs,seqid,base,seq,1,backward_score, outfp) ) - { - err_log("DO_SEQ: output failed"); - retval = -1; - } - } - - } - - if ( pargs->print_all ) - { - for ( l=0; l=0 ) - { - if ( output(pargs,seqid,base,seq,strand,score,outfp) ) - { - err_log("DO_SEQ: output failed"); - retval = -1; - } - } - } - - if ( __DEBUG__ ) - announce("+++\nLeaving do_seq.\n+++\n"); - - return(retval); - -} - /*********************************************************************** * ERR_LOG and ERR_SHOW * @@ -341,85 +87,37 @@ err_show() return; } + /*-------------------------------------------------------------------- - * GET_CMD_ARGS - Parse execute line, fill arg structure. + * SAVE_HIT - save location, strand and score of a hit in an array of such * - * Called by main. + * Called by do_seq. * * Returns: 0 for success, -1 for failure. *------------------------------------------------------------------*/ -int get_cmd_args(argc,argv,pargs) -int argc; /* argc as passed to main */ -char **argv; /* argv as passed to main */ -struct arguments *pargs; /* args from command line */ +int +save_hit(base,strand,score,hits,pnhit) +long base; +int strand; +double score; +struct HIT *hits; +long *pnhit; { int retval = 0; - int arg_count = 4; - - if ( __DEBUG__ ) - announce("+++\nEntering get_cmd_args\n+++\n"); - /* See if we got at least three arguments */ - if ( argc < 4 ) - { retval = -1; - err_log("GET_CMD_ARGS: Too few arguments."); + if ( *pnhit == MAXHITS ) + { + err_log("SAVE_HIT: MAXHITS limit reached."); + retval = -1; } - /* Get the arguments */ - else - { strcpy(pargs->counts_file,argv[1]); - strcpy(pargs->seq_file,argv[2]); - pargs->threshold = atof(argv[3]); - pargs->best_only = 0; - pargs->print_all = 0; - pargs->mask_file[0] = '\0'; - while (arg_count < argc) - { - if ( argv[arg_count][0]=='-' && argv[arg_count][1]=='b' ) - { - pargs->best_only = 1; - arg_count++; - } - else if ( argv[arg_count][0]=='-' && argv[arg_count][1]=='a' ) - { - pargs->print_all = 1; - arg_count++; - } - else if ( arg_countmask_file,argv[arg_count+1]); - arg_count = arg_count+2; - } - else if ( arg_countname,argv[arg_count+1]); - arg_count = arg_count+2; - } - else if ( arg_countclass,argv[arg_count+1]); - arg_count = arg_count+2; - } - else - { - arg_count++; - } - } - } - if ( __DEBUG__ ) - announce("+++\nLeaving get_cmd_args\n+++\n"); - return( retval ); + hits[*pnhit].base = base; + hits[*pnhit].strand = strand; + hits[*pnhit].score = score; + *pnhit = *pnhit + 1; + + return(retval); } - /*-------------------------------------------------------------------- * GET_MATRIX - Read in pwm. * @@ -515,6 +213,85 @@ get_matrix(struct arguments* pargs, doub } /*-------------------------------------------------------------------- + * GET_CMD_ARGS - Parse execute line, fill arg structure. + * + * Called by main. + * + * Returns: 0 for success, -1 for failure. + *------------------------------------------------------------------*/ +int get_cmd_args(argc,argv,pargs) +int argc; /* argc as passed to main */ +char **argv; /* argv as passed to main */ +struct arguments *pargs; /* args from command line */ +{ + int retval = 0; + int arg_count = 4; + + if ( __DEBUG__ ) + announce("+++\nEntering get_cmd_args\n+++\n"); + + /* See if we got at least three arguments */ + if ( argc < 4 ) + { retval = -1; + err_log("GET_CMD_ARGS: Too few arguments."); + } + + /* Get the arguments */ + else + { strcpy(pargs->counts_file,argv[1]); + strcpy(pargs->seq_file,argv[2]); + pargs->threshold = atof(argv[3]); + pargs->best_only = 0; + pargs->print_all = 0; + pargs->mask_file[0] = '\0'; + while (arg_count < argc) + { + if ( argv[arg_count][0]=='-' && argv[arg_count][1]=='b' ) + { + pargs->best_only = 1; + arg_count++; + } + else if ( argv[arg_count][0]=='-' && argv[arg_count][1]=='a' ) + { + pargs->print_all = 1; + arg_count++; + } + else if ( arg_countmask_file,argv[arg_count+1]); + arg_count = arg_count+2; + } + else if ( arg_countname,argv[arg_count+1]); + arg_count = arg_count+2; + } + else if ( arg_countclass,argv[arg_count+1]); + arg_count = arg_count+2; + } + else + { + arg_count++; + } + } + } + if ( __DEBUG__ ) + announce("+++\nLeaving get_cmd_args\n+++\n"); + return( retval ); +} + +/*-------------------------------------------------------------------- * GET_SEQUENCE * * Get the next sequence from the input file (fasta format) @@ -628,50 +405,48 @@ char *sequence; /* text of sequence } /*-------------------------------------------------------------------- - * LOOP_ON_SEQS - Loop through the sequences of the input file, - * doing the search and output. + * BEST_PULL - Copy back the best score saved * - * Called by main. + * Called by do_seq * - * Returns: 0 for success, -1 for failure. + * Returns: 0 *------------------------------------------------------------------*/ -int -loop_on_seqs(pargs,pwm,fp, outfp) +best_pull(pargs,pbase,pstrand,pscore) struct arguments *pargs; /* args from command line */ -double *pwm; /* pwm, from get_matrix */ -FILE *fp; /* sequence file pointer */ -FILE *outfp; /* output file pointer */ +long *pbase; /* base where score occurs */ +int *pstrand; /* strand where score occurs */ +double *pscore; /* score of hit to pull back */ { - char seq[SEQLEN+1]; - char seqid[SEQNAMELEN+1]; - int done = 0; - int retval=0; - if ( __DEBUG__ ) - announce("+++\nEntering loop_on_seqs\n+++\n"); - - /* Main loop */ - while ( !retval && !done ) + *pbase = pargs->best_base; + if ( pargs->best_base >= 0 ) { - done = get_sequence(fp,seqid,seq); - if ( done == -1 ) - { - err_log("LOOP_ON_SEQS: get_sequence failed."); - retval = -1; - } - else if ( done == 0 ) - { - if ( do_seq(pargs,pwm,seqid,seq,outfp) ) - { - err_log("LOOP_ON_SEQS: do_seq failed."); - retval = -1; - } - } + *pscore = pargs->best_score; + *pstrand = pargs->best_strand; } + return(0); +} - if ( __DEBUG__ ) - announce("+++\nLeaving loop_on_seqs\n+++\n"); +/*-------------------------------------------------------------------- + * BEST_SAVE - Save the best score so far + * + * Called by do_seq + * + * Returns: 0 + *------------------------------------------------------------------*/ +int best_save(struct arguments* pargs, long base, int strand, double score) + //struct arguments *pargs; /* args from command line */ + //long base; /* base where score occurs */ + //int strand; /* strand where score occurs */ + //double score; /* score of hit to save */ +{ + if ( pargs->best_base < 0 || score > pargs->best_score ) + { + pargs->best_base = base; + pargs->best_score = score; + pargs->best_strand = strand; + } - return (retval); + return(0); } /*-------------------------------------------------------------------- @@ -754,32 +529,257 @@ FILE *outfp; } /*-------------------------------------------------------------------- - * SAVE_HIT - save location, strand and score of a hit in an array of such + * DO_SEQ - Search through the given sequence with the given matrix * - * Called by do_seq. + * Called by loop_on_seqs * * Returns: 0 for success, -1 for failure. *------------------------------------------------------------------*/ int -save_hit(base,strand,score,hits,pnhit) -long base; -int strand; -double score; -struct HIT *hits; -long *pnhit; +do_seq(pargs,pwm,seqid,seq,outfp) +struct arguments *pargs; /* args from command line */ +double *pwm; /* pwm from get_matrix */ +char *seqid; /* id of sequence to work on */ +char *seq; /* the sequence to work on */ +FILE *outfp; { + double backward_score; + double forward_score; + double score; + long base; + int done = 0; + int nt; + int pos; int retval = 0; + int strand; + long l; + long nhit=0L; + struct HIT hits[MAXHITS]; - if ( *pnhit == MAXHITS ) + if ( __DEBUG__ ) + announce("+++\nEntering do_seq.\n+++\n"); + + /* first make sure sequence is long enough */ + for ( base=0; base < pargs->width; ++base ) { - err_log("SAVE_HIT: MAXHITS limit reached."); - retval = -1; + if ( seq[base] == '\0' ) + done = 1; } - hits[*pnhit].base = base; - hits[*pnhit].strand = strand; - hits[*pnhit].score = score; - *pnhit = *pnhit + 1; + /* loop on windows */ + pargs->best_base = -1; + for ( base=0; !retval && !done && seq[base+pargs->width-1]; ++base ) + { + forward_score = 0.0; + backward_score = 0.0; + for ( pos=0; poswidth; ++pos ) + { + nt = TRANS[seq[base+pos]]; + forward_score += pwm[5*pos + nt]; + nt = ( nt==4 ) ? 4 : 3-nt; + backward_score += pwm[5*(pargs->width - pos -1) + nt]; + } + if ( forward_score > pargs->threshold ) + { + if ( pargs->print_all ) + { + if ( save_hit(base,0,forward_score,hits,&nhit) ) + { + err_log("DO_SEQ: save_hit failed"); + retval = -1; + } + } + else if ( pargs->best_only ) + { + best_save(pargs,base,0,forward_score); + } + else if ( output(pargs,seqid,base,seq,0,forward_score,outfp) ) + { + err_log("DO_SEQ: output failed"); + retval = -1; + } + } + if ( backward_score > pargs->threshold ) + { + if ( pargs->print_all ) + { + if ( save_hit(base,1,backward_score,hits,&nhit) ) + { + err_log("DO_SEQ: save_hit failed"); + retval = -1; + } + } + else if ( pargs->best_only ) + { + best_save(pargs,base,1,backward_score); + } + else if ( output(pargs,seqid,base,seq,1,backward_score, outfp) ) + { + err_log("DO_SEQ: output failed"); + retval = -1; + } + } + + } + + if ( pargs->print_all ) + { + for ( l=0; l=0 ) + { + if ( output(pargs,seqid,base,seq,strand,score,outfp) ) + { + err_log("DO_SEQ: output failed"); + retval = -1; + } + } + } + + if ( __DEBUG__ ) + announce("+++\nLeaving do_seq.\n+++\n"); return(retval); + +} + +/*-------------------------------------------------------------------- + * LOOP_ON_SEQS - Loop through the sequences of the input file, + * doing the search and output. + * + * Called by main. + * + * Returns: 0 for success, -1 for failure. + *------------------------------------------------------------------*/ +int +loop_on_seqs(pargs,pwm,fp, outfp) +struct arguments *pargs; /* args from command line */ +double *pwm; /* pwm, from get_matrix */ +FILE *fp; /* sequence file pointer */ +FILE *outfp; /* output file pointer */ +{ + char seq[SEQLEN+1]; + char seqid[SEQNAMELEN+1]; + int done = 0; + int retval=0; + if ( __DEBUG__ ) + announce("+++\nEntering loop_on_seqs\n+++\n"); + + /* Main loop */ + while ( !retval && !done ) + { + done = get_sequence(fp,seqid,seq); + if ( done == -1 ) + { + err_log("LOOP_ON_SEQS: get_sequence failed."); + retval = -1; + } + else if ( done == 0 ) + { + if ( do_seq(pargs,pwm,seqid,seq,outfp) ) + { + err_log("LOOP_ON_SEQS: do_seq failed."); + retval = -1; + } + } + } + + if ( __DEBUG__ ) + announce("+++\nLeaving loop_on_seqs\n+++\n"); + + return (retval); +} + +int do_search(char* matrixfile, + char* seqfile, + float threshold, + char* tfname, + char* tfclass, + char* outfile) + /*was: main + int argc; + char **argv;*/ +{ + double pwm[2*MAXCOUNTS]; /* for pwm matrix */ + /* do own indexing; 5*pos + nt */ + int exitval = -1; /* exit value from main */ + struct arguments args; /* command line args */ + FILE *fp; /* for sequence input file */ + FILE *outfp; + NUM_ERRS = 0; + if (__DEBUG__) fprintf(stderr, "%s %s %f %s %s %s\n", matrixfile, seqfile, threshold, tfname, tfclass, outfile); + if ( __DEBUG__ ) + announce("+++\nEntering main.\n+++\n"); + + /* Parse command line arguments */ + /*if ( get_cmd_args(argc,argv,&args) ) + { + err_log( + "Usage: pwm_searchPFF pwm_file seq_file threshold [-a][-b]|[-m mask_file] [-n TFname] [-c TFclass]\n" + ); + }*/ + + strcpy(args.counts_file, matrixfile); + strcpy(args.seq_file, seqfile); + args.threshold = threshold; + strcpy(args.name, tfname); + strcpy(args.class, tfclass); + args.print_all = 0; + args.best_only= 0; + /* Read in the pwm; calculate max/min score */ + //else + if ( get_matrix(&args,pwm) ) + { + err_log("MAIN: get_matrix failed."); + } + + /* Open the sequence file */ + else if ( (fp=fopen(args.seq_file,"r")) == NULL ) + { + err_log("MAIN: open_seq_file failed."); + } + else if ( (outfp=fopen(outfile,"w")) == NULL ) + { + err_log("MAIN: open_outfile failed."); + } + + /* Loop on sequences */ + else if ( loop_on_seqs(&args,pwm,fp,outfp) ) + { + err_log("MAIN: loop_on_seqs failed."); + } + + /* Normal completion */ + else + { + exitval = 0; + } + + /* Clean up and close out */ + err_show(); + fclose(fp); + fclose(outfp); + if ( __DEBUG__ ) + announce("+++\nLeaving main.\n+++\n"); + + return(exitval); }