Exemplo n.º 1
0
static void md5_one(const char *fn)
{
    hts_md5_context *md5_one, *md5_all;
    int l, i, k;
    gzFile fp;
    kseq_t *seq;
    unsigned char unordered[16], digest[16];
    char hex[33];

    for (l = 0; l < 16; ++l) unordered[l] = 0;
    fp = strcmp(fn, "-")? gzopen(fn, "r") : gzdopen(fileno(stdin), "r");
    if (fp == 0) {
        fprintf(stderr, "md5fa: %s: No such file or directory\n", fn);
        exit(1);
    }

    if (!(md5_all = hts_md5_init()))
        exit(1);

    if (!(md5_one = hts_md5_init())) {
        hts_md5_destroy(md5_all);
        exit(1);
    }

    seq = kseq_init(fp);
    while ((l = kseq_read(seq)) >= 0) {
        for (i = k = 0; i < seq->seq.l; ++i) {
            if (islower(seq->seq.s[i])) seq->seq.s[k++] = toupper(seq->seq.s[i]);
            else if (isupper(seq->seq.s[i])) seq->seq.s[k++] = seq->seq.s[i];
        }
        hts_md5_reset(md5_one);
        hts_md5_update(md5_one, (unsigned char*)seq->seq.s, k);
        hts_md5_final(digest, md5_one);
        hts_md5_hex(hex, digest);
        for (l = 0; l < 16; ++l)
            unordered[l] ^= digest[l];
        printf("%s  %s  %s\n", hex, fn, seq->name.s);
        hts_md5_update(md5_all, (unsigned char*)seq->seq.s, k);
    }
    hts_md5_final(digest, md5_all);
    kseq_destroy(seq);

    hts_md5_hex(hex, digest);
    printf("%s  %s  >ordered\n", hex, fn);
    hts_md5_hex(hex, unordered);
    printf("%s  %s  >unordered\n", hex, fn);

    hts_md5_destroy(md5_all);
    hts_md5_destroy(md5_one);
}
Exemplo n.º 2
0
static void md5_one(const char *fn)
{
    unsigned char buf[4096], digest[16];
    char hex[33];
    hts_md5_context *md5;
    int l;
    FILE *fp;

    fp = strcmp(fn, "-")? fopen(fn, "r") : stdin;
    if (fp == 0) {
        fprintf(stderr, "md5sum: %s: No such file or directory\n", fn);
        exit(1);
    }
    if (!(md5 = hts_md5_init())) {
        fprintf(stderr, "md5sum: %s: Failed to allocate md5 buffer\n", fn);
        exit(1);
    }
    while ((l = fread(buf, 1, 4096, fp)) > 0)
        hts_md5_update(md5, buf, l);
    hts_md5_final(digest, md5);
    if (fp != stdin) fclose(fp);
    hts_md5_hex(hex, digest);
    printf("%s  %s\n", hex, fn);
    hts_md5_destroy(md5);
}
Exemplo n.º 3
0
static void write_dict(const char *fn, args_t *args)
{
    hts_md5_context *md5;
    int l, i, k;
    gzFile fp;
    kseq_t *seq;
    unsigned char digest[16];
    char hex[33];

    fp = strcmp(fn, "-") ? gzopen(fn, "r") : gzdopen(fileno(stdin), "r");
    if (fp == 0) {
        fprintf(stderr, "dict: %s: No such file or directory\n", fn);
        exit(1);
    }
    FILE *out = stdout;
    if (args->output_fname) {
        out = fopen(args->output_fname, "w");
        if (out == NULL) {
          fprintf(stderr, "dict: %s: Cannot open file for writing\n", args->output_fname);
          exit(1);
        }
    }

    if (!(md5 = hts_md5_init()))
        exit(1);

    seq = kseq_init(fp);
    if (args->header) fprintf(out, "@HD\tVN:1.0\tSO:unsorted\n");
    while ((l = kseq_read(seq)) >= 0) {
        for (i = k = 0; i < seq->seq.l; ++i) {
            if (seq->seq.s[i] >= '!' && seq->seq.s[i] <= '~')
                seq->seq.s[k++] = toupper(seq->seq.s[i]);
        }
        hts_md5_reset(md5);
        hts_md5_update(md5, (unsigned char*)seq->seq.s, k);
        hts_md5_final(digest, md5);
        hts_md5_hex(hex, digest);
        fprintf(out, "@SQ\tSN:%s\tLN:%d\tM5:%s", seq->name.s, k, hex);
        if (args->uri)
            fprintf(out, "\tUR:%s", args->uri);
        else if (strcmp(fn, "-") != 0) {
#ifdef _WIN32
            char *real_path = _fullpath(NULL, fn, PATH_MAX);
#else
            char *real_path = realpath(fn, NULL);
#endif
            fprintf(out, "\tUR:file://%s", real_path);
            free(real_path);
        }
        if (args->assembly) fprintf(out, "\tAS:%s", args->assembly);
        if (args->species) fprintf(out, "\tSP:%s", args->species);
        fprintf(out, "\n");
    }
    kseq_destroy(seq);
    hts_md5_destroy(md5);

    if (args->output_fname) fclose(out);
}