Unconfigured Ad

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

    #1

    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:

                              http://picard.sourceforge.net/comman...laceReadGroups

                              Comment

                              Latest Articles

                              Collapse

                              • SEQadmin2
                                Multiomic Liquid Biopsy: What DNA/RNA Panels Reveal That DNA Alone Can’t
                                by SEQadmin2



                                Tumors contain complex mixtures of cell populations that evolve in response to treatment and host-specific factors. Tissue biopsies provide only static snapshots of a tumor’s state. But what if we could follow that evolution over time using a minimally invasive technique?

                                Liquid biopsies can detect tumor-derived material circulating in the bloodstream, providing a way to study treatment response, detect emerging resistance, and discover new biomarkers. Circulating
                                ...
                                10-14-2026, 09:55 AM
                              • SEQadmin2
                                New Genomics Technologies Take Aim at Long-Standing Limits
                                by SEQadmin2


                                Researchers using sequencing and genomics tools often have to make trade-offs. They can choose between speed or scale, short reads or long-range information, or targeted panels or a view of the whole transcriptome. New technologies that have been released this year are built to address those tough choices.

                                We asked six companies the same four questions to learn about their latest products. The new technologies bring a lot to the table, including rethinking sequencing
                                ...
                                09-28-2026, 10:25 AM

                              ad_right_rmr

                              Collapse

                              News

                              Collapse

                              Topics Statistics Last Post
                              Started by SEQadmin2, 10-15-2026, 10:52 AM
                              0 responses
                              23 views
                              0 reactions
                              Last Post SEQadmin2  
                              Started by SEQadmin2, 10-14-2026, 05:39 AM
                              0 responses
                              27 views
                              0 reactions
                              Last Post SEQadmin2  
                              Started by SEQadmin2, 10-13-2026, 09:56 AM
                              0 responses
                              24 views
                              0 reactions
                              Last Post SEQadmin2  
                              Started by SEQadmin2, 10-09-2026, 11:14 AM
                              0 responses
                              28 views
                              0 reactions
                              Last Post SEQadmin2  
                              Working...