From Genome Analysis Wiki
Jump to: navigation, search

LibStatGen: BAM

1,121 bytes added, 13:46, 16 March 2010
no edit summary
Returns true if successfully written, false if not.
=== Usage Example ===
The following example reads in a sam/bam file and writes it out as a sam/bam file. The file format of the input sam/bam is determined by the SamFile class based on reading the type from the file. The file format of the output sam/bam file is determined by the SamFile class based on the extension of the output file. A ".bam" extension indicates a BAM file. All other extensions indicate SAM files.
int main(int argc, char ** argv)
if(argc != 3)
printf("./bam <inputFile> <outputFile.sam/bam>\n");
SamFile samIn;
SamFile samOut;
// Read the sam header.
SamFileHeader samHeader;
// Read the first sam record.
SamRecord samRecord;
// Keep reading records until it fails.
int recordCount = 0;
while (samIn.ReadRecord(samHeader, samRecord) == true)
samOut.WriteRecord(samHeader, samRecord);
printf("RecordCount = %d\n", recordCount);

Navigation menu