Esempio n. 1
0
        void EncodeQual(byte[] buffer, ref long i, BinaryWriter writer, FastqReader reader)
        {
            //the first byte starts with 0 if we are encoding a quality
            byte first = (byte)0;
            int  b     = 0;

            if (qualityRunLengthContinuation != 0)
            {
                buffer[b++] = (byte)qualityRunLengthContinuation;
                qualityRunLengthContinuation = 0;
            }
            while (reader.HasQLeft(i, 1) && b < BUFFER)
            {
                long j  = i + 1;
                int  rl = 1;
                while (reader.HasQLeft(j, 1) && reader.GetQ(j - 1) == reader.GetQ(j) && rl < MAX)
                {
                    j++;
                    rl++;
                }
                if (rl > 1)   //run length
                {
                    ae.GetBytes(reader.GetQ(j - 1).ToString(), 0, 1, buffer, b);
                    buffer[b] = (byte)(buffer[b] + 128);
                    b++;
                    if (b >= BUFFER)
                    {
                        qualityRunLengthContinuation = rl;
                    }
                    else
                    {
                        buffer[b++] = (byte)rl;
                    }
                    i = j;
                }
                else     //single char
                {
                    ae.GetBytes(reader.GetQ(i).ToString(), 0, 1, buffer, b);
                    b++;
                    i++;
                }
            }

            if (b == BUFFER)
            {
                writer.Write(first);
                writer.Write(buffer);
            }
            else
            {
                first += (byte)32;  //we have to tell the decoder that we have a block with a length
                                    //different than BUFFER
                writer.Write(first);
                writer.Write(b);
                writer.Write(buffer, 0, b);
            }
        }
Esempio n. 2
0
        void EncodeQual(byte[] buffer, ref long i, BinaryWriter writer, FastqReader reader)
        {
            int b = 0;

            if (qualityRunLengthContinuation != 0)
            {
                buffer[b++] = (byte)qualityRunLengthContinuation;
                qualityRunLengthContinuation = 0;
            }
            while (reader.HasQLeft(i, 1) && b < BUFFER)
            {
                long j  = i + 1;
                int  rl = 1;
                while (reader.HasQLeft(j, 1) && reader.GetQ(j - 1) == reader.GetQ(j) && rl < MAX)
                {
                    j++;
                    rl++;
                }
                if (rl > 1)   //run length
                //ae.GetBytes(reader.GetQ(j-1).ToString(), 0, 1, buffer, b);
                {
                    buffer[b] = Convert.ToByte(reader.GetQ(j - 1));
                    buffer[b] = (byte)(buffer[b] + 128);
                    b++;
                    if (b >= BUFFER)
                    {
                        qualityRunLengthContinuation = rl;
                    }
                    else
                    {
                        buffer[b++] = (byte)rl;
                    }
                    i = j;
                }
                else     //single char
                //ae.GetBytes(reader.GetQ(i).ToString(), 0, 1, buffer, b);
                {
                    buffer[b] = Convert.ToByte(reader.GetQ(i));
                    b++;
                    i++;
                }
            }

            if (b == BUFFER)
            {
                writer.Write(buffer);
            }
            else
            {
                writer.Write(buffer, 0, b);
            }
        }