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
|
#include <alignment/datastructures/anchoring/WeightedInterval.hpp>
WeightedInterval::WeightedInterval() {}
void WeightedInterval::Init(int _size, int _start, int _end, int _readIndex, float _pValue)
{
size = _size;
start = _start;
end = _end;
readIndex = _readIndex;
pValue = _pValue;
qStart = 0;
qEnd = 0;
nAnchors = 0;
totalAnchorSize = 0;
pValueVariance = 0;
pValueNStdDev = 0;
sizeVariance = 0;
sizeNStdDev = 0;
}
WeightedInterval::WeightedInterval(int _size, int _start, int _end, int _readIndex, float _pValue)
{
Init(_size, _start, _end, _readIndex, _pValue);
}
WeightedInterval::WeightedInterval(int _size, int _start, int _end, int _readIndex, float _pValue,
int _qStart, int _qEnd)
{
Init(_size, _start, _end, _readIndex, _pValue);
qStart = _qStart;
qEnd = _qEnd;
}
WeightedInterval::WeightedInterval(int _size, unsigned int _nAnchors, unsigned int _totalAnchorSize,
int _start, int _end, int _readIndex, float _pValue, int _qStart,
int _qEnd, std::vector<ChainedMatchPos> &_matches)
{
Init(_size, _start, _end, _readIndex, _pValue);
qStart = _qStart;
qEnd = _qEnd;
matches = _matches;
nAnchors = _nAnchors;
totalAnchorSize = _totalAnchorSize;
}
float WeightedInterval::PValue() const { return pValue; }
int WeightedInterval::Size() const { return size; }
int WeightedInterval::GetStrandIndex() const { return readIndex; }
void WeightedInterval::SetPValueVariance(float v) { pValueVariance = v; }
void WeightedInterval::SetPValueNStdDev(float v) { pValueNStdDev = v; }
void WeightedInterval::SetSizeVariance(float v) { sizeVariance = v; }
void WeightedInterval::SetSizeNStdDev(float v) { sizeNStdDev = v; }
int WeightedInterval::operator<(const WeightedInterval &intv) const
{
if (size == intv.size) {
return start > intv.start;
} else {
return size < intv.size;
}
}
int WeightedInterval::operator==(const WeightedInterval &intv) const { return size == intv.size; }
// Functions of class CompareWeightedIntervalByPValue
int CompareWeightedIntervalByPValue::operator()(const WeightedInterval &a,
const WeightedInterval &b) const
{
if (a.PValue() != b.PValue()) {
return a.PValue() < b.PValue();
} else {
return a.start < b.start;
}
}
// Functions of class WeightedIntervalSet
WeightedIntervalSet::WeightedIntervalSet() : maxSize(0) {}
WeightedIntervalSet::WeightedIntervalSet(const size_t maxSizeP) : maxSize(maxSizeP) {}
bool WeightedIntervalSet::insert(WeightedInterval &intv)
{
intv.isOverlapping = false;
//
// Make sure this interval is not contained inside any other
// weighted intervals.
//
WeightedIntervalSet::iterator it = (*this).begin();
WeightedIntervalSet::iterator endit = (*this).end();
bool isContained = false;
while (it != endit and isContained == false) {
if (intv.qStart >= (*it).qStart and intv.qEnd <= (*it).qEnd and
intv.start >= (*it).start and intv.end <= (*it).end and
intv.readIndex == (*it).readIndex and intv.pValue >= (*it).pValue) {
//
// This already overlaps an existing interval, don't bother
// trying to add it.
//
isContained = true;
intv.isOverlapping = true;
} else if ((*it).start >= intv.start and (*it).end <= intv.end and
(*it).qStart >= intv.qStart and (*it).qEnd <= intv.qEnd and
(*it).readIndex == intv.readIndex and (*it).pValue >= intv.pValue) {
WeightedIntervalSet::iterator next = it;
++next;
this->erase(it);
it = next;
} else {
++it;
}
}
//
// Take a peek to see if this interval is too low of a score to
// bother attempting to add at all.
//
if (size() >= maxSize and maxSize > 0) {
WeightedIntervalSet::iterator last = (*this).end();
last--;
if (last->pValue < intv.pValue) {
return false;
}
}
if (isContained == false) {
bool addInsert = false;
if (size() == 0) {
addInsert = true;
} else {
it = end();
--it;
if (size() < maxSize or (*it).pValue > intv.pValue) {
addInsert = true;
//
// Keep the size of the stack the same if it is at the limit.
//
if (maxSize != 0 and size() >= maxSize and size() > 0) {
erase(it);
}
}
}
if (addInsert) {
((T_WeightedIntervalMultiSet *)this)->insert(intv);
}
return true;
}
return false;
}
|