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
                      Essential Discoveries and Tools in Epitranscriptomics
                      by seqadmin


                      The field of epigenetics has traditionally concentrated more on DNA and how changes like methylation and phosphorylation of histones impact gene expression and regulation. However, our increased understanding of RNA modifications and their importance in cellular processes has led to a rise in epitranscriptomics research. “Epitranscriptomics brings together the concepts of epigenetics and gene expression,” explained Adrien Leger, PhD, Principal Research Scientist on Modified Bases...
                      Yesterday, 07:01 AM
                    • seqadmin
                      Current Approaches to Protein Sequencing
                      by seqadmin


                      Proteins are often described as the workhorses of the cell, and identifying their sequences is key to understanding their role in biological processes and disease. Currently, the most common technique used to determine protein sequences is mass spectrometry. While still a valuable tool, mass spectrometry faces several limitations and requires a highly experienced scientist familiar with the equipment to operate it. Additionally, other proteomic methods, like affinity assays, are constrained...
                      04-04-2024, 04:25 PM

                    ad_right_rmr

                    Collapse

                    News

                    Collapse

                    Topics Statistics Last Post
                    Started by seqadmin, 04-11-2024, 12:08 PM
                    0 responses
                    51 views
                    0 likes
                    Last Post seqadmin  
                    Started by seqadmin, 04-10-2024, 10:19 PM
                    0 responses
                    50 views
                    0 likes
                    Last Post seqadmin  
                    Started by seqadmin, 04-10-2024, 09:21 AM
                    0 responses
                    44 views
                    0 likes
                    Last Post seqadmin  
                    Started by seqadmin, 04-04-2024, 09:00 AM
                    0 responses
                    55 views
                    0 likes
                    Last Post seqadmin  
                    Working...
                    X