Unconfigured Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Axel
    Junior Member
    • Feb 2014
    • 8

    samtools view segmentation fault

    Hi all,

    I am trying to convert a sorted .bam file back into a .sam file for downstream programs
    but when I run the command:

    samtools view -h in_sorted.bam > out_sorted.sam

    I get the error:

    zsh: segmentation fault samtools view -h in_sorted.bam > out_sorted.sam

    I am on a Ubuntu 12.04 desktop machine (BioLinux), with 8 GB RAM and 1 TB Hard-disk space.

    I could convert from a .sam file to a .bam file through samtools sort to get the sorted .bam file on the same machine so I don't think I'm running out of memory.

    I wonder if anyone could help me figure out what is going wrong.
  • Axel
    Junior Member
    • Feb 2014
    • 8

    #2
    Hi again,
    I thought I'd write and say I've sorted it out.
    Instead of trying to write a new .sam file I pipe the contents of the .bam file straight to the downstream programs in .sam format

    e.g.
    Code:
    samtools view -h in_sorted.bam | htseq-count - features.gtf

    Comment

    • arundurvasula
      Member
      • Jun 2014
      • 16

      #3
      Hi, I figured I'd just comment on this thread since I was going to name my thread the same thing. I'm trying to go from sam -> bam with
      Code:
      samtools view -bS ../results/Y920/Y920-trimmed-idba_ud/alignment.sam > ../results/Y920/Y920-trimmed-idba_ud/alignment.bam
      but I'm getting a segmentation fault. I have 8 GB of RAM, which I guess could be a problem. My sam file is ~300Mb. Do I need more RAM or is this a problem with samtools? I'm running 0.1.19 from the Ubuntu Software Repository.

      Also I'm using a virtual machine.
      Last edited by arundurvasula; 07-08-2014, 12:41 PM.

      Comment

      • swbarnes2
        Senior Member
        • May 2008
        • 910

        #4
        Can you confirm that you .bam really is a .bam file? That's the first thing I'd check.

        Comment

        • dpryan
          Devon Ryan
          • Jul 2011
          • 3478

          #5
          swbarnes2 meant ".sam" rather than ".bam". It's likely that a line is corrupt in the SAM file. If the file looks correct, then use "head -n some_number ... | samtools view -Sb - > ..." to determine if you can find the line triggering the problem (or just run the thing in a debugger).

          Comment

          • WhatsOEver
            Senior Member
            • Apr 2012
            • 215

            #6
            @arundurvasular: using the view command requires indeed more RAM (though 300Mb is actually a really small file) Try the following instead:

            Build an index of your genome
            Code:
            samtools faidx genomeFile.fasta
            Use the import command to convert from sam to bam
            Code:
            samtools import $samIndex $samFile $bamFile

            Comment

            • dpryan
              Devon Ryan
              • Jul 2011
              • 3478

              #7
              The "import" command was removed years ago. It's an alias for "samtools view" now.
              Code:
              int main_import(int argc, char *argv[])
              {
                      int argc2, ret;
                      char **argv2;
                      if (argc != 4) {
                              fprintf(stderr, "Usage: bamtk import <in.ref_list> <in.sam> <out.bam>\n");
                              return 1;
                      }
                      argc2 = 6;
                      argv2 = calloc(6, sizeof(char*));
                      argv2[0] = "import", argv2[1] = "-o", argv2[2] = argv[3], argv2[3] = "-bt", argv2[4] = argv[1], argv2[5] = argv[2];
                      ret = main_samview(argc2, argv2);
                      free(argv2);
                      return ret;
              }

              Comment

              • WhatsOEver
                Senior Member
                • Apr 2012
                • 215

                #8
                oh, good to know

                It's then just the provided index that results in less memory consumption?! Cause my command works faster and requires less RAM on my dataset then the previously posted command.

                Comment

                • dpryan
                  Devon Ryan
                  • Jul 2011
                  • 3478

                  #9
                  I'd be a bit surprised if it used less memory (at least if there's a significant difference). The only difference is the reheadering that's done with samtools import. A header doesn't really take that much RAM, at least unless it's filled with lots of small contigs.

                  Comment

                  • WhatsOEver
                    Senior Member
                    • Apr 2012
                    • 215

                    #10
                    yes, sry, my fault - indeed my header is kind of extremely big (17M contigs)
                    But nevertheless: Memory shouldn't actually be an issue here. The sam file is really small and although arundurvasular is running a virtual machine, 8Gb should be enough.

                    Comment

                    • dpryan
                      Devon Ryan
                      • Jul 2011
                      • 3478

                      #11
                      Yeah, 8 gigs should be way more than could possibly be needed.

                      @arundurvasular: If you're unable to find a way around this, then try posting the file somewhere (dropbox, google drive, etc.) and one of us can run samtools in a debugger (unless you're familiar with doing that yourself). It's possible that this is an obscure bug, but I suspect the original file is just malformed.

                      Comment

                      Latest Articles

                      Collapse

                      • GATTACAT
                        Reply to Nine Things a Sample Prep Scientist Thinks About Before Sequencing
                        by GATTACAT
                        Love this - good data definitely starts from good input, and poor input can only give relatively poor data. I particularly like the mention of Nanodrop/absorbance based methods for quantification. It's such a toss up if you'll get an accurate reading or what amounts to a randomly generated number, and a lot of library/sequencing related issues can be traced back to poor quant.
                        07-01-2026, 11:43 AM
                      • SEQadmin2
                        Nine Things a Sample Prep Scientist Thinks About Before Sequencing
                        by SEQadmin2


                        I’m not a sequencing expert. I’m a purification scientist who uses NGS to evaluate workflows my group develops. With this perspective, we think about the sample first and the NGS workflow second. The sequencer is an exceptionally honest reporter, but it can only report on what you give it, so whether you get clean, interpretable data from an NGS workflow is largely determined before you begin.

                        Here are nine questions we think about, in roughly the order they matter, before...
                        06-18-2026, 07:11 AM

                      ad_right_rmr

                      Collapse

                      News

                      Collapse

                      Topics Statistics Last Post
                      Started by SEQadmin2, 07-02-2026, 11:08 AM
                      0 responses
                      18 views
                      0 reactions
                      Last Post SEQadmin2  
                      Started by SEQadmin2, 06-30-2026, 05:37 AM
                      0 responses
                      19 views
                      0 reactions
                      Last Post SEQadmin2  
                      Started by SEQadmin2, 06-26-2026, 11:10 AM
                      0 responses
                      21 views
                      0 reactions
                      Last Post SEQadmin2  
                      Started by SEQadmin2, 06-17-2026, 06:09 AM
                      0 responses
                      54 views
                      0 reactions
                      Last Post SEQadmin2  
                      Working...