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
|
#ifndef _BLASR_QUALITY_VALUE_VECTOR_IMPL_HPP_
#define _BLASR_QUALITY_VALUE_VECTOR_IMPL_HPP_
#include <pbdata/NucConversion.hpp>
template <typename T_QV>
T_QV &QualityValueVector<T_QV>::operator[](unsigned int pos) const
{
return data[pos];
}
template <typename T_QV>
QualityValueVector<T_QV>::QualityValueVector()
{
data = NULL;
// Default to phred.
qvScale = PHRED;
_length = 0;
}
template <typename T_QV>
QualityProbability QualityValueVector<T_QV>::ToProbability(unsigned int pos)
{
return QualityValueToProbability(data[pos], qvScale);
}
template <typename T_QV>
T_QV QualityValueVector<T_QV>::ToPhred(unsigned int pos)
{
if (qvScale == PHRED) {
return data[pos];
} else {
return PacBioQVToPhred(data[pos]);
}
}
template <typename T_QV>
void QualityValueVector<T_QV>::Copy(const QualityValueVector<T_QV> &rhs, const DNALength length)
{
Free();
if (rhs.Empty()) {
return;
}
Allocate(length);
std::memcpy(data, rhs.data, length * sizeof(T_QV));
}
template <typename T_QV>
void QualityValueVector<T_QV>::Copy(const std::string &rhs)
{
// Char to QualityValue
Free();
if (rhs.size() == 0) return;
Allocate(static_cast<DNALength>(rhs.size()));
for (size_t i = 0; i < rhs.size(); i++) {
data[i] = static_cast<T_QV>(rhs[i] - FASTQ_CHAR_TO_QUALITY);
}
}
template <typename T_QV>
void QualityValueVector<T_QV>::Free()
{
if (data != NULL) {
delete[] data;
data = NULL;
}
_length = 0;
}
template <typename T_QV>
void QualityValueVector<T_QV>::Allocate(unsigned int length)
{
Free();
data = ProtectedNew<T_QV>(length);
_length = static_cast<DNALength>(length);
}
template <typename T_QV>
void QualityValueVector<T_QV>::Fill(const T_QV &value)
{
memset(data, value, sizeof(T_QV) * _length);
}
template <typename T_QV>
void QualityValueVector<T_QV>::Fill(const DNALength thisStart, const DNALength fillLength,
const QualityValueVector<T_QV> &rhs, const DNALength rhsStart)
{
assert(this->_length >= thisStart + fillLength);
assert(rhs.Length() >= rhsStart + fillLength);
memcpy(&this->data[thisStart], &rhs.data[rhsStart], sizeof(T_QV) * fillLength);
}
template <typename T_QV>
bool QualityValueVector<T_QV>::Empty() const
{
return data == NULL;
}
template <typename T_QV>
void QualityValueVector<T_QV>::ShallowCopy(const QualityValueVector<T_QV> &ref, int pos,
const DNALength &length)
{
data = &ref.data[pos];
qvScale = ref.qvScale;
_length = static_cast<DNALength>(length);
}
template <typename T_QV>
void QualityValueVector<T_QV>::ResetShallowData(void)
{
data = NULL;
qvScale = PHRED;
_length = 0;
}
template <typename T_QV>
std::string QualityValueVector<T_QV>::ToString(void)
{
if (data == NULL) {
return "";
}
std::string str(static_cast<size_t>(_length), '0');
for (DNALength i = 0; i < _length; i++) {
str[i] = static_cast<char>(data[i] + FASTQ_CHAR_TO_QUALITY);
}
return str;
}
template <typename T_QV>
DNALength QualityValueVector<T_QV>::Length(void) const
{
return _length;
}
template class QualityValueVector<QualityValue>;
#endif
|