SAM to BAM conversion error after mapping with STAR

1,565 views
Skip to first unread message

lazaros lataniotis

unread,
Nov 18, 2014, 11:04:11 AM11/18/14
to rna-...@googlegroups.com
Hello,

I am trying to convert some sam files to bam and I am facing some problems.

After having mapped my fq files using STAR aligner with this command:

/data/home/hhx037/STAR/STAR --genomeDir /share/panosscratch/REPOSITORY/Reference_genomes/GRCh37.75/STAR --readFilesIn /share/panosscratch/REPOSITORY/SEQUENCING/Stanislas/fastq/$sample.end1.fq /share/panosscratch/REPOSITORY/SEQUENCING/Stanislas/fastq/$sample.end2.fq --runThreadN 4 --outFileNamePrefix $sample --outSAMattributes Standard

I am trying to convert the SAM file I got to BAM files. The header of one of my samfile looks like:

@HD     VN:1.4
@SQ     SN:1    LN:249250621
@SQ     SN:2    LN:243199373
@SQ     SN:3    LN:198022430
@SQ     SN:4    LN:191154276
@SQ     SN:5    LN:180915260
@SQ     SN:6    LN:171115067
@SQ     SN:7    LN:159138663
@SQ     SN:8    LN:146364022
@SQ     SN:9    LN:141213431
@SQ     SN:10   LN:135534747
@SQ     SN:11   LN:135006516
@SQ     SN:12   LN:133851895
@SQ     SN:13   LN:115169878
@SQ     SN:14   LN:107349540
@SQ     SN:15   LN:102531392
@SQ     SN:16   LN:90354753
@SQ     SN:17   LN:81195210
@SQ     SN:18   LN:78077248
@SQ     SN:19   LN:59128983
@SQ     SN:20   LN:63025520
@SQ     SN:21   LN:48129895
@SQ     SN:22   LN:51304566
@SQ     SN:X    LN:155270560
@SQ     SN:Y    LN:59373566
@SQ     SN:MT   LN:16569
@PG     ID:STAR PN:STAR VN:STAR_2.4.0e  CL:/data/home/hhx037/STAR/STAR   --runThreadN 4   --genomeDir /share/panosscratch/REPOSITORY/Reference_genomes/GRCh37.75/STAR   --readFilesIn /share/panosscratch/REPOSITORY/SEQUENCING/Stanislas/fastq/2660_stanislas.end1.fq   /share/panosscratch/REPOSITORY/SEQUENCING/Stanislas/fastq/2660_stanislas.end2.fq      --outFileNamePrefix 2660_stanislas   --outSAMattributes Standard
@CO     user command line: /data/home/hhx037/STAR/STAR --genomeDir /share/panosscratch/REPOSITORY/Reference_genomes/GRCh37.75/STAR --readFilesIn /share/panosscratch/REPOSITORY/SEQUENCING/Stanislas/fastq/2660_stanislas.end1.fq /share/panosscratch/REPOSITORY/SEQUENCING/Stanislas/fastq/2660_stanislas.end2.fq --runThreadN 4 --outFileNamePrefix 2660_stanislas --outSAMattributes Standard

The command I am for the conversion is 

samtools view -bS samfile.sam > bamfile.bam

And the error message when I am trying to view the bamfile.bam is:

[W::sam_read1] parse error at line 1
[main_samview] truncated file.

Any thoughts?

Thank you in advance.

Alexander Dobin

unread,
Nov 20, 2014, 12:22:27 AM11/20/14
to rna-...@googlegroups.com
Hi Lazaros,

did you get any error message while converting with samtools?
The header looks fine to me. Could you attach the file with ~100 lines of alignments (not copy-paste since that converts tabs to spaces)?

Cheers
Alex

lazaros lataniotis

unread,
Nov 20, 2014, 5:25:26 AM11/20/14
to rna-...@googlegroups.com

Hi Alex,

Thank you for your reply.

I do not get any errors when I am converting samfiles to bamfiles with samtools.

Please see attached file for the 100 first lines of a random samfile.

Best,
Lazaros
forum.docx

lazaros lataniotis

unread,
Nov 25, 2014, 9:49:51 AM11/25/14
to rna-...@googlegroups.com
I have also used the latest version of STAR i.e. STAR_2.4.0f1 and still it does not work properly. I have also tried different --outSAMAttributes options (as I have read on previous posts) and still no luck. 

Any thoughts?

Alexander Dobin

unread,
Nov 25, 2014, 5:32:36 PM11/25/14
to rna-...@googlegroups.com
Hi Lazaros,

the file looks fine by eye, but it seems that all tabs were converted to spaces when you saved it as .doc.
Can you try the following:
$ head -n 100 Aligned.out.sam > a.sam
$ samtools view -bS a.sam > a.bam
$ samtools view a.bam
This will check whether the small file can be converted to BAM properly. If it does not work, please gzip the a.sam
$ gzip a.sam
and send me the a.sam.gz - this will avoid the format conversion problems.

Cheers
Alex

lazaros lataniotis

unread,
Nov 26, 2014, 6:21:27 AM11/26/14
to rna-...@googlegroups.com
Hi Alex,

Thank you for your reply.

The small file a.sam is converted to bam properly. I can read it with samtools without any problem. 

Alexander Dobin

unread,
Dec 4, 2014, 10:54:55 PM12/4/14
to rna-...@googlegroups.com
Hi Lazaros,

this means that there some troublesome lines in the big file you are trying to convert. Please try to look at the end of the file with $ tail.
How big is the full sam file that causes the problem? If you can send it to me zipped, I will check it.
You can also try to find the troublesome lines with Picard ValidateSamFile.jar
If nothing helps, you can use the --outSAMtype Unsorted or SortedByCoordinate for direct BAM output.

Cheers
Alex
Reply all
Reply to author
Forward
0 new messages