Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yaximik
    Senior Member
    • Apr 2011
    • 199

    #1

    samtools sorting problem

    Hi everyone,

    I encountered a strange problem with samtools sorting. A 37.6 GB sam file was generated by Stampy after mapping Illumina reads to hg19. It was converted to a 11.3 GB bam file with samtools. Then I tried to sort it and this where I hit the problem. I used fisrt default settings (1 thread, 756MB/thread):
    Code:
    samtools sort input.sam out_sorted.bam
    After a while samtools started spitting chunks of out_sorted.bam000X.bam files, each new initiated after previous reached 130-160 MB; at 21st chunk I killed it.
    Then I increased memory:
    Code:
    samtools sort -m 10G input.sam out_sorted.bam
    This time samtools spit out only 6 chunks of 1.5-2.5 GB, then started pouring binary gibberish to stdout, and eventually hang.
    When I tried to run multithreaded sorting
    Code:
    samtools sort -@ 8 -m 3G input.sam out_sorted.bam
    the behavior was the same except chunks were spit in multiples of 8, with -@ 16 in multiples of 16, but eventually all ended up with binary gibberish to stdout.
    I am using version 0.1.19-44428cd; the 2x4 cpu box has 96GB of memory, RHEL5.8.
    Can anyone advise what is going on and why?
  • swbarnes2
    Senior Member
    • May 2008
    • 910

    #2
    A 37 gig sam file?

    Why haven't you converted it to .bam?

    I didn't think samtools would even work on a .sam file.

    Also note that if your command line worked, it would make an output file called output.bam.bam

    Why did you kill the sort function? It is supposed to make all those intermediate files, then it merges them.

    Comment

    • yaximik
      Senior Member
      • Apr 2011
      • 199

      #3
      Originally posted by swbarnes2 View Post
      A 37 gig sam file?

      Why haven't you converted it to .bam?

      I didn't think samtools would even work on a .sam file.

      Also note that if your command line worked, it would make an output file called output.bam.bam

      Why did you kill the sort function? It is supposed to make all those intermediate files, then it merges them.
      This is what Stampy produced, not my choice. Then I converted it with samtools, it does take sam files with -S option
      Code:
      samtools view -bS -@ 16 infile.sam -o outfile.bam
      If if you read again my previous post, I got not output.bam.bam, but output.bam000X.bam, where X was incremented for each new chunk. I killed it because it did not look right, it could have produced hundreds of intermediate files. Indeed, with larger allocated memory file chinks become larger and less in number, yet everytime I waited instead of combined files I got binary gibberish to stdout. It seemed that the size of chinks was roughly 1/5 of the allocated memory (150-160MB at default 756MB, 2-2.5GB at 10GB, and 11GB at 48GB). Finally I used just one default thread but gave it 72 GB - no intremediate file outfile_sorted.bam0000.bam was formed, yet after a while the same binary gibberish was spilled out to stdout.

      Comment

      • syfo
        Just a member
        • Nov 2012
        • 103

        #4
        What about simply trying

        Code:
        samtools sort input.bam out_sorted

        Comment

        • yaximik
          Senior Member
          • Apr 2011
          • 199

          #5
          Originally posted by syfo View Post
          What about simply trying

          Code:
          samtools sort input.bam out_sorted
          Well, the only difference is that instead of hundreds of out_sorted.bam000X.bam I get hundreds of 150MB out_sorted000X.bam files and then binary gibberish if I wait long enough. Not an enticing reason to try...

          Comment

          • sBeier
            Member
            • Jan 2013
            • 41

            #6
            The temporary files are normal. And I guess the binary gibberish could actually be you sorted output bam-file.
            I usually use bamtools sort, but have you tried
            Code:
            samtools sort input.bam > output.bam

            Comment

            • syfo
              Just a member
              • Nov 2012
              • 103

              #7
              Originally posted by yaximik View Post
              Well, the only difference is that instead of hundreds of out_sorted.bam000X.bam I get hundreds of 150MB out_sorted000X.bam files and then binary gibberish if I wait long enough. Not an enticing reason to try...
              How do you know? Have you tried to use it on a proper bam file?
              According to the manual:

              Code:
              Usage:   samtools sort [options] <in.bam> <out.prefix>
              I do not get the point of keeping huge sam files.

              Comment

              • swbarnes2
                Senior Member
                • May 2008
                • 910

                #8
                Originally posted by yaximik View Post
                This is what Stampy produced, not my choice. Then I converted it with samtools, it does take sam files with -S option
                Code:
                samtools view -bS -@ 16 infile.sam -o outfile.bam
                If if you read again my previous post, I got not output.bam.bam, but output.bam000X.bam, where X was incremented for each new chunk.
                And this is totally in line with how samtools sort works.

                I killed it because it did not look right, it could have produced hundreds of intermediate files.
                Probably not hundreds, but it is supposed to produce a lot of them. And then it deletes them after it merges them together.

                And again, why do you still have a .sam file?

                bwa outputs a .sam file too, but I don't leave them lying around. I make them into .bams as soon as possible, piping the program that makes the .sam file directly into samtools view, where possible, and I don't keep the .sams once I have .bams.

                And I don't see any documentation for samtools sort that says it takes a .sam file as input. I'm using samtools 1.18, and it doesn't.

                Comment

                • yaximik
                  Senior Member
                  • Apr 2011
                  • 199

                  #9
                  [SOLVED] samtools sorting problem

                  Originally posted by swbarnes2 View Post
                  And this is totally in line with how samtools sort works.



                  Probably not hundreds, but it is supposed to produce a lot of them. And then it deletes them after it merges them together.

                  And again, why do you still have a .sam file?

                  bwa outputs a .sam file too, but I don't leave them lying around. I make them into .bams as soon as possible, piping the program that makes the .sam file directly into samtools view, where possible, and I don't keep the .sams once I have .bams.

                  And I don't see any documentation for samtools sort that says it takes a .sam file as input. I'm using samtools 1.18, and it doesn't.
                  Samtools 0.1.19 does take sam file, and I did convert it to bam once I got the output from Stampy, which produces sam by default.

                  I got answer from samtools-help mailing list. Darn, that was so simple! The option -o means output to stdout, so I was getting what I asked for. I confused this with other programs, in which option -o outfile does exactly opposite. syfo was absolutely correct and I apologize for brushing the correct advice off.

                  Comment

                  • syfo
                    Just a member
                    • Nov 2012
                    • 103

                    #10
                    Originally posted by yaximik View Post
                    Samtools 0.1.19 does take sam file, and I did convert it to bam once I got the output from Stampy, which produces sam by default.

                    I got answer from samtools-help mailing list. Darn, that was so simple! The option -o means output to stdout, so I was getting what I asked for. I confused this with other programs, in which option -o outfile does exactly opposite. syfo was absolutely correct and I apologize for brushing the correct advice off.
                    No problem Thanks for the update, that could help others.

                    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
                    16 views
                    0 reactions
                    Last Post SEQadmin2  
                    Started by SEQadmin2, Yesterday, 10:48 AM
                    0 responses
                    16 views
                    0 reactions
                    Last Post SEQadmin2  
                    Started by SEQadmin2, 10-15-2026, 10:52 AM
                    0 responses
                    35 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...