int convert(FILE *infp, FILE *outfp, char *infname, char *outfname, struct opts *opts) { Read *r; if (NULL == (r = fread_reading(infp, infname, opts->in_format))) { fprintf(stderr, "failed to read file %s\n", infname); return 1; } if (opts->sub_background) { /* trace_freq(r->traceA, r->NPoints); trace_freq(r->traceC, r->NPoints); trace_freq(r->traceG, r->NPoints); trace_freq(r->traceT, r->NPoints); */ subtract_background(r); /* separate_dyes(r, matrix); trace_freq(r->traceA, r->NPoints); trace_freq(r->traceC, r->NPoints); trace_freq(r->traceG, r->NPoints); trace_freq(r->traceT, r->NPoints); */ reset_max_called_height(r); } if (opts->normalise) { rescale_heights(r); } if (opts->scale) { rescale_trace(r, opts->scale); } if (opts->name) r->ident = strdup(opts->name); else if (0 == strcmp(outfname, "(stdout)")) r->ident = strdup(infname); else r->ident = strdup(outfname); if (opts->compress_mode != -1) set_compression_method(opts->compress_mode); if (0 != (fwrite_reading(outfp, r, opts->out_format))) { fprintf(stderr, "failed to write file %s\n", outfname); read_deallocate(r); return 1; } read_deallocate(r); return 0; }
Read *fread_pln(FILE *fp) { return fread_reading(fp, NULL, TT_PLN); }
Read *fread_ctf(FILE *fp) { return fread_reading(fp, NULL, TT_CTF); }
Read *fread_alf(FILE *fp) { return fread_reading(fp, NULL, TT_ALF); }
Read *fread_abi(FILE *fp) { return fread_reading(fp, NULL, TT_ABI); }
int convert(char *file, int format, mFILE *ofp, char *name, int output_conf) { Read *r; Exp_info *e; char buf[50]; double aq; if (format == TT_BIO) { if (NULL == (r = read_reading(file, format))) { fprintf(stderr, "%s: failed to read\n", file); return 1; } } else { FILE *infp; if (NULL == (infp = open_trace_file(file, NULL))) { perror(file); return 1; } if (NULL == (r = fread_reading(infp, file, format))) { fprintf(stderr, "%s: failed to read\n", file); return 1; } fclose(infp); } e = read2exp(r, name); if (NULL == e) { fprintf(stderr, "Failed to create experiment file.\n"); read_deallocate(r); return 1; } sprintf(buf, "%f", aq = avg_qual(r)); exp_set_entry(e, EFLT_AQ, buf); exp_print_mfile(ofp, e); if (output_conf && aq != 0) { char *cstr; int1 *conf; int i; conf = xmalloc(r->NBases * sizeof(*conf)); cstr = xmalloc(5 * r->NBases+2); for (i = 0; i < r->NBases; i++) { switch (r->base[i]) { case 'a': case 'A': conf[i] = r->prob_A[i]; break; case 'c': case 'C': conf[i] = r->prob_C[i]; break; case 'g': case 'G': conf[i] = r->prob_G[i]; break; case 't': case 'T': conf[i] = r->prob_T[i]; break; default: conf[i] = (r->prob_A[i] + r->prob_C[i] + r->prob_G[i] + r->prob_T[i]) / 4; break; } } conf2str(conf, r->NBases, cstr); exp_set_entry(e, EFLT_AV, cstr); xfree(cstr); xfree(conf); } read_deallocate(r); exp_destroy_info(e); mfflush(ofp); return 0; }