Neither of these methods is going to take care of the duplicates. It does not appear that @Picasa ran the MarkDuplicates command with REMOVE_DUPLICATES=TRUE option.
Hi everybody,
From a mapping file, I used the fonction to assess my duplicates rates
picard-tools MarkDuplicates I=input.bam O=output.bam M=marked_dup_metrics.txt
I would like to creates 2 fastq files (paired end reads) without those duplicates and keep mate as possible.
Should I use samtools to keep only non duplicates paired reads ? what would be the flag/command ?
Thanks for your help.
1 answer
To remove duplication in picard set
REMOVE_DUPLICATES=true
like
java -jar picard.jar MarkDuplicates \
I=input.bam \
O=marked_duplicates.bam \
REMOVE_DUPLICATES=true \
M=marked_dup_metrics.txt
After that sort by query name, then you can extract them like follow
samtools sort -n aln.bam aln.qsort
bedtools bamtofastq -i aln.qsort.bam -fq aln.end1.fq -fq2 aln.end2.fq
using picard
java -jar picard.jar SamToFASTQ INPUT=<bamfile> FASTQ=outfile_1.fastq SECOND_END_FASTQ=outfile_2.fastq
I saw that after posting the answer "I thought that he did remove it" then I changed it
Thanks for your help.
1) Does it keep the paired end ? I mean if reads 1 is a duplicate and reads 2 is not, does it discard the both ? (this is what I want)
2) is that mandatory to sort by query name ?
To answer the first question I will quote from previous answer
If you have a paired data, then both reads for a pair will be used to select duplicates. In this case, if there is another pair that has both of its reads aligning at the same exact location as this pair, then one of these would be marked as duplicates
more info can be found here A: Samtools Remove Duplicates Question
2) is that mandatory to sort by query name ?
It should be according to documentation
BAM should be sorted by query name (samtools sort -n aln.bam aln.qsort) if creating paired FASTQ with this option.
Log in to answer this question.
If you have not done so already then run
MarkDuplicateswithREMOVE_DUPLICATES=TRUEoption. Then @Medhat's methods mentioned below will work.