20c459c45647bd0b8bf30cf68da82eafb5f0e5c5 ceisenhart Mon Jun 23 18:35:34 2014 -0700 Updated the main for loop to be 0 based index rather than 1 based index diff --git src/utils/bamMerge/bamMerge.c src/utils/bamMerge/bamMerge.c index 6a25028..85885be 100644 --- src/utils/bamMerge/bamMerge.c +++ src/utils/bamMerge/bamMerge.c @@ -15,53 +15,53 @@ " bamMerge input1.bam input2.bam ... inputn.bam\n" "options:\n" " \n" ); } /* Command line validation table. */ static struct optionSpec options[] = { {NULL, 0}, }; void bamMerge(char *fileNames[], int files) /* bamMerge - Merges multiple bam files into a single bam file. */ { -samfile_t *chromHead = bamMustOpenLocal(fileNames[1], "rb", NULL); +samfile_t *chromHead = bamMustOpenLocal(fileNames[0], "rb", NULL); bam_header_t *head = chromHead->header; samfile_t *out = bamMustOpenLocal("merged.bam", "wb", head); samclose(chromHead); /* Opens the output and sets the header to be the same as the first input. */ int i; -for (i = 1; i < files; ++i) +for (i = 0; i < files - 1; ++i) /* Loop through all input files */ { samfile_t *in = bamMustOpenLocal(fileNames[i], "rb", NULL); bam1_t one; ZeroVar(&one); // This seems to be necessary! /* Open an input file */ for (;;) { if (samread(in, &one) < 0) { break; } samwrite(out, &one); /* Copy the input to the output */ } samclose(in); } samclose(out); } int main(int argc, char *argv[]) /* Process command line. */ { optionInit(&argc, argv, options); if (argc < 2) usage(); -bamMerge(argv,argc); +bamMerge(argv+1,argc); return 0; }