SamValidator Class Reference

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

#include <SamValidation.h>

List of all members.

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 165 of file SamValidation.h.


Member Function Documentation

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.

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().

00197 {
00198     bool status = true;
00199     status &= isValidQname(samRecord.getReadName(), 
00200                            samRecord.getReadNameLength(), 
00201                            validationErrors);
00202 
00203     status &= isValidFlag(samRecord.getFlag(), 
00204                           validationErrors);
00205 
00206     // Validate the RName including validating it against the header.
00207     status &= isValidRname(samHeader,
00208                            samRecord.getReferenceName(), 
00209                            validationErrors);
00210 
00211     status &= isValidRefID(samRecord.getReferenceID(), 
00212                            *samHeader.getReferenceInfo(), 
00213                            validationErrors);
00214 
00215     status &= isValid1BasedPos(samRecord.get1BasedPosition(),
00216                                validationErrors);
00217     
00218     status &= isValidMapQuality(samRecord.getMapQuality(), validationErrors);
00219 
00220     status &= isValidSequence(samRecord, validationErrors);
00221 
00222     status &= isValidCigar(samRecord, validationErrors);
00223     
00224     status &= isValidQuality(samRecord, validationErrors);
00225 
00226     status &= isValidTags(samRecord, validationErrors);
00227 
00228     return(status);
00229 }

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.

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

Referenced by isValid().

00506 {
00507     // Validation for pos is:
00508     //   a) must be between 0 and (2^29)-1.
00509 
00510     bool status = true;
00511 
00512     if((pos < 0) || (pos > 536870911))
00513     {
00514         String message = "POS out of range (";
00515         message += pos;
00516         message += ") must be between 0 and (2^29)-1.";
00517 
00518         validationErrors.addError(SamValidationError::INVALID_POS,
00519                                   SamValidationError::WARNING, 
00520                                   message.c_str());
00521         status = false;
00522     }
00523 
00524     return(status);
00525 }

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

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

00561 {
00562     // Validation for CIGAR is:
00563     //   a) cannot be 0 length.
00564     // if not "*", validate the following:
00565     //   b) must have an integer length for each operator (if not "*"). TODO
00566     //   c) all operators must be valid (if not "*"). TODO
00567     //   d) evaluates to the same read length as the sequence string.
00568     bool status = true;
00569     String message;
00570 
00571     int32_t cigarLen = strlen(cigar);
00572 
00573     //   a) cannot be 0 length.
00574     if(cigarLen == 0)
00575     {
00576         validationErrors.addError(SamValidationError::INVALID_CIGAR,
00577                                   SamValidationError::WARNING,
00578                                   "Cigar must not be blank.");
00579         status = false;
00580     }
00581     
00582     if(strcmp(cigar, "*") != 0)
00583     {
00584         // The cigar is not "*", so validate it.
00585         CigarRoller cigarRoller(cigar);
00586         
00587         //   b) must have an integer length for each operator.
00588         // TODO
00589         //   c) all operators must be valid.
00590         // TODO
00591 
00592         //   d) is the same length as the sequence string.
00593         int cigarSeqLen = cigarRoller.getExpectedQueryBaseCount();
00594         if(cigarSeqLen != seqLen)
00595         {
00596             message = "CIGAR does not evaluate to the same length as SEQ, (";
00597             message += cigarSeqLen;
00598             message += " != ";
00599             message += seqLen;
00600             message += ").";
00601             validationErrors.addError(SamValidationError::INVALID_CIGAR,
00602                                       SamValidationError::WARNING, 
00603                                       message.c_str());
00604             status = false;
00605         }
00606     }
00607     return(status);
00608 }

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.

References isValidCigar().

00554 {
00555     return(isValidCigar(cigar, strlen(sequence), validationErrors));
00556 }

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.

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

Referenced by isValid(), and isValidCigar().

00545 {
00546     return(isValidCigar(samRecord.getCigar(), 
00547                         samRecord.getReadLength(),
00548                         validationErrors));
00549 }

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.

Referenced by isValid().

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

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

Referenced by isValid().

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

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

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

Referenced by isValid().

00240 {
00241     // Validation for QNAME is:
00242     //   a) length of the qname string is the same as the read name length
00243     //   b) length is between 1 and 254.
00244     //   c) [ \t\n\r] are not allowed in the name.
00245 
00246     bool status = true;
00247 
00248     // Get the length of the qname string.
00249     int32_t qnameLenNull = strlen(qname) + 1;
00250 
00251     ////////////////////////////////////
00252     //   a) length of the qname string is the same as the read name length
00253     if(qnameLenNull != readNameLen)
00254     {
00255         // This results from a poorly formatted bam file, where the null
00256         // terminated read_name field is not the same length as specified by 
00257         // read_name_len.
00258         String message = "Invalid Query Name - the string length (";
00259         message += qnameLenNull;
00260         message += ") does not match the specified query name length (";
00261         message += readNameLen;
00262         message += ").";
00263 
00264         validationErrors.addError(SamValidationError::INVALID_QNAME,
00265                                   SamValidationError::ERROR, 
00266                                   message.c_str());
00267         status = false;
00268     }
00269 
00270     ////////////////////////////////////
00271     //   b) length is between 1 and 254
00272     // The length with the terminating null must be between 2 & 255,
00273     if((qnameLenNull < 2) || (qnameLenNull > 255))
00274     {
00275         String message = "Invalid Query Name (QNAME) length: ";
00276         message += qnameLenNull;
00277         message += ".  Length with the terminating null must be between 2 & 255.";
00278       
00279         validationErrors.addError(SamValidationError::INVALID_QNAME,
00280                                   SamValidationError::WARNING, 
00281                                   message.c_str());
00282         status = false;
00283     }
00284 
00285     ////////////////////////////////////
00286     // Loop through and validate they all characters are valid.
00287     //   c) [ \t\n\r] are not allowed in the name.
00288     String message;
00289     for(int i = 0; i < qnameLenNull; ++i)
00290     {
00291         switch(qname[i])
00292         {
00293             case ' ':
00294                 // Invalid character.
00295                 message = "Invalid character in the Query Name (QNAME): ' ' at position ";
00296                 message += i;
00297                 message += ".";
00298                 validationErrors.addError(SamValidationError::INVALID_QNAME,
00299                                           SamValidationError::WARNING, 
00300                                           message.c_str());
00301                 status = false;
00302                 break;
00303             case '\t':
00304                 // Invalid character.
00305                 message = "Invalid character in the Query Name (QNAME): '\t' at position ";
00306                 message += i;
00307                 message += ".";
00308                 validationErrors.addError(SamValidationError::INVALID_QNAME,
00309                                           SamValidationError::WARNING, 
00310                                           message.c_str());
00311                 status = false;
00312                 break;
00313             case '\n':
00314                 // Invalid character.
00315                 message = "Invalid character in the Query Name (QNAME): '\n' at position ";
00316                 message += i;
00317                 message += ".";
00318                 validationErrors.addError(SamValidationError::INVALID_QNAME,
00319                                           SamValidationError::WARNING, 
00320                                           message.c_str());
00321                 status = false;
00322                 break;
00323             case '\r':
00324                 // Invalid character.
00325                 message = "Invalid character in the Query Name (QNAME): '\r' at position ";
00326                 message += i;
00327                 message += ".";
00328                 validationErrors.addError(SamValidationError::INVALID_QNAME,
00329                                           SamValidationError::WARNING, 
00330                                           message.c_str());
00331                 status = false;
00332                 break;
00333         }
00334     }
00335 
00336     return(status);
00337 }

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

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

00639 {
00640     bool status = true;
00641 
00642     // If the quality or the sequence are non-"*", validate that the quality
00643     // and sequence have the same length.
00644     if((seqLength != 0) && (strcmp(quality, "*") != 0))
00645     {
00646         int qualLen = strlen(quality);
00647         // Both the sequence and the quality are not "*", so validate
00648         // that they are the same length.
00649         if(seqLength != qualLen)
00650         {
00651             // Both fields are specified but are different lengths.
00652             
00653             String message = "QUAL is not the same length as SEQ, (";
00654             message += qualLen;
00655             message += " != ";
00656             message += seqLength;
00657             message += ").";
00658             
00659             validationErrors.addError(SamValidationError::INVALID_QUAL,
00660                                       SamValidationError::WARNING, 
00661                                       message.c_str());
00662         status = false;
00663         }
00664     }
00665     return(status);
00666 }

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

References isValidQuality().

00623 {
00624     // Determine the length of the sequence.
00625     int seqLen = strlen(sequence);
00626 
00627     // Check if the sequence is '*' since then the seqLength is 0.
00628     if(strcmp(sequence, "*") == 0)
00629     {
00630         seqLen = 0;
00631     }
00632     return(isValidQuality(quality, seqLen, validationErrors));
00633 }

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

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

Referenced by isValid(), and isValidQuality().

00613 {
00614     return(isValidQuality(samRecord.getQuality(), 
00615                           samRecord.getReadLength(),
00616                           validationErrors));
00617 }

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.

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

Referenced by isValid().

00479 {
00480     // Validation for rID is:
00481     //   a) must be between -1 and the number of refInfo.
00482     //      -1 is allowed, and otherwise it must properly index into the array.
00483 
00484     bool status = true;
00485     if((refID < -1) || (refID >= refInfo.getNumEntries()))
00486     {
00487         // Reference ID is too large or too small.
00488         String message = "Invalid Reference ID, out of range (";
00489         message += refID;
00490         message += ") must be between -1 and ";
00491         message += refInfo.getNumEntries() - 1;
00492         message += ".";
00493 
00494         validationErrors.addError(SamValidationError::INVALID_REF_ID,
00495                                   SamValidationError::WARNING, 
00496                                   message.c_str());
00497         status = false;
00498     }
00499 
00500     return(status);
00501 }

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

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

00378 {
00379     // Validation for RNAME is:
00380     //   a) cannot be 0 length.
00381     //   b) [ \t\n\r@=] are not allowed in the name.
00382 
00383     bool status = true;
00384 
00385     // Get the length of the rname string.
00386     int32_t rnameLen = strlen(rname);
00387 
00388     String message;
00389 
00390     if(rnameLen == 0)
00391     {
00392         validationErrors.addError(SamValidationError::INVALID_RNAME,
00393                                   SamValidationError::WARNING, 
00394                                   "Reference Sequence Name (RNAME) cannot have 0 length.");
00395         status = false;
00396     }
00397 
00398     ////////////////////////////////////
00399     ////////////////////////////////////
00400     // Loop through and validate they all characters are valid.
00401     //   b) [ \t\n\r] are not allowed in the name.
00402     for(int i = 0; i < rnameLen; ++i)
00403     {
00404         switch(rname[i])
00405         {
00406             case ' ':
00407                 // Invalid character.
00408                 message = "Invalid character in the Reference Sequence Name (RNAME): ' ' at position ";
00409                 message += i;
00410                 message += ".";
00411                 validationErrors.addError(SamValidationError::INVALID_RNAME,
00412                                           SamValidationError::WARNING, 
00413                                           message.c_str());
00414                 status = false;
00415                 break;
00416             case '\t':
00417                 // Invalid character.
00418                 message = "Invalid character in the Reference Sequence Name (RNAME): '\t' at position ";
00419                 message += i;
00420                 message += ".";
00421                 validationErrors.addError(SamValidationError::INVALID_RNAME,
00422                                           SamValidationError::WARNING, 
00423                                           message.c_str());
00424                 status = false;
00425                 break;
00426             case '\n':
00427                 // Invalid character.
00428                 message = "Invalid character in the Reference Sequence Name (RNAME): '\n' at position ";
00429                 message += i;
00430                 message += ".";
00431                 validationErrors.addError(SamValidationError::INVALID_RNAME,
00432                                           SamValidationError::WARNING, 
00433                                           message.c_str());
00434                 status = false;
00435                 break;
00436             case '\r':
00437                 // Invalid character.
00438                 message = "Invalid character in the Reference Sequence Name (RNAME): '\r' at position ";
00439                 message += i;
00440                 message += ".";
00441                 validationErrors.addError(SamValidationError::INVALID_RNAME,
00442                                           SamValidationError::WARNING, 
00443                                           message.c_str());
00444                 status = false;
00445                 break;
00446             case '@':
00447                 // Invalid character.
00448                 message = "Invalid character in the Reference Sequence Name (RNAME): '@' at position ";
00449                 message += i;
00450                 message += ".";
00451                 validationErrors.addError(SamValidationError::INVALID_RNAME,
00452                                           SamValidationError::WARNING, 
00453                                           message.c_str());
00454                 status = false;
00455                 break;
00456             case '=':
00457                 // Invalid character.
00458                 message = "Invalid character in the Reference Sequence Name (RNAME): '=' at position ";
00459                 message += i;
00460                 message += ".";
00461                 validationErrors.addError(SamValidationError::INVALID_RNAME,
00462                                           SamValidationError::WARNING, 
00463                                           message.c_str());
00464                 status = false;
00465                 break;
00466             default:
00467                 // Allowed character.
00468                 break;
00469         }
00470     }
00471 
00472     return(status);
00473 }

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.

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

Referenced by isValid().

00351 {
00352     bool status = true;
00353 
00354     // Cross validate the rname and the header.
00355     // If the rname is not '*'
00356     // AND there are any SQ records in the header,
00357     // Then the rname must be in one of them.
00358     if((strcmp(rname, "*") != 0) &&
00359        (samHeader.getNumSQs() != 0) && 
00360        (samHeader.getSQ(rname) == NULL))
00361     {
00362         // There are SQ fields, but the ref name is not in it.
00363         status = false;
00364         std::string message = "RNAME, ";
00365         message += rname;
00366         message += ", was not found in a SAM Header SQ record";
00367         validationErrors.addError(SamValidationError::INVALID_RNAME,
00368                                   SamValidationError::WARNING,
00369                                   message.c_str());
00370     }
00371     status &= isValidRname(rname, validationErrors);
00372     return(status);
00373 }

static bool SamValidator::isValidSeq (  )  [static]

TODO, validate the sequence.

Returns:
true if it is valid, false and appends to SamValidationErrors if it is not
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.

Referenced by isValid().

00538 {
00539     return(true);
00540 }

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

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

Referenced by isValid().

00671 {
00672     bool status = true;
00673 
00674     GenomeSequence* reference = samRecord.getReference();
00675     // If the reference is not null, check the MD tag.
00676     if(reference != NULL)
00677     {
00678         String* recordMD = samRecord.getStringTag(SamTags::MD_TAG);
00679         if(recordMD != NULL)
00680         {
00681             // The record has an MD tag so check to see if it is correct.
00682             if(!SamTags::isMDTagCorrect(samRecord, *reference))
00683             {
00684                 // Invalid MD tags.
00685                 String correctMD;
00686                 if(!SamTags::createMDTag(correctMD, samRecord, *reference))
00687                 {
00688                     // Failed to get the MD tag, so indicate that it is unknown.
00689                     correctMD = "UNKNOWN";
00690                 }
00691                 String message = "Incorrect MD Tag, ";
00692                 message += *recordMD;
00693                 message += ", should be ";
00694                 message += correctMD;
00695                 message += ".";
00696                 
00697                 validationErrors.addError(SamValidationError::INVALID_TAG,
00698                                           SamValidationError::WARNING, 
00699                                           message.c_str());
00700                 
00701                 status = false;
00702             }
00703         }
00704     }
00705 
00706     return(status);
00707 }

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
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:
Generated on Tue Sep 6 17:52:07 2011 for libStatGen Software by  doxygen 1.6.3