Proper parameters for samtools view?
1
0
Entering edit mode
23 months ago
zhousun21 ▴ 40

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.

samtools • 1.5k views
ADD COMMENT
3
Entering edit mode
23 months ago

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".

ADD COMMENT
0
Entering edit mode

I assumed that the -f 4 parameter would add the unaligned to the aligned, and keep both.

No? It keeps only the unaligned?

ADD REPLY
1
Entering edit mode

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.

ADD REPLY
1
Entering edit mode

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?

ADD REPLY
0
Entering edit mode

Yep :)

ADD REPLY
0
Entering edit mode

Ah! Thanks very much for clarifying. That explains it.

ADD REPLY

Login before adding your answer.

Traffic: 2669 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6