3,045
edits
Changes
From Genome Analysis Wiki
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.
<pre>
int main(int argc, char ** argv)
{
if(argc != 3)
{
printf("./bam <inputFile> <outputFile.sam/bam>\n");
exit(-1);
}
SamFile samIn;
samIn.OpenForRead(argv[1]);
SamFile samOut;
samOut.OpenForWrite(argv[2]);
// Read the sam header.
SamFileHeader samHeader;
samIn.ReadHeader(samHeader);
samOut.WriteHeader(samHeader);
// Read the first sam record.
SamRecord samRecord;
// Keep reading records until it fails.
int recordCount = 0;
while (samIn.ReadRecord(samHeader, samRecord) == true)
{
recordCount++;
samOut.WriteRecord(samHeader, samRecord);
}
printf("RecordCount = %d\n", recordCount);
}
</pre>