SamStatistics.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "SamStatistics.h"
00019 #include <iomanip>
00020 #include "SamFlag.h"
00021
00022 SamStatistics::SamStatistics()
00023 {
00024 reset();
00025 }
00026
00027 SamStatistics::~SamStatistics()
00028 {
00029 reset();
00030 }
00031
00032 void SamStatistics::reset()
00033 {
00034 myReadCount = 0;
00035 myMappedReadCount = 0;
00036 myPairedReadCount = 0;
00037 myProperPairedReadCount = 0;
00038 myBaseCount = 0;
00039 myMappedReadBases = 0;
00040 myDupReadCount = 0;
00041 myQCFailureReadCount = 0;
00042 }
00043
00044
00045 bool SamStatistics::updateStatistics(SamRecord& samRecord)
00046 {
00047
00048 ++myReadCount;
00049
00050 int32_t readLen = samRecord.getReadLength();
00051
00052
00053
00054 uint16_t flag = samRecord.getFlag();
00055
00056
00057 if(SamFlag::isMapped(flag))
00058 {
00059 ++myMappedReadCount;
00060 myMappedReadBases += readLen;
00061 }
00062 if(SamFlag::isPaired(flag))
00063 {
00064 ++myPairedReadCount;
00065 if(SamFlag::isProperPair(flag))
00066 {
00067 ++myProperPairedReadCount;
00068 }
00069 }
00070 if(SamFlag::isDuplicate(flag))
00071 {
00072 ++myDupReadCount;
00073 }
00074 if(SamFlag::isQCFailure(flag))
00075 {
00076 ++myQCFailureReadCount;
00077 }
00078
00079
00080 myBaseCount += readLen;
00081
00082 return(true);
00083 }
00084
00085
00086 void SamStatistics::print()
00087 {
00088 double DIVIDE_UNITS = 1000000;
00089 std::string units = "(e6)";
00090
00091 std::cerr << std::fixed << std::setprecision(2);
00092
00093
00094 if(myReadCount < DIVIDE_UNITS)
00095 {
00096 DIVIDE_UNITS = 1;
00097 units.clear();
00098 }
00099
00100
00101 std::cerr << "TotalReads" << units << "\t"
00102 << myReadCount/DIVIDE_UNITS << std::endl;
00103 std::cerr << "MappedReads" << units << "\t"
00104 << myMappedReadCount/DIVIDE_UNITS << std::endl;
00105 std::cerr << "PairedReads" << units << "\t"
00106 << myPairedReadCount/DIVIDE_UNITS << std::endl;
00107 std::cerr << "ProperPair" << units << "\t"
00108 << myProperPairedReadCount/DIVIDE_UNITS << std::endl;
00109 std::cerr << "DuplicateReads" << units << "\t"
00110 << myDupReadCount/DIVIDE_UNITS << std::endl;
00111 std::cerr << "QCFailureReads" << units << "\t"
00112 << myQCFailureReadCount/DIVIDE_UNITS << std::endl;
00113 std::cerr << std::endl;
00114
00115
00116 std::cerr << "MappingRate(%)\t"
00117 << 100 * myMappedReadCount/(double)myReadCount << std::endl;
00118 std::cerr << "PairedReads(%)\t"
00119 << 100 * myPairedReadCount/(double)myReadCount << std::endl;
00120 std::cerr << "ProperPair(%)\t"
00121 << 100 * myProperPairedReadCount/(double)myReadCount << std::endl;
00122 std::cerr << "DupRate(%)\t"
00123 << 100 * myDupReadCount/(double)myReadCount << std::endl;
00124 std::cerr << "QCFailRate(%)\t"
00125 << 100 * myQCFailureReadCount/(double)myReadCount << std::endl;
00126 std::cerr << std::endl;
00127
00128
00129 std::cerr << "TotalBases" << units << "\t"
00130 << myBaseCount/DIVIDE_UNITS << std::endl;
00131 std::cerr << "BasesInMappedReads" << units << "\t"
00132 << myMappedReadBases/DIVIDE_UNITS << std::endl;
00133 }