Changes

From Genome Analysis Wiki
Jump to navigationJump to search
726 bytes added ,  10:41, 6 April 2010
Line 69: Line 69:  
   // Read the first sam record.
 
   // Read the first sam record.
 
   SamRecord samRecord;
 
   SamRecord samRecord;
 +
 +
  // Track if any of the records are invalid.  Initialize to 0, it will
 +
  // be set to -1 on an invalid record.
 +
  int status = 0;
    
   // Keep reading records until the end of the file is reached.
 
   // Keep reading records until the end of the file is reached.
 
   int numValidRecords = 0;
 
   int numValidRecords = 0;
  int numRecords = 0;
   
   while(!samIn.IsEOF())
 
   while(!samIn.IsEOF())
 
   {
 
   {
 
       if(samIn.ReadRecord(samHeader, samRecord) == true)
 
       if(samIn.ReadRecord(samHeader, samRecord) == true)
 
       {
 
       {
        numRecords++;
   
         // Successfully read a record from the file, so check to see
 
         // Successfully read a record from the file, so check to see
 
         // if it is valid.
 
         // if it is valid.
Line 85: Line 87:  
             numValidRecords++;
 
             numValidRecords++;
 
             samOut.WriteRecord(samHeader, samRecord);
 
             samOut.WriteRecord(samHeader, samRecord);
 +
        }
 +
        else
 +
        {
 +
            // There is at least one invalid record, return -1.
 +
            status = -1;
 +
        }
 +
      }
 +
      else
 +
      {
 +
        // Failed to read the record.  Check to see if it failed due to
 +
        // there being no more records, which is not a failure.  Any
 +
        // other failure reason counts as a failure.
 +
        if(samIn.GetFailure() != SamStatus::NO_MORE_RECS)
 +
        {
 +
            // Read failed, invalid.
 +
            status = -1;
 
         }
 
         }
 
       }
 
       }
     
   
   }
 
   }
   std::cout << "Number of records = " << numRecords << std::endl;
+
   std::cout << "Number of records read = " <<  
 +
      samIn.GetCurrentRecordCount() << std::endl;
 +
  std::cout << "Number of records written = " <<
 +
      samOut.GetCurrentRecordCount() << std::endl;
 
   std::cout << "Number of valid records = " << numValidRecords << std::endl;
 
   std::cout << "Number of valid records = " << numValidRecords << std::endl;
 +
 +
  return(status);
 
}
 
}
 
</source>
 
</source>
      
== Reading Indexed (and Sorted) BAM Files ==
 
== Reading Indexed (and Sorted) BAM Files ==

Navigation menu