本文整理汇总了C++中SamFile::attemptRecoverySync方法的典型用法代码示例。如果您正苦于以下问题:C++ SamFile::attemptRecoverySync方法的具体用法?C++ SamFile::attemptRecoverySync怎么用?C++ SamFile::attemptRecoverySync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SamFile
的用法示例。
在下文中一共展示了SamFile::attemptRecoverySync方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: execute
//.........这里部分代码省略.........
refPtr = new GenomeSequence(refFile);
}
SamRecord::SequenceTranslation translation;
if((useBases) && (refPtr != NULL))
{
translation = SamRecord::BASES;
}
else if((useEquals) && (refPtr != NULL))
{
translation = SamRecord::EQUAL;
}
else
{
useOrigSeq = true;
translation = SamRecord::NONE;
}
if(params)
{
inputParameters.Status();
}
// Open the input file for reading.
SamFile samIn;
if(recover) samIn.setAttemptRecovery(true);
samIn.OpenForRead(inFile);
// Open the output file for writing.
SamFile samOut;
samOut.OpenForWrite(outFile);
samOut.SetWriteSequenceTranslation(translation);
samOut.SetReference(refPtr);
// Read the sam header.
SamFileHeader samHeader;
samIn.ReadHeader(samHeader);
// Write the sam header.
samOut.WriteHeader(samHeader);
SamRecord samRecord;
// Set returnStatus to success. It will be changed
// to the failure reason if any of the writes fail.
SamStatus::Status returnStatus = SamStatus::SUCCESS;
while(1) {
try {
// Keep reading records until ReadRecord returns false.
while(samIn.ReadRecord(samHeader, samRecord))
{
// left shift if necessary.
if(lshift)
{
samRecord.shiftIndelsLeft();
}
// Successfully read a record from the file, so write it.
if(!samOut.WriteRecord(samHeader, samRecord))
{
// Failed to write a record.
fprintf(stderr, "%s\n", samOut.GetStatusMessage());
returnStatus = samOut.GetStatus();
}
}
break;
} catch (std::runtime_error e) {
std::cerr << "Caught runtime error: " << e.what() << "\n";
if(!recover) {
std::cerr << "Corrupted BAM file detected - consider using --recover option.\n";
break;
}
std::cerr << "Attempting to resync at next good BGZF block and BAM record.\n";
// XXX need to resync SamFile stream here
bool rc = samIn.attemptRecoverySync(checkSignature, SIGNATURE_LENGTH);
if(rc) {
std::cerr << "Successful resync - some data lost.\n";
continue; // succeeded
}
std::cerr << "Failed to re-sync on data stream.\n";
break; // failed to resync
}
}
std::cerr << std::endl << "Number of records read = " <<
samIn.GetCurrentRecordCount() << std::endl;
std::cerr << "Number of records written = " <<
samOut.GetCurrentRecordCount() << std::endl;
if(refPtr != NULL)
{
delete(refPtr);
}
// Since the reads were successful, return the status based
// on the status of the writes. If any failed, return
// their failure status.
return(returnStatus);
}