Question: Convert Bam To Fastq With Pe & Se Reads
5
gravatar for Pasta
7.5 years ago by
Pasta1.3k
Switzerland
Pasta1.3k wrote:

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 next-gen bam sequencing • 6.1k views
ADD COMMENTlink modified 3.0 years ago by Shicheng Guo7.7k • written 7.5 years ago by Pasta1.3k
3
gravatar for Swbarnes2
7.5 years ago by
Swbarnes21.5k
Swbarnes21.5k wrote:

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.

ADD COMMENTlink written 7.5 years ago by Swbarnes21.5k
2

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.

ADD REPLYlink written 7.5 years ago by Swbarnes21.5k

Question edited with more details

ADD REPLYlink written 7.5 years ago by Pasta1.3k
3
gravatar for Shicheng Guo
3.0 years ago by
Shicheng Guo7.7k
Shicheng Guo7.7k wrote:

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
ADD COMMENTlink modified 3.0 years ago • written 3.0 years ago by Shicheng Guo7.7k
0
gravatar for Zev.Kronenberg
7.5 years ago by
United States
Zev.Kronenberg11k wrote:

Is this thread what you are looking for? http://biostar.stackexchange.com/questions/8787/from-compressed-bam-to-fastq

ADD COMMENTlink written 7.5 years ago by Zev.Kronenberg11k

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

ADD REPLYlink written 7.5 years ago by Pasta1.3k

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?

ADD REPLYlink written 7.5 years ago by Zev.Kronenberg11k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1721 users visited in the last hour