libStatGen Software 1
Loading...
Searching...
No Matches
SamValidator Class Reference

The SamValidator class contains static methods for validating the SAM/BAM Record and each of its fields. More...

#include <SamValidation.h>

Static Public Member Functions

static bool isValid (SamFileHeader &samHeader, SamRecord &samRecord, SamValidationErrors &validationErrors)
 Validates whether or not the specified SamRecord is valid, calling all of the other validations.
 
static bool isValidQname (const char *qname, uint8_t qnameLen, SamValidationErrors &validationErrors)
 Determines whether or not the specified qname is valid.
 
static bool isValidFlag (uint16_t flag, SamValidationErrors &validationErrors)
 Determines whether or not the flag is valid.
 
static bool isValidRname (SamFileHeader &samHeader, const char *rname, SamValidationErrors &validationErrors)
 Validate the reference name including validating against the header.
 
static bool isValidRname (const char *rname, SamValidationErrors &validationErrors)
 Validate the rname without validating against the header.
 
static bool isValidRefID (int32_t refID, const SamReferenceInfo &refInfo, SamValidationErrors &validationErrors)
 Validate whether or not the specified reference id is valid.
 
static bool isValid1BasedPos (int32_t pos, SamValidationErrors &validationErrors)
 Validate the refeference position.
 
static bool isValidMapQuality (uint8_t mapQuality, SamValidationErrors &validationErrors)
 Validate the mapping quality.
 
static bool isValidSequence (SamRecord &samRecord, SamValidationErrors &validationErrors)
 Validate the sequence, but not against the cigar or quality string.
 
static bool isValidCigar (SamRecord &samRecord, SamValidationErrors &validationErrors)
 Validate the cigar.
 
static bool isValidCigar (const char *cigar, const char *sequence, SamValidationErrors &validationErrors)
 Validate the cigar.
 
static bool isValidCigar (const char *cigar, int seqLen, SamValidationErrors &validationErrors)
 Validate the cigar.
 
static bool isValidMrnm ()
 TODO: validate the mate/next fragment's reference name.
 
static bool isValidMpos ()
 TODO: validate the mate/next fragment's position.
 
static bool isValidIsize ()
 TODO: validate the insertion size/observed template length.
 
static bool isValidSeq ()
 TODO, validate the sequence.
 
static bool isValidQuality (SamRecord &samRecord, SamValidationErrors &validationErrors)
 Validate the base quality.
 
static bool isValidQuality (const char *quality, const char *sequence, SamValidationErrors &validationErrors)
 Validate the base quality.
 
static bool isValidQuality (const char *quality, int seqLength, SamValidationErrors &validationErrors)
 Validate the base quality.
 
static bool isValidTags (SamRecord &samRecord, SamValidationErrors &validationErrors)
 Validate the tags.
 
static bool isValidVtype ()
 TODO validate the tag vtype.
 
static bool isValidValue ()
 TODO validate the tag vtype.
 

Detailed Description

The SamValidator class contains static methods for validating the SAM/BAM Record and each of its fields.

The generic isValid method performs all of the other validations. The SamValidator methods return whether or not what is being validated is valid. True means it is valid, false means it is not. The specifics of the invalid value(s) are contained in the SamValidationErrors object that is passed in (by reference) to the method. The specific errors can be pulled out of that object. TODO: VALIDATION METHODS STILL NEED TO BE ADDED, and isValid does not yet validate all fields!!!

Definition at line 173 of file SamValidation.h.

Member Function Documentation

◆ isValid()

bool SamValidator::isValid ( SamFileHeader samHeader,
SamRecord samRecord,
SamValidationErrors validationErrors 
)
static

Validates whether or not the specified SamRecord is valid, calling all of the other validations.

TODO: more validation needs to be added.

Parameters
samHeaderheader associated with the record to be validated.
samRecordrecord to be validated.
validationErrorsstatus to append any errors too.
Returns
true if it is valid, false and appends to SamValidationErrors if it is not

Definition at line 195 of file SamValidation.cpp.

197{
198 bool status = true;
199 status &= isValidQname(samRecord.getReadName(),
200 samRecord.getReadNameLength(),
201 validationErrors);
202
203 status &= isValidFlag(samRecord.getFlag(),
204 validationErrors);
205
206 // Validate the RName including validating it against the header.
207 status &= isValidRname(samHeader,
208 samRecord.getReferenceName(),
209 validationErrors);
210
211 status &= isValidRefID(samRecord.getReferenceID(),
212 samHeader.getReferenceInfo(),
213 validationErrors);
214
215 status &= isValid1BasedPos(samRecord.get1BasedPosition(),
216 validationErrors);
217
218 status &= isValidMapQuality(samRecord.getMapQuality(), validationErrors);
219
220 status &= isValidSequence(samRecord, validationErrors);
221
222 status &= isValidCigar(samRecord, validationErrors);
223
224 status &= isValidQuality(samRecord, validationErrors);
225
226 status &= isValidTags(samRecord, validationErrors);
227
228 return(status);
229}
const SamReferenceInfo & getReferenceInfo() const
Get the Reference Information.
const char * getReferenceName()
Get the reference sequence name (RNAME) of the record.
int32_t get1BasedPosition()
Get the 1-based(SAM) leftmost position (POS) of the record.
int32_t getReferenceID()
Get the reference sequence id of the record (BAM format rid).
uint8_t getReadNameLength()
Get the length of the readname (QNAME) including the null.
uint16_t getFlag()
Get the flag (FLAG).
uint8_t getMapQuality()
Get the mapping quality (MAPQ) of the record.
const char * getReadName()
Returns the SAM formatted Read Name (QNAME).
static bool isValidQname(const char *qname, uint8_t qnameLen, SamValidationErrors &validationErrors)
Determines whether or not the specified qname is valid.
static bool isValidTags(SamRecord &samRecord, SamValidationErrors &validationErrors)
Validate the tags.
static bool isValidFlag(uint16_t flag, SamValidationErrors &validationErrors)
Determines whether or not the flag is valid.
static bool isValidQuality(SamRecord &samRecord, SamValidationErrors &validationErrors)
Validate the base quality.
static bool isValid1BasedPos(int32_t pos, SamValidationErrors &validationErrors)
Validate the refeference position.
static bool isValidRname(SamFileHeader &samHeader, const char *rname, SamValidationErrors &validationErrors)
Validate the reference name including validating against the header.
static bool isValidRefID(int32_t refID, const SamReferenceInfo &refInfo, SamValidationErrors &validationErrors)
Validate whether or not the specified reference id is valid.
static bool isValidCigar(SamRecord &samRecord, SamValidationErrors &validationErrors)
Validate the cigar.
static bool isValidMapQuality(uint8_t mapQuality, SamValidationErrors &validationErrors)
Validate the mapping quality.
static bool isValidSequence(SamRecord &samRecord, SamValidationErrors &validationErrors)
Validate the sequence, but not against the cigar or quality string.

References SamRecord::get1BasedPosition(), SamRecord::getFlag(), SamRecord::getMapQuality(), SamRecord::getReadName(), SamRecord::getReadNameLength(), SamRecord::getReferenceID(), SamFileHeader::getReferenceInfo(), SamRecord::getReferenceName(), isValid1BasedPos(), isValidCigar(), isValidFlag(), isValidMapQuality(), isValidQname(), isValidQuality(), isValidRefID(), isValidRname(), isValidSequence(), and isValidTags().

Referenced by SamRecord::isValid().

◆ isValid1BasedPos()

bool SamValidator::isValid1BasedPos ( int32_t  pos,
SamValidationErrors validationErrors 
)
static

Validate the refeference position.

Validation for pos is: a) must be between 0 and (2^29)-1.

Parameters
posposition to be validated.
validationErrorsstatus to append any errors too.
Returns
true if it is valid, false and appends to SamValidationErrors if it is not

Definition at line 504 of file SamValidation.cpp.

506{
507 // Validation for pos is:
508 // a) must be between 0 and (2^29)-1.
509
510 bool status = true;
511
512 if((pos < 0) || (pos > 536870911))
513 {
514 String message = "POS out of range (";
515 message += pos;
516 message += ") must be between 0 and (2^29)-1.";
517
520 message.c_str());
521 status = false;
522 }
523
524 return(status);
525}
@ WARNING
Warning is used if it is just an invalid value.
@ INVALID_POS
Invalid position.
void addError(SamValidationError::Type newType, SamValidationError::Severity newSeverity, const char *newMessage)
Add the specified error to this container.

References SamValidationErrors::addError(), SamValidationError::INVALID_POS, and SamValidationError::WARNING.

Referenced by isValid().

◆ isValidCigar() [1/3]

bool SamValidator::isValidCigar ( const char *  cigar,
const char *  sequence,
SamValidationErrors validationErrors 
)
static

Validate the cigar.

Cigar validation depends on sequence. Validation for CIGAR is: a) cannot be 0 length. if not "*", validate the following: b) must have an integer length for each operator (if not "*"). TODO c) all operators must be valid (if not "*"). TODO d) evaluates to the same read length as the sequence string.

Parameters
cigarcigar string to be validated.
sequencesequence to check the cigar against.
validationErrorsstatus to append any errors too.
Returns
true if it is valid, false and appends to SamValidationErrors if it is not

Definition at line 551 of file SamValidation.cpp.

554{
555 if(strcmp(sequence, "*") != 0)
556 {
557 return(isValidCigar(cigar, strlen(sequence), validationErrors));
558 }
559 // Sequence is '*', so the length is 0.
560 return(isValidCigar(cigar, 0, validationErrors));
561}

References isValidCigar().

◆ isValidCigar() [2/3]

bool SamValidator::isValidCigar ( const char *  cigar,
int  seqLen,
SamValidationErrors validationErrors 
)
static

Validate the cigar.

Cigar validation depends on sequence. Validation for CIGAR is: a) cannot be 0 length. if not "*", validate the following: b) TODO: must have an integer length for each operator (if not "*"). c) TODO: all operators must be valid (if not "*"). d) evaluates to the same read length as the sequence string.

Parameters
cigarcigar string to be validated.
seqLensequence length to check the cigar against.
validationErrorsstatus to append any errors too.
Returns
true if it is valid, false and appends to SamValidationErrors if it is not

Definition at line 563 of file SamValidation.cpp.

566{
567 // Validation for CIGAR is:
568 // a) cannot be 0 length.
569 // if not "*", validate the following:
570 // b) must have an integer length for each operator (if not "*"). TODO
571 // c) all operators must be valid (if not "*"). TODO
572 // d) evaluates to the same read length as the sequence string if not '*'.
573 bool status = true;
574 String message;
575
576 int32_t cigarLen = strlen(cigar);
577
578 // a) cannot be 0 length.
579 if(cigarLen == 0)
580 {
583 "Cigar must not be blank.");
584 status = false;
585 }
586
587 if(strcmp(cigar, "*") != 0)
588 {
589 // The cigar is not "*", so validate it.
590 CigarRoller cigarRoller(cigar);
591
592 // b) must have an integer length for each operator.
593 // TODO
594 // c) all operators must be valid.
595 // TODO
596
597 // d) is the same length as the sequence string.
598 int cigarSeqLen = cigarRoller.getExpectedQueryBaseCount();
599 if((cigarSeqLen != seqLen) && (seqLen != 0))
600 {
601 message = "CIGAR does not evaluate to the same length as SEQ, (";
602 message += cigarSeqLen;
603 message += " != ";
604 message += seqLen;
605 message += ").";
608 message.c_str());
609 status = false;
610 }
611 }
612 return(status);
613}
The purpose of this class is to provide accessors for setting, updating, modifying the CIGAR object....
Definition CigarRoller.h:67
@ INVALID_CIGAR
Invalid CIGAR.

References SamValidationErrors::addError(), Cigar::getExpectedQueryBaseCount(), SamValidationError::INVALID_CIGAR, and SamValidationError::WARNING.

◆ isValidCigar() [3/3]

bool SamValidator::isValidCigar ( SamRecord samRecord,
SamValidationErrors validationErrors 
)
static

Validate the cigar.

Cigar validation depends on sequence. Validation for CIGAR is: a) cannot be 0 length. if not "*", validate the following: b) must have an integer length for each operator (if not "*"). TODO c) all operators must be valid (if not "*"). TODO d) evaluates to the same read length as the sequence string.

Parameters
samRecordrecord whose cigar should be validated.
validationErrorsstatus to append any errors too.
Returns
true if it is valid, false and appends to SamValidationErrors if it is not

Definition at line 543 of file SamValidation.cpp.

545{
546 return(isValidCigar(samRecord.getCigar(),
547 samRecord.getReadLength(),
548 validationErrors));
549}
int32_t getReadLength()
Get the length of the read.
const char * getCigar()
Returns the SAM formatted CIGAR string.

References SamRecord::getCigar(), SamRecord::getReadLength(), and isValidCigar().

Referenced by isValid(), isValidCigar(), and isValidCigar().

◆ isValidFlag()

bool SamValidator::isValidFlag ( uint16_t  flag,
SamValidationErrors validationErrors 
)
static

Determines whether or not the flag is valid.

TODO: currently no validation is done on the flag.

Parameters
flagflag to be validated.
validationErrorsstatus to append any errors too.
Returns
true if it is valid, false and appends to SamValidationErrors if it is not

Definition at line 340 of file SamValidation.cpp.

342{
343 // All values in a uint16_t are valid, so return true.
344 return(true);
345}

Referenced by isValid().

◆ isValidIsize()

static bool SamValidator::isValidIsize ( )
static

TODO: validate the insertion size/observed template length.

Returns
true if it is valid, false and appends to SamValidationErrors if it is not

◆ isValidMapQuality()

bool SamValidator::isValidMapQuality ( uint8_t  mapQuality,
SamValidationErrors validationErrors 
)
static

Validate the mapping quality.

TODO: currently no validation is done on the mapping quality.

Parameters
mapQualitymapping quality to be validated.
validationErrorsstatus to append any errors too.
Returns
true if it is valid, false and appends to SamValidationErrors if it is not

Definition at line 528 of file SamValidation.cpp.

530{
531 // All values in a uint8_t are valid, so return true.
532 return(true);
533}

Referenced by isValid().

◆ isValidMpos()

static bool SamValidator::isValidMpos ( )
static

TODO: validate the mate/next fragment's position.

Returns
true if it is valid, false and appends to SamValidationErrors if it is not

◆ isValidMrnm()

static bool SamValidator::isValidMrnm ( )
static

TODO: validate the mate/next fragment's reference name.

Returns
true if it is valid, false and appends to SamValidationErrors if it is not

◆ isValidQname()

bool SamValidator::isValidQname ( const char *  qname,
uint8_t  qnameLen,
SamValidationErrors validationErrors 
)
static

Determines whether or not the specified qname is valid.

Validation for QNAME is: a) length of the qname string is the same as the read name length b) length is between 1 and 254. c) [ \t
\r] are not allowed in the name.

Parameters
qnamethe read/query name.
qnameLenlength of the read including the null (result of SamRecord::getReadNameLength().
validationErrorsstatus to append any errors too.
Returns
true if it is valid, false and appends to SamValidationErrors if it is not

Definition at line 238 of file SamValidation.cpp.

240{
241 // Validation for QNAME is:
242 // a) length of the qname string is the same as the read name length
243 // b) length is between 1 and 254.
244 // c) [ \t\n\r] are not allowed in the name.
245
246 bool status = true;
247
248 // Get the length of the qname string.
249 int32_t qnameLenNull = strlen(qname) + 1;
250
251 ////////////////////////////////////
252 // a) length of the qname string is the same as the read name length
253 if(qnameLenNull != readNameLen)
254 {
255 // This results from a poorly formatted bam file, where the null
256 // terminated read_name field is not the same length as specified by
257 // read_name_len.
258 String message = "Invalid Query Name - the string length (";
259 message += qnameLenNull;
260 message += ") does not match the specified query name length (";
261 message += readNameLen;
262 message += ").";
263
266 message.c_str());
267 status = false;
268 }
269
270 ////////////////////////////////////
271 // b) length is between 1 and 254
272 // The length with the terminating null must be between 2 & 255,
273 if((qnameLenNull < 2) || (qnameLenNull > 255))
274 {
275 String message = "Invalid Query Name (QNAME) length: ";
276 message += qnameLenNull;
277 message += ". Length with the terminating null must be between 2 & 255.";
278
281 message.c_str());
282 status = false;
283 }
284
285 ////////////////////////////////////
286 // Loop through and validate they all characters are valid.
287 // c) [ \t\n\r] are not allowed in the name.
288 String message;
289 for(int i = 0; i < qnameLenNull; ++i)
290 {
291 switch(qname[i])
292 {
293 case ' ':
294 // Invalid character.
295 message = "Invalid character in the Query Name (QNAME): ' ' at position ";
296 message += i;
297 message += ".";
300 message.c_str());
301 status = false;
302 break;
303 case '\t':
304 // Invalid character.
305 message = "Invalid character in the Query Name (QNAME): '\t' at position ";
306 message += i;
307 message += ".";
310 message.c_str());
311 status = false;
312 break;
313 case '\n':
314 // Invalid character.
315 message = "Invalid character in the Query Name (QNAME): '\n' at position ";
316 message += i;
317 message += ".";
320 message.c_str());
321 status = false;
322 break;
323 case '\r':
324 // Invalid character.
325 message = "Invalid character in the Query Name (QNAME): '\r' at position ";
326 message += i;
327 message += ".";
330 message.c_str());
331 status = false;
332 break;
333 }
334 }
335
336 return(status);
337}
@ ERROR
Error is used if parsing could not succeed.
@ INVALID_QNAME
Invalid read/query name.

References SamValidationErrors::addError(), SamValidationError::ERROR, SamValidationError::INVALID_QNAME, and SamValidationError::WARNING.

Referenced by isValid().

◆ isValidQuality() [1/3]

bool SamValidator::isValidQuality ( const char *  quality,
const char *  sequence,
SamValidationErrors validationErrors 
)
static

Validate the base quality.

Quality validation depends on sequence. Validation for quality is: a) quality & sequence are the same length if both are specified. TODO: more validation.

Parameters
qualityquality string to be validated.
seqLensequence length to check the quality against.
validationErrorsstatus to append any errors too.
Returns
true if it is valid, false and appends to SamValidationErrors if it is not

Definition at line 625 of file SamValidation.cpp.

628{
629 // Determine the length of the sequence.
630 int seqLen = strlen(sequence);
631
632 // Check if the sequence is '*' since then the seqLength is 0.
633 if(strcmp(sequence, "*") == 0)
634 {
635 seqLen = 0;
636 }
637 return(isValidQuality(quality, seqLen, validationErrors));
638}

References isValidQuality().

◆ isValidQuality() [2/3]

bool SamValidator::isValidQuality ( const char *  quality,
int  seqLength,
SamValidationErrors validationErrors 
)
static

Validate the base quality.

Quality validation depends on sequence. Validation for quality is: a) quality & sequence are the same length if both are specified. TODO: more validation.

Parameters
qualityquality string to be validated.
seqLensequence length to check the quality against.
validationErrorsstatus to append any errors too.
Returns
true if it is valid, false and appends to SamValidationErrors if it is not

Definition at line 641 of file SamValidation.cpp.

644{
645 bool status = true;
646
647 // If the quality or the sequence are non-"*", validate that the quality
648 // and sequence have the same length.
649 if((seqLength != 0) && (strcmp(quality, "*") != 0))
650 {
651 int qualLen = strlen(quality);
652 // Both the sequence and the quality are not "*", so validate
653 // that they are the same length.
654 if(seqLength != qualLen)
655 {
656 // Both fields are specified but are different lengths.
657
658 String message = "QUAL is not the same length as SEQ, (";
659 message += qualLen;
660 message += " != ";
661 message += seqLength;
662 message += ").";
663
666 message.c_str());
667 status = false;
668 }
669 }
670 return(status);
671}
@ INVALID_QUAL
Invalid base quality.

References SamValidationErrors::addError(), SamValidationError::INVALID_QUAL, and SamValidationError::WARNING.

◆ isValidQuality() [3/3]

bool SamValidator::isValidQuality ( SamRecord samRecord,
SamValidationErrors validationErrors 
)
static

Validate the base quality.

Quality validation depends on sequence. Validation for quality is: a) quality & sequence are the same length if both are specified. TODO: more validation.

Parameters
samRecordrecord whose quality should be validated.
validationErrorsstatus to append any errors too.
Returns
true if it is valid, false and appends to SamValidationErrors if it is not

Definition at line 616 of file SamValidation.cpp.

618{
619 return(isValidQuality(samRecord.getQuality(),
620 samRecord.getReadLength(),
621 validationErrors));
622}
const char * getQuality()
Returns the SAM formatted quality string (QUAL).

References SamRecord::getQuality(), SamRecord::getReadLength(), and isValidQuality().

Referenced by isValid(), isValidQuality(), and isValidQuality().

◆ isValidRefID()

bool SamValidator::isValidRefID ( int32_t  refID,
const SamReferenceInfo refInfo,
SamValidationErrors validationErrors 
)
static

Validate whether or not the specified reference id is valid.

Validation for rID is: a) must be between -1 and the number of refInfo. -1 is allowed, and otherwise it must properly index into the array.

Parameters
refIDreference id to be validated.
refInfosam reference information containing the mapping from reference id to reference name for this refID.
validationErrorsstatus to append any errors too.
Returns
true if it is valid, false and appends to SamValidationErrors if it is not

Definition at line 476 of file SamValidation.cpp.

479{
480 // Validation for rID is:
481 // a) must be between -1 and the number of refInfo.
482 // -1 is allowed, and otherwise it must properly index into the array.
483
484 bool status = true;
485 if((refID < -1) || (refID >= refInfo.getNumEntries()))
486 {
487 // Reference ID is too large or too small.
488 String message = "Invalid Reference ID, out of range (";
489 message += refID;
490 message += ") must be between -1 and ";
491 message += refInfo.getNumEntries() - 1;
492 message += ".";
493
496 message.c_str());
497 status = false;
498 }
499
500 return(status);
501}
int32_t getNumEntries() const
Get the number of entries contained here.
@ INVALID_REF_ID
Invalid reference id.

References SamValidationErrors::addError(), SamReferenceInfo::getNumEntries(), SamValidationError::INVALID_REF_ID, and SamValidationError::WARNING.

Referenced by isValid().

◆ isValidRname() [1/2]

bool SamValidator::isValidRname ( const char *  rname,
SamValidationErrors validationErrors 
)
static

Validate the rname without validating against the header.

Validation for RNAME is: a) cannot be 0 length. b) [ \t
\r=] are not allowed in the name.

Parameters
rnamereference name to be validated.
validationErrorsstatus to append any errors too.
Returns
true if it is valid, false and appends to SamValidationErrors if it is not

Definition at line 376 of file SamValidation.cpp.

378{
379 // Validation for RNAME is:
380 // a) cannot be 0 length.
381 // b) [ \t\n\r@=] are not allowed in the name.
382
383 bool status = true;
384
385 // Get the length of the rname string.
386 int32_t rnameLen = strlen(rname);
387
388 String message;
389
390 if(rnameLen == 0)
391 {
394 "Reference Sequence Name (RNAME) cannot have 0 length.");
395 status = false;
396 }
397
398 ////////////////////////////////////
399 ////////////////////////////////////
400 // Loop through and validate they all characters are valid.
401 // b) [ \t\n\r] are not allowed in the name.
402 for(int i = 0; i < rnameLen; ++i)
403 {
404 switch(rname[i])
405 {
406 case ' ':
407 // Invalid character.
408 message = "Invalid character in the Reference Sequence Name (RNAME): ' ' at position ";
409 message += i;
410 message += ".";
413 message.c_str());
414 status = false;
415 break;
416 case '\t':
417 // Invalid character.
418 message = "Invalid character in the Reference Sequence Name (RNAME): '\t' at position ";
419 message += i;
420 message += ".";
423 message.c_str());
424 status = false;
425 break;
426 case '\n':
427 // Invalid character.
428 message = "Invalid character in the Reference Sequence Name (RNAME): '\n' at position ";
429 message += i;
430 message += ".";
433 message.c_str());
434 status = false;
435 break;
436 case '\r':
437 // Invalid character.
438 message = "Invalid character in the Reference Sequence Name (RNAME): '\r' at position ";
439 message += i;
440 message += ".";
443 message.c_str());
444 status = false;
445 break;
446 case '@':
447 // Invalid character.
448 message = "Invalid character in the Reference Sequence Name (RNAME): '@' at position ";
449 message += i;
450 message += ".";
453 message.c_str());
454 status = false;
455 break;
456 case '=':
457 // Invalid character.
458 message = "Invalid character in the Reference Sequence Name (RNAME): '=' at position ";
459 message += i;
460 message += ".";
463 message.c_str());
464 status = false;
465 break;
466 default:
467 // Allowed character.
468 break;
469 }
470 }
471
472 return(status);
473}
@ INVALID_RNAME
Invalid reference name.

References SamValidationErrors::addError(), SamValidationError::INVALID_RNAME, and SamValidationError::WARNING.

◆ isValidRname() [2/2]

bool SamValidator::isValidRname ( SamFileHeader samHeader,
const char *  rname,
SamValidationErrors validationErrors 
)
static

Validate the reference name including validating against the header.

1) Cross validate the rname and the header. 2) perform the validation in the method that doesn't take the header.

Parameters
samHeaderheader associated with the rname to be validated.
rnamereference name to be validated.
validationErrorsstatus to append any errors too.
Returns
true if it is valid, false and appends to SamValidationErrors if it is not

Definition at line 348 of file SamValidation.cpp.

351{
352 bool status = true;
353
354 // Cross validate the rname and the header.
355 // If the rname is not '*'
356 // AND there are any SQ records in the header,
357 // Then the rname must be in one of them.
358 if((strcmp(rname, "*") != 0) &&
359 (samHeader.getNumSQs() != 0) &&
360 (samHeader.getSQ(rname) == NULL))
361 {
362 // There are SQ fields, but the ref name is not in it.
363 status = false;
364 std::string message = "RNAME, ";
365 message += rname;
366 message += ", was not found in a SAM Header SQ record";
369 message.c_str());
370 }
371 status &= isValidRname(rname, validationErrors);
372 return(status);
373}
SamHeaderSQ * getSQ(const char *name)
Get the SQ object with the specified sequence name, returning NULL if there is no SQ object with that...
int getNumSQs()
Get the number of SQ objects.

References SamValidationErrors::addError(), SamFileHeader::getNumSQs(), SamFileHeader::getSQ(), SamValidationError::INVALID_RNAME, isValidRname(), and SamValidationError::WARNING.

Referenced by isValid(), and isValidRname().

◆ isValidSeq()

static bool SamValidator::isValidSeq ( )
static

TODO, validate the sequence.

Returns
true if it is valid, false and appends to SamValidationErrors if it is not

◆ isValidSequence()

bool SamValidator::isValidSequence ( SamRecord samRecord,
SamValidationErrors validationErrors 
)
static

Validate the sequence, but not against the cigar or quality string.

Validation against cigar is done in isValidCigar. Validation against the quality string is done in isValidQuality. TODO: currently no validation is done in this method.

Parameters
samRecordrecord whose sequence should be validated.
validationErrorsstatus to append any errors too.
Returns
true if it is valid, false and appends to SamValidationErrors if it is not

Definition at line 536 of file SamValidation.cpp.

538{
539 return(true);
540}

Referenced by isValid().

◆ isValidTags()

bool SamValidator::isValidTags ( SamRecord samRecord,
SamValidationErrors validationErrors 
)
static

Validate the tags.

Validation for tags is: a) check that the "MD" tag is correct if it is present. TODO: more validation.

Parameters
samRecordrecord whose tags should be validated.
validationErrorsstatus to append any errors too.
Returns
true if it is valid, false and appends to SamValidationErrors if it is not

Definition at line 674 of file SamValidation.cpp.

676{
677 bool status = true;
678
679 GenomeSequence* reference = samRecord.getReference();
680 // If the reference is not null, check the MD tag.
681 if(reference != NULL)
682 {
683 const String* recordMD = samRecord.getStringTag(SamTags::MD_TAG);
684 if(recordMD != NULL)
685 {
686 // The record has an MD tag so check to see if it is correct.
687 if(!SamTags::isMDTagCorrect(samRecord, *reference))
688 {
689 // Invalid MD tags.
690 String correctMD;
691 if(!SamTags::createMDTag(correctMD, samRecord, *reference))
692 {
693 // Failed to get the MD tag, so indicate that it is unknown.
694 correctMD = "UNKNOWN";
695 }
696 String message = "Incorrect MD Tag, ";
697 message += *recordMD;
698 message += ", should be ";
699 message += correctMD;
700 message += ".";
701
704 message.c_str());
705
706 status = false;
707 }
708 }
709 }
710
711 return(status);
712}
Create/Access/Modify/Load Genome Sequences stored as binary mapped files.
GenomeSequence * getReference()
Returns a pointer to the genome sequence object associated with this record if it was set (NULL if it...
const String * getStringTag(const char *tag)
Get the string value for the specified tag.
static bool isMDTagCorrect(SamRecord &inputRec, GenomeSequence &genome)
Check to see if the MD tag in the record is accurate.
Definition SamTags.cpp:126
static bool createMDTag(String &outputMDtag, SamRecord &inputRec, GenomeSequence &genome)
Create the MD tag for the specified input record and the genome.
Definition SamTags.cpp:34
@ INVALID_TAG
Invalid tag.

References SamValidationErrors::addError(), SamTags::createMDTag(), SamRecord::getReference(), SamRecord::getStringTag(), SamValidationError::INVALID_TAG, SamTags::isMDTagCorrect(), and SamValidationError::WARNING.

Referenced by isValid().

◆ isValidValue()

static bool SamValidator::isValidValue ( )
static

TODO validate the tag vtype.

Returns
true if it is valid, false and appends to SamValidationErrors if it is not

◆ isValidVtype()

static bool SamValidator::isValidVtype ( )
static

TODO validate the tag vtype.

Returns
true if it is valid, false and appends to SamValidationErrors if it is not

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