// -*- mode: c++; indent-tabs-mode: nil; -*- // // Copyright 2009 Illumina, Inc. // // This software is covered by the "Illumina Genome Analyzer Software // License Agreement" and the "Illumina Source Code License Agreement", // and certain third party copyright/licenses, and any user of this // source file is bound by the terms therein (see accompanying files // Illumina_Genome_Analyzer_Software_License_Agreement.pdf and // Illumina_Source_Code_License_Agreement.pdf and third party // copyright/license notices). // // /// \file /// /// \author Chris Saunders /// /// /// This code demonstrates a very simple parse of the bam index (bai) file to /// discover what reference indexes are present. Note the error checking is /// very incomplete. /// #include #include #include #include #include #include int main(int argc, char **argv) { const char* prog_name(argv[0]); if(argc != 2){ fprintf(stderr,"usage: %s bai_file\n",prog_name); exit(EXIT_FAILURE); } const char* bai_name(argv[1]); FILE* fp(fopen(bai_name,"rb")); if(fp == NULL) { fprintf(stderr,"Can't open bai_file: %s\n",bai_name); exit(EXIT_FAILURE); } char magic[4]; if((4 != fread(magic, 1, 4, fp))){ assert(0); } static const char* BAI_MAGIC_STR = "BAI\1"; if(strncmp(magic,BAI_MAGIC_STR,4) != 0){ assert(0); } static const size_t i32s(sizeof(int32_t)); static const size_t u32s(sizeof(uint32_t)); static const size_t u64s(sizeof(uint64_t)); int32_t n_ref(0); if(1 != fread(&n_ref,i32s,1,fp)){ assert(0); } assert(n_ref >= 0); std::vector is_ref_present(n_ref,false); for(int32_t i(0);i= 0); is_ref_present[i] = (n_bin > 0); for(int32_t j(0);j= 0); if(n_chunk>0) fseek(fp,n_chunk*u64s*2,SEEK_CUR); } int32_t n_intv(0); if(1 != fread(&n_intv,i32s,1,fp)){ assert(0); } assert(n_intv >= 0); if(n_intv>0) fseek(fp,n_intv*u64s,SEEK_CUR); } fclose(fp); fprintf(stdout,"n_ref_ids: %i\n",n_ref); fprintf(stdout,"ref_ids_mapped in file: (zero-indexed)\n"); for(int32_t i(0);i