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

## 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

  samHeader | header associated with the record to be validated.
  samRecord | record to be validated.
  validationErrors | status 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.

{
bool status = true;
status &= isValidQname(samRecord.getReadName(),
samRecord.getReadNameLength(),
validationErrors);
status &= isValidFlag(samRecord.getFlag(),
validationErrors);
// Validate the RName including validating it against the header.
status &= isValidRname(samHeader,
samRecord.getReferenceName(),
validationErrors);
status &= isValidRefID(samRecord.getReferenceID(),
samHeader.getReferenceInfo(),
validationErrors);
status &= isValid1BasedPos(samRecord.get1BasedPosition(),
validationErrors);
status &= isValidMapQuality(samRecord.getMapQuality(), validationErrors);
status &= isValidSequence(samRecord, validationErrors);
status &= isValidCigar(samRecord, validationErrors);
status &= isValidQuality(samRecord, validationErrors);
status &= isValidTags(samRecord, validationErrors);
return(status);
}
SamFileHeader::getReferenceInfo
const SamReferenceInfo & getReferenceInfo() const
Get the Reference Information.
Definition: SamFileHeader.cpp:165
SamRecord::getReferenceName
const char * getReferenceName()
Get the reference sequence name (RNAME) of the record.
Definition: SamRecord.cpp:1298
SamRecord::get1BasedPosition
int32_t get1BasedPosition()
Get the 1-based(SAM) leftmost position (POS) of the record.
Definition: SamRecord.cpp:1312
SamRecord::getReferenceID
int32_t getReferenceID()
Get the reference sequence id of the record (BAM format rid).
Definition: SamRecord.cpp:1305
SamRecord::getReadNameLength
uint8_t getReadNameLength()
Get the length of the readname (QNAME) including the null.
Definition: SamRecord.cpp:1326
SamRecord::getFlag
uint16_t getFlag()
Get the flag (FLAG).
Definition: SamRecord.cpp:1384
SamRecord::getMapQuality
uint8_t getMapQuality()
Get the mapping quality (MAPQ) of the record.
Definition: SamRecord.cpp:1340
SamRecord::getReadName
const char * getReadName()
Returns the SAM formatted Read Name (QNAME).
Definition: SamRecord.cpp:1542
SamValidator::isValidQname
static bool isValidQname(const char *qname, uint8_t qnameLen, SamValidationErrors &validationErrors)
Determines whether or not the specified qname is valid.
Definition: SamValidation.cpp:238
SamValidator::isValidTags
static bool isValidTags(SamRecord &samRecord, SamValidationErrors &validationErrors)
Validate the tags.
Definition: SamValidation.cpp:674
SamValidator::isValidFlag
static bool isValidFlag(uint16_t flag, SamValidationErrors &validationErrors)
Determines whether or not the flag is valid.
Definition: SamValidation.cpp:340
SamValidator::isValidQuality
static bool isValidQuality(SamRecord &samRecord, SamValidationErrors &validationErrors)
Validate the base quality.
Definition: SamValidation.cpp:616
SamValidator::isValid1BasedPos
static bool isValid1BasedPos(int32_t pos, SamValidationErrors &validationErrors)
Validate the refeference position.
Definition: SamValidation.cpp:504
SamValidator::isValidRname
static bool isValidRname(SamFileHeader &samHeader, const char *rname, SamValidationErrors &validationErrors)
Validate the reference name including validating against the header.
Definition: SamValidation.cpp:348
SamValidator::isValidRefID
static bool isValidRefID(int32_t refID, const SamReferenceInfo &refInfo, SamValidationErrors &validationErrors)
Validate whether or not the specified reference id is valid.
Definition: SamValidation.cpp:476
SamValidator::isValidCigar
static bool isValidCigar(SamRecord &samRecord, SamValidationErrors &validationErrors)
Validate the cigar.
Definition: SamValidation.cpp:543
SamValidator::isValidMapQuality
static bool isValidMapQuality(uint8_t mapQuality, SamValidationErrors &validationErrors)
Validate the mapping quality.
Definition: SamValidation.cpp:528
SamValidator::isValidSequence
static bool isValidSequence(SamRecord &samRecord, SamValidationErrors &validationErrors)
Validate the sequence, but not against the cigar or quality string.
Definition: SamValidation.cpp:536

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

  pos | position to be validated.
  validationErrors | status 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.

{
// Validation for pos is:
// a) must be between 0 and (2^29)-1.
bool status = true;
if((pos < 0) || (pos > 536870911))
{
String message = "POS out of range (";
message += pos;
message += ") must be between 0 and (2^29)-1.";
validationErrors.addError(SamValidationError::INVALID_POS,
SamValidationError::WARNING,
message.c_str());
status = false;
}
return(status);
}
SamValidationError::WARNING
@ WARNING
Warning is used if it is just an invalid value.
Definition: SamValidation.h:40
SamValidationError::INVALID_POS
@ INVALID_POS
Invalid position.
Definition: SamValidation.h:52
SamValidationErrors::addError
void addError(SamValidationError::Type newType, SamValidationError::Severity newSeverity, const char *newMessage)
Add the specified error to this container.
Definition: SamValidation.cpp:132
String
Definition: StringBasics.h:39

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

  cigar | cigar string to be validated.
  sequence | sequence to check the cigar against.
  validationErrors | status 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.

{
if(strcmp(sequence, "*") != 0)
{
return(isValidCigar(cigar, strlen(sequence), validationErrors));
}
// Sequence is '*', so the length is 0.
return(isValidCigar(cigar, 0, validationErrors));
}

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

  cigar | cigar string to be validated.
  seqLen | sequence length to check the cigar against.
  validationErrors | status 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.

{
// 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 if not '*'.
bool status = true;
String message;
int32_t cigarLen = strlen(cigar);
// a) cannot be 0 length.
if(cigarLen == 0)
{
validationErrors.addError(SamValidationError::INVALID_CIGAR,
SamValidationError::WARNING,
"Cigar must not be blank.");
status = false;
}
if(strcmp(cigar, "*") != 0)
{
// The cigar is not "*", so validate it.
CigarRoller cigarRoller(cigar);
// b) must have an integer length for each operator.
// TODO
// c) all operators must be valid.
// TODO
// d) is the same length as the sequence string.
int cigarSeqLen = cigarRoller.getExpectedQueryBaseCount();
if((cigarSeqLen != seqLen) && (seqLen != 0))
{
message = "CIGAR does not evaluate to the same length as SEQ, (";
message += cigarSeqLen;
message += " != ";
message += seqLen;
message += ").";
validationErrors.addError(SamValidationError::INVALID_CIGAR,
SamValidationError::WARNING,
message.c_str());
status = false;
}
}
return(status);
}
CigarRoller
The purpose of this class is to provide accessors for setting, updating, modifying the CIGAR object....
Definition: CigarRoller.h:67
SamValidationError::INVALID_CIGAR
@ INVALID_CIGAR
Invalid CIGAR.
Definition: SamValidation.h:54

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

  samRecord | record whose cigar should be validated.
  validationErrors | status 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.

{
return(isValidCigar(samRecord.getCigar(),
samRecord.getReadLength(),
validationErrors));
}
SamRecord::getReadLength
int32_t getReadLength()
Get the length of the read.
Definition: SamRecord.cpp:1391
SamRecord::getCigar
const char * getCigar()
Returns the SAM formatted CIGAR string.
Definition: SamRecord.cpp:1555

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

Referenced by isValid(), 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

  flag | flag to be validated.
  validationErrors | status 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.

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

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

  mapQuality | mapping quality to be validated.
  validationErrors | status 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.

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

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

  qname | the read/query name.
  qnameLen | length of the read including the null (result of SamRecord::getReadNameLength().
  validationErrors | status 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.

{
// 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\n\r] are not allowed in the name.
bool status = true;
// Get the length of the qname string.
int32_t qnameLenNull = strlen(qname) + 1;
////////////////////////////////////
// a) length of the qname string is the same as the read name length
if(qnameLenNull != readNameLen)
{
// This results from a poorly formatted bam file, where the null
// terminated read_name field is not the same length as specified by
// read_name_len.
String message = "Invalid Query Name - the string length (";
message += qnameLenNull;
message += ") does not match the specified query name length (";
message += readNameLen;
message += ").";
validationErrors.addError(SamValidationError::INVALID_QNAME,
SamValidationError::ERROR,
message.c_str());
status = false;
}
////////////////////////////////////
// b) length is between 1 and 254
// The length with the terminating null must be between 2 & 255,
if((qnameLenNull < 2) || (qnameLenNull > 255))
{
String message = "Invalid Query Name (QNAME) length: ";
message += qnameLenNull;
message += ". Length with the terminating null must be between 2 & 255.";
validationErrors.addError(SamValidationError::INVALID_QNAME,
SamValidationError::WARNING,
message.c_str());
status = false;
}
////////////////////////////////////
// Loop through and validate they all characters are valid.
// c) [ \t\n\r] are not allowed in the name.
String message;
for(int i = 0; i < qnameLenNull; ++i)
{
switch(qname[i])
{
case ' ':
// Invalid character.
message = "Invalid character in the Query Name (QNAME): ' ' at position ";
message += i;
message += ".";
validationErrors.addError(SamValidationError::INVALID_QNAME,
SamValidationError::WARNING,
message.c_str());
status = false;
break;
case '\t':
// Invalid character.
message = "Invalid character in the Query Name (QNAME): '\t' at position ";
message += i;
message += ".";
validationErrors.addError(SamValidationError::INVALID_QNAME,
SamValidationError::WARNING,
message.c_str());
status = false;
break;
case '\n':
// Invalid character.
message = "Invalid character in the Query Name (QNAME): '\n' at position ";
message += i;
message += ".";
validationErrors.addError(SamValidationError::INVALID_QNAME,
SamValidationError::WARNING,
message.c_str());
status = false;
break;
case '\r':
// Invalid character.
message = "Invalid character in the Query Name (QNAME): '\r' at position ";
message += i;
message += ".";
validationErrors.addError(SamValidationError::INVALID_QNAME,
SamValidationError::WARNING,
message.c_str());
status = false;
break;
}
}
return(status);
}
SamValidationError::ERROR
@ ERROR
Error is used if parsing could not succeed.
Definition: SamValidation.h:41
SamValidationError::INVALID_QNAME
@ INVALID_QNAME
Invalid read/query name.
Definition: SamValidation.h:49

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

  quality | quality string to be validated.
  seqLen | sequence length to check the quality against.
  validationErrors | status 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.

{
// Determine the length of the sequence.
int seqLen = strlen(sequence);
// Check if the sequence is '*' since then the seqLength is 0.
if(strcmp(sequence, "*") == 0)
{
seqLen = 0;
}
return(isValidQuality(quality, seqLen, validationErrors));
}

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

  quality | quality string to be validated.
  seqLen | sequence length to check the quality against.
  validationErrors | status 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.

{
bool status = true;
// If the quality or the sequence are non-"*", validate that the quality
// and sequence have the same length.
if((seqLength != 0) && (strcmp(quality, "*") != 0))
{
int qualLen = strlen(quality);
// Both the sequence and the quality are not "*", so validate
// that they are the same length.
if(seqLength != qualLen)
{
// Both fields are specified but are different lengths.
String message = "QUAL is not the same length as SEQ, (";
message += qualLen;
message += " != ";
message += seqLength;
message += ").";
validationErrors.addError(SamValidationError::INVALID_QUAL,
SamValidationError::WARNING,
message.c_str());
status = false;
}
}
return(status);
}
SamValidationError::INVALID_QUAL
@ INVALID_QUAL
Invalid base quality.
Definition: SamValidation.h:56

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

  samRecord | record whose quality should be validated.
  validationErrors | status 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.

{
return(isValidQuality(samRecord.getQuality(),
samRecord.getReadLength(),
validationErrors));
}
SamRecord::getQuality
const char * getQuality()
Returns the SAM formatted quality string (QUAL).
Definition: SamRecord.cpp:1638

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

Referenced by isValid(), 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

  refID | reference id to be validated.
  refInfo | sam reference information containing the mapping from reference id to reference name for this refID.
  validationErrors | status 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.

{
// 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.
bool status = true;
if((refID < -1) || (refID >= refInfo.getNumEntries()))
{
// Reference ID is too large or too small.
String message = "Invalid Reference ID, out of range (";
message += refID;
message += ") must be between -1 and ";
message += refInfo.getNumEntries() - 1;
message += ".";
validationErrors.addError(SamValidationError::INVALID_REF_ID,
SamValidationError::WARNING,
message.c_str());
status = false;
}
return(status);
}
SamReferenceInfo::getNumEntries
int32_t getNumEntries() const
Get the number of entries contained here.
Definition: SamReferenceInfo.cpp:93
SamValidationError::INVALID_REF_ID
@ INVALID_REF_ID
Invalid reference id.
Definition: SamValidation.h:50

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

  rname | reference name to be validated.
  validationErrors | status 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.

{
// Validation for RNAME is:
// a) cannot be 0 length.
// b) [ \t\n\r@=] are not allowed in the name.
bool status = true;
// Get the length of the rname string.
int32_t rnameLen = strlen(rname);
String message;
if(rnameLen == 0)
{
validationErrors.addError(SamValidationError::INVALID_RNAME,
SamValidationError::WARNING,
"Reference Sequence Name (RNAME) cannot have 0 length.");
status = false;
}
////////////////////////////////////
////////////////////////////////////
// Loop through and validate they all characters are valid.
// b) [ \t\n\r] are not allowed in the name.
for(int i = 0; i < rnameLen; ++i)
{
switch(rname[i])
{
case ' ':
// Invalid character.
message = "Invalid character in the Reference Sequence Name (RNAME): ' ' at position ";
message += i;
message += ".";
validationErrors.addError(SamValidationError::INVALID_RNAME,
SamValidationError::WARNING,
message.c_str());
status = false;
break;
case '\t':
// Invalid character.
message = "Invalid character in the Reference Sequence Name (RNAME): '\t' at position ";
message += i;
message += ".";
validationErrors.addError(SamValidationError::INVALID_RNAME,
SamValidationError::WARNING,
message.c_str());
status = false;
break;
case '\n':
// Invalid character.
message = "Invalid character in the Reference Sequence Name (RNAME): '\n' at position ";
message += i;
message += ".";
validationErrors.addError(SamValidationError::INVALID_RNAME,
SamValidationError::WARNING,
message.c_str());
status = false;
break;
case '\r':
// Invalid character.
message = "Invalid character in the Reference Sequence Name (RNAME): '\r' at position ";
message += i;
message += ".";
validationErrors.addError(SamValidationError::INVALID_RNAME,
SamValidationError::WARNING,
message.c_str());
status = false;
break;
case '@':
// Invalid character.
message = "Invalid character in the Reference Sequence Name (RNAME): '@' at position ";
message += i;
message += ".";
validationErrors.addError(SamValidationError::INVALID_RNAME,
SamValidationError::WARNING,
message.c_str());
status = false;
break;
case '=':
// Invalid character.
message = "Invalid character in the Reference Sequence Name (RNAME): '=' at position ";
message += i;
message += ".";
validationErrors.addError(SamValidationError::INVALID_RNAME,
SamValidationError::WARNING,
message.c_str());
status = false;
break;
default:
// Allowed character.
break;
}
}
return(status);
}
SamValidationError::INVALID_RNAME
@ INVALID_RNAME
Invalid reference name.
Definition: SamValidation.h:51

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

  samHeader | header associated with the rname to be validated.
  rname | reference name to be validated.
  validationErrors | status 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.

{
bool status = true;
// Cross validate the rname and the header.
// If the rname is not '*'
// AND there are any SQ records in the header,
// Then the rname must be in one of them.
if((strcmp(rname, "*") != 0) &&
(samHeader.getNumSQs() != 0) &&
(samHeader.getSQ(rname) == NULL))
{
// There are SQ fields, but the ref name is not in it.
status = false;
std::string message = "RNAME, ";
message += rname;
message += ", was not found in a SAM Header SQ record";
validationErrors.addError(SamValidationError::INVALID_RNAME,
SamValidationError::WARNING,
message.c_str());
}
status &= isValidRname(rname, validationErrors);
return(status);
}
SamFileHeader::getSQ
SamHeaderSQ * getSQ(const char *name)
Get the SQ object with the specified sequence name, returning NULL if there is no SQ object with that...
Definition: SamFileHeader.cpp:775
SamFileHeader::getNumSQs
int getNumSQs()
Get the number of SQ objects.
Definition: SamFileHeader.cpp:747

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

  samRecord | record whose sequence should be validated.
  validationErrors | status 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.

{
return(true);
}

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

  samRecord | record whose tags should be validated.
  validationErrors | status 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.

{
bool status = true;
GenomeSequence* reference = samRecord.getReference();
// If the reference is not null, check the MD tag.
if(reference != NULL)
{
const String* recordMD = samRecord.getStringTag(SamTags::MD_TAG);
if(recordMD != NULL)
{
// The record has an MD tag so check to see if it is correct.
if(!SamTags::isMDTagCorrect(samRecord, *reference))
{
// Invalid MD tags.
String correctMD;
if(!SamTags::createMDTag(correctMD, samRecord, *reference))
{
// Failed to get the MD tag, so indicate that it is unknown.
correctMD = "UNKNOWN";
}
String message = "Incorrect MD Tag, ";
message += *recordMD;
message += ", should be ";
message += correctMD;
message += ".";
validationErrors.addError(SamValidationError::INVALID_TAG,
SamValidationError::WARNING,
message.c_str());
status = false;
}
}
}
return(status);
}
GenomeSequence
Create/Access/Modify/Load Genome Sequences stored as binary mapped files.
Definition: GenomeSequence.h:100
SamRecord::getReference
GenomeSequence * getReference()
Returns a pointer to the genome sequence object associated with this record if it was set (NULL if it...
Definition: SamRecord.cpp:1923
SamRecord::getStringTag
const String * getStringTag(const char *tag)
Get the string value for the specified tag.
Definition: SamRecord.cpp:2180
SamTags::isMDTagCorrect
static bool isMDTagCorrect(SamRecord &inputRec, GenomeSequence &genome)
Check to see if the MD tag in the record is accurate.
Definition: SamTags.cpp:126
SamTags::createMDTag
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
SamValidationError::INVALID_TAG
@ INVALID_TAG
Invalid tag.
Definition: SamValidation.h:57

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:

- bam/SamValidation.h
- bam/SamValidation.cpp