File: DNATuple.cpp

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 (93 lines) | stat: -rw-r--r-- 2,550 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <alignment/tuples/DNATuple.hpp>

DNATuple::DNATuple() : pos(0) {}

DNATuple::DNATuple(const DNATuple &rhs) : BaseTuple(rhs), pos(rhs.pos) {}

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

    //
    // Tuples are created with the right-most character
    // in the most significant bit in the sequence.
    //
    DNASequence tmpSeq;
    tmpSeq.seq = strPtr;
    tmpSeq.length = tm.tupleSize;
    if (!OnlyACTG(tmpSeq)) return 0;

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

    tuple = 0;
    Nucleotide *p;
    for (p = strPtr + tm.tupleSize - 1; p > strPtr; p--) {
        tuple += TwoBit[*p];
        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];
    return 1;
}

int DNATuple::MakeRC(DNATuple &dest, TupleMetrics &tm)
{
    int i;
    TupleData tempTuple = tuple;
    dest.tuple = 0;
    TupleData mask = 0x3;
    if (tm.tupleSize == 0) return 0;
    for (i = 0; i < tm.tupleSize - 1; i++) {
        dest.tuple += (~tempTuple & mask);
        tempTuple >>= 2;
        dest.tuple <<= 2;
    }
    dest.tuple += (~tempTuple & mask);
    return 1;
}

std::string DNATuple::ToString(TupleMetrics &tm)
{
    int i;
    std::string s;
    TupleData tempTuple = tuple;
    for (i = 0; i < tm.tupleSize; i++) {
        s.insert(s.begin(), TwoBitToAscii[tempTuple & 3]);
        tempTuple = tempTuple >> 2;
    }
    return s;
}

bool CompareByTuple::operator()(const DNATuple &lhs, const DNATuple &rhs) const
{
    return lhs.tuple < rhs.tuple;
}

CountedDNATuple::CountedDNATuple(const CountedDNATuple &rhs) : DNATuple(rhs), count(rhs.count) {}

PositionDNATuple::PositionDNATuple() : DNATuple() { pos = static_cast<DNALength>(-1); }

PositionDNATuple::PositionDNATuple(const PositionDNATuple &rhs) : DNATuple(rhs) {}

PositionDNATuple::PositionDNATuple(const PositionDNATuple &tupleP, const DNALength posP)
    : DNATuple(tupleP)
{
    pos = posP;
}

int PositionDNATuple::operator==(const DNATuple &pTuple) const { return tuple == pTuple.tuple; }

int OrderPositionDNATuplesByPosition::operator()(const PositionDNATuple &lhs,
                                                 const PositionDNATuple &rhs) const
{
    return lhs.pos < rhs.pos;
}

int OrderPositionDNATuplesByTuple::operator()(const PositionDNATuple &lhs,
                                              const PositionDNATuple &rhs) const
{
    return lhs.tuple < rhs.tuple;
}