Skip to content
Snippets Groups Projects
Commit afc844d4 authored by Aaron's avatar Aaron
Browse files

Added logic to keep dups and failed QC for multiBamCov. Thanks to Chip Stewart.

parent 04a6b489
No related branches found
No related tags found
No related merge requests found
...@@ -17,12 +17,16 @@ ...@@ -17,12 +17,16 @@
/* /*
Constructor Constructor
*/ */
MultiCovBam::MultiCovBam(const vector<string> &bam_files, const string bed_file, int minQual, bool properOnly) MultiCovBam::MultiCovBam(const vector<string> &bam_files, const string bed_file,
int minQual, bool properOnly,
bool keepDuplicates, bool keepFailedQC)
: :
_bam_files(bam_files), _bam_files(bam_files),
_bed_file(bed_file), _bed_file(bed_file),
_minQual(minQual), _minQual(minQual),
_properOnly(properOnly) _properOnly(properOnly),
_keepDuplicates(keepDuplicates),
_keepFailedQC(keepFailedQC)
{ {
_bed = new BedFile(_bed_file); _bed = new BedFile(_bed_file);
LoadBamFileMap(); LoadBamFileMap();
...@@ -76,8 +80,12 @@ void MultiCovBam::CollectCoverage() ...@@ -76,8 +80,12 @@ void MultiCovBam::CollectCoverage()
BamAlignment al; BamAlignment al;
while ( reader.GetNextAlignment(al) ) while ( reader.GetNextAlignment(al) )
{ {
bool duplicate = al.IsDuplicate();
bool failedQC = al.IsFailedQC();
if (_keepDuplicates) duplicate = false;
if (_keepFailedQC) failedQC = false;
// map qual must exceed minimum // map qual must exceed minimum
if (al.MapQuality >= _minQual) { if ((al.MapQuality >= _minQual) && (!duplicate) && (!failedQC)) {
// ignore if not properly paired and we actually care. // ignore if not properly paired and we actually care.
if (_properOnly && !al.IsProperPair()) if (_properOnly && !al.IsProperPair())
continue; continue;
......
...@@ -30,7 +30,9 @@ class MultiCovBam { ...@@ -30,7 +30,9 @@ class MultiCovBam {
public: public:
// constructor // constructor
MultiCovBam(const vector<string> &bam_files, const string bed_file, int minQual, bool properOnly); MultiCovBam(const vector<string> &bam_files, const string bed_file,
int minQual, bool properOnly,
bool keepDuplicates, bool keepFailedQC);
// destructor // destructor
~MultiCovBam(void); ~MultiCovBam(void);
...@@ -49,6 +51,9 @@ private: ...@@ -49,6 +51,9 @@ private:
// attributes to control what is counted // attributes to control what is counted
int _minQual; int _minQual;
bool _properOnly; bool _properOnly;
bool _keepDuplicates;
bool _keepFailedQC;
map<string, int> bamFileMap; map<string, int> bamFileMap;
......
...@@ -38,6 +38,8 @@ int main(int argc, char* argv[]) { ...@@ -38,6 +38,8 @@ int main(int argc, char* argv[]) {
bool haveBed = false; bool haveBed = false;
bool haveBams = false; bool haveBams = false;
bool properOnly = false; bool properOnly = false;
bool keepDuplicates = false;
bool keepFailedQC = false;
// check to see if we should print out some help // check to see if we should print out some help
if(argc <= 1) showHelp = true; if(argc <= 1) showHelp = true;
...@@ -88,10 +90,21 @@ int main(int argc, char* argv[]) { ...@@ -88,10 +90,21 @@ int main(int argc, char* argv[]) {
else if(PARAMETER_CHECK("-p", 2, parameterLength)) { else if(PARAMETER_CHECK("-p", 2, parameterLength)) {
properOnly = true; properOnly = true;
} }
else if(PARAMETER_CHECK("-D", 2, parameterLength)) {
keepDuplicates = true;
}
else if(PARAMETER_CHECK("-F", 2, parameterLength)) {
keepFailedQC = true;
}
else {
cerr << endl << "*****ERROR: Unrecognized parameter: " << argv[i] << " *****" << endl << endl;
showHelp = true;
}
} }
if (!showHelp) { if (!showHelp) {
MultiCovBam *mc = new MultiCovBam(bamFiles, bedFile, minQual, properOnly); MultiCovBam *mc = new MultiCovBam(bamFiles, bedFile, minQual, properOnly, keepDuplicates, keepFailedQC);
mc->CollectCoverage(); mc->CollectCoverage();
delete mc; delete mc;
return 0; return 0;
...@@ -119,6 +132,10 @@ void ShowHelp(void) { ...@@ -119,6 +132,10 @@ void ShowHelp(void) {
cerr << "\t-q\t" << "Minimum mapping quality allowed. Default is 0." << endl << endl; cerr << "\t-q\t" << "Minimum mapping quality allowed. Default is 0." << endl << endl;
cerr << "\t-D\t" << "Include duplicate-marked reads. Default is to count non-duplicates only" << endl << endl;
cerr << "\t-F\t" << "Include failed-QC reads. Default is to count pass-QC reads only" << endl << endl;
cerr << "\t-p\t" << "Only count proper pairs. Default is to count all alignments with MAPQ" << endl; cerr << "\t-p\t" << "Only count proper pairs. Default is to count all alignments with MAPQ" << endl;
cerr << "\t\t" << "greater than the -q argument, regardless of the BAM FLAG field." << endl << endl; cerr << "\t\t" << "greater than the -q argument, regardless of the BAM FLAG field." << endl << endl;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment