File: CompressedDNATuple.hpp

package info (click to toggle)
pbseqlib 5.3.5%2Bdfsg-10
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 7,148 kB
  • sloc: cpp: 77,259; python: 331; sh: 103; makefile: 41
file content (66 lines) | stat: -rw-r--r-- 1,932 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef _BLASR_COMPRESSED_DNA_TUPLE_HPP_
#define _BLASR_COMPRESSED_DNA_TUPLE_HPP_

#include <alignment/tuples/DNATuple.hpp>
#include <pbdata/CompressedSequence.hpp>

template <typename T_Sequence>
class CompressedDNATuple : public DNATuple
{
    static const unsigned char mask = 0xf;

public:
    CompressedDNATuple(const CompressedDNATuple &rhs) : DNATuple(rhs) {}

    int FromStringLR(Nucleotide *strPtr, TupleMetrics &tm)
    {
        //
        // Make sure the sequence contains all valid characters.
        //

        if (!CompressedSequence<T_Sequence>::Only4BitACTG(strPtr, tm.tupleSize)) return 0;

        if (tm.tupleSize == 0) return 1;

        tuple = 0;
        Nucleotide *p;
        Nucleotide *endPtr = &strPtr[tm.tupleSize - 1];
        for (p = strPtr; p != endPtr; p++) {
            tuple += TwoBit[*p & mask];
            tuple <<= 2;
        }
        //
        // The tuple size is guaranteed to be at least
        // 1, so it's safe to add the last value.
        // This cannot be in the previous loop since
        // the shift shouldn't happen.
        tuple += TwoBit[*p & mask];
        return 1;
    }

    int FromStringRL(Nucleotide *strPtr, TupleMetrics &tm)
    {

        if (!CompressedSequence<T_Sequence>::Only4BitACTG((CompressedNucleotide *)strPtr,
                                                          tm.tupleSize))
            return 0;

        if (tm.tupleSize == 0) return 1;

        tuple = 0;
        Nucleotide *p;
        for (p = strPtr + tm.tupleSize - 1; p > strPtr; p--) {
            tuple += TwoBit[*p & mask];
            tuple <<= 2;
        }
        //
        // The tuple size is guaranteed to be at least
        // 1, so it's safe to add the last value.
        // This cannot be in the previous loop since
        // the shift shouldn't happen.
        tuple += TwoBit[*p & mask];
        return 1;
    }
};

#endif  // _BLASR_COMPRESSED_DNA_TUPLE_HPP_