Unconfigured Ad

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

    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

              • GATTACAT
                Reply to Nine Things a Sample Prep Scientist Thinks About Before Sequencing
                by GATTACAT
                Love this - good data definitely starts from good input, and poor input can only give relatively poor data. I particularly like the mention of Nanodrop/absorbance based methods for quantification. It's such a toss up if you'll get an accurate reading or what amounts to a randomly generated number, and a lot of library/sequencing related issues can be traced back to poor quant.
                07-01-2026, 11:43 AM
              • SEQadmin2
                Nine Things a Sample Prep Scientist Thinks About Before Sequencing
                by SEQadmin2


                I’m not a sequencing expert. I’m a purification scientist who uses NGS to evaluate workflows my group develops. With this perspective, we think about the sample first and the NGS workflow second. The sequencer is an exceptionally honest reporter, but it can only report on what you give it, so whether you get clean, interpretable data from an NGS workflow is largely determined before you begin.

                Here are nine questions we think about, in roughly the order they matter, before...
                06-18-2026, 07:11 AM

              ad_right_rmr

              Collapse

              News

              Collapse

              Topics Statistics Last Post
              Started by SEQadmin2, Yesterday, 11:08 AM
              0 responses
              6 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 06-30-2026, 05:37 AM
              0 responses
              11 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 06-26-2026, 11:10 AM
              0 responses
              19 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 06-17-2026, 06:09 AM
              0 responses
              53 views
              0 reactions
              Last Post SEQadmin2  
              Working...