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

getBamBlocks no longer splits on D CIGAR ops when not wanted.

parent ca6fed36
No related branches found
No related tags found
No related merge requests found
...@@ -27,15 +27,21 @@ namespace BamTools { ...@@ -27,15 +27,21 @@ namespace BamTools {
string name = bam.Name; string name = bam.Name;
string strand = "+"; string strand = "+";
string score = ToString(bam.MapQuality); string score = ToString(bam.MapQuality);
char prevOp = '\0';
if (bam.IsReverseStrand()) strand = "-"; if (bam.IsReverseStrand()) strand = "-";
bool blocksFound = false;
vector<CigarOp>::const_iterator cigItr = bam.CigarData.begin(); vector<CigarOp>::const_iterator cigItr = bam.CigarData.begin();
vector<CigarOp>::const_iterator cigEnd = bam.CigarData.end(); vector<CigarOp>::const_iterator cigEnd = bam.CigarData.end();
for ( ; cigItr != cigEnd; ++cigItr ) { for ( ; cigItr != cigEnd; ++cigItr ) {
if (cigItr->Type == 'M') { if (cigItr->Type == 'M') {
currPosition += cigItr->Length; currPosition += cigItr->Length;
blocks.push_back( BED(chrom, blockStart, currPosition, name, score, strand) ); // we only want to create a new block if the current M op
blockStart = currPosition; // was preceded by an N op or a D op (and we are breaking on D ops)
if ((prevOp == 'D' && breakOnDeletionOps == true) || (prevOp == 'N')) {
blocks.push_back( BED(chrom, blockStart, currPosition, name, score, strand) );
blockStart = currPosition;
}
} }
else if (cigItr->Type == 'D') { else if (cigItr->Type == 'D') {
if (breakOnDeletionOps == false) if (breakOnDeletionOps == false)
...@@ -47,7 +53,8 @@ namespace BamTools { ...@@ -47,7 +53,8 @@ namespace BamTools {
} }
else if (cigItr->Type == 'N') { else if (cigItr->Type == 'N') {
currPosition += cigItr->Length; currPosition += cigItr->Length;
blockStart = currPosition; } blockStart = currPosition;
}
else if (cigItr->Type == 'S' || cigItr->Type == 'H' || cigItr->Type == 'P' || cigItr->Type == 'I') { else if (cigItr->Type == 'S' || cigItr->Type == 'H' || cigItr->Type == 'P' || cigItr->Type == 'I') {
// do nothing // do nothing
} }
...@@ -56,6 +63,11 @@ namespace BamTools { ...@@ -56,6 +63,11 @@ namespace BamTools {
<< ") for: " << bam.Name << endl; << ") for: " << bam.Name << endl;
exit(1); exit(1);
} }
prevOp = cigItr->Type;
}
// if there were no splits, we just create a block representing the contiguous alignment.
if (blocksFound == false) {
blocks.push_back( BED(chrom, bam.Position, currPosition, name, score, strand) );
} }
} }
} }
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