1
$\begingroup$

I'm trying to do some calculus in parallel with BAM files. For that, I need to split the input bam file in chunks, process them in parallel and join them at the end. But I'm facing a read duplication issue on the split points.

I'm trying to split the input files by equally sized intervals (computed by GATK SplitIntervals), but that means the one of the files will contain all reads that covers the last base of the interval and the next file will contain all the reads that covers the following position. This means that we are putting in both files all the reads that crosses the boundary.

When we have to merge the results back into one file (via merge, sort or GatherBamFiles), all this repeated reads go into the result file, givin us a bam file with some extra reads that happen to have the same ID as others (because, in fact, they are the same).

Which would be the way to go to accomplish this task? How could I gather the files without duplicates? Or how could I split the files without putting the same read in more than one file?

For reference, these are the commands I'm trying to check that I'm duplicating reads. I extract a one base interval from a file, the next base interval from the same file and finally counting the number of reads in the files:

$ samtools view -c test.bam 1:18454-18454  # Reads covering position 18454
251
$ samtools view -c test.bam 1:18455-18455  # Reads covering position 18455
250
$ samtools view -c test.bam 1:18454-18455  # Reads covering 18454-18455 range
251

$ samtools view -b -o test.1_18454_18454.bam test.bam 1:18454-18454
$ samtools view -b -o test.1_18455_18455.bam test.bam 1:18455-18455

$ samtools view -c test.1_18454_18454.bam  # Reads extracted that covers position 18454
251
$ samtools view -c test.1_18455_18455.bam  # Reads extracted that covers position 18455
250

$ samtools merge test.1_18454_18455.merged.bam test.1_18454_18454.bam test.1_18455_18455.bam
$ samtools view -c test.1_18454_18455.merged.bam  # Reads merged that covers 18454-18455 range
501
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.