Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Cbon
    Junior Member
    • Jun 2010
    • 2

    #1

    BWA - number of sequences aligned

    Hello everyone,

    I am quite a newbie in bioinformatics, and I have some difficulties using bwa software.

    I successfully aligned my dataset to my reference genome. Now, I want to see the impact of the settings on my results, but I don't know how to obtain the number of reads aligned in the .sam file.

    Is there a useful trick to obtain the number of reads aligned ?

    I have found no clue on the bwa manual, neither in the samtool package and I begin to feel quite helpless ...

    Thank you for your answers !
  • dawe
    Senior Member
    • Apr 2009
    • 258

    #2
    Originally posted by Cbon View Post
    Hello everyone,

    Is there a useful trick to obtain the number of reads aligned ?
    Try

    Code:
    samtools flagstat [I]file.bam[/I]
    Although I don't know if it works on sam files (in case you should convert in BAM, which I believe should be the default...).

    d

    Comment

    • racetrout
      Junior Member
      • Jun 2010
      • 2

      #3
      If you are using UNIX and GNU awk,
      Code:
      gawk '!/^[@#]/ && (!and($2,4){print}' bwa.sam| wc -l
      should give you the number of reads aligned - providing BWA is setting the flag for unaligned reads. If you have many reads and BWA writes out only the aligned reads,
      Code:
      wc -l bwa.sam
      is a very good simple approximate of aligned reads (it counts the header of course, but the ~5 lines of the header compared to the millions of reads are negligible).

      Comment

      • Cbon
        Junior Member
        • Jun 2010
        • 2

        #4
        Thank you both for your answers !

        My files are already converted in .bam, so I hope I can use the flagstat command. If it doesn't work, I will try the code.

        thank you again !

        Comment

        • saml
          Junior Member
          • Oct 2010
          • 4

          #5
          Originally posted by racetrout View Post
          If you are using UNIX and GNU awk,
          Code:
          gawk '!/^[@#]/ && (!and($2,4){print}' bwa.sam| wc -l
          should give you the number of reads aligned - providing BWA is setting the flag for unaligned reads. If you have many reads and BWA writes out only the aligned reads,
          Code:
          wc -l bwa.sam
          is a very good simple approximate of aligned reads (it counts the header of course, but the ~5 lines of the header compared to the millions of reads are negligible).
          Yes, but removing the lines is easy too. Skipping 2 header lines (think I had that), and starting on the 3rd line, can be done with the tail command and adding a '+' before the number of lines, to denote which line to start from:

          Code:
          tail -n +3 bwa.sam | gawk '!/^[@#]/ && (!and($2,4){print}' | wc -l
          ... or for the case with only aligned reads coming from bwa:
          Code:
          tail -n +3 bwa.sam | wc -l

          Comment

          • swbarnes2
            Senior Member
            • May 2008
            • 910

            #6
            bwa by default includes all reads, even unaligned ones. You can tell that they are unmapped, from the binary tag.

            So the flagstat command will distinguish between the mapped an unmapped reads.

            You can also use samtools view -bF0x4 all.bam > mapped .bam to get a bam which has all the unmapped reads filtered out.

            Comment

            • nilshomer
              Nils Homer
              • Nov 2008
              • 1283

              #7
              Use "samtools view -c -S <in.sam>" and add the "-f/-F" options as desired.

              Comment

              • solonas13
                Junior Member
                • May 2012
                • 1

                #8
                I personally find it---at the best case---unacceptable the fact that a short-read aligner does not have an extra line of code to report the total number of aligned reads... Especially when it outputs (on the standard error) things like:

                `[infer_isize] (25, 50, 75) percentile: (137, 179, 227)'

                Anyhow, isn't there a closing parenthesis missing from this one?

                Originally posted by saml View Post
                Code:
                tail -n +3 bwa.sam | gawk '!/^[@#]/ && (!and($2,4){print}' | wc -l
                Thanks
                Last edited by solonas13; 05-13-2012, 03:47 PM.

                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
                16 views
                0 reactions
                Last Post SEQadmin2  
                Started by SEQadmin2, 10-14-2026, 05:39 AM
                0 responses
                21 views
                0 reactions
                Last Post SEQadmin2  
                Started by SEQadmin2, 10-13-2026, 09:56 AM
                0 responses
                22 views
                0 reactions
                Last Post SEQadmin2  
                Started by SEQadmin2, 10-09-2026, 11:14 AM
                0 responses
                27 views
                0 reactions
                Last Post SEQadmin2  
                Working...