/usr/include/pbseq/alignment/tuples/DNATupleImpl.hpp is in libblasr-dev 0~20161219-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | #include <cassert>
#include "../../pbdata/NucConversion.hpp"
inline int DNATuple::FromStringLR(Nucleotide *strPtr, TupleMetrics &tm) {
DNASequence tmpSeq;
tmpSeq.seq = strPtr;
tmpSeq.length = tm.tupleSize;
if (!OnlyACTG(tmpSeq))
return 0;
if (tm.tupleSize == 0)
return 1;
tuple = 0;
Nucleotide *p;
Nucleotide *endPtr = &strPtr[tm.tupleSize - 1];
for (p = strPtr; p != endPtr; p++) {
// If it is not possible to convert this string, return null.
if (ThreeBit[*p] > 3) {
return 0;
}
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;
}
inline int DNATuple::ShiftAddRL(Nucleotide nuc, TupleMetrics &tm) {
if (ThreeBit[nuc] > 3) {
return 0;
}
else {
tuple >>= 2;
tuple += (TwoBit[nuc] << ((tm.tupleSize-1)*2));
return 1;
}
}
template<typename Sequence>
int SearchSequenceForTuple(Sequence &seq, TupleMetrics &tm, DNATuple &queryTuple) {
DNALength p;
PositionDNATuple tempTuple, upperTuple;
p = 0;
DNALength cur = 0;
DNALength curValidEnd = 0;
//
// Construct the mask-off bit pair for the shifted tuple.
//
PositionDNATuple maskLeftTuple;
maskLeftTuple.tuple = 3;
maskLeftTuple.tuple = maskLeftTuple.tuple << 2*tm.tupleSize;
maskLeftTuple.tuple = ~maskLeftTuple.tuple;
PositionDNATuple testTuple;
while (curValidEnd < seq.length) {
//
// Search for the next available window that can be translated into a tuple.
//
cur = curValidEnd;
while(curValidEnd < seq.length and IsACTG[seq.seq[curValidEnd]]) {
curValidEnd++;
}
if (curValidEnd - cur >= static_cast<DNALength>(tm.tupleSize)) {
//
// Found a span that does not have N's in it,
//
assert (tempTuple.FromStringRL(&(seq.seq[cur]), tm) == 1);
p = cur;
if (tempTuple.tuple == queryTuple.tuple) {
return 1;
}
for (p++; p < curValidEnd - tm.tupleSize + 1; p++) {
tempTuple.tuple >>=2;
// tempTuple.tuple &= maskLeftTuple.tuple;
upperTuple.tuple = TwoBit[seq.seq[p+tm.tupleSize-1]];
upperTuple.tuple = upperTuple.tuple << (2 * (tm.tupleSize-1));
tempTuple.tuple += upperTuple.tuple;
if (tempTuple.tuple == queryTuple.tuple) {
return 1;
}
}
}
else {
++curValidEnd;
}
}
}
template<typename Sequence>
int SequenceToTupleList(Sequence &seq, TupleMetrics &tm, TupleList<DNATuple> &tupleList) {
DNALength p;
PositionDNATuple tempTuple, upperTuple;
p = 0;
DNALength cur = 0;
DNALength curValidEnd = 0;
//
// Construct the mask-off bit pair for the shifted tuple.
//
PositionDNATuple maskLeftTuple;
maskLeftTuple.tuple = 3;
maskLeftTuple.tuple = maskLeftTuple.tuple << 2*tm.tupleSize;
maskLeftTuple.tuple = ~maskLeftTuple.tuple;
PositionDNATuple testTuple;
while (curValidEnd < seq.length) {
//
// Search for the next available window that can be translated into a tuple.
//
cur = curValidEnd;
while(curValidEnd < seq.length and IsACTG[seq.seq[curValidEnd]]) {
curValidEnd++;
}
if (curValidEnd - cur >= static_cast<DNALength>(tm.tupleSize)) {
//
// Found a span that does not have N's in it,
//
assert (tempTuple.FromStringRL(&(seq.seq[cur]), tm) == 1);
p = cur;
tupleList.Append(tempTuple);
for (p++; p < curValidEnd - tm.tupleSize + 1; p++) {
tempTuple.tuple >>=2;
// tempTuple.tuple &= maskLeftTuple.tuple;
upperTuple.tuple = TwoBit[seq.seq[p+tm.tupleSize-1]];
upperTuple.tuple = upperTuple.tuple << (2 * (tm.tupleSize-1));
tempTuple.tuple += upperTuple.tuple;
//testTuple.FromStringRL(&seq.seq[p], tm);
//assert(testTuple.tuple == tempTuple.tuple);
tupleList.Append(tempTuple);
}
}
else {
++curValidEnd;
}
}
return tupleList.size();
}
template<typename Sequence>
int SequenceToTupleList(Sequence &seq, TupleMetrics &tm, TupleList<PositionDNATuple> &tupleList) {
DNALength p;
PositionDNATuple tempTuple, upperTuple;
p = 0;
DNALength cur = 0;
DNALength curValidEnd = 0;
//
// Construct the mask-off bit pair for the shifted tuple.
//
PositionDNATuple maskLeftTuple;
maskLeftTuple.tuple = 3;
maskLeftTuple.tuple = maskLeftTuple.tuple << 2*tm.tupleSize;
maskLeftTuple.tuple = ~maskLeftTuple.tuple;
PositionDNATuple testTuple;
while (curValidEnd < seq.length) {
//
// Search for the next available window that can be translated into a tuple.
//
cur = curValidEnd;
while(curValidEnd < seq.length and IsACTG[seq.seq[curValidEnd]]) {
curValidEnd++;
}
if (curValidEnd - cur >= static_cast<DNALength>(tm.tupleSize)) {
//
// Found a span that does not have N's in it,
//
assert (tempTuple.FromStringRL(&(seq.seq[cur]), tm) == 1);
p = cur;
tempTuple.pos = p;
tupleList.Append(tempTuple);
for (p++; p < curValidEnd - tm.tupleSize + 1; p++) {
tempTuple.tuple >>=2;
// tempTuple.tuple &= maskLeftTuple.tuple;
upperTuple.tuple = TwoBit[seq.seq[p+tm.tupleSize-1]];
upperTuple.tuple = upperTuple.tuple << (2 * (tm.tupleSize-1));
tempTuple.tuple += upperTuple.tuple;
tempTuple.pos = p;
//testTuple.FromStringRL(&seq.seq[p], tm);
//assert(testTuple.tuple == tempTuple.tuple);
tupleList.Append(tempTuple);
}
}
else {
++curValidEnd;
}
}
return tupleList.size();
}
|