Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ddmoore1028
    Junior Member
    • Jun 2013
    • 6

    #1

    Samtools bam sort and index errors

    I'm having issues with the sorting/indexing of a bam file. I just started working with samtools (and all bioinformatics) last week so I'm pretty new to this.

    First I generated a SAM alignment file using STAR. Then I converted that to a BAM file and it seemed to run correctly. But the I try to sort the bam file, and here are my inputs and the resulting output:

    samtools sort alignment1.bam alignment1.sorted
    [bam_header_read] EOF marker is absent. The input is probably truncated.
    [bam_header_read] invalid BAM binary header (this is not a BAM file).
    Segmentation fault

    If I try to go straight to indexing, I get a similar error:

    samtools index alignment1.bam alignment1.bai
    [bam_header_read] EOF marker is absent. The input is probably truncated.
    [bam_header_read] invalid BAM binary header (this is not a BAM file).
    [bam_index_core] Invalid BAM header.[bam_index_build2] fail to index the BAM file.

    Can someone help me fix these issues?

    Thanks
  • GenoMax
    Senior Member
    • Feb 2008
    • 7142

    #2
    For the first part see this thread (post #2): http://seqanswers.com/forums/showthread.php?t=21908

    Are you doing this using a virtual (or real) server?

    Comment

    • Richard Finney
      Senior Member
      • Feb 2009
      • 701

      #3
      Show your command for creating the BAM from the SAM.
      What version of samtools are you using?

      If you know the "od" command, try this ...
      od -x YOURFILENAME.bam | head -1

      output should be

      0000000 8b1f 0408 0000 0000 ff00 0006 4342 0002

      The message you are getting is from this code which is checking for the "BAM\001" characters ...

      magic_len = bam_read(fp, buf, 4);
      if (magic_len != 4 || strncmp(buf, "BAM\001", 4) != 0) {
      fprintf(stderr, "[bam_header_read] invalid BAM binary header (this is not a BAM file).\n");
      return 0;
      }

      Possible reasons are : the file zero length, the file is a sam file, it is corrupted.

      Can you view the first few bytes of the "bam" file in question ?
      Last edited by Richard Finney; 06-13-2013, 09:27 AM.

      Comment

      • ddmoore1028
        Junior Member
        • Jun 2013
        • 6

        #4
        Originally posted by GenoMax View Post
        Are you doing this using a virtual (or real) server?
        I'm not entirely sure. I'm accessing a computer that I think has 24 cores using the ssh command in Unix, and using that to run my programs. My program files and data are stored in what I think is probably a virtual server (to access it directly from my macbook, not using Unix, I use the Go > Connect to server function in the Finder).

        Show your command for creating the BAM from the SAM.
        nohup samtools view -bS Aligned.out.sam > alignment1.bam &>secondtrybam.out&

        I tried the od command and got this:

        od -x alignment1.bam | head -1
        0000000

        My program file is : samtools-0.1.19

        Can you view the first few bytes of the "bam" file in question ?
        I just tried to use vi, more, and less to view and there doesn't seem to be anything in the file. Is there something wrong with my SAM>BAM conversion?

        Thank you

        Comment

        • ddmoore1028
          Junior Member
          • Jun 2013
          • 6

          #5
          When I checked the SAM file, it definitely seems correct. The first number of lines begin with @ and seem to refer to the chromosomes mapped, and after out I see line after line of reads

          Comment

          • Richard Finney
            Senior Member
            • Feb 2009
            • 701

            #6
            What does "&>" do?

            Try running just this ...
            samtools view -bS Aligned.out.sam > alignment1.bam

            What happens ?
            What is the size of alignment1.bam ?

            Comment

            • ddmoore1028
              Junior Member
              • Jun 2013
              • 6

              #7
              Since nohup makes the program run in the background and not quit if I have to log out of my laptop, I thought "&>" changed the nohup.out file to the name I assigned it, but I think that may have changed the command somehow.

              The original bam file that was giving me trouble is 2 kb.

              The new bam file is 622 mb and counting. When I entered the simpler command I got:

              samtools view -bS Aligned.out.sam > alignment1again.bam
              [samopen] SAM header is present: 25 sequences.
              []

              and its been running since. I think this is probably going to fix it! Thank you!

              The SAM file is about 50 gb, what can I expect the bam file size to be at the end?

              Comment

              • ddmoore1028
                Junior Member
                • Jun 2013
                • 6

                #8
                I checked the size of the secondtrybam.out file that I used &> on, and it's 13.04 gb. I think that the &> directed the binary to write to the .out file rather than the .bam file. I think that's the problem I had.

                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, Yesterday, 11:13 AM
                0 responses
                21 views
                0 reactions
                Last Post SEQadmin2  
                Started by SEQadmin2, Yesterday, 10:48 AM
                0 responses
                18 views
                0 reactions
                Last Post SEQadmin2  
                Started by SEQadmin2, 10-15-2026, 10:52 AM
                0 responses
                36 views
                0 reactions
                Last Post SEQadmin2  
                Started by SEQadmin2, 10-14-2026, 05:39 AM
                0 responses
                42 views
                0 reactions
                Last Post SEQadmin2  
                Working...