This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Samtools bam2fq converting bam file to fastq. What happens to unmapped reads?

Hi,

I am trying to convert a bam file back to fastq files. I have used samtools bam2fq in the past and it has worked well. In this particular case, I want to make sure that the unmapped reads in my bam file are part of the fastq files that are output from samtools bam2fq. I have already confirmed my bam file has unmapped reads. I am just not exactly sure if samtools bam2fastq will take those unmapped reads and put them in the fastq files? I was wondering if anyone had any insight into this? This is the command I typically use. Not to ask too many questions but is there a way to create two fastq files instead of just one?

samtools bam2fq merged.dedup.realn.bam > samtools.bam2fq.fastq

I have been using the following commands to split the fastq file into two

cat input.samtools.bam2fq.fastq | grep '^@.*/1$' -A 3 --no-group-separator > output.samtools.bam2fq_R1.fastq

cat input.samtools.bam2fq.fastq | grep '^@.*/2$' -A 3 --no-group-separator > outout.samtools.bam2fq_R2.fastq
assembly alignment sequencing next-gen

Why not use following. Be sure to name sort/collate the BAM file.

samtools fastq -1 paired1.fq -2 paired2.fq -0 /dev/null -s single.fq -n in.bam

That is fine. Unmapped reads will be converted as any other read.

You can also try SamToFastq from Pircard

java -jar picard.jar SamToFastq I=merged.dedup.realn.bam FASTQ=output.samtools.bam2fq_R1.fastq --SECOND_END_FASTQ=outout.samtools.bam2fq_R2.fastq

0 answers

No answers yet.

Log in to answer this question.