本文整理汇总了C++中SamRecord::getSequence方法的典型用法代码示例。如果您正苦于以下问题:C++ SamRecord::getSequence方法的具体用法?C++ SamRecord::getSequence怎么用?C++ SamRecord::getSequence使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SamRecord
的用法示例。
在下文中一共展示了SamRecord::getSequence方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ifprintf
void Bam2FastQ::writeFastQ(SamRecord& samRec, IFILE filePtr,
const char* readNameExt)
{
static int16_t flag;
static std::string sequence;
static String quality;
if(filePtr == NULL)
{
return;
}
flag = samRec.getFlag();
const char* readName = samRec.getReadName();
sequence = samRec.getSequence();
quality = samRec.getQuality();
if(SamFlag::isReverse(flag) && myReverseComp)
{
// It is reverse, so reverse compliment the sequence
BaseUtilities::reverseComplement(sequence);
// Reverse the quality.
quality.Reverse();
}
else
{
// Ensure it is all capitalized.
int seqLen = sequence.size();
for (int i = 0; i < seqLen; i++)
{
sequence[i] = (char)toupper(sequence[i]);
}
}
if(myRNPlus)
{
ifprintf(filePtr, "@%s%s\n%s\n+%s%s\n%s\n", readName, readNameExt,
sequence.c_str(), readName, readNameExt, quality.c_str());
}
else
{
ifprintf(filePtr, "@%s%s\n%s\n+\n%s\n", readName, readNameExt,
sequence.c_str(), quality.c_str());
}
// Release the record.
myPool.releaseRecord(&samRec);
}
示例2: ifopen
void Bam2FastQ::writeFastQ(SamRecord& samRec, IFILE filePtr,
const std::string& fileNameExt, const char* readNameExt)
{
static int16_t flag;
static std::string sequence;
static String quality;
static std::string rg;
static std::string rgFastqExt;
static std::string rgListStr;
static std::string fileName;
static std::string fq2;
if(mySplitRG)
{
rg = samRec.getString("RG").c_str();
rgFastqExt = rg + fileNameExt;
OutFastqMap::iterator it;
it = myOutFastqs.find(rgFastqExt);
if(it == myOutFastqs.end())
{
// New file.
fileName = myOutBase.c_str();
if(rg != "")
{
fileName += '.';
}
else
{
rg = ".";
}
fileName += rgFastqExt;
filePtr = ifopen(fileName.c_str(), "w", myCompression);
myOutFastqs[rgFastqExt] = filePtr;
if(fileNameExt != mySecondFileNameExt)
{
// first end.
const char* sm = mySamHeader.getRGTagValue("SM", rg.c_str());
if(strcmp(sm, "") == 0){sm = myOutBase.c_str();}
rgListStr.clear();
SamHeaderRG* rgPtr = mySamHeader.getRG(rg.c_str());
if((rgPtr == NULL) || (!rgPtr->appendString(rgListStr)))
{
// No RG info for this record.
rgListStr = ".\n";
}
fq2 = ".";
if(fileNameExt == myFirstFileNameExt)
{
fq2 = myOutBase.c_str();
if(rg != ".")
{
fq2 += '.';
fq2 += rg;
}
fq2 += mySecondFileNameExt;
}
ifprintf(myFqList, "%s\t%s\t%s\t%s",
sm, fileName.c_str(), fq2.c_str(),
rgListStr.c_str());
}
}
else
{
filePtr = it->second;
}
}
if(filePtr == NULL)
{
throw(std::runtime_error("Programming ERROR/EXITING: Bam2FastQ filePtr not set."));
return;
}
flag = samRec.getFlag();
const char* readName = samRec.getReadName();
sequence = samRec.getSequence();
if(myQField.IsEmpty())
{
// Read the quality from the quality field
quality = samRec.getQuality();
}
else
{
// Read Quality from the specified tag
const String* qTagPtr = samRec.getStringTag(myQField.c_str());
if((qTagPtr != NULL) && (qTagPtr->Length() == (int)sequence.length()))
{
// Use the tag value for quality
quality = qTagPtr->c_str();
}
else
{
// Tag was not found, so use the quality field.
++myNumQualTagErrors;
if(myNumQualTagErrors == 1)
{
std::cerr << "Bam2FastQ: " << myQField.c_str()
<< " tag was not found/invalid, so using the quality field in records without the tag\n";
}
//.........这里部分代码省略.........
示例3: processReadApplyTable
bool Recab::processReadApplyTable(SamRecord& samRecord)
{
static BaseData data;
static std::string readGroup;
static std::string aligTypes;
int seqLen = samRecord.getReadLength();
uint16_t flag = samRecord.getFlag();
// Check if the flag contains an exclude.
if((flag & myIntApplyExcludeFlags) != 0)
{
// Do not apply the recalibration table to this read.
++myNumApplySkipped;
return(false);
}
++myNumApplyReads;
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;
if(!myQField.IsEmpty())
{
// Check if there is an old quality.
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
{
myQualityStrings.oldq = samRecord.getQuality();
}
}
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.");
return(false);
}
myQualityStrings.newq.resize(seqLen);
////////////////
////// iterate sequence
////////////////
int32_t seqPos = 0;
int seqIncr = 1;
bool reverse;
if(SamFlag::isReverse(flag))
{
reverse = true;
seqPos = seqLen - 1;
seqIncr = -1;
}
else
reverse = false;
// Check which read - this will be the same for all positions, so
// do this outside of the smaller loop.
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;
// Set unsetbase for curBase.
// This will be used for the prebase of cycle 0.
data.curBase = 'K';
for (data.cycle = 0; data.cycle < seqLen; data.cycle++, seqPos += seqIncr)
{
// Set the preBase to the previous cycle's current base.
// For cycle 0, curBase was set to a default value.
data.preBase = data.curBase;
// Get the current base.
data.curBase = samRecord.getSequence(seqPos);
//.........这里部分代码省略.........
示例4: processReadBuildTable
//.........这里部分代码省略.........
////////////////
////// 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;
// Set unsetbase for curBase.
// This will be used for the prebase of cycle 0.
data.curBase = 'K';
for (data.cycle = 0; data.cycle < seqLen; data.cycle++, seqPos += seqIncr)
{
// Store the previous current base in preBase.
data.preBase = data.curBase;
// Get the current base before checking if we are going to
// process this position so it will be set for the next position.
data.curBase = samRecord.getSequence(seqPos);
if(reverse)
{
// Complement the current base.
// The prebase is already complemented.
data.curBase =
BaseAsciiMap::base2complement[(unsigned int)(data.curBase)];
}
// Get the reference offset.
refOffset = cigarPtr->getRefOffset(seqPos);
if(refOffset == Cigar::INDEX_NA)
{
// Not a match/mismatch, so continue to the next one which will
// not have a previous match/mismatch.
// Set previous ref offset to a negative so
// the next one won't be kept.
prevRefOffset = -2;
continue;
}
// This one is a match.
refPos = mapPos + refOffset;
// Check to see if we should process this position.
// Do not process if it is cycle 0 and:
// 1) current base is in dbsnp
if(data.cycle == 0)
{
if(!(myDbsnpFile.IsEmpty()) && myDbSNP[refPos])
{
// Save the previous reference offset.
++myNumDBSnpSkips;
示例5: 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);
//.........这里部分代码省略.........
示例6: 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');
//.........这里部分代码省略.........
示例7: execute
//.........这里部分代码省略.........
else
{
// ignore strand, treating forward & reverse strands the same
fprintf(stderr,"\t#Bases to trim from the left of reverse strands : %d\n",
numTrimBaseL);
fprintf(stderr,"\t#Bases to trim from the right of reverse strands : %d\n",
numTrimBaseR);
}
}
// Read the sam header.
SamFileHeader samHeader;
if(!samIn.ReadHeader(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());
}
SamRecord samRecord;
char seq[65536];
char qual[65536];
int i, len;
// 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,
示例8: 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)
{
//.........这里部分代码省略.........