SEQanswers

Go Back   SEQanswers > Bioinformatics > Bioinformatics



Similar Threads
Thread Thread Starter Forum Replies Last Post
the header of SAM and BAM missing dongshenglulv Bioinformatics 5 10-23-2011 11:44 PM
SAM header missing in BFAST cdry7ue Bioinformatics 6 05-03-2011 02:13 PM
how to convert sam to bam with EOF marker in header jianfeng.mao Bioinformatics 2 12-17-2010 05:56 AM
missing header information in bam cause GATK unifiedgenotyper fail foxyg Bioinformatics 3 11-11-2010 09:37 AM
sam/bam header lines keebs42 Bioinformatics 1 08-21-2009 11:25 AM

Reply
 
Thread Tools
Old 09-05-2011, 03:39 PM   #1
efoss
Member
 
Location: Seattle

Join Date: Jul 2011
Posts: 98
Default sam to bam conversion error, no @SQ lines in the header, missing header?

I have a sam file that I want to convert to a bam file:

samtools view -b -S in.sam > out.bam

I get this error:

[samopen] no @SQ lines in the header.
[sam_read1] missing header? Abort!

My sam file looks perfectly normal to me. Does anyone see what I'm doing wrong?

Thanks.

Eric
efoss is offline   Reply With Quote
Old 09-05-2011, 05:16 PM   #2
efoss
Member
 
Location: Seattle

Join Date: Jul 2011
Posts: 98
Default

To add to my previous post: I also tried the following command but I got the same error message:

samtools view -h -b -S in.sam > out.bam
efoss is offline   Reply With Quote
Old 09-05-2011, 06:24 PM   #3
BAMseek
Senior Member
 
Location: St. Louis, MO, USA

Join Date: Apr 2011
Posts: 124
Default

I think you might need to specify a reference file containing the names of the sequences and the total sequence lengths. This is done with the "-t" flag. Here is a description from samtools:

Quote:
-t FILE
This file is TAB-delimited. Each line must contain the reference name and the length of the reference, one line for each distinct reference;
BAMseek is offline   Reply With Quote
Old 09-06-2011, 03:43 AM   #4
maubp
Peter (Biopython etc)
 
Location: Dundee, Scotland, UK

Join Date: Jul 2009
Posts: 1,543
Default

Or from memory -T can specify a FASTA file of the references.
maubp is offline   Reply With Quote
Old 09-06-2011, 08:44 AM   #5
swbarnes2
Senior Member
 
Location: San Diego

Join Date: May 2008
Posts: 912
Default

Quote:
Originally Posted by maubp View Post
Or from memory -T can specify a FASTA file of the references.
samtools view doesn't require -T. It works fine without a reference fasta.

Maybe your headers aren't right?

Here's what mine look like:

@SQ SN:SNP_8787 LN:161
@SQ SN:vector LN:13078
swbarnes2 is offline   Reply With Quote
Old 09-06-2011, 10:15 AM   #6
efoss
Member
 
Location: Seattle

Join Date: Jul 2011
Posts: 98
Default

Quote:
Originally Posted by swbarnes2 View Post
samtools view doesn't require -T. It works fine without a reference fasta.

Maybe your headers aren't right?

Here's what mine look like:

@SQ SN:SNP_8787 LN:161
@SQ SN:vector LN:13078
Yes - it was the headers. I see that when I made my sam file, I didn't use the -h option, so then when I went to convert it back to a bam file, I couldn't fix things simply by adding the -h option. I had to go back and remake the sam file with -h and then convert it back to a bam file with -h, and now everything is working fine. Thanks very much, everyone, for the help.

Eric
efoss is offline   Reply With Quote
Old 12-08-2012, 07:42 AM   #7
prasadg
Member
 
Location: Newark, Delaware, USA

Join Date: Mar 2012
Posts: 16
Default

Quote:
Originally Posted by efoss View Post
Yes - it was the headers. I see that when I made my sam file, I didn't use the -h option, so then when I went to convert it back to a bam file, I couldn't fix things simply by adding the -h option. I had to go back and remake the sam file with -h and then convert it back to a bam file with -h, and now everything is working fine. Thanks very much, everyone, for the help.

Eric
Hey efoss,

I am also facing the same problem. I couldn't undertsood this line of yours "I didn't use the -h option, so then when I went to convert it back to a bam file, I couldn't fix things simply by adding the -h option. I had to go back and remake the sam file with -h" how to did you make same file with -h? Did you use Bwa to create sam file.?
prasadg is offline   Reply With Quote
Old 12-08-2012, 10:45 AM   #8
efoss
Member
 
Location: Seattle

Join Date: Jul 2011
Posts: 98
Default

Quote:
Originally Posted by prasadg View Post
Hey efoss,

I am also facing the same problem. I couldn't undertsood this line of yours "I didn't use the -h option, so then when I went to convert it back to a bam file, I couldn't fix things simply by adding the -h option. I had to go back and remake the sam file with -h" how to did you make same file with -h? Did you use Bwa to create sam file.?
Hi prasadg,

It's been a while, but I think that I created a sam file with samtools' view command and that that command accepts a -h flag, which will create a sam file with appropriate headers.

Eric
efoss is offline   Reply With Quote
Old 12-08-2012, 10:56 AM   #9
prasadg
Member
 
Location: Newark, Delaware, USA

Join Date: Mar 2012
Posts: 16
Default

Quote:
Originally Posted by efoss View Post
Hi prasadg,

It's been a while, but I think that I created a sam file with samtools' view command and that that command accepts a -h flag, which will create a sam file with appropriate headers.

Eric
Okay . I will look into it . I have the sam file created by bwa. So I was using samtools to convert sam to bam but I am getting same answer as you have got

[samopen] no @SQ lines in the header.
[sam_read1] missing header? Abort!

So I wanted to know how did you do it .

Thanks
prasadg is offline   Reply With Quote
Old 12-08-2012, 11:00 AM   #10
efoss
Member
 
Location: Seattle

Join Date: Jul 2011
Posts: 98
Default

Quote:
Originally Posted by prasadg View Post
Okay . I will look into it . I have the sam file created by bwa. So I was using samtools to convert sam to bam but I am getting same answer as you have got

[samopen] no @SQ lines in the header.
[sam_read1] missing header? Abort!

So I wanted to know how did you do it .

Thanks
Hi prasadg,

Another thing to try if that doesn't work is using the -r option in bwa to add read group information when you create your original alignment file.

Eric
efoss is offline   Reply With Quote
Old 12-08-2012, 11:05 AM   #11
prasadg
Member
 
Location: Newark, Delaware, USA

Join Date: Mar 2012
Posts: 16
Default

Quote:
Originally Posted by efoss View Post
Hi prasadg,

Another thing to try if that doesn't work is using the -r option in bwa to add read group information when you create your original alignment file.

Eric
I will give it a shot. by -r you mean -R ? cause as I see the alignment options -r is with uppercase. There is no lower case 'r' option.
prasadg is offline   Reply With Quote
Old 12-08-2012, 11:07 AM   #12
efoss
Member
 
Location: Seattle

Join Date: Jul 2011
Posts: 98
Default

Quote:
Originally Posted by prasadg View Post
I will give it a shot. by -r you mean -R ? cause as I see the alignment options -r is with uppercase. There is no lower case 'r' option.
No - I mean -r. Look under sampe and you'll see the option.

Eric
efoss is offline   Reply With Quote
Old 12-08-2012, 11:10 AM   #13
prasadg
Member
 
Location: Newark, Delaware, USA

Join Date: Mar 2012
Posts: 16
Default

Quote:
Originally Posted by efoss View Post
No - I mean -r. Look under sampe and you'll see the option.

Eric
Thanks alot . It certainly made my day. I certainly was on wrong track .

Really appreciate you replys.
prasadg is offline   Reply With Quote
Old 01-08-2014, 08:59 AM   #14
bbm
Member
 
Location: North Carolina

Join Date: Sep 2011
Posts: 36
Default

I converted sam file to bam, then removes PCR duplicates, then convert bam to sam. It showed the same error msg:

error msg: [samopen] no @SQ lines in the header.
[sam_read1] missing header? Abort!

I tried -h option, still didn't work...
bbm is offline   Reply With Quote
Old 01-08-2014, 09:44 AM   #15
efoss
Member
 
Location: Seattle

Join Date: Jul 2011
Posts: 98
Default

Hi bbm,

You might want to try Picard's AddOrReplaceReadGroups:

http://picard.sourceforge.net/comman...laceReadGroups
efoss is offline   Reply With Quote
Old 11-26-2014, 12:38 AM   #16
Risha
Junior Member
 
Location: London

Join Date: Aug 2010
Posts: 4
Default

I also came across the 'missing header' error. I found that that when converting BAM-> SAM, I had forgotten about printing the headers. This fixed it for me:


BAM -> SAM:
Note : -h print header for the SAM output
Code:
samtools view -h in.bam > out.sam

SAM -> BAM (even SAM produced from BWA):

Code:
samtools view -bS in.sam > out.bam
Risha is offline   Reply With Quote
Old 12-03-2015, 02:41 AM   #17
Lovro
Member
 
Location: Slovenia

Join Date: Mar 2015
Posts: 19
Default

i have the same problem...

this is from the man samtools:
o 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.

However, i don't know which ref.fa to use.
The sam i'm trying to convert to bam, sort and index was generated by a foreign seq searching program, readscan, which uses host and pathogen ref seqs and try to map to both of them.

the actual sam file i'm trying to convert is "ambiguous.sam" which contains reads mapped to both ref seqs.

can somebody please explain what is going on... what are @SQ lines, why does samtools need them to convert to bam and index the file, why am i expected to provide a ref.fa ....

its really confusing

tnx !
Lovro is offline   Reply With Quote
Old 12-03-2015, 04:28 AM   #18
mastal
Senior Member
 
Location: uk

Join Date: Mar 2009
Posts: 667
Default

If you are aligning to something like the human genome, then you would usually have one @SQ line for each chromosome in the sam file header.

If you have the sequences of the host and pathogen the reads were mapped to, you could combine them into a ref.fa file, and run samtools faidx.
mastal is offline   Reply With Quote
Reply

Tags
error message, sam to bam

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 01:27 AM.


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