Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • albireo
    Member
    • Sep 2012
    • 39

    #1

    How to count uniquely mapping reads with BWA?

    Apologies if this has been asked before.

    I'm quite familiar with Bowtie, which I use with the following options:

    --best --strata -m 1

    To retrieve only "uniquely" mapping chip-seq reads. On completion of an alignment, Bowtie provides an output similar to this:

    # reads processed: 2307803
    # reads with at least one reported alignment: 1653076 (71.63%)
    # reads that failed to align: 236689 (10.26%)
    # reads with alignments suppressed due to -m: 418038 (18.11%)
    Reported 1653076 alignments to 1 output stream(s)

    Where I interpret that 71.63% as the number of uniquely mapping reads.

    Now I would like to do the same with BWA. I have ran BWA with default options and would like to generate similar statistics. Is there a tool that allows me to do that? I understand that, having used default options, I will have "multiply" mapping reads, but these reads are given a MAPQ=0 by bwa.

    Any suggestions would be appreciated. Thanks!
  • pbluescript
    Senior Member
    • Nov 2009
    • 224

    #2
    There are many ways to do this. Here's one you can use if you have a BAM file of reads aligned with BWA.

    Code:
    samtools view -F 256 your_file.bam | wc -l
    This will remove all the reads that are not primary alignments and then count the lines of output. The number you get will be the number of unique alignments.

    BWA also outputs an X0 tag that tells you how many "best" alignments there are. You could count the reads where X0 = 1 to get your answer as well.

    Comment

    • albireo
      Member
      • Sep 2012
      • 39

      #3
      Hi thanks, but this is not working. If I use it with a .bam file obtained with bwa, It just gives me the total number of reads in the .bam, 2307803 (corresponding to the "reads processed" in the bowtie output). What am I doing wrong?

      Btw, I found a utility called bamtools with has a "stats" option. If I use it on the bowtie alignment, it yields

      **********************************************
      Stats for BAM file(s):
      **********************************************

      Total reads: 2307803
      Mapped reads: 1653076 (71.6299%)
      Forward strand: 1481385 (64.1903%)
      Reverse strand: 826418 (35.8097%)
      Failed QC: 0 (0%)
      Duplicates: 0 (0%)
      Paired-end reads: 0 (0%)

      which agrees with Bowtie's own output. If I use it with the BWA alignment of the same file, it yields

      Total reads: 2307803
      Mapped reads: 2103778 (91.1593%)
      Forward strand: 1255418 (54.3988%)
      Reverse strand: 1052385 (45.6012%)
      Failed QC: 0 (0%)
      Duplicates: 0 (0%)
      Paired-end reads: 0 (0%)

      So it's telling me that 91.1% of my reads have been mapped. However I imagine this includes also those mapped to multiple locations (because I've used bwa with default options). Is there an easy way to remove them from this statistics, and get an output comparable to that 71.63% from bowtie? Thanks once more for your help.
      Last edited by albireo; 05-10-2013, 03:58 AM.

      Comment

      • pbluescript
        Senior Member
        • Nov 2009
        • 224

        #4
        How do you know it's not working? If you get 0 from this command, it is working.

        Code:
        samtools view -f 256 your_file.bam | wc -l
        BWA can do soft clipping while the original Bowtie does not. Maybe you have some adapter contamination or low quality reads that can be mapped with BWA that can't be mapped with Bowtie.

        Comment

        • albireo
          Member
          • Sep 2012
          • 39

          #5
          Hi, thanks for this. I do get 0 with this command. However I still don't understand why

          Code:
          samtools view -F 256 your_file.bam | wc -l
          gives me the total number of reads, and not the uniquely mapped ones. The other program, bamtools, shows that these two numbers should not be the same.

          Comment

          • pbluescript
            Senior Member
            • Nov 2009
            • 224

            #6
            You are getting those results because BWA only gave you unique alignments.

            Comment

            • albireo
              Member
              • Sep 2012
              • 39

              #7
              Thanks, so is the following bamtools output wrong, or am I misunderstanding something?

              Total reads: 2307803
              Mapped reads: 2103778 (91.1593%)

              Comment

              • pbluescript
                Senior Member
                • Nov 2009
                • 224

                #8
                BWA outputs mapped as well as unmapped reads to the SAM file.

                Comment

                • albireo
                  Member
                  • Sep 2012
                  • 39

                  #9
                  Ok, we agree on that. My original question was: how do I get the proportion of lines in the BWA .bam which map only to one location of the genome? It is certainly not the output of your line, because that gives me 2307803, which includes

                  1-uniquely mapped
                  2-multiply mapped
                  3-unmapped.

                  1+2+3 = 2307803 = 100%
                  1+2=2103778 = 91.1593%
                  1=?

                  Comment

                  • pbluescript
                    Senior Member
                    • Nov 2009
                    • 224

                    #10
                    Haha... that's what I get for reading your posts too quickly. Something is a bit odd about your flag fields. I've never had this particular problem before.

                    What happens if you use samtools view -f 4?

                    What are in the X0 fields of the mapped and unmapped reads?

                    Comment

                    • Chipper
                      Senior Member
                      • Mar 2008
                      • 323

                      #11
                      Samtools view -q 10

                      Comment

                      • swbarnes2
                        Senior Member
                        • May 2008
                        • 910

                        #12
                        Try:

                        Code:
                        samtools view whatever.bam | grep XT:A:U | grep -v XA: > unique.sam
                        If a read maps equally well to multiple places, bwa will pick one site, and only output that alignment. And it's never going to assign the 256 flag, that's why filtering based on it won't work. XT:R is assigned if the reads maps to multiple places, and the XA tag shows where those alternate alignment sites are (well the first few such sites, anyway)

                        So the above command line will filter away reads that have indications of being mapped multiple ways.
                        Last edited by swbarnes2; 05-10-2013, 11:16 AM.

                        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, 10-15-2026, 10:52 AM
                        0 responses
                        31 views
                        0 reactions
                        Last Post SEQadmin2  
                        Started by SEQadmin2, 10-14-2026, 05:39 AM
                        0 responses
                        39 views
                        0 reactions
                        Last Post SEQadmin2  
                        Started by SEQadmin2, 10-13-2026, 09:56 AM
                        0 responses
                        31 views
                        0 reactions
                        Last Post SEQadmin2  
                        Started by SEQadmin2, 10-09-2026, 11:14 AM
                        0 responses
                        29 views
                        0 reactions
                        Last Post SEQadmin2  
                        Working...