#include <getopt.h>
#include <unistd.h>
#include <htslib/sam.h>
static void print_usage(FILE *fp)
{
fprintf(fp, "Usage: write_fast <file>\n\
Appends a fasta/fastq file.\n");
return;
}
int main(int argc, char *argv[])
{
const char *outname = NULL; int ret = EXIT_FAILURE;
samFile *outfile = NULL; sam_hdr_t *out_samhdr = NULL; bam1_t *bamdata = NULL; char mode[4] = "a";
if (argc != 2) {
print_usage(stdout);
goto end;
}
outname = argv[1];
if (!(bamdata = bam_init1())) {
printf("Failed to initialize bamdata\n");
goto end;
}
if (sam_open_mode(mode + 1, outname, NULL) < 0) {
printf("Invalid file name\n");
goto end;
}
if (!(outfile = sam_open(outname, mode))) {
printf("Could not open %s\n", outname);
goto end;
}
if (bam_set1(bamdata, sizeof("test"), "test", BAM_FUNMAP, -1, -1, 0, 0, NULL, -1, -1, 0, 10, "AACTGACTGA", "1234567890", 0) < 0) {
printf("Failed to set data\n");
goto end;
}
if (sam_write1(outfile, out_samhdr, bamdata) < 0) {
printf("Failed to write data\n");
goto end;
}
ret = EXIT_SUCCESS;
end:
if (out_samhdr) {
sam_hdr_destroy(out_samhdr);
}
if (outfile) {
sam_close(outfile);
}
if (bamdata) {
bam_destroy1(bamdata);
}
return ret;
}