Seqanswers Leaderboard Ad

Collapse

Announcement

Collapse
No announcement yet.
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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!

  • #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


    • #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


      • #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


        • #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


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

            Comment


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

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

              Comment


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

                Comment


                • #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


                  • #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


                    • #11
                      Samtools view -q 10

                      Comment


                      • #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

                        • seqadmin
                          Strategies for Sequencing Challenging Samples
                          by seqadmin


                          Despite advancements in sequencing platforms and related sample preparation technologies, certain sample types continue to present significant challenges that can compromise sequencing results. Pedro Echave, Senior Manager of the Global Business Segment at Revvity, explained that the success of a sequencing experiment ultimately depends on the amount and integrity of the nucleic acid template (RNA or DNA) obtained from a sample. “The better the quality of the nucleic acid isolated...
                          03-22-2024, 06:39 AM
                        • seqadmin
                          Techniques and Challenges in Conservation Genomics
                          by seqadmin



                          The field of conservation genomics centers on applying genomics technologies in support of conservation efforts and the preservation of biodiversity. This article features interviews with two researchers who showcase their innovative work and highlight the current state and future of conservation genomics.

                          Avian Conservation
                          Matthew DeSaix, a recent doctoral graduate from Kristen Ruegg’s lab at The University of Colorado, shared that most of his research...
                          03-08-2024, 10:41 AM

                        ad_right_rmr

                        Collapse

                        News

                        Collapse

                        Topics Statistics Last Post
                        Started by seqadmin, Yesterday, 06:37 PM
                        0 responses
                        8 views
                        0 likes
                        Last Post seqadmin  
                        Started by seqadmin, Yesterday, 06:07 PM
                        0 responses
                        8 views
                        0 likes
                        Last Post seqadmin  
                        Started by seqadmin, 03-22-2024, 10:03 AM
                        0 responses
                        49 views
                        0 likes
                        Last Post seqadmin  
                        Started by seqadmin, 03-21-2024, 07:32 AM
                        0 responses
                        66 views
                        0 likes
                        Last Post seqadmin  
                        Working...
                        X