This is a test version of Biostars. For the public version, visit https://www.biostars.org.
samtools collate

Hi all,

I am using samtools collate to convert my bam files to paired end fastq files. here is the command that I am using

samtools view -h -T mm10.fa {input.bam} | samtools collate -O -u -@ {threads} - | samtools fastq -1 output_paired1.fq.gz  -2 output_paired2.fq.gz -0 /dev/null -s /dev/null - 2>>{log}

but when I am running it shows me the usage of samtools collate is not correct

Usage:   samtools collate [-Ou] [-n nFiles] [-l cLevel] <in.bam> <out.prefix>

Options:
      -O       output to stdout
      -u       uncompressed BAM output
      -l INT   compression level [1]
      -n INT   number of temporary files [64]
      --input-fmt-option OPT[=VAL]
               Specify a single input file format option in the form
               of OPTION or OPTION=VALUE
      --output-fmt FORMAT[,OPT[=VAL]]...
               Specify output format (SAM, BAM, CRAM)
      --output-fmt-option OPT[=VAL]
               Specify a single output file format option in the form
               of OPTION or OPTION=VALUE
      --reference FILE
               Reference sequence FASTA FILE [null]
  -@, --threads INT
               Number of additional threads to use [0]

I could not realize how to correct my command line. is the prefix is matter? but it is optional I would be grateful if anyone can help me.

Thank you in advance!

samtools

it shows me the usage of samtools collate is not correct

What is the exact error message?

there is no error massage it just give me

Usage:   samtools collate [-Ou] [-n nFiles] [-l cLevel] <in.bam> <out.prefix>

Options:
      -O       output to stdout
      -u       uncompressed BAM output
      -l INT   compression level [1]
      -n INT   number of temporary files [64]
      --input-fmt-option OPT[=VAL]
               Specify a single input file format option in the form
               of OPTION or OPTION=VALUE
      --output-fmt FORMAT[,OPT[=VAL]]...
               Specify output format (SAM, BAM, CRAM)
      --output-fmt-option OPT[=VAL]
               Specify a single output file format option in the form
               of OPTION or OPTION=VALUE
      --reference FILE
               Reference sequence FASTA FILE [null]
  -@, --threads INT
               Number of additional threads to use [0]
[M::bam2fq_mainloop] discarded 0 singletons
[M::bam2fq_mainloop] processed 0 reads

What is the output to samtools view {input.bam} | head?

it displays a few lines of bam files

Try adding STDOUT at the end to the collate command like so:

| samtools collate -O -u -@ {threads} - STDOUT |

Any string will do, it just needs something to prefix tmp files. Also, you don't need the view command at all.

The usage doc needs to be better then - the angle brackets around the out prefix param is the only hint that points to the possibility that it could be required even when common sense says it's not. One would expect a tool built by lh3 to either specify this explicitly or use a default prefix when not provided one.

what does - STDOUT do? (which @Ram mentioned) is it like to do the prefix tmp files? and how and when do I have to realize to use STDOUT? for the view command, I wanted to use the ref.fa for proper interpretation of the alignment positions, isn't that necessary?

Reference is only needed with .cram format files.

what is 'proper interpretation of alignment positions'? no not necessary.

the first samtools view is useless

1 answer

Thank you everyone for all the help. it seemed that the problem was with a version of samtools (it was samtools 1.6 in the environment I used for samtools collate). with updating the samtools problem was solved.

Also, it is better to use PREFIX for temporary files

samtools collate -O -u -@ {threads} {input.bam} 2>{log} | samtools fastq -1 {output.R1} -2 {output.R2} -0 /dev/null -s /dev/null 2>>{log}

While you are saying it is better to use PREFIX you do not show that in your example command line. Not sure why you need a log file for collate step?

Here is with using a prefix

samtools collate -O -u -@ {threads} {input.bam} -T {input.bam}_prefix 2>{log}| samtools fastq -1 {output.R1} -2 {output.R2} -0 /dev/null -s /dev/null 2>>{log}

I used the log to check errors(I used Snakemake). for ex: I received the following error in my log file

samtools collate: Couldn't write to intermediate file "/tmp/collate70898.0002.bam"

So, then I added -T PREFIX for using the temporary files.

Log in to answer this question.