Hi everyone,
I have a sam file created by minimap2: aln.sam
Using samtools view to convert it to a bam file works fine:
samtools view -S -b aln.sam > aln.bam
But adding the -f 4 parameter to retain the unmapped sequences does not work properly:
samtools view -S -b -f 4 aln.sam > aln.bam
It produces a very small file then the process ends. The small file can be sorted:
samtools sort aln.bam -o aln_sorted.bam
But when converting that to a bed file produces a file of size zero:
bedtools bamtobed -i aln_sorted.bam > out.bed
Can anyone see anything wrong with this command?
samtools view -S -b -f 4 aln.sam > aln.bam
Thanks for any advice.
I assumed that the -f 4 parameter would add the unaligned to the aligned, and keep both.
No? It keeps only the unaligned?
The
-f
is a filter, it means either keep (-f
) or remove (-F
) those reads with a given flag. Your-f 4
means to keep only the unmapped reads in the BAM. if you have few of them then small BAM size is expected. Unmapped reads have no coordinates, and BED is a coordinate-based format, hence you cannot convert unmapped reads to BED.So, not adding any -f or -F flags will keep everything, but the unmapped reads will not appear in the bedfile regardless because there are no associated coordinates.
Is that right?
Yep :)
Ah! Thanks very much for clarifying. That explains it.