samtools crashes when sorting files
1
0
Entering edit mode
2.1 years ago
yomogy ▴ 120

Hi,

I am processing ChIP sequencing data. I mapped FASTQ files using Bowtie2 then I tried to convert sam files to bam files, then sort and index the files using samtools. When I try to sort the bam files, gibberish letters show up and crash in the middle. I have total four files but I got the same error in all four files (all files were downloaded from publicly available data). I used samtools 1.2 this time(server in my university installed samtools1.2), I also used samtools 1.12 on the laptop computer, the same error occurred.

The code I used was:

for i in *.sam
do
  samtools view -b -S $i -o $i.bam
  samtools sort $i.bam -o $i.sorted.bam
  samtools index $i.sorted.bam
done

I also tried:

for i in *.sam
do
  samtools sort $i -o $i.sorted.bam
  samtools index $i.sorted.bam
done

but the same result.

These codes worked in the past, and I could not figure out where the problem is.

samtools • 1.5k views
ADD COMMENT
0
Entering edit mode

for i in *.sam

you should learn about make and about workflow managers (nextflow, snakemake....)

ADD REPLY
0
Entering edit mode

, gibberish letters show up and crash in the middle.

is there any space in the filenames ? protect the filenames with quotes:

set -x
for i in *.sam
do
echo "RUNNING $i" 1>&2
samtools sort -T "$i.tmp"  -O BAM -o "$i.sorted.bam" "$i"
samtools index "$i.sorted.bam"
done
ADD REPLY
0
Entering edit mode

Thank you for your reply.

I got error message saying

  • can't parse output format "BAM"
  • "fail to open file output.bam" <- I got this message whenever I ran "samtools sort -o output.bam input.sam" (I don't know I need to put "input.sam" right after "sort")
ADD REPLY
0
Entering edit mode

What version of samtools are you using?

ADD REPLY
1
Entering edit mode

1.2 according to original post. So older.

yomogy : Latest version is 1.16. It may feel odd but 1.2 is not the latest. It goes 1.1, 1.2,1.3 and so on.

ADD REPLY
0
Entering edit mode

add an echo in front of each samtools command, then send us the resulting output

PS. if you have only four samples, just run them manually :-) or add the commands to a text file manually

then run

bash myfile.txt

see if they crashes that way as well

ADD REPLY
1
Entering edit mode
2.1 years ago

can't parse output format "BAM"

remove -O BAM . Your samtools is too old.

ADD COMMENT
0
Entering edit mode

Thank you very much, it works!

ADD REPLY

Login before adding your answer.

Traffic: 1564 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