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
                                Genetic Variation in Immunogenetics and Antibody Diversity
                                by seqadmin



                                The field of immunogenetics explores how genetic variations influence immune responses and susceptibility to disease. In a recent SEQanswers webinar, Oscar Rodriguez, Ph.D., Postdoctoral Researcher at the University of Louisville, and Ruben Martínez Barricarte, Ph.D., Assistant Professor of Medicine at Vanderbilt University, shared recent advancements in immunogenetics. This article discusses their research on genetic variation in antibody loci, antibody production processes,...
                                11-06-2024, 07:24 PM
                              • seqadmin
                                Choosing Between NGS and qPCR
                                by seqadmin



                                Next-generation sequencing (NGS) and quantitative polymerase chain reaction (qPCR) are essential techniques for investigating the genome, transcriptome, and epigenome. In many cases, choosing the appropriate technique is straightforward, but in others, it can be more challenging to determine the most effective option. A simple distinction is that smaller, more focused projects are typically better suited for qPCR, while larger, more complex datasets benefit from NGS. However,...
                                10-18-2024, 07:11 AM

                              ad_right_rmr

                              Collapse

                              News

                              Collapse

                              Topics Statistics Last Post
                              Started by seqadmin, 11-08-2024, 11:09 AM
                              0 responses
                              217 views
                              0 likes
                              Last Post seqadmin  
                              Started by seqadmin, 11-08-2024, 06:13 AM
                              0 responses
                              160 views
                              0 likes
                              Last Post seqadmin  
                              Started by seqadmin, 11-01-2024, 06:09 AM
                              0 responses
                              80 views
                              0 likes
                              Last Post seqadmin  
                              Started by seqadmin, 10-30-2024, 05:31 AM
                              0 responses
                              27 views
                              0 likes
                              Last Post seqadmin  
                              Working...
                              X