I assumed that the -f 4 parameter would add the unaligned to the aligned, and keep both.
No? It keeps only the unaligned?
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.
If the reads don't align, there is nothing to convert to a BED file.
A BED file would contain the start and end coordinates of the alignments.
When you keep the unaligned reads, you basically keep alignments that are "not valid alignments".
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.
Log in to answer this question.