Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intersect library fragments and not alignment in multibamcov #72

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions src/multiBamCov/multiBamCov.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ MultiCovBam::MultiCovBam(const vector<string> &bam_files, const string bed_file,
bool keepDuplicates, bool keepFailedQC,
bool obeySplits, bool sameStrand,
bool diffStrand, float overlapFraction,
bool reciprocal)
bool reciprocal, bool extendOneRead)
:
_bam_files(bam_files),
_bed_file(bed_file),
Expand All @@ -34,7 +34,8 @@ _obeySplits(obeySplits),
_sameStrand(sameStrand),
_diffStrand(diffStrand),
_overlapFraction(overlapFraction),
_reciprocal(reciprocal)
_reciprocal(reciprocal),
_extendOneRead(extendOneRead)
{
_bed = new BedFile(_bed_file);
LoadBamFileMap();
Expand Down Expand Up @@ -157,6 +158,8 @@ void MultiCovBam::CollectCoverage()
(_diffStrand && strands_are_same) ||
(al.MapQuality < _minQual) ||
(duplicate) ||
(_extendOneRead && al.IsSecondMate()) ||
(_extendOneRead && !al.IsProperPair()) ||
(failedQC)
)
{
Expand Down Expand Up @@ -185,6 +188,32 @@ void MultiCovBam::CollectCoverage()
counts[bamFileMap[al.Filename]]++;
}
}
else if (_extendOneRead) {
int al_start = al.Position;
if (al.IsReverseStrand())
al_start = al.MatePosition;

int al_end = al.InsertSize + al_start;

CHRPOS s = max(al.Position, (int) bed.start);
CHRPOS e = min(al_end, (int) bed.end);
CHRPOS aLength = (bed.end - bed.start);
CHRPOS bLength = (al_end - al.Position);
int overlapBases = (e - s);
float aOverlap =
( (float) overlapBases / (float) aLength );
float bOverlap =
( (float) overlapBases / (float) bLength );

if ( aOverlap >= _overlapFraction)
{
if (!_reciprocal)
counts[bamFileMap[al.Filename]]++;
else if (bOverlap >= _overlapFraction)
counts[bamFileMap[al.Filename]]++;
}

}
else {
// break alignment into discrete blocks,
bedVector bed_blocks, hits;
Expand Down
3 changes: 2 additions & 1 deletion src/multiBamCov/multiBamCov.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class MultiCovBam {
bool keepDuplicates, bool keepFailedQC,
bool obeySplits, bool sameStrand,
bool diffStrand, float overlapFraction,
bool reciprocal);
bool reciprocal, bool extendOneRead);

// destructor
~MultiCovBam(void);
Expand All @@ -62,6 +62,7 @@ class MultiCovBam {
bool _diffStrand;
float _overlapFraction;
bool _reciprocal;
bool _extendOneRead;


map<string, int> bamFileMap;
Expand Down
15 changes: 14 additions & 1 deletion src/multiBamCov/multiBamCovMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ int multibamcov_main(int argc, char* argv[]) {
float overlapFraction = 1E-9;
bool haveFraction = false;
bool reciprocalFraction = false;
bool extendOneRead = false;

// check to see if we should print out some help
if(argc <= 1) showHelp = true;
Expand Down Expand Up @@ -121,11 +122,21 @@ int multibamcov_main(int argc, char* argv[]) {
else if (PARAMETER_CHECK("-S", 2, parameterLength)) {
diffStrand = true;
}
else if (PARAMETER_CHECK("-E", 2, parameterLength)) {
extendOneRead = true;
}
else {
cerr << endl << "*****ERROR: Unrecognized parameter: " <<
argv[i] << " *****" << endl << endl;
showHelp = true;
}

if (extendOneRead && (sameStrand || diffStrand))
cerr << endl << "*****ERROR: read extension cannot be used with strand constrains" << endl;
if (extendOneRead && obeySplits)
cerr << endl << "*****ERROR: read extension cannot be used with split option" << endl;


}

if (!showHelp) {
Expand All @@ -134,7 +145,7 @@ int multibamcov_main(int argc, char* argv[]) {
keepDuplicates, keepFailedQC,
obeySplits, sameStrand,
diffStrand, overlapFraction,
reciprocalFraction);
reciprocalFraction, extendOneRead);
mc->CollectCoverage();
delete mc;
}
Expand Down Expand Up @@ -185,6 +196,8 @@ void multibamcov_help(void) {
cerr << "\t-p\t" << "Only count proper pairs. Default counts all alignments with" << endl;
cerr << "\t\t" << "MAPQ > -q argument, regardless of the BAM FLAG field." << endl << endl;

cerr << "\t-E\t" << "Extend one read (R1) to the extent of insert size" << endl << endl;

// end the program here
exit(1);

Expand Down