Unconfigured Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • efoss
    Member
    • Jul 2011
    • 98

    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
    Member
    • Jul 2011
    • 98

    #2
    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

    Comment

    • BAMseek
      Senior Member
      • Apr 2011
      • 124

      #3
      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:

      -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;

      Comment

      • maubp
        Peter (Biopython etc)
        • Jul 2009
        • 1544

        #4
        Or from memory -T can specify a FASTA file of the references.

        Comment

        • swbarnes2
          Senior Member
          • May 2008
          • 910

          #5
          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

          Comment

          • efoss
            Member
            • Jul 2011
            • 98

            #6
            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

            Comment

            • prasadg
              Member
              • Mar 2012
              • 16

              #7
              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.?

              Comment

              • efoss
                Member
                • Jul 2011
                • 98

                #8
                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

                Comment

                • prasadg
                  Member
                  • Mar 2012
                  • 16

                  #9
                  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

                  Comment

                  • efoss
                    Member
                    • Jul 2011
                    • 98

                    #10
                    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

                    Comment

                    • prasadg
                      Member
                      • Mar 2012
                      • 16

                      #11
                      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.

                      Comment

                      • efoss
                        Member
                        • Jul 2011
                        • 98

                        #12
                        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

                        Comment

                        • prasadg
                          Member
                          • Mar 2012
                          • 16

                          #13
                          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.

                          Comment

                          • bbm
                            Member
                            • Sep 2011
                            • 38

                            #14
                            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...

                            Comment

                            • efoss
                              Member
                              • Jul 2011
                              • 98

                              #15
                              Hi bbm,

                              You might want to try Picard's AddOrReplaceReadGroups:

                              Comment

                              Latest Articles

                              Collapse

                              • SEQadmin2
                                From Collection to Sequencing: Why Sample Preparation and Preservation Define Sequencing Data
                                by SEQadmin2


                                Data variability is still an issue in sequencing technologies despite the advances in reproducibility and accuracy of these platforms. But the problem does not originate in the sequencing itself, but in the previous steps, before the sample reaches the sequencer.


                                The first step is collection, followed by preservation and sample preparation for analysis. Most scientists overlook those steps, but not being careful might just be skewing the experiment’s results.
                                ...
                                06-02-2026, 10:05 AM
                              • SEQadmin2
                                Single-Cell Sequencing at an Inflection Point: Early Impacts of New Platforms and Emerging Trends
                                by SEQadmin2


                                With the launch of new single-cell sequencing platforms in 2026, the field stands at an exciting inflection point. This article surveys the most impactful advances in the field and discusses how they’re reshaping research in cancer, immunology, and beyond.


                                Introduction

                                Single-cell sequencing technologies have undergone remarkable advances over the past decade, transitioning from low-throughput experimental approaches to highly scalable platforms capable of...
                                05-22-2026, 06:42 AM
                              • SEQadmin2
                                Environmental Genomics in the Age of NGS: From Microbes to Conservation Strategies
                                by SEQadmin2

                                Studying ecosystems means dealing with complex, multi-species communities that are hard to observe at scale. This complexity, however, hides many important questions to be answered, from how biogeochemical cycles work and how climate change can affect species distribution to how conservation strategies can work best.


                                Genomics, particularly since the expansion of NGS, has transformed ecosystem ecology. By sequencing environmental DNA, we can now assess biodiversity without direct...
                                05-06-2026, 09:04 AM

                              ad_right_rmr

                              Collapse

                              News

                              Collapse

                              Topics Statistics Last Post
                              Started by SEQadmin2, 06-02-2026, 12:03 PM
                              0 responses
                              19 views
                              0 reactions
                              Last Post SEQadmin2  
                              Started by SEQadmin2, 06-02-2026, 11:40 AM
                              0 responses
                              14 views
                              0 reactions
                              Last Post SEQadmin2  
                              Started by SEQadmin2, 05-28-2026, 11:40 AM
                              0 responses
                              29 views
                              0 reactions
                              Last Post SEQadmin2  
                              Started by SEQadmin2, 05-26-2026, 10:12 AM
                              0 responses
                              31 views
                              0 reactions
                              Last Post SEQadmin2  
                              Working...