libStatGen Software  1
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
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.

References SamRecord::get1BasedPosition(), SamRecord::getFlag(), SamRecord::getMapQuality(), SamRecord::getReadName(), SamRecord::getReadNameLength(), SamRecord::getReferenceID(), SamFileHeader::getReferenceInfo(), and SamRecord::getReferenceName().

Referenced by SamRecord::isValid().

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 }
static bool isValidSequence(SamRecord &samRecord, SamValidationErrors &validationErrors)
Validate the sequence, but not against the cigar or quality string.
uint8_t getMapQuality()
Get the mapping quality (MAPQ) of the record.
Definition: SamRecord.cpp:1328
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.
const char * getReadName()
Returns the SAM formatted Read Name (QNAME).
Definition: SamRecord.cpp:1530
int32_t getReferenceID()
Get the reference sequence id of the record (BAM format rid).
Definition: SamRecord.cpp:1293
const SamReferenceInfo & getReferenceInfo() const
Get the Reference Information.
static bool isValidMapQuality(uint8_t mapQuality, SamValidationErrors &validationErrors)
Validate the mapping quality.
uint8_t getReadNameLength()
Get the length of the readname (QNAME) including the null.
Definition: SamRecord.cpp:1314
int32_t get1BasedPosition()
Get the 1-based(SAM) leftmost position (POS) of the record.
Definition: SamRecord.cpp:1300
static bool isValidQname(const char *qname, uint8_t qnameLen, SamValidationErrors &validationErrors)
Determines whether or not the specified qname is valid.
static bool isValidRefID(int32_t refID, const SamReferenceInfo &refInfo, SamValidationErrors &validationErrors)
Validate whether or not the specified reference id is valid.
static bool isValidRname(SamFileHeader &samHeader, const char *rname, SamValidationErrors &validationErrors)
Validate the reference name including validating against the header.
static bool isValid1BasedPos(int32_t pos, SamValidationErrors &validationErrors)
Validate the refeference position.
uint16_t getFlag()
Get the flag (FLAG).
Definition: SamRecord.cpp:1372
static bool isValidQuality(SamRecord &samRecord, SamValidationErrors &validationErrors)
Validate the base quality.
static bool isValidCigar(SamRecord &samRecord, SamValidationErrors &validationErrors)
Validate the cigar.
const char * getReferenceName()
Get the reference sequence name (RNAME) of the record.
Definition: SamRecord.cpp:1286

◆ 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.

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

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 
518  validationErrors.addError(SamValidationError::INVALID_POS,
520  message.c_str());
521  status = false;
522  }
523 
524  return(status);
525 }
Warning is used if it is just an invalid value.
Definition: SamValidation.h:40
void addError(SamValidationError::Type newType, SamValidationError::Severity newSeverity, const char *newMessage)
Add the specified error to this container.

◆ isValidCigar() [1/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.

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

545 {
546  return(isValidCigar(samRecord.getCigar(),
547  samRecord.getReadLength(),
548  validationErrors));
549 }
int32_t getReadLength()
Get the length of the read.
Definition: SamRecord.cpp:1379
static bool isValidCigar(SamRecord &samRecord, SamValidationErrors &validationErrors)
Validate the cigar.
const char * getCigar()
Returns the SAM formatted CIGAR string.
Definition: SamRecord.cpp:1543

◆ isValidCigar() [2/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  return(isValidCigar(cigar, strlen(sequence), validationErrors));
556 }
static bool isValidCigar(SamRecord &samRecord, SamValidationErrors &validationErrors)
Validate the cigar.

◆ isValidCigar() [3/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 558 of file SamValidation.cpp.

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

561 {
562  // Validation for CIGAR is:
563  // a) cannot be 0 length.
564  // if not "*", validate the following:
565  // b) must have an integer length for each operator (if not "*"). TODO
566  // c) all operators must be valid (if not "*"). TODO
567  // d) evaluates to the same read length as the sequence string.
568  bool status = true;
569  String message;
570 
571  int32_t cigarLen = strlen(cigar);
572 
573  // a) cannot be 0 length.
574  if(cigarLen == 0)
575  {
578  "Cigar must not be blank.");
579  status = false;
580  }
581 
582  if(strcmp(cigar, "*") != 0)
583  {
584  // The cigar is not "*", so validate it.
585  CigarRoller cigarRoller(cigar);
586 
587  // b) must have an integer length for each operator.
588  // TODO
589  // c) all operators must be valid.
590  // TODO
591 
592  // d) is the same length as the sequence string.
593  int cigarSeqLen = cigarRoller.getExpectedQueryBaseCount();
594  if(cigarSeqLen != seqLen)
595  {
596  message = "CIGAR does not evaluate to the same length as SEQ, (";
597  message += cigarSeqLen;
598  message += " != ";
599  message += seqLen;
600  message += ").";
603  message.c_str());
604  status = false;
605  }
606  }
607  return(status);
608 }
Warning is used if it is just an invalid value.
Definition: SamValidation.h:40
The purpose of this class is to provide accessors for setting, updating, modifying the CIGAR object...
Definition: CigarRoller.h:66
void addError(SamValidationError::Type newType, SamValidationError::Severity newSeverity, const char *newMessage)
Add the specified error to this container.

◆ 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 }

◆ 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 }

◆ 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) [
] 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.

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

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 is used if parsing could not succeed.
Definition: SamValidation.h:41
Warning is used if it is just an invalid value.
Definition: SamValidation.h:40
Invalid read/query name.
Definition: SamValidation.h:49
void addError(SamValidationError::Type newType, SamValidationError::Severity newSeverity, const char *newMessage)
Add the specified error to this container.

◆ isValidQuality() [1/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 611 of file SamValidation.cpp.

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

613 {
614  return(isValidQuality(samRecord.getQuality(),
615  samRecord.getReadLength(),
616  validationErrors));
617 }
int32_t getReadLength()
Get the length of the read.
Definition: SamRecord.cpp:1379
const char * getQuality()
Returns the SAM formatted quality string (QUAL).
Definition: SamRecord.cpp:1626
static bool isValidQuality(SamRecord &samRecord, SamValidationErrors &validationErrors)
Validate the base quality.

◆ isValidQuality() [2/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 620 of file SamValidation.cpp.

623 {
624  // Determine the length of the sequence.
625  int seqLen = strlen(sequence);
626 
627  // Check if the sequence is '*' since then the seqLength is 0.
628  if(strcmp(sequence, "*") == 0)
629  {
630  seqLen = 0;
631  }
632  return(isValidQuality(quality, seqLen, validationErrors));
633 }
static bool isValidQuality(SamRecord &samRecord, SamValidationErrors &validationErrors)
Validate the base quality.

◆ isValidQuality() [3/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 636 of file SamValidation.cpp.

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

639 {
640  bool status = true;
641 
642  // If the quality or the sequence are non-"*", validate that the quality
643  // and sequence have the same length.
644  if((seqLength != 0) && (strcmp(quality, "*") != 0))
645  {
646  int qualLen = strlen(quality);
647  // Both the sequence and the quality are not "*", so validate
648  // that they are the same length.
649  if(seqLength != qualLen)
650  {
651  // Both fields are specified but are different lengths.
652 
653  String message = "QUAL is not the same length as SEQ, (";
654  message += qualLen;
655  message += " != ";
656  message += seqLength;
657  message += ").";
658 
661  message.c_str());
662  status = false;
663  }
664  }
665  return(status);
666 }
Invalid base quality.
Definition: SamValidation.h:56
Warning is used if it is just an invalid value.
Definition: SamValidation.h:40
void addError(SamValidationError::Type newType, SamValidationError::Severity newSeverity, const char *newMessage)
Add the specified error to this container.

◆ 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.

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

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.
Warning is used if it is just an invalid value.
Definition: SamValidation.h:40
void addError(SamValidationError::Type newType, SamValidationError::Severity newSeverity, const char *newMessage)
Add the specified error to this container.

◆ isValidRname() [1/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.

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

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 }
Invalid reference name.
Definition: SamValidation.h:51
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.
static bool isValidRname(SamFileHeader &samHeader, const char *rname, SamValidationErrors &validationErrors)
Validate the reference name including validating against the header.
Warning is used if it is just an invalid value.
Definition: SamValidation.h:40
void addError(SamValidationError::Type newType, SamValidationError::Severity newSeverity, const char *newMessage)
Add the specified error to this container.

◆ isValidRname() [2/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) [
@=] 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.

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

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 reference name.
Definition: SamValidation.h:51
Warning is used if it is just an invalid value.
Definition: SamValidation.h:40
void addError(SamValidationError::Type newType, SamValidationError::Severity newSeverity, const char *newMessage)
Add the specified error to this container.

◆ 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 }

◆ 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 669 of file SamValidation.cpp.

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

671 {
672  bool status = true;
673 
674  GenomeSequence* reference = samRecord.getReference();
675  // If the reference is not null, check the MD tag.
676  if(reference != NULL)
677  {
678  const String* recordMD = samRecord.getStringTag(SamTags::MD_TAG);
679  if(recordMD != NULL)
680  {
681  // The record has an MD tag so check to see if it is correct.
682  if(!SamTags::isMDTagCorrect(samRecord, *reference))
683  {
684  // Invalid MD tags.
685  String correctMD;
686  if(!SamTags::createMDTag(correctMD, samRecord, *reference))
687  {
688  // Failed to get the MD tag, so indicate that it is unknown.
689  correctMD = "UNKNOWN";
690  }
691  String message = "Incorrect MD Tag, ";
692  message += *recordMD;
693  message += ", should be ";
694  message += correctMD;
695  message += ".";
696 
697  validationErrors.addError(SamValidationError::INVALID_TAG,
699  message.c_str());
700 
701  status = false;
702  }
703  }
704  }
705 
706  return(status);
707 }
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
const String * getStringTag(const char *tag)
Get the string value for the specified tag.
Definition: SamRecord.cpp:2168
static bool isMDTagCorrect(SamRecord &inputRec, GenomeSequence &genome)
Check to see if the MD tag in the record is accurate.
Definition: SamTags.cpp:126
Warning is used if it is just an invalid value.
Definition: SamValidation.h:40
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...
Definition: SamRecord.cpp:1911
void addError(SamValidationError::Type newType, SamValidationError::Severity newSeverity, const char *newMessage)
Add the specified error to this container.

◆ 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: