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

                              ad_right_rmr

                              Collapse

                              News

                              Collapse

                              Topics Statistics Last Post
                              Started by SEQadmin2, Yesterday, 10:09 AM
                              0 responses
                              10 views
                              0 reactions
                              Last Post SEQadmin2  
                              Started by SEQadmin2, 06-04-2026, 08:59 AM
                              0 responses
                              20 views
                              0 reactions
                              Last Post SEQadmin2  
                              Started by SEQadmin2, 06-02-2026, 12:03 PM
                              0 responses
                              27 views
                              0 reactions
                              Last Post SEQadmin2  
                              Started by SEQadmin2, 06-02-2026, 11:40 AM
                              0 responses
                              21 views
                              0 reactions
                              Last Post SEQadmin2  
                              Working...