Пример #1
0
void freeSeqInfo(SeqInfo *si)
/*
 *
 */
{
#define FREE(F) \
    if (si->F != NULL) {\
        xfree(si->F);\
	si->F = NULL;\
    }

    if (si != NULL) {
	if(si->e != NULL) { exp_destroy_info(si->e); si->e = NULL; }
	FREE(confidence);
	FREE(origpos);
	xfree(si);
    }
}
Пример #2
0
/*
 * Write a sequence to a FILE *fp of format "format". If "format" is 0,
 * we choose our favourite - SCF.
 *
 * Returns:
 *   0 for success
 *  -1 for failure
 */
int mfwrite_reading(mFILE *fp, Read *read, int format) {
    int r = -1;
    int no_compress = 0;

#ifdef _WIN32
    /*
     * jkb 09/06/00 comment below
     *
     * On windows "prog > file.scf" will work wrongly (compared to
     * "prog file.scf") because windows is rather stupid. It treats ascii
     * and binary streams differently, it considers stdout 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

    switch (format) {
    default:
	/* Defaults to ZTR type */

#ifdef IOLIB_ZTR
    case TT_ZTR:
    case TT_ZTR2: {
        ztr_t *ztr;
	ztr = read2ztr(read);
	compress_ztr(ztr, 2);
	r = mfwrite_ztr(fp, ztr); 
	delete_ztr(ztr);
	no_compress = 1;
	break;
    }
    case TT_ZTR1: {
        ztr_t *ztr;
	ztr = read2ztr(read);
	compress_ztr(ztr, 1);
	r = mfwrite_ztr(fp, ztr); 
	delete_ztr(ztr);
	break;
    }
    case TT_ZTR3: {
        ztr_t *ztr;
	ztr = read2ztr(read);
	compress_ztr(ztr, 3);
	r = mfwrite_ztr(fp, ztr); 
	delete_ztr(ztr);
	no_compress = 1;
	break;
    }
#endif

#ifdef IOLIB_SCF
    case TT_SCF: {
        Scf *scf;
	scf = read2scf(read);
	r = mfwrite_scf(scf, fp);
	scf_deallocate(scf);
	break;
    }
#endif

#ifdef IOLIB_CTF
    case TT_CTF:
	r = mfwrite_ctf(fp, read); 
	break;
#endif

#ifdef IOLIB_ABI
    case TT_ABI:
	/*return mfwrite_abi(fp, read); */
	break;
#endif

#ifdef IOLIB_ALF
    case TT_ALF:
	/* return mfwrite_alf(fp, read); */
	break;
#endif

#ifdef IOLIB_EXP
    case TT_EXP: {
	Exp_info *e = read2exp(read, read->ident ? read->ident : "unknown");
	
	if (NULL == e) {
	    fprintf(stderr, "Failed to create experiment file.\n");
	    r = -1;
	} else {
	    exp_print_mfile(fp, e);
	    exp_destroy_info(e);
	    r = 0;
	}
	break;
    }
#endif

#ifdef IOLIB_PLN
    case TT_PLN:
	r = mfwrite_pln(fp, read);
	break;
#endif
    }

    mftruncate(fp, -1);
    if (r == 0 && !no_compress) {
	fcompress_file(fp);
    }
    mfflush(fp);

    return r;
}
Пример #3
0
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;
}