I have two paired-end FASQ files named fq1.fastq and fq2.fastq. Then I use BWA MEM to map these two files with the paired-end mode, like this:
bwa mem reference.fasta fq1.fastq fq2.fastq > result.sam
Then I transfer this sam file to bam format and sort it by coordinates with samtools:
samtools view result.sam > result.bam && samtools sort result.bam -o result_sort.bam
Now I want to restore these two fastq files from result_sort.bam. I know that I can use picard SamToFastq to do this. But reads in fastq files not remain sorted like the result_sort.bam. So, is there any other way that I can restore fastq files with reads sorted? I want to do this, because when I get fq1.fastq and fq2.fastq from result_sort.bam and use BWA to map then I again, I can get a sam file within that many reads are sorted. Any reply will be much appreciated!