Seqanswers Leaderboard Ad

Collapse

Announcement

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

  • Find unmapped read from sam/bam file

    Hi guys

    Could anyone tell me how to extract the unmapped reads from sam/bam file and convert the result to fastq format using samtools?

    Thx!

  • #2
    samtools view -f 4 yourbamfile.bam will give you unmapped reads

    Then pull out the first column of read names (cut -f1 -d" ") and extract those reads from your original fastq files, or make an awk script to reformat the readid, sequence, and quality scores into fastq.

    Note that depending on the alignment program that you are using, unmapped reads may or may not be reported in the results. Also, some programs trim off the /1 or /2 of the read ID, if you are working with paired ends). Finally, keep in mind that if you use this to extract other flags, the sequence in the BAM file is only what aligned, and could be the reverse complement of the input. (Shouldn't be an issue for unmapped reads)
    Last edited by Adrian_H; 07-01-2010, 07:52 AM. Reason: changed filename

    Comment


    • #3
      If you've used bwasw then the command line suggested by Adrian won't work.
      You'll have to write your own perl or awk script to extract unmapped reads comparing your bam output with your fastq file and rewrite it omitting aligned reads.

      Comment


      • #4
        can use bam2fastq

        Comment


        • #5
          +1 on the BAM2FASTQ. Great tool...of course I'm biased as it came from my group but it is well documented and fast. Let us know if you have any questions or problems.
          HudsonAlpha Institute for Biotechnology
          http://www.hudsonalpha.org/gsl

          Comment


          • #6
            Hi,

            I used bam2fastq tool to extract unmapped reads, it's really fast and better documented. but I had difficulties to address the cause of the warning message:

            Code:
            $ ./bam2fastq -o s_%#_extracted_reads.txt -f --no-aligned --unaligned --no-filter alignments.bam 
            [bam_header_read] EOF marker is absent.
            This looks like paired data from lane 1.
            Output will be in s_1_1_extracted_reads.txt and s_1_2_extracted_reads.txt
            55130926 sequences in the BAM file
            8238703 sequences exported
            WARNING: 5947209 reads could not be matched to a mate and were not exported
            Fastq files contain 1145747 reads each, which means those 5947209 unmapped reads are discarded. But I really would like to have them included in the result. Could you help me out here?

            PS: Reads are pair end, ranging from 25 - 78 after quality trimming.


            Originally posted by csquared View Post
            +1 on the BAM2FASTQ. Great tool...of course I'm biased as it came from my group but it is well documented and fast. Let us know if you have any questions or problems.

            Comment


            • #7
              samtools view -bh -f 0*4 -o output.file input

              Comment


              • #8
                What about reads mapping to the reverse strand? Should they be reverse complemented before converting to fastq?

                Comment


                • #9
                  Originally posted by JonB View Post
                  What about reads mapping to the reverse strand? Should they be reverse complemented before converting to fastq?
                  No, sequences and qualities are always the same as the source fastq, regardless of mapped strand.

                  Comment


                  • #10
                    Good to know, thanks!

                    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
                    67 views
                    0 likes
                    Last Post seqadmin  
                    Working...
                    X