本文整理汇总了C++中SamRecord::getReferenceName方法的典型用法代码示例。如果您正苦于以下问题:C++ SamRecord::getReferenceName方法的具体用法?C++ SamRecord::getReferenceName怎么用?C++ SamRecord::getReferenceName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SamRecord
的用法示例。
在下文中一共展示了SamRecord::getReferenceName方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: verify
bool Demux::verify(){ //at least one decoy should be present
BamReader bamReader(bamFilePath);
SamRecord samRecord;
int verifiedDecoys = 0;
while ( bamReader.getNextRecord(samRecord)) {
string recordName(samRecord.getReadName());
recordName = cHandler.decrypt(recordName);
//clean record name
int len=recordName.find("$");
recordName=recordName.substr(0,len);
//clean ended
if (isDecoy(recordName)){
char decoyChromosome[2][20];
int decoyLocation[2];
int decoyJobID;
sscanf( recordName.c_str(),"DECOY.%[^.].%d_%[^.].%d.%d",
decoyChromosome[0], decoyLocation,
decoyChromosome[1], decoyLocation + 1, &decoyJobID);
int pair = !SamFlag::isFirstFragment(samRecord.getFlag());
if (strcmp(decoyChromosome[pair],samRecord.getReferenceName())){
cout << "Chromosome mismatch\n";
cout << "Expected: " << decoyChromosome[pair] << endl;
cout << "Got: " << samRecord.getReferenceName() << endl;
return false;
}
if ( decoyLocation[pair] != samRecord.get0BasedPosition()){
cout << "Position mismatch\n";
cout << "Expected: " << decoyLocation[pair] << endl;
cout << "Got: " << samRecord.get0BasedPosition() << endl;
return false;
}
if (decoyJobID != jobID){
cout << "Job ID mismatch\n";
cout << "Expected: " << decoyJobID << endl;
cout << "Got: " << jobID << endl;
return false;
}
verifiedDecoys++;
}
}
if (verifiedDecoys)
return true;
else
return false;
}
示例2: CalcClusters
void GenomeRegionSeqStats::CalcClusters(String &bamFile, int minMapQuality)
{
SamFile sam;
SamRecord samRecord;
SamFileHeader samHeader;
if(!sam.OpenForRead(bamFile.c_str()))
error("Open BAM file %s failed!\n", bamFile.c_str());
if(!sam.ReadHeader(samHeader)) {
error("Read BAM file header %s failed!\n", bamFile.c_str());
}
if(depth.size()==0) depth.resize(referencegenome.sequenceLength());
String contigLabel;
uint32_t start;
uint32_t gstart;
Reset();
while(sam.ReadRecord(samHeader, samRecord))
{
nReads++;
if(samRecord.getFlag() & SamFlag::UNMAPPED) nUnMapped++;
if(samRecord.getMapQuality() < minMapQuality) continue;
CigarRoller cigar(samRecord.getCigar());
int nonClipSequence = 0;
if(cigar.size()!=0 && cigar[0].operation==Cigar::softClip)
nonClipSequence = cigar[0].count;
contigLabel = samRecord.getReferenceName();
start = nonClipSequence + samRecord.get0BasedPosition(); // start is 0-based
gstart = referencegenome.getGenomePosition(contigLabel.c_str(), start);
if(IsInRegions(contigLabel, start, start+samRecord.getReadLength())) continue;
for(uint32_t i=gstart; i<gstart+samRecord.getReadLength(); i++)
if(depth[i]<MAXDP)
depth[i]++;
nMappedOutTargets++;
}
}
示例3: CalcRegionStats
void GenomeRegionSeqStats::CalcRegionStats(String &bamFile)
{
SamFile sam;
SamRecord samRecord;
SamFileHeader samHeader;
if(!sam.OpenForRead(bamFile.c_str()))
error("Open BAM file %s failed!\n", bamFile.c_str());
if(!sam.ReadHeader(samHeader)) {
error("Read BAM file header %s failed!\n", bamFile.c_str());
}
String contigLabel;
int start, end;
Reset();
while(sam.ReadRecord(samHeader, samRecord))
{
nReads++;
if(samRecord.getFlag() & SamFlag::UNMAPPED) nUnMapped++;
if(contigFinishedCnt>=contigs.size()) continue;
CigarRoller cigar(samRecord.getCigar());
int nonClipSequence = 0;
if(cigar.size()!=0 && cigar[0].operation==Cigar::softClip)
nonClipSequence = cigar[0].count;
contigLabel = samRecord.getReferenceName();
start = nonClipSequence + samRecord.get0BasedPosition(); // start is 0-based
end = start + samRecord.getReadLength() - 1;
if(UpdateRegionStats(contigLabel, start, end)) nMapped2Targets++;
}
CalcRegionReadCountInGCBins();
CalcGroupReadCountInGCBins();
std::cout << "Total reads : " << nReads << std::endl;
}
示例4: 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)
//.........这里部分代码省略.........
示例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: processFile
int GapInfo::processFile(const char* inputFileName, const char* outputFileName,
const char* refFile, bool detailed,
bool checkFirst, bool checkStrand)
{
// Open the file for reading.
SamFile samIn;
samIn.OpenForRead(inputFileName);
// Read the sam header.
SamFileHeader samHeader;
samIn.ReadHeader(samHeader);
SamRecord samRecord;
GenomeSequence* refPtr = NULL;
if(strcmp(refFile, "") != 0)
{
refPtr = new GenomeSequence(refFile);
}
IFILE outFile = ifopen(outputFileName, "w");
// Map for summary.
std::map<int, int> gapInfoMap;
// Keep reading records until ReadRecord returns false.
while(samIn.ReadRecord(samHeader, samRecord))
{
uint16_t samFlags = samRecord.getFlag();
if((!SamFlag::isMapped(samFlags)) ||
(!SamFlag::isMateMapped(samFlags)) ||
(!SamFlag::isPaired(samFlags)) ||
(samFlags & SamFlag::SECONDARY_ALIGNMENT) ||
(SamFlag::isDuplicate(samFlags)) ||
(SamFlag::isQCFailure(samFlags)))
{
// unmapped, mate unmapped, not paired,
// not the primary alignment,
// duplicate, fails vendor quality check
continue;
}
// No gap info if the chromosome names are different or
// are unknown.
int32_t refID = samRecord.getReferenceID();
if((refID != samRecord.getMateReferenceID()) || (refID == -1))
{
continue;
}
int32_t readStart = samRecord.get0BasedPosition();
int32_t mateStart = samRecord.get0BasedMatePosition();
// If the mate starts first, then the pair was processed by
// the mate.
if(mateStart < readStart)
{
continue;
}
if((mateStart == readStart) && (SamFlag::isReverse(samFlags)))
{
// read and mate start at the same position, so
// only process the forward strand.
continue;
}
// Process this read pair.
int32_t readEnd = samRecord.get0BasedAlignmentEnd();
int32_t gapSize = mateStart - readEnd - 1;
if(detailed)
{
// Output the gap info.
ifprintf(outFile, "%s\t%d\t%d",
samRecord.getReferenceName(), readEnd+1, gapSize);
// Check if it is not the first or if it is not the forward strand.
if(checkFirst && !SamFlag::isFirstFragment(samFlags))
{
ifprintf(outFile, "\tNotFirst");
}
if(checkStrand && SamFlag::isReverse(samFlags))
{
ifprintf(outFile, "\tReverse");
}
ifprintf(outFile, "\n");
}
else
{
// Summary.
// Skip reads that are not the forward strand.
if(SamFlag::isReverse(samFlags))
{
// continue
continue;
}
//.........这里部分代码省略.........
示例8: execute
// Dump the reference information from specified SAM/BAM file.
int DumpRefInfo::execute(int argc, char **argv)
{
// Extract command line arguments.
String inFile = "";
bool noeof = false;
bool printRecordRefs = false;
bool params = false;
ParameterList inputParameters;
BEGIN_LONG_PARAMETERS(longParameterList)
LONG_STRINGPARAMETER("in", &inFile)
LONG_PARAMETER("noeof", &noeof)
LONG_PARAMETER("printRecordRefs", &printRecordRefs)
LONG_PARAMETER("params", ¶ms)
LONG_PHONEHOME(VERSION)
END_LONG_PARAMETERS();
inputParameters.Add(new LongParameters ("Input Parameters",
longParameterList));
// parameters start at index 2 rather than 1.
inputParameters.Read(argc, argv, 2);
// If no eof block is required for a bgzf file, set the bgzf file type to
// not look for it.
if(noeof)
{
// Set that the eof block is not required.
BgzfFileType::setRequireEofBlock(false);
}
// Check to see if the in file was specified, if not, report an error.
if(inFile == "")
{
usage();
inputParameters.Status();
// In file was not specified but it is mandatory.
std::cerr << "--in 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);
// Read the sam header.
SamFileHeader samHeader;
samIn.ReadHeader(samHeader);
const SamReferenceInfo& refInfo = samHeader.getReferenceInfo();
int numReferences = refInfo.getNumEntries();
for(int i = 0; i < numReferences; i++)
{
std::cout << "Reference Index " << i;
std::cout << "; Name: " << refInfo.getReferenceName(i)
<< std::endl;
}
if(numReferences == 0)
{
// There is no reference info.
std::cerr << "The header contains no reference information.\n";
}
// If we are to print the references as found in the records, loop
// through reading the records.
if(printRecordRefs)
{
SamRecord samRecord;
// Track the prev name/id.
std::string prevName = "";
int prevID = -2;
int recCount = 0; // track the num records in a ref.
// Keep reading records until ReadRecord returns false.
while(samIn.ReadRecord(samHeader, samRecord))
{
const char* name = samRecord.getReferenceName();
int id = samRecord.getReferenceID();
if((strcmp(name, prevName.c_str()) != 0) || (id != prevID))
{
if(prevID != -2)
{
std::cout << "\tRef ID: " << prevID
<< "\tRef Name: " << prevName
<< "\tNumRecs: " << recCount
<< std::endl;
}
recCount = 0;
prevID = id;
prevName = name;
}
++recCount;
//.........这里部分代码省略.........