本文整理汇总了C++中SamFile::GetCurrentRecordCount方法的典型用法代码示例。如果您正苦于以下问题:C++ SamFile::GetCurrentRecordCount方法的具体用法?C++ SamFile::GetCurrentRecordCount怎么用?C++ SamFile::GetCurrentRecordCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SamFile
的用法示例。
在下文中一共展示了SamFile::GetCurrentRecordCount方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: execute
//.........这里部分代码省略.........
uint32_t secondaryCount = 0;
uint32_t supplementaryCount = 0;
uint32_t excludedCount = 0;
// Now we start reading records
SamRecord* recordPtr;
SamStatus::Status returnStatus = SamStatus::SUCCESS;
while(returnStatus == SamStatus::SUCCESS)
{
recordPtr = mySamPool.getRecord();
if(recordPtr == NULL)
{
std::cerr << "Failed to allocate enough records\n";
return(-1);
}
if(!samIn.ReadRecord(header, *recordPtr))
{
returnStatus = samIn.GetStatus();
continue;
}
// Take note of properties of this record
int flag = recordPtr->getFlag();
if(SamFlag::isPaired(flag)) ++pairedCount;
if(SamFlag::isProperPair(flag)) ++properPairCount;
if(SamFlag::isReverse(flag)) ++reverseCount;
if(SamFlag::isQCFailure(flag)) ++qualCheckFailCount;
if(SamFlag::isSecondary(flag)) ++secondaryCount;
if(flag & SamFlag::SUPPLEMENTARY_ALIGNMENT) ++supplementaryCount;
if(!SamFlag::isMapped(flag)) ++unmappedCount;
// put the record in the appropriate maps:
// single reads go in myFragmentMap
// paired reads go in myPairedMap
recordCount = samIn.GetCurrentRecordCount();
// if we have moved to a new position, look back at previous reads for duplicates
if (hasPositionChanged(*recordPtr))
{
cleanupPriorReads(recordPtr);
}
// Determine if this read should be checked for duplicates.
if((!SamFlag::isMapped(flag)) || ((flag & intExcludeFlags) != 0))
{
++excludedCount;
// No deduping done on this record, but still build the recab table.
if(myDoRecab)
{
myRecab.processReadBuildTable(*recordPtr);
}
// Nothing more to do with this record, so
// release the pointer.
mySamPool.releaseRecord(recordPtr);
}
else
{
if(SamFlag::isDuplicate(flag) && !myForceFlag)
{
// Error: Marked duplicates, and duplicates aren't excluded.
Logger::gLogger->error("There are records already duplicate marked.");
Logger::gLogger->error("Use -f to clear the duplicate flag and start the dedup_LowMem procedure over");
}
checkDups(*recordPtr, recordCount);
mySamPool.releaseRecord(recordPtr);
示例2: execute
//.........这里部分代码省略.........
}
if(outFile == "")
{
usage();
inputParameters.Status();
// In file was not specified but it is mandatory.
std::cerr << "--out is a mandatory argument, "
<< "but was not specified" << std::endl;
return(-1);
}
if(params)
{
inputParameters.Status();
}
// Open the input file for reading.
SamFile samIn;
samIn.OpenForRead(inFile);
// Open the output file for writing.
SamFile samOut;
samOut.OpenForWrite(outFile);
// 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 or updates fail.
SamStatus::Status returnStatus = SamStatus::SUCCESS;
// Keep reading records until ReadRecord returns false.
while(samIn.ReadRecord(samHeader, samRecord))
{
// Update the cigar & position.
if(cigar)
{
if(!updateCigar(samRecord))
{
// Failed to update the cigar & position.
fprintf(stderr, "%s\n", samIn.GetStatusMessage());
returnStatus = samIn.GetStatus();
}
}
if(qual)
{
if(!updateQual(samRecord))
{
// Failed to update the quality.
fprintf(stderr, "%s\n", samIn.GetStatusMessage());
returnStatus = samIn.GetStatus();
}
}
if(rmBQ)
{
if(!removeBQ(samRecord))
{
// Failed to remove BQ.
fprintf(stderr, "%s\n", samIn.GetStatusMessage());
returnStatus = samIn.GetStatus();
}
}
if(rmTags != "")
{
if(!samRecord.rmTags(rmTags.c_str()))
{
// Failed to remove the specified tags.
fprintf(stderr, "%s\n", samIn.GetStatusMessage());
returnStatus = samIn.GetStatus();
}
}
// 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();
}
}
std::cerr << std::endl << "Number of records read = " <<
samIn.GetCurrentRecordCount() << std::endl;
std::cerr << "Number of records written = " <<
samOut.GetCurrentRecordCount() << std::endl;
// Since the reads were successful, return the status based
// on the status of the writes. If any failed, return
// their failure status.
return(returnStatus);
}
示例3: 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);
}
示例4: main
//.........这里部分代码省略.........
else if ( static_cast<int>(fastaFile.vnSequenceLengths[i]) != atoi(pSamHeaderRecord->getTagValue("LN")) ) {
gpLogger->error("SequenceLength is not identical between fasta and input BAM file");
}
else {
if ( !sAS.empty() )
samHeader.setSQTag("AS",sAS.c_str(),fastaFile.vsSequenceNames[i].c_str());
samHeader.setSQTag("M5",fastaFile.vsMD5sums[i].c_str(),fastaFile.vsSequenceNames[i].c_str());
if ( !sUR.empty() )
samHeader.setSQTag("UR",sUR.c_str(),fastaFile.vsSequenceNames[i].c_str());
if ( !sSP.empty() )
samHeader.setSQTag("SP",sSP.c_str(),fastaFile.vsSequenceNames[i].c_str());
}
}
gpLogger->write_log("Finished checking the consistency of SQ tags");
}
else {
gpLogger->write_log("Skipped checking the consistency of SQ tags");
}
// go over the headers again,
// assuming order of HD, SQ, RG, PG, and put proper tags at the end of the original tags
gpLogger->write_log("Creating the header of new output file");
//SamFileHeader outHeader;
samHeader.resetHeaderRecordIter();
for(unsigned int i=0; i < vsHDHeaders.size(); ++i) {
samHeader.addHeaderLine(vsHDHeaders[i].c_str());
}
/*
for(int i=0; i < fastaFile.vsSequenceNames.size(); ++i) {
std::string s("@SQ\tSN:");
char buf[1024];
s += fastaFile.vsSequenceNames[i];
sprintf(buf,"\tLN:%d",fastaFile.vnSequenceLengths[i]);
s += buf;
if ( !sAS.empty() ) {
sprintf(buf,"\tAS:%s",sAS.c_str());
s += buf;
}
if ( !sUR.empty() ) {
sprintf(buf,"\tUR:%s",sUR.c_str());
s += buf;
}
sprintf(buf,"\tM5:%s",fastaFile.vsMD5sums[i].c_str());
s += buf;
if ( !sSP.empty() ) {
sprintf(buf,"\tSP:%s",sSP.c_str());
s += buf;
}
outHeader.addHeaderLine(s.c_str());
}*/
for(unsigned int i=0; i < vsRGHeaders.size(); ++i) {
samHeader.addHeaderLine(vsRGHeaders[i].c_str());
}
for(unsigned int i=0; i < vsPGHeaders.size(); ++i) {
samHeader.addHeaderLine(vsPGHeaders[i].c_str());
}
samOut.WriteHeader(samHeader);
gpLogger->write_log("Adding %d HD, %d RG, and %d PG headers",vsHDHeaders.size(), vsRGHeaders.size(), vsPGHeaders.size());
gpLogger->write_log("Finished writing output headers");
// parse RG tag and get RG ID to append
std::string sRGID;
if ( ! vsRGHeaders.empty() ) {
std::vector<std::string> tokens;
FastaFile::tokenizeString( vsRGHeaders[0].c_str(), tokens );
for(unsigned int i=0; i < tokens.size(); ++i) {
if ( tokens[i].find("ID:") == 0 ) {
sRGID = tokens[i].substr(3);
}
}
}
gpLogger->write_log("Writing output BAM file");
SamRecord samRecord;
while (samIn.ReadRecord(samHeader, samRecord) == true) {
if ( !sRGID.empty() ) {
if ( samRecord.addTag("RG",'Z',sRGID.c_str()) == false ) {
gpLogger->error("Failed to add a RG tag %s",sRGID.c_str());
}
// temporary code added
if ( strncmp(samRecord.getReadName(),"seqcore_",8) == 0 ) {
char buf[1024];
sprintf(buf,"UM%s",samRecord.getReadName()+8);
samRecord.setReadName(buf);
}
}
samOut.WriteRecord(samHeader, samRecord);
//if ( samIn.GetCurrentRecordCount() == 1000 ) break;
}
samOut.Close();
gpLogger->write_log("Successfully written %d records",samIn.GetCurrentRecordCount());
delete gpLogger;
return 0;
}
示例5: execute
//.........这里部分代码省略.........
// Check for valid quality.
if((qual[index] < START_QUAL) || (qual[index] > MAX_QUAL))
{
if(qual)
{
std::cerr << "Invalid Quality found: " << qual[index]
<< ". Must be between "
<< START_QUAL << " and " << MAX_QUAL << ".\n";
}
if(phred)
{
std::cerr << "Invalid Phred Quality found: " << qual[index] - PHRED_DIFF
<< ". Must be between "
<< START_QUAL << " and " << MAX_QUAL << ".\n";
}
// Skip an invalid quality.
++index;
// Update the position if this is found in the reference or a clip.
if(Cigar::foundInReference(cigarChar) || Cigar::isClip(cigarChar))
{
++refPos;
}
continue;
}
// Increment the count for this quality.
++(qualCount[(int)(qual[index])]);
++(phredCount[(int)(qual[index]) - PHRED_DIFF]);
// Update the position if this is found in the reference or a clip.
if(Cigar::foundInReference(cigarChar) || Cigar::isClip(cigarChar))
{
++refPos;
}
++index;
}
}
}
// Check the next thing to do for the read.
if((baseQCPtr != NULL) || baseSum)
{
// Pileup the bases for this read.
pileup.processAlignmentRegion(samRecord, myStartPos, myEndPos, dbsnpListPtr);
}
}
// Done with a section, move on to the next one.
// New section, so flush the pileup.
pileup.flushPileup();
}
// Flush the rest of the pileup.
if((baseQCPtr != NULL) || baseSum)
{
// Pileup the bases.
pileup.processAlignmentRegion(samRecord, myStartPos, myEndPos, dbsnpListPtr);
PileupElementBaseQCStats::printSummary();
ifclose(baseQCPtr);
}
std::cerr << "Number of records read = " <<
samIn.GetCurrentRecordCount() << std::endl;
if(basic)
{
std::cerr << std::endl;
samIn.PrintStatistics();
}
// Print the quality stats.
if(qual)
{
std::cerr << std::endl;
std::cerr << "Quality\tCount\n";
for(int i = START_QUAL; i <= MAX_QUAL; i++)
{
std::cerr << i << "\t" << qualCount[i] << std::endl;
}
}
// Print the phred quality stats.
if(phred)
{
std::cerr << std::endl;
std::cerr << "Phred\tCount\n";
for(int i = START_PHRED; i <= MAX_PHRED; i++)
{
std::cerr << i << "\t" << phredCount[i] << std::endl;
}
}
SamStatus::Status status = samIn.GetStatus();
if(status == SamStatus::NO_MORE_RECS)
{
// A status of NO_MORE_RECS means that all reads were successful.
status = SamStatus::SUCCESS;
}
return(status);
}
示例6: execute
//.........这里部分代码省略.........
// Keep reading records until ReadRecord returns false.
while(samIn.ReadRecord(samHeader, samRecord)) {
// Successfully read a record from the file, so write it.
strcpy(seq,samRecord.getSequence());
strcpy(qual,samRecord.getQuality());
// Number of bases to trim from the left/right,
// set based on ignoreStrand flag and strand info.
int trimLeft = numTrimBaseL;
int trimRight = numTrimBaseR;
if(!ignoreStrand)
{
if(SamFlag::isReverse(samRecord.getFlag()))
{
// We are reversing the reverse reads,
// so swap the left & right trim counts.
trimRight = numTrimBaseL;
trimLeft = numTrimBaseR;
}
}
len = strlen(seq);
// Do not trim if sequence is '*'
if ( strcmp(seq, "*") != 0 ) {
bool qualValue = true;
if(strcmp(qual, "*") == 0)
{
qualValue = false;
}
int qualLen = strlen(qual);
if ( (qualLen != len) && qualValue ) {
fprintf(stderr,"ERROR: Sequence and Quality have different length\n");
return(-1);
}
if ( len < (trimLeft + trimRight) ) {
// Read Length is less than the total number of bases to trim,
// so trim the entire read.
for(i=0; i < len; ++i) {
seq[i] = 'N';
if ( qualValue ) {
qual[i] = '!';
}
}
}
else
{
// Read Length is larger than the total number of bases to trim,
// so trim from the left, then from the right.
for(i=0; i < trimLeft; ++i)
{
// Trim the bases from the left.
seq[i] = 'N';
if ( qualValue )
{
qual[i] = '!';
}
}
for(i = 0; i < trimRight; i++)
{
seq[len-i-1] = 'N';
if(qualValue)
{
qual[len-i-1] = '!';
}
}
}
samRecord.setSequence(seq);
samRecord.setQuality(qual);
}
if(!samOut.WriteRecord(samHeader, samRecord)) {
// Failed to write a record.
fprintf(stderr, "Failure in writing record %s\n", samOut.GetStatusMessage());
return(-1);
}
}
if(samIn.GetStatus() != SamStatus::NO_MORE_RECS)
{
// Failed to read a record.
fprintf(stderr, "%s\n", samIn.GetStatusMessage());
}
std::cerr << std::endl << "Number of records read = " <<
samIn.GetCurrentRecordCount() << std::endl;
std::cerr << "Number of records written = " <<
samOut.GetCurrentRecordCount() << std::endl;
if(samIn.GetStatus() != SamStatus::NO_MORE_RECS)
{
// Failed reading a record.
return(samIn.GetStatus());
}
// Since the reads were successful, return the status based
samIn.Close();
samOut.Close();
return 0;
}