本文整理汇总了C++中SamRecord::get1BasedPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ SamRecord::get1BasedPosition方法的具体用法?C++ SamRecord::get1BasedPosition怎么用?C++ SamRecord::get1BasedPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SamRecord
的用法示例。
在下文中一共展示了SamRecord::get1BasedPosition方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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]++;
}
}
}
示例2: 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;
}
}
}
示例3: getEstimatedBreakPoint
// given mapping start position
// if anchor on left
// expected_breakp = position + avr_ins_size / 2;
// if anchor on right
// expected_breakp = position + read_length - avr_ins_size / 2;
// key = round( expected_breakp / WIN )
int Sites::getEstimatedBreakPoint( SamRecord & rec )
{
int ep;
int clen = GetMaxClipLen(rec);
if ( !rec.getFlag() & 0x10 ) { // left anchor
if (clen < -MIN_CLIP/2) // end clip of anchor decides position
ep = rec.get1BasedAlignmentEnd();
else
ep = rec.get1BasedPosition() + avr_ins_size / 3;
}
else { // right anchor
if (clen > MIN_CLIP/2)
ep = rec.get1BasedPosition();
else
ep = rec.get1BasedPosition() + avr_read_length - avr_ins_size / 3;
}
return ep;
}
示例4: getFlankingCount
int Likelihood::getFlankingCount( string & chr, int pos )
{
bool status = bam.SetReadSection( chr.c_str(), pos - avr_read_length * 2, pos + avr_read_length/2 );
if (!status)
return 0;
int n = 0;
SamRecord rec;
while(bam.ReadRecord(bam_header, rec)) {
if ( !(rec.getFlag() & 0x2) )
continue;
if (IsSupplementary(rec.getFlag()))
continue;
if (rec.getReadLength() < avr_read_length / 3)
continue;
if (rec.getMapQuality() < MIN_QUALITY)
continue;
if (rec.get1BasedPosition() + MIN_CLIP/2 <= pos && rec.get1BasedAlignmentEnd() - MIN_CLIP/2 >= pos )
n++;
}
return n;
}
示例5: processReadBuildTable
bool Recab::processReadBuildTable(SamRecord& samRecord)
{
static BaseData data;
static std::string chromosomeName;
static std::string readGroup;
static std::string aligTypes;
int seqLen = samRecord.getReadLength();
// Check if the parameters have been processed.
if(!myParamsSetup)
{
// This throws an exception if the reference cannot be setup.
processParams();
}
uint16_t flag = samRecord.getFlag();
if(!SamFlag::isMapped(flag))
{
// Unmapped, skip processing
++myUnMappedCount;
}
else
{
// This read is mapped.
++myMappedCount;
}
if(SamFlag::isSecondary(flag))
{
// Secondary read
++mySecondaryCount;
}
if(SamFlag::isDuplicate(flag))
{
++myDupCount;
}
if(SamFlag::isQCFailure(flag))
{
++myQCFailCount;
}
// Check if the flag contains an exclude.
if((flag & myIntBuildExcludeFlags) != 0)
{
// Do not use this read for building the recalibration table.
++myNumBuildSkipped;
return(false);
}
if(samRecord.getMapQuality() == 0)
{
// 0 mapping quality, so skip processing.
++myMapQual0Count;
++myNumBuildSkipped;
return(false);
}
if(samRecord.getMapQuality() == 255)
{
// 255 mapping quality, so skip processing.
++myMapQual255Count;
++myNumBuildSkipped;
return(false);
}
chromosomeName = samRecord.getReferenceName();
readGroup = samRecord.getString("RG").c_str();
// Look for the read group in the map.
// TODO - extra string constructor??
RgInsertReturn insertRet =
myRg2Id.insert(std::pair<std::string, uint16_t>(readGroup, 0));
if(insertRet.second == true)
{
// New element inserted.
insertRet.first->second = myId2Rg.size();
myId2Rg.push_back(readGroup);
}
data.rgid = insertRet.first->second;
//reverse
bool reverse;
if(SamFlag::isReverse(flag))
reverse = true;
else
reverse = false;
if(myReferenceGenome == NULL)
{
throw std::runtime_error("Failed to setup Reference File.\n");
}
genomeIndex_t mapPos =
myReferenceGenome->getGenomePosition(chromosomeName.c_str(),
samRecord.get1BasedPosition());
if(mapPos==INVALID_GENOME_INDEX)
//.........这里部分代码省略.........
示例6: processRecord
//.........这里部分代码省略.........
);
// convert alignment to cigar
ref_shift = roll_cigar (roller, batches_, bno, clean_len, clips, qry_off, ref_off);
}
break;
case ContalignParams::POLY:
{
new_score = contalign_.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 = contalign_.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);
}
break;
default:
break;
}
++realigned_cnt_;
// compare original and new cigar (and location)
if (ref_shift || !(*cigar_p == roller))
{
// save original cigar and position for reporting
std::string orig_cigar_str;
rec_.getCigarInfo ()->getCigarString (orig_cigar_str);
int32_t prior_pos = rec_.get0BasedPosition ();
// replace cigar
rec_.setCigar (roller);
++ modified_cnt_;
// update pos_adjusted_cnt if position changed
if (ref_shift != 0)
{
myassert (prior_pos + ref_shift >= 0);
rec_.set0BasedPosition (prior_pos + ref_shift);
++ pos_adjusted_cnt_;
}
if (log_diff_)
{
const unsigned MAX_BATCH_PRINTED = 100;
BATCH batches [MAX_BATCH_PRINTED];
std::string new_cigar_str;
unsigned bno;
int swscore;
rec_.getCigarInfo ()->getCigarString (new_cigar_str);
if (!log_base_ && !log_matr_)
logfile_ << "Record " << read_cnt_ << ": " << rec_.getReadName () << " (" << rec_.getReadLength () << " bases)\n";
logfile_ << " ORIG ALIGNMENT:" << std::right << std::setw (9) << prior_pos+1 << "->" << orig_cigar_str << "\n";
bno = cigar_to_batches (orig_cigar_str, batches, MAX_BATCH_PRINTED);
swscore = align_score (batches, bno, clean_read, ref_buffer_, p_->gip (), p_->gep (), p_->mat (), p_->mis ());
print_batches (clean_read, clean_len, false, ref_buffer_, ref_len, false, batches, bno, logfile_, false, prior_pos + clips.soft_beg_, clips.soft_beg_, 0, 160);
logfile_ << "\n 'classic' SW score is " << swscore << "\n";
logfile_ << " NEW ALIGNMENT:" << std::right << std::setw (9) << rec_.get1BasedPosition () << "->" << new_cigar_str << std::endl;
bno = cigar_to_batches (new_cigar_str, batches, MAX_BATCH_PRINTED);
swscore = align_score (batches, bno, clean_read + qry_off, ref_buffer_ + ref_off, p_->gip (), p_->gep (), p_->mat (), p_->mis ());
print_batches (clean_read + qry_off, clean_len - qry_off, false, ref_buffer_ + ref_off, ref_len - ref_off, false, batches, bno, logfile_, false, prior_pos + clips.soft_beg_ + ref_off, clips.soft_beg_ + qry_off, 0, 160);
logfile_ << "\n 'classic' SW score is " << swscore;
logfile_ << "\n alternate (context-aware) score is " << new_score << ", used bandwidth left: " << qry_ins + band_width_ << ", right: " << ref_ins + band_width_ << "\n" << std::endl;
}
else if (log_base_)
{
logfile_ << "Recomputed alignment differs from original:\n";
logfile_ << " ORIG ALIGNMENT:" << std::right << std::setw (9) << prior_pos+1 << "->" << orig_cigar_str << "\n";
std::string new_cigar_str;
rec_.getCigarInfo ()->getCigarString (new_cigar_str);
logfile_ << " NEW ALIGNMENT:" << std::right << std::setw (9) << rec_.get1BasedPosition () << "->" << new_cigar_str << "\n" << std::endl;
}
}
else
{
if (log_base_)
{
logfile_ << "Recomputed alignment matches the original:\n";
std::string orig_cigar_str;
rec_.getCigarInfo ()->getCigarString (orig_cigar_str);
int32_t prior_pos = rec_.get0BasedPosition ();
logfile_ << " " << std::right << std::setw (9) << prior_pos+1 << "->" << orig_cigar_str << "\n" << std::endl;
}
}
return true;
}
示例7: validateRead1ModQuality
void validateRead1ModQuality(SamRecord& samRecord)
{
//////////////////////////////////////////
// Validate Record 1
// Create record structure for validating.
int expectedBlockSize = 89;
const char* expectedReferenceName = "1";
const char* expectedMateReferenceName = "1";
const char* expectedMateReferenceNameOrEqual = "=";
bamRecordStruct* expectedRecordPtr =
(bamRecordStruct *) malloc(expectedBlockSize + sizeof(int));
char tag[3];
char type;
void* value;
bamRecordStruct* bufferPtr;
unsigned char* varPtr;
expectedRecordPtr->myBlockSize = expectedBlockSize;
expectedRecordPtr->myReferenceID = 0;
expectedRecordPtr->myPosition = 1010;
expectedRecordPtr->myReadNameLength = 23;
expectedRecordPtr->myMapQuality = 0;
expectedRecordPtr->myBin = 4681;
expectedRecordPtr->myCigarLength = 2;
expectedRecordPtr->myFlag = 73;
expectedRecordPtr->myReadLength = 5;
expectedRecordPtr->myMateReferenceID = 0;
expectedRecordPtr->myMatePosition = 1010;
expectedRecordPtr->myInsertSize = 0;
// Check the alignment end
assert(samRecord.get0BasedAlignmentEnd() == 1016);
assert(samRecord.get1BasedAlignmentEnd() == 1017);
assert(samRecord.getAlignmentLength() == 7);
assert(samRecord.get0BasedUnclippedStart() == 1010);
assert(samRecord.get1BasedUnclippedStart() == 1011);
assert(samRecord.get0BasedUnclippedEnd() == 1016);
assert(samRecord.get1BasedUnclippedEnd() == 1017);
// Check the accessors.
assert(samRecord.getBlockSize() == expectedRecordPtr->myBlockSize);
assert(samRecord.getReferenceID() == expectedRecordPtr->myReferenceID);
assert(strcmp(samRecord.getReferenceName(), expectedReferenceName) == 0);
assert(samRecord.get1BasedPosition() == expectedRecordPtr->myPosition + 1);
assert(samRecord.get0BasedPosition() == expectedRecordPtr->myPosition);
assert(samRecord.getReadNameLength() ==
expectedRecordPtr->myReadNameLength);
assert(samRecord.getMapQuality() == expectedRecordPtr->myMapQuality);
assert(samRecord.getBin() == expectedRecordPtr->myBin);
assert(samRecord.getCigarLength() == expectedRecordPtr->myCigarLength);
assert(samRecord.getFlag() == expectedRecordPtr->myFlag);
assert(samRecord.getReadLength() == expectedRecordPtr->myReadLength);
assert(samRecord.getMateReferenceID() ==
expectedRecordPtr->myMateReferenceID);
assert(strcmp(samRecord.getMateReferenceName(),
expectedMateReferenceName) == 0);
assert(strcmp(samRecord.getMateReferenceNameOrEqual(),
expectedMateReferenceNameOrEqual) == 0);
assert(samRecord.get1BasedMatePosition() ==
expectedRecordPtr->myMatePosition + 1);
assert(samRecord.get0BasedMatePosition() ==
expectedRecordPtr->myMatePosition);
assert(samRecord.getInsertSize() == expectedRecordPtr->myInsertSize);
assert(strcmp(samRecord.getReadName(), "1:1011:F:255+17M15D20M") == 0);
assert(strcmp(samRecord.getCigar(), "5M2D") == 0);
assert(strcmp(samRecord.getSequence(), "CCGAA") == 0);
assert(strcmp(samRecord.getQuality(), "ABCDE") == 0);
assert(samRecord.getNumOverlaps(1010, 1017) == 5);
assert(samRecord.getNumOverlaps(1010, 1016) == 5);
assert(samRecord.getNumOverlaps(1012, 1017) == 3);
assert(samRecord.getNumOverlaps(1015, 1017) == 0);
assert(samRecord.getNumOverlaps(1017, 1010) == 0);
assert(samRecord.getNumOverlaps(1013, 1011) == 0);
assert(samRecord.getNumOverlaps(-1, 1017) == 5);
// Reset the tag iter, since the tags have already been read.
samRecord.resetTagIter();
// Check the tags.
assert(samRecord.getNextSamTag(tag, type, &value) == true);
assert(tag[0] == 'A');
assert(tag[1] == 'M');
assert(type == 'i');
assert(*(char*)value == 0);
assert(samRecord.getNextSamTag(tag, type, &value) == true);
assert(tag[0] == 'M');
assert(tag[1] == 'D');
assert(type == 'Z');
assert(*(String*)value == "37");
assert(samRecord.getNextSamTag(tag, type, &value) == true);
assert(tag[0] == 'N');
assert(tag[1] == 'M');
assert(type == 'i');
assert(*(char*)value == 0);
assert(samRecord.getNextSamTag(tag, type, &value) == true);
assert(tag[0] == 'X');
assert(tag[1] == 'T');
assert(type == 'A');
//.........这里部分代码省略.........
示例8: of
/*
if a discordant read is mapped to MEI (overlap with MEI coord)
add centor of ( anchor_end + 3*avr_ins_var )
skip unmap & clip
check 3 types at the same time
*/
void Sites::AddDiscoverSiteFromSingleBam( SingleSampleInfo & si )
{
/*for(int i=0;i<NMEI; i++) {
std::cout << "m=" << i << ": ";
for(map<string, map<int, bool> >::iterator t=meiCoord[m].begin(); t!=meiCoord[m].end(); t++)
std::cout << t->first << "->" << t->second.size() << " ";
std::cout << std::endl;
}*/
avr_read_length = si.avr_read_length;
avr_ins_size = si.avr_ins_size;
min_read_length = avr_read_length / 3;
current_depth = si.depth;
// total_depth += current_depth;
resetDepthAddFlag();
SamFile bam;
SamFileHeader bam_header;
OpenBamAndBai( bam,bam_header, si.bam_name );
for( int i=0; i<pchr_list->size(); i++ ) {
string chr = (*pchr_list)[i];
// if ( !single_chr.empty() && chr.compare(single_chr)!=0 )
// continue;
if ( siteList.find(chr) == siteList.end() )
siteList[chr].clear();
// map<string, map<int, SingleSite> >::iterator pchr = siteList[m].find(chr);
// map<string, map<int, bool> >::iterator coord_chr_ptr = meiCoord[m].find(chr);
// if (coord_chr_ptr == meiCoord[m].end())
// continue;
bool section_status;
if (range_start<0) { // no range
section_status = bam.SetReadSection( chr.c_str() );
if (!section_status) {
string str = "Cannot set read section at chr " + chr;
morphWarning( str );
}
}
else { // set range
section_status = bam.SetReadSection( chr.c_str(), range_start, range_end );
if (!section_status) {
string str = "Cannot set read section at chr " + chr + " " + std::to_string(range_start) + "-" + std::to_string(range_end);
morphWarning( str );
}
}
// DO ADDING
// if (siteList[chr].empty())
// p_reach_last = 1;
// else {
// p_reach_last = 0;
pnearest = siteList[chr].begin();
// }
SingleSite new_site; // temporary cluster. will be added to map later.
new_site.depth = current_depth;
bool start_new = 1; // check if need to add new_site to map and start new new_site
SamRecord rec;
int between = 0; // count #reads after new_site.end. If end changed, add it to rcount and reset to zero
while( bam.ReadRecord( bam_header, rec ) ) {
if (!start_new) {
if (rec.get1BasedPosition() >= new_site.end)
between++;
else
new_site.rcount++;
}
if (rec.getFlag() & 0x2)
continue;
if ( OneEndUnmap( rec.getFlag() ) )
continue;
if ( IsSupplementary(rec.getFlag()) )
continue;
if ( rec.getReadLength() < min_read_length )
continue;
if ( rec.getMapQuality() < MIN_QUALITY )
continue;
if (chr.compare(rec.getMateReferenceName())==0 && rec.getInsertSize() < abs(avr_ins_size*2))
continue;
bool is_mei = 0;
vector<bool> is_in_coord;
is_in_coord.resize(3, 0);
for(int m=0; m<NMEI; m++) {
map<string, map<int, bool> >::iterator coord_chr_ptr = meiCoord[m].find(rec.getMateReferenceName());
if (coord_chr_ptr == meiCoord[m].end())
is_in_coord[m] = 0;
else
is_in_coord[m] = isWithinCoord( rec.get1BasedMatePosition(), coord_chr_ptr->second ); // within MEI coord
if (is_in_coord[m])
is_mei = 1;
}
if (!is_mei)
continue;
if (start_new) {
setNewCluster( is_in_coord, new_site,rec);
start_new = 0;
//.........这里部分代码省略.........