<p>Yes, if MarkDuplicates encounters a pair that's marked as a duplicate that it considers (for whatever reason) to not be a duplicate then it will unset the duplicate mark. You can test this yourself by making a small BAM file either with or without duplicate entries but some marked regardless. In the case of actual duplicates, the duplicate flag will be maintained. In the case where there are no actual duplicates then the flag will be removed. At least that's the case in version 2.14.</p>

CC BY-SA 3.0
2017-10-30T20:15:42.250Z
2017-10-30T20:15:42.250Z
Devon Ryan
<p>I have a RNA-seq bam file and there are few reads that are puzzling me.</p>

<p>According to the bam header, this bam file is sorted by coordinate, created using tophat and markduplicate step is not done. But some reads are marked for being duplicate in the samflag. What is worse is when I run picard markduplicate, these reads' pcr duplicate flag is toggled, marking them not a duplicate. Also I manually found the duplicate of this read (identical reads with same start positions and mates start position) so initial marking looks true.</p>

<p>So my questions are: </p>

<p>Any idea why would this happen?</p>

<p>Does Tophat mark reads for being duplicate? ( I don't think so)
And does <code>picard markduplicate</code> toggle the duplicate flag if the reads are already marked as being duplicates?</p>

<p>Here is how the read looks before and after mark duplicate step.<br></p>

<p>Before:</p>

<pre><code>C0RTF 1187 17 7579880 255 61M10754N40M = 7579927 10902 CTC... 
0UNP1 163 17 7579880 255 61M10754N40M = 7579927 10902 CTC... 
</code></pre>

<p>After Markduplicate:</p>

<pre><code>C0RTF 163 17 7579880 255 61M10754N40M = 7579927 10902 CTC... 
0UNP1 163 17 7579880 255 61M10754N40M = 7579927 10902 CTC... 
</code></pre>

CC BY-SA 3.0
2017-10-30T14:21:48.503Z
> And does picard markduplicate toggle the duplicate flag if the reads are already marked as being duplicates? yes: https://github.com/broadinstitute/picard/blob/master/src/main/java/picard/sam/markduplicates/MarkDuplicates.java#L342
Pierre
CC BY-SA 3.0
2017-10-30T16:00:58.443Z
@Pierre I know no Java, but that looks like it will unset the duplicate flag if `isDuplicate` is false. Not if it is already true. Am I missing something?
terdon
CC BY-SA 3.0
2017-10-30T16:18:25.307Z
@terdon: if it's duplicate the flag is set https://github.com/broadinstitute/picard/blob/master/src/main/java/picard/sam/markduplicates/MarkDuplicates.java#L330 , else it is unset https://github.com/broadinstitute/picard/blob/master/src/main/java/picard/sam/markduplicates/MarkDuplicates.java#L342
Pierre
CC BY-SA 3.0
2017-10-30T16:33:09.253Z
@Pierre yes, exactly. If I understand correctly, the OP has a file with the duplicate flags already set but, when passed through markDuplicates, the flags that were set are now toggled: they're unset, so they are no longer marked as duplicates. The code you show would suggest that if the flag is already set, nothing will be changed. Unless picard doesn't read the flags and only does its own calculations to determine the dupes and, in this case, disagreed with whatever produced the original markings.
terdon
<rna-seq><samtools><markduplicate>
Does picard markduplicate toggle PCR duplicate samflag
# Does picard markduplicate toggle PCR duplicate samflag

(Asked by: username_0 on 2017-10-27)

I have a RNA-seq bam file and there are few reads that are puzzling me.
According to the bam header, this bam file is sorted by coordinate, created using tophat and markduplicate step is not done. But some reads are marked for being duplicate in the samflag. What is worse is when I run picard markduplicate, these reads' pcr duplicate flag is toggled, marking them not a duplicate. Also I manually found the duplicate of this read (identical reads with same start positions and mates start position) so initial marking looks true.
So my questions are: 
Any idea why would this happen?
Does Tophat mark reads for being duplicate? ( I don't think so)
And does picard markduplicate toggle the duplicate flag if the reads are already marked as being duplicates?
Here is how the read looks before and after mark duplicate step.
Before:
C0RTF 1187 17 7579880 255 61M10754N40M = 7579927 10902 CTC... 
0UNP1 163 17 7579880 255 61M10754N40M = 7579927 10902 CTC... 

After Markduplicate:
C0RTF 163 17 7579880 255 61M10754N40M = 7579927 10902 CTC... 
0UNP1 163 17 7579880 255 61M10754N40M = 7579927 10902 CTC...

**Tags:** rna-seq, samtools, markduplicate
> **Comments:**
> **username_1**: > And does picard markduplicate toggle the duplicate flag if the reads are already marked as being duplicates? yes: https://github.com/broadinstitute/picard/blob/master/src/main/java/picard/sam/markduplicates/MarkDuplicates.java#L342  
> **username_2**: @Pierre I know no Java, but that looks like it will unset the duplicate flag if `isDuplicate` is false. Not if it is already true. Am I missing something?  
> **username_1**: @terdon: if it's duplicate the flag is set https://github.com/broadinstitute/picard/blob/master/src/main/java/picard/sam/markduplicates/MarkDuplicates.java#L330 , else it is unset https://github.com/broadinstitute/picard/blob/master/src/main/java/picard/sam/markduplicates/MarkDuplicates.java#L342  
> **username_2**: @Pierre yes, exactly. If I understand correctly, the OP has a file with the duplicate flags already set but, when passed through markDuplicates, the flags that were set are now toggled: they're unset, so they are no longer marked as duplicates. The code you show would suggest that if the flag is already set, nothing will be changed. Unless picard doesn't read the flags and only does its own calculations to determine the dupes and, in this case, disagreed with whatever produced the original markings.  

---

## 1 answers

### Answer by username_3 on 2017-10-30. Score: 6

Yes, if MarkDuplicates encounters a pair that's marked as a duplicate that it considers (for whatever reason) to not be a duplicate then it will unset the duplicate mark. You can test this yourself by making a small BAM file either with or without duplicate entries but some marked regardless. In the case of actual duplicates, the duplicate flag will be maintained. In the case where there are no actual duplicates then the flag will be removed. At least that's the case in version 2.14.


---

