Samtools sam to bam error
0
0
Entering edit mode
2.6 years ago
kb_93 ▴ 10

Hi there!

I am trying to convert my SAM file (7.5G) to BAM format using this line of code:

samtools view --threads 4 -buS ${sample}.sam -o ${sample}.bam

My first issue is the memory requirement - it is taking over 180G to start running and secondly when it does run I get the the following error

samtools view: error reading file "*l.sam"\
samtools view: error closing "*.sam": -5

Can anyone suggest what the error means and how to correct it please!

samtools • 1.8k views
ADD COMMENT
0
Entering edit mode

Which version of samtools are you using? It is odd that you need 180G of RAM. There is no need to use any flags since samtools should autodetermine the options from file extensions.

$ samtools --version
samtools 1.15.1
Using htslib 1.15.1
Copyright (C) 2022 Genome Research Ltd.
ADD REPLY
0
Entering edit mode

I am using v1.14 - I tried conda update samtools but it is not updating to v1.15.1

ADD REPLY
0
Entering edit mode

That version is recent enough. What happens if you simply do samtools view --threads 4 ${sample}.sam -o ${sample}.bam?? Any specific reason to choose uncompressed BAM in your original command?

ADD REPLY
0
Entering edit mode

I still get the following error when I change it to your suggested code

samtools view: error reading file "{sample}.sam" samtools view: error closing "{sample}.sam": -5

ADD REPLY
0
Entering edit mode

Is ${SAMPLE} variable properly expanding to a file that exists? Error indicates that samtools is having a problem reading the file.

ADD REPLY
0
Entering edit mode

Yes, I checked the SAM file exist. The line of code does start to generate a bam file, however, it only gets to ~ 200Mb before throwing the error.

ADD REPLY
0
Entering edit mode

Please show the full script so how the variable gets defined. It makes no sense this uses excessive memory, the command essentially needs none so the error is somewhere in the script.

ADD REPLY
0
Entering edit mode

Here's the code

for sample in *.fq  
do  
echo $sample >> alignment.log  
bowtie -p 16 --chunkmbs 200 -a --best --strata -v 0 --norc -m 20 -x $index ${sample}  -S ${sample::-3}.sam --un ${sample::-3}_unaligned.fq --max ${sample::-3}_overM.fq 2>> alignment.log  
samtools view  ${sample::-3}.sam -o ${sample::-3}.bam                           
samtools flagstat ${sample::-3}.bam  
samtools view -b -F 4 ${sample::-3}.bam | samtools sort -o ${sample::-3}.sort.bam                   
samtools index ${sample::-3}l.sort.bam
ADD REPLY
0
Entering edit mode

Did you eventually figure it out? I am facing a similar issue. Thanks

ADD REPLY

Login before adding your answer.

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