Commit 12d23da1 by Eric Coissac

Patch bugs in the decoding functions

parent 67bbf042
......@@ -42,9 +42,9 @@ char * decode(buffer_t *buffer, uint32_t recordid, uint32_t begin, int32_t lengt
dest = (char*)PTR8(dest);
idest = (uint16_t*)dest;
from = recordid * buffer->recordSize + (begin >> 2);
shift = begin & 3;
lcompact = length / 8 + ((length & 7) ? 1:0);
from = recordid * buffer->recordSize + ((begin >> 2) & 0xFFFFFFFE);
shift = begin & 7;
lcompact = (length+shift) / 8 + (((length+shift) & 7) ? 1:0);
for (compactseq = (uint16_t*)(buffer->records + from), i=0;
i < lcompact;
......@@ -60,11 +60,11 @@ char * decode(buffer_t *buffer, uint32_t recordid, uint32_t begin, int32_t lengt
char *decodeComp(buffer_t *buffer, uint32_t recordid, uint32_t begin, int32_t length, char *dest)
{
static char internal[MAXREADLEN+9];
char internal2[MAXREADLEN+9];
char internal2[MAXREADLEN+9];
uint64_t* idest;
uint32_t from;
uint32_t shift;
int32_t i;
int32_t i;
uint32_t lcompact;
uint32_t mask;
uint16_t *compactseq;
......@@ -78,17 +78,34 @@ char *decodeComp(buffer_t *buffer, uint32_t recordid, uint32_t begin, int32_t le
dest2 = (char*)PTR8(internal2);
idest = (uint16_t*)dest;
key = READEND(buffer,buffer->order1[recordid]) - (begin >> 2);
lkey = CODELENGTH(buffer->readSize) - (begin >> 2) + 1;
from = buffer->readSize - begin;
// lkey -> length of the compacted sequence to unpack
// old version potentially with a bug
// lkey = CODELENGTH(buffer->readSize) - (begin >> 2) + 1;
lkey = CODELENGTH(from);
// key -> pointer to the byte of the compacted sequence containing
// the position begin on the complementary sequence
// old version potentially with a bug
// key = READEND(buffer,buffer->order1[recordid]) - (begin >> 2);
key = READSTART(buffer,buffer->order1[recordid])+lkey-1;
// reverse complement the read in the dest2 buffer in a compact form
for (i=0; i<lkey;i++)
dest2[i]=complement4nuc[*(((uint8_t*)(key)-i))];
shift = (begin & 3) + (buffer->readSize & 3);
// (buffer->readSize & 3) : base count encoded by the last byte
// old version potentially with a bug
// shift = (begin & 3) + (buffer->readSize & 3);
shift = (4 - (from & 3)) & 3;
ASSERT (shift <4,"There is a bug readsize = %d length = %d shift=%d",buffer->readSize,begin,shift)
ASSERT (shift <4,"There is a bug readsize = %d begin = %d shift=%d",buffer->readSize,begin,shift)
lcompact = length / 8 + ((length & 7) ? 1:0);
lcompact = (length+shift) / 8 + (((length+shift) & 7) ? 1:0);
for (compactseq = (uint16_t*)(dest2), i=0;
i < lcompact;
......
......@@ -38,7 +38,7 @@
#define PTR16(p) (void*)(((size_t)(p) & ((size_t)~((size_t)0xF))) + (((size_t)(p) & 0xF) ? (0x10):0))
#define PTR8(p) (void*)(((size_t)(p) & ((size_t)~((size_t)0x7))) + (((size_t)(p) & 0x7) ? (0x8):0))
#define CODELENGTH(x) (((x)>>2) + ((x & 3) ? 1:0))
#define CODELENGTH(x) (((x)>>2) + (((x) & 3) ? 1:0))
#define READSTART(buf,id) ((pnuc)((buf)->records + (buf)->recordSize * (id)))
#define READEND(buf,id) (READSTART((buf),(id))+CODELENGTH((buf)->readSize)-1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment