本文整理汇总了C++中SamRecord::getCigarInfo方法的典型用法代码示例。如果您正苦于以下问题:C++ SamRecord::getCigarInfo方法的具体用法?C++ SamRecord::getCigarInfo怎么用?C++ SamRecord::getCigarInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SamRecord
的用法示例。
在下文中一共展示了SamRecord::getCigarInfo方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: softClip
// Soft clip the record from the front and/or the back.
SamFilter::FilterStatus SamFilter::softClip(SamRecord& record,
int32_t numFrontClips,
int32_t numBackClips)
{
//////////////////////////////////////////////////////////
Cigar* cigar = record.getCigarInfo();
FilterStatus status = NONE;
int32_t startPos = record.get0BasedPosition();
CigarRoller updatedCigar;
status = softClip(*cigar, numFrontClips, numBackClips,
startPos, updatedCigar);
if(status == FILTERED)
{
/////////////////////////////
// The entire read is clipped, so rather than clipping it,
// filter it out.
filterRead(record);
return(FILTERED);
}
else if(status == CLIPPED)
{
// Part of the read was clipped, and now that we have
// an updated cigar, update the read.
record.setCigar(updatedCigar);
// Update the starting position.
record.set0BasedPosition(startPos);
}
return(status);
}
示例2: addToCurrentCluster
void Sites::addToCurrentCluster( vector<bool> & is_in_coord, SingleSite & new_site, SamRecord & rec )
{
if (is_in_coord.size() != NMEI)
morphError("[Sites::setNewCluster] is_in_coord size error");
// update breakpoint
int old_evi = new_site.evidence;
float a1 = (float)1 / float(old_evi+1);
int ep = getEstimatedBreakPoint(rec);
new_site.breakp = round( a1 * (float)ep + (float)new_site.breakp * (1-a1));
new_site.evidence++;
// update position
if (rec.get1BasedPosition() < new_site.start)
new_site.start = rec.get1BasedPosition();
else if (rec.get1BasedAlignmentEnd() > new_site.end)
new_site.end = rec.get1BasedAlignmentEnd();
// update info
if (rec.getFlag() & 0x10) {
if (new_site.right_clip_only) {
Cigar * myCigar = rec.getCigarInfo();
int begin_clip = myCigar->getNumBeginClips();
if ( begin_clip < MIN_CLIP/2)
new_site.right_clip_only = 0;
}
for(int m=0; m<NMEI; m++) {
if (is_in_coord[m])
new_site.right[m]++;
}
}
else {
if (new_site.left_clip_only) {
Cigar * myCigar = rec.getCigarInfo();
int end_clip = myCigar->getNumEndClips();
if (end_clip < MIN_CLIP/2)
new_site.left_clip_only = 0;
}
for( int m=0; m<NMEI; m++) {
if (is_in_coord[m])
new_site.left[m]++;
}
}
}
示例3: setNewCluster
void Sites::setNewCluster( vector<bool> & is_in_coord, SingleSite & new_site, SamRecord & rec )
{
if (is_in_coord.size() != NMEI)
morphError("[Sites::setNewCluster] is_in_coord size error");
// set info
new_site.breakp = getEstimatedBreakPoint(rec);
new_site.rcount = 1;
new_site.evidence = 1;
for(int m=0; m<NMEI; m++) {
new_site.left[m] = 0;
new_site.right[m] = 0;
}
new_site.left_clip_only = 1;
new_site.right_clip_only = 1;
new_site.depth = current_depth;
new_site.depth_add = 1;
// set position & mtype
if ( rec.getFlag() & 0x10 ) { // right anchor
new_site.start = rec.get1BasedPosition();
new_site.end = rec.get1BasedAlignmentEnd();
Cigar * myCigar = rec.getCigarInfo();
int begin_clip = myCigar->getNumBeginClips();
if ( begin_clip < MIN_CLIP/2)
new_site.right_clip_only = 0;
for(int m=0; m<NMEI; m++) {
if (is_in_coord[m])
new_site.right[m] = 1;
}
}
else {
new_site.start = rec.get1BasedPosition();
new_site.end = rec.get1BasedAlignmentEnd();
Cigar * myCigar = rec.getCigarInfo();
int end_clip = myCigar->getNumEndClips();
if (end_clip < MIN_CLIP/2)
new_site.left_clip_only = 0;
for(int m=0; m<NMEI; m++) {
if (is_in_coord[m])
new_site.left[m] = 1;
}
}
}
示例4: getMaxClipLen
int getMaxClipLen( SamRecord & sam_rec )
{
Cigar * myCigar = sam_rec.getCigarInfo();
int begin_clip = myCigar->getNumBeginClips();
int end_clip = myCigar->getNumEndClips();
if (begin_clip >= end_clip)
return begin_clip;
else
return -end_clip;
}
示例5: processReadBuildTable
//.........这里部分代码省略.........
const String* oldQPtr =
samRecord.getStringTag(myQField.c_str());
if((oldQPtr != NULL) && (oldQPtr->Length() == seqLen))
{
// There is an old quality, so use that.
myQualityStrings.oldq = oldQPtr->c_str();
}
else
{
// Tag was not found, so use the current quality.
++myNumQualTagErrors;
if(myNumQualTagErrors == 1)
{
Logger::gLogger->warning("Recab: %s tag was not found/invalid, so using the quality field in records without the tag", myQField.c_str());
}
myQualityStrings.oldq = samRecord.getQuality();
}
//printf("%s\n",samRecord.getQuality());
//printf("%s:%s\n",myQField.c_str(),temp.c_str());
}
else
{
myQualityStrings.oldq = samRecord.getQuality();
}
if(myQualityStrings.oldq.length() != (unsigned int)seqLen)
{
Logger::gLogger->warning("Quality is not the correct length, so skipping recalibration on that record.");
++myNumBuildSkipped;
return(false);
}
aligTypes = "";
Cigar* cigarPtr = samRecord.getCigarInfo();
if(cigarPtr == NULL)
{
Logger::gLogger->warning("Failed to get the cigar");
++myNumBuildSkipped;
return(false);
}
// This read will be used for building the recab table.
++myNumBuildReads;
////////////////
////// iterate sequence
////////////////
genomeIndex_t refPos = 0;
int32_t refOffset = 0;
int32_t prevRefOffset = Cigar::INDEX_NA;
int32_t seqPos = 0;
int seqIncr = 1;
if(reverse)
{
seqPos = seqLen - 1;
seqIncr = -1;
}
// read
if(!SamFlag::isPaired(flag) || SamFlag::isFirstFragment(flag))
// Mark as first if it is not paired or if it is the
// first in the pair.
data.read = 0;
else
data.read = 1;
示例6: processRecord
bool BamProcessor::processRecord ()
{
trclog << "\nProcessing record " << read_cnt_ << " - " << rec_.getReadName () << ", " << rec_.get0BasedUnclippedEnd () << "->" << rec_.getReadLength () << ", ref " << rec_.getReferenceName () << std::endl;
const char* seq = rec_.getSequence ();
unsigned position = rec_.get0BasedPosition ();
unsigned new_position = position;
bool reverse_match = (rec_.getFlag () & 0x10);
Cigar* cigar_p = rec_.getCigarInfo ();
if (!cigar_p->size ()) // can not recreate reference is cigar is missing. Keep record unaligned.
{ // TODO: allow to specify and load external reference
++ unaligned_cnt_;
return true;
}
myassert (cigar_p);
const String *mdval = rec_.getStringTag ("MD");
if (!mdval) // can not recreate reference is MD tag is missing. Keep record as is.
{
warn << "No MD Tag for record " << proc_cnt_ << ". Skipping record." << std::endl;
++nomd_cnt_;
return true; // record will be kept as-is.
}
std::string md_tag = mdval->c_str ();
// find the non-clipped region
uint32_t clean_len;
EndClips clips;
const char* clean_read = clip_seq (seq, *cigar_p, clean_len, clips);
// find length needed for the reference
// this reserves space enough for entire refference, including softclipped ends.
unsigned ref_len = cigar_p->getExpectedReferenceBaseCount ();
if (ref_buffer_sz_ < ref_len)
{
ref_buffer_sz_ = (1 + ref_len / REF_BUF_INCR) * REF_BUF_INCR;
ref_buffer_.reset (ref_buffer_sz_);
}
if (clean_len > MAX_SEQ_LEN || ref_len > MAX_SEQ_LEN)
{
++ toolongs_;
return true;
}
// recreate reference by Query, Cigar, and MD tag. Do not include softclipped ends in the recreated sequence (use default last parameter)
recreate_ref (seq, rec_.getReadLength (), cigar_p, md_tag.c_str (), ref_buffer_, ref_buffer_sz_);
unsigned qry_ins; // extra bases in query == width_left
unsigned ref_ins; // extra bases in reference == width_right
band_width (*cigar_p, qry_ins, ref_ins);
if (log_matr_ || log_base_)
{
logfile_ << "Record " << read_cnt_ << ": " << rec_.getReadName () << "\n"
<< " sequence (" << rec_.getReadLength () << " bases)\n";
}
CigarRoller roller;
int ref_shift = 0; // shift of the new alignment position on refereance relative the original
unsigned qry_off, ref_off; // offsets on the query and reference of the first non-clipped aligned bases
double new_score = 0;
switch (p_->algo ())
{
case ContalignParams::TEMPL:
{
// call aligner
new_score = taligner_.eval (clean_read, clean_len, ref_buffer_, ref_len, 0, band_width_);
// read traceback
// TODO: convert directly to cigar
genstr::Alignment* al = taligner_.trace ();
// convert alignment to cigar
ref_shift = roll_cigar (roller, *al, clean_len, clips, qry_off, ref_off);
}
break;
case ContalignParams::PLAIN:
{
new_score = aligner_.align_band (
clean_read, // xseq
clean_len, // xlen
ref_buffer_, // yseq
ref_len, // ylen
0, // xpos
0, // ypos
std::max (clean_len, ref_len), // segment length
qry_ins + band_width_, // width_left
false, // unpack
ref_ins + band_width_, // width_right - forces to width_left
true, // to_beg
true // to_end
);
unsigned bno = aligner_.backtrace (
batches_, // BATCH buffer
max_batch_no_, // size of BATCH buffer
false, // fill the BATCH array in reverse direction
ref_ins + band_width_ // width
);
// convert alignment to cigar
ref_shift = roll_cigar (roller, batches_, bno, clean_len, clips, qry_off, ref_off);
//.........这里部分代码省略.........
示例7: execute
//.........这里部分代码省略.........
}
int refPos = 0;
Cigar* cigarPtr = NULL;
char cigarChar = '?';
// Exclude clips from the qual/phred counts if unmapped reads are excluded.
bool qualExcludeClips = excludeFlags & SamFlag::UNMAPPED;
//////////////////////////////////
// When not reading by sections, getNextSection returns true
// the first time, then false the next time.
while(getNextSection(samIn))
{
// Keep reading records from the file until SamFile::ReadRecord
// indicates to stop (returns false).
while(((maxNumReads < 0) || (numReads < maxNumReads)) && samIn.ReadRecord(samHeader, samRecord))
{
// Another record was read, so increment the number of reads.
++numReads;
// See if the quality histogram should be genereated.
if(qual || phred)
{
// Get the quality.
const char* qual = samRecord.getQuality();
// Check for no quality ('*').
if((qual[0] == '*') && (qual[1] == 0))
{
// This record does not have a quality string, so no
// quality processing is necessary.
}
else
{
int index = 0;
cigarPtr = samRecord.getCigarInfo();
cigarChar = '?';
refPos = samRecord.get0BasedPosition();
if(!qualExcludeClips && (cigarPtr != NULL))
{
// Offset the reference position by any soft clips
// by subtracting the queryIndex of this start position.
// refPos is now the start position of the clips.
refPos -= cigarPtr->getQueryIndex(0);
}
while(qual[index] != 0)
{
// Skip this quality if it is clipped and we are skipping clips.
if(cigarPtr != NULL)
{
cigarChar = cigarPtr->getCigarCharOpFromQueryIndex(index);
}
if(qualExcludeClips && Cigar::isClip(cigarChar))
{
// Skip a clipped quality.
++index;
// Increment the position.
continue;
}
if(withinRegion && (myEndPos != -1) && (refPos >= myEndPos))
{
// We have hit the end of the region, stop processing this
// quality string.
break;
}
示例8: softClipBeginByRefPos
// Soft Clip from the beginning of the read to the specified reference position.
int32_t CigarHelper::softClipBeginByRefPos(SamRecord& record,
int32_t refPosition0Based,
CigarRoller& newCigar,
int32_t &new0BasedPosition)
{
newCigar.clear();
Cigar* cigar = record.getCigarInfo();
if(cigar == NULL)
{
// Failed to get the cigar.
ErrorHandler::handleError("Soft clipping, but failed to read the cigar");
return(NO_CLIP);
}
// No cigar or position in the record, so return no clip.
if((cigar->size() == 0) || (record.get0BasedPosition() == -1))
{
return(NO_CLIP);
}
// Check to see if the reference position occurs before the record starts,
// if it does, do no clipping.
if(refPosition0Based < record.get0BasedPosition())
{
// Not within this read, so nothing to clip.
newCigar.Set(record.getCigar());
return(NO_CLIP);
}
// The position falls after the read starts, so loop through until the
// position or the end of the read is found.
int32_t readClipPosition = 0;
bool clipWritten = false;
new0BasedPosition = record.get0BasedPosition();
for(int i = 0; i < cigar->size(); i++)
{
const Cigar::CigarOperator* op = &(cigar->getOperator(i));
if(clipWritten)
{
// Clip point has been found, so just add everything.
newCigar += *op;
// Go to the next operation.
continue;
}
// The clip point has not yet been found, so check to see if we found
// it now.
// Not a clip, check to see if the operation is found in the
// reference.
if(Cigar::foundInReference(*op))
{
// match, mismatch, deletion, skip
// increment the current reference position to just past this
// operation.
new0BasedPosition += op->count;
// Check to see if this is also in the query, because otherwise
// the operation is still being consumed.
if(Cigar::foundInQuery(*op))
{
// Also in the query, determine if the entire thing should
// be clipped or just part of it.
uint32_t numKeep = 0;
// Check to see if we have hit our clip position.
if(refPosition0Based < new0BasedPosition)
{
// The specified clip position is in this cigar operation.
numKeep = new0BasedPosition - refPosition0Based - 1;
if(numKeep > op->count)
{
// Keep the entire read. This happens because
// we keep reading until the first match/mismatch
// after the clip.
numKeep = op->count;
}
}
// Add the part of this operation that is being clipped
// to the clip count.
readClipPosition += (op->count - numKeep);
// Only write the clip if we found a match/mismatch
// to write. Otherwise we will keep accumulating clips
// for the case of insertions.
if(numKeep > 0)
{
new0BasedPosition -= numKeep;
newCigar.Add(Cigar::softClip, readClipPosition);
// Add the clipped part of this cigar to the clip
// position.
newCigar.Add(op->operation, numKeep);
//.........这里部分代码省略.........
示例9: softClipEndByRefPos
// Soft Clip from the end of the read at the specified reference position.
int32_t CigarHelper::softClipEndByRefPos(SamRecord& record,
int32_t refPosition0Based,
CigarRoller& newCigar)
{
newCigar.clear();
Cigar* cigar = record.getCigarInfo();
if(cigar == NULL)
{
// Failed to get the cigar.
ErrorHandler::handleError("Soft clipping, but failed to read the cigar");
return(NO_CLIP);
}
// No cigar or position in the record, so return no clip.
if((cigar->size() == 0) || (record.get0BasedPosition() == -1))
{
return(NO_CLIP);
}
// Check to see if the reference position occurs after the record ends,
// if so, do no clipping.
if(refPosition0Based > record.get0BasedAlignmentEnd())
{
// Not within this read, so nothing to clip.
newCigar.Set(record.getCigar());
return(NO_CLIP);
}
// The position falls before the read ends, so loop through until the
// position is found.
int32_t currentRefPosition = record.get0BasedPosition();
int32_t readClipPosition = 0;
for(int i = 0; i < cigar->size(); i++)
{
const Cigar::CigarOperator* op = &(cigar->getOperator(i));
// If the operation is found in the reference, increase the
// reference position.
if(Cigar::foundInReference(*op))
{
// match, mismatch, deletion, skip
// increment the current reference position to just past
// this operation.
currentRefPosition += op->count;
}
// Check to see if we have hit our clip position.
if(refPosition0Based < currentRefPosition)
{
// If this read is also in the query (match/mismatch),
// write the partial op to the new cigar.
int32_t numKeep = 0;
if(Cigar::foundInQuery(*op))
{
numKeep = op->count - (currentRefPosition - refPosition0Based);
if(numKeep > 0)
{
newCigar.Add(op->operation, numKeep);
readClipPosition += numKeep;
}
}
else if(Cigar::isClip(*op))
{
// This is a hard clip, so write it.
newCigar.Add(op->operation, op->count);
}
else
{
// Not found in the query (skip/deletion),
// so don't write any of the operation.
}
// Found the clip point, so break.
break;
}
else if(refPosition0Based == currentRefPosition)
{
newCigar += *op;
if(Cigar::foundInQuery(*op))
{
readClipPosition += op->count;
}
}
else
{
// Not yet to the clip position, so add this operation/size to
// the new cigar.
newCigar += *op;
if(Cigar::foundInQuery(*op))
{
// Found in the query, so update the read clip position.
readClipPosition += op->count;
}
}
} // End loop through cigar.
// Before adding the softclip, read from the end of the cigar checking to
// see if the operations are in the query, removing operations that are
// not (pad/delete/skip) until a hardclip or an operation in the query is
//.........这里部分代码省略.........
示例10: addEntry
// Add an entry to this pileup element.
void PileupElementBaseQual::addEntry(SamRecord& record)
{
// Call the base class:
PileupElement::addEntry(record);
if(myRefAllele.empty())
{
genomeIndex_t markerIndex = (*myRefSeq).getGenomePosition(getChromosome(), static_cast<uint32_t>(getRefPosition()+1));
myRefAllele = (*myRefSeq)[markerIndex];
}
// Increment the index
++myIndex;
// if the index has gone beyond the allocated space, double the size.
if(myIndex >= myAllocatedSize)
{
char* tempBuffer = (char*)realloc(myBases, myAllocatedSize * 2);
if(tempBuffer == NULL)
{
std::cerr << "Memory Allocation Failure\n";
// TODO
return;
}
myBases = tempBuffer;
int8_t* tempInt8Buffer = (int8_t*)realloc(myMapQualities, myAllocatedSize * 2 * sizeof(int8_t));
if(tempInt8Buffer == NULL)
{
std::cerr << "Memory Allocation Failure\n";
// TODO
return;
}
myMapQualities = tempInt8Buffer;
tempInt8Buffer = (int8_t*)realloc(myQualities, myAllocatedSize * 2 * sizeof(int8_t));
if(tempInt8Buffer == NULL)
{
std::cerr << "Memory Allocation Failure\n";
// TODO
return;
}
myQualities = tempInt8Buffer;
tempBuffer = (char*)realloc(myStrands, myAllocatedSize * 2);
if(tempBuffer == NULL)
{
std::cerr << "Memory Allocation Failure\n";
// TODO
return;
}
myStrands = tempBuffer;
tempInt8Buffer = (int8_t*)realloc(myCycles, myAllocatedSize * 2 * sizeof(int8_t));
if(tempInt8Buffer == NULL)
{
std::cerr << "Memory Allocation Failure\n";
// TODO
return;
}
myCycles = tempInt8Buffer;
int16_t* tempInt16Buffer = (int16_t*)realloc(myGLScores, myAllocatedSize * 2 * sizeof(int16_t));
if(tempInt8Buffer == NULL)
{
std::cerr << "Memory Allocation Failure\n";
// TODO
return;
}
myGLScores = tempInt16Buffer;
myAllocatedSize = myAllocatedSize * 2;
}
Cigar* cigar = record.getCigarInfo();
if(cigar == NULL)
{
throw std::runtime_error("Failed to retrieve cigar info from the record.");
}
int32_t readIndex =
cigar->getQueryIndex(getRefPosition(), record.get0BasedPosition());
// If the readPosition is N/A, this is a deletion.
if(readIndex != CigarRoller::INDEX_NA)
{
char base = record.getSequence(readIndex);
int8_t mapQual = record.getMapQuality();
//-33 to obtain the PHRED base quality
char qual = record.getQuality(readIndex) - 33;
if(qual == UNSET_QUAL)
{
qual = ' ';
}
char strand = (record.getFlag() & 0x0010) ? 'R' : 'F';
int cycle = strand == 'F' ? readIndex + 1 : record.getReadLength() - readIndex;
myBases[myIndex] = base;
myMapQualities[myIndex] = mapQual;
myQualities[myIndex] = qual;
myStrands[myIndex] = strand;
myCycles[myIndex] = cycle;
}
else if(myAddDelAsBase)
{
//.........这里部分代码省略.........