Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • krapulaxdoctor
    Member
    • May 2015
    • 22

    #1

    Samtools filter reads based on CIGAR values

    Dear all,

    I would like to ask for some help with samtools:

    I found many threads about using samtools to filter reads based on some criteria, however, I did not find any clue how to filter reads based on the CIGAR value.

    How can I filter reads (from a BAM) from RNA-seq files that are non-splitted / non-gapped?

    From one BAM, I would like to have two BAMs ne with gapped reads and one with non-gapped reads.

    Could someone write an example?
    Thank you for the help in advance,
  • dariober
    Senior Member
    • May 2010
    • 311

    #2
    Gapped reads are those containing the N operator in the cigar string right? You could do this:

    Code:
    samtools view -h in.bam \
    | awk '{if($0 ~ /^@/ || $6 ~ /N/) {print $0}}' \
    | samtools view -Sb - > gapped.bam
    And for ungapped reads:

    Code:
    samtools view -h in.bam \
    | awk '{if($0 ~ /^@/ || $6 !~ /N/) {print $0}}' \
    | samtools view -Sb - > ungapped.bam

    Comment

    • HESmith
      Senior Member
      • Oct 2009
      • 512

      #3
      Be aware that deletions (CIGAR string D) also give rise to gapped alignments, and the representation as N vs. D depends on the gap length and the aligner.

      Comment

      • dariober
        Senior Member
        • May 2010
        • 311

        #4
        Originally posted by HESmith View Post
        Be aware that deletions (CIGAR string D) also give rise to gapped alignments, and the representation as N vs. D depends on the gap length and the aligner.
        True, but I surmise the OP wants to select reads spanning different exons as opposed those only assigned to one exon. If this is the case, I think tophat uses N to mark gaps between exons (don't know other aligners).

        Comment

        • dpryan
          Devon Ryan
          • Jul 2011
          • 3478

          #5
          Originally posted by dariober View Post
          True, but I surmise the OP wants to select reads spanning different exons as opposed those only assigned to one exon. If this is the case, I think tophat uses N to mark gaps between exons (don't know other aligners).
          Realistically, any aligner that advertises the ability to handle spliced reads will do this too. If not, it shouldn't be used.

          Comment

          • krapulaxdoctor
            Member
            • May 2015
            • 22

            #6
            Thank you for all the quick responses.
            It is a great help for me.

            dariober:
            True, but I surmise the OP wants to select reads spanning different exons as opposed those only assigned to one exon. If this is the case...
            Yes, that would be the main goal. Thanks.

            Comment

            • HESmith
              Senior Member
              • Oct 2009
              • 512

              #7
              Originally posted by dpryan View Post
              Realistically, any aligner that advertises the ability to handle spliced reads will do this too. If not, it shouldn't be used.
              I agree 100%, but it would not be the first time that someone used an inappropriate tool for the job. The alert was directed at the OP, in case the awk filter did not produce the expected results.

              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-15-2026, 10:52 AM
              0 responses
              25 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 10-14-2026, 05:39 AM
              0 responses
              31 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 10-13-2026, 09:56 AM
              0 responses
              28 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 10-09-2026, 11:14 AM
              0 responses
              28 views
              0 reactions
              Last Post SEQadmin2  
              Working...