libStatGen Software 1
PackedRead Class Reference
Collaboration diagram for PackedRead:

Public Member Functions

int size ()
 
void clear ()
 
void set (const char *rhs, int padWithNCount=0)
 
uint8_t operator[] (int index)
 

Public Attributes

std::vector< uint8_t > packedBases
 
uint32_t length
 

Detailed Description

Definition at line 141 of file GenomeSequenceHelpers.h.

Member Function Documentation

◆ clear()

void PackedRead::clear ( )
inline

Definition at line 157 of file GenomeSequenceHelpers.h.

158 {
159 packedBases.clear();
160 length=0;
161 }

◆ operator[]()

uint8_t PackedRead::operator[] ( int  index)
inline

Definition at line 163 of file GenomeSequenceHelpers.h.

164 {
165 return (packedBases[index>>1] >> ((index&0x1)<<2)) & 0xf;
166 }

◆ set()

void PackedRead::set ( const char *  rhs,
int  padWithNCount = 0 
)

Definition at line 56 of file GenomeSequence.cpp.

57{
58 clear();
59
60 // pad this packed read with 'N' bases two at a time
61 while (padWithNCount>1)
62 {
63 packedBases.push_back(
64 BaseAsciiMap::base2int[(int) 'N'] << 4 |
65 BaseAsciiMap::base2int[(int) 'N']
66 );
67 padWithNCount -= 2;
68 length+=2;
69 }
70
71 // when we have only one base, pack one 'N' base with
72 // the first base in rhs if there is one.
73 if (padWithNCount)
74 {
75 // NB: *rhs could be NUL, which is ok here - just keep
76 // the length straight.
77 packedBases.push_back(
78 BaseAsciiMap::base2int[(int) *rhs] << 4 |
79 BaseAsciiMap::base2int[(int) 'N']
80 );
81 // two cases - have characters in rhs or we don't:
82 if (*rhs)
83 {
84 length+=2; // pad byte plus one byte from rhs
85 rhs++;
86 }
87 else
88 {
89 length++;
90 }
91 padWithNCount--; // should now be zero, so superfluous.
92 assert(padWithNCount==0);
93 }
94
95 // pad pairs of bases from rhs, two at a time:
96 while (*rhs && *(rhs+1))
97 {
98 packedBases.push_back(
99 BaseAsciiMap::base2int[(int) *(rhs+1)] << 4 |
100 BaseAsciiMap::base2int[(int) *(rhs+0)]
101 );
102 rhs+=2;
103 length+=2;
104 }
105
106 // if there is an odd base left at the end, put it
107 // in a byte all its own (low 4 bits == 0):
108 if (*rhs)
109 {
110 packedBases.push_back(
111 BaseAsciiMap::base2int[(int) *(rhs+0)]
112 );
113 length++;
114 }
115 return;
116}
static unsigned char base2int[256+1]
Map ASCII values to a 2 (or 3) bit encoding for the base pair value for just base space (ACTGNactgn).
Definition: BaseAsciiMap.h:61

◆ size()

int PackedRead::size ( )
inline

Definition at line 153 of file GenomeSequenceHelpers.h.

154 {
155 return length;
156 }

Member Data Documentation

◆ length

uint32_t PackedRead::length

Definition at line 152 of file GenomeSequenceHelpers.h.

◆ packedBases

std::vector<uint8_t> PackedRead::packedBases

Definition at line 151 of file GenomeSequenceHelpers.h.


The documentation for this class was generated from the following files: