From Genome Analysis Wiki
Jump to navigationJump to search
969 bytes added
, 13:09, 23 March 2010
Line 22: |
Line 22: |
| Determines if it is a BAM/SAM file by reading the beginning of the file. | | Determines if it is a BAM/SAM file by reading the beginning of the file. |
| Returns true if successfully opened reading, false if not. | | Returns true if successfully opened reading, false if not. |
| + | |- |
| + | | bool IsEOF() |
| + | | bool: true if the end of file has been reached, false if not. |
| |- | | |- |
| | bool OpenForWrite(const char * filename) | | | bool OpenForWrite(const char * filename) |
Line 74: |
Line 77: |
| SamRecord samRecord; | | SamRecord samRecord; |
| | | |
− | // Keep reading records until it fails. | + | // Keep reading records until the end of the file is reached. |
− | int recordCount = 0; | + | int numValidRecords = 0; |
− | while (samIn.ReadRecord(samHeader, samRecord) == true) | + | int numRecords = 0; |
| + | while(!samIn.IsEOF()) |
| { | | { |
− | recordCount++; | + | if(samIn.ReadRecord(samHeader, samRecord) == true) |
− | samOut.WriteRecord(samHeader, samRecord);
| + | { |
| + | numRecords++; |
| + | // Successfully read a record from the file, so check to see |
| + | // if it is valid. |
| + | if(samRecord.isValid()) |
| + | { |
| + | // It is valid, so write it. |
| + | numValidRecords++; |
| + | samOut.WriteRecord(samHeader, samRecord); |
| + | } |
| + | } |
| + | |
| } | | } |
− | printf("RecordCount = %d\n", recordCount); | + | std::cout << "Number of records = " << numRecords << std::endl; |
| + | std::cout << "Number of valid records = " << numValidRecords << std::endl; |
| } | | } |
| </pre> | | </pre> |
Line 118: |
Line 134: |
| ! width=""|Method Name | | ! width=""|Method Name |
| ! width=""|Description | | ! width=""|Description |
| + | |- |
| + | | void resetRecord() |
| + | | Resets the record to be an empty record. This is not necessary when you are reading a Sam/Bam file, but if you are setting fields, it is a good idea to clean out a record before reusing it. Clearing it allows you to not have to set any empty fields. |
| |- | | |- |
| | bool setReadName(const char* readName) | | | bool setReadName(const char* readName) |
Line 187: |
Line 206: |
| ! width=""|Method Name | | ! width=""|Method Name |
| ! width=""|Description | | ! width=""|Description |
| + | |- |
| + | | bool isValid() |
| + | | Returns true if the record is valid. This performs validation steps. TODO: the method exists, but it does not yet perform any checks, so just returns true. |
| |- | | |- |
| | int getBlockSize() | | | int getBlockSize() |