I need to get a .fq file and I have bam files, I am following a code that I found online that sorts it at first
samtools sort -n file.bam > sorted.bam
and then converts it to fastq
samtools fastq sorted.bam > file.fq
Is the sort needed? I think in this case it was used because the data had paired-end reads and sorting by read name makes it so that the files have the mates in the same order, and that can make things easier when using the fastq files (I think???)
But is it needed in single-end data?
So with paired-end I can avoid the sort and use
samtools collate file.bam | samtools fastq > file.fq
while with single end I can directly convert to fastq?