Hi,

I am using **samtools markdup -r** parameter to remove PCR duplicates from my mapped ChIP reads. How does it detects the PCR duplicated reads?

Please let me know if I am understanding it correctly. This is what I understood:

I need to name sort the mapped reads and put MS-MC tags (using fixmate) and then I need to coordinate sort the reads before using the "**markdup -r**" command. 
If the chromosome number and 5' end of the read are the same, it will treat them as duplicate and by looking at the MC and MS scores it will choose the best-read among the duplicates and delete the rest of the reads (I am using **"-r"** parameter).. Is this what is happening here?

Any kind of help will be highly appreciated.

Thanks

-S
Samtools markdup is written to match Picard 2.10.3 (also Biobambam's bamstreamingmarkduplicates) so if you can find documentation on those then it should also apply to Samtools.

It may seem like a complex dance to have both name and position sorted requirements, but this is perhaps due to a traditional view and attempting to do markdup as an after thought.

The design leverages the fact that the data produced by the sequencing instrument and subsequent aligner will be name collated (not sorted, but collated is all it actually needs - we should probably fix the man page).  So while it is in this order we can add additional tags regarding the other ends of reads in an efficient manner.  Then after positional sorting markdup has sufficient information to make the assessment which it can now also do in an efficient manner.

When viewed in that perspective, marking duplicates actually has zero additional sort steps than we're already using in our standard pipelines.  Hopefully that helps to explain the somewhat unusual approach.

As for the exact maths, I don't know all the intricacies, but I think it's pretty much as you describe.  There is more information here:

https://www.htslib.org/doc/samtools-markdup.1.html

https://www.htslib.org/algorithms/duplicate.html