This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to solve the error 'ERROR::MATE_NOT_FOUND:Found xxx unpaired mates' when run SamToFastq

Good morning,

I aim to chop an already aligned bam file based on different regions of a gene as follow:

samtools view -b -o out.bam -L  regions.bed origin.bam

samtools sort -o  out.sort.bam out.bam

samtools index 

Then I want to convert the out.bam into two unaligned FASTQ files (each member of the read pair parsed to one of the two files) using SamToFastq:

java -jar picard.jar SamToFastq I=out.sort.bam  F=out.sort.bam_R1.fastq F2=out.sort.bam_R2.fastq

at this point I get the error: SAM validation error: ERROR::MATE_NOT_FOUND:Found 227 unpaired mates

see below output from java -Xmx10g -jar picard.jar ValidateSamFile I=out.sort.bam O=out_file.log

ERROR::MATE_NOT_FOUND:Read name xxxx, Mate not found for paired read

I've also tried samtools fixmate -r out.sort.bam out.sort.bam_fixmate.bam but doesn't work.

Any suggestions about how to fix this or an alternative way to do it?

Thank you!

samtofasq picard validatesamfile

1 answer

faster use samtools collate+ fastq

samtools collate -uOn128 in.bam TMPDIR | samtools fastq  -1 R1.fq.gz -2 R2.fq.gz -s Rx.fq.gz -0 R0.fq.gz

Thank you for the feedback! I already used just the samtools fastq -1 R1.fq.gz -2 R2.fq.gz -s Rx.fq.gz -0 R0.fq.gz. Could you please explain what the collate does? Thank you!

Log in to answer this question.