SEQanswers

Go Back   SEQanswers > Bioinformatics > Bioinformatics



Similar Threads
Thread Thread Starter Forum Replies Last Post
TopHat "-M" option and Unmapped.bam file washy RNA Sequencing 2 05-24-2013 06:20 AM
Something wrong with access Bam file using "SeqAn" library sunredrock Bioinformatics 2 04-14-2013 11:59 PM
samtools sort bam file error: generate non-existent file mediator Bioinformatics 0 03-05-2012 08:42 PM
The position file formats ".clocs" and "_pos.txt"? Ist there any difference? elgor Illumina/Solexa 0 06-27-2011 07:55 AM
help on "truncated file", when converting sam to bam jianfeng.mao Bioinformatics 0 12-18-2010 02:03 AM

Reply
 
Thread Tools
Old 06-04-2014, 04:18 AM   #1
MarinePAM
Junior Member
 
Location: France

Join Date: Jun 2014
Posts: 7
Unhappy Can't sort BAM file ("not a BAM file")

Dear everyone,

I try to convert some SAM files to BAM files following the Samtools FAQ method :
First indexing my reference fasta file (I have no header in my SAM file) :
Code:
samtools faidx ref.fa
Then converting my SAM file to BAM file :
Code:
samtools view -bt ref.fa.fai aln.sam > aln.bam
Until here, everything seems fine, but...

When trying to sort my BAM file :
Code:
samtools sort aln.bam aln-sorted
I instantly get :
[bam_header_read] invalid BAM binary header (this is not a BAM file).
[bam_sort_core] truncated file. Continue anyway.
Seegmentation fault (core dumped)


The problem seems to be in the SAM-->BAM conversion... My SAM file seems OK (obtained with the Illumina script : illumina_export2sam.pl). It only contains one "@PG" line at its beginning, that's why I followed the Samtools FAQ method.

I've already once done that on another data and everything went fine...So I really don't understand what is happening now.
Could someone tell me what is wrong ?
I'd be very grateful if someone could help me !!!

Best regards,

Marine
MarinePAM is offline   Reply With Quote
Old 06-04-2014, 04:44 AM   #2
Michael.Ante
Senior Member
 
Location: Vienna

Join Date: Oct 2011
Posts: 123
Default

Hi Marine,
I assume your SAM file consists of non-aligned reads. Thus, trying to sort your reads according to their chromosomal locations might lead to the error. If you want to sort the BAM file anyway, try
Code:
samtools sort -n aln.bam aln-sorted
Cheers,
Michael
Michael.Ante is offline   Reply With Quote
Old 06-04-2014, 04:48 AM   #3
dpryan
Devon Ryan
 
Location: Freiburg, Germany

Join Date: Jul 2011
Posts: 3,480
Default

Which version of samtools are you using? Can you "samtools view aln.bam"? I'm guessing not. Also, what happens if you instead use "samtools view -Sbt ref.fa.fai aln.sam > aln.bam"?

BTW, am I correct in assuming you're the same person that just emailed the samtools-help email list?
dpryan is offline   Reply With Quote
Old 06-04-2014, 04:51 AM   #4
MarinePAM
Junior Member
 
Location: France

Join Date: Jun 2014
Posts: 7
Default

Thank you for your quick answer !!
My SAM file is about aligned reads. But the names of each feature in my reference file (ref.fa, to which I aligned the reads) are not like "Chr..." but rather like "15648-ref" ... Is this supposed to be a problem ?

Whatsmore, trying what you proposed gives me exactly the same error message
MarinePAM is offline   Reply With Quote
Old 06-04-2014, 04:54 AM   #5
dpryan
Devon Ryan
 
Location: Freiburg, Germany

Join Date: Jul 2011
Posts: 3,480
Default

Quote:
Originally Posted by MarinePAM View Post
My SAM file is about aligned reads. But the names of each feature in my reference file (ref.fa, to which I aligned the reads) are not like "Chr..." but rather like "15648-ref" ... Is this supposed to be a problem ?
That should be fine.

Quote:
Whatsmore, trying what you proposed gives me exactly the same error message
Try the "samtools view -Sbt blah.fa.fai foo.sam > foo.bam" command that I suggested above and see if you can even "samtools view foo.bam" then (I'm assuming you get the error if you try that on the current BAM file).
dpryan is offline   Reply With Quote
Old 06-04-2014, 05:04 AM   #6
MarinePAM
Junior Member
 
Location: France

Join Date: Jun 2014
Posts: 7
Default

Dear dpryan,

Thank you for your answer !

The version is : Version: 0.1.18 (r982:295)

Indeed, "samtools view aln.bam" gives me the same error message...

I've just ran : "samtools view -Sbt ref.fa.fai aln.sam > aln.bam". It worked (as well as without the -S option). When running the next sort step, it seems to work !! I thought the "-S" option was forced by the "-t" option as described in the help, but maybe not ?
While currently still running, this message appears : "merging from 10 files..." Do you know what are these 10 files ?

(Yes I am the same person as on the mailing list !)
MarinePAM is offline   Reply With Quote
Old 06-04-2014, 05:07 AM   #7
dpryan
Devon Ryan
 
Location: Freiburg, Germany

Join Date: Jul 2011
Posts: 3,480
Default

0.1.18 is an older version, so perhaps -S wasn't forced by -t in that version.

When samtools sorts a BAM file, it breaks it into smaller sorted files and then merges them. This drastically decreases memory requirements (otherwise, you have to hold the whole thing in memory!) and is quick because merging sorted files is quite fast.

Let me know once that's done if it works and I'll leave a note on the samtools list about the cause/solution.
dpryan is offline   Reply With Quote
Old 06-04-2014, 05:14 AM   #8
MarinePAM
Junior Member
 
Location: France

Join Date: Jun 2014
Posts: 7
Default

It worked ! I've done the "sort" and "index" steps with success !!
Many many thanks to you, I'm very happy !

So it was the -S option. I'm surprised because I read the help corresponding to this older version !
Thank you also for leaving a note on the samtools list (I was about to ask you if I need to do so) !
MarinePAM is offline   Reply With Quote
Reply

Tags
bam, convert, sam, samtools, sort

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off




All times are GMT -8. The time now is 02:10 PM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Single Sign On provided by vBSSO