This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Convert Bam To Fastq With Pe & Se Reads

Hi there,

EDIT

I filtered my PE reads based on quality. Filtering generated 3 kind of files:

  • 1 file with PE of good quality
  • 1 file with discarded reads,
  • 1 file with orphan PE reads of good quality(unpaired PE).

I concatenated good quality reads, and submitted my reads to BWA to generate a SAM file. So basically, all my reads "look like" PE reads, even though I have unpaired reads.

!EDIT

I would like to convert a BAM/SAM file to FASTQ. The thing is that my BAM file contains Paired-end reads and Single-end reads, and I'd like a tool that will generate 3 files :

  • 1 file with paired end reads #1
  • 1 file with paired end reads #2
  • 1 file with single end reads (unpaired)

I tried Picard and Bam2Fastq but this option doesnt exist. Any idea ?

Thanks

fastq bam next-gen sequencing

3 answers

You could use samtools view to filter the .bam into three files; reads that are read 1, reads that are read 2, and reads from SE experiments. Picard can sort each .bam by read name, before you convert them to fastq.

Question edited with more details

What's so onerous about running samtools view 3 times to split up the .bam into those three groups?

samtools view -bf 64 mixed.bam > read1.bam samtools view -bf 128 mixed.bam > read2.bam samtools view -bF 1 mixed.bam > SE.bam

Then run bam2fastq on each of those files.

Swbarnes2 method is quite right. three Step:

1, Get all the reads belong to read1 (paired-end). With -f 64, you can get all the reads including 64, such as 65, 193 and so on

samtools view -bf 64 mixed.bam > read1.bam

2, Get all the reads belong to read2 (paired-end). With -f 128, you can get all the reads including 128, such as 129, 177 and so on

samtools view -bf 128 mixed.bam > read2.bam

3, Get all the reads belong to single-end. With -F 1, you can exclude all the pair-end reads.

samtools view -bF 1 mixed.bam > SE.bam

Is this thread what you are looking for?

Thanks. I read this thread already but I need to sort PE and SE while converting to fastq

Do the read ids contain information on pairing? If so there are easy ways to do what you want. Can you provide a few read ids?

Log in to answer this question.