Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lovestow
    Junior Member
    • May 2015
    • 5

    #1

    samtools mpileup segfault with positions list

    Hello,

    I am using samtools v 1.2 on a machine with Ubuntu 14.04.2 and I am trying
    to generate a SNP table from sorted bam files (generated from a GBS library
    prep) aligned to a reference. So far I have used bwa for the alignment,
    samtools view to convert sam to bam, samtools sort, and samtools index.
    Those are all working fine, but when I use samtools mpileup, I get a
    segmentation fault. I think it is because I am trying to pass mpileup a
    list of positions to include from the reference with the -l flag (I don't
    get a segfault if I leave out the list of positions):

    samtools mpileup -g -b ~/Data/alignments/bamfilenames.txt -f
    /Data/alignments/reference.fa -l ~/Data/alignments/positions_to_include.txt
    > fish_snps.bcf

    This returns "segmentation fault (core dumped)." It also segaults if I just
    pass it a single bam file, rather than a list of bam files. How does the
    list of positions file need to be formatted? Is this what could be causing
    the segfault?

    Thanks for any help,

    Sierra
  • Richard Finney
    Senior Member
    • Feb 2009
    • 701

    #2
    What does your regions file look like?

    Comment

    • lovestow
      Junior Member
      • May 2015
      • 5

      #3
      It's just a list of the chromosome names in one column and the position along the chromosome in the other, like so ...

      chrUn 1
      chrUn 2
      chrUn 3
      chrUn 4
      ...
      chr_Sex 353216
      chr_Sex 353217
      chr_Sex 353218
      chr_Sex 353219
      chr_Sex 353220
      chr_Sex 353221
      chr_Sex 353222

      I'm trying to exclude SNPs called in regions of my reference genome that are potential paralogs, which I've identified by read depth of the original short reads used to build the reference.

      Comment

      • Richard Finney
        Senior Member
        • Feb 2009
        • 701

        #4
        I'm not sure what's going on.

        Looks like it needs a "bed file".


        Code says this for option 'l' ("el", not one "1") ... at line 846 in "bam_plcmd.c"


        case 'l':

        // In the original version the whole BAM was streamed which is inefficient
        // with few BED intervals and big BAMs. Todo: devise a heuristic to determine
        // best strategy, that is streaming or jumping.
        mplp.bed = bed_read(optarg);
        if (!mplp.bed) { print_error_errno("Could not read file \"%s\"", optarg); return 1; }
        break;

        _________

        If you know C or gdb, you can always debug using "printfs" or compile with -g (debug on) and step through using gdb ( linux debugger) .... a little advanced for most but very easy for linux wizards.
        Last edited by Richard Finney; 05-07-2015, 01:10 PM.

        Comment

        • lovestow
          Junior Member
          • May 2015
          • 5

          #5
          Hmm, that might be it. Based on the vague man page, I thought the -l flag could take a list of positions or a BED file:

          -l FILE list of positions (chr pos) or regions (BED) [null]

          but possibly it needs to be BED formatted. I will look into that. Thanks!

          I'm very far from a linux wizard, but will enlist the help of the nice wizards down the hall to help me debug with printfs and gdb.

          Comment

          • Richard Finney
            Senior Member
            • Feb 2009
            • 701

            #6
            You can find *where* it's segfaulting using printf (and an immediate fflush) very easily.

            figuring out *why* it segfaulted is another dimension.

            Comment

            • lovestow
              Junior Member
              • May 2015
              • 5

              #7
              I realize that stackoverflow and other venues might be a more appropriate venue for this question, but what's the usage for printf() and fflush()? Right before my call to samtools? Inexperienced linux user here...

              Comment

              • Richard Finney
                Senior Member
                • Feb 2009
                • 701

                #8
                samtools is written in C.
                The main author of samtools, Heng Li, provides the source which is *very* easy to compile.
                You can edit this code and type "make" and , if you didn't make a syntax error,
                have a new samtools executable with your modifications.

                the printf function is a convenient way to output strings.
                So, you can do things like ....

                printf("hey, i'm here before call to bed() function\n'); fflush(stdout);

                Output is not always done immediately, so the fflush forces the issue; before the next
                statement is executed.

                If you see your custom output, then the segfault, you know it happened *after* your printf call. If you had another printf expected to execute later, but you did not see it, then
                your program bombed *before* that statement.

                Strategic and refined placements or printfs can quickly tell you where the bomb blew up.
                It takes about 2 seconds to compile a modifed samtools, so this is often faster and easier thand cranking up gdb (a famous linux debugger). gdb can be used for tricky situations where more robust monitoring the states of variables is required.

                ____
                If you did ask on stackoverflow, your question would get promptly closed as "off topic" ... and you'd get ridiculed. The most frequently asked questions seem to suffer this fate over there.
                Last edited by Richard Finney; 05-08-2015, 04:50 AM.

                Comment

                • lovestow
                  Junior Member
                  • May 2015
                  • 5

                  #9
                  Sweet, thanks!

                  Comment

                  Latest Articles

                  Collapse

                  • SEQadmin2
                    Beyond CRISPR/Cas9: Understand, Choose, and Use the Right Genome Editing Tool
                    by SEQadmin2



                    CRISPR/Cas9 sparked the gene editing revolution for both research and therapeutics.1 But this system still showed severe issues that limited its applications. The most prominent were the heavy reliance on PAM sequences, delivery limitations, double-stranded breaks that prompt unintended edits and cell death, and editing inefficiency (both in targeting and in knock-in reliability).

                    Despite this, “CRISPR helped turn genome editing from a specialized technique into
                    ...
                    Yesterday, 11:01 AM
                  • SEQadmin2
                    Proteomic Platforms: How to Choose the Right Analytical Strategy to Improve Detection and Clinical Applications
                    by SEQadmin2


                    Proteomics platforms are evolving rapidly, with advances in mass spectrometry and affinity-based approaches expanding what researchers can detect and at what scale. As the field moves toward deeper proteome coverage and clinical applications, scientists face an increasingly complex landscape of tools. This article will explore how researchers are navigating these choices to find the right platform for their work.

                    The systematic characterization of the human proteome has
                    ...
                    07-20-2026, 11:48 AM
                  • SEQadmin2
                    Advanced Sequencing Platforms Tackle Neuroscience’s Toughest Genomics Problems
                    by SEQadmin2



                    Genomics studies in neuroscience face a special challenge due to the brain’s complexity and scarcity of samples. Mapping changes in cell type and state using conventional next-generation sequencing methods remains challenging. Advances in technologies like single-cell sequencing, spatial transcriptomics, and long-read sequencing have opened the door to deeper studies of the brain and diseases like Alzheimer’s, amyotrophic lateral sclerosis (ALS), and schizophrenia.
                    ...
                    07-09-2026, 11:10 AM

                  ad_right_rmr

                  Collapse

                  News

                  Collapse

                  Topics Statistics Last Post
                  Started by SEQadmin2, Yesterday, 02:55 AM
                  0 responses
                  8 views
                  0 reactions
                  Last Post SEQadmin2  
                  Started by SEQadmin2, 07-24-2026, 12:17 PM
                  0 responses
                  12 views
                  0 reactions
                  Last Post SEQadmin2  
                  Started by SEQadmin2, 07-23-2026, 11:41 AM
                  0 responses
                  12 views
                  0 reactions
                  Last Post SEQadmin2  
                  Started by SEQadmin2, 07-20-2026, 11:10 AM
                  0 responses
                  24 views
                  0 reactions
                  Last Post SEQadmin2  
                  Working...