Seqanswers Leaderboard Ad

Collapse

Announcement

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

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

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


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


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


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


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


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

              Comment


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

                • seqadmin
                  Understanding Genetic Influence on Infectious Disease
                  by seqadmin




                  During the COVID-19 pandemic, scientists observed that while some individuals experienced severe illness when infected with SARS-CoV-2, others were barely affected. These disparities left researchers and clinicians wondering what causes the wide variations in response to viral infections and what role genetics plays.

                  Jean-Laurent Casanova, M.D., Ph.D., Professor at Rockefeller University, is a leading expert in this crossover between genetics and infectious...
                  09-09-2024, 10:59 AM
                • seqadmin
                  Addressing Off-Target Effects in CRISPR Technologies
                  by seqadmin






                  The first FDA-approved CRISPR-based therapy marked the transition of therapeutic gene editing from a dream to reality1. CRISPR technologies have streamlined gene editing, and CRISPR screens have become an important approach for identifying genes involved in disease processes2. This technique introduces targeted mutations across numerous genes, enabling large-scale identification of gene functions, interactions, and pathways3. Identifying the full range...
                  08-27-2024, 04:44 AM

                ad_right_rmr

                Collapse

                News

                Collapse

                Topics Statistics Last Post
                Started by seqadmin, Today, 06:25 AM
                0 responses
                13 views
                0 likes
                Last Post seqadmin  
                Started by seqadmin, Yesterday, 01:02 PM
                0 responses
                12 views
                0 likes
                Last Post seqadmin  
                Started by seqadmin, 09-18-2024, 06:39 AM
                0 responses
                14 views
                0 likes
                Last Post seqadmin  
                Started by seqadmin, 09-11-2024, 02:44 PM
                0 responses
                14 views
                0 likes
                Last Post seqadmin  
                Working...
                X