Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vincent lee
    Junior Member
    • Aug 2012
    • 4

    #1

    How to exclude the unmapped pair reads in bam files

    There is a bam file with the pair-end reads alignment.

    I want to exclude the reads only when neither of pair reads are mapped onto the genome.
    What command I should type?

    I have tried samtools view -f 2, which just removed the pair if either one is unmapped.( The same as samtools view -F 12 )

    Besides, samtools view -F 4 or samtools view -F 8 will remove a read while the other is mapped.

    Thanks!

    Best regards!
  • Lluc
    Member
    • Aug 2010
    • 12

    #2
    I would suggest to go through the file a couple of times, first to take the half mapped reads, and then the ones completely mapped:

    samtools view -F 4 -f 8 input.bam > only_this_end_mapped.sam
    samtools view -F 8 -f 4 input.bam > only_that_end_mapped.sam
    samtools view -F 12 input.bam > both_ends_mapped.sam

    And then, merge them.

    Alternatively, you could select the reads that you want to exclude, write their names in a file, and use that list as a filter with Picard's FilterSamReads:

    samtools view -f 12 input.bam | cut -f 1 > blacklist
    java -jar FilterSamReads.jar INPUT=input.bam FILTER=excludeReadList READ_LIST_FILE=blacklist OUTPUT=clean.bam

    Comment

    • vincent lee
      Junior Member
      • Aug 2012
      • 4

      #3
      Thanks for your reply Lluc!

      It seem no other method can be faster... I would like to try the first one you mention above.
      Hoping someone could write a program in C or C++, which can make it faster.

      Best regards!

      Comment

      Latest Articles

      Collapse

      • SEQadmin2
        16S/ITS Profiling vs. Shotgun Metagenomics: What Changes in Your Workflow?
        by SEQadmin2




        NGS has revolutionized clinical microbiology by offering new ways to identify and surveil pathogens without prior knowledge of the target. One popular approach is 16S rRNA and ITS amplicon sequencing, which targets specific microbial markers. But studies are increasingly incorporating shotgun metagenomics, a technique that sequences all DNA from a sample without targeting specific microbial markers. This approach allows more detailed taxonomic classification, detection...
        10-30-2026, 06:46 AM
      • 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

      ad_right_rmr

      Collapse

      News

      Collapse

      Topics Statistics Last Post
      Started by SEQadmin2, 10-28-2026, 09:57 AM
      0 responses
      37 views
      0 reactions
      Last Post SEQadmin2  
      Started by SEQadmin2, 10-28-2026, 09:51 AM
      0 responses
      23 views
      0 reactions
      Last Post SEQadmin2  
      Started by SEQadmin2, 10-22-2026, 11:13 AM
      0 responses
      72 views
      0 reactions
      Last Post SEQadmin2  
      Started by SEQadmin2, 10-22-2026, 10:48 AM
      0 responses
      48 views
      0 reactions
      Last Post SEQadmin2  
      Working...