This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Separating bam file based on directionality / samtools view -F/-f option(s) appears to not do anything

Hi,

I am trying to separate a bam/sam file based on directionality of reads. Samtools does not have a way to do this from an aligned sam/bam file to a reference sequence that I can find. My attempted workaround was to use samtools view -F or -f options to attempt to separate reads based on alignment flags. I am using the -o option because I need an output to occur if any changes are to happen. The big issue I am running into is that it would appear that my commands are not doing anything at all:

Samtools version:
samtools 1.13
Using htslib 1.13+ds

Please describe your environment.

  • Windows CPU running Ubuntu 22.04.3 environment
  • machine architecture (run uname -m on Linux/Mac OS or wmic os get OSArchitecture on Windows)
  • ^ result from ubuntu cmd: x86_64
  • ^ Result from windows cmd: OSArchitecture 64-bit
  • gcc (Ubuntu 11.3.0-1ubuntu1~22.04.1) 11.3.0

What I have tried:

$samtools view -o -F aligned-input.bam

No output message of any kind, no error, no new file produced in my file explorer, no modifications to the existing file in my file explorer

Similarly, the -f version did the same thing:

$samtools view -o -f aligned-input.bam

No output message of any kind, no error, no new file produced in my file explorer, no modifications to the existing file in my file explorer

I tried the verbose version of the command:

$samtools view -o --require-flags aligned-input.bam

No output message or error, this one did produce a new output file, but it's not a SAM or BAM file, it's just listed as file type "file", and its name is --require-flags, clearly indicating that that option did not function as intended.

Same thing for the other verbose version:

$samtools view -o --excl-flags aligned-input.bam

No output message or error, this one did produce a new output file, but it's not a SAM or BAM file, it's just listed as file type "file", and its name is --excl-flags, clearly indicating that that option did not function as intended.

I tried to specify a flag (just to try to get it to do anything) in multiple different ways:

$samtools view -o -f 0x4 aligned-input.bam

Output in return:

[E::hts_open_format] Failed to open file "0x4" : No such file or directory
samtools view: failed to open "0x4" for reading: No such file or directory

This same output happens no matter what tag I try, whether in hexidecimal format or octadecimal formatting, and it also does the same thing for -F and -f.

How do I get the $samtools view -o -F aligned-input.bam (or -f) to do something? Alternatively, if I am barking up the wrong tree, does anyone have a good idea on how to separate a .bam or .sam file based on flags.

Thank you for your time, and I hope to get an answer!

ubuntu linux samtools

1 answer

$samtools view -o -F aligned-input.bam
$samtools view -o --require-flags aligned-input.bam
(...)

This is not a proper syntax. All those options require a parameter https://stackoverflow.com/a/36495940/58082

Log in to answer this question.