Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MarinePAM
    Junior Member
    • Jun 2014
    • 7

    #1

    Can't sort BAM file ("not a BAM file")

    Dear everyone,

    I try to convert some SAM files to BAM files following the Samtools FAQ method :
    First indexing my reference fasta file (I have no header in my SAM file) :
    Code:
    samtools faidx ref.fa
    Then converting my SAM file to BAM file :
    Code:
    samtools view -bt ref.fa.fai aln.sam > aln.bam
    Until here, everything seems fine, but...

    When trying to sort my BAM file :
    Code:
    samtools sort aln.bam aln-sorted
    I instantly get :
    [bam_header_read] invalid BAM binary header (this is not a BAM file).
    [bam_sort_core] truncated file. Continue anyway.
    Seegmentation fault (core dumped)


    The problem seems to be in the SAM-->BAM conversion... My SAM file seems OK (obtained with the Illumina script : illumina_export2sam.pl). It only contains one "@PG" line at its beginning, that's why I followed the Samtools FAQ method.

    I've already once done that on another data and everything went fine...So I really don't understand what is happening now.
    Could someone tell me what is wrong ?
    I'd be very grateful if someone could help me !!!

    Best regards,

    Marine
  • Michael.Ante
    Senior Member
    • Oct 2011
    • 127

    #2
    Hi Marine,
    I assume your SAM file consists of non-aligned reads. Thus, trying to sort your reads according to their chromosomal locations might lead to the error. If you want to sort the BAM file anyway, try
    Code:
    samtools sort -n aln.bam aln-sorted
    Cheers,
    Michael

    Comment

    • dpryan
      Devon Ryan
      • Jul 2011
      • 3478

      #3
      Which version of samtools are you using? Can you "samtools view aln.bam"? I'm guessing not. Also, what happens if you instead use "samtools view -Sbt ref.fa.fai aln.sam > aln.bam"?

      BTW, am I correct in assuming you're the same person that just emailed the samtools-help email list?

      Comment

      • MarinePAM
        Junior Member
        • Jun 2014
        • 7

        #4
        Thank you for your quick answer !!
        My SAM file is about aligned reads. But the names of each feature in my reference file (ref.fa, to which I aligned the reads) are not like "Chr..." but rather like "15648-ref" ... Is this supposed to be a problem ?

        Whatsmore, trying what you proposed gives me exactly the same error message

        Comment

        • dpryan
          Devon Ryan
          • Jul 2011
          • 3478

          #5
          Originally posted by MarinePAM View Post
          My SAM file is about aligned reads. But the names of each feature in my reference file (ref.fa, to which I aligned the reads) are not like "Chr..." but rather like "15648-ref" ... Is this supposed to be a problem ?
          That should be fine.

          Whatsmore, trying what you proposed gives me exactly the same error message
          Try the "samtools view -Sbt blah.fa.fai foo.sam > foo.bam" command that I suggested above and see if you can even "samtools view foo.bam" then (I'm assuming you get the error if you try that on the current BAM file).

          Comment

          • MarinePAM
            Junior Member
            • Jun 2014
            • 7

            #6
            Dear dpryan,

            Thank you for your answer !

            The version is : Version: 0.1.18 (r982:295)

            Indeed, "samtools view aln.bam" gives me the same error message...

            I've just ran : "samtools view -Sbt ref.fa.fai aln.sam > aln.bam". It worked (as well as without the -S option). When running the next sort step, it seems to work !! I thought the "-S" option was forced by the "-t" option as described in the help, but maybe not ?
            While currently still running, this message appears : "merging from 10 files..." Do you know what are these 10 files ?

            (Yes I am the same person as on the mailing list !)

            Comment

            • dpryan
              Devon Ryan
              • Jul 2011
              • 3478

              #7
              0.1.18 is an older version, so perhaps -S wasn't forced by -t in that version.

              When samtools sorts a BAM file, it breaks it into smaller sorted files and then merges them. This drastically decreases memory requirements (otherwise, you have to hold the whole thing in memory!) and is quick because merging sorted files is quite fast.

              Let me know once that's done if it works and I'll leave a note on the samtools list about the cause/solution.

              Comment

              • MarinePAM
                Junior Member
                • Jun 2014
                • 7

                #8
                It worked ! I've done the "sort" and "index" steps with success !!
                Many many thanks to you, I'm very happy !

                So it was the -S option. I'm surprised because I read the help corresponding to this older version !
                Thank you also for leaving a note on the samtools list (I was about to ask you if I need to do so) !

                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...