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

                • kinpict.com
                  Reply to 16S/ITS Profiling vs. Shotgun Metagenomics: What Changes in Your Workflow?
                  by kinpict.com
                  The part about this topic feels surprisingly grounded, and the details on the page is the bit that made me slow down. I’d keep <a href="https://kinpict.com/">ai family photo generator</a> bookmarked for later.
                  Today, 06:37 PM
                • SEQadmin2
                  16S/ITS Profiling vs. Shotgun Metagenomics: What Changes in Your Workflow?
                  by SEQadmin2





                  NGS has revolutionized clinical microbiology by offering new ways to identify and surveil pathogens without prior knowledge of the target. One popular approach is 16S rRNA and ITS amplicon sequencing, which targets specific microbial markers. But studies are increasingly incorporating shotgun metagenomics, a technique that sequences all DNA from a sample without targeting specific microbial markers. This approach allows more detailed taxonomic classification,...
                  10-30-2026, 06:46 AM

                ad_right_rmr

                Collapse

                News

                Collapse

                Topics Statistics Last Post
                Started by SEQadmin2, 11-12-2026, 07:59 AM
                0 responses
                27 views
                0 reactions
                Last Post SEQadmin2  
                Started by SEQadmin2, 11-05-2026, 09:25 AM
                0 responses
                35 views
                0 reactions
                Last Post SEQadmin2  
                Started by SEQadmin2, 11-03-2026, 11:54 AM
                2 responses
                56 views
                0 reactions
                Last Post kinpict.com  
                Started by SEQadmin2, 10-28-2026, 09:57 AM
                0 responses
                175 views
                0 reactions
                Last Post SEQadmin2  
                Working...