139{
140
142
143 if((filePtr == NULL) || (filePtr->
isOpen() ==
false))
144 {
145
147 "filePtr does not point to an open file.");
148 return;
149 }
150
151
152
153 if(myFirstRecord.Length() != 0)
154 {
155 buffer = myFirstRecord;
156 myFirstRecord.Clear();
157 }
158 else
159 {
160
161 buffer.Clear();
162 buffer.ReadLine(filePtr);
163
164 if ((
ifeof(filePtr)) && (buffer.Length() == 0))
165 {
166
168 "No more records in the file.");
169 return;
170 }
171 }
172
173 tokens.ReplaceColumns(buffer, '\t');
174
175
176
178
179 if (tokens.Length() < 11)
180 {
181 errorString = "Too few columns (";
182 errorString += tokens.Length();
183 errorString += ") in the Record, expected at least 11.";
185 errorString.c_str());
186 return;
187 }
188
189
191
193 {
195 }
196
197 long flagInt = 0;
198 if(!tokens[1].AsInteger(flagInt))
199 {
200 errorString = "flag, ";
201 errorString += tokens[1].c_str();
202 errorString += ", is not an integer.";
204 errorString.c_str());
205 }
206 else if((flagInt < 0) || (flagInt > UINT16_MAX))
207 {
208 errorString = "flag, ";
209 errorString += tokens[1].c_str();
210 errorString += ", is not between 0 and (2^16)-1 = 65535.";
212 errorString.c_str());
213 }
214 else if(!record.
setFlag(flagInt))
215 {
218 }
219
221 {
224 }
225
226 long posInt = 0;
227 if(!tokens[3].AsInteger(posInt))
228 {
229 errorString = "position, ";
230 errorString += tokens[3].c_str();
231 errorString += ", is not an integer.";
233 errorString.c_str());
234 }
235 else if((posInt < INT32_MIN) || (posInt > INT32_MAX))
236 {
237
238 errorString = "position, ";
239 errorString += tokens[3].c_str();
240 errorString += ", does not fit in a 32 bit signed int.";
242 errorString.c_str());
243 }
245 {
248 }
249
250 long mapInt = 0;
251 if(!tokens[4].AsInteger(mapInt))
252 {
253 errorString = "map quality, ";
254 errorString += tokens[4].c_str();
255 errorString += ", is not an integer.";
257 errorString.c_str());
258 }
259 else if((mapInt < 0) || (mapInt > UINT8_MAX))
260 {
261 errorString = "map quality, ";
262 errorString += tokens[4].c_str();
263 errorString += ", is not between 0 and (2^8)-1 = 255.";
265 errorString.c_str());
266 }
268 {
271 }
272
274 {
277 }
278
280 {
283 }
284
285 long matePosInt = 0;
286 if(!tokens[7].AsInteger(matePosInt))
287 {
288 errorString = "mate position, ";
289 errorString += tokens[7].c_str();
290 errorString += ", is not an integer.";
292 errorString.c_str());
293 }
295 {
298 }
299
300 long insertInt = 0;
301 if(!tokens[8].AsInteger(insertInt))
302 {
303 errorString = "insert size, ";
304 errorString += tokens[8].c_str();
305 errorString += ", is not an integer.";
307 errorString.c_str());
308 }
310 {
313 }
314
316 {
319 }
320
322 {
325 }
326
327
329
330
331 for (int i = 11; i < tokens.Length(); i++)
332 {
333 String & nugget = tokens[i];
334
335 if (nugget.Length() < 6 || nugget[2] != ':' || nugget[4] != ':')
336 {
337
338 errorString = "Invalid Tag Format: ";
339 errorString += nugget.c_str();
340 errorString += ", should be cc:c:x*.";
342 errorString.c_str());
343 continue;
344 }
345
346
347
348 if(!record.
addTag((
const char *)nugget, nugget[3],
349 (const char *)nugget + 5))
350 {
353 }
354 }
355
356 return;
357}
bool setReadName(const char *readName)
Set QNAME to the passed in name.
void clearTags()
Clear the tags in this record.
bool setInsertSize(int32_t insertSize)
Sets the inferred insert size (ISIZE)/observed template length (TLEN).
bool setMateReferenceName(SamFileHeader &header, const char *mateReferenceName)
Set the mate/next fragment's reference sequence name (RNEXT) to the specified name,...
bool setMapQuality(uint8_t mapQuality)
Set the mapping quality (MAPQ).
bool addTag(const char *tag, char vtype, const char *value)
Add the specified tag,vtype,value to the record.
void resetRecord()
Reset the fields of the record to a default value.
bool setFlag(uint16_t flag)
Set the bitwise FLAG to the specified value.
bool set1BasedPosition(int32_t position)
Set the leftmost position (POS) using the specified 1-based (SAM format) value.
const SamStatus & getStatus()
Returns the status associated with the last method that sets the status.
bool setCigar(const char *cigar)
Set the CIGAR to the specified SAM formatted cigar string.
bool setSequence(const char *seq)
Sets the sequence (SEQ) to the specified SAM formatted sequence string.
bool set1BasedMatePosition(int32_t matePosition)
Set the mate/next fragment's leftmost position (PNEXT) using the specified 1-based (SAM format) value...
bool setQuality(const char *quality)
Sets the quality (QUAL) to the specified SAM formatted quality string.
bool setReferenceName(SamFileHeader &header, const char *referenceName)
Set the reference sequence name (RNAME) to the specified name, using the header to determine the refe...
const char * getStatusMessage() const
Return the status message for this object.
@ NO_MORE_RECS
NO_MORE_RECS: failed to read a record since there are no more to read either in the file or section i...
@ SUCCESS
method completed successfully.
Status getStatus() const
Return the enum for this status object.
void addError(Status newStatus, const char *newMessage)
Add the specified error message to the status message, setting the status to newStatus if the current...