本文整理汇总了C++中SamFileHeader::getReferenceInfo方法的典型用法代码示例。如果您正苦于以下问题:C++ SamFileHeader::getReferenceInfo方法的具体用法?C++ SamFileHeader::getReferenceInfo怎么用?C++ SamFileHeader::getReferenceInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SamFileHeader
的用法示例。
在下文中一共展示了SamFileHeader::getReferenceInfo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: writeHeader
bool BamInterface::writeHeader(IFILE filePtr, SamFileHeader& header,
SamStatus& status)
{
if((filePtr == NULL) || (filePtr->isOpen() == false))
{
// File is not open, return false.
status.setStatus(SamStatus::FAIL_ORDER,
"Cannot write header since the file pointer is null");
return(false);
}
char magic[4];
magic[0] = 'B';
magic[1] = 'A';
magic[2] = 'M';
magic[3] = 1;
// Write magic to the file.
ifwrite(filePtr, magic, 4);
////////////////////////////////
// Write the header to the file.
////////////////////////////////
// Construct a string containing the entire header.
std::string headerString = "";
header.getHeaderString(headerString);
int32_t headerLen = headerString.length();
int numWrite = 0;
// Write the header length.
numWrite = ifwrite(filePtr, &headerLen, sizeof(int32_t));
if(numWrite != sizeof(int32_t))
{
status.setStatus(SamStatus::FAIL_IO,
"Failed to write the BAM header length.");
return(false);
}
// Write the header to the file.
numWrite = ifwrite(filePtr, headerString.c_str(), headerLen);
if(numWrite != headerLen)
{
status.setStatus(SamStatus::FAIL_IO,
"Failed to write the BAM header.");
return(false);
}
////////////////////////////////////////////////////////
// Write the Reference Information.
const SamReferenceInfo& refInfo = header.getReferenceInfo();
// Get the number of sequences.
int32_t numSeq = refInfo.getNumEntries();
ifwrite(filePtr, &numSeq, sizeof(int32_t));
// Write each reference sequence
for (int i = 0; i < numSeq; i++)
{
const char* refName = refInfo.getReferenceName(i);
// Add one for the null value.
int32_t nameLength = strlen(refName) + 1;
// Write the length of the reference name.
ifwrite(filePtr, &nameLength, sizeof(int32_t));
// Write the name.
ifwrite(filePtr, refName, nameLength);
// Write the length of the reference sequence.
int32_t refLen = refInfo.getReferenceLength(i);
ifwrite(filePtr, &refLen, sizeof(int32_t));
}
return(true);
}
示例2: execute
//.........这里部分代码省略.........
// read each BAM file and its header,
// making sure that the headers are identical
std::string firstHeaderNoRGPG = "";
std::string headerNoRGPG = "";
SamFileHeader newHeader;
std::string firstHeaderString = "";
for(uint32_t i=0; i < n_bams; ++i)
{
if ( ! p_in_bams[i].OpenForRead(vs_in_bam_files[i].c_str()) )
{
Logger::gLogger->error("Cannot open BAM file %s for reading",vs_in_bam_files[i].c_str());
}
p_in_bams[i].setSortedValidation(SamFile::COORDINATE);
p_in_bams[i].ReadHeader(p_headers[i]);
// Extract the RGs from this header.
if(i == 0)
{
// First header, so store it as the first header
newHeader = p_headers[i];
// Determine the header without RG.
parseOutRG(p_headers[i], firstHeaderNoRGPG, NULL);
}
else
{
parseOutRG(p_headers[i], headerNoRGPG, &newHeader);
if(firstHeaderNoRGPG != headerNoRGPG)
{
Logger::gLogger->error("The headers are not identical at index %d",i);
}
if(newHeader.getReferenceInfo() != p_headers[i].getReferenceInfo())
{
Logger::gLogger->error("The headers are not identical at index %d",i);
}
}
}
// first header will be the new header to be written to output
// adding all possible readGroups to the new header
for(uint32_t i=0; i < v_uniq_readgroups.size(); ++i)
{
addReadGroupToHeader(newHeader, v_uniq_readgroups[i]);
}
// Write an output file with new headers
SamFile bam_out;
if ( !bam_out.OpenForWrite(s_out.c_str()) )
{
Logger::gLogger->error("Cannot open BAM file %s for writing",s_out.c_str());
}
bam_out.setSortedValidation(SamFile::COORDINATE);
bam_out.WriteHeader(newHeader);
// create SamRecords and GenomicCoordinates for each input BAM file
SamRecord* p_records = new SamRecord[n_bams];
uint64_t* p_gcoordinates = new uint64_t[n_bams];
// read the first record for every input BAM file
for(uint32_t i=0; i < n_bams; ++i) {
if ( p_in_bams[i].ReadRecord(p_headers[i],p_records[i]) ) {
if ( p_records[i].isValid(p_headers[i]) ) {
p_gcoordinates[i] = getGenomicCoordinate(p_records[i]);
}
示例3: execute
//.........这里部分代码省略.........
// Read the sam header.
SamFileHeader samHeader;
if(!samIn.ReadHeader(samHeader))
{
fprintf(stderr, "%s\n", samIn.GetStatusMessage());
return(samIn.GetStatus());
}
// Open the bam index file for reading if we are
// doing unmapped reads (also set the read section).
if(useIndex)
{
samIn.ReadBamIndex(indexFile);
if(unmapped)
{
samIn.SetReadSection(-1);
}
if(!regionList.IsEmpty())
{
myRegionList = ifopen(regionList, "r");
}
}
//////////////////////////
// Read dbsnp if specified and doing baseQC
if(((baseQCPtr != NULL) || baseSum) && (!dbsnp.IsEmpty()))
{
// Read the dbsnp file.
IFILE fdbSnp;
fdbSnp = ifopen(dbsnp,"r");
// Determine how many entries.
const SamReferenceInfo& refInfo = samHeader.getReferenceInfo();
int maxRefLen = 0;
for(int i = 0; i < refInfo.getNumEntries(); i++)
{
int refLen = refInfo.getReferenceLength(i);
if(refLen >= maxRefLen)
{
maxRefLen = refLen + 1;
}
}
dbsnpListPtr = new PosList(refInfo.getNumEntries(),maxRefLen);
if(fdbSnp==NULL)
{
std::cerr << "Open dbSNP file " << dbsnp.c_str() << " failed!\n";
}
else if(dbsnpListPtr == NULL)
{
std::cerr << "Failed to init the memory allocation for the dbsnpList.\n";
}
else
{
// Read the dbsnp file.
StringArray tokens;
String buffer;
int position = 0;
int refID = 0;
// Loop til the end of the file.
while (!ifeof(fdbSnp))
{
// Read the next line.
示例4: 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;
//.........这里部分代码省略.........