a14d8dea71b926b326385cdd03a50b5db372240c kent Wed Nov 2 14:22:24 2016 -0700 Updating to use htslib. diff --git src/utils/bamToFastq/bamToFastq.c src/utils/bamToFastq/bamToFastq.c index 4854860..d3651d4 100644 --- src/utils/bamToFastq/bamToFastq.c +++ src/utils/bamToFastq/bamToFastq.c @@ -29,50 +29,55 @@ /* This function updates the bam quality to a fastq quality. */ { int size = strlen(seq->dna); int i = 0; for (i = 0; i < size; ++i) { seq->quality[i] += 33; } seq->quality[size] = '\0'; } void bamToFastq(char *inBam, char *outFastq) /* bamToFastq - converts a bam file to Fastq. */ { samfile_t *in = bamMustOpenLocal(inBam, "rb", NULL); +bam_header_t *head = sam_hdr_read(in); +if (head == NULL) + errAbort("Aborting ... bad BAM header in %s", inBam); + /* Open up the bam input and a fastq sequence */ FILE *f = mustOpen(outFastq, "w"); bam1_t one; ZeroVar(&one); // This seems to be necessary! struct fq seq = {}; for (;;) { - if (samread(in, &one) < 0) + if (sam_read1(in, head, &one) < 0) { break; } seq.header = catTwoStrings("@",bam1_qname(&one)); seq.dna = bamGetQuerySequence(&one, TRUE); seq.quality = bamGetQueryQuals(&one, TRUE); /* Enter in the required fq values. */ fixQuality(&seq); fqWriteNext(&seq, f); /* Print the fq to file. */ freez(&seq.header); freez(&seq.dna); freez(&seq.quality); } samclose(in); +carefulClose(&f); } int main(int argc, char *argv[]) /* Process command line. */ { optionInit(&argc, argv, options); if (argc != 3) usage(); bamToFastq(argv[1],argv[2]); return 0; }