/*=== FUNCTION ============================================================* Name: test_qes_seqfile_write Description: Tests the qes_seqfile_write function from qes_seqfile.c *===========================================================================*/ static void test_qes_seqfile_write (void *ptr) { struct qes_seq *seq = qes_seq_create(); size_t expt_bytes = 0; ssize_t res = 0; struct qes_seqfile *sf = NULL; char *fname = NULL; char *crc = NULL; (void) ptr; /* Make a seq to write */ qes_seq_fill_name(seq, "HWI-TEST", 8); qes_seq_fill_comment(seq, "testseq 1 2 3", 13); qes_seq_fill_seq(seq, "ACTCAATT", 8); qes_seq_fill_qual(seq, "IIIIIIII", 8); expt_bytes = 1 + 8 + 1 + 13 + 1 + /* @ + name + ' ' + comment + '\n' */ 8 + 1 + 2 + 8 + 1; /* seq + '\n' + "+\n" + qual + '\n' */ /* Test with a FASTQ seqfile */ fname = get_writable_file(); tt_assert(fname != NULL); sf = qes_seqfile_create(fname, "wT"); qes_seqfile_set_format(sf, FASTQ_FMT); res = qes_seqfile_write(sf, seq); tt_int_op(res, ==, expt_bytes); qes_seqfile_destroy(sf); /* Has to happen here to flush it */ crc = crc32_file(fname); tt_str_op(crc, ==, "d4665941"); clean_writable_file(fname); free(crc); fname = NULL; crc = NULL; /* Test with a FASTA seqfile */ expt_bytes = 1 + 8 + 1 + 13 + 1 + /* @ + name + ' ' + comment + '\n' */ 8 + 1; /* seq + '\n'*/ fname = get_writable_file(); tt_assert(fname != NULL); sf = qes_seqfile_create(fname, "wT"); qes_seqfile_set_format(sf, FASTA_FMT); /* do the write */ res = qes_seqfile_write(sf, seq); tt_int_op(res, ==, expt_bytes); qes_seqfile_destroy(sf); /* Flush it */ crc = crc32_file(fname); tt_str_op(crc, ==, "0a295c77"); clean_writable_file(fname); fname = NULL; /* Check with bad params that it returns -2 */ res = qes_seqfile_write(NULL, seq); tt_int_op(res, ==, -2); res = qes_seqfile_write(sf, NULL); tt_int_op(res, ==, -2); end: qes_seqfile_destroy(sf); qes_seq_destroy(seq); if (fname != NULL) free(fname); if (crc != NULL) free(crc); }
inline int qes_seq_fill(struct qes_seq *seqobj, const char *name, const char *comment, const char *seq, const char *qual) { if (!qes_seq_ok(seqobj) || name == NULL || comment == NULL || seq == NULL \ || qual == NULL) { return 1; } if (qes_seq_fill_name(seqobj, name, strlen(name)) != 0) return 1; if (qes_seq_fill_comment(seqobj, comment, strlen(comment)) != 0) return 1; if (qes_seq_fill_seq(seqobj, seq, strlen(seq)) != 0) return 1; if (qes_seq_fill_qual(seqobj, qual, strlen(qual)) != 0) return 1; return 0; }