/* Convert synthetic candidates from fraction format to ".can" format */ /* Last edited on 2023-02-12 07:49:36 by stolfi */ #include #include #include #include #include #include #include #include TYPE Options = struct ??? { char *input; /* Input candidate file name (without ".txt") */ char *chainDir; /* Directory where chain files can be found. */ char *chainPrefix; /* Prefix for chain file names */ unsigned band; /* Nominal band width (lambda) for file names */ double step; /* Nominal sampling step size. */ char *output; /* Output candidate file name (without ".can") */ } ???; FractionInterval = struct ??? { /* Identifies a segment of a filtered chain */ unsigned cvx; /* Chain identifier */ double ini; /* Segment beginning (as fraction of length */ double fin; /* Segment end (as fraction of length */ } ???; FractionList == ARRAY[0..1]_vec_t *OF FractionInterval; ChainList == ARRAY OF pz_r3_chain_read_data; int main(int argc, char **argv ) { { /* with */ ??? o = pz_get_options(int argc, char **argv); ??? lambda = FLOAT(o.band,double); ??? rd = open_read(o.input & ".txt", TRUE); ??? perc = ReadFractionFile(rd)^; ??? chains = GetChains(perc)^; chAllData = pz_r3_chain_read_all( o.chainPrefix, o.band, ".flc", sel := chains, dir := o.chainDir; header_only := TRUE, recenter := pz_ctr_NONE ); ??? cand = ConvertCandidates(perc, chAllData.chData^, o.step)^; ??? wr = open_write(o.output & ".can", TRUE); /* do */ pz_candidate_write(wr, Comments(o), cand, lambda);; }; } /* Main */ Options pz_get_options(int argc, char **argv ) VAR o: Options; { argparser_t *pp = argparser_new(stderr, argc, argv); argparser_set_help(pp, PROG_NAME " version " PROG_VERS ", usage:\n" PROG_HELP); argparser_set_info(pp, PROG_INFO); argparser_process_help_info_options(pp); { /* with */ /* do */ TRY argparser_get_keyword(pp, "-input"); o.input = argparser_get_next(pp); argparser_get_keyword(pp, "-chainPrefix"); o.chainPrefix = argparser_get_next(pp); if (( argparser_keyword_present(pp, "-chainDir") )){ o.chainDir = argparser_get_next(pp) }else{ o.chainDir = "."; }; argparser_get_keyword(pp, "-band"); o.band = argparser_get_next_int(pp); argparser_get_keyword(pp, "-step"); o.step = argparser_get_next_double(pp, 0.0e0); argparser_get_keyword(pp, "-output"); o.output = argparser_get_next(pp); argparser_finish(pp); EXCEPT | ParseParams.Error ==> fprintf(stderr, "Usage: pz_convert_synthetic_cands \\\n"); fprintf(stderr, " -input NAME \\\n"); fprintf(stderr, " [ -chainDir NAME ] -chainPrefix STRING \\\n"); fprintf(stderr, " -band NUMBER -step NUMBER \\\n"); fprintf(stderr, " -output NAME \\\n"); Process.Exit(1);; };; }; return o } /* GetOptions */ bool_vec_t *GetChains( FractionList *perc ) CONST MaxChains == 10000; VAR mxc: unsigned := 0; /* Max chain number in "cand" */ { { /* with */ ??? seen = bool_vec_new(MaxChains)^; /* do */ for (k = 0; k < (seen.ne ) ; k++){ seen[k] = FALSE ;}; for (i = 0; i < (perc.ne ) ; i++){ for (j = 0; j <= 1 ; j++){ { /* with */ ??? k = perc[i][j].cvx; /* do */ if (( NOT seen[k] )){ seen[k] = TRUE; mxc = max(mxc, k); };; }; }; }; mxc = mxc+1; { /* with */ ??? rb = bool_vec_new(mxc); /* do */ rb^ = SUBARRAY(seen, 0, mxc); return rb; }; } } /* GetChains */ pz_candidate.List *ConvertCandidates( FractionList *perc, ChainList *ch, double step ) VAR segL, canL: double; { { /* with */ ??? n = (perc.ne); ??? rc = NEW(REF pz_candidate.List, n); ??? cand = rc^; /* do */ for (i = 0; i <= n-1 ; i++){ { /* with */ ??? ci = cand[i]; /* do */ canL = 0.0e0; for (j = 0; j <= 1 ; j++){ { /* with */ ??? p = perc[i,j]; ??? m = ch[p.cvx].samples; /* do */ affirm(m > 0 ); { /* with */ ??? ini = FLOOR(((double)m) * p.ini); ??? fin = CEILING(((double)m) * p.fin); ??? ns = (fin - ini) MOD m + 1; /* do */ ci.seg[j] = pz_segment_t{ cvx = p.cvx, tot = m, ini = ini, ns = ns, rev = (j == 1) }; segL = step * ((double)ns - 1); canL = canL + segL;; }; }; }; ci.length = canL/2.0e0; ci.mismatch = 0.0e0; ci.matchedLength = ci.length; ci.pm = NULL; }; }; return rc; } } /* ConvertCandidates */ char *Comments( Options *o ) { { /* with */ ??? wr = NEW(TextFILE *).init(); /* do */ fprintf(wr, "pz_convert_synthetic_cands: \n"); fprintf(wr, " input: %s\n", o.input ); fprintf(wr, " chainPrefix: %s\n", o.chainPrefix ); fprintf(wr, " band: %s\n", Fmt.Int(o.band) ); fprintf(wr, " output: %s\n", o.output ); return(TextFILE *oText(wr)); } /* ){ */; } /* Comments */ FractionList *ReadFractionFile( FILE *rd ) VAR c: REF FractionList; { { /* with */ ??? n = nget_int32(rd, "n"); /* do */ fget_eol(rd); c = NEW(REF FractionList, n); for (i = 0; i <= n-1 ; i++){ fget_skip_spaces(rd); { /* with */ ??? ci = c[i]; /* do */ for (j = 0; j <= 1 ; j++){ { /* with */ ??? seg = ci[j]; /* do */ seg.cvx = fget_int32(rd); fget_skip_spaces(rd); seg.ini = fget_double(rd); fget_skip_spaces(rd); seg.fin = fget_double(rd); fget_skip_spaces(rd);; };; }; fget_eol(rd); }; }; return c;; }; } /* ReadFractionFile */ { /* Copyright © 2001 Universidade Estadual de Campinas (UNICAMP). Authors: Helena C. G. Leitão and Jorge Stolfi. This file can be freely distributed, used, and modified, provided that this copyright and authorship notice is preserved, and that any modified versions are clearly marked as such. This software has NO WARRANTY of correctness or applicability for any purpose. Neither the authors nor their employers chall be held responsible for any losses or damages that may result from its use. */