Thank you for your explanation. But I tried the method you said and got the following results. I don't know whether this result is right or not or some sequences will be lost.
Set INTERLEAVED to false
Started output stream.
Input: 93882272 reads 13772616099 bases.
Result: 93882272 reads (100.00%) 13772616099 bases (100.00%)
Pairs: 93882272 reads (100.00%) 13772616099 bases (100.00%)
Singletons: 0 reads (0.00%) 0 bases (0.00%)
Time: 156.499 seconds.
Reads Processed: 93882k 599.89k reads/sec
Bases Processed: 13772m 88.00m bases/sec
it's just a warning. samtools cannot find some reads associated to a pair of reads. It can happen if it's a sub region of the bam , or some reads were removed.
I'm sorry. Do you mean to ignore the warning? But when I do bwa mem after conversion, it can't run. Is there any way to solve this problem?
Maybe try samtools fixmate first, and then bamtofastq?
Thank you! I've tried your method, but there is still warning.
Has there been any kind of filtering applied to the bam file that you want to convert?
Sorry, I don't quite understand what you mean. I used the above method.
Yes, but after initial alignment of the data to produce that bam file, has there been any filtering applied that might explain why certain mates are missing.
I use BWA and samtools software to get the initial bam file, and then use Picard (RG, mark duplicate, build BAM index) and gatk (I use BWA and sampools software to get the initial BAM file, and then use Picard (RG, mark duplicate, build BAM index) and gatk ( RealignerTargetCreator, IndelRealigner) to get the final BAM file. Now I want to convert the final BAM file to fastq file (the previous fastq file has been lost), so I used the above method. Other filters are not used.
You obviously lost some of the mates during your processing. My guess is that one of the steps you've used filtered out one of the mates but kept the other one. Without having the whole code it's impossible to know where they got lost. And since it seems you don't have any of the previous BAMs you will have to go with fixing the mate pairs as commented below.