void EndSW(void) /* switch文の終了 */ { CSentry *p; for (p = SWtbl[SWTptr].CTptr; p < CaseP; p++) { /* 分岐命令の生成 */ Pout(COPY); Cout(PUSHI, p->label); Pout(COMP); Cout(BNE, PC()+3); Pout(REMOVE); Cout(JUMP, p->addr); } Pout(REMOVE); if (SWtbl[SWTptr].DefltAddr > 0) /* defaultラベルが定義? */ Cout(JUMP, SWtbl[SWTptr].DefltAddr); /* そこへのジャンプ命令 */ CaseP = SWtbl[SWTptr--].CTptr; /* ラベル表のポインタを */ } /* 戻す */
ccMesh* FromCorkMesh(const CorkMesh& in, ccMainAppInterface* app = 0) { const std::vector<CorkMesh::Tri>& inTris = in.getTris(); const std::vector<CorkVertex>& inVerts = in.getVerts(); if (inTris.empty() || inVerts.empty()) { if (app) app->dispToConsole("[Cork] Output mesh is empty?!",ccMainAppInterface::WRN_CONSOLE_MESSAGE); return 0; } unsigned triCount = static_cast<unsigned>(inTris.size()); unsigned vertCount = static_cast<unsigned>(inVerts.size()); ccPointCloud* vertices = new ccPointCloud("vertices"); if (!vertices->reserve(vertCount)) { if (app) app->dispToConsole("[Cork] Not enough memory!",ccMainAppInterface::ERR_CONSOLE_MESSAGE); delete vertices; return 0; } ccMesh* mesh = new ccMesh(vertices); mesh->addChild(vertices); if (!mesh->reserve(triCount)) { if (app) app->dispToConsole("[Cork] Not enough memory!",ccMainAppInterface::ERR_CONSOLE_MESSAGE); delete mesh; return 0; } //import vertices { for(unsigned i=0; i<vertCount; i++) { const CorkVertex& P = inVerts[i]; CCVector3 Pout( static_cast<PointCoordinateType>(P.pos.x), static_cast<PointCoordinateType>(P.pos.y), static_cast<PointCoordinateType>(P.pos.z) ); vertices->addPoint(Pout); } } //import triangle indexes { for(unsigned i=0; i<triCount; i++) { const CorkMesh::Tri& tri = inTris[i]; mesh->addTriangle(tri.a,tri.b,tri.c); } } mesh->setVisible(true); vertices->setEnabled(false); return mesh; }
void EndSW(void) { CSentry *p; for (p = SWtbl[SWTptr].CTptr; p < CaseP; p++) { Pout(COPY); Cout(PUSHI, p->label); Pout(COMP); Cout(BNE, PC() + 3); Pout(REMOVE); Cout(JUMP, p->addr); } Pout(REMOVE); if (SWtbl[SWTptr].DefltAddr > 0) { Cout(JUMP, SWtbl[SWTptr].DefltAddr); } CaseP = SWtbl[SWTptr--].CTptr; }
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 ); // construct new header ::libmaus2::bambam::BamHeader uphead(upheadtext); libmaus2::bambam::BamBlockWriterBase::unique_ptr_type Pout ( libmaus2::bambam::BamBlockWriterBaseFactory::construct(uphead, arginfo, &cbs) ); // input decoder wrapper 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::BamAlignment & algn = dec.getAlignment(); while ( dec.readAlignment() ) { if ( (!algn.isPaired()) && algn.isMapped() ) { assert ( algn.getRefID() >= 0 ); assert ( algn.getRefID() < static_cast<int64_t>(usedrefseq->size()) ); assert ( usedrefseq->get(algn.getRefID()) ); assert ( usedrefseq->rank1(algn.getRefID())-1 < uphead.getNumRef() ); algn.putRefId(usedrefseq->rank1(algn.getRefID())-1); } if ( algn.isPaired() && algn.isMapped() ) { assert ( algn.getRefID() >= 0 ); assert ( algn.getRefID() < static_cast<int64_t>(usedrefseq->size()) ); assert ( usedrefseq->get(algn.getRefID()) ); assert ( usedrefseq->rank1(algn.getRefID())-1 < uphead.getNumRef() ); algn.putRefId(usedrefseq->rank1(algn.getRefID())-1); } if ( algn.isPaired() && algn.isMateMapped() ) { assert ( algn.getNextRefID() >= 0 ); assert ( algn.getNextRefID() < static_cast<int64_t>(usedrefseq->size()) ); assert ( usedrefseq->get(algn.getNextRefID()) ); assert ( usedrefseq->rank1(algn.getNextRefID())-1 < uphead.getNumRef() ); algn.putNextRefId(usedrefseq->rank1(algn.getNextRefID())-1); } // erase unmapped refid and pos if ( algn.isUnmap() ) { algn.putRefId(-1); algn.putPos(-1); } if ( algn.isMateUnmap() ) { algn.putNextRefId(-1); algn.putNextPos(-1); } Pout->writeAlignment(algn); } Pout.reset(); if ( Pmd5cb ) { Pmd5cb->saveDigestAsFile(md5filename); } if ( Pindex ) { Pindex->flush(std::string(indexfilename)); } return 0; }
int main() { char powerfile[]="Power.txt"; GetPower(powerfile); /* * 声明核中的变量 */ std::vector<double> Vcore; std::vector<double> Rcore; //std::vector<double> ecore;//核的热容中的电流源部分 //std::vector<double> rcore;//核的热容中的热阻部分 //std::vector<double> Ipoint; /* * 声明基底中的变量 */ double Vbase(Tamb); double Ibase; double Rbase((r_conduct+r_fan)/A);//初始化基底的热阻,/@param A表示从密度换算 double ebase(0); double rbase(h/(2*(c_conduct*A)));//初始化基底的热容中的热阻部分=@param h/2@param c,*@param A表示从密度换算 /* * 初始化基底中的@param Vbase和@param ebase */ for(int i=0;i<CoreNumber;i++) { Rcore.push_back(r_bulk/Acore.at(i));//初始化核中的热阻,/@param Acore表示从密度换算 } /* * 初始化核中的@param Vcore和@param ecore */ for(int i=0;i<CoreNumber;i++) { Vcore.push_back(Tamb); //rcore.push_back(h/(2*(c_bulk*Acore.at(i))));//初始化@param rcore=@param h/2@param c,*@param Acore表示从密度换算 //ecore.push_back(0); } /* * 二级等效电路中,计算热阻和热容热阻部分的等效值 */ std::vector<double> r; for(int i=0;i<CoreNumber;i++) { r.push_back(Rcore.at(i));//计算等效值 } double rtmp=r.at(0);//用来计算@param Vbase的临时变量,是所有@param rcore的并联值 double Itmp(0); /* * 计算@param Vbase时用到的热阻并联和 */ for(int i=0;i<CoreNumber-1;i++) { rtmp=Pararlle(rtmp,r.at(i+1));//计算并联值 } rtmp=Pararlle(rtmp,Pararlle(Rbase,rbase));//与@param Rbase并联 /* * @brief 打开输出文件,并相应的打印表头 * 主要的输出内容:@param Vore、@param Pcore、@param Vbase、@param compareVbase */ std::ofstream Vout("Vcore.txt"); std::ofstream Pout("Pcore.txt"); std::ofstream Bout("Base.txt"); if(not Vout) std::perror("Vcore.txt"); if(not Bout) std::perror("Pcore.txt"); if(not Pout) std::perror("Base.txt"); Vout.precision(SetPrecision); Bout.precision(SetPrecision); Pout.precision(SetPrecision); for(int i=0;i<CoreNumber;i++) Pout<<std::setw(SetWidth)<<std::right<<"Pcore("<<i+1<<")"; Pout<<"\n"; for(int i=0;i<CoreNumber;i++) Vout<<std::setw(SetWidth)<<std::right<<"Vcore("<<i+1<<")"; Vout<<std::endl; Bout<<std::setw(SetWidth)<<"R(bc)Cb="<<Pararlle(Rbase,Rcore[0])*c_conduct<<"\n"; Bout<<std::setw(SetWidth)<<"VBase"; Bout<<std::setw(SetWidth)<<"Charge"<<"\n"; std::vector<double> Vref; std::vector<double> newPower; for(int i=0;i<CoreNumber;i++) { Vref.push_back(Vcore.at(i)); newPower.push_back(CorePower.at(i)); } double eps(1); double compareVbase(0); do { for(std::vector<double>::iterator i=Vcore.begin();i!=Vcore.end();i++) Vout<<std::setw(SetWidth)<<*i+amb<<"\t"; Vout<<std::endl; for(std::vector<double>::iterator i=newPower.begin();i!=newPower.end();i++) Pout<<std::setw(SetWidth)<<*i; Pout<<"\n"; Bout<<std::setw(SetWidth)<<Vbase; Bout<<std::setw(SetWidth)<<compareVbase<<"\n"; for(int i=0;i<CoreNumber;i++) { Vref.at(i)=Vcore.at(i); } /* * 刷新@param Vbase以及@param ebase */ Itmp=0;//用来计算@param Vbase的临时变量,是所有核内电流的和 for(int j=0;j<CoreNumber;j++) { newPower.at(j)=CorePower.at(j)+LeakagePower(Vcore.at(j));//刷新实际的功耗值(密度)=源功耗+漏电流功耗 //Ipoint.at(j)=(newPower.at(j)*rcore.at(j)/r.at(j)); Itmp+=newPower.at(j);//计算@param Itmp,需要每次刷新 } Itmp+=ebase; /* * 刷新@param Vcore,@param Vbase的值 */ Vbase=rtmp*Itmp; double SumNewPower=0;//计算所有核的实际功耗总值,用以计算稳定@param Vcore以及充电曲线中的@param Vbase for(int i=0;i<CoreNumber;i++) { SumNewPower+=newPower.at(i); } compareVbase=ChargeLine(SumNewPower,Rbase,c_conduct*A,IterNumber++);//注意:@param Cbase=@param c_conduct*@param A for(int i=0;i<CoreNumber;i++) { Vcore.at(i)=Vbase+newPower.at(i)*Rcore.at(i); } /* * 刷新@param Ibase,@param ebase的值 */ Ibase=0; for(int i=0;i<CoreNumber;i++) { Ibase+=(Vcore.at(i)-Vbase)/Rcore.at(i); } Ibase+=-Vbase/Rbase; ebase=Vbase/rbase+Ibase;//计算@param ebase,需要每次刷新 /* * 根据@param eps(@param Icore的前后迭代差)判断迭代的收敛情况 */ eps=0; for(int i=0;i<CoreNumber;i++) { Vref.at(i)=std::fabs(Vref.at(i)-Vcore.at(i)); eps=std::max(Vref.at(i),eps); } }while(std::fabs(eps)>0.000001); std::vector<double> Vstable=StableVcore(newPower,Rcore,Rbase);//@param Vstable看作是理论稳定温度 注意:计算中用的是新的稳定后的功耗向量 char charVstable[]="Vstable"; DisplayVector(Vstable,charVstable);//输出稳定温度值用来对比而已(打开Vstable.txt) Vout.close(); Bout.close(); Pout.close(); return 0; }
int bamsort(::libmaus::util::ArgInfo const & arginfo) { ::libmaus::util::TempFileRemovalContainer::setup(); bool const inputisstdin = (!arginfo.hasArg("I")) || (arginfo.getUnparsedValue("I","-") == "-"); bool const outputisstdout = (!arginfo.hasArg("O")) || (arginfo.getUnparsedValue("O","-") == "-"); if ( isatty(STDIN_FILENO) && inputisstdin && (arginfo.getValue<std::string>("inputformat","bam") != "sam") ) { ::libmaus::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) && outputisstdout && (arginfo.getValue<std::string>("outputformat","bam") != "sam") ) { ::libmaus::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()); bool const disablevalidation = arginfo.getValue<int>("disablevalidation",getDefaultDisableValidation()); std::string const inputformat = arginfo.getUnparsedValue("inputformat",getDefaultInputFormat()); int const level = arginfo.getValue<int>("level",getDefaultLevel()); switch ( level ) { case Z_NO_COMPRESSION: case Z_BEST_SPEED: case Z_BEST_COMPRESSION: case Z_DEFAULT_COMPRESSION: break; default: { ::libmaus::exception::LibMausException se; se.getStream() << "Unknown compression level, please use" << " level=" << Z_DEFAULT_COMPRESSION << " (default) or" << " level=" << Z_BEST_SPEED << " (fast) or" << " level=" << Z_BEST_COMPRESSION << " (best) or" << " level=" << Z_NO_COMPRESSION << " (no compression)" << std::endl; se.finish(); throw se; } break; } // prefix for tmp files std::string const tmpfilenamebase = arginfo.getValue<std::string>("tmpfile",arginfo.getDefaultTmpFileName()); std::string const tmpfilenameout = tmpfilenamebase + "_bamsort"; ::libmaus::util::TempFileRemovalContainer::addTempFile(tmpfilenameout); uint64_t blockmem = arginfo.getValue<uint64_t>("blockmb",getDefaultBlockSize())*1024*1024; std::string const sortorder = arginfo.getValue<std::string>("SO","coordinate"); bool const fixmates = arginfo.getValue<int>("fixmates",getDefaultFixMates()); uint64_t sortthreads = arginfo.getValue<uint64_t>("sortthreads",getDefaultSortThreads()); // input decoder wrapper libmaus::bambam::BamAlignmentDecoderWrapper::unique_ptr_type decwrapper( libmaus::bambam::BamMultiAlignmentDecoderFactory::construct( arginfo,false // put rank ) ); ::libmaus::bambam::BamAlignmentDecoder * ppdec = &(decwrapper->getDecoder()); ::libmaus::bambam::BamAlignmentDecoder & dec = *ppdec; if ( disablevalidation ) dec.disableValidation(); ::libmaus::bambam::BamHeader const & header = dec.getHeader(); std::string const headertext(header.text); // add PG line to header std::string const upheadtext = ::libmaus::bambam::ProgramHeaderLineSet::addProgramLine( headertext, "bamsort", // ID "bamsort", // PN arginfo.commandline, // CL ::libmaus::bambam::ProgramHeaderLineSet(headertext).getLastIdInChain(), // PP std::string(PACKAGE_VERSION) // VN ); // construct new header ::libmaus::bambam::BamHeader uphead(upheadtext); /* * start index/md5 callbacks */ std::string const tmpfileindex = tmpfilenamebase + "_index"; ::libmaus::util::TempFileRemovalContainer::addTempFile(tmpfileindex); std::string md5filename; std::string indexfilename; std::vector< ::libmaus::lz::BgzfDeflateOutputCallback * > cbs; ::libmaus::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() ) { ::libmaus::lz::BgzfDeflateOutputCallbackMD5::unique_ptr_type Tmd5cb(new ::libmaus::lz::BgzfDeflateOutputCallbackMD5); Pmd5cb = UNIQUE_PTR_MOVE(Tmd5cb); cbs.push_back(Pmd5cb.get()); } } libmaus::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() ) { libmaus::bambam::BgzfDeflateOutputCallbackBamIndex::unique_ptr_type Tindex(new libmaus::bambam::BgzfDeflateOutputCallbackBamIndex(tmpfileindex)); Pindex = UNIQUE_PTR_MOVE(Tindex); cbs.push_back(Pindex.get()); } } std::vector< ::libmaus::lz::BgzfDeflateOutputCallback * > * Pcbs = 0; if ( cbs.size() ) Pcbs = &cbs; /* * end md5/index callbacks */ if ( sortorder != "queryname" ) uphead.changeSortOrder("coordinate"); else uphead.changeSortOrder("queryname"); libmaus::bambam::BamBlockWriterBase::unique_ptr_type Pout ( libmaus::bambam::BamBlockWriterBaseFactory::construct(uphead, arginfo, Pcbs) ); if ( fixmates ) { if ( sortorder != "queryname" ) { ::libmaus::bambam::BamEntryContainer< ::libmaus::bambam::BamAlignmentPosComparator > BEC(blockmem,tmpfilenameout,sortthreads); if ( verbose ) std::cerr << "[V] Reading alignments from source." << std::endl; uint64_t incnt = 0; // current alignment libmaus::bambam::BamAlignment & curalgn = dec.getAlignment(); // previous alignment libmaus::bambam::BamAlignment prevalgn; // previous alignment valid bool prevalgnvalid = false; // MQ field filter libmaus::bambam::BamAuxFilterVector MQfilter; MQfilter.set("MQ"); while ( dec.readAlignment() ) { if ( curalgn.isSecondary() || curalgn.isSupplementary() ) { BEC.putAlignment(curalgn); } else if ( prevalgnvalid ) { // different name if ( strcmp(curalgn.getName(),prevalgn.getName()) ) { BEC.putAlignment(prevalgn); curalgn.swap(prevalgn); } // same name else { libmaus::bambam::BamAlignment::fixMateInformation(prevalgn,curalgn,MQfilter); BEC.putAlignment(prevalgn); BEC.putAlignment(curalgn); prevalgnvalid = false; } } else { prevalgn.swap(curalgn); prevalgnvalid = true; } if ( verbose && ( ( ++incnt & ((1ull<<20)-1) ) == 0 ) ) std::cerr << "[V] " << incnt << std::endl; } if ( prevalgnvalid ) { BEC.putAlignment(prevalgn); prevalgnvalid = false; } if ( verbose ) std::cerr << "[V] read " << incnt << " alignments" << std::endl; // BEC.createOutput(std::cout, uphead, level, verbose, Pcbs); BEC.createOutput(*Pout, verbose); } else { ::libmaus::bambam::BamEntryContainer< ::libmaus::bambam::BamAlignmentNameComparator > BEC(blockmem,tmpfilenameout,sortthreads); if ( verbose ) std::cerr << "[V] Reading alignments from source." << std::endl; uint64_t incnt = 0; // current alignment libmaus::bambam::BamAlignment & curalgn = dec.getAlignment(); // previous alignment libmaus::bambam::BamAlignment prevalgn; // previous alignment valid bool prevalgnvalid = false; // MQ field filter libmaus::bambam::BamAuxFilterVector MQfilter; MQfilter.set("MQ"); while ( dec.readAlignment() ) { if ( curalgn.isSecondary() || curalgn.isSupplementary() ) { BEC.putAlignment(curalgn); } else if ( prevalgnvalid ) { // different name if ( strcmp(curalgn.getName(),prevalgn.getName()) ) { BEC.putAlignment(prevalgn); curalgn.swap(prevalgn); } // same name else { libmaus::bambam::BamAlignment::fixMateInformation(prevalgn,curalgn,MQfilter); BEC.putAlignment(prevalgn); BEC.putAlignment(curalgn); prevalgnvalid = false; } } else { prevalgn.swap(curalgn); prevalgnvalid = true; } if ( verbose && ( ( ++incnt & ((1ull<<20)-1) ) == 0 ) ) std::cerr << "[V] " << incnt << std::endl; } if ( prevalgnvalid ) { BEC.putAlignment(prevalgn); prevalgnvalid = false; } if ( verbose ) std::cerr << "[V] read " << incnt << " alignments" << std::endl; // BEC.createOutput(std::cout, uphead, level, verbose, Pcbs); BEC.createOutput(*Pout, verbose); } } else { if ( sortorder != "queryname" ) { ::libmaus::bambam::BamEntryContainer< ::libmaus::bambam::BamAlignmentPosComparator > BEC(blockmem,tmpfilenameout,sortthreads); if ( verbose ) std::cerr << "[V] Reading alignments from source." << std::endl; uint64_t incnt = 0; while ( dec.readAlignment() ) { BEC.putAlignment(dec.getAlignment()); incnt++; if ( verbose && (incnt % (1024*1024) == 0) ) std::cerr << "[V] " << incnt/(1024*1024) << "M" << std::endl; } if ( verbose ) std::cerr << "[V] read " << incnt << " alignments" << std::endl; // BEC.createOutput(std::cout, uphead, level, verbose, Pcbs); BEC.createOutput(*Pout, verbose); } else { ::libmaus::bambam::BamEntryContainer< ::libmaus::bambam::BamAlignmentNameComparator > BEC(blockmem,tmpfilenameout,sortthreads); if ( verbose ) std::cerr << "[V] Reading alignments from source." << std::endl; uint64_t incnt = 0; while ( dec.readAlignment() ) { BEC.putAlignment(dec.getAlignment()); incnt++; if ( verbose && (incnt % (1024*1024) == 0) ) std::cerr << "[V] " << incnt/(1024*1024) << "M" << std::endl; } if ( verbose ) std::cerr << "[V] read " << incnt << " alignments" << std::endl; // BEC.createOutput(std::cout, uphead, level, verbose, Pcbs); BEC.createOutput(*Pout, verbose); } } // flush encoder so callbacks see all output data Pout.reset(); if ( Pmd5cb ) { Pmd5cb->saveDigestAsFile(md5filename); } if ( Pindex ) { Pindex->flush(std::string(indexfilename)); } return EXIT_SUCCESS; }
int main(int argc, char * argv[]) { try { libmaus2::util::ArgInfo const arginfo(argc,argv); std::string const isain = arginfo.getUnparsedRestArg(0); std::string const isaout = arginfo.getUnparsedRestArg(1); std::string const tmpdir = arginfo.getUnparsedValue("tmpdir",arginfo.getCurDir()); std::string const tmpout = tmpdir + "/" + arginfo.getDefaultTmpFileName() + "_sort_isa.tmp"; libmaus2::util::TempFileRemovalContainer::addTempFile(tmpout); // std::string const tmpout = isaout + ".tmp"; uint64_t const sortbufsize = arginfo.getValueUnsignedNumeric<uint64_t>("sortbufsize",16*1024*1024); uint64_t const inbufsize = arginfo.getValueUnsignedNumeric<uint64_t>("inbufsize",8*1024); bool const verbose = arginfo.getValue<int>("verbose",1); libmaus2::aio::OutputStream::unique_ptr_type Ptmp(libmaus2::aio::OutputStreamFactoryContainer::constructUnique(tmpout)); libmaus2::aio::SortingBufferedOutput< std::pair<uint64_t,uint64_t> >::unique_ptr_type Psortout( new libmaus2::aio::SortingBufferedOutput< std::pair<uint64_t,uint64_t> >(*Ptmp,sortbufsize)); libmaus2::aio::InputStream::unique_ptr_type Pin(libmaus2::aio::InputStreamFactoryContainer::constructUnique(isain)); libmaus2::aio::SynchronousGenericInput<uint64_t> Sin(*Pin,inbufsize); uint64_t v0 = 0, v1 = 0; uint64_t c_in = 0; while ( Sin.peekNext(v0) ) { bool const ok0 = Sin.getNext(v0); assert ( ok0 ); bool const ok1 = Sin.getNext(v1); if ( ! ok1 ) { libmaus2::exception::LibMausException lme; lme.getStream() << "Uneven number of words in input file." << std::endl; lme.finish(); throw lme; } Psortout->put(std::pair<uint64_t,uint64_t>(v1,v0)); c_in += 1; if ( verbose && (c_in & (1024*1024-1)) == 0 ) std::cerr << "[V] in " << c_in/(1024*1024) << std::endl; } Psortout->flush(); std::vector<uint64_t> const blocksizes = Psortout->getBlockSizes(); Psortout.reset(); Ptmp->flush(); Ptmp.reset(); // libmaus2::aio::InputStream::unique_ptr_type Ptmpin(libmaus2::aio::InputStreamFactoryContainer::constructUnique(tmpout)); libmaus2::sorting::MergingReadBack< std::pair<uint64_t,uint64_t> >::unique_ptr_type Min( new libmaus2::sorting::MergingReadBack< std::pair<uint64_t,uint64_t> >(tmpout,blocksizes) ); std::pair<uint64_t,uint64_t> P; libmaus2::aio::OutputStream::unique_ptr_type Pout(libmaus2::aio::OutputStreamFactoryContainer::constructUnique(isaout)); uint64_t c_out = 0; bool gotfirst = false; bool gotfirstdif = false; bool difconsistent = true; uint64_t firstpos = std::numeric_limits<uint64_t>::max(); uint64_t prevpos = std::numeric_limits<uint64_t>::max(); uint64_t firstdif = std::numeric_limits<uint64_t>::max(); libmaus2::util::Histogram hist; while ( Min->getNext(P) ) { libmaus2::util::NumberSerialisation::serialiseNumber(*Pout,P.first); libmaus2::util::NumberSerialisation::serialiseNumber(*Pout,P.second); c_out += 1; if ( verbose && (c_out & (1024*1024-1)) == 0 ) std::cerr << "[V] out " << static_cast<double>(c_out) / c_in << " first pos " << firstpos << " first dif " << firstdif << " consistent " << difconsistent << std::endl; if ( ! gotfirst ) { gotfirst = true; firstpos = P.first; } else { assert ( prevpos != std::numeric_limits<uint64_t>::max() ); assert ( P.first > prevpos ); uint64_t const dif = P.first - prevpos; hist(dif); if ( ! gotfirstdif ) { gotfirstdif = true; firstdif = dif; } else { if ( dif != firstdif ) difconsistent = false; } } prevpos = P.first; } if ( verbose ) std::cerr << "[V] out " << static_cast<double>(c_out) / c_in << " first pos " << firstpos << " first dif " << firstdif << " consistent " << difconsistent << std::endl; Min.reset(); Pout->flush(); Pout.reset(); hist.print(std::cerr); } catch(std::exception const & ex) { std::cerr << ex.what() << std::endl; } }