Line 20: |
Line 20: |
| // Open the input file for reading. | | // Open the input file for reading. |
| SamFile samIn; | | SamFile samIn; |
− | if(!samIn.OpenForRead(argv[1])) | + | samIn.OpenForRead(argv[1]); |
− | {
| |
− | fprintf(stderr, "%s\n", samIn.GetStatusMessage());
| |
− | return(samIn.GetStatus());
| |
− | }
| |
| | | |
| // Open the output file for writing. | | // Open the output file for writing. |
| SamFile samOut; | | SamFile samOut; |
− | if(!samOut.OpenForWrite(argv[2])) | + | samOut.OpenForWrite(argv[2]); |
− | {
| |
− | fprintf(stderr, "%s\n", samOut.GetStatusMessage());
| |
− | return(samOut.GetStatus());
| |
− | }
| |
| | | |
| // Read the sam header. | | // Read the sam header. |
| SamFileHeader samHeader; | | SamFileHeader samHeader; |
− | if(!samIn.ReadHeader(samHeader)) | + | samIn.ReadHeader(samHeader); |
− | {
| |
− | fprintf(stderr, "%s\n", samIn.GetStatusMessage());
| |
− | return(samIn.GetStatus());
| |
− | }
| |
| | | |
| // Write the sam header. | | // Write the sam header. |
− | if(!samOut.WriteHeader(samHeader)) | + | samOut.WriteHeader(samHeader); |
− | {
| |
− | fprintf(stderr, "%s\n", samOut.GetStatusMessage());
| |
− | return(samOut.GetStatus());
| |
− | }
| |
| | | |
| SamRecord samRecord; | | SamRecord samRecord; |
Line 60: |
Line 44: |
| { | | { |
| // Successfully read a record from the file, so write it. | | // Successfully read a record from the file, so write it. |
− | if(!samOut.WriteRecord(samHeader, samRecord)) | + | samOut.WriteRecord(samHeader, samRecord); |
− | {
| |
− | // Failed to write a record.
| |
− | fprintf(stderr, "%s\n", samOut.GetStatusMessage());
| |
− | returnStatus = samOut.GetStatus();
| |
− | }
| |
− | }
| |
− | | |
− | if(samIn.GetStatus() != SamStatus::NO_MORE_RECS)
| |
− | {
| |
− | // Failed to read a record.
| |
− | fprintf(stderr, "%s\n", samIn.GetStatusMessage());
| |
− | // Set the return status to the reason why
| |
− | // the read failed.
| |
− | returnStatus = samIn.GetStatus();
| |
| } | | } |
| | | |
Line 82: |
Line 52: |
| samOut.GetCurrentRecordCount() << std::endl; | | samOut.GetCurrentRecordCount() << std::endl; |
| | | |
− | // Since the reads were successful, return the status based | + | // Return success since a failure would have thrown |
− | // on the status of the writes. If any failed, return
| + | // an exception. |
− | // their failure status. | |
| return(returnStatus); | | return(returnStatus); |
| } | | } |
Line 102: |
Line 71: |
| // Open the input file for reading. | | // Open the input file for reading. |
| SamFile samIn; | | SamFile samIn; |
− | if(!samIn.OpenForRead(inputFilename)) | + | samIn.OpenForRead(inputFilename); |
− | {
| |
− | fprintf(stderr, "%s\n", samIn.GetStatusMessage());
| |
− | return(samIn.GetStatus());
| |
− | }
| |
| | | |
| // Open the bam index file for reading. | | // Open the bam index file for reading. |
− | if(!samIn.ReadBamIndex(indexFilename)) | + | samIn.ReadBamIndex(indexFilename); |
− | {
| |
− | fprintf(stderr, "%s\n", samIn.GetStatusMessage());
| |
− | return(samIn.GetStatus());
| |
− | }
| |
| | | |
| // Open the output file for writing. | | // Open the output file for writing. |
| SamFile samOut; | | SamFile samOut; |
− | if(!samOut.OpenForWrite(outputFilename)) | + | samOut.OpenForWrite(outputFilename); |
− | {
| |
− | fprintf(stderr, "%s\n", samOut.GetStatusMessage());
| |
− | return(samOut.GetStatus());
| |
− | }
| |
| | | |
| // Read the sam header. | | // Read the sam header. |
| SamFileHeader samHeader; | | SamFileHeader samHeader; |
− | if(!samIn.ReadHeader(samHeader)) | + | samIn.ReadHeader(samHeader); |
− | {
| |
− | fprintf(stderr, "%s\n", samIn.GetStatusMessage());
| |
− | return(samIn.GetStatus());
| |
− | }
| |
| | | |
| // Write the sam header. | | // Write the sam header. |
− | if(!samOut.WriteHeader(samHeader)) | + | samOut.WriteHeader(samHeader); |
− | {
| |
− | fprintf(stderr, "%s\n", samOut.GetStatusMessage());
| |
− | return(samOut.GetStatus());
| |
− | }
| |
| | | |
| SamRecord samRecord; | | SamRecord samRecord; |
Line 151: |
Line 100: |
| numSectionRecords++; | | numSectionRecords++; |
| // Successfully read a record from the file, so write it. | | // Successfully read a record from the file, so write it. |
− | if(!samOut.WriteRecord(samHeader, samRecord)) | + | samOut.WriteRecord(samHeader, samRecord); |
− | {
| |
− | // Failed to write a record.
| |
− | fprintf(stderr, "%s\n", samOut.GetStatusMessage());
| |
− | }
| |
− | }
| |
− | | |
− | if(samIn.GetStatus() != SamStatus::NO_MORE_RECS)
| |
− | {
| |
− | // Failed to read a record.
| |
− | fprintf(stderr, "%s\n", samIn.GetStatusMessage());
| |
| } | | } |
| | | |
Line 255: |
Line 194: |
| SamFile samIn; | | SamFile samIn; |
| // Open the file for reading. | | // Open the file for reading. |
− | if(!samIn.OpenForRead(inFile)) | + | samIn.OpenForRead(inFile); |
− | {
| |
− | fprintf(stderr, "%s\n", samIn.GetStatusMessage());
| |
− | return(samIn.GetStatus());
| |
− | }
| |
| | | |
| // If refName is set, use that. | | // If refName is set, use that. |
Line 265: |
Line 200: |
| { | | { |
| // Use Reference Name. | | // Use Reference Name. |
− | if(!samIn.SetReadSection(refName.c_str(), start, end)) | + | samIn.SetReadSection(refName.c_str(), start, end); |
− | {
| |
− | fprintf(stderr, "%s\n", samIn.GetStatusMessage());
| |
− | return(samIn.GetStatus());
| |
− | }
| |
| } | | } |
| else | | else |
| { | | { |
| // Use Reference ID | | // Use Reference ID |
− | if(!samIn.SetReadSection(refID, start, end)) | + | samIn.SetReadSection(refID, start, end); |
− | {
| |
− | fprintf(stderr, "%s\n", samIn.GetStatusMessage());
| |
− | return(samIn.GetStatus());
| |
− | }
| |
| } | | } |
| | | |
| // Open the output file for writing. | | // Open the output file for writing. |
| SamFile samOut; | | SamFile samOut; |
− | if(!samOut.OpenForWrite(outFile)) | + | samOut.OpenForWrite(outFile); |
− | {
| |
− | fprintf(stderr, "%s\n", samOut.GetStatusMessage());
| |
− | return(samOut.GetStatus());
| |
− | }
| |
| | | |
| // Open the bam index file for reading. | | // Open the bam index file for reading. |
− | if(!samIn.ReadBamIndex(indexFile)) | + | samIn.ReadBamIndex(indexFile); |
− | {
| |
− | fprintf(stderr, "%s\n", samIn.GetStatusMessage());
| |
− | return(samIn.GetStatus());
| |
− | }
| |
| | | |
− | // Read the sam header. | + | // Read & write the sam header. |
| SamFileHeader samHeader; | | SamFileHeader samHeader; |
− | if(!samIn.ReadHeader(samHeader)) | + | samIn.ReadHeader(samHeader); |
− | {
| + | samOut.WriteHeader(samHeader); |
− | fprintf(stderr, "%s\n", samIn.GetStatusMessage());
| |
− | return(samIn.GetStatus());
| |
− | } | |
− |
| |
− | // Write the sam header.
| |
− | if(!samOut.WriteHeader(samHeader))
| |
− | {
| |
− | fprintf(stderr, "%s\n", samOut.GetStatusMessage());
| |
− | return(samOut.GetStatus());
| |
− | }
| |
| | | |
| // Read the sam records. | | // Read the sam records. |
Line 316: |
Line 225: |
| int numSectionRecords = 0; | | int numSectionRecords = 0; |
| | | |
− | // Set returnStatus to success. It will be changed | + | // Set returnStatus to success. |
− | // to the failure reason if any of the writes fail.
| |
| SamStatus::Status returnStatus = SamStatus::SUCCESS; | | SamStatus::Status returnStatus = SamStatus::SUCCESS; |
| | | |
Line 324: |
Line 232: |
| { | | { |
| // Successfully read a record from the file, so write it. | | // Successfully read a record from the file, so write it. |
− | if(!samOut.WriteRecord(samHeader, samRecord)) | + | samOut.WriteRecord(samHeader, samRecord); |
− | {
| |
− | // Failed to write a record.
| |
− | fprintf(stderr, "%s\n", samOut.GetStatusMessage());
| |
− | returnStatus = samOut.GetStatus();
| |
− | }
| |
| ++numSectionRecords; | | ++numSectionRecords; |
− | }
| |
− |
| |
− | if(samIn.GetStatus() != SamStatus::NO_MORE_RECS)
| |
− | {
| |
− | // Failed to read a record.
| |
− | fprintf(stderr, "%s\n", samIn.GetStatusMessage());
| |
− | // Set the return status to the reason why
| |
− | // the read failed.
| |
− | returnStatus = samIn.GetStatus();
| |
| } | | } |
| | | |
Line 365: |
Line 259: |
| } | | } |
| | | |
− | SamFile samIn; | + | SamFile samIn(ErrorHandler::RETURN); |
| // Open the file for reading. | | // Open the file for reading. |
| if(!samIn.OpenForRead(inFile)) | | if(!samIn.OpenForRead(inFile)) |