Seqanswers Leaderboard Ad

Collapse

Announcement

Collapse
No announcement yet.
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • SAM to BAM --- samtools fail to read error

    I am trying to transfer a SAM file to BAM file using samtools but get error as shown in the attached figure.

    I have the SAM files ready in the right format, this SAM file is prepared by join another sam file with one bed file together. The columns are correct.

    I used -S to indicate input is sam, and -b to indicate output is bam

    i use -t to indicate that the sam file contains tab delimiter, and no header.

    what could be the issue?

    Thanks a lot
    Attached Files

  • #2
    $ /usr/local/samtools-0.1.18/samtools view -bS all-hg18.bam -o test.bam
    [samopen] no @SQ lines in the header.
    [sam_read1] missing header? Abort!

    $ /usr/local/samtools-0.1.18/samtools view -tbS all-hg18.bam -o test.bam
    [main_samview] fail to open "all-hg18.bam" for reading.

    Comment


    • #3
      find online manual said:
      If your SAM file has header @SQ lines, you may get BAM by ...
      If not, you need to have your reference file ref.fa and then do this:
      looks like i need a ref.fa file, not sure what is that? how does it looks like and how to get it?

      thanks

      Shuoguo

      Comment


      • #4
        That was shorthand for your reference genome in FASTA format.

        Comment


        • #5
          Try

          samtools view -bSh mysam.sam > mybam.bam
          I don't think you need the -t, and I'm not sure that the software likes you putting the -o option after the input file name.

          -h will make sure the header goes on there.

          Comment


          • #6
            It seems that no matter how I run it it will just spit out errors

            $ /usr/local/samtools-0.1.18/samtools view -bS all-hg18-lifted.sam -o test.bam
            [samopen] no @SQ lines in the header.
            [sam_read1] missing header? Abort!

            ]$ /usr/local/samtools-0.1.18/samtools view -bS all-hg18-lifted.sam test.bam
            [samopen] no @SQ lines in the header.
            [main_samview] random alignment retrieval only works for indexed BAM files.

            Comment


            • #7
              in my case i do not have teh original fasta files

              Originally posted by maubp View Post
              That was shorthand for your reference genome in FASTA format.

              Comment


              • #8
                Originally posted by shuoguo View Post
                It seems that no matter how I run it it will just spit out errors
                Use the caret to write to the .bam

                /usr/local/samtools-0.1.18/samtools view -bS all-hg18-lifted.sam > test.bam

                Comment


                • #9
                  tried that with no luck. thanks for the reply.

                  Originally posted by swbarnes2 View Post
                  Use the caret to write to the .bam

                  Comment


                  • #10
                    Which version of samtools do you have?

                    Comment


                    • #11
                      samtools-0.1.18

                      Comment


                      • #12
                        Without knowing the chromosome names and sizes, you won't be able to make a BAM file (there'd be no way for it to know how to create the header). You can probably half-ass it by just getting a sorted list of chromosomes from your SAM file:
                        Code:
                        cat all-hg18-lifted.sam | cut -f 3 | sort | uniq > ref.fa.fai
                        For each line in ref.fa.fai, you then need to add that chromosome's length (separated by a tab from the chromosome name, so "chr1 500000000"). Obviously you don't know that, but you could just use a sufficiently large number. That would at least allow things to be converted to a BAM file. I don't know if that would screw things up with any downstream applications, but I can't currently think of a situation where it would.

                        Comment


                        • #13
                          As what dpryan and other said, its the header issue. May I know how you generate the sam file at the first place?

                          Comment


                          • #14
                            Originally posted by masterpiece View Post
                            As what dpryan and other said, its the header issue. May I know how you generate the sam file at the first place?
                            Step 1: i have the original bam and bam.bai files downloaded from web. These are aligned with hg18.

                            Step 2: i transfer the same bam file to a bed file and a sam file.

                            Step 3: i liftover the bed file with the hg19 chain file (so the position is updated)

                            Step 4: I replace the position (3rd column) in the sam file with the liftover file.

                            Step 5: I want to transfer this sam file back to bam file, getting the error

                            Thanks for the help!!

                            Comment


                            • #15
                              Ah, then since this is just hg18, you have a two options:

                              1) Do what I suggested above, substituting the length of the various chromosomes in hg18 for the made up values I originally suggested. You would have to look up these values.

                              2) Download the hg18 fasta file and run "samtools faidx" on it. You can then use the "-t" option that you tried before with the resulting .fai file. This is effectively the same as option 1, but requires less googling.

                              BTW, I hope you replaced all of the coordinate information rather than just the chromosome (position 3). Otherwise whatever you do downstream will be messed up.

                              Comment

                              Latest Articles

                              Collapse

                              • seqadmin
                                Non-Coding RNA Research and Technologies
                                by seqadmin




                                Non-coding RNAs (ncRNAs) do not code for proteins but play important roles in numerous cellular processes including gene silencing, developmental pathways, and more. There are numerous types including microRNA (miRNA), long ncRNA (lncRNA), circular RNA (circRNA), and more. In this article, we discuss innovative ncRNA research and explore recent technological advancements that improve the study of ncRNAs.

                                Nobel Prize for MicroRNA Discovery
                                This week,...
                                10-07-2024, 08:07 AM
                              • seqadmin
                                Recent Developments in Metagenomics
                                by seqadmin





                                Metagenomics has improved the way researchers study microorganisms across diverse environments. Historically, studying microorganisms relied on culturing them in the lab, a method that limits the investigation of many species since most are unculturable1. Metagenomics overcomes these issues by allowing the study of microorganisms regardless of their ability to be cultured or the environments they inhabit. Over time, the field has evolved, especially with the advent...
                                09-23-2024, 06:35 AM

                              ad_right_rmr

                              Collapse

                              News

                              Collapse

                              Topics Statistics Last Post
                              Started by seqadmin, Today, 06:55 AM
                              0 responses
                              9 views
                              0 likes
                              Last Post seqadmin  
                              Started by seqadmin, 10-02-2024, 04:51 AM
                              0 responses
                              105 views
                              0 likes
                              Last Post seqadmin  
                              Started by seqadmin, 10-01-2024, 07:10 AM
                              0 responses
                              114 views
                              0 likes
                              Last Post seqadmin  
                              Started by seqadmin, 09-30-2024, 08:33 AM
                              1 response
                              118 views
                              0 likes
                              Last Post EmiTom
                              by EmiTom
                               
                              Working...
                              X