/* * Read a sequence from a FILE *fp of format "format". If "format" is 0 * (ANY_FORMAT), we automatically determine the correct format. * We still pass a filename 'fn' although this isn't used other than for * filling in the read->trace_name field. * * NB this function should NOT be used when Biolims support is required * (as biolims readings are not stored in a file) * * Returns: * Read * for success * NULLRead for failure */ Read *mfread_reading(mFILE *fp, char *fn, int format) { Read *read; mFILE *newfp; if (!fn) fn = "(unknown)"; newfp = freopen_compressed(fp, NULL); if (newfp != fp) { fp = newfp; } else { newfp = NULL; } #ifdef _WIN32 /* * jkb 16/05/00 comment below * * On windows "prog < file.abi" will work wrongly (compared to * "prog file.abi") because windows is rather stupid. It treats ascii * and binary streams differently, it considers stdin to be ascii unless * told otherwise, and it can only be told otherwise by using non-ansi * windows-specific function calls. */ if (format != TT_EXP && format != TT_PLN && fp->fp) _setmode(_fileno(fp->fp), _O_BINARY); #endif if (format == TT_ANY) { format = fdetermine_trace_type(fp); mrewind(fp); } switch (format) { case TT_UNK: case TT_ERR: errout("File '%s' has unknown trace type\n", fn); read = NULLRead; break; #ifdef IOLIB_SCF case TT_SCF: { Scf *scf; scf = mfread_scf(fp); if (scf) { read = scf2read(scf); scf_deallocate(scf); } else read = NULLRead; break; } #endif #ifdef IOLIB_CTF case TT_CTF: read = mfread_ctf(fp); break; #endif #ifdef IOLIB_ZTR case TT_ZTR: case TT_ZTR1: case TT_ZTR2: case TT_ZTR3: { ztr_t *ztr; if ((ztr = mfread_ztr(fp))) { uncompress_ztr(ztr); read = ztr2read(ztr); delete_ztr(ztr); } else { read = NULLRead; } break; } #endif #ifdef IOLIB_ABI case TT_ABI: read = mfread_abi(fp); break; #endif #ifdef IOLIB_ALF case TT_ALF: read = mfread_alf(fp); break; #endif #ifdef IOLIB_EXP case TT_EXP: { /* FIXME: we shouldn't redirect like this */ Exp_info *e = exp_mfread_info(fp); read = e ? exp2read(e,fn) : NULLRead; break; } #endif #ifdef IOLIB_PLN case TT_PLN: read = mfread_pln(fp); break; #endif default: errout("Unknown format %d specified to read_reading()\n", format); read = NULLRead; } if (read != NULLRead && (read->trace_name = (char *)xmalloc(strlen(fn)+1))) strcpy(read->trace_name, fn); if (newfp) mfclose(newfp); return read; }
/* * Ripped out of io_lib's trace_dump program. * It reformats a trace to as printable ASCII. */ void dump_text(ztr_t *z, char *name, char mode, FILE **files) { Read *read; int i; uncompress_ztr(z); read = ztr2read(z); /* Inefficient; can do direct */ if (read == NULL) { fprintf(stderr, "Tracedump was unable to open file %s\n", name ); return; } fprintf(files[0], "[Trace]\n"); fprintf(files[0], "%s\n", name); fprintf(files[0], "\n[Header]\n"); fprintf(files[0], "%d\t\t# format\n", read->format); fprintf(files[0], "%d\t\t# NPoints\n", read->NPoints); fprintf(files[0], "%d\t\t# NBases\n", read->NBases); fprintf(files[0], "%d\t\t# NFlows\n", read->nflows); fprintf(files[0], "%d\t\t# maxTraceVal\n", (int)read->maxTraceVal-read->baseline); fprintf(files[0], "%d\t\t# baseline\n", read->baseline); fprintf(files[0], "%d\t\t# leftCutoff\n", read->leftCutoff); fprintf(files[0], "%d\t\t# rightCutoff\n", read->rightCutoff); fputs("\n[Bases]\n", files[0]); for (i = 0; i < read->NBases; i++) { fprintf(files[0], "%c %05d %+03d %+03d %+03d %+03d #%3d\n", read->base[i], read->basePos ? read->basePos[i] : 0, (int)read->prob_A[i], (int)read->prob_C[i], (int)read->prob_G[i], (int)read->prob_T[i], i); } if (read->NPoints) { fputs("\n[A_Trace]\n", files[0]); for(i = 0; i < read->NPoints; i++) fprintf(files[0], "%d\t#%5d\n", (int)read->traceA[i] - read->baseline, i); fputs("\n[C_Trace]\n", files[0]); for(i = 0; i < read->NPoints; i++) fprintf(files[0], "%d\t#%5d\n", (int)read->traceC[i] - read->baseline, i); fputs("\n[G_Trace]\n", files[0]); for(i = 0; i < read->NPoints; i++) fprintf(files[0], "%d\t#%5d\n", (int)read->traceG[i] - read->baseline, i); fputs("\n[T_Trace]\n", files[0]); for(i = 0; i < read->NPoints; i++) fprintf(files[0], "%d\t#%5d\n", (int)read->traceT[i] - read->baseline, i); } if (read->flow_order) { fputs("\n[Flows]\n", files[0]); for (i = 0; i < read->nflows; i++) { fprintf(files[0], "%c %5.2f %u\t#%5d\n", read->flow_order[i], read->flow ? read->flow[i] : 0, read->flow_raw ? read->flow_raw[i] : 0, i); } } if (read->info) { fputs("\n[Info]\n", files[0]); fprintf(files[0], "%s\n", read->info); } read_deallocate(read); }