Seqanswers Leaderboard Ad

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

    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

                        • seqadmin
                          Pathogen Surveillance with Advanced Genomic Tools
                          by seqadmin




                          The COVID-19 pandemic highlighted the need for proactive pathogen surveillance systems. As ongoing threats like avian influenza and newly emerging infections continue to pose risks, researchers are working to improve how quickly and accurately pathogens can be identified and tracked. In a recent SEQanswers webinar, two experts discussed how next-generation sequencing (NGS) and machine learning are shaping efforts to monitor viral variation and trace the origins of infectious...
                          03-24-2025, 11:48 AM
                        • seqadmin
                          New Genomics Tools and Methods Shared at AGBT 2025
                          by seqadmin


                          This year’s Advances in Genome Biology and Technology (AGBT) General Meeting commemorated the 25th anniversary of the event at its original venue on Marco Island, Florida. While this year’s event didn’t include high-profile musical performances, the industry announcements and cutting-edge research still drew the attention of leading scientists.

                          The Headliner
                          The biggest announcement was Roche stepping back into the sequencing platform market. In the years since...
                          03-03-2025, 01:39 PM

                        ad_right_rmr

                        Collapse

                        News

                        Collapse

                        Topics Statistics Last Post
                        Started by seqadmin, 03-20-2025, 05:03 AM
                        0 responses
                        42 views
                        0 reactions
                        Last Post seqadmin  
                        Started by seqadmin, 03-19-2025, 07:27 AM
                        0 responses
                        51 views
                        0 reactions
                        Last Post seqadmin  
                        Started by seqadmin, 03-18-2025, 12:50 PM
                        0 responses
                        38 views
                        0 reactions
                        Last Post seqadmin  
                        Started by seqadmin, 03-03-2025, 01:15 PM
                        0 responses
                        194 views
                        0 reactions
                        Last Post seqadmin  
                        Working...