本文整理汇总了C++中BamWriter::Close方法的典型用法代码示例。如果您正苦于以下问题:C++ BamWriter::Close方法的具体用法?C++ BamWriter::Close怎么用?C++ BamWriter::Close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BamWriter
的用法示例。
在下文中一共展示了BamWriter::Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
bool RevertTool::RevertToolPrivate::Run(void) {
// opens the BAM file without checking for indexes
BamReader reader;
if ( !reader.Open(m_settings->InputFilename) ) {
cerr << "Could not open input BAM file... quitting." << endl;
return false;
}
// get BAM file metadata
const string& headerText = reader.GetHeaderText();
const RefVector& references = reader.GetReferenceData();
// open writer
BamWriter writer;
bool writeUncompressed = ( m_settings->OutputFilename == Options::StandardOut() && !m_settings->IsForceCompression );
if ( !writer.Open(m_settings->OutputFilename, headerText, references, writeUncompressed) ) {
cerr << "Could not open " << m_settings->OutputFilename << " for writing." << endl;
return false;
}
// plow through file, reverting alignments
BamAlignment al;
while ( reader.GetNextAlignment(al) ) {
RevertAlignment(al);
writer.SaveAlignment(al);
}
// clean and exit
reader.Close();
writer.Close();
return true;
}
示例2: IntersectBamPE
void BedIntersectPE::IntersectBamPE(string bamFile) {
// load the "B" bed file into a map so
// that we can easily compare "A" to it for overlaps
_bedB->loadBedFileIntoMap();
// open the BAM file
BamReader reader;
BamWriter writer;
reader.Open(bamFile);
// get header & reference information
string bamHeader = reader.GetHeaderText();
RefVector refs = reader.GetReferenceData();
// open a BAM output to stdout if we are writing BAM
if (_bamOutput == true) {
// set compression mode
BamWriter::CompressionMode compressionMode = BamWriter::Compressed;
if ( _isUncompressedBam ) compressionMode = BamWriter::Uncompressed;
writer.SetCompressionMode(compressionMode);
// open our BAM writer
writer.Open("stdout", bamHeader, refs);
}
// track the previous and current sequence
// names so that we can identify blocks of
// alignments for a given read ID.
string prevName, currName;
prevName = currName = "";
vector<BamAlignment> alignments; // vector of BAM alignments for a given ID in a BAM file.
alignments.reserve(100);
_bedA->bedType = 10; // it's a full BEDPE given it's BAM
// rip through the BAM file and convert each mapped entry to BEDPE
BamAlignment bam1, bam2;
while (reader.GetNextAlignment(bam1)) {
// the alignment must be paired
if (bam1.IsPaired() == true) {
// grab the second alignment for the pair.
reader.GetNextAlignment(bam2);
// require that the alignments are from the same query
if (bam1.Name == bam2.Name) {
ProcessBamBlock(bam1, bam2, refs, writer);
}
else {
cerr << "*****ERROR: -bedpe requires BAM to be sorted or grouped by query name. " << endl;
exit(1);
}
}
}
// close up
reader.Close();
if (_bamOutput == true) {
writer.Close();
}
}
示例3: main
int main (int argc, char *argv[]) {
if( (argc== 1) ||
(argc== 2 && string(argv[1]) == "-h") ||
(argc== 2 && string(argv[1]) == "-help") ||
(argc== 2 && string(argv[1]) == "--help") ){
cout<<"Usage:setAsUnpaired [in bam] [outbam]"<<endl<<"this program takes flags all paired sequences as singles"<<endl;
return 1;
}
string bamfiletopen = string(argv[1]);
string bamFileOUT = string(argv[2]);
BamReader reader;
BamWriter writer;
if ( !reader.Open(bamfiletopen) ) {
cerr << "Could not open input BAM files." << endl;
return 1;
}
const SamHeader header = reader.GetHeader();
const RefVector references = reader.GetReferenceData();
if ( !writer.Open(bamFileOUT,header,references) ) {
cerr << "Could not open output BAM file "<<bamFileOUT << endl;
return 1;
}
BamAlignment al;
while ( reader.GetNextAlignment(al) ) {
if(al.IsMapped()){
cerr << "Cannot yet handle mapped reads " << endl;
return 1;
}
al.SetIsPaired (false);
writer.SaveAlignment(al);
} //while al
reader.Close();
writer.Close();
return 0;
}
示例4: while
// merges sorted temp BAM files into single sorted output BAM file
bool SortTool::SortToolPrivate::MergeSortedRuns(void) {
// open up multi reader for all of our temp files
// this might get broken up if we do a multi-pass system later ??
BamMultiReader multiReader;
if ( !multiReader.Open(m_tempFilenames) ) {
cerr << "bamtools sort ERROR: could not open BamMultiReader for merging temp files... Aborting."
<< endl;
return false;
}
// set sort order for merge
if ( m_settings->IsSortingByName )
multiReader.SetSortOrder(BamMultiReader::SortedByReadName);
else
multiReader.SetSortOrder(BamMultiReader::SortedByPosition);
// open writer for our completely sorted output BAM file
BamWriter mergedWriter;
if ( !mergedWriter.Open(m_settings->OutputBamFilename, m_headerText, m_references) ) {
cerr << "bamtools sort ERROR: could not open " << m_settings->OutputBamFilename
<< " for writing... Aborting." << endl;
multiReader.Close();
return false;
}
// while data available in temp files
BamAlignment al;
while ( multiReader.GetNextAlignmentCore(al) )
mergedWriter.SaveAlignment(al);
// close readers
multiReader.Close();
mergedWriter.Close();
// delete all temp files
vector<string>::const_iterator tempIter = m_tempFilenames.begin();
vector<string>::const_iterator tempEnd = m_tempFilenames.end();
for ( ; tempIter != tempEnd; ++tempIter ) {
const string& tempFilename = (*tempIter);
remove(tempFilename.c_str());
}
return true;
}
示例5:
bool SortTool::SortToolPrivate::WriteTempFile(const vector<BamAlignment>& buffer,
const string& tempFilename)
{
// open temp file for writing
BamWriter tempWriter;
if ( !tempWriter.Open(tempFilename, m_headerText, m_references) ) {
cerr << "bamtools sort ERROR: could not open " << tempFilename
<< " for writing." << endl;
return false;
}
// write data
vector<BamAlignment>::const_iterator buffIter = buffer.begin();
vector<BamAlignment>::const_iterator buffEnd = buffer.end();
for ( ; buffIter != buffEnd; ++buffIter ) {
const BamAlignment& al = (*buffIter);
tempWriter.SaveAlignment(al);
}
// close temp file & return success
tempWriter.Close();
return true;
}
示例6: while
bool CompressTool::CompressToolPrivate::Run(void) {
// ------------------------------------
// initialize conversion input/output
// set to default input if none provided
if ( !m_settings->HasInput )
m_settings->InputFilename = Options::StandardIn();
if ( !m_settings->HasOutput )
m_settings->InputFilename = Options::StandardOut();
SamReader reader;
reader.Open(m_settings->InputFilename);
BamWriter writer;
writer.Open( m_settings->OutputFilename, reader.GetHeader(), reader.GetReferenceData());
int alignment_ct = 0;
while(true) {
BamAlignment alignment;
if(!reader.GetNextAlignment(alignment))
break;
writer.SaveAlignment(alignment);
alignment_ct++;
//progress indicator
//if(alignment_ct % 500000 == 0)
// cerr << ".";
}
reader.Close();
writer.Close();
return true;
}
示例7: filelist
bool FilterTool::FilterToolPrivate::Run(void) {
// set to default input if none provided
if ( !m_settings->HasInput && !m_settings->HasInputFilelist )
m_settings->InputFiles.push_back(Options::StandardIn());
// add files in the filelist to the input file list
if ( m_settings->HasInputFilelist ) {
ifstream filelist(m_settings->InputFilelist.c_str(), ios::in);
if ( !filelist.is_open() ) {
cerr << "bamtools filter ERROR: could not open input BAM file list... Aborting." << endl;
return false;
}
string line;
while ( getline(filelist, line) )
m_settings->InputFiles.push_back(line);
}
// initialize defined properties & user-specified filters
// quit if failed
if ( !SetupFilters() )
return false;
// open reader without index
BamMultiReader reader;
if ( !reader.Open(m_settings->InputFiles) ) {
cerr << "bamtools filter ERROR: could not open input files for reading." << endl;
return false;
}
// retrieve reader header & reference data
const string headerText = reader.GetHeaderText();
filterToolReferences = reader.GetReferenceData();
// determine compression mode for BamWriter
bool writeUncompressed = ( m_settings->OutputFilename == Options::StandardOut() &&
!m_settings->IsForceCompression );
BamWriter::CompressionMode compressionMode = BamWriter::Compressed;
if ( writeUncompressed ) compressionMode = BamWriter::Uncompressed;
// open BamWriter
BamWriter writer;
writer.SetCompressionMode(compressionMode);
if ( !writer.Open(m_settings->OutputFilename, headerText, filterToolReferences) ) {
cerr << "bamtools filter ERROR: could not open " << m_settings->OutputFilename << " for writing." << endl;
reader.Close();
return false;
}
// if no region specified, filter entire file
BamAlignment al;
if ( !m_settings->HasRegion ) {
while ( reader.GetNextAlignment(al) ) {
if ( CheckAlignment(al) )
writer.SaveAlignment(al);
}
}
// otherwise attempt to use region as constraint
else {
// if region string parses OK
BamRegion region;
if ( Utilities::ParseRegionString(m_settings->Region, reader, region) ) {
// attempt to find index files
reader.LocateIndexes();
// if index data available for all BAM files, we can use SetRegion
if ( reader.HasIndexes() ) {
// attempt to use SetRegion(), if failed report error
if ( !reader.SetRegion(region.LeftRefID, region.LeftPosition, region.RightRefID, region.RightPosition) ) {
cerr << "bamtools filter ERROR: set region failed. Check that REGION describes a valid range" << endl;
reader.Close();
return false;
}
// everything checks out, just iterate through specified region, filtering alignments
while ( reader.GetNextAlignment(al) )
if ( CheckAlignment(al) )
writer.SaveAlignment(al);
}
// no index data available, we have to iterate through until we
// find overlapping alignments
else {
while ( reader.GetNextAlignment(al) ) {
if ( (al.RefID >= region.LeftRefID) && ((al.Position + al.Length) >= region.LeftPosition) &&
(al.RefID <= region.RightRefID) && ( al.Position <= region.RightPosition) )
{
if ( CheckAlignment(al) )
writer.SaveAlignment(al);
}
}
}
}
//.........这里部分代码省略.........
示例8: Tag
void TagBam::Tag() {
// open the annotations files for processing;
OpenAnnoFiles();
// open the BAM file
BamReader reader;
BamWriter writer;
if (!reader.Open(_bamFile)) {
cerr << "Failed to open BAM file " << _bamFile << endl;
exit(1);
}
// get header & reference information
string bamHeader = reader.GetHeaderText();
RefVector refs = reader.GetReferenceData();
// set compression mode
BamWriter::CompressionMode compressionMode = BamWriter::Compressed;
// if ( _isUncompressedBam ) compressionMode = BamWriter::Uncompressed;
writer.SetCompressionMode(compressionMode);
// open our BAM writer
writer.Open("stdout", bamHeader, refs);
// rip through the BAM file and test for overlaps with each annotation file.
BamAlignment al;
vector<BED> hits;
while (reader.GetNextAlignment(al)) {
if (al.IsMapped() == true) {
BED a;
a.chrom = refs.at(al.RefID).RefName;
a.start = al.Position;
a.end = al.GetEndPosition(false, false);
a.strand = "+";
if (al.IsReverseStrand()) a.strand = "-";
ostringstream annotations;
// annotate the BAM file based on overlaps with the annotation files.
for (size_t i = 0; i < _annoFiles.size(); ++i)
{
// grab the current annotation file.
BedFile *anno = _annoFiles[i];
if (!_useNames && !_useScores && !_useIntervals) {
// add the label for this annotation file to tag if there is overlap
if (anno->anyHits(a.chrom, a.start, a.end, a.strand,
_sameStrand, _diffStrand, _overlapFraction, false))
{
annotations << _annoLabels[i] << ";";
}
}
// use the score field
else if (!_useNames && _useScores && !_useIntervals) {
anno->allHits(a.chrom, a.start, a.end, a.strand,
hits, _sameStrand, _diffStrand, 0.0, false);
for (size_t i = 0; i < hits.size(); ++i) {
annotations << hits[i].score;
if (i < hits.size() - 1) annotations << ",";
}
if (hits.size() > 0) annotations << ";";
hits.clear();
}
// use the name field from the annotation files to populate tag
else if (_useNames && !_useScores && !_useIntervals) {
anno->allHits(a.chrom, a.start, a.end, a.strand,
hits, _sameStrand, _diffStrand, 0.0, false);
for (size_t j = 0; j < hits.size(); ++j) {
annotations << hits[j].name;
if (j < hits.size() - 1) annotations << ",";
}
if (hits.size() > 0) annotations << ";";
hits.clear();
}
// use the full interval information annotation files to populate tag
else if (!_useNames && !_useScores && _useIntervals) {
anno->allHits(a.chrom, a.start, a.end, a.strand,
hits, _sameStrand, _diffStrand, 0.0, false);
for (size_t j = 0; j < hits.size(); ++j) {
annotations << _annoLabels[i] << ":" <<
hits[j].chrom << ":" <<
hits[j].start << "-" <<
hits[j].end << "," <<
hits[j].name << "," <<
hits[j].score << "," <<
hits[j].strand;
if (j < hits.size() - 1) annotations << ",";
}
if (hits.size() > 0) annotations << ";";
hits.clear();
}
}
// were there any overlaps with which to make a tag?
if (annotations.str().size() > 0) {
al.AddTag(_tag, "Z", annotations.str().substr(0, annotations.str().size() - 1)); // get rid of the last ";"
}
}
writer.SaveAlignment(al);
}
reader.Close();
//.........这里部分代码省略.........
示例9: main
//.........这里部分代码省略.........
BamAlignment bam_alignment;
bam_alignment.SetIsMapped(false);
bam_alignment.Name = sff->rheader->name->s;
nBases = sff->rheader->n_bases + 1 - sff->rheader->clip_qual_left;
if(sff->rheader->clip_qual_right > 0)
{
nBases = sff->rheader->clip_qual_right - sff->rheader->clip_qual_left;
}
if(nBases > 0)
{
bam_alignment.QueryBases.reserve(nBases);
bam_alignment.Qualities.reserve(nBases);
for (int base = sff->rheader->clip_qual_left - 1; base < sff->rheader->clip_qual_right - 1; ++base)
{
bam_alignment.QueryBases.push_back(sff->read->bases->s[base]);
bam_alignment.Qualities.push_back(sff->read->quality->s[base] + 33);
}
}
clip_flow = 0;
for (unsigned int base = 0; base <= sff->rheader->clip_qual_left && base < sff->rheader->n_bases; ++base)
{
clip_flow += sff->read->flow_index[base];
}
if (clip_flow > 0)
{
clip_flow--;
}
bam_alignment.AddTag("RG","Z", rgname);
bam_alignment.AddTag("PG","Z", string("sff2bam"));
bam_alignment.AddTag("ZF","i", clip_flow); // TODO: trim flow
vector<uint16_t> flowgram(sff->gheader->flow_length);
copy(sff->read->flowgram, sff->read->flowgram + sff->gheader->flow_length, flowgram.begin());
bam_alignment.AddTag("FZ", flowgram);
sff_destroy(sff);
sff = NULL;
bamWriter.SaveAlignment(bam_alignment);
}
sff_fclose(sff_file);
if(combineSffs && infiles.size() > 1)
{
for(size_t n = 1; n < infiles.size(); ++n)
{
sff_file_t* sff_file2 = sff_fopen(infiles[n].c_str(), "r", NULL, NULL);
while(NULL != (sff = sff_read(sff_file2)))
{
BamAlignment bam_alignment;
bam_alignment.SetIsMapped(false);
bam_alignment.Name = sff->rheader->name->s;
nBases = sff->rheader->n_bases + 1 - sff->rheader->clip_qual_left;
if(sff->rheader->clip_qual_right > 0)
{
nBases = sff->rheader->clip_qual_right - sff->rheader->clip_qual_left;
}
if(nBases > 0)
{
bam_alignment.QueryBases.reserve(nBases);
bam_alignment.Qualities.reserve(nBases);
for (int base = sff->rheader->clip_qual_left - 1; base < sff->rheader->clip_qual_right - 1; ++base)
{
bam_alignment.QueryBases.push_back(sff->read->bases->s[base]);
bam_alignment.Qualities.push_back(sff->read->quality->s[base] + 33);
}
}
clip_flow = 0;
for (unsigned int base = 0; base <= sff->rheader->clip_qual_left && base < sff->rheader->n_bases; ++base)
{
clip_flow += sff->read->flow_index[base];
}
if (clip_flow > 0)
{
clip_flow--;
}
bam_alignment.AddTag("RG","Z", rgname);
bam_alignment.AddTag("PG","Z", string("sff2bam"));
bam_alignment.AddTag("ZF","i", clip_flow); // TODO: trim flow
vector<uint16_t> flowgram(sff->gheader->flow_length);
copy(sff->read->flowgram, sff->read->flowgram + sff->gheader->flow_length, flowgram.begin());
bam_alignment.AddTag("FZ", flowgram);
sff_destroy(sff);
sff = NULL;
bamWriter.SaveAlignment(bam_alignment);
}
sff_fclose(sff_file2);
}
}
bamWriter.Close();
return 0;
}
示例10: file
bool MergeTool::MergeToolPrivate::Run(void) {
// set to default input if none provided
if ( !m_settings->HasInputBamFilename )
m_settings->InputFiles.push_back(Options::StandardIn());
// opens the BAM files (by default without checking for indexes)
BamMultiReader reader;
if ( !reader.Open(m_settings->InputFiles) ) {
cerr << "bamtools merge ERROR: could not open input BAM file(s)... Aborting." << endl;
return false;
}
// retrieve header & reference dictionary info
std::string mergedHeader = reader.GetHeaderText();
RefVector references = reader.GetReferenceData();
// determine compression mode for BamWriter
bool writeUncompressed = ( m_settings->OutputFilename == Options::StandardOut() &&
!m_settings->IsForceCompression );
BamWriter::CompressionMode compressionMode = BamWriter::Compressed;
if ( writeUncompressed ) compressionMode = BamWriter::Uncompressed;
// open BamWriter
BamWriter writer;
writer.SetCompressionMode(compressionMode);
if ( !writer.Open(m_settings->OutputFilename, mergedHeader, references) ) {
cerr << "bamtools merge ERROR: could not open "
<< m_settings->OutputFilename << " for writing." << endl;
reader.Close();
return false;
}
// if no region specified, store entire contents of file(s)
if ( !m_settings->HasRegion ) {
BamAlignment al;
while ( reader.GetNextAlignmentCore(al) )
writer.SaveAlignment(al);
}
// otherwise attempt to use region as constraint
else {
// if region string parses OK
BamRegion region;
if ( Utilities::ParseRegionString(m_settings->Region, reader, region) ) {
// attempt to find index files
reader.LocateIndexes();
// if index data available for all BAM files, we can use SetRegion
if ( reader.HasIndexes() ) {
// attempt to use SetRegion(), if failed report error
if ( !reader.SetRegion(region.LeftRefID,
region.LeftPosition,
region.RightRefID,
region.RightPosition) )
{
cerr << "bamtools merge ERROR: set region failed. Check that REGION describes a valid range"
<< endl;
reader.Close();
return false;
}
// everything checks out, just iterate through specified region, storing alignments
BamAlignment al;
while ( reader.GetNextAlignmentCore(al) )
writer.SaveAlignment(al);
}
// no index data available, we have to iterate through until we
// find overlapping alignments
else {
BamAlignment al;
while ( reader.GetNextAlignmentCore(al) ) {
if ( (al.RefID >= region.LeftRefID) && ( (al.Position + al.Length) >= region.LeftPosition ) &&
(al.RefID <= region.RightRefID) && ( al.Position <= region.RightPosition) )
{
writer.SaveAlignment(al);
}
}
}
}
// error parsing REGION string
else {
cerr << "bamtools merge ERROR: could not parse REGION - " << m_settings->Region << endl;
cerr << "Check that REGION is in valid format (see documentation) and that the coordinates are valid"
<< endl;
reader.Close();
writer.Close();
return false;
}
}
// clean & exit
reader.Close();
writer.Close();
return true;
//.........这里部分代码省略.........
示例11: main
//.........这里部分代码省略.........
cerr << "Cannot have reverse complemented unmapped reads: " <<al.Name<< endl;
//return 1;
}
int indexToCheck;
//second base
indexToCheck=1;
if(toupper(al.QueryBases[indexToCheck]) == 'A'){
// al.Qualities[indexToCheck]=char(offset+baseQualForDeam);
// cout<<"51 "<<al.QueryBases<<endl;
// cout<<"51 "<<al.Qualities<<endl;
al.QueryBases = al.QueryBases.substr(indexToCheck+1);
al.Qualities = al.Qualities.substr(indexToCheck+1);
// cout<<"52 "<<al.QueryBases<<endl;
// cout<<"52 "<<al.Qualities<<endl;
}else{
//first base
indexToCheck=0;
if(toupper(al.QueryBases[indexToCheck]) == 'A'){
// al.Qualities[indexToCheck]=char(offset+baseQualForDeam);
// cout<<"61 "<<al.QueryBases<<endl;
// cout<<"61 "<<al.Qualities<<endl;
al.QueryBases = al.QueryBases.substr(indexToCheck+1);
al.Qualities = al.Qualities.substr(indexToCheck+1);
// cout<<"62 "<<al.QueryBases<<endl;
// cout<<"62 "<<al.Qualities<<endl;
}
}
//last
indexToCheck=al.QueryBases.length()-1;
if(toupper(al.QueryBases[indexToCheck]) == 'A'){
// al.Qualities[indexToCheck]=char(offset+baseQualForDeam);
// cout<<"21 "<<al.QueryBases<<endl;
// cout<<"21 "<<al.Qualities<<endl;
al.QueryBases = al.QueryBases.substr(0,indexToCheck);
al.Qualities = al.Qualities.substr(0, indexToCheck);
// cout<<"22 "<<al.QueryBases<<endl;
// cout<<"22 "<<al.Qualities<<endl;
}
}else{
int indexToCheck;
//first base
indexToCheck=0;
if(toupper(al.QueryBases[indexToCheck]) == 'T'){
// al.Qualities[indexToCheck]=char(offset+baseQualForDeam);
// cout<<"11 "<<al.QueryBases<<endl;
// cout<<"11 "<<al.Qualities<<endl;
al.QueryBases = al.QueryBases.substr(indexToCheck+1);
al.Qualities = al.Qualities.substr(indexToCheck+1);
// cout<<"12 "<<al.QueryBases<<endl;
// cout<<"12 "<<al.Qualities<<endl;
}
//second to last
indexToCheck=al.QueryBases.length()-2;
if(toupper(al.QueryBases[indexToCheck]) == 'T'){
// al.Qualities[indexToCheck]=char(offset+baseQualForDeam);
// cout<<"31 "<<al.QueryBases<<endl;
// cout<<"31 "<<al.Qualities<<endl;
al.QueryBases = al.QueryBases.substr(0,indexToCheck);
al.Qualities = al.Qualities.substr(0, indexToCheck);
// cout<<"32 "<<al.QueryBases<<endl;
// cout<<"32 "<<al.Qualities<<endl;
}else{
//last
indexToCheck=al.QueryBases.length()-1;
if(toupper(al.QueryBases[indexToCheck]) == 'T'){
// al.Qualities[indexToCheck]=char(offset+baseQualForDeam);
// cout<<"41 "<<al.QueryBases<<endl;
// cout<<"41 "<<al.Qualities<<endl;
al.QueryBases = al.QueryBases.substr(0,indexToCheck);
al.Qualities = al.Qualities.substr(0, indexToCheck);
// cout<<"42 "<<al.QueryBases<<endl;
// cout<<"42 "<<al.Qualities<<endl;
}
}
}
}//end of single end
writer.SaveAlignment(al);
}// while ( reader.GetNextAlignment(al) ) {
reader.Close();
writer.Close();
return 0;
}
示例12: main
//.........这里部分代码省略.........
// if(toprint->getRef()[0] != refeBase){
// cerr<<reconstructedReference<<endl;
// cerr<<al.Position<<endl;
// cerr<<lengthMatches<<endl;
// cerr<<numberOfDeletions(&al)<<endl;
// cerr<<positionJump<<endl;
// cerr<<"Problem5 position "<<*toprint<<" does not have a "<<refeBase<<" as reference allele for read "<<al.Name<<endl;
// exit(1);
// }
// if( toprint->hasAtLeastOneC() &&
// !toprint->hasAtLeastOneT() ){
// isDeaminated=true;
// }
// }
}
//last base next to 3'
i = (al.QueryBases.length()-1);
refeBase=toupper(reconstructedReference[i]);
readBase=toupper( al.QueryBases[i]);
//&& refeBase == 'C'
if( readBase == 'T' && int(al.Qualities[i]-offset) >= minBaseQuality){
if( skipAlign(reconstructedReference,&al,&skipped) ){ continue; }
transformRef(&refeBase,&readBase);
int lengthMatches=countMatchesRecons(reconstructedReference,0);
int positionJump = al.Position+lengthMatches+numberOfDeletions(&al);
if(hasCnoT[positionJump] &&
!thousandGenomesHasT[positionJump] )
isDeaminated=true;
// vcfr.repositionIterator(chrname,positionJump,positionJump);
// while(vcfr.hasData()){
// SimpleVCF * toprint=vcfr.getData();
// //skip deletions in the alt
// if(toprint->getRef().length() != 1 )
// continue;
// if(toprint->getRef()[0] != refeBase){
// cerr<<reconstructedReference<<endl;
// cerr<<al.Position<<endl;
// cerr<<lengthMatches<<endl;
// cerr<<numberOfDeletions(&al)<<endl;
// cerr<<positionJump<<endl;
// cerr<<"Problem6 position "<<*toprint<<" does not have a "<<refeBase<<" as reference allele for read "<<al.Name<<endl;
// exit(1);
// }
// if( toprint->hasAtLeastOneC() &&
// !toprint->hasAtLeastOneT() ){
// isDeaminated=true;
// }
// }
}
}
totalReads++;
if(isDeaminated){
deaminatedReads++;
writerDeam.SaveAlignment(al);
}else{
ndeaminatedReads++;
writerNoDeam.SaveAlignment(al);
}
}//end for each read
reader.Close();
writerDeam.Close();
writerNoDeam.Close();
delete(hasCnoT);
delete(hasGnoA);
cerr<<"Program finished sucessfully, out of "<<totalReads<<" mapped reads (skipped: "<<skipped<<" reads) we flagged "<<deaminatedReads<<" as deaminated and "<<ndeaminatedReads<<" as not deaminated"<<endl;
return 0;
}
示例13: main
//.........这里部分代码省略.........
SimpleVCF * toprint=vcfr.getData();
//skip deletions in the alt
if(toprint->getRef().length() != 1 )
continue;
if(toprint->getRef()[0] != refeBase){
cerr<<reconstructedReference<<endl;
cerr<<al.Position<<endl;
cerr<<lengthMatches<<endl;
cerr<<numberOfDeletions(&al)<<endl;
cerr<<positionJump<<endl;
cerr<<"Problem5 position "<<*toprint<<" does not have a "<<refeBase<<" as reference allele for read "<<al.Name<<endl;
exit(1);
}
if( toprint->hasAtLeastOneC() &&
!toprint->hasAtLeastOneT() ){
isDeaminated=true;
}
}
}
//last base next to 3'
i = (al.QueryBases.length()-1);
refeBase=toupper(reconstructedReference[i]);
readBase=toupper( al.QueryBases[i]);
//&& refeBase == 'C'
if( readBase == 'T' && int(al.Qualities[i]-offset) >= minBaseQuality){
if( skipAlign(reconstructedReference,&al,&skipped) ){ continue; }
transformRef(&refeBase,&readBase);
int lengthMatches=countMatchesRecons(reconstructedReference,0);
int positionJump = al.Position+lengthMatches+numberOfDeletions(&al);
vcfr.repositionIterator(chrname,positionJump,positionJump);
while(vcfr.hasData()){
SimpleVCF * toprint=vcfr.getData();
//skip deletions in the alt
if(toprint->getRef().length() != 1 )
continue;
if(toprint->getRef()[0] != refeBase){
cerr<<reconstructedReference<<endl;
cerr<<al.Position<<endl;
cerr<<lengthMatches<<endl;
cerr<<numberOfDeletions(&al)<<endl;
cerr<<positionJump<<endl;
cerr<<"Problem6 position "<<*toprint<<" does not have a "<<refeBase<<" as reference allele for read "<<al.Name<<endl;
exit(1);
}
if( toprint->hasAtLeastOneC() &&
!toprint->hasAtLeastOneT() ){
isDeaminated=true;
}
}
}
}
totalReads++;
if(isDeaminated){
deaminatedReads++;
writerDeam.SaveAlignment(al);
}else{
ndeaminatedReads++;
writerNoDeam.SaveAlignment(al);
}
}//end for each read
reader.Close();
writerDeam.Close();
writerNoDeam.Close();
cerr<<"Program finished sucessfully, out of "<<totalReads<<" mapped reads (skipped: "<<skipped<<" reads) we flagged "<<deaminatedReads<<" as deaminated and "<<ndeaminatedReads<<" as not deaminated"<<endl;
return 0;
}
示例14: main
//.........这里部分代码省略.........
//3' of second mate reversed
indexToCheck=al.QueryBases.length()-1;
for(int i=0;i<bpToDecrease3;i++){
if(toupper(al.QueryBases[indexToCheck]) == 'T'){
al.Qualities[indexToCheck]=char(offset+baseQualForDeam);
}
indexToCheck=max(indexToCheck-1,0);
}
}else{
int indexToCheck;
//3' of second mate forward
indexToCheck=0;
for(int i=0;i<bpToDecrease3;i++){ //first base
if(toupper(al.QueryBases[indexToCheck]) == 'A'){
al.Qualities[indexToCheck]=char(offset+baseQualForDeam);
}
indexToCheck=min(indexToCheck+1,int(al.Qualities.size()));
}
}
}else{
cerr << "Wrong state" << endl;
return 1;
}
}
}//end of paired end
else{//we consider single reads to have been sequenced from 5' to 3'
if(al.IsReverseStrand()){ //need to consider
if(!al.IsMapped()){
cerr << "Cannot have reverse complemented unmapped reads :" <<al.Name<< endl;
//return 1;
}
int indexToCheck;
//5' of single read reversed
indexToCheck=al.QueryBases.length()-1;
for(int i=0;i<bpToDecrease5;i++){
if(toupper(al.QueryBases[indexToCheck]) == 'A'){
al.Qualities[indexToCheck]=char(offset+baseQualForDeam);
}
indexToCheck=max(indexToCheck-1,0);
}
//3' of single read reversed
indexToCheck=0;
for(int i=0;i<bpToDecrease3;i++){ //first base
if(toupper(al.QueryBases[indexToCheck]) == 'A'){
al.Qualities[indexToCheck]=char(offset+baseQualForDeam);
}
indexToCheck=min(indexToCheck+1,int(al.Qualities.size()));
}
}else{
int indexToCheck;
//5' of single read
indexToCheck=0;
for(int i=0;i<bpToDecrease5;i++){ //first base
if(toupper(al.QueryBases[indexToCheck]) == 'T'){
al.Qualities[indexToCheck]=char(offset+baseQualForDeam);
}
indexToCheck=min(indexToCheck+1,int(al.Qualities.size()));
}
//3' of single read
indexToCheck=al.QueryBases.length()-1;
for(int i=0;i<bpToDecrease3;i++){
if(toupper(al.QueryBases[indexToCheck]) == 'T'){
al.Qualities[indexToCheck]=char(offset+baseQualForDeam);
}
indexToCheck=max(indexToCheck-1,0);
}
}
}//end of single end
writer.SaveAlignment(al);
}// while ( reader.GetNextAlignment(al) ) {
reader.Close();
writer.Close();
cerr<<"Program terminated gracefully"<<endl;
return 0;
}
示例15: Run
int MergeTool::Run(int argc, char* argv[]) {
// parse command line arguments
Options::Parse(argc, argv, 1);
// set to default input if none provided
if ( !m_settings->HasInputBamFilename )
m_settings->InputFiles.push_back(Options::StandardIn());
// opens the BAM files (by default without checking for indexes)
BamMultiReader reader;
if ( !reader.Open(m_settings->InputFiles, false, true) ) {
cerr << "ERROR: Could not open input BAM file(s)... Aborting." << endl;
return 1;
}
// retrieve header & reference dictionary info
std::string mergedHeader = reader.GetHeaderText();
RefVector references = reader.GetReferenceData();
// open writer
BamWriter writer;
bool writeUncompressed = ( m_settings->OutputFilename == Options::StandardOut() && !m_settings->IsForceCompression );
if ( !writer.Open(m_settings->OutputFilename, mergedHeader, references, writeUncompressed) ) {
cerr << "ERROR: Could not open BAM file " << m_settings->OutputFilename << " for writing... Aborting." << endl;
reader.Close();
return 1;
}
// if no region specified, store entire contents of file(s)
if ( !m_settings->HasRegion ) {
BamAlignment al;
while ( reader.GetNextAlignmentCore(al) )
writer.SaveAlignment(al);
}
// otherwise attempt to use region as constraint
else {
// if region string parses OK
BamRegion region;
if ( Utilities::ParseRegionString(m_settings->Region, reader, region) ) {
// attempt to re-open reader with index files
reader.Close();
bool openedOK = reader.Open(m_settings->InputFiles, true, true );
// if error
if ( !openedOK ) {
cerr << "ERROR: Could not open input BAM file(s)... Aborting." << endl;
return 1;
}
// if index data available, we can use SetRegion
if ( reader.IsIndexLoaded() ) {
// attempt to use SetRegion(), if failed report error
if ( !reader.SetRegion(region.LeftRefID, region.LeftPosition, region.RightRefID, region.RightPosition) ) {
cerr << "ERROR: Region requested, but could not set BamReader region to REGION: " << m_settings->Region << " Aborting." << endl;
reader.Close();
return 1;
}
// everything checks out, just iterate through specified region, storing alignments
BamAlignment al;
while ( reader.GetNextAlignmentCore(al) )
writer.SaveAlignment(al);
}
// no index data available, we have to iterate through until we
// find overlapping alignments
else {
BamAlignment al;
while ( reader.GetNextAlignmentCore(al) ) {
if ( (al.RefID >= region.LeftRefID) && ( (al.Position + al.Length) >= region.LeftPosition ) &&
(al.RefID <= region.RightRefID) && ( al.Position <= region.RightPosition) )
{
writer.SaveAlignment(al);
}
}
}
}
// error parsing REGION string
else {
cerr << "ERROR: Could not parse REGION - " << m_settings->Region << endl;
cerr << "Be sure REGION is in valid format (see README) and that coordinates are valid for selected references" << endl;
reader.Close();
writer.Close();
return 1;
}
}
// clean & exit
reader.Close();
writer.Close();
return 0;
}