本文整理汇总了C++中libmaus2::util::ArgInfo::hasArg方法的典型用法代码示例。如果您正苦于以下问题:C++ ArgInfo::hasArg方法的具体用法?C++ ArgInfo::hasArg怎么用?C++ ArgInfo::hasArg使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类libmaus2::util::ArgInfo
的用法示例。
在下文中一共展示了ArgInfo::hasArg方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: bamrecompress
uint64_t bamrecompress(libmaus2::util::ArgInfo const & arginfo)
{
int const level = libmaus2::bambam::BamBlockWriterBaseFactory::checkCompressionLevel(arginfo.getValue<int>("level",getDefaultLevel()));
int const verbose = arginfo.getValue<int>("verbose",getDefaultVerbose());
int const numthreads = std::max(1,arginfo.getValue<int>("numthreads",getDefaultNumThreads()));
/*
* start index/md5 callbacks
*/
std::string const tmpfilenamebase = arginfo.getValue<std::string>("tmpfile",arginfo.getDefaultTmpFileName());
std::string const tmpfileindex = tmpfilenamebase + "_index";
::libmaus2::util::TempFileRemovalContainer::addTempFile(tmpfileindex);
std::string md5filename;
std::string indexfilename;
std::vector< ::libmaus2::lz::BgzfDeflateOutputCallback * > cbs;
::libmaus2::lz::BgzfDeflateOutputCallbackMD5::unique_ptr_type Pmd5cb;
if ( arginfo.getValue<unsigned int>("md5",getDefaultMD5()) )
{
if ( arginfo.hasArg("md5filename") && arginfo.getUnparsedValue("md5filename","") != "" )
md5filename = arginfo.getUnparsedValue("md5filename","");
else
std::cerr << "[V] no filename for md5 given, not creating hash" << std::endl;
if ( md5filename.size() )
{
::libmaus2::lz::BgzfDeflateOutputCallbackMD5::unique_ptr_type Tmd5cb(new ::libmaus2::lz::BgzfDeflateOutputCallbackMD5);
Pmd5cb = UNIQUE_PTR_MOVE(Tmd5cb);
cbs.push_back(Pmd5cb.get());
}
}
libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex::unique_ptr_type Pindex;
if ( arginfo.getValue<unsigned int>("index",getDefaultIndex()) )
{
if ( arginfo.hasArg("indexfilename") && arginfo.getUnparsedValue("indexfilename","") != "" )
indexfilename = arginfo.getUnparsedValue("indexfilename","");
else
std::cerr << "[V] no filename for index given, not creating index" << std::endl;
if ( indexfilename.size() )
{
libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex::unique_ptr_type Tindex(new libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex(tmpfileindex));
Pindex = UNIQUE_PTR_MOVE(Tindex);
cbs.push_back(Pindex.get());
}
}
/*
* end md5/index callbacks
*/
libmaus2::lz::BgzfInflateDeflateParallel::unique_ptr_type BIDP(new libmaus2::lz::BgzfInflateDeflateParallel(std::cin,std::cout,level,numthreads,4*numthreads));
for ( uint64_t i = 0; i < cbs.size(); ++i )
BIDP->registerBlockOutputCallback(cbs[i]);
libmaus2::autoarray::AutoArray<char> B(64*1024,false);
int r;
uint64_t t = 0;
uint64_t last = std::numeric_limits<uint64_t>::max();
uint64_t lcnt = 0;
uint64_t const mod = 64*1024*1024;
libmaus2::timing::RealTimeClock rtc; rtc.start();
libmaus2::timing::RealTimeClock lrtc; lrtc.start();
while ( (r = BIDP->read(B.begin(),B.size())) )
{
BIDP->write(B.begin(),r);
lcnt += r;
t += r;
if ( t/mod != last/mod )
{
if ( verbose )
{
if ( isatty(STDERR_FILENO) )
std::cerr
<< "\r" << std::string(60,' ') << "\r";
std::cerr
<< rtc.formatTime(rtc.getElapsedSeconds()) << " " << t/(1024*1024) << "MB, " << (lcnt/lrtc.getElapsedSeconds())/(1024.0*1024.0) << "MB/s";
if ( isatty(STDERR_FILENO) )
std::cerr << std::flush;
else
std::cerr << std::endl;
}
lrtc.start();
last = t;
lcnt = 0;
}
}
if ( verbose )
{
if ( isatty(STDERR_FILENO) )
std::cerr
<< "\r" << std::string(60,' ') << "\r";
//.........这里部分代码省略.........
示例2: bamclipreinsert
int bamclipreinsert(::libmaus2::util::ArgInfo const & arginfo)
{
if ( isatty(STDIN_FILENO) )
{
::libmaus2::exception::LibMausException se;
se.getStream() << "Refusing to read binary data from terminal, please redirect standard input to pipe or file." << std::endl;
se.finish();
throw se;
}
if ( isatty(STDOUT_FILENO) )
{
::libmaus2::exception::LibMausException se;
se.getStream() << "Refusing write binary data to terminal, please redirect standard output to pipe or file." << std::endl;
se.finish();
throw se;
}
int const level = libmaus2::bambam::BamBlockWriterBaseFactory::checkCompressionLevel(arginfo.getValue<int>("level",getDefaultLevel()));
int const verbose = arginfo.getValue<int>("verbose",getDefaultVerbose());
::libmaus2::bambam::BamDecoder dec(std::cin,false);
::libmaus2::bambam::BamHeader const & header = dec.getHeader();
std::string const headertext(header.text);
// add PG line to header
std::string const upheadtext = ::libmaus2::bambam::ProgramHeaderLineSet::addProgramLine(
headertext,
"bamclipreinsert", // ID
"bamclipreinsert", // PN
arginfo.commandline, // CL
::libmaus2::bambam::ProgramHeaderLineSet(headertext).getLastIdInChain(), // PP
std::string(PACKAGE_VERSION) // VN
);
// construct new header
libmaus2::bambam::BamHeader const uphead(upheadtext);
/*
* start index/md5 callbacks
*/
std::string const tmpfilenamebase = arginfo.getValue<std::string>("tmpfile",arginfo.getDefaultTmpFileName());
std::string const tmpfileindex = tmpfilenamebase + "_index";
::libmaus2::util::TempFileRemovalContainer::addTempFile(tmpfileindex);
std::string md5filename;
std::string indexfilename;
std::vector< ::libmaus2::lz::BgzfDeflateOutputCallback * > cbs;
::libmaus2::lz::BgzfDeflateOutputCallbackMD5::unique_ptr_type Pmd5cb;
if ( arginfo.getValue<unsigned int>("md5",getDefaultMD5()) )
{
if ( arginfo.hasArg("md5filename") && arginfo.getUnparsedValue("md5filename","") != "" )
md5filename = arginfo.getUnparsedValue("md5filename","");
else
std::cerr << "[V] no filename for md5 given, not creating hash" << std::endl;
if ( md5filename.size() )
{
::libmaus2::lz::BgzfDeflateOutputCallbackMD5::unique_ptr_type Tmd5cb(new ::libmaus2::lz::BgzfDeflateOutputCallbackMD5);
Pmd5cb = UNIQUE_PTR_MOVE(Tmd5cb);
cbs.push_back(Pmd5cb.get());
}
}
libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex::unique_ptr_type Pindex;
if ( arginfo.getValue<unsigned int>("index",getDefaultIndex()) )
{
if ( arginfo.hasArg("indexfilename") && arginfo.getUnparsedValue("indexfilename","") != "" )
indexfilename = arginfo.getUnparsedValue("indexfilename","");
else
std::cerr << "[V] no filename for index given, not creating index" << std::endl;
if ( indexfilename.size() )
{
libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex::unique_ptr_type Tindex(new libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex(tmpfileindex));
Pindex = UNIQUE_PTR_MOVE(Tindex);
cbs.push_back(Pindex.get());
}
}
std::vector< ::libmaus2::lz::BgzfDeflateOutputCallback * > * Pcbs = 0;
if ( cbs.size() )
Pcbs = &cbs;
/*
* end md5/index callbacks
*/
::libmaus2::bambam::BamWriter::unique_ptr_type writer(new ::libmaus2::bambam::BamWriter(std::cout,uphead,level,Pcbs));
libmaus2::bambam::BamAuxFilterVector bafv;
// bafv.set('z','z');
// std::vector<uint8_t> R(8);
// std::string const zz("zz");
libmaus2::bambam::BamAlignment & algn = dec.getAlignment();
uint64_t c = 0;
libmaus2::autoarray::AutoArray < std::pair<uint8_t,uint8_t> > auxtags;
libmaus2::autoarray::AutoArray<libmaus2::bambam::cigar_operation> cigop;
std::stack < libmaus2::bambam::cigar_operation > hardstack;
libmaus2::bambam::BamAlignment::D_array_type Tcigar;
//.........这里部分代码省略.........
示例3: bamreset
int bamreset(::libmaus2::util::ArgInfo const & arginfo)
{
if ( isatty(STDIN_FILENO) )
{
::libmaus2::exception::LibMausException se;
se.getStream() << "Refusing to read binary data from terminal, please redirect standard input to pipe or file." << std::endl;
se.finish();
throw se;
}
if ( isatty(STDOUT_FILENO) )
{
::libmaus2::exception::LibMausException se;
se.getStream() << "Refusing write binary data to terminal, please redirect standard output to pipe or file." << std::endl;
se.finish();
throw se;
}
int const level = libmaus2::bambam::BamBlockWriterBaseFactory::checkCompressionLevel(arginfo.getValue<int>("level",getDefaultLevel()));
int const verbose = arginfo.getValue<int>("verbose",getDefaultVerbose());
int const resetsortorder = arginfo.getValue<int>("resetsortorder",getDefaultResetSortOrder());
::libmaus2::bambam::BamDecoder dec(std::cin,false);
::libmaus2::bambam::BamHeader const & header = dec.getHeader();
std::string headertext = header.text;
// no replacement header file given
if ( ! arginfo.hasArg("resetheadertext") )
{
// remove SQ lines
std::vector<libmaus2::bambam::HeaderLine> allheaderlines = libmaus2::bambam::HeaderLine::extractLines(headertext);
std::ostringstream upheadstr;
for ( uint64_t i = 0; i < allheaderlines.size(); ++i )
if ( allheaderlines[i].type != "SQ" )
upheadstr << allheaderlines[i].line << std::endl;
headertext = upheadstr.str();
}
// replace header given in file
else
{
std::string const headerfilename = arginfo.getUnparsedValue("resetheadertext","");
uint64_t const headerlen = libmaus2::util::GetFileSize::getFileSize(headerfilename);
libmaus2::aio::CheckedInputStream CIS(headerfilename);
libmaus2::autoarray::AutoArray<char> ctext(headerlen,false);
CIS.read(ctext.begin(),headerlen);
headertext = std::string(ctext.begin(),ctext.end());
}
// add PG line to header
headertext = libmaus2::bambam::ProgramHeaderLineSet::addProgramLine(
headertext,
"bamreset", // ID
"bamreset", // PN
arginfo.commandline, // CL
::libmaus2::bambam::ProgramHeaderLineSet(headertext).getLastIdInChain(), // PP
std::string(PACKAGE_VERSION) // VN
);
// construct new header
libmaus2::bambam::BamHeader uphead(headertext);
if ( resetsortorder )
uphead.changeSortOrder("unknown");
/*
* start index/md5 callbacks
*/
std::string const tmpfilenamebase = arginfo.getValue<std::string>("tmpfile",arginfo.getDefaultTmpFileName());
std::string const tmpfileindex = tmpfilenamebase + "_index";
::libmaus2::util::TempFileRemovalContainer::addTempFile(tmpfileindex);
uint32_t const excludeflags = libmaus2::bambam::BamFlagBase::stringToFlags(
arginfo.getValue<std::string>("exclude",getDefaultExcludeFlags()));
std::string md5filename;
std::string indexfilename;
std::vector< ::libmaus2::lz::BgzfDeflateOutputCallback * > cbs;
::libmaus2::lz::BgzfDeflateOutputCallbackMD5::unique_ptr_type Pmd5cb;
if ( arginfo.getValue<unsigned int>("md5",getDefaultMD5()) )
{
if ( arginfo.hasArg("md5filename") && arginfo.getUnparsedValue("md5filename","") != "" )
md5filename = arginfo.getUnparsedValue("md5filename","");
else
std::cerr << "[V] no filename for md5 given, not creating hash" << std::endl;
if ( md5filename.size() )
{
::libmaus2::lz::BgzfDeflateOutputCallbackMD5::unique_ptr_type Tmd5cb(new ::libmaus2::lz::BgzfDeflateOutputCallbackMD5);
Pmd5cb = UNIQUE_PTR_MOVE(Tmd5cb);
cbs.push_back(Pmd5cb.get());
}
}
libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex::unique_ptr_type Pindex;
if ( arginfo.getValue<unsigned int>("index",getDefaultIndex()) )
{
if ( arginfo.hasArg("indexfilename") && arginfo.getUnparsedValue("indexfilename","") != "" )
indexfilename = arginfo.getUnparsedValue("indexfilename","");
else
//.........这里部分代码省略.........
示例4: bam12auxmerge
//.........这里部分代码省略.........
{
std::vector<uint64_t> const & children = headerlines.edges.find(hid)->second;
for ( uint64_t j = 0; j < children.size(); ++j )
pgtodo.push(std::pair<uint64_t,std::string>(children[j],ID));
}
}
/* copy SQ lines */
std::ostringstream sqconcstr;
sqconcstr << upheadtext;
for ( uint64_t i = 0; i < allheaderlines.size(); ++i )
if ( allheaderlines[i].type == "SQ" )
sqconcstr << allheaderlines[i].line << "\n";
upheadtext = sqconcstr.str();
::libmaus2::bambam::BamHeader uphead(upheadtext);
uphead.changeSortOrder("unknown");
/*
* start index/md5 callbacks
*/
std::string const tmpfilenamebase = arginfo.getValue<std::string>("tmpfile",arginfo.getDefaultTmpFileName());
std::string const tmpfileindex = tmpfilenamebase + "_index";
::libmaus2::util::TempFileRemovalContainer::addTempFile(tmpfileindex);
std::string md5filename;
std::string indexfilename;
std::vector< ::libmaus2::lz::BgzfDeflateOutputCallback * > cbs;
::libmaus2::lz::BgzfDeflateOutputCallbackMD5::unique_ptr_type Pmd5cb;
if ( arginfo.getValue<unsigned int>("md5",getDefaultMD5()) )
{
if ( arginfo.hasArg("md5filename") && arginfo.getUnparsedValue("md5filename","") != "" )
md5filename = arginfo.getUnparsedValue("md5filename","");
else
std::cerr << "[V] no filename for md5 given, not creating hash" << std::endl;
if ( md5filename.size() )
{
::libmaus2::lz::BgzfDeflateOutputCallbackMD5::unique_ptr_type Tmd5cb(new ::libmaus2::lz::BgzfDeflateOutputCallbackMD5);
Pmd5cb = UNIQUE_PTR_MOVE(Tmd5cb);
cbs.push_back(Pmd5cb.get());
}
}
libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex::unique_ptr_type Pindex;
if ( arginfo.getValue<unsigned int>("index",getDefaultIndex()) )
{
if ( arginfo.hasArg("indexfilename") && arginfo.getUnparsedValue("indexfilename","") != "" )
indexfilename = arginfo.getUnparsedValue("indexfilename","");
else
std::cerr << "[V] no filename for index given, not creating index" << std::endl;
if ( indexfilename.size() )
{
libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex::unique_ptr_type Tindex(new libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex(tmpfileindex));
Pindex = UNIQUE_PTR_MOVE(Tindex);
cbs.push_back(Pindex.get());
}
}
std::vector< ::libmaus2::lz::BgzfDeflateOutputCallback * > * Pcbs = 0;
if ( cbs.size() )
Pcbs = &cbs;
/*
* end md5/index callbacks
*/
示例5: bamheaderfilter
uint64_t bamheaderfilter(libmaus2::util::ArgInfo const & arginfo)
{
std::string const inputfilename = arginfo.getUnparsedValue("I","");
if ( ! inputfilename.size() || inputfilename == "-" )
{
::libmaus2::exception::LibMausException se;
se.getStream() << "No input filename given, please set the I key appropriately." << std::endl;
se.finish();
throw se;
}
libmaus2::bitio::IndexedBitVector::unique_ptr_type usedrefseq;
libmaus2::bitio::IndexedBitVector::unique_ptr_type usedrg;
libmaus2::bambam::BamHeader::unique_ptr_type uheader;
getUsedRefSeqs(arginfo,usedrefseq,usedrg,uheader);
/*
* start index/md5 callbacks
*/
std::string const tmpfilenamebase = arginfo.getValue<std::string>("tmpfile",arginfo.getDefaultTmpFileName());
std::string const tmpfileindex = tmpfilenamebase + "_index";
::libmaus2::util::TempFileRemovalContainer::addTempFile(tmpfileindex);
std::string md5filename;
std::string indexfilename;
std::vector< ::libmaus2::lz::BgzfDeflateOutputCallback * > cbs;
::libmaus2::lz::BgzfDeflateOutputCallbackMD5::unique_ptr_type Pmd5cb;
if ( arginfo.getValue<unsigned int>("md5",getDefaultMD5()) )
{
if ( arginfo.hasArg("md5filename") && arginfo.getUnparsedValue("md5filename","") != "" )
md5filename = arginfo.getUnparsedValue("md5filename","");
else
std::cerr << "[V] no filename for md5 given, not creating hash" << std::endl;
if ( md5filename.size() )
{
::libmaus2::lz::BgzfDeflateOutputCallbackMD5::unique_ptr_type Tmd5cb(new ::libmaus2::lz::BgzfDeflateOutputCallbackMD5);
Pmd5cb = UNIQUE_PTR_MOVE(Tmd5cb);
cbs.push_back(Pmd5cb.get());
}
}
libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex::unique_ptr_type Pindex;
if ( arginfo.getValue<unsigned int>("index",getDefaultIndex()) )
{
if ( arginfo.hasArg("indexfilename") && arginfo.getUnparsedValue("indexfilename","") != "" )
indexfilename = arginfo.getUnparsedValue("indexfilename","");
else
std::cerr << "[V] no filename for index given, not creating index" << std::endl;
if ( indexfilename.size() )
{
libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex::unique_ptr_type Tindex(new libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex(tmpfileindex));
Pindex = UNIQUE_PTR_MOVE(Tindex);
cbs.push_back(Pindex.get());
}
}
/*
* end md5/index callbacks
*/
std::string headertext(uheader->text);
std::vector<libmaus2::bambam::HeaderLine> hl = libmaus2::bambam::HeaderLine::extractLines(headertext);
std::ostringstream headertextostr;
uint64_t rscnt = 0;
uint64_t rgcnt = 0;
for ( uint64_t i = 0; i < hl.size(); ++i )
{
if ( hl[i].type == "SQ" )
{
if ( usedrefseq->get(rscnt) )
headertextostr << hl[i].line << std::endl;
rscnt += 1;
}
else if ( hl[i].type == "RG" )
{
if ( usedrg->get(rgcnt) )
headertextostr << hl[i].line << std::endl;
rgcnt += 1;
}
else
{
headertextostr << hl[i].line << std::endl;
}
}
headertext = headertextostr.str();
// add PG line to header
std::string const upheadtext = ::libmaus2::bambam::ProgramHeaderLineSet::addProgramLine(
headertext,
"bamheaderfilter", // ID
"bamheaderfilter", // PN
arginfo.commandline, // CL
::libmaus2::bambam::ProgramHeaderLineSet(headertext).getLastIdInChain(), // PP
std::string(PACKAGE_VERSION) // VN
//.........这里部分代码省略.........
示例6: bammaskflags
int bammaskflags(::libmaus2::util::ArgInfo const & arginfo)
{
uint64_t const maskpos = arginfo.getValue<uint64_t>("maskpos",0xFFFFUL);
uint64_t const maskneg = arginfo.getValue<uint64_t>("maskneg",getDefaultMaskNeg());
uint64_t const mask = maskpos & (~maskneg);
if ( mask )
{
std::cerr << "Keeping flags ";
for ( uint64_t i = 1; i <= ::libmaus2::bambam::BamFlagBase::LIBMAUS2_BAMBAM_FSUPPLEMENTARY; i <<= 1 )
if ( mask & i )
std::cerr << static_cast< ::libmaus2::bambam::BamFlagBase::bam_flags >(i) << ";";
std::cerr << std::endl;
std::cerr << "Erasing flags ";
for ( uint64_t i = 1; i <= ::libmaus2::bambam::BamFlagBase::LIBMAUS2_BAMBAM_FSUPPLEMENTARY; i <<= 1 )
if ( !(mask & i) )
std::cerr << static_cast< ::libmaus2::bambam::BamFlagBase::bam_flags >(i) << ";";
std::cerr << std::endl;
}
else
{
std::cerr << "Erasing all flags." << std::endl;
}
int const level = libmaus2::bambam::BamBlockWriterBaseFactory::checkCompressionLevel(arginfo.getValue<int>("level",getDefaultLevel()));
int const resetmatecoord = arginfo.getValue<int>("resetmatecoord",0);
::libmaus2::bambam::BamDecoder BD(std::cin);
::libmaus2::bambam::BamHeader const & bamheader = BD.getHeader();
std::string const headertext(bamheader.text);
// add PG line to header
std::string const upheadtext = ::libmaus2::bambam::ProgramHeaderLineSet::addProgramLine(
headertext,
"bammaskflags", // ID
"bammaskflags", // PN
arginfo.commandline, // CL
::libmaus2::bambam::ProgramHeaderLineSet(headertext).getLastIdInChain(), // PP
std::string(PACKAGE_VERSION) // VN
);
// construct new header
::libmaus2::bambam::BamHeader uphead(upheadtext);
::libmaus2::bambam::BamAlignment & alignment = BD.getAlignment();
/*
* start index/md5 callbacks
*/
std::string const tmpfilenamebase = arginfo.getValue<std::string>("tmpfile",arginfo.getDefaultTmpFileName());
std::string const tmpfileindex = tmpfilenamebase + "_index";
::libmaus2::util::TempFileRemovalContainer::addTempFile(tmpfileindex);
std::string md5filename;
std::string indexfilename;
std::vector< ::libmaus2::lz::BgzfDeflateOutputCallback * > cbs;
::libmaus2::lz::BgzfDeflateOutputCallbackMD5::unique_ptr_type Pmd5cb;
if ( arginfo.getValue<unsigned int>("md5",getDefaultMD5()) )
{
if ( arginfo.hasArg("md5filename") && arginfo.getUnparsedValue("md5filename","") != "" )
md5filename = arginfo.getUnparsedValue("md5filename","");
else
std::cerr << "[V] no filename for md5 given, not creating hash" << std::endl;
if ( md5filename.size() )
{
::libmaus2::lz::BgzfDeflateOutputCallbackMD5::unique_ptr_type Tmd5cb(new ::libmaus2::lz::BgzfDeflateOutputCallbackMD5);
Pmd5cb = UNIQUE_PTR_MOVE(Tmd5cb);
cbs.push_back(Pmd5cb.get());
}
}
libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex::unique_ptr_type Pindex;
if ( arginfo.getValue<unsigned int>("index",getDefaultIndex()) )
{
if ( arginfo.hasArg("indexfilename") && arginfo.getUnparsedValue("indexfilename","") != "" )
indexfilename = arginfo.getUnparsedValue("indexfilename","");
else
std::cerr << "[V] no filename for index given, not creating index" << std::endl;
if ( indexfilename.size() )
{
libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex::unique_ptr_type Tindex(new libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex(tmpfileindex));
Pindex = UNIQUE_PTR_MOVE(Tindex);
cbs.push_back(Pindex.get());
}
}
std::vector< ::libmaus2::lz::BgzfDeflateOutputCallback * > * Pcbs = 0;
if ( cbs.size() )
Pcbs = &cbs;
/*
* end md5/index callbacks
*/
::libmaus2::bambam::BamWriter::unique_ptr_type writer(new ::libmaus2::bambam::BamWriter(std::cout,uphead,level,Pcbs));
while ( BD.readAlignment() )
{
alignment.putFlags(alignment.getFlags() & mask);
if ( resetmatecoord )
//.........这里部分代码省略.........
示例7: bamvalidateTemplate
int bamvalidateTemplate(::libmaus2::util::ArgInfo const & arginfo)
{
libmaus2::timing::RealTimeClock rtc; rtc.start();
bool const verbose = arginfo.getValue("verbose",getDefaultVerbose());
bool const basequalhist = arginfo.getValue("basequalhist",getDefaultBaseQualHist());
libmaus2::bambam::BamAlignmentDecoderWrapper::unique_ptr_type decwrapper(
libmaus2::bambam::BamMultiAlignmentDecoderFactory::construct(
arginfo,false // put rank
)
);
::libmaus2::bambam::BamAlignmentDecoder * ppdec = &(decwrapper->getDecoder());
::libmaus2::bambam::BamAlignmentDecoder & dec = *ppdec;
::libmaus2::bambam::BamHeader const & header = dec.getHeader();
::libmaus2::bambam::BamAlignment const & algn = dec.getAlignment();
// add PG line to header
std::string const upheadtext = ::libmaus2::bambam::ProgramHeaderLineSet::addProgramLine(
header.text,
"bamvalidate", // ID
"bamvalidate", // PN
arginfo.commandline, // CL
::libmaus2::bambam::ProgramHeaderLineSet(header.text).getLastIdInChain(), // PP
std::string(PACKAGE_VERSION) // VN
);
// construct new header
::libmaus2::bambam::BamHeader uphead(upheadtext);
/*
* start index/md5 callbacks and alignment writer
*/
std::string md5filename;
std::string indexfilename;
std::vector< ::libmaus2::lz::BgzfDeflateOutputCallback * > cbs;
::libmaus2::lz::BgzfDeflateOutputCallbackMD5::unique_ptr_type Pmd5cb;
libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex::unique_ptr_type Pindex;
libmaus2::bambam::BamBlockWriterBase::unique_ptr_type Pout;
if ( passthrough )
{
std::string const tmpfilenamebase = arginfo.getValue<std::string>("tmpfile",arginfo.getDefaultTmpFileName());
std::string const tmpfileindex = tmpfilenamebase + "_index";
::libmaus2::util::TempFileRemovalContainer::addTempFile(tmpfileindex);
if ( arginfo.getValue<unsigned int>("md5",getDefaultMD5()) )
{
if ( arginfo.hasArg("md5filename") && arginfo.getUnparsedValue("md5filename","") != "" )
md5filename = arginfo.getUnparsedValue("md5filename","");
else
std::cerr << "[V] no filename for md5 given, not creating hash" << std::endl;
if ( md5filename.size() )
{
::libmaus2::lz::BgzfDeflateOutputCallbackMD5::unique_ptr_type Tmd5cb(new ::libmaus2::lz::BgzfDeflateOutputCallbackMD5);
Pmd5cb = UNIQUE_PTR_MOVE(Tmd5cb);
cbs.push_back(Pmd5cb.get());
}
}
if ( arginfo.getValue<unsigned int>("index",getDefaultIndex()) )
{
if ( arginfo.hasArg("indexfilename") && arginfo.getUnparsedValue("indexfilename","") != "" )
indexfilename = arginfo.getUnparsedValue("indexfilename","");
else
std::cerr << "[V] no filename for index given, not creating index" << std::endl;
if ( indexfilename.size() )
{
libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex::unique_ptr_type Tindex(new libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex(tmpfileindex));
Pindex = UNIQUE_PTR_MOVE(Tindex);
cbs.push_back(Pindex.get());
}
}
std::vector< ::libmaus2::lz::BgzfDeflateOutputCallback * > * Pcbs = 0;
if ( cbs.size() )
Pcbs = &cbs;
libmaus2::bambam::BamBlockWriterBase::unique_ptr_type Tout (
libmaus2::bambam::BamBlockWriterBaseFactory::construct(uphead, arginfo, Pcbs)
);
Pout = UNIQUE_PTR_MOVE(Tout);
}
libmaus2::autoarray::AutoArray<char> lastvalidname(256); // max valid read name is 255 bytes
uint64_t alsok = 0;
::libmaus2::autoarray::AutoArray<char> qual;
libmaus2::autoarray::AutoArray<uint64_t> H(static_cast<uint64_t>(std::numeric_limits<uint8_t>::max())+1);
std::fill(H.begin(),H.end(),0ull);
try
{
while ( dec.readAlignment() )
{
if ( passthrough )
Pout->writeAlignment(algn);
if ( basequalhist )
{
//.........这里部分代码省略.........
示例8: bamrecalculatecigar
int bamrecalculatecigar(libmaus2::util::ArgInfo const & arginfo)
{
if ( isatty(STDOUT_FILENO) )
{
::libmaus2::exception::LibMausException se;
se.getStream() << "Refusing write binary data to terminal, please redirect standard output to pipe or file." << std::endl;
se.finish();
throw se;
}
int const verbose = arginfo.getValue<int>("verbose",getDefaultVerbose());
// input decoder wrapper
libmaus2::bambam::BamAlignmentDecoderWrapper::unique_ptr_type decwrapper(
libmaus2::bambam::BamMultiAlignmentDecoderFactory::construct(
arginfo,false // put rank
)
);
libmaus2::bambam::BamAlignmentDecoder & bamdec = decwrapper->getDecoder();
libmaus2::bambam::BamAlignment & algn = bamdec.getAlignment();
libmaus2::bambam::BamHeader const & header = bamdec.getHeader();
::libmaus2::bambam::BamHeader::unique_ptr_type uphead(updateHeader(arginfo,header));
/*
* start index/md5 callbacks
*/
std::string const tmpfilenamebase = arginfo.getValue<std::string>("tmpfile",arginfo.getDefaultTmpFileName());
std::string const tmpfileindex = tmpfilenamebase + "_index";
::libmaus2::util::TempFileRemovalContainer::addTempFile(tmpfileindex);
std::string md5filename;
std::string indexfilename;
std::vector< ::libmaus2::lz::BgzfDeflateOutputCallback * > cbs;
::libmaus2::lz::BgzfDeflateOutputCallbackMD5::unique_ptr_type Pmd5cb;
if ( arginfo.getValue<unsigned int>("md5",getDefaultMD5()) )
{
if ( arginfo.hasArg("md5filename") && arginfo.getUnparsedValue("md5filename","") != "" )
md5filename = arginfo.getUnparsedValue("md5filename","");
else
std::cerr << "[V] no filename for md5 given, not creating hash" << std::endl;
if ( md5filename.size() )
{
::libmaus2::lz::BgzfDeflateOutputCallbackMD5::unique_ptr_type Tmd5cb(new ::libmaus2::lz::BgzfDeflateOutputCallbackMD5);
Pmd5cb = UNIQUE_PTR_MOVE(Tmd5cb);
cbs.push_back(Pmd5cb.get());
}
}
libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex::unique_ptr_type Pindex;
if ( arginfo.getValue<unsigned int>("index",getDefaultIndex()) )
{
if ( arginfo.hasArg("indexfilename") && arginfo.getUnparsedValue("indexfilename","") != "" )
indexfilename = arginfo.getUnparsedValue("indexfilename","");
else
std::cerr << "[V] no filename for index given, not creating index" << std::endl;
if ( indexfilename.size() )
{
libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex::unique_ptr_type Tindex(new libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex(tmpfileindex));
Pindex = UNIQUE_PTR_MOVE(Tindex);
cbs.push_back(Pindex.get());
}
}
std::vector< ::libmaus2::lz::BgzfDeflateOutputCallback * > * Pcbs = 0;
if ( cbs.size() )
Pcbs = &cbs;
/*
* end md5/index callbacks
*/
libmaus2::bambam::BamBlockWriterBase::unique_ptr_type writer(
libmaus2::bambam::BamBlockWriterBaseFactory::construct(*uphead, arginfo, Pcbs)
);
libmaus2::autoarray::AutoArray<libmaus2::bambam::cigar_operation> cigopin;
libmaus2::autoarray::AutoArray<char> readdata;
libmaus2::bambam::BamAlignment::D_array_type T;
if ( ! arginfo.hasArg("reference") )
{
libmaus2::exception::LibMausException se;
se.getStream() << "reference key is missing." << std::endl;
se.finish();
throw se;
}
std::string const reference = arginfo.getUnparsedValue("reference","");
if ( ! libmaus2::util::GetFileSize::fileExists(reference) )
{
libmaus2::exception::LibMausException se;
se.getStream() << "file " << reference << " does not exist." << std::endl;
se.finish();
throw se;
}
libmaus2::fastx::FastAIndex::unique_ptr_type FAindex(libmaus2::fastx::FastAIndex::load(reference + ".fai"));
libmaus2::aio::InputStreamInstance FAISI(reference);
//.........这里部分代码省略.........
示例9: bamfilterflags
int bamfilterflags(::libmaus2::util::ArgInfo const & arginfo)
{
uint32_t const excludeflags = libmaus2::bambam::BamFlagBase::stringToFlags(arginfo.getValue<std::string>("exclude",""));
std::cerr << "[V] excluding " << excludeflags << std::endl;
int const level = libmaus2::bambam::BamBlockWriterBaseFactory::checkCompressionLevel(arginfo.getValue<int>("level",Z_DEFAULT_COMPRESSION));
uint64_t const numthreads = arginfo.getValue<uint64_t>("numthreads",1);
uint64_t cnt = 0;
uint64_t kept = 0;
/*
* start index/md5 callbacks
*/
std::string const tmpfilenamebase = arginfo.getValue<std::string>("tmpfile",arginfo.getDefaultTmpFileName());
std::string const tmpfileindex = tmpfilenamebase + "_index";
::libmaus2::util::TempFileRemovalContainer::addTempFile(tmpfileindex);
std::string md5filename;
std::string indexfilename;
std::vector< ::libmaus2::lz::BgzfDeflateOutputCallback * > cbs;
::libmaus2::lz::BgzfDeflateOutputCallbackMD5::unique_ptr_type Pmd5cb;
if ( arginfo.getValue<unsigned int>("md5",getDefaultMD5()) )
{
if ( arginfo.hasArg("md5filename") && arginfo.getUnparsedValue("md5filename","") != "" )
md5filename = arginfo.getUnparsedValue("md5filename","");
else
std::cerr << "[V] no filename for md5 given, not creating hash" << std::endl;
if ( md5filename.size() )
{
::libmaus2::lz::BgzfDeflateOutputCallbackMD5::unique_ptr_type Tmd5cb(new ::libmaus2::lz::BgzfDeflateOutputCallbackMD5);
Pmd5cb = UNIQUE_PTR_MOVE(Tmd5cb);
cbs.push_back(Pmd5cb.get());
}
}
libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex::unique_ptr_type Pindex;
if ( arginfo.getValue<unsigned int>("index",getDefaultIndex()) )
{
if ( arginfo.hasArg("indexfilename") && arginfo.getUnparsedValue("indexfilename","") != "" )
indexfilename = arginfo.getUnparsedValue("indexfilename","");
else
std::cerr << "[V] no filename for index given, not creating index" << std::endl;
if ( indexfilename.size() )
{
libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex::unique_ptr_type Tindex(new libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex(tmpfileindex));
Pindex = UNIQUE_PTR_MOVE(Tindex);
cbs.push_back(Pindex.get());
}
}
std::vector< ::libmaus2::lz::BgzfDeflateOutputCallback * > * Pcbs = 0;
if ( cbs.size() )
Pcbs = &cbs;
/*
* end md5/index callbacks
*/
if ( numthreads == 1 )
{
::libmaus2::bambam::BamDecoder BD(std::cin);
::libmaus2::bambam::BamHeader const & bamheader = BD.getHeader();
::libmaus2::bambam::BamHeader::unique_ptr_type uphead(libmaus2::bambam::BamHeaderUpdate::updateHeader(arginfo,bamheader,"bamfilterflags",std::string(PACKAGE_VERSION)));
::libmaus2::bambam::BamAlignment & alignment = BD.getAlignment();
::libmaus2::bambam::BamWriter::unique_ptr_type writer(new ::libmaus2::bambam::BamWriter(std::cout,*uphead,level,Pcbs));
for ( ; BD.readAlignment(); ++cnt )
{
if ( cnt % (1024*1024) == 0 )
std::cerr << "[V] processed " << cnt << " kept " << kept << " removed " << (cnt-kept) << std::endl;
if ( ! (alignment.getFlags() & excludeflags) )
{
alignment.serialise(writer->getStream());
++kept;
}
}
std::cerr << "[V] " << cnt << std::endl;
}
else
{
::libmaus2::bambam::BamHeaderUpdate UH(arginfo,"bamfilterflags",std::string(PACKAGE_VERSION));
libmaus2::bambam::BamParallelRewrite BPR(std::cin,UH,std::cout,Z_DEFAULT_COMPRESSION,numthreads,4 /* blocks per thread */,Pcbs);
libmaus2::bambam::BamAlignmentDecoder & dec = BPR.getDecoder();
libmaus2::bambam::BamParallelRewrite::writer_type & writer = BPR.getWriter();
libmaus2::bambam::BamAlignment const & algn = dec.getAlignment();
for ( ; dec.readAlignment(); ++cnt )
{
if ( cnt % (1024*1024) == 0 )
std::cerr << "[V] processed " << cnt << " kept " << kept << " removed " << (cnt-kept) << std::endl;
if ( ! (algn.getFlags() & excludeflags) )
{
algn.serialise(writer.getStream());
++kept;
}
}
//.........这里部分代码省略.........
示例10: fagzToCompact4
int fagzToCompact4(libmaus2::util::ArgInfo const & arginfo)
{
bool const rc = arginfo.getValue<unsigned int>("rc",1);
bool const gz = arginfo.getValue<unsigned int>("gz",1);
std::vector<std::string> inputfilenames;
inputfilenames = arginfo.restargs;
if ( arginfo.hasArg("inputfilenames") )
{
std::string const inf = arginfo.getUnparsedValue("inputfilenames",std::string());
libmaus2::aio::InputStream::unique_ptr_type Pinf(libmaus2::aio::InputStreamFactoryContainer::constructUnique(inf));
while ( *Pinf )
{
std::string line;
std::getline(*Pinf,line);
if ( line.size() )
inputfilenames.push_back(line);
}
}
std::string const inlcp = libmaus2::util::OutputFileNameTools::lcp(inputfilenames);
std::string defout = inlcp;
defout = libmaus2::util::OutputFileNameTools::clipOff(defout,".gz");
defout = libmaus2::util::OutputFileNameTools::clipOff(defout,".fasta");
defout = libmaus2::util::OutputFileNameTools::clipOff(defout,".fa");
std::string const outputfilename = arginfo.getUnparsedValue("outputfilename",defout + ".compact");
std::string const metaoutputfilename = outputfilename + ".meta";
int const verbose = arginfo.getValue<int>("verbose",1);
libmaus2::autoarray::AutoArray<char> B(8*1024,false);
libmaus2::bitio::CompactArrayWriterFile compactout(outputfilename,2 /* bits per symbol */);
if ( ! rc )
std::cerr << "[V] not storing reverse complements" << std::endl;
// forward mapping table
libmaus2::autoarray::AutoArray<uint8_t> ftable(256,false);
// rc mapping for mapped symbols
libmaus2::autoarray::AutoArray<uint8_t> ctable(256,false);
std::fill(ftable.begin(),ftable.end(),4);
std::fill(ctable.begin(),ctable.end(),4);
ftable['a'] = ftable['A'] = 0;
ftable['c'] = ftable['C'] = 1;
ftable['g'] = ftable['G'] = 2;
ftable['t'] = ftable['T'] = 3;
uint64_t insize = 0;
ctable[0] = 3; // A->T
ctable[1] = 2; // C->G
ctable[2] = 1; // G->C
ctable[3] = 0; // T->A
libmaus2::aio::OutputStreamInstance::unique_ptr_type metaOut(new libmaus2::aio::OutputStreamInstance(metaoutputfilename));
libmaus2::util::NumberSerialisation::serialiseNumber(*metaOut,0);
uint64_t nseq = 0;
std::vector<uint64_t> lvec;
for ( uint64_t i = 0; i < inputfilenames.size(); ++i )
{
std::string const fn = inputfilenames[i];
libmaus2::aio::InputStreamInstance CIS(fn);
libmaus2::lz::BufferedGzipStream::unique_ptr_type BGS;
std::istream * istr = 0;
if ( gz )
{
libmaus2::lz::BufferedGzipStream::unique_ptr_type tBGS(
new libmaus2::lz::BufferedGzipStream(CIS));
BGS = UNIQUE_PTR_MOVE(tBGS);
istr = BGS.get();
}
else
{
istr = &CIS;
}
libmaus2::fastx::StreamFastAReaderWrapper fain(*istr);
libmaus2::fastx::StreamFastAReaderWrapper::pattern_type pattern;
while ( fain.getNextPatternUnlocked(pattern) )
{
if ( verbose )
std::cerr << (i+1) << " " << stripAfterDot(basename(fn)) << " " << pattern.sid << "...";
libmaus2::util::NumberSerialisation::serialiseNumber(*metaOut,pattern.spattern.size());
lvec.push_back(pattern.spattern.size());
libmaus2::util::NumberSerialisation::serialiseNumber(*metaOut,0);
// map symbols
for ( uint64_t j = 0; j < pattern.spattern.size(); ++j )
pattern.spattern[j] = ftable[static_cast<uint8_t>(pattern.spattern[j])];
// replace blocks of N symbols by random bases
uint64_t l = 0;
// number of replaced blocks
uint64_t nr = 0;
while ( l < pattern.spattern.size() )
{
// skip regular bases
while ( l < pattern.spattern.size() && pattern.spattern[l] < 4 )
//.........这里部分代码省略.........
示例11: bamcat
int bamcat(libmaus2::util::ArgInfo const & arginfo)
{
if ( isatty(STDOUT_FILENO) )
{
::libmaus2::exception::LibMausException se;
se.getStream() << "Refusing write binary data to terminal, please redirect standard output to pipe or file." << std::endl;
se.finish();
throw se;
}
int const level = libmaus2::bambam::BamBlockWriterBaseFactory::checkCompressionLevel(arginfo.getValue<int>("level",getDefaultLevel()));
int const verbose = arginfo.getValue<int>("verbose",getDefaultVerbose());
int const streaming = arginfo.getValue<int>("streaming",getDefaultStreaming());
std::vector<std::string> inputfilenames = arginfo.getPairValues("I");
for ( uint64_t i = 0; i < arginfo.restargs.size(); ++i )
inputfilenames.push_back(arginfo.restargs[i]);
libmaus2::bambam::BamCat bamdec(inputfilenames, false /* put rank */, streaming);
libmaus2::bambam::BamAlignment const & algn = bamdec.getAlignment();
libmaus2::bambam::BamHeader const & header = bamdec.getHeader();
::libmaus2::bambam::BamHeader::unique_ptr_type uphead(updateHeader(arginfo,header));
/*
* start index/md5 callbacks
*/
std::string const tmpfilenamebase = arginfo.getValue<std::string>("tmpfile",arginfo.getDefaultTmpFileName());
std::string const tmpfileindex = tmpfilenamebase + "_index";
::libmaus2::util::TempFileRemovalContainer::addTempFile(tmpfileindex);
std::string md5filename;
std::string indexfilename;
std::vector< ::libmaus2::lz::BgzfDeflateOutputCallback * > cbs;
::libmaus2::lz::BgzfDeflateOutputCallbackMD5::unique_ptr_type Pmd5cb;
if ( arginfo.getValue<unsigned int>("md5",getDefaultMD5()) )
{
if ( arginfo.hasArg("md5filename") && arginfo.getUnparsedValue("md5filename","") != "" )
md5filename = arginfo.getUnparsedValue("md5filename","");
else
std::cerr << "[V] no filename for md5 given, not creating hash" << std::endl;
if ( md5filename.size() )
{
::libmaus2::lz::BgzfDeflateOutputCallbackMD5::unique_ptr_type Tmd5cb(new ::libmaus2::lz::BgzfDeflateOutputCallbackMD5);
Pmd5cb = UNIQUE_PTR_MOVE(Tmd5cb);
cbs.push_back(Pmd5cb.get());
}
}
libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex::unique_ptr_type Pindex;
if ( arginfo.getValue<unsigned int>("index",getDefaultIndex()) )
{
if ( arginfo.hasArg("indexfilename") && arginfo.getUnparsedValue("indexfilename","") != "" )
indexfilename = arginfo.getUnparsedValue("indexfilename","");
else
std::cerr << "[V] no filename for index given, not creating index" << std::endl;
if ( indexfilename.size() )
{
libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex::unique_ptr_type Tindex(new libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex(tmpfileindex));
Pindex = UNIQUE_PTR_MOVE(Tindex);
cbs.push_back(Pindex.get());
}
}
std::vector< ::libmaus2::lz::BgzfDeflateOutputCallback * > * Pcbs = 0;
if ( cbs.size() )
Pcbs = &cbs;
/*
* end md5/index callbacks
*/
::libmaus2::bambam::BamWriter::unique_ptr_type writer(new ::libmaus2::bambam::BamWriter(std::cout,*uphead,level,Pcbs));
libmaus2::bambam::BamWriter::stream_type & bamoutstr = writer->getStream();
if ( verbose )
{
uint64_t c = 0;
while ( bamdec.readAlignment() )
{
algn.serialise(bamoutstr);
if ( ((++c) & ((1ull<<20)-1)) == 0 )
std::cerr << "[V] " << c << std::endl;
}
std::cerr << "[V] " << c << std::endl;
}
else
while ( bamdec.readAlignment() )
algn.serialise(bamoutstr);
writer.reset();
if ( Pmd5cb )
{
Pmd5cb->saveDigestAsFile(md5filename);
}
if ( Pindex )
{
//.........这里部分代码省略.........