static void test_qes_seqfile_guess_format (void *ptr) { struct qes_seqfile *sf = NULL; int res = -1; char *fname = NULL; (void) ptr; /* Test file opening for reading */ fname = find_data_file("test.fastq"); tt_assert(fname != NULL); sf = qes_seqfile_create(fname, "r"); /* test with a FASTQ file */ res = qes_seqfile_guess_format(sf); tt_int_op(res, ==, FASTQ_FMT); tt_int_op(sf->format, ==, FASTQ_FMT); qes_seqfile_destroy(sf); free(fname); /* test with a FASTA file */ fname = find_data_file("test.fasta"); tt_assert(fname != NULL); sf = qes_seqfile_create(fname, "r"); res = qes_seqfile_guess_format(sf); tt_int_op(res, ==, FASTA_FMT); tt_int_op(sf->format, ==, FASTA_FMT); qes_seqfile_destroy(sf); free(fname); fname = NULL; #ifdef ZLIB_FOUND /* test with a gziped FASTQ file */ fname = find_data_file("test.fastq.gz"); tt_assert(fname != NULL); sf = qes_seqfile_create(fname, "r"); res = qes_seqfile_guess_format(sf); tt_int_op(res, ==, FASTQ_FMT); tt_int_op(sf->format, ==, FASTQ_FMT); qes_seqfile_destroy(sf); #endif end: qes_seqfile_destroy(sf); if (fname != NULL) free(fname); }
struct qes_seqfile * qes_seqfile_create (const char *path, const char *mode) { struct qes_seqfile *sf = NULL; if (path == NULL || mode == NULL) return NULL; sf = qes_calloc(1, sizeof(*sf)); sf->qf = qes_file_open(path, mode); if (sf->qf == NULL) { qes_free(sf->qf); qes_free(sf); return NULL; } qes_str_init(&sf->scratch, __INIT_LINE_LEN); sf->n_records = 0; qes_seqfile_guess_format(sf); return sf; }