void f2() { srand(time(NULL)); int size=1536; map<int,int> counts; uint64_t samples=100000000; uint64_t base=rand(); int wordSize=63; Kmer kmer; kmer.setU64(0,base); int average=samples/size; while(samples--) { uint64_t second=rand(); kmer.setU64(1,second); int rank=vertexRank(&kmer,size,wordSize,false); counts[rank]++; } vector<int> data; for(int i=0; i<size; i++) { data.push_back(counts[i]); //cout<<i<<" "<<counts[i]<<endl; } int deviation=average/10; int min=average-deviation; int max=average+deviation; for(int i=0; i<size; i++) { if(counts[i]>=max) { cout<<counts[i]<<" and Max="<<max<<endl; } assert(counts[i]<max); assert(counts[i]>min); } }
/** * Get the ingoing edges * one bit (1=yes, 0=no) per possible edge */ vector<Kmer> Kmer::_getIngoingEdges(uint8_t edges,int k){ vector<Kmer> b; Kmer aTemplate; aTemplate=*this; int posToClear=2*k; for(int i=0;i<aTemplate.getNumberOfU64();i++){ uint64_t element=aTemplate.getU64(i); element=element<<2; // 1 0 // // 127..64 63...0 // // 00abcdefgh ijklmnopqr // initial state // abcdefgh00 klmnopqr00 // shift left // abcdefghij klmnopqr00 // copy the last to the first // 00cdefghij klmnopqr00 // reset the 2 last /** * Now, we need to copy 2 bits from */ if(i!=0){ // the 2 last of the previous will be the 2 first of this one uint64_t last=getU64(i-1); last=(last>>62); element=element|last; } /** * The two last bits that shifted must be cleared * Otherwise, it will change the hash value of the Kmer... * The chunk number i contains bits from i to i*64-1 * Therefore, if posToClear is inside these boundaries, * then it is obvious that these awful bits must be changed * to 0 */ if(i*64<=posToClear&&posToClear<i*64+64){ int position=posToClear%64; uint64_t filter=3;// 11 or 1*2^1+1*2^0 filter=filter<<(position); filter=~filter; element=element&filter; } aTemplate.setU64(i,element); }
Kmer wordId(const char*a){ Kmer i; int theLen=strlen(a); for(int j=0;j<(int)theLen;j++){ uint64_t k=charToCode(a[j]); int bitPosition=2*j; int chunk=bitPosition/64; int bitPositionInChunk=bitPosition%64; #ifdef ASSERT if(!(chunk<i.getNumberOfU64())){ cout<<"Chunk="<<chunk<<" positionInKmer="<<j<<" KmerLength="<<strlen(a)<<" bitPosition=" <<bitPosition<<" Chunks="<<i.getNumberOfU64()<<endl; } assert(chunk<i.getNumberOfU64()); #endif uint64_t filter=(k<<bitPositionInChunk); i.setU64(chunk,i.getU64(chunk)|filter); } return i; }
/** * Get the outgoing edges * one bit (1=yes, 0=no) per possible edge */ vector<Kmer> Kmer::_getOutgoingEdges(uint8_t edges,int k){ vector<Kmer> b; Kmer aTemplate; aTemplate=*this; for(int i=0;i<aTemplate.getNumberOfU64();i++){ uint64_t word=aTemplate.getU64(i)>>2; if(i!=aTemplate.getNumberOfU64()-1){ uint64_t next=aTemplate.getU64(i+1); /* * abcd efgh * 00ab 00ef * 00ab cdef */ next=(next<<62); word=word|next; } aTemplate.setU64(i,word); } int positionToUpdate=2*k; int chunkIdToUpdate=positionToUpdate/64; positionToUpdate=positionToUpdate%64; for(int i=0;i<4;i++){ int j=((((uint64_t)edges)<<(sizeof(uint64_t)*8-5-i))>>(sizeof(uint64_t)*8-1)); if(j==1){ Kmer newKmer=aTemplate; uint64_t last=newKmer.getU64(chunkIdToUpdate); uint64_t filter=i; filter=filter<<(positionToUpdate-2); last=last|filter; newKmer.setU64(chunkIdToUpdate,last); b.push_back(newKmer); } } return b; }