This is a test version of Biostars. For the public version, visit https://www.biostars.org.
samtools view: failed to open "sort" for reading: No such file or directory

I'm having an issue with the "SAM-BAM conversion and sorting steps together" command. After the following command...

bwa mem -t2 -R '@RG\tID:NA12878\tSM:NA12878\tLB:NA12878' genome.fa SRR1611183_1.fastq.gz `SRR1611183_2.fastq.gz |samtools view -u -samtools sort -@2 - > SRR1611183.bam`

...I get the following error:

E::hts_open_format] Failed to open file sort
samtools view: failed to open "sort" for reading: No such file or directory
[M::bwa_idx_load_from_disk] read 0 ALT contigs
[M::process] read 200000 sequences (20000000 bp)...
[M::process] read 200000 sequences (20000000 bp)...
[M::mem_pestat] # candidate unique pairs for (FF, FR, RF, RR): (5, 72922, 1, 3)
[M::mem_pestat] skip orientation FF as there are not enough pairs
[M::mem_pestat] analyzing insert size distribution for orientation FR...
[M::mem_pestat] (25, 50, 75) percentile: (216, 239, 258)
[M::mem_pestat] low and high boundaries for computing mean and std.dev: (132, 342)
[M::mem_pestat] mean and std.dev: (235.53, 32.36)
[M::mem_pestat] low and high boundaries for proper pairs: (90, 384)
[M::mem_pestat] skip orientation RF as there are not enough pairs
[M::mem_pestat] skip orientation RR as there are not enough pairs
[M::mem_process_seqs] Processed 200000 reads in 32.785 CPU sec, 16.249 real sec

The command actually still runs but changes your SRR1611183.bam so that there is now 0 bytes on data in the file.

I'm a little scared to repeat this command since you need to reconstruct your SRR1611183.bam file which takes about 30-40 mins. I'd hate to wipe it out again.

Does anyone see a glaring error in my bwa mem script?

samtools

samtools view -u -samtools

Looks weird to me. Why's there a -samtools flag? Is it supposed to be a | samtools perhaps?

|samtools view -u -samtools sort

you are missing a pipe here.

2 answers

the problem is here:

... |samtools view -u -samtools sort -@2

you want (with a recent version of samtools)

 .... | samtools sort -@2  -T SRR1611183tmp  -o SRR1611183.bam -

Thanks - I see the pipe I missed. Many thanks to all!

Why not just this?

bwa mem -t2 -R '@RG\tID:NA12878\tSM:NA12878\tLB:NA12878' genome.fa SRR1611183_1.fastq.gz SRR1611183_2.fastq.gz | samtools sort -@2 - > SRR1611183.bam

Log in to answer this question.