Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • paolo.kunder
    Member
    • Aug 2011
    • 93

    #1

    Discard reads from file that fail to map as a proper pair.

    Dear All,
    I would like use Samtools to discard reads from the bam file that fail to map as a proper pair.

    Is this command correct?

    Code:
    samtools view -b-h -f 4 -o out.bam in.bam
    I am wondering about the integer after the f option

    Thanks,
    Paolo
  • syfo
    Just a member
    • Nov 2012
    • 103

    #2
    Originally posted by paolo.kunder View Post
    Dear All,
    I would like use Samtools to discard reads from the bam file that fail to map as a proper pair.

    Is this command correct?

    Code:
    samtools view -b-h -f 4 -o out.bam in.bam
    I am wondering about the integer after the f option

    Thanks,
    Paolo
    I would have done:
    Code:
    samtools view -bh -f2 in.bam > out.bam
    -f4 gets you the unmapped reads
    FYI, a flag reader is available here

    Comment

    • swbarnes2
      Senior Member
      • May 2008
      • 910

      #3
      You want

      Code:
      samtools view -bhF 2 in.bam > out.bam
      You want to filter out all the reads that didn't map right, so the F needs to be uppercase.

      Comment

      • syfo
        Just a member
        • Nov 2012
        • 103

        #4
        Originally posted by swbarnes2 View Post
        You want

        Code:
        samtools view -bhF 2 in.bam > out.bam
        You want to filter out all the reads that didn't map right, so the F needs to be uppercase.
        mhm.. isn't it precisely the other way around? I think that "-f2" gives you proper pairs and "-F2" filters them out.

        Comment

        • winsettz
          Member
          • Sep 2012
          • 91

          #5
          From samtools (http://samtools.sourceforge.net/samtools.shtml)

          -f INT Only output alignments with all bits in INT present in the FLAG field. INT can be in hex in the format of /^0x[0-9A-F]+/ [0]
          -F INT Skip alignments with bits present in INT [0]
          -f to output only a particular bit, -F to skip.

          From the SAM spec: (http://samtools.sourceforge.net/SAM1.pdf)

          FLAG: bitwise FLAG. Each bit is explained in the following table:
          Bit Description
          0x1 template having multiple segments in sequencing
          0x2 each segment properly aligned according to the aligner
          0x4 segment unmapped
          SAM spec is not as clear as I would like. 4 is obvious, and I've thought of 2 as meaning "mapped to one position" and 1 meaning "maps in multiple regions".

          Though the flag explainer is new to me; thanks for posting it.
          Last edited by winsettz; 02-04-2013, 10:03 AM.

          Comment

          • swbarnes2
            Senior Member
            • May 2008
            • 910

            #6
            Originally posted by swbarnes2 View Post
            You want

            Code:
            samtools view -bhF 2 in.bam > out.bam
            You want to filter out all the reads that didn't map right, so the F needs to be uppercase.
            Edit: Oops, brain fart, I was wrong.

            Comment

            • syfo
              Just a member
              • Nov 2012
              • 103

              #7
              Even better: add -F12 to make sure you remove the ones that are not mapped and whose mate is not mapped. Believe it or not, the "mapped in proper pair" flag can be given to... unmapped reads.

              Explanation from the SAM format specs (according to a previous post): "If 0x4 is set, no assumptions can be made about RNAME, POS, CIGAR, MAPQ, bits 0x2, 0x10 and 0x100 and the bit 0x20 of the next segment in the template.".

              Conclusion: don't trust the sole "proper pair" nor the "mapq" flag and always control for the mapping status.

              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-22-2026, 11:13 AM
              0 responses
              23 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 10-22-2026, 10:48 AM
              0 responses
              20 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 10-15-2026, 10:52 AM
              0 responses
              36 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 10-14-2026, 05:39 AM
              0 responses
              42 views
              0 reactions
              Last Post SEQadmin2  
              Working...