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

                              • mylaser
                                Reply to Advanced Sequencing Platforms Tackle Neuroscience’s Toughest Genomics Problems
                                by mylaser
                                Kheloyar – Everything You Need to Know About Kheloyaar Login and Kheoyar Id
                                If you are looking for an online gaming platform that offers a user-friendly experience, Kheloyar has become a name that many users search for. Whether you're interested in creating a new account, accessing your dashboard through Kheloyaar Login, or learning how to obtain a Kheoyar Id, understanding the platform's features and account process is essential.
                                This guide explains everything you need to know about...
                                Today, 01:13 AM
                              • SEQadmin2
                                Advanced Sequencing Platforms Tackle Neuroscience’s Toughest Genomics Problems
                                by SEQadmin2



                                Genomics studies in neuroscience face a special challenge due to the brain’s complexity and scarcity of samples. Mapping changes in cell type and state using conventional next-generation sequencing methods remains challenging. Advances in technologies like single-cell sequencing, spatial transcriptomics, and long-read sequencing have opened the door to deeper studies of the brain and diseases like Alzheimer’s, amyotrophic lateral sclerosis (ALS), and schizophrenia.
                                ...
                                07-09-2026, 11:10 AM
                              • SEQadmin2
                                Cancer Drug Resistance: The Lingering Barrier to Rising Survival
                                by SEQadmin2



                                Cancer survival rates have significantly increased in the last few decades in the United States, reaching a combined 70% 5-year survival rate by 2021. Behind this number, there are years of research to find new therapies, drug targets, and early detection methods. But there is one core challenge that keeps slowing down these advances, and it’s about drug resistance.

                                There is no single reason why many patients don’t respond to treatment as expected. Cancer is...
                                07-08-2026, 05:17 AM

                              ad_right_rmr

                              Collapse

                              News

                              Collapse

                              Topics Statistics Last Post
                              Started by SEQadmin2, 07-09-2026, 10:04 AM
                              0 responses
                              11 views
                              0 reactions
                              Last Post SEQadmin2  
                              Started by SEQadmin2, 07-08-2026, 10:08 AM
                              0 responses
                              9 views
                              0 reactions
                              Last Post SEQadmin2  
                              Started by SEQadmin2, 07-07-2026, 11:05 AM
                              0 responses
                              17 views
                              0 reactions
                              Last Post SEQadmin2  
                              Started by SEQadmin2, 07-02-2026, 11:08 AM
                              0 responses
                              31 views
                              0 reactions
                              Last Post SEQadmin2  
                              Working...