This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Error In Sam To Bam Conversion

I want to convert SAM file into BAM. I am using command

samtools view -b -S -o bowtie.glob.bam bowtie.glob.sam

but getting error

Parse error at line 25645: invalid CIGAR character

Could someone please help me to solve this problem?

next-gen samtools rna-seq

Could you please try:

samtools view -b -S bowtie.glob.bam bowtie.glob.sam

This is because -b already gives bam output and -S as sam input. This might help.

Thanks Rohit, but samtools view -b -S -o bowtie.glob.bam bowtie.glob.sam is the same command that I used.

Could you post line 25645 of your SAM file? And the version number of your samtools?

Also, what program generated that SAM file?

I am still getting parser error after trying all the commands mentioned above. My sam file also contain @SQ line. Any suggestions please??

2 answers

I went through it, the solution is to add the index file. Create the index files with

samtools faidx sequence.fa

This creates the index file *.fai. The final command for conversion is

samtools view -bt sequence.fa.fai -S bowtie.glob.sam -o bowtie.glob.sam

Cheers,
Rohit

I know you have got the solution but here is what is mentioned in the samtools manual:

Import SAM to BAM when @SQ lines are present in the header:

samtools view -bS aln.sam > aln.bam

If @SQ lines are absent:

samtools faidx ref.fa 
samtools view -bt ref.fa.fai aln.sam > aln.bam

where ref.fa.fai is generated automatically by the faidx command.

The manual was where I got the solution from... Forgot to mention that...

Cheers...

Hi Dcolinmorgan,

Go through the SAM format specification here and see if you are missing anything.

Log in to answer this question.