/* * Attempt to open the disk described by (dev) for use by (f). * * Note that the philosophy here is "give them exactly what * they ask for". This is necessary because being too "smart" * about what the user might want leads to complications. * (eg. given no slice or partition value, with a disk that is * sliced - are they after the first BSD slice, or the DOS * slice before it?) */ static int bd_open(struct open_file *f, ...) { va_list ap; struct i386_devdesc *dev; struct open_disk *od; int error; va_start(ap, f); dev = va_arg(ap, struct i386_devdesc *); va_end(ap); if ((error = bd_opendisk(&od, dev))) return(error); BD(dev).bd_open++; if (BD(dev).bd_bcache == NULL) BD(dev).bd_bcache = bcache_allocate(); /* * Save our context */ ((struct i386_devdesc *)(f->f_devdata))->d_kind.biosdisk.data = od; DEBUG("open_disk %p, partition at 0x%x", od, od->od_boff); return(0); }
static int bd_close(struct open_file *f) { struct i386_devdesc *dev = f->f_devdata; struct open_disk *od = (struct open_disk *)(dev->d_kind.biosdisk.data); BD(dev).bd_open--; if (BD(dev).bd_open == 0) { bcache_free(BD(dev).bd_bcache); BD(dev).bd_bcache = NULL; } bd_closedisk(od); return(0); }
ContainmentResult TestSphereSphere ( Sphere const & A, Sphere const & B ) { // ---------- // do a quick outside test first Vector delta = B.getCenter() - A.getCenter(); real dist2 = delta.magnitudeSquared(); real sumRadius = A.getRadius() + B.getRadius(); real sumRadius2 = sumRadius * sumRadius; if(dist2 > sumRadius2) { return CR_Outside; } else if(dist2 == sumRadius2) //lint !e777 // testing floats for equality { return CR_TouchingOutside; } else { // ---------- // and if that fails do the full test real dist = sqrt(dist2); Range AD( dist - A.getRadius(), dist + A.getRadius() ); Range BD( -B.getRadius(), B.getRadius() ); return Containment1d::TestRangeRange( AD, BD ); } }
static int bd_strategy(void *devdata, int rw, daddr_t dblk, size_t size, char *buf, size_t *rsize) { struct bcache_devdata bcd; struct i386_devdesc *dev = devdata; struct open_disk *od = (struct open_disk *)(dev->d_kind.biosdisk.data); bcd.dv_strategy = bd_realstrategy; bcd.dv_devdata = devdata; bcd.dv_cache = BD(dev).bd_bcache; return(bcache_strategy(&bcd, rw, dblk+od->od_boff, size, buf, rsize)); }
ContainmentResult TestCylinderCylinder ( Cylinder const & A, Cylinder const & B ) { Vector delta = B.getBase() - A.getBase(); delta.y = 0; real dist = delta.magnitude(); Range AD( dist - A.getRadius(), dist + A.getRadius() ); Range BD( -B.getRadius(), B.getRadius() ); ContainmentResult hTest = Containment1d::TestRangeRange( AD, BD ); ContainmentResult vTest = Containment1d::TestRangeRange( A.getRangeY(), B.getRangeY() ); // ---------- return Containment::ComposeAxisTests(hTest,vTest); }
int bamfilter(libmaus::util::ArgInfo const & arginfo) { uint64_t const minmapped = arginfo.getValue<uint64_t>("minmapped",getDefaultMinMapped()); uint64_t const maxmapped = arginfo.getValue<uint64_t>("maxmapped",getDefaultMaxMapped()); uint64_t const minlen = arginfo.getValue<uint64_t>("minlen",getDefaultMinLen()); int const level = libmaus::bambam::BamBlockWriterBaseFactory::checkCompressionLevel(arginfo.getValue<int>("level",getDefaultLevel())); ::libmaus::bambam::BamDecoder BD(std::cin); ::libmaus::bambam::BamHeader const & bamheader = BD.getHeader(); ::libmaus::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"; ::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 */ ::libmaus::bambam::BamHeader::unique_ptr_type uphead(libmaus::bambam::BamHeaderUpdate::updateHeader(arginfo,bamheader,"bamfilter",std::string(PACKAGE_VERSION))); ::libmaus::bambam::BamWriter::unique_ptr_type writer(new ::libmaus::bambam::BamWriter(std::cout,*uphead,level,Pcbs)); while ( BD.readAlignment() ) { bool const a_1_mapped = !(alignment.getFlags() & ::libmaus::bambam::BamFlagBase::LIBMAUS_BAMBAM_FUNMAP); bool const a_2_mapped = !(alignment.getFlags() & ::libmaus::bambam::BamFlagBase::LIBMAUS_BAMBAM_FMUNMAP); bool const proper = (alignment.getFlags() & ::libmaus::bambam::BamFlagBase::LIBMAUS_BAMBAM_FPROPER_PAIR); uint64_t const nummapped = (a_1_mapped?1:0)+(a_2_mapped?1:0)+(proper?1:0); if ( nummapped >= minmapped && nummapped <= maxmapped && alignment.getLseq() >= static_cast<int64_t>(minlen) ) alignment.serialise(writer->getStream()); } writer.reset(); if ( Pmd5cb ) { Pmd5cb->saveDigestAsFile(md5filename); } if ( Pindex ) { Pindex->flush(std::string(indexfilename)); } return EXIT_SUCCESS; }
void CCorrelationFilters::fusion_matrix_inverse(Eigen::ArrayXXcd &X, Eigen::MatrixXi indices) { /* We compute the inverse of the fusion matrix by using the schur complement * on our data structure. We use an inplace implementation therefore it is quite * memory efficient as well. */ int num_blocks=0; int total_blocks=0; int size_blocks = X.rows(); if (indices.rows() != indices.cols()){ std::cout << "Something Wrong" << std::endl; return; } else { num_blocks = indices.rows(); } if (num_blocks == 1){ X = X.inverse(); return; } if (num_blocks == 2) { Eigen::ArrayXXcd temp1; Eigen::ArrayXXcd temp2; Eigen::ArrayXXcd DC(size_blocks,1); Eigen::ArrayXXcd BD(size_blocks,1); Eigen::ArrayXXcd BDC(size_blocks,1); Eigen::ArrayXXcd ABDC(size_blocks,1); DC = X.block(0,indices(1,0),size_blocks,1)/X.block(0,indices(1,1),size_blocks,1); BD = X.block(0,indices(0,1),size_blocks,1)/X.block(0,indices(1,1),size_blocks,1); BDC = X.block(0,indices(0,1),size_blocks,1)*DC; ABDC = (X.block(0,indices(0,0),size_blocks,1)-BDC).inverse(); X.block(0,indices(0,0),size_blocks,1) = ABDC; X.block(0,indices(0,1),size_blocks,1) = -ABDC*BD; X.block(0,indices(1,0),size_blocks,1) = -DC*ABDC; X.block(0,indices(1,1),size_blocks,1) = 1/X.block(0,indices(1,1),size_blocks,1) - X.block(0,indices(1,0),size_blocks,1)*BD; } else { int num_B = num_blocks-1; int num_C = num_blocks-1; Eigen::MatrixXi ind_A; Eigen::MatrixXi ind_B; Eigen::MatrixXi ind_C; Eigen::MatrixXi ind_D; total_blocks = num_blocks*num_blocks; ind_D = indices.block(num_blocks-1,num_blocks-1,1,1); ind_B = indices.block(0,num_blocks-1,num_blocks-1,1); ind_C = indices.block(num_blocks-1,0,1,num_blocks-1); ind_A = indices.block(0,0,num_blocks-1,num_blocks-1).transpose(); num_blocks = num_blocks-1; Eigen::ArrayXXcd D = Eigen::ArrayXXcd::Zero(size_blocks,1); Eigen::ArrayXXcd DC = Eigen::ArrayXXcd::Zero(size_blocks,num_blocks); Eigen::ArrayXXcd BD = Eigen::ArrayXXcd::Zero(size_blocks,num_blocks); Eigen::ArrayXXcd BDC = Eigen::ArrayXXcd::Zero(size_blocks,num_blocks*num_blocks); Eigen::ArrayXXcd ABDC = Eigen::ArrayXXcd::Zero(size_blocks,num_blocks*num_blocks); Eigen::ArrayXXcd tmp_B = Eigen::ArrayXXcd::Zero(size_blocks,num_B); Eigen::ArrayXXcd tmp_C = Eigen::ArrayXXcd::Zero(size_blocks,num_C); Eigen::ArrayXXcd tmp_D = Eigen::ArrayXXcd::Zero(size_blocks,1); for(int i=0;i<num_C;i++){ tmp_C.block(0,i,size_blocks,1) = X.block(0,ind_C(0,i),size_blocks,1); } for(int i=0;i<num_B;i++){ tmp_B.block(0,i,size_blocks,1) = X.block(0,ind_B(i,0),size_blocks,1); } D.block(0,0,size_blocks,1) = X.block(0,total_blocks-1,size_blocks,1).inverse(); Eigen::Vector2i num_blocks_1, num_blocks_2; num_blocks_1 << 1,1; num_blocks_2 << 1,num_blocks; fusion_matrix_multiply(DC,D,tmp_C,num_blocks_1,num_blocks_2); num_blocks_1 << num_blocks,1; num_blocks_2 << 1,1; fusion_matrix_multiply(BD,tmp_B,D,num_blocks_1,num_blocks_2); num_blocks_1 << num_blocks,1; num_blocks_2 << 1,num_blocks; fusion_matrix_multiply(BDC,tmp_B,DC,num_blocks_1,num_blocks_2); for(int i=0;i<ind_A.rows();i++){ for(int j=0;j<ind_A.cols();j++){ X.block(0,ind_A(i,j),size_blocks,1) -= BDC.block(0,i,size_blocks,1); } } fusion_matrix_inverse(X,ind_A); tmp_B = Eigen::ArrayXXcd::Zero(size_blocks,num_B); tmp_C = Eigen::ArrayXXcd::Zero(size_blocks,num_C); tmp_D = Eigen::ArrayXXcd::Zero(size_blocks,1); num_blocks_1 << num_blocks,num_blocks; num_blocks_2 << num_blocks,1; fusion_matrix_multiply(tmp_B,ABDC,BD,num_blocks_1,num_blocks_2); for(int i=0;i<num_B;i++){ X.block(0,ind_B(i,0),size_blocks,1) = -tmp_B.block(0,i,size_blocks,1); } num_blocks_1 << 1,num_blocks; num_blocks_2 << num_blocks,num_blocks; fusion_matrix_multiply(tmp_C,DC,ABDC,num_blocks_1,num_blocks_2); for(int i=0;i<num_C;i++){ X.block(0,ind_C(0,i),size_blocks,1) = -tmp_C.block(0,i,size_blocks,1); } tmp_C = Eigen::ArrayXXcd::Zero(size_blocks,num_C); num_blocks_1 << 1,num_blocks; num_blocks_2 << num_blocks,num_blocks; fusion_matrix_multiply(tmp_C,DC,ABDC,num_blocks_1,num_blocks_2); num_blocks_1 << 1,num_blocks; num_blocks_2 << num_blocks,1; fusion_matrix_multiply(tmp_D,tmp_C,BD,num_blocks_1,num_blocks_2); tmp_D += D; X.block(0,total_blocks-1,size_blocks,1) = tmp_D.block(0,0,size_blocks,1); } }
/* returns 1 if GPRs have been modified */ int _rvec_io_write( int dummy_rvec, ulong mphys_ioaddr, void *usr_data ) { int op, op_ext, rS, rA, rB, d, flag=0, ret=0; ulong ea, cont, len, inst=mregs->inst_opcode; enum { byte=1, half=2, word=4, len_mask=7, indexed=8, update=16, reverse=32, nop=64, fpinst=128 }; /* do_io_write() is considered FPU-unsafe */ shield_fpu( mregs ); /* break instruction into parts */ op = OPCODE_PRIM( inst ); op_ext = OPCODE_EXT( inst ); rS = B1( inst ); /* bit 6-10 */ rA = B2( inst ); /* bit 11-15 */ rB = B3( inst ); /* bit 16-20 */ d = BD( inst ); /* bit 16-31 sign extended */ switch( op ) { case 38: /* stb rS,d(rA) */ flag = byte ; break; case 39: /* stbu rS,d(rA) */ flag = byte | update; break; case 44: /* sth rS,d(rA) */ flag = half ; break; case 45: /* sthu rS,d(rA) */ flag = half | update; break; case 36: /* stw rS,d(rA) */ flag = word ; break; case 37: /* stwud rS,d(rA) */ flag = word | update; break; case 54: /* stfd frS,d(rA) */ /* FPU */ flag = word | fpinst; break; case 55: /* stfdu frS,d(rA) */ /* FPU */ flag = word | fpinst | update; break; } if( !flag && op==31 ) { switch( op_ext ) { case 215: /* stbx rS,rA,rB */ flag = byte | indexed ; break; case 247: /* stbux rS,rA,rB */ flag = byte | indexed | update; break; case 407: /* sthx rS,rA,rB */ flag = half | indexed ; break; case 439: /* sthux rS,rA,rB */ flag = half | indexed | update; break; case 151: /* stwx rS,rA,rB */ flag = word | indexed ; break; case 183: /* stwux rS,rA,rB */ flag = word | indexed | update; break; case 918: /* sthbrx rS,rA,rB */ flag = half | indexed | reverse; break; case 662: /* stwbrx rS,rA,rB */ flag = word | indexed | reverse; break; case 727: /* stfdx frS,rA,rB */ /* printm("FPU store inst\n"); */ flag = word | indexed | fpinst; break; case 759: /* stfdux frS,rA,rB */ /* printm("FPU store inst\n"); */ flag = word | indexed | update | fpinst; break; } } if( flag & len_mask ) { /* instruction found */ if( flag & indexed ) { /* stxxx rS,rA,rB */ ea = mregs->gpr[rB]; ea += rA ? mregs->gpr[rA] : 0; } else { /* stxxx rS,d(rA) */ ea = rA ? mregs->gpr[rA] : 0; ea += d; } if( !(flag & fpinst ) ) cont = mregs->gpr[rS]; else { save_fpu_completely( mregs ); cont = mregs->fpr[rS].h; } len = flag & len_mask; if( flag & byte ) { cont &= 0xff; } else if( flag & half ) { if( !(flag & reverse) ) cont &= 0xffff; else cont = bswap_16( cont ); } else if( flag & reverse ) cont = ld_le32(&cont); /* ea is the mac untranslated address, * mregs->mmu_ioaddr holds the translated address */ do_io_write( usr_data, mphys_ioaddr, cont, len ); if( flag & fpinst ) { if( ((mphys_ioaddr+4) & 0xfff) < 4 ) printm("emulate store data inst: Possible MMU translation error\n"); do_io_write( usr_data, mphys_ioaddr+4, mregs->fpr[rS].l, 4 ); } if( (flag & update) && rA ) { mregs->gpr[rA] = ea; ret = 1; } } if( flag ) mregs->nip += 4; else { printm("Unimplemented store instruction %08lX\n", inst ); stop_emulation(); } return ret; }
/* returns 1 if GPRs have been modified */ int _rvec_io_read( int dummy_rvec, ulong mphys_ioaddr, void *usr_data ) { ulong ea, cont, inst=mregs->inst_opcode; int op, op_ext, rD, rA, rB, d; int flag=0, ret=1; enum { byte=1, half=2, word=4, len_mask=7, indexed=8, update=16, zero=32, reverse=64, nop=128, fpinst=256 }; /* do_io_read() is considered FPU-unsafe */ shield_fpu( mregs ); /* break instruction into parts */ op = OPCODE_PRIM( inst ); /* bit 0-5 */ op_ext = OPCODE_EXT( inst ); rD = B1( inst ); /* bit 6-10 */ rA = B2( inst ); /* bit 11-15 */ rB = B3( inst ); /* bit 16-20 */ d = BD( inst ); /* bit 16-31 sign extended */ switch( op ) { case 34: /* lbz rD,d(rA) */ flag = byte | zero; break; case 35: /* lbzu rD,d(rA) */ flag = byte | zero | update; break; case 40: /* lhz rD,d(rA) */ flag = half | zero; break; case 41: /* lhzu rD,d(rA) */ flag = half | zero | update; break; case 42: /* lha rD,d(rA) */ flag = half; break; case 43: /* lhau rD,d(rA) */ flag = half | update; break; case 32: /* lwz rD,d(rA) */ flag = word | zero; break; case 33: /* lwzu, rD,d(rA) */ flag = word | zero | update; break; case 50: /* lfd frD,d(rA) */ /* FPU */ flag = word | fpinst | zero; break; case 51: /* lfdu frD, d(rA) */ /* FPU */ flag = word | fpinst | update | zero; break; } if( !flag && op==31 ) { switch( op_ext ) { /* lxxx rD,rA,rB */ case 87: /* lbzx rD,rA,rB */ flag = byte | indexed | zero; break; case 119: /* lbzux rD,rA,rB */ flag = byte | indexed | zero | update; break; case 279: /* lhzx rD,rA,rB */ flag = half | indexed | zero; break; case 311: /* lhzux rD,rA,rB */ flag = half | indexed | zero | update; break; case 343: /* lhax rD,rA,rB */ flag = half | indexed; break; case 375: /* lhaux rD,rA,rB */ flag = half | indexed | update; break; case 23: /* lwzx rD,rA,rB */ flag = word | indexed | zero; break; case 55: /* lwzux rD,rA,rB */ flag = word | indexed | zero | update; break; case 790: /* lhbrx rS,rA,rB */ flag = half | indexed | zero | reverse; break; case 534: /* lwbrx rS,rA,rB */ flag = word | indexed | zero | reverse; break; case 599: /* lfdx frD,rA,rB */ /* FPU */ flag = word | indexed | zero | fpinst; break; case 631: /* lfdux frD,rA,rB */ /* FPU */ flag = word | indexed | zero | update | fpinst; break; case 86: /* dcbf rA,rB - cache instruction*/ /* treat as nop if data-translation is off */ flag = (mregs->msr & MSR_DR) ? 0 : nop; break; } } if( flag & len_mask) { /* instruction found */ if( flag & indexed ) { /* lxxx rD,rA,rB */ ea = mregs->gpr[rB]; ea += rA ? mregs->gpr[rA] : 0; } else { /* lxxx rD,d(rA) */ ea = rA ? mregs->gpr[rA] : 0; ea += d; } /* ea is the mac untranslated address, */ /* mphys_ioaddr is the mac-physical address */ cont = 0; do_io_read( usr_data, mphys_ioaddr, (flag & len_mask), &cont ); if( flag & byte ){ cont &= 0xff; } else if( flag & half ) { cont &= 0xffff; if( !(flag & zero) ) /* algebraic */ cont |= (cont & 0x8000)? 0xffff0000 : 0; if( flag & reverse ) cont = bswap_16( cont ); } else if( flag & reverse) cont = ld_le32(&cont); if( !(flag & fpinst) ) mregs->gpr[rD] = cont; else { /* FPU instruction */ save_fpu_completely( mregs ); ret = 0; mregs->fpr[rD].h = cont; /* check for 4K boundary crossings... */ if( ((mphys_ioaddr+4) & 0xfff) < 4 ) printm("emulate_load_data_inst: MMU translation might be bad\n"); do_io_read( usr_data, mphys_ioaddr+4, 4, &cont ); mregs->fpr[rD].l = cont; reload_tophalf_fpu( mregs ); } if( (flag & update) && rA && (rA!=rD || (flag & fpinst)) ) { ret = 1; mregs->gpr[rA] = ea; } } if( flag ) mregs->nip += 4; else { printm("Unimplemented load instruction %08lX\n", inst ); stop_emulation(); } return ret; }
int main(int argc, char *argv[]) { { libmaus2::lz::LineSplittingGzipOutputStream LSG("gzsplit",4,17); for ( uint64_t i = 0; i < 17; ++i ) LSG << "line_" << i << "\n"; } { libmaus2::lz::LineSplittingGzipOutputStream LSG("nogzsplit",4,17); } testGzip(); testlz4(); #if 0 maskBamDuplicateFlag(std::cin,std::cout); return 0; #endif #if 0 { libmaus2::lz::BgzfInflateDeflateParallel BIDP(std::cin,std::cout,Z_DEFAULT_COMPRESSION,32,128); 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 ( 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 ( isatty(STDERR_FILENO) ) std::cerr << "\r" << std::string(60,' ') << "\r"; std::cerr << rtc.formatTime(rtc.getElapsedSeconds()) << " " << t/(1024*1024) << "MB, " << (t/rtc.getElapsedSeconds())/(1024.0*1024.0) << "MB/s"; std::cerr << std::endl; return 0; } #endif #if 0 { ::libmaus2::lz::BgzfDeflateParallel BDP(std::cout,32,128,Z_DEFAULT_COMPRESSION); while ( std::cin ) { libmaus2::autoarray::AutoArray<char> B(16384); std::cin.read(B.begin(),B.size()); int64_t const r = std::cin.gcount(); BDP.write(B.begin(),r); } BDP.flush(); std::cout.flush(); } return 0; #endif #if 0 { try { libmaus2::lz::BgzfInflateParallel BIP(std::cin /* ,4,16 */); uint64_t c = 0; uint64_t b = 0; uint64_t d = 0; libmaus2::timing::RealTimeClock rtc; rtc.start(); libmaus2::autoarray::AutoArray<uint8_t> adata(64*1024,false); while ( (d=BIP.read(reinterpret_cast<char *>(adata.begin()),adata.size())) != 0 ) { b += d; if ( ++c % (16*1024) == 0 ) { std::cerr << c << "\t" << b/(1024.0*1024.0*1024.0) << "\t" << static_cast<double>(b)/(1024.0*1024.0*rtc.getElapsedSeconds()) << " MB/s" << std::endl; } } std::cerr << c << "\t" << b/(1024.0*1024.0*1024.0) << "\t" << static_cast<double>(b)/(1024.0*1024.0*rtc.getElapsedSeconds()) << " MB/s" << std::endl; std::cerr << "decoded " << b << " bytes in " << rtc.getElapsedSeconds() << " seconds." << std::endl; } catch(std::exception const & ex) { std::cerr << ex.what() << std::endl; return EXIT_FAILURE; } } return 0; #endif std::cerr << "Testing random data on bgzf..."; testBgzfRandom(); std::cerr << "done." << std::endl; std::cerr << "Testing mono..."; testBgzfMono(); std::cerr << "done." << std::endl; ::libmaus2::lz::BgzfDeflate<std::ostream> bdefl(std::cout); char const * str = "Hello, world.\n"; bdefl.write(reinterpret_cast<char const *>(str),strlen(str)); bdefl.flush(); bdefl.write(reinterpret_cast<char const *>(str),strlen(str)); bdefl.flush(); bdefl.addEOFBlock(); return 0; ::libmaus2::lz::BgzfInflateStream SW(std::cin); ::libmaus2::autoarray::AutoArray<char> BB(200,false); while ( SW.read(BB.begin(),BB.size()) ) { } if ( argc < 2 ) return EXIT_FAILURE; return 0; #if 0 ::libmaus2::lz::GzipHeader GZH(argv[1]); return 0; #endif std::ostringstream ostr; ::libmaus2::autoarray::AutoArray<uint8_t> message = ::libmaus2::util::GetFileSize::readFile(argv[1]); std::cerr << "Deflating message of length " << message.size() << "..."; ::libmaus2::lz::Deflate DEFL(ostr); DEFL.write ( reinterpret_cast<char const *>(message.begin()), message.size() ); DEFL.flush(); std::cerr << "done." << std::endl; std::cerr << "Checking output..."; std::istringstream istr(ostr.str()); ::libmaus2::lz::Inflate INFL(istr); int c; uint64_t i = 0; while ( (c=INFL.get()) >= 0 ) { assert ( c == message[i] ); i++; } std::cerr << "done." << std::endl; // std::cerr << "Message size " << message.size() << std::endl; std::string testfilename = "test"; ::libmaus2::lz::BlockDeflate BD(testfilename); BD.write ( message.begin(), message.size() ); BD.flush(); uint64_t const decpos = message.size() / 3; ::libmaus2::lz::BlockInflate BI(testfilename,decpos); ::libmaus2::autoarray::AutoArray<uint8_t> dmessage (message.size(),false); uint64_t const red = BI.read(dmessage.begin()+decpos,dmessage.size()); assert ( red == dmessage.size()-decpos ); std::cerr << "("; for ( uint64_t i = decpos; i < message.size(); ++i ) assert ( message[i] == dmessage[i] ); std::cerr << ")\n"; std::string shortmes1("123456789"); std::string shortmes2("AA"); std::string shortmes3("BB"); std::string shortmes4("CC"); std::string textfile1("test1"); std::string textfile2("test2"); std::string textfile3("test3"); std::string textfile4("test4"); ::libmaus2::lz::BlockDeflate BD1(textfile1); BD1.write ( reinterpret_cast<uint8_t const *>(shortmes1.c_str()), shortmes1.size() ); BD1.flush(); ::libmaus2::lz::BlockDeflate BD2(textfile2); BD2.write ( reinterpret_cast<uint8_t const *>(shortmes2.c_str()), shortmes2.size() ); BD2.flush(); ::libmaus2::lz::BlockDeflate BD3(textfile3); BD3.write ( reinterpret_cast<uint8_t const *>(shortmes3.c_str()), shortmes3.size() ); BD3.flush(); ::libmaus2::lz::BlockDeflate BD4(textfile4); BD4.write ( reinterpret_cast<uint8_t const *>(shortmes4.c_str()), shortmes4.size() ); BD4.flush(); std::vector < std::string > filenames; filenames.push_back(textfile1); filenames.push_back(textfile2); filenames.push_back(textfile3); filenames.push_back(textfile4); for ( uint64_t j = 0; j <= 15; ++j ) { ::libmaus2::lz::ConcatBlockInflate CBI(filenames,j); for ( uint64_t i = 0; i < j; ++i ) std::cerr << ' '; for ( uint64_t i = 0; i < CBI.n-j; ++i ) std::cerr << (char)CBI.get(); std::cerr << std::endl; } return 0; }
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 ) { alignment.putNextRefId(-1); alignment.putNextPos(-1); } alignment.serialise(writer->getStream()); } writer.reset(); if ( Pmd5cb ) { Pmd5cb->saveDigestAsFile(md5filename); } if ( Pindex ) { Pindex->flush(std::string(indexfilename)); } return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { Pooma::initialize(argc,argv); Pooma::Tester tester(argc,argv); #if POOMA_EXCEPTIONS try { #endif tester.out() << "\n\nTesting 5D slice-range subsetting...\n\n"; Interval<1> I(5); Interval<5> BD(I,I,I,I,I); Brick5_t b(BD); for (int i4 = 0; i4 < b.domain()[4].length(); ++i4) for (int i3 = 0; i3 < b.domain()[3].length(); ++i3) for (int i2 = 0; i2 < b.domain()[2].length(); ++i2) for (int i1 = 0; i1 < b.domain()[1].length(); ++i1) for (int i0 = 0; i0 < b.domain()[0].length(); ++i0) b(i0,i1,i2,i3,i4) = i4+10*(i3+10*(i2+10*(i1+10*i0))); tester.out() << "b.domain() = " << b.domain() << std::endl; tester.out() << std::endl; typedef NewDomain5<int, Range<1>, int, AllDomain<1>, Interval<1> > NewDomain_t; typedef NewDomain_t::SliceType_t SliceType_t; SliceType_t VD; AllDomain<1> A; Interval<1> I1(1,3); Range<1> R(0,4,2); NewDomain_t::fillSlice(VD, b.domain(), 2, R, 1, A, I1); tester.out() << "VD = " << VD << std::endl; typedef NewEngine<Brick5_t, SliceType_t>::Type_t Engine_t; Engine_t v(b, VD); // v.domain() should be: [0:2:1,0:4:1,0:2:1] tester.out() << "v.domain() = " << v.domain() << std::endl; // v's values should be 2 | 0,2,4 | 1 | 0,1,2,3,4 | 1,2,3 tester.out() << "v = \n"; for (int i2 = 0; i2 < v.domain()[2].length(); ++i2) for (int i1 = 0; i1 < v.domain()[1].length(); ++i1) for (int i0 = 0; i0 < v.domain()[0].length(); ++i0) tester.out() << v(i0,i1,i2) << std::endl; typedef NewDomain3<int, Range<1>, Interval<1> > NewDomain2_t; typedef NewDomain2_t::SliceType_t SliceType2_t; SliceType2_t VD2; Interval<1> I2(1,2); Range<1> R2(0,2,2); NewDomain2_t::fillSlice(VD2, v.domain(), 0, R2, I2); tester.out() << "VD2 = " << VD2 << std::endl; NewEngine<Engine_t, SliceType2_t>::Type_t v2(v, VD2); // v2.domain() should be: [0:1:1,0:1:1] tester.out() << "v2.domain() = " << v2.domain() << std::endl; // v2's values should be 2 | 0 | 1 | 0,2 | 2,3 tester.out() << "v2 = \n"; for (int i1 = 0; i1 < v2.domain()[1].length(); ++i1) for (int i0 = 0; i0 < v2.domain()[0].length(); ++i0) tester.out() << v2(i0,i1) << std::endl; #if POOMA_EXCEPTIONS } catch(const char *err) { tester.exceptionHandler( err ); tester.set( false ); } catch(const Pooma::Assertion &err) { tester.exceptionHandler( err ); tester.set( false ); } #endif int ret = tester.results("brickview_test1"); Pooma::finalize(); return ret; }
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; } } std::cerr << "[V] " << cnt << std::endl; } std::cerr << "[V] kept " << kept << " removed " << cnt-kept << std::endl; if ( Pmd5cb ) { Pmd5cb->saveDigestAsFile(md5filename); } if ( Pindex ) { Pindex->flush(std::string(indexfilename)); } return EXIT_SUCCESS; }