Dear Biostar users.
I wanna convert bam to fastq. So I used "samtools bam2fq".
This is my script.
fastq1=`echo $(basename ${input_file%%.gz.*})`
fastq2=`echo ${fastq1/R1/R2}`
samtools bam2fq $input/$input_file > $output_dir/${input_file}_fastq
cat $output_dir/${input_file}_fastq | grep '^@.*/1$' -A 3 > $fastq1
cat $output_dir/${input_file}_fastq | grep '^@.*/2$' -A 3 > $fastq2
Is this right?
And I wanna identify whether my bam file includes unmapped reads. so I run samtools flagstat.
This is the result. In this result, can I think that my bam file includes unmapped reads?
40304229 + 0 in total (QC-passed reads + QC-failed reads)
0 + 0 secondary
0 + 0 supplementary
0 + 0 duplicates
40304225 + 0 mapped (100.00% : N/A)
39496046 + 0 paired in sequencing
19799602 + 0 read1
19696444 + 0 read2
39219752 + 0 properly paired (99.30% : N/A)
39486133 + 0 with itself and mate mapped
9909 + 0 singletons (0.03% : N/A)
219437 + 0 with mate mapped to a different chr
219437 + 0 with mate mapped to a different chr (mapQ>=5)
Thank you so much
I don't completely understand your script since it appears to be circular. I am going to assume that you are feeling a BAM file to
samtools bam2fq
.Considering that the total number of reads is almost identical to mapped (only 4 less) it looks like your BAM must have only mapped reads (or your dataset was almost entirely mapped, rare but possible).
Dear genomax. Thanks for your reply.
My script is ..
samtools bam2fq [in.bam] > [out.fastq]
cat [out.fastq] | grep '^@.*/1$' -A 3 > [fastq.1]
cat [out.fastq]| grep '^@.*/2$' -A 3 > [fastq.2]
And as you said, my flagstat result looks like all reads are mapped.
You've been great help to me. Thank you.